[
  {
    "path": ".github/ISSUE_TEMPLATE/feature_request.md",
    "content": "---\nname: Feature request\nabout: Suggest an idea for this project\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Describe the feature or solution you'd like to see included:**\n- Give a clear description of what you would like to see changed or added.\n\n**Is this feature request related to a problem or specific use case?:**\n- Please describe what use case or problem this new feature will help solve. \n\n**Additional context:**\n- Please provide any additional context or background here.\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/issue-report.md",
    "content": "---\nname: Issue report\nabout: Create an issue report to help improve the installer\ntitle: ''\nlabels: ''\nassignees: ''\n\n---\n\n**Describe the issue:**\n- Please provide a clear and concise description of what the issue is. \"It doesn't work\" is not enough detail!\n\n**Steps to reproduce the issue:**\n- Please provide the steps to reproduce the error or behaviour (include what you believe should happen):\n\n**Describe the software environment:**\n- OS & version\n  - Include platform i.e. physical, virtual, cloud image etc\n- List other applications present\n- List other services or tasks the system also currently provides\n- Details any other relevant background context about your OS, its location, method of management or access, firewall settings etc.\n\n**Logs / screenshots / error outputs etc**\n- Where possible, provide as much background detail as possible to help explain your problem through the outputs you have available.\n\n**Troubleshooting steps already taken?:**\n- What steps have already taken to diagnose, debug or resolve the issue?\n- Details of any testing already performed?\n"
  },
  {
    "path": "1-setup.sh",
    "content": "#!/bin/bash\n######################################################################################################################\n# Guacamole appliance setup script\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n# To install the latest code snapshot:\n# wget https://raw.githubusercontent.com/itiligent/Guacamole-Install/main/1-setup.sh && chmod +x 1-setup.sh && ./1-setup.sh\n\n# 1-setup.sh is a central script that manages all inputs, options and sequences other included 'install' scripts.\n# 2-install-guacamole downloads Guacamole source and exectutes all Guacamole's build instructions.\n# 3-install-nginx.sh automatically installs and configures Nginx to work as an http port 80 front end to Guacamole.\n# 4a-install-tls-self-signed-nginx.sh sets up the new Nginx/Guacamole front end with self signed TLS certificates.\n# 4b-install-tls-letsencrypt-nginx.sh sets up Nginx with public TLS certificates from LetsEncrypt.\n# Scripts with \"add\" in their name can be run post install to add optional features not included in the main install.\n\n# For troubleshooting check logs or place Guacamole in debug mode:\n#     tail -f /var/log/syslog /var/log/tomcat*/*.out guac-setup/guacamole_setup.log\n#     sudo systemctl stop guacd && sudo /usr/local/sbin/guacd -L debug -f\n\n#######################################################################################################################\n# Script pre-flight checks and settings ###############################################################################\n#######################################################################################################################\n\nclear\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\n# Make sure the user is NOT running this script as root\nif [[ $EUID -eq 0 ]]; then\n    echo\n    echo -e \"${LRED}This script must NOT be run as root, it will prompt for sudo when needed.\" 1>&2\n    echo -e ${NC}\n    exit 1\nfi\n\n# Check if sudo is installed. (Debian does not always include sudo by default)\nif ! command -v sudo &> /dev/null; then\n    echo \"${LRED}Sudo is not installed. Please install sudo.\"\n    echo -e ${NC}\n    exit 1\nfi\n\n# Make sure the user running setup is a member of the sudo group\nif ! id -nG \"$USER\" | grep -qw \"sudo\"; then\n    echo\n    echo -e \"${LRED}The current user (${USER}) must be a member of the 'sudo' group. Run as root: usermod -aG sudo your-username & re-login ${USER}${NC}\" 1>&2\n    exit 1\nfi\n\n# Check to see if any previous version of build files exist, if so stop and check to be safe.\nif [[ \"$(find . -maxdepth 1 \\( -name 'guacamole-*' -o -name 'mysql-connector-j-*' \\))\" != \"\" ]]; then\n    echo\n    echo -e \"${LRED}Possible previous install files detected in current build path. Please review and remove old guacamole install files before proceeding.${GREY}, exiting...\" 1>&2\n    echo\n    exit 1\nfi\n\n# Query the OS version\nsource /etc/os-release\n\n#######################################################################################################################\n# Core setup variables and mandatory inputs - EDIT VARIABLE VALUES TO SUIT ############################################\n#######################################################################################################################\n\n# Setup download and temp directory paths\nUSER_HOME_DIR=$(eval echo ~${SUDO_USER})\nDOWNLOAD_DIR=$USER_HOME_DIR/guac-setup\nDB_BACKUP_DIR=$USER_HOME_DIR/mysqlbackups\nmkdir -p $DOWNLOAD_DIR\nmkdir -p $DB_BACKUP_DIR\n\n# GitHub download branch\nGITHUB=\"https://raw.githubusercontent.com/itiligent/Guacamole-Install/main\"\n\n# Version of Guacamole to install\nGUAC_VERSION=\"1.6.0\"\nGUAC_SOURCE_LINK=\"http://apache.org/dyn/closer.cgi?action=download&filename=guacamole/${GUAC_VERSION}\"\n\n# MySQL Connector/J version to install\nMYSQLJCON=\"9.3.0\"\nMYSQLJCON_SOURCE_LINK=\"https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-j-${MYSQLJCON}.tar.gz\"\n\n# Provide a specific MySQL version e.g. 11.1.2 or leave blank \"\" to use distro default MySQL packages.\n# See https://mariadb.org/mariadb/all-releases/ for available versions.\nMYSQL_VERSION=\"\"\nMARIADB_SOURCE_LINK=\"https://downloads.mariadb.com/MariaDB/mariadb_repo_setup\"\n\n# Reverse proxy uses this URL (Guacamole default is http://localhost:8080/guacamole/):\nGUAC_URL=http://localhost:8080/guacamole/\n\n# Get the default route interface IP. May need to manually override this for multi homed systems or where cloud images may use 127.0.x.x\nDEFAULT_IP=$(ip addr show $(ip route | awk '/default/ { print $5 }') | grep \"inet\" | head -n 1 | awk '/inet/ {print $2}' | cut -d'/' -f1)\n\n# Install log Location\nINSTALL_LOG=\"${DOWNLOAD_DIR}/guacamole_install.log\"\n\n#######################################################################################################################\n# Silent setup options - true/false or specific values below will skip prompt at install. EDIT TO SUIT ################\n#######################################################################################################################\nSERVER_NAME=\"\"                  # Server hostname (blank = use the current hostname)\nLOCAL_DOMAIN=\"\"                 # Local DNS namespace/domain suffix (blank = keep the current suffix)\nINSTALL_MYSQL=\"\"                # Install MySQL locally (true/false)\nSECURE_MYSQL=\"\"                 # Apply mysql secure configuration tool (true/false)\nMYSQL_HOST=\"\"                   # Blank \"\" = localhost MySQL install, adding a specific IP address will assume a remote MySQL instance\nMYSQL_PORT=\"\"                   # If blank \"\" default is 3306\nGUAC_DB=\"\"                      # If blank \"\" default is guacamole_db\nGUAC_USER=\"\"                    # If blank \"\" default is guacamole_user\nMYSQL_ROOT_PWD=\"\"               # Manadatory entry here or at script prompt\nGUAC_PWD=\"\"                     # Manadatory entry here or at script prompt\nGUACD_ACCOUNT=\"guacd\"           # Service account guacd will run under (and will be very heavily locked down)\nDB_TZ=$(timedatectl show -p Timezone --value) # Blank \"\" defaults to UTC, for local timezone: $(cat /etc/timezone)\nINSTALL_TOTP=\"\"                 # Add TOTP MFA extension (true/false), can't be installed simultaneously with DUO)\nINSTALL_DUO=\"\"                  # Add DUO MFA extension (true/false, can't be installed simultaneously with TOTP)\nINSTALL_LDAP=\"\"                 # Add Active Directory extension (true/false)\nINSTALL_QCONNECT=\"\"             # Add Guacamole console quick connect feature (true/false)\nINSTALL_HISTREC=\"\"              # Add Guacamole history recording storage feature (true/false)\nHISTREC_PATH=\"\"                 # If blank \"\" sets the Apache's default path of /var/lib/guacamole/recordings\nGUAC_URL_REDIR=\"\"               # Auto redirect of host root URL http://xxx:8080 to http://xxx:8080/guacamole  (true/false)\nINSTALL_NGINX=\"\"                # Install & configure Nginx reverse proxy http:80 frontend (true/false)\nPROXY_SITE=\"\"                   # Local DNS name for reverse proxy site and/or self signed TLS certificates (blank \"\" defaults to $DEFAULT_FQDN)\nSELF_SIGN=\"\"                    # Add self signed TLS/https support to Nginx (true/false, Let's Encrypt not available with this option)\nRSA_KEYLENGTH=\"2048\"            # Self signed RSA TLS key length. At least 2048, must not be blank\nCERT_COUNTRY=\"AU\"               # Self signed cert setup, 2 character country code only, must not be blank\nCERT_STATE=\"Victoria\"           # Self signed cert setup, must not be blank\nCERT_LOCATION=\"Melbourne\"       # Self signed cert setup, must not be blank\nCERT_ORG=\"Itiligent\"            # Self signed cert setup, must not be blank\nCERT_OU=\"I.T.\"                  # Self signed cert setup, must not be blank\nCERT_DAYS=\"3650\"                # Self signed cert setup, days until self signed TLS cert expiry, blank = default 3650\nLETS_ENCRYPT=\"\"                 # Add Lets Encrypt public TLS cert for Nginx (true/false, self signed TLS not available with this option) \nLE_DNS_NAME=\"\"                  # Public DNS name for use with Lets Encrypt certificates, must match public DNS\nLE_EMAIL=\"\"                     # Webmaster email for Lets Encrypt notifications\nBACKUP_EMAIL=\"\"                 # Email address to send MySQL backup notifications to\nBACKUP_RETENTION=\"30\"           # Days to keep SQL backups locally\nRDP_SHARE_HOST=\"\"               # Custom RDP host name shown in Windows Explorer (eg. \"RDP_SHARE_LABEL on RDP_SHARE_HOST\"). Blank \"\" = $SERVER_NAME\nRDP_SHARE_LABEL=\"RDP Share\"     # Custom RDP shared drive name in Windows Explorer (eg. \"RDP_SHARE_LABEL on RDP_SHARE_HOST\" eg. \"your RDP share name on server01\"\nRDP_PRINTER_LABEL=\"RDP Printer\" # Custom RDP printer name shown in Windows\nCRON_DENY_FILE=\"/etc/cron.deny\" # Distro's cron deny file\nFREERDP=\"freerdp2-dev\"\t\t\t# Set default FreeRDP package\n\n#######################################################################################################################\n# Download GitHub setup scripts. BEFORE RUNNING SETUP, COMMENT OUT DOWNLOAD LINES OF ANY SCRIPTS YOU HAVE EDITED ! ####\n#######################################################################################################################\n\n# Script branding header\necho\necho -e \"${GREYB}Guacamole ${GUAC_VERSION} Appliance Auto Installer\"\necho -e \"              ${LGREEN}Powered by Itiligent\"\necho\necho\n\n# Download the suite of install scripts from GitHub\ncd $DOWNLOAD_DIR\necho -e \"${GREY}Downloading the Guacamole build suite...${DGREY}\"\nwget -q --show-progress ${GITHUB}/2-install-guacamole.sh -O 2-install-guacamole.sh\nwget -q --show-progress ${GITHUB}/3-install-nginx.sh -O 3-install-nginx.sh\nwget -q --show-progress ${GITHUB}/4a-install-tls-self-signed-nginx.sh -O 4a-install-tls-self-signed-nginx.sh\nwget -q --show-progress ${GITHUB}/4b-install-tls-letsencrypt-nginx.sh -O 4b-install-tls-letsencrypt-nginx.sh\n\n# Download the suite of optional feature adding scripts\nwget -q --show-progress ${GITHUB}/guac-optional-features/add-auth-duo.sh -O add-auth-duo.sh\nwget -q --show-progress ${GITHUB}/guac-optional-features/add-auth-ldap.sh -O add-auth-ldap.sh\nwget -q --show-progress ${GITHUB}/guac-optional-features/add-auth-totp.sh -O add-auth-totp.sh\nwget -q --show-progress ${GITHUB}/guac-optional-features/add-xtra-quickconnect.sh -O add-xtra-quickconnect.sh\nwget -q --show-progress ${GITHUB}/guac-optional-features/add-xtra-histrecstor.sh -O add-xtra-histrecstor.sh\nwget -q --show-progress ${GITHUB}/guac-optional-features/add-smtp-relay-o365.sh -O add-smtp-relay-o365.sh\nwget -q --show-progress ${GITHUB}/guac-optional-features/add-tls-guac-daemon.sh -O add-tls-guac-daemon.sh\nwget -q --show-progress ${GITHUB}/guac-optional-features/add-fail2ban.sh -O add-fail2ban.sh\nwget -q --show-progress ${GITHUB}/guac-management/backup-guacamole.sh -O backup-guacamole.sh\nwget -q --show-progress ${GITHUB}/upgrade-guacamole.sh -O upgrade-guacamole.sh\n\n# Download the dark theme & branding template\nwget -q --show-progress ${GITHUB}/branding.jar -O branding.jar\nchmod +x *.sh\n\n# Pause here to optionally customise downloaded scripts before any actual install actions begin\necho -e \"${LYELLOW}Ctrl+Z now to exit now if you wish to customise 1-setup.sh options or create an unattended install.\"\necho\n\n# This first sudo command is a trigger to pause for setup script customisation shown above, then to continue as sudo where needed.\nsudo apt-get update -qq &> /dev/null\n\n#######################################################################################################################\n# Package dependency handling and workarounds for various distros, MODIFY ONLY IF NEEDED ##############################\n#######################################################################################################################\n\n# Standardise on a lexicon for the different MySQL package options\nif [[ -z \"${MYSQL_VERSION}\" ]]; then\n    # Use Linux distro default version.\n    MYSQLSRV=\"default-mysql-server default-mysql-client mysql-common\" # Server\n    MYSQLCLIENT=\"default-mysql-client\" # Client\n    DB_CMD=\"mysql\" # The mysql -v command is depricated on some versions.\nelse\n    # Use official mariadb.org repo\n    MYSQLSRV=\"mariadb-server mariadb-client mariadb-common\" # Server\n    MYSQLCLIENT=\"mariadb-client\" # Client\n    DB_CMD=\"mariadb\" # The mysql -v command is depricated on some versions.\nfi\n\n# Standardise on a lexicon for the differing dependency package names between distros\n# Current package names for various distros are referenced at https://guacamole.apache.org/doc/gug/installing-guacamole.html\nJPEGTURBO=\"\"\nLIBPNG=\"\"\nif [[ ${ID,,} = \"ubuntu\" ]] || [[ ${ID,,} = *\"ubuntu\"* ]] || [[ ${ID,,} = *\"linuxmint\"* ]]; then\n    JPEGTURBO=\"libjpeg-turbo8-dev\"\n    LIBPNG=\"libpng-dev\"\n    # Just in case this repo is not present in the distro\n    sudo add-apt-repository -y universe &>>${INSTALL_LOG}\nelif [[ ${ID,,} = \"debian\" ]] || [[ ${ID,,} = \"raspbian\" ]]; then\n    JPEGTURBO=\"libjpeg62-turbo-dev\"\n    LIBPNG=\"libpng-dev\"\nfi\n\n#######################################################################################################################\n# Ongoing fixes and workarounds as distros diverge/change #############################################################\n#######################################################################################################################\n\n# Check for the more recent versions of Tomcat currently supported by the distro\nif [[ $(apt-cache show tomcat10 2>/dev/null | egrep \"Version: 10\" | wc -l) -gt 0 ]]; then\n    TOMCAT_VERSION=\"tomcat10\"\nelif [[ $(apt-cache show tomcat9 2>/dev/null | egrep \"Version: 9\" | wc -l) -gt 0 ]]; then\n    TOMCAT_VERSION=\"tomcat9\"\nelse\n    # Default to this version\n    TOMCAT_VERSION=\"tomcat9\"\nfi\n\n# Decide the appropriate FreeRDP package (Debian 13.0 has issues with FreeRDP3) \nif [[ \"${VERSION_CODENAME,,}\" == \"bookworm\" || \"${VERSION_CODENAME,,}\" == \"noble\" ]]; then\n    FREERDP=\"freerdp3-dev\"\nfi\n\n# Workaround for Debian incompatibilities with later Tomcat versions. (Adds the oldstable repo and downgrades the Tomcat version)\nif [[ ${ID,,} = \"debian\" && ${VERSION_CODENAME,,} = *\"bookworm\"* ]] || [[ ${ID,,} = \"debian\" && ${VERSION_CODENAME,,} = *\"trixie\"* ]]; then #(checks for upper and lower case)\n    echo \"deb http://deb.debian.org/debian/ bullseye main\" | sudo tee /etc/apt/sources.list.d/bullseye.list &> /dev/null\n    sudo apt-get update -qq &> /dev/null\n    TOMCAT_VERSION=\"tomcat9\"\nfi\n\n# Workaround for Ubuntu 23.x Tomcat 10 incompatibilities. Downgrades Tomcat to version 9 which is available from the Lunar repo.\nif [[ ${ID,,} = \"ubuntu\" ]] && [[ ${VERSION_CODENAME,,} = *\"lunar\"* ]]; then\n    TOMCAT_VERSION=\"tomcat9\"\nfi\n\n# Workaround for Ubuntu 24.x Tomcat 10 incompatibilities. (Adds old Jammy repo and downgrades the Tomcat version)\nif [[ ${ID,,} = \"ubuntu\" && ${VERSION_CODENAME,,} = *\"noble\"* ]]; then\n    echo \"deb http://archive.ubuntu.com/ubuntu/ jammy universe\" | sudo tee /etc/apt/sources.list.d/jammy.list &> /dev/null\n    sudo apt-get update -qq &> /dev/null\n    TOMCAT_VERSION=\"tomcat9\"\nfi\n\n# Uncomment here to force a specific Tomcat version.\n# TOMCAT_VERSION=\"tomcat9\"\n\n# Workaround for 1.5.4 specific bug, see issue #31. This was fixed in 1.5.5\nif [[ \"${ID,,}\" = \"debian\" && \"${VERSION_CODENAME,,}\" = *\"bullseye\"* ]] || [[ \"${ID,,}\" = \"ubuntu\" && \"${VERSION_CODENAME,,}\" = *\"focal\"* ]]; then\n    IFS='.' read -ra guac_version_parts <<< \"${GUAC_VERSION}\"\n    major=\"${guac_version_parts[0]}\"\n    minor=\"${guac_version_parts[1]}\"\n    patch=\"${guac_version_parts[2]}\"\n    # Uncomment 2nd line and comment first line if issue returns >=1.5.4 (See https://issues.apache.org/jira/browse/GUACAMOLE-1892))\n\tif (( major == 1 && minor == 5 && patch == 4 )); then\n\t#if (( major > 1 || (major == 1 && minor > 5) || ( major == 1 && minor == 5 && patch >= 4 ) )); then\n      export LDFLAGS=\"-lrt\"\n    fi\nfi\n\n#######################################################################################################################\n# DO NOT EDIT PAST THIS POINT! ########################################################################################\n#######################################################################################################################\n\n# An intitial dns suffix is needed as a starting value for the script prompts\nget_domain_suffix() {\n    echo \"$1\" | awk '{print $2}'\n}\n# Search for \"search\" and \"domain\" entries in /etc/resolv.conf\nsearch_line=$(grep -E '^search[[:space:]]+' /etc/resolv.conf)\ndomain_line=$(grep -E '^domain[[:space:]]+' /etc/resolv.conf)\n# Check if both \"search\" and \"domain\" lines exist\nif [[ -n \"$search_line\" ]] && [[ -n \"$domain_line\" ]]; then\n    # Both \"search\" and \"domain\" lines exist, extract the domain suffix from both\n    search_suffix=$(get_domain_suffix \"$search_line\")\n    domain_suffix=$(get_domain_suffix \"$domain_line\")\n    # Print the domain suffix that appears first\n    if [[ ${#search_suffix} -lt ${#domain_suffix} ]]; then\n        DOMAIN_SUFFIX=$search_suffix\n    else\n        DOMAIN_SUFFIX=$domain_suffix\n    fi\nelif [[ -n \"$search_line\" ]]; then\n    # If only \"search\" line exists\n    DOMAIN_SUFFIX=$(get_domain_suffix \"$search_line\")\nelif [[ -n \"$domain_line\" ]]; then\n    # If only \"domain\" line exists\n    DOMAIN_SUFFIX=$(get_domain_suffix \"$domain_line\")\nelse\n    # If no \"search\" or \"domain\" lines found\n    DOMAIN_SUFFIX=\"local\"\nfi\n\n#######################################################################################################################\n# Begin install menu prompts ##########################################################################################\n#######################################################################################################################\n\n# Consistent /etc/hosts and domain suffix values are needed for TLS implementation. The below approach\n# allows the user to either hit enter at the prompt to keep current values, or enter new values for both. Silent install\n# pre-set values (if provided) will bypass these prompts.\n\n# Ensure SERVER_NAME is consistent with local host entries\nif [[ -z ${SERVER_NAME} ]]; then\n    echo -e \"${LYELLOW} Update Linux system HOSTNAME? [Enter to keep: ${HOSTNAME}]${LGREEN}\"\n    read -p \"              Enter Linux hostname : \" SERVER_NAME\n    # If hit enter making no SERVER_NAME change, assume the existing hostname as current\n    if [[ \"${SERVER_NAME}\" = \"\" ]]; then\n        SERVER_NAME=$HOSTNAME\n    fi\n    echo\n    # A SERVER_NAME was derived via the prompt\n    # Apply the SERVER_NAME value & remove & update any old 127.0.1.1 localhost references\n    $(sudo hostnamectl set-hostname $SERVER_NAME &>/dev/null &) &>/dev/null\n\tsleep 1\n    sudo sed -i '/127.0.1.1/d' /etc/hosts &>>${INSTALL_LOG}\n    echo '127.0.1.1       '${SERVER_NAME}'' | sudo tee -a /etc/hosts &>>${INSTALL_LOG}\n    $(sudo systemctl restart systemd-hostnamed &>/dev/null &) &>/dev/null\nelse\n    echo\n    # A SERVER_NAME value was derived from a pre-set silent install option.\n    # Apply the SERVER_NAME value & remove & update any old 127.0.1.1 localhost references\n    $(sudo hostnamectl set-hostname $SERVER_NAME &>/dev/null &) &>/dev/null\n\tsleep 1\n    sudo sed -i '/127.0.1.1/d' /etc/hosts &>>${INSTALL_LOG}\n    echo '127.0.1.1       '${SERVER_NAME}'' | sudo tee -a /etc/hosts &>>${INSTALL_LOG}\n    $(sudo systemctl restart systemd-hostnamed &>/dev/null &) &>/dev/null\nfi\n\n# Ensure LOCAL_DOMAIN suffix & localhost entries are consistent\nif [[ -z ${LOCAL_DOMAIN} ]]; then\n    echo -e \"${LYELLOW} Update Linux LOCAL DNS SUFFIX [Enter to keep: ${SERVER_NAME}.${DOMAIN_SUFFIX}]${LGREEN}\"\n    read -p \"              Complete this local domain suffix: $SERVER_NAME.\" LOCAL_DOMAIN\n    # If hit enter making no LOCAL_DOMAIN name change, assume the existing domain suffix as current\n    if [[ \"${LOCAL_DOMAIN}\" = \"\" ]]; then\n        LOCAL_DOMAIN=$DOMAIN_SUFFIX\n    fi\n    echo\n    # A LOCAL_DOMAIN value was derived via the prompt\n    # Remove any old localhost & resolv file values & update these with the new LOCAL_DOMAIN value\n\t$(sudo systemctl restart systemd-hostnamed &>/dev/null &) &>/dev/null\n\tsleep 1\n    sudo sed -i \"/${DEFAULT_IP}/d\" /etc/hosts\n    sudo sed -i '/domain/d' /etc/resolv.conf\n    sudo sed -i '/search/d' /etc/resolv.conf\n    # Refresh the /etc/hosts file with the server name & new local domain value\n    echo ''${DEFAULT_IP}'\t'${SERVER_NAME}.${LOCAL_DOMAIN} ${SERVER_NAME}'' | sudo tee -a /etc/hosts &>>${INSTALL_LOG}\n    # Refresh /etc/resolv.conf with new domain & search suffix values\n    echo 'domain\t'${LOCAL_DOMAIN}'' | sudo tee -a /etc/resolv.conf &>>${INSTALL_LOG}\n    echo 'search\t'${LOCAL_DOMAIN}'' | sudo tee -a /etc/resolv.conf &>>${INSTALL_LOG}\n    $(sudo systemctl restart systemd-hostnamed &>/dev/null &) &>/dev/null\nelse\n    echo\n    # A LOCAL_DOMIN value was derived from a pre-set silent install option.\n    # Remove any old localhost & resolv file values & update these with the new LOCAL_DOMAIN value\n\t$(sudo systemctl restart systemd-hostnamed &>/dev/null &) &>/dev/null\n\tsleep 1\n    sudo sed -i \"/${DEFAULT_IP}/d\" /etc/hosts\n    sudo sed -i '/domain/d' /etc/resolv.conf\n    sudo sed -i '/search/d' /etc/resolv.conf\n    # Refresh the /etc/hosts file with the server name & new local domain value\n    echo ''${DEFAULT_IP}'\t'${SERVER_NAME}.${LOCAL_DOMAIN} ${SERVER_NAME}'' | sudo tee -a /etc/hosts &>>${INSTALL_LOG}\n    # Refresh /etc/resolv.conf with new domain & search suffix values\n    echo 'domain\t'${LOCAL_DOMAIN}'' | sudo tee -a /etc/resolv.conf &>>${INSTALL_LOG}\n    echo 'search\t'${LOCAL_DOMAIN}'' | sudo tee -a /etc/resolv.conf &>>${INSTALL_LOG}\n    $(sudo systemctl restart systemd-hostnamed &>/dev/null &) &>/dev/null\nfi\n\n# Now that $SERVER_NAME and $LOCAL_DOMAIN values are updated and refreshed, both values are merged to build\n# a local FQDN value (this is later used for the default reverse proxy site name.)\nDEFAULT_FQDN=$SERVER_NAME.$LOCAL_DOMAIN\n\n# Default RDP share and host labels will now use the updated $SERVER_NAME value as default (if not otherwise specified in silent setup options).\nif [[ -z ${RDP_SHARE_HOST} ]]; then\n    RDP_SHARE_HOST=$SERVER_NAME\nfi\n\n# Prompt to install MySQL\necho -e \"${LGREEN}MySQL setup options:${GREY}\"\nif [[ -z ${INSTALL_MYSQL} ]]; then\n    echo -e -n \"SQL: Install MySQL locally? (For a REMOTE MySQL server select 'n') [y/n] [default y]: ${GREY}\"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Nn]$ ]]; then\n        INSTALL_MYSQL=false\n    else\n        INSTALL_MYSQL=true\n    fi\nfi\n\n# Prompt to apply the Mysql secure installation locally\nif [[ -z ${SECURE_MYSQL} ]] && [[ \"${INSTALL_MYSQL}\" = true ]]; then\n    echo -e -n \"${GREY}SQL: Apply MySQL secure installation settings to LOCAL db? [y/n] [default y]: ${GREY}\"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Nn]$ ]]; then\n        SECURE_MYSQL=false\n    else\n        SECURE_MYSQL=true\n    fi\nfi\n\n# Prompt for additional MYSQL settings and values\nif [[ \"${INSTALL_MYSQL}\" = false ]]; then\n    [[ -z \"${MYSQL_HOST}\" ]] &&\n        read -p \"SQL: Enter remote MySQL server hostname or IP: \" MYSQL_HOST\n    [[ -z \"${MYSQL_PORT}\" ]] &&\n        read -p \"SQL: Enter remote MySQL server port [3306]: \" MYSQL_PORT\n    [[ -z \"${GUAC_DB}\" ]] &&\n        read -p \"SQL: Enter remote Guacamole database name [guacamole_db]: \" GUAC_DB\n    [[ -z \"${GUAC_USER}\" ]] &&\n        read -p \"SQL: Enter remote Guacamole user name [guacamole_user]: \" GUAC_USER\nfi\n# Checking if a mysql host given, if not set a default\nif [[ -z \"${MYSQL_HOST}\" ]]; then\n    MYSQL_HOST=\"localhost\"\nfi\n# Checking if a mysql port given, if not set a default\nif [[ -z \"${MYSQL_PORT}\" ]]; then\n    MYSQL_PORT=\"3306\"\nfi\n# Checking if a database name given, if not set a default\nif [[ -z \"${GUAC_DB}\" ]]; then\n    GUAC_DB=\"guacamole_db\"\nfi\n# Checking if a mysql user given, if not set a default\nif [[ -z \"${GUAC_USER}\" ]]; then\n    GUAC_USER=\"guacamole_user\"\nfi\n\n# Prompt for MySQL root password, confirm correct password entry and prevent blank passwords. No root pw needed for remote instances.\nif [[ -z \"${MYSQL_ROOT_PWD}\" ]] && [[ \"${INSTALL_MYSQL}\" = true ]]; then\n    while true; do\n        read -s -p \"SQL: Enter ${MYSQL_HOST}'s MySQL ROOT password: \" MYSQL_ROOT_PWD\n        echo\n        read -s -p \"SQL: Confirm ${MYSQL_HOST}'s MySQL ROOT password: \" PROMPT2\n        echo\n        [[ \"${MYSQL_ROOT_PWD}\" = \"${PROMPT2}\" ]] && [[ \"${MYSQL_ROOT_PWD}\" != \"\" ]] && [[ \"${PROMPT2}\" != \"\" ]] && break\n        echo -e \"${LRED}Passwords don't match or can't be null. Please try again.${GREY}\" 1>&2\n    done\nfi\n\n# Prompt for Guacamole User password, confirm correct password entry and prevent blank passwords\nif [[ -z \"${GUAC_PWD}\" ]]; then\n    while true; do\n        read -s -p \"SQL: Enter ${MYSQL_HOST}'s MySQL ${GUAC_USER} password: \" GUAC_PWD\n        echo\n        read -s -p \"SQL: Confirm ${MYSQL_HOST}'s MySQL ${GUAC_USER} password: \" PROMPT2\n        echo\n        [[ \"${GUAC_PWD}\" = \"${PROMPT2}\" ]] && [[ \"${GUAC_PWD}\" != \"\" ]] && [[ \"${PROMPT2}\" != \"\" ]] && break\n        echo -e \"${LRED}Passwords don't match or can't be null. Please try again.${GREY}\" 1>&2\n    done\nfi\n\n# Prompt for preferred backup notification email address\nif [[ -z ${BACKUP_EMAIL} ]]; then\n    while true; do\n        read -p \"SQL: Enter email address for SQL backup messages [Enter to skip]: \" BACKUP_EMAIL\n        [[ \"${BACKUP_EMAIL}\" = \"\" ]] || [[ \"${BACKUP_EMAIL}\" != \"\" ]] && break\n        # Rather than allow a blank value, un-comment to alternately force user to enter an explicit value instead\n        # [[ \"${BACKUP_EMAIL}\" != \"\" ]] && break\n        # echo -e \"${LRED}You must enter an email address. Please try again.${GREY}\" 1>&2\n    done\nfi\n# If no backup notification email address is given, provide a non blank default value\nif [[ -z ${BACKUP_EMAIL} ]]; then\n    BACKUP_EMAIL=\"backup-email@yourdomain.com\"\nfi\n\necho\n# Prompt to install TOTP MFA\necho -e \"${LGREEN}Guacamole authentication extension options:${GREY}\"\nif [[ -z \"${INSTALL_TOTP}\" ]] && [[ \"${INSTALL_DUO}\" != true ]]; then\n    echo -e -n \"AUTH: Install TOTP? (choose 'n' if you want Duo) [y/n]? [default n]: \"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n        INSTALL_TOTP=true\n        INSTALL_DUO=false\n    else\n        INSTALL_TOTP=false\n    fi\nfi\n\n# Prompt to install Duo MFA\nif [[ -z \"${INSTALL_DUO}\" ]] && [[ \"${INSTALL_TOTP}\" != true ]]; then\n    echo -e -n \"${GREY}AUTH: Install Duo? [y/n] [default n]: \"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n        INSTALL_DUO=true\n        INSTALL_TOTP=false\n    else\n        INSTALL_DUO=false\n    fi\nfi\n\n# We can't install TOTP and Duo at the same time (option not supported by Guacamole)\nif [[ \"${INSTALL_TOTP}\" = true ]] && [[ \"${INSTALL_DUO}\" = true ]]; then\n    echo -e \"${LRED}GUAC MFA: TOTP and Duo cannot be installed at the same time.${GREY}\" 1>&2\n    exit 1\nfi\n\n# Prompt to install Duo MFA\nif [[ -z \"${INSTALL_LDAP}\" ]]; then\n    echo -e -n \"${GREY}AUTH: Install LDAP? [y/n] [default n]: \"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n        INSTALL_LDAP=true\n    else\n        INSTALL_LDAP=false\n    fi\nfi\n\necho\n# Prompt to install the Quick Connect feature (some higher security use cases may not want this)\necho -e \"${LGREEN}Guacamole console optional extras:${GREY}\"\nif [[ -z \"${INSTALL_QCONNECT}\" ]]; then\n    echo -e -n \"${GREY}EXTRAS: Install Quick Connect feature? [y/n] [default n]: \"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n        INSTALL_QCONNECT=true\n    else\n        INSTALL_QCONNECT=false\n    fi\nfi\n\n# Prompt to install the History Recorded Storage feature\nif [[ -z \"${INSTALL_HISTREC}\" ]]; then\n    echo -e -n \"${GREY}EXTRAS: Install History Recorded Storage feature [y/n] [default n]: \"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n        INSTALL_HISTREC=true\n    else\n        INSTALL_HISTREC=false\n    fi\nfi\n\nHISTREC_PATH_DEFAULT=/var/lib/guacamole/recordings # Apache default\nif [[ -z ${HISTREC_PATH} ]] && [[ \"${INSTALL_HISTREC}\" = true ]]; then\n    while true; do\n        read -p \"EXTRAS: Enter recorded storage path [Enter for default ${HISTREC_PATH_DEFAULT}]: \" HISTREC_PATH\n        [[ \"${HISTREC_PATH}\" = \"\" ]] || [[ \"${HISTREC_PATH}\" != \"\" ]] && break\n    done\nfi\n\n# If no custom path is given, assume the Apache default path on hitting enter\nif [[ -z \"${HISTREC_PATH}\" ]]; then\n    HISTREC_PATH=\"${HISTREC_PATH_DEFAULT}\"\nfi\n\necho\n# Prompt for Guacamole front end reverse proxy option\necho -e \"${LGREEN}Reverse Proxy & front end options:${GREY}\"\nif [[ -z ${INSTALL_NGINX} ]]; then\n    echo -e -n \"FRONT END: Protect Guacamole behind Nginx reverse proxy [y/n]? [default n]: \"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n        INSTALL_NGINX=true\n        GUAC_URL_REDIR=false\n    else\n        INSTALL_NGINX=false\n    fi\nfi\n\n# Prompt to redirect http://root:8080 to http://root:8080/guacamole if not installing reverse proxy\nif [[ -z ${GUAC_URL_REDIR} ]] && [[ \"${INSTALL_NGINX}\" = false ]]; then\n    echo -e -n \"FRONT END: Redirect http://domain.root:8080 to /guacamole (Warning: redirect may break DUO) [y/n]? [default n]: \"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n        GUAC_URL_REDIR=true\n    else\n        GUAC_URL_REDIR=false\n    fi\nfi\n\n# We must assign a DNS name for the new proxy site\nif [[ -z ${PROXY_SITE} ]] && [[ \"${INSTALL_NGINX}\" = true ]]; then\n    while true; do\n        read -p \"FRONT END: Enter proxy LOCAL DNS name? [Enter to use ${DEFAULT_FQDN}]: \" PROXY_SITE\n        [[ \"${PROXY_SITE}\" = \"\" ]] || [[ \"${PROXY_SITE}\" != \"\" ]] && break\n        # Rather than allow the default value below, un-comment to alternately force user to enter an explicit name instead\n        # [[ \"${PROXY_SITE}\" != \"\" ]] && break\n        # echo -e \"${LRED}You must enter a proxy site DNS name. Please try again.${GREY}\" 1>&2\n    done\nfi\n\n# If no proxy site dns name is given, lets assume the default FQDN is the proxy site name\nif [[ -z \"${PROXY_SITE}\" ]]; then\n    PROXY_SITE=\"${DEFAULT_FQDN}\"\nfi\n\n# Prompt for self signed TLS reverse proxy option\nif [[ -z ${SELF_SIGN} ]] && [[ \"${INSTALL_NGINX}\" = true ]]; then\n    # Prompt the user to see if they would like to install self signed TLS support for Nginx, default of no\n    echo -e -n \"FRONT END: Add self signed TLS support to Nginx? [y/n]? (choose 'n' for Let's Encrypt)[default n]: \"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n        SELF_SIGN=true\n        LETS_ENCRYPT=false\n    else\n        SELF_SIGN=false\n    fi\nfi\n\n# Prompt to enter a self sign TLS certificate expiry\nif [[ -z \"${CERT_DAYS}\" ]] && [[ \"${SELF_SIGN}\" = true ]]; then\n    while true; do\n    read -p \"FRONT END: Enter number of days till TLS certificates will expire [Enter for ${CERT_DAYS}]: \" CERT_DAYS\n        [[ \"${CERT_DAYS}\" = \"\" ]] || [[ \"${CERT_DAYS}\" != \"\" ]] && break\n    done\nfi\n# If no self sign TLS certificate expiry given, lets assume a generous 10 year default certificate expiry\nif [[ -z \"${CERT_DAYS}\" ]]; then\n    CERT_DAYS=\"3650\"\nfi\n\n# Prompt for Let's Encrypt TLS reverse proxy configuration option\nif [[ -z ${LETS_ENCRYPT} ]] && [[ \"${INSTALL_NGINX}\" = true ]] && [[ \"${SELF_SIGN}\" = false ]]; then\n    echo -e -n \"FRONT END: Add Let's Encrypt TLS support to Nginx reverse proxy [y/n] [default n]: ${GREY}\"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n        LETS_ENCRYPT=true\n        SELF_SIGN=false\n    else\n        LETS_ENCRYPT=false\n    fi\nfi\n\n# Prompt for Let's Encrypt public dns name\nif [[ -z ${LE_DNS_NAME} ]] && [[ \"${LETS_ENCRYPT}\" = true ]] && [[ \"${SELF_SIGN}\" = false ]]; then\n    while true; do\n        read -p \"FRONT END: Enter the PUBLIC FQDN for your proxy site : \" LE_DNS_NAME\n        [[ \"${LE_DNS_NAME}\" != \"\" ]] && break\n        echo -e \"${LRED}You must enter a public DNS name. Please try again.${GREY}\" 1>&2\n    done\nfi\n\n# Prompt for Let's Encrypt admin email\nif [[ -z ${LE_EMAIL} ]] && [[ \"${LETS_ENCRYPT}\" = true ]] && [[ \"${SELF_SIGN}\" = false ]]; then\n    while true; do\n        read -p \"FRONT END: Enter the email address for Let's Encrypt notifications : \" LE_EMAIL\n        [[ \"${LE_EMAIL}\" != \"\" ]] && break\n        echo -e \"${LRED}You must enter an email address. Please try again.${GREY}\" 1>&2\n    done\nfi\n\n#######################################################################################################################\n# Start global setup actions  #########################################################################################\n#######################################################################################################################\n\nclear\necho\necho -e \"${GREYB}Guacamole ${GUAC_VERSION} Auto Installer.\"\necho -e \"              ${LGREEN}Powered by Itiligent\"\necho\necho\n\necho -e \"${LGREEN}Beginning Guacamole setup...${GREY}\"\necho\n\necho -e \"${GREY}Synchronising the install script suite with the selected installation options...\"\n# Sync the various manual config scripts with the relevant variables selected at install\n# This way scripts can be run at a later time without modification to match the original install\nsed -i \"s|MYSQL_HOST=|MYSQL_HOST='${MYSQL_HOST}'|g\" $DOWNLOAD_DIR/backup-guacamole.sh\nsed -i \"s|MYSQL_PORT=|MYSQL_PORT='${MYSQL_PORT}'|g\" $DOWNLOAD_DIR/backup-guacamole.sh\nsed -i \"s|GUAC_USER=|GUAC_USER='${GUAC_USER}'|g\" $DOWNLOAD_DIR/backup-guacamole.sh\nsed -i \"s|GUAC_PWD=|GUAC_PWD='${GUAC_PWD}'|g\" $DOWNLOAD_DIR/backup-guacamole.sh\nsed -i \"s|GUAC_DB=|GUAC_DB='${GUAC_DB}'|g\" $DOWNLOAD_DIR/backup-guacamole.sh\nsed -i \"s|DB_BACKUP_DIR=|DB_BACKUP_DIR='${DB_BACKUP_DIR}'|g\" $DOWNLOAD_DIR/backup-guacamole.sh\nsed -i \"s|BACKUP_EMAIL=|BACKUP_EMAIL='${BACKUP_EMAIL}'|g\" $DOWNLOAD_DIR/backup-guacamole.sh\nsed -i \"s|BACKUP_RETENTION=|BACKUP_RETENTION='${BACKUP_RETENTION}'|g\" $DOWNLOAD_DIR/backup-guacamole.sh\n\nsed -i \"s|CERT_COUNTRY=|CERT_COUNTRY='${CERT_COUNTRY}'|g\" $DOWNLOAD_DIR/add-tls-guac-daemon.sh\nsed -i \"s|CERT_STATE=|CERT_STATE='${CERT_STATE}'|g\" $DOWNLOAD_DIR/add-tls-guac-daemon.sh\nsed -i \"s|CERT_LOCATION=|CERT_LOCATION='${CERT_LOCATION=}'|g\" $DOWNLOAD_DIR/add-tls-guac-daemon.sh\nsed -i \"s|CERT_ORG=|CERT_ORG='${CERT_ORG}'|g\" $DOWNLOAD_DIR/add-tls-guac-daemon.sh\nsed -i \"s|CERT_OU=|CERT_OU='${CERT_OU}'|g\" $DOWNLOAD_DIR/add-tls-guac-daemon.sh\nsed -i \"s|CERT_DAYS=|CERT_DAYS='${CERT_DAYS}'|g\" $DOWNLOAD_DIR/add-tls-guac-daemon.sh\n\nsed -i \"s|INSTALL_MYSQL=|INSTALL_MYSQL='${INSTALL_MYSQL}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\nsed -i \"s|MYSQL_HOST=|MYSQL_HOST='${MYSQL_HOST}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\nsed -i \"s|MYSQL_PORT=|MYSQL_PORT='${MYSQL_PORT}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\nsed -i \"s|GUAC_DB=|GUAC_DB='${GUAC_DB}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\nsed -i \"s|MYSQL_ROOT_PWD=|MYSQL_ROOT_PWD='${MYSQL_ROOT_PWD}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\nsed -i \"s|GUAC_USER=|GUAC_USER='${GUAC_USER}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\nsed -i \"s|GUAC_PWD=|GUAC_PWD='${GUAC_PWD}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\nsed -i \"s|GUACD_ACCOUNT=|GUACD_ACCOUNT='${GUACD_ACCOUNT}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\n\nsed -i \"s|RDP_SHARE_HOST=|RDP_SHARE_HOST='${RDP_SHARE_HOST}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\nsed -i \"s|RDP_SHARE_LABEL=|RDP_SHARE_LABEL='${RDP_SHARE_LABEL}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\nsed -i \"s|RDP_PRINTER_LABEL=|RDP_PRINTER_LABEL='${RDP_PRINTER_LABEL}'|g\" $DOWNLOAD_DIR/upgrade-guacamole.sh\n\nsed -i \"s|PROXY_SITE=|PROXY_SITE='${PROXY_SITE}'|g\" $DOWNLOAD_DIR/3-install-nginx.sh\nsed -i \"s|INSTALL_LOG=|INSTALL_LOG='${INSTALL_LOG}'|g\" $DOWNLOAD_DIR/3-install-nginx.sh\nsed -i \"s|GUAC_URL=|GUAC_URL='${GUAC_URL}'|g\" $DOWNLOAD_DIR/3-install-nginx.sh\n\nsed -i \"s|DOWNLOAD_DIR=|DOWNLOAD_DIR='${DOWNLOAD_DIR}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|PROXY_SITE=|PROXY_SITE='${PROXY_SITE}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|CERT_COUNTRY=|CERT_COUNTRY='${CERT_COUNTRY}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|CERT_STATE=|CERT_STATE='${CERT_STATE}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|CERT_LOCATION=|CERT_LOCATION='${CERT_LOCATION=}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|CERT_ORG=|CERT_ORG='${CERT_ORG}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|CERT_OU=|CERT_OU='${CERT_OU}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|CERT_DAYS=|CERT_DAYS='${CERT_DAYS}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|GUAC_URL=|GUAC_URL='${GUAC_URL}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|INSTALL_LOG=|INSTALL_LOG='${INSTALL_LOG}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|DEFAULT_IP=|DEFAULT_IP='${DEFAULT_IP}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\nsed -i \"s|RSA_KEYLENGTH=|RSA_KEYLENGTH='${RSA_KEYLENGTH}'|g\" $DOWNLOAD_DIR/4a-install-tls-self-signed-nginx.sh\n\nsed -i \"s|DOWNLOAD_DIR=|DOWNLOAD_DIR='${DOWNLOAD_DIR}'|g\" $DOWNLOAD_DIR/4b-install-tls-letsencrypt-nginx.sh\nsed -i \"s|PROXY_SITE=|PROXY_SITE='${PROXY_SITE}'|g\" $DOWNLOAD_DIR/4b-install-tls-letsencrypt-nginx.sh\nsed -i \"s|GUAC_URL=|GUAC_URL='${GUAC_URL}'|g\" $DOWNLOAD_DIR/4b-install-tls-letsencrypt-nginx.sh\nsed -i \"s|LE_DNS_NAME=|LE_DNS_NAME='${LE_DNS_NAME}'|g\" $DOWNLOAD_DIR/4b-install-tls-letsencrypt-nginx.sh\nsed -i \"s|LE_EMAIL=|LE_EMAIL='${LE_EMAIL}'|g\" $DOWNLOAD_DIR/4b-install-tls-letsencrypt-nginx.sh\nsed -i \"s|INSTALL_LOG=|INSTALL_LOG='${INSTALL_LOG}'|g\" $DOWNLOAD_DIR/4b-install-tls-letsencrypt-nginx.sh\n\nsed -i \"s|LOCAL_DOMAIN=|LOCAL_DOMAIN='${LOCAL_DOMAIN}'|g\" $DOWNLOAD_DIR/add-smtp-relay-o365.sh\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Export the required variables for use by child install scripts\nexport DOWNLOAD_DIR=\"${DOWNLOAD_DIR}\"\nexport GUAC_VERSION=$GUAC_VERSION\nexport GUAC_SOURCE_LINK=$GUAC_SOURCE_LINK\nexport ID=$ID\nexport VERSION_ID=$VERSION_ID\nexport FREERDP=$FREERDP\nexport VERSION_CODENAME=$VERSION_CODENAME\nexport MYSQLJCON=$MYSQLJCON\nexport MYSQLJCON_SOURCE_LINK=$MYSQLJCON_SOURCE_LINK\nexport MYSQL_VERSION=$MYSQL_VERSION\nexport MARIADB_SOURCE_LINK=$MARIADB_SOURCE_LINK\nexport MYSQLSRV=$MYSQLSRV\nexport MYSQLCLIENT=$MYSQLCLIENT\nexport DB_CMD=$DB_CMD\nexport TOMCAT_VERSION=$TOMCAT_VERSION\nexport GUAC_URL=$GUAC_URL\nexport INSTALL_LOG=$INSTALL_LOG\nexport JPEGTURBO=$JPEGTURBO\nexport LIBPNG=$LIBPNG\nexport INSTALL_MYSQL=$INSTALL_MYSQL\nexport SECURE_MYSQL=$SECURE_MYSQL\nexport MYSQL_HOST=$MYSQL_HOST\nexport MYSQL_PORT=$MYSQL_PORT\nexport GUAC_DB=$GUAC_DB\nexport GUAC_USER=$GUAC_USER\nexport MYSQL_ROOT_PWD=\"${MYSQL_ROOT_PWD}\"\nexport GUAC_PWD=\"${GUAC_PWD}\"\nexport GUACD_ACCOUNT=$GUACD_ACCOUNT\nexport DB_TZ=\"${DB_TZ}\"\nexport INSTALL_TOTP=$INSTALL_TOTP\nexport INSTALL_DUO=$INSTALL_DUO\nexport INSTALL_LDAP=$INSTALL_LDAP\nexport INSTALL_QCONNECT=$INSTALL_QCONNECT\nexport INSTALL_HISTREC=$INSTALL_HISTREC\nexport HISTREC_PATH=\"${HISTREC_PATH}\"\nexport GUAC_URL_REDIR=$GUAC_URL_REDIR\nexport INSTALL_NGINX=$INSTALL_NGINX\nexport PROXY_SITE=$PROXY_SITE\nexport RSA_KEYLENGTH=$RSA_KEYLENGTH\nexport DEFAULT_IP=$DEFAULT_IP\nexport CERT_COUNTRY=$CERT_COUNTRY\nexport CERT_STATE=\"${CERT_STATE}\"\nexport CERT_LOCATION=\"${CERT_LOCATION}\"\nexport CERT_ORG=\"${CERT_ORG}\"\nexport CERT_OU=\"${CERT_OU}\"\nexport CERT_DAYS=$CERT_DAYS\nexport LE_DNS_NAME=$LE_DNS_NAME\nexport LE_EMAIL=$LE_EMAIL\nexport BACKUP_EMAIL=$BACKUP_EMAIL\nexport RDP_SHARE_HOST=\"${RDP_SHARE_HOST}\"\nexport RDP_SHARE_LABEL=\"${RDP_SHARE_LABEL}\"\nexport RDP_PRINTER_LABEL=\"${RDP_PRINTER_LABEL}\"\nexport LOCAL_DOMAIN=$LOCAL_DOMAIN\nexport DOMAIN_SUFFIX=$DOMAIN_SUFFIX\nexport CRON_DENY_FILE=$CRON_DENY_FILE\n\n# Run the Guacamole install script (with all exported variables from this current shell)\nsudo -E ./2-install-guacamole.sh\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}2-install-guacamole.sh FAILED. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelif [[ \"${GUAC_URL_REDIR}\" = true ]]; then\n    echo -e \"${LGREEN}Guacamole install complete\\nhttp://${PROXY_SITE}:8080 - login user/pass: guacadmin/guacadmin\\n${LYELLOW}***Be sure to change the password***${GREY}\"\nelse\n    echo -e \"${LGREEN}Guacamole install complete\\nhttp://${PROXY_SITE}:8080/guacamole - login user/pass: guacadmin/guacadmin\\n${LYELLOW}***Be sure to change the password***${GREY}\"\nfi\n\n# Add a Guacamole database backup (Mon-Fri 12:00am) into the current user's cron\nmv $DOWNLOAD_DIR/backup-guacamole.sh $DB_BACKUP_DIR\ncrontab -l >cron_1\n# Remove any pre-existing entry just in case\nsed -i '/# backup guacamole/d' cron_1\n# Create the backup job\necho \"0 0 * * 1-5 ${DB_BACKUP_DIR}/backup-guacamole.sh # backup guacamole\" >>cron_1\n# Overwrite the old cron settings and cleanup\ncrontab cron_1\nrm cron_1\n\n#######################################################################################################################\n# Start optional setup actions   ######################################################################################\n#######################################################################################################################\n\n# Install Nginx reverse proxy front end to Guacamole if option is selected (with all exported variables from this current shell)\nif [[ \"${INSTALL_NGINX}\" = true ]]; then\n    sudo -E ./3-install-nginx.sh\n    echo -e \"${LGREEN}Nginx install complete\\nhttp://${PROXY_SITE} - admin login: guacadmin pass: guacadmin\\n${LYELLOW}***Be sure to change the password***${GREY}\"\nfi\n\n# Apply self signed TLS certificates to Nginx reverse proxy if option is selected (with all exported variables from this current shell)\nif [[ \"${INSTALL_NGINX}\" = true ]] && [[ \"${SELF_SIGN}\" = true ]] && [[ \"${LETS_ENCRYPT}\" != true ]]; then\n    sudo -E ./4a-install-tls-self-signed-nginx.sh ${PROXY_SITE} ${CERT_DAYS} ${DEFAULT_IP} | tee -a ${INSTALL_LOG} # Logged to capture client cert import instructions\n    echo -e \"${LGREEN}Self signed certificate configured for Nginx \\n${LYELLOW}https:${LGREEN}//${PROXY_SITE}  - login user/pass: guacadmin/guacadmin\\n${LYELLOW}***Be sure to change the password***${GREY}\"\nfi\n\n# Apply Let's Encrypt TLS certificates to Nginx reverse proxy if option is selected (with all exported variables from this current shell)\nif [[ \"${INSTALL_NGINX}\" = true ]] && [[ \"${LETS_ENCRYPT}\" = true ]] && [[ \"${SELF_SIGN}\" != true ]]; then\n    sudo -E ./4b-install-tls-letsencrypt-nginx.sh\n    echo -e \"${LGREEN}Let's Encrypt TLS configured for Nginx \\n${LYELLOW}https:${LGREEN}//${LE_DNS_NAME}  - login user/pass: guacadmin/guacadmin\\n${LYELLOW}***Be sure to change the password***${GREY}\"\nfi\n\n# Duo Settings reminder - If Duo is selected you can't login to Guacamole until this extension is fully configured\nif [[ $INSTALL_DUO == \"true\" ]]; then\n    echo\n    echo -e \"${LYELLOW}Reminder: Duo requires extra account specific info configured in the\\n/etc/guacamole/guacamole.properties file before you can log in to Guacamole.\"\n    echo -e \"See https://guacamole.apache.org/doc/gug/duo-auth.html\"\nfi\n\n# LDAP Settings reminder, LDAP auth is not functional until the config is complete\nif [[ $INSTALL_LDAP == \"true\" ]]; then\n    echo\n    echo -e \"${LYELLOW}Reminder: LDAP requires that your LDAP directory configuration match the exact format\\nadded to the /etc/guacamole/guacamole.properties file before LDAP auth will be active.\"\n    echo -e \"See https://guacamole.apache.org/doc/gug/ldap-auth.html\"\nfi\n\n# Tidy up\necho\necho -e \"${GREY}Removing build-essential package & cleaning up...\"\nmv $USER_HOME_DIR/1-setup.sh $DOWNLOAD_DIR\nsudo apt remove -y build-essential &>>${INSTALL_LOG} # Lets not leave build resources installed on a secure system\nsudo apt-get -y autoremove &>>${INSTALL_LOG}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Done\nprintf \"${LGREEN}Guacamole ${GUAC_VERSION} install complete! \\n${NC}\"\necho -e ${NC}\n"
  },
  {
    "path": "2-install-guacamole.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Guacamole main build script\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\n\n# Update everything but don't do the annoying prompts during apt installs\necho -e \"${GREY}Updating base Linux OS...\"\nexport DEBIAN_FRONTEND=noninteractive\nspinner() {\n  local pid=$1\n  local delay=0.15\n  local spinstr='|/-\\'\n  tput civis\n  while ps -p $pid > /dev/null; do\n    for i in $(seq 0 3); do\n      tput sc\n      printf \"[%c]\" \"${spinstr:$i:1}\"\n      tput rc\n      sleep $delay\n    done\n  done\n  tput cnorm\n  printf \"       \"\n  tput rc\n}\n# We already ran apt-get update from the 1st setup script, now we begin to upgrade packages\napt-get upgrade -qq -y &>>${INSTALL_LOG} &\ncommand_pid=$!\nspinner $command_pid\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Pre-seed MySQL root password values for Linux Distro default packages only\nif [[ \"${INSTALL_MYSQL}\" = true ]] && [[ -z \"${MYSQL_VERSION}\" ]]; then\n    debconf-set-selections <<<\"mysql-server mysql-server/root_password password ${MYSQL_ROOT_PWD}\"\n    debconf-set-selections <<<\"mysql-server mysql-server/root_password_again password ${MYSQL_ROOT_PWD}\"\nfi\n\n# Install official MariaDB repo and MariaDB version if a specific version number was provided.\nif [[ -n \"${MYSQL_VERSION}\" ]]; then\n    echo -e \"${GREY}Adding the official MariaDB repository and installing version ${MYSQL_VERSION}...\"\n    # Add the Official MariaDB repo.\n    apt-get -qq -y install curl gnupg2 &>>${INSTALL_LOG}\n    curl -LsS -O ${MARIADB_SOURCE_LINK} &>>${INSTALL_LOG}\n    bash mariadb_repo_setup --mariadb-server-version=$MYSQL_VERSION &>>${INSTALL_LOG}\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Select the appropriate MySQL client or server packages, and don't clobber any pre-existing database installation accidentally\nif [[ \"${INSTALL_MYSQL}\" = true ]]; then\n    MYSQLPKG=\"${MYSQLSRV}\"\nelif [ -x \"$(command -v ${DB_CMD})\" ]; then\n     MYSQLPKG=\"\"\nelse\n    MYSQLPKG=\"${MYSQLCLIENT}\"\nfi\n\n# Install Guacamole build dependencies (pwgen needed for duo config only, expect is auto removed after install)\necho -e \"${GREY}Installing dependencies required for building Guacamole, this might take a few minutes...\"\nspinner() {\n  local pid=$1\n  local delay=0.15\n  local spinstr='|/-\\'\n  tput civis\n  while ps -p $pid > /dev/null; do\n    for i in $(seq 0 3); do\n      tput sc\n      printf \"[%c]\" \"${spinstr:$i:1}\"\n      tput rc\n      sleep $delay\n    done\n  done\n  tput cnorm\n  printf \"       \"\n  tput rc\n}\napt-get -qq -y install ${MYSQLPKG} ${TOMCAT_VERSION} ${JPEGTURBO} ${LIBPNG} ${FREERDP} ufw pwgen expect \\\n    build-essential libcairo2-dev libtool-bin uuid-dev libavcodec-dev libavformat-dev libavutil-dev \\\n    libswscale-dev libpango1.0-dev libssh2-1-dev libtelnet-dev libvncserver-dev libwebsockets-dev \\\n    libpulse-dev libssl-dev libvorbis-dev libwebp-dev ghostscript &>>${INSTALL_LOG} &\ncommand_pid=$!\nspinner $command_pid\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Install Postfix with default settings for smtp email relay\necho -e \"${GREY}Installing Postfix MTA for backup email notifications and alerts, see separate SMTP relay configuration script...\"\nspinner() {\n  local pid=$1\n  local delay=0.15\n  local spinstr='|/-\\'\n  tput civis\n  while ps -p $pid > /dev/null; do\n    for i in $(seq 0 3); do\n      tput sc\n      printf \"[%c]\" \"${spinstr:$i:1}\"\n      tput rc\n      sleep $delay\n    done\n  done\n  tput cnorm\n  printf \"       \"\n  tput rc\n}\nDEBIAN_FRONTEND=\"noninteractive\" apt-get install postfix mailutils -qq -y &>>${INSTALL_LOG} &\ncommand_pid=$!\nspinner $command_pid\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    systemctl restart postfix\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Download Guacamole Server\necho -e \"${GREY}Downloading Guacamole source files...\"\nwget -q --show-progress -O guacamole-server-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/source/guacamole-server-${GUAC_VERSION}.tar.gz\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed to download guacamole-server-${GUAC_VERSION}.tar.gz\" 1>&2\n    echo -e \"${GUAC_SOURCE_LINK}/source/guacamole-server-${GUAC_VERSION}.tar.gz${GREY}\"\n    exit 1\nelse\n    tar -xzf guacamole-server-${GUAC_VERSION}.tar.gz\n    echo -e \"${LGREEN}Downloaded guacamole-server-${GUAC_VERSION}.tar.gz${GREY}\"\nfi\n\n# Download Guacamole Client\nwget -q --show-progress -O guacamole-${GUAC_VERSION}.war ${GUAC_SOURCE_LINK}/binary/guacamole-${GUAC_VERSION}.war\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed to download guacamole-${GUAC_VERSION}.war\" 1>&2\n    echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-${GUAC_VERSION}.war${GREY}\"\n    exit 1\nelse\n    echo -e \"${LGREEN}Downloaded guacamole-${GUAC_VERSION}.war${GREY}\"\nfi\n\n# Download MySQL connector/j\nwget -q --show-progress -O mysql-connector-j-${MYSQLJCON}.tar.gz ${MYSQLJCON_SOURCE_LINK}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed to download mysql-connector-j-${MYSQLJCON}.tar.gz\" 1>&2\n    echo -e \"${MYSQLJCON_SOURCE_LINK}${GREY}\"\n    exit 1\nelse\n    tar -xzf mysql-connector-j-${MYSQLJCON}.tar.gz\n    echo -e \"${LGREEN}Downloaded mysql-connector-j-${MYSQLJCON}.tar.gz${GREY}\"\nfi\n\n# Download Guacamole database auth extension\nwget -q --show-progress -O guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed to download guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz\" 1>&2\n    echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz\"\n    exit 1\nelse\n    tar -xzf guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz\n    echo -e \"${LGREEN}Downloaded guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz${GREY}\"\nfi\n\n# Download TOTP auth extension\nif [[ \"${INSTALL_TOTP}\" = true ]]; then\n    wget -q --show-progress -O guacamole-auth-totp-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-totp-${GUAC_VERSION}.tar.gz\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed to download guacamole-auth-totp-${GUAC_VERSION}.tar.gz\" 1>&2\n        echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-totp-${GUAC_VERSION}.tar.gz\"\n        exit 1\n    else\n        tar -xzf guacamole-auth-totp-${GUAC_VERSION}.tar.gz\n        echo -e \"${LGREEN}Downloaded guacamole-auth-totp-${GUAC_VERSION}.tar.gz${GREY}\"\n    fi\nfi\n\n# Download DUO auth extension\nif [[ \"${INSTALL_DUO}\" = true ]]; then\n    wget -q --show-progress -O guacamole-auth-duo-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-duo-${GUAC_VERSION}.tar.gz\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed to download guacamole-auth-duo-${GUAC_VERSION}.tar.gz\" 1>&2\n        echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-duo-${GUAC_VERSION}.tar.gz\"\n        exit 1\n    else\n        tar -xzf guacamole-auth-duo-${GUAC_VERSION}.tar.gz\n        echo -e \"${LGREEN}Downloaded guacamole-auth-duo-${GUAC_VERSION}.tar.gz${GREY}\"\n    fi\nfi\n\n# Download LDAP auth extension\nif [[ \"${INSTALL_LDAP}\" = true ]]; then\n    wget -q --show-progress -O guacamole-auth-ldap-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-ldap-${GUAC_VERSION}.tar.gz\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed to download guacamole-auth-ldap-${GUAC_VERSION}.tar.gz\" 1>&2\n        echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-ldap-${GUAC_VERSION}.tar.gz\"\n        exit 1\n    else\n        tar -xzf guacamole-auth-ldap-${GUAC_VERSION}.tar.gz\n        echo -e \"${LGREEN}Downloaded guacamole-auth-ldap-${GUAC_VERSION}.tar.gz${GREY}\"\n    fi\nfi\n\n# Download Guacamole quick-connect extension\nif [[ \"${INSTALL_QCONNECT}\" = true ]]; then\n    wget -q --show-progress -O guacamole-auth-quickconnect-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-quickconnect-${GUAC_VERSION}.tar.gz\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed to download guacamole-auth-quickconnect-${GUAC_VERSION}.tar.gz\" 1>&2\n        echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-quickconnect-${GUAC_VERSION}.tar.gz\"\n        exit 1\n    else\n        tar -xzf guacamole-auth-quickconnect-${GUAC_VERSION}.tar.gz\n        echo -e \"${LGREEN}Downloaded guacamole-auth-quickconnect-${GUAC_VERSION}.tar.gz${GREY}\"\n    fi\nfi\n\n# Download Guacamole history recording storage extension\nif [[ \"${INSTALL_HISTREC}\" = true ]]; then\n    wget -q --show-progress -O guacamole-history-recording-storage-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-history-recording-storage-${GUAC_VERSION}.tar.gz\n\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed to download guacamole-history-recording-storage-${GUAC_VERSION}.tar.gz\" 1>&2\n        echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-history-recording-storage-${GUAC_VERSION}.tar.gz\"\n        exit 1\n    else\n        tar -xzf guacamole-history-recording-storage-${GUAC_VERSION}.tar.gz\n        echo -e \"${LGREEN}Downloaded guacamole-history-recording-storage-${GUAC_VERSION}.tar.gz${GREY}\"\n    fi\nfi\necho -e \"Source download complete.${GREY}\"\n\n# Place a pause in script here if you wish to make final tweaks to source code before compiling\n#read -p $'Script paused for editing source before building. Enter to begin the build...\\n'\n\n# Add customised RDP share names and printer labels, remove Guacamole default labelling\nsed -i -e 's/IDX_CLIENT_NAME, \"Guacamole RDP\"/IDX_CLIENT_NAME, \"'\"${RDP_SHARE_HOST}\"'\"/' ${DOWNLOAD_DIR}/guacamole-server-${GUAC_VERSION}/src/protocols/rdp/settings.c\nsed -i -e 's/IDX_DRIVE_NAME, \"Guacamole Filesystem\"/IDX_DRIVE_NAME, \"'\"${RDP_SHARE_LABEL}\"'\"/' ${DOWNLOAD_DIR}/guacamole-server-${GUAC_VERSION}/src/protocols/rdp/settings.c\nsed -i -e 's/IDX_PRINTER_NAME, \"Guacamole Printer\"/IDX_PRINTER_NAME, \"'\"${RDP_PRINTER_LABEL}\"'\"/' ${DOWNLOAD_DIR}/guacamole-server-${GUAC_VERSION}/src/protocols/rdp/settings.c\n\n# Make Guacamole directories\nrm -rf /etc/guacamole/lib/\nrm -rf /etc/guacamole/extensions/\nmkdir -p /etc/guacamole/lib/\nmkdir -p /etc/guacamole/extensions/\n\n# Create a custom guacd service account and heavily lock it down\nadduser \"${GUACD_ACCOUNT}\" --disabled-password --disabled-login --gecos \"\" > /dev/null 2>&1\ngpasswd -d \"${GUACD_ACCOUNT}\" users > /dev/null 2>&1\necho -e \"\\nMatch User ${GUACD_ACCOUNT}\\n    X11Forwarding no\\n    AllowTcpForwarding no\\n    PermitTTY no\\n    ForceCommand cvs server\" | sudo tee -a /etc/ssh/sshd_config > /dev/null 2>&1\nsystemctl restart ssh\ntouch \"${CRON_DENY_FILE}\"\nchmod 644 \"${CRON_DENY_FILE}\"\nchown root:root \"${CRON_DENY_FILE}\"\nif ! grep -q \"^${GUACD_ACCOUNT}$\" \"${CRON_DENY_FILE}\"; then\n   echo \"$GUACD_ACCOUNT\" | sudo tee -a \"$CRON_DENY_FILE\" > /dev/null 2>&1\nfi\n\n# Setup freerdp profile permissions for storing certificates\nmkdir -p /home/\"${GUACD_ACCOUNT}\"/.config/freerdp\nchown ${GUACD_ACCOUNT}:${GUACD_ACCOUNT} /home/\"${GUACD_ACCOUNT}\"/.config/freerdp\n\n# Setup guacamole permissions\nmkdir -p /var/guacamole\nchown \"${GUACD_ACCOUNT}\":\"${GUACD_ACCOUNT}\" /var/guacamole\n\n# Make and install guacd (Guacamole-Server)\necho\necho -e \"${GREY}Compiling Guacamole-Server from source with with GCC $(gcc --version | head -n1 | grep -oP '\\)\\K.*' | awk '{print $1}'), this might take a few minutes...${GREY}\"\n\ncd guacamole-server-${GUAC_VERSION}/\n# Skip any deprecated software warnings various distros may throw during build\nexport CFLAGS=\"-Wno-error\"\n\n# Configure Guacamole Server source\nspinner() {\n  local pid=$1\n  local delay=0.15\n  local spinstr='|/-\\'\n  tput civis\n  while ps -p $pid > /dev/null; do\n    for i in $(seq 0 3); do\n      tput sc\n      printf \"[%c]\" \"${spinstr:$i:1}\"\n      tput rc\n      sleep $delay\n    done\n  done\n  tput cnorm\n  printf \"       \"\n  tput rc\n}\n./configure --with-systemd-dir=/etc/systemd/system &>>${INSTALL_LOG} &\ncommand_pid=$!\nspinner $command_pid\nif [[ $? -ne 0 ]]; then\n    echo \"Failed to configure guacamole-server\"\n    echo \"Trying again with --enable-allow-freerdp-snapshots\"\n    ./configure --with-systemd-dir=/etc/systemd/system --enable-allow-freerdp-snapshots\n    if [[ $? -ne 0 ]]; then\n        echo \"Failed to configure guacamole-server - again\"\n        exit\n    fi\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\necho -e \"${GREY}Running make and building the Guacamole-Server application...\"\nspinner() {\n  local pid=$1\n  local delay=0.15\n  local spinstr='|/-\\'\n  tput civis\n  while ps -p $pid > /dev/null; do\n    for i in $(seq 0 3); do\n      tput sc\n      printf \"[%c]\" \"${spinstr:$i:1}\"\n      tput rc\n      sleep $delay\n    done\n  done\n  tput cnorm\n  printf \"       \"\n  tput rc\n}\nmake &>>${INSTALL_LOG} &\ncommand_pid=$!\nspinner $command_pid\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\necho -e \"${GREY}Installing Guacamole-Server...\"\nmake install &>>${INSTALL_LOG}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Update the shared library cache\nldconfig\n\n# Move Guacamole client and authentication extensions to their correct install locations\ncd ..\necho -e \"${GREY}Moving guacamole-${GUAC_VERSION}.war (/etc/guacamole/extensions/)...\"\nmv -f guacamole-${GUAC_VERSION}.war /etc/guacamole/guacamole.war\nchmod 664 /etc/guacamole/guacamole.war\n# Create a symbolic link for Tomcat\nln -sf /etc/guacamole/guacamole.war /var/lib/${TOMCAT_VERSION}/webapps/ &>>${INSTALL_LOG}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\necho -e \"${GREY}Moving guacamole-auth-jdbc-mysql-${GUAC_VERSION}.jar (/etc/guacamole/extensions/)...\"\nmv -f guacamole-auth-jdbc-${GUAC_VERSION}/mysql/guacamole-auth-jdbc-mysql-${GUAC_VERSION}.jar /etc/guacamole/extensions/\nchmod 664 /etc/guacamole/extensions/guacamole-auth-jdbc-mysql-${GUAC_VERSION}.jar\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Move MySQL connector/j files\necho -e \"${GREY}Moving mysql-connector-j-${MYSQLJCON}.jar (/etc/guacamole/lib/mysql-connector-java.jar)...\"\nmv -f mysql-connector-j-${MYSQLJCON}/mysql-connector-j-${MYSQLJCON}.jar /etc/guacamole/lib/mysql-connector-java.jar\nchmod 664 /etc/guacamole/lib/mysql-connector-java.jar\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Configure guacamole.properties file\nrm -f /etc/guacamole/guacamole.properties\ntouch /etc/guacamole/guacamole.properties\necho \"mysql-hostname: ${MYSQL_HOST}\" >>/etc/guacamole/guacamole.properties\necho \"mysql-port: ${MYSQL_PORT}\" >>/etc/guacamole/guacamole.properties\necho \"mysql-database: ${GUAC_DB}\" >>/etc/guacamole/guacamole.properties\necho \"mysql-username: ${GUAC_USER}\" >>/etc/guacamole/guacamole.properties\necho \"mysql-password: ${GUAC_PWD}\" >>/etc/guacamole/guacamole.properties\n\n# Move TOTP files\nif [[ \"${INSTALL_TOTP}\" = true ]]; then\n    echo -e \"${GREY}Moving guacamole-auth-totp-${GUAC_VERSION}.jar (/etc/guacamole/extensions/)...\"\n    mv -f guacamole-auth-totp-${GUAC_VERSION}/guacamole-auth-totp-${GUAC_VERSION}.jar /etc/guacamole/extensions/\n    chmod 664 /etc/guacamole/extensions/guacamole-auth-totp-${GUAC_VERSION}.jar\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Move Duo files\nif [[ \"${INSTALL_DUO}\" = true ]]; then\n    echo -e \"${GREY}Moving guacamole-auth-duo-${GUAC_VERSION}.jar (/etc/guacamole/extensions/)...\"\n    mv -f guacamole-auth-duo-${GUAC_VERSION}/guacamole-auth-duo-${GUAC_VERSION}.jar /etc/guacamole/extensions/\n    chmod 664 /etc/guacamole/extensions/guacamole-auth-duo-${GUAC_VERSION}.jar\n    echo \"#duo-api-hostname: \" >>/etc/guacamole/guacamole.properties\n    echo \"#duo-integration-key: \" >>/etc/guacamole/guacamole.properties\n    echo \"#duo-secret-key: \" >>/etc/guacamole/guacamole.properties\n    echo \"#duo-application-key: \" >>/etc/guacamole/guacamole.properties\n    echo -e \"Duo auth is installed, it will need to be configured via guacamole.properties\"\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Move LDAP files\nif [[ \"${INSTALL_LDAP}\" = true ]]; then\n    echo -e \"${GREY}Moving guacamole-auth-ldap-${GUAC_VERSION}.jar (/etc/guacamole/extensions/)...\"\n    mv -f guacamole-auth-ldap-${GUAC_VERSION}/guacamole-auth-ldap-${GUAC_VERSION}.jar /etc/guacamole/extensions/\n    chmod 664 /etc/guacamole/extensions/guacamole-auth-ldap-${GUAC_VERSION}.jar\n    echo \"#If you have issues with LDAP, check the formatting is exactly as below or you will despair!\" >>/etc/guacamole/guacamole.properties\n    echo \"#Be extra careful with spaces at line ends or with windows line feeds.\" >>/etc/guacamole/guacamole.properties\n    echo \"#ldap-hostname: dc1.yourdomain.com dc2.yourdomain.com\" >>/etc/guacamole/guacamole.properties\n    echo \"#ldap-port: 389\" >>/etc/guacamole/guacamole.properties\n    echo \"#ldap-username-attribute: sAMAccountName\" >>/etc/guacamole/guacamole.properties\n    echo \"#ldap-encryption-method: none\" >>/etc/guacamole/guacamole.properties\n    echo \"#ldap-search-bind-dn: ad-account@yourdomain.com\" >>/etc/guacamole/guacamole.properties\n    echo \"#ldap-search-bind-password: ad-account-password\" >>/etc/guacamole/guacamole.properties\n    echo \"#ldap-config-base-dn: dc=domain,dc=com\" >>/etc/guacamole/guacamole.properties\n    echo \"#ldap-user-base-dn: OU=SomeOU,DC=domain,DC=com\" >>/etc/guacamole/guacamole.properties\n    echo \"#ldap-user-search-filter:(objectClass=user)(!(objectCategory=computer))\" >>/etc/guacamole/guacamole.properties\n    echo \"#ldap-max-search-results:200\" >>/etc/guacamole/guacamole.properties\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Move quick-connect extension files\nif [[ \"${INSTALL_QCONNECT}\" = true ]]; then\n    echo -e \"${GREY}Moving guacamole-auth-quickconnect-${GUAC_VERSION}.jar (/etc/guacamole/extensions/)...\"\n    mv -f guacamole-auth-quickconnect-${GUAC_VERSION}/guacamole-auth-quickconnect-${GUAC_VERSION}.jar /etc/guacamole/extensions/\n    chmod 664 /etc/guacamole/extensions/guacamole-auth-quickconnect-${GUAC_VERSION}.jar\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Move history recording storage extension files\nif [[ \"${INSTALL_HISTREC}\" = true ]]; then\n    echo -e \"${GREY}Moving guacamole-history-recording-storage-${GUAC_VERSION}.jar (/etc/guacamole/extensions/)...\"\n    mv -f guacamole-history-recording-storage-${GUAC_VERSION}/guacamole-history-recording-storage-${GUAC_VERSION}.jar /etc/guacamole/extensions/\n    chmod 664 /etc/guacamole/extensions/guacamole-history-recording-storage-${GUAC_VERSION}.jar\n    #Setup the default recording path\n    mkdir -p ${HISTREC_PATH}\n    chown ${GUACD_ACCOUNT}:tomcat ${HISTREC_PATH}\n    chmod 2750 ${HISTREC_PATH}\n    echo \"recording-search-path: ${HISTREC_PATH}\" >>/etc/guacamole/guacamole.properties\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Apply a branded interface and dark theme. You may delete this file and restart guacd & tomcat for the default console\necho -e \"${GREY}Setting the Guacamole console to a (customisable) dark mode themed template...\"\nmv branding.jar /etc/guacamole/extensions\nchmod 664 /etc/guacamole/extensions/branding.jar\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Restart Tomcat\necho -e \"${GREY}Restarting Tomcat service & enable at boot...\"\nsystemctl restart ${TOMCAT_VERSION}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Set Tomcat to start at boot\nsystemctl enable ${TOMCAT_VERSION}\n\n# Begin the MySQL database config only if this is a local MYSQL install.\nif [[ \"${INSTALL_MYSQL}\" = true ]]; then\n    # Set MySQL password\n    export MYSQL_PWD=${MYSQL_ROOT_PWD}\n\n    # Set the root password without a reliance on debconf.\n    echo -e \"${GREY}Setting MySQL root password...\"\n    SQLCODE=\"\nFLUSH PRIVILEGES;\nALTER USER 'root'@'localhost' IDENTIFIED BY '$MYSQL_ROOT_PWD';\"\n    echo ${SQLCODE} | $DB_CMD -u root\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\n\n   # A simple method to find the correct file containing the default MySQL timezone setting from a potential list of candidates. \n   # Add to this array if your distro uses a different path to the .cnf containing the default_time_zone value.\n    for x in /etc/mysql/mariadb.conf.d/50-server.cnf \\\n        /etc/mysql/mysql.conf.d/mysqld.cnf \\\n        /etc/mysql/my.cnf; do\n        # Check inside each candidate to see if a [mysqld] or [mariadbd] section exists, assign $x the correct filename.\n        if [[ -e \"${x}\" ]]; then\n            if grep -qE '^\\[(mysqld|mariadbd)\\]$' \"${x}\"; then\n                mysqlconfig=\"${x}\"\n                # Reduce any duplicated section names, then sanitise the [ ] special characters for sed below)\n                config_section=$(grep -m 1 -E '^\\[(mysqld|mariadbd)\\]$' \"${x}\" | sed 's/\\[\\(.*\\)\\]/\\1/')\n                break\n            fi\n        fi\n    done\n\n    # Set the MySQL Timezone\n    if [[ -z \"${mysqlconfig}\" ]]; then\n        echo -e \"${GREY}Couldn't detect MySQL config file - you will need to manually configure database timezone settings\"\n    else\n        # Is there already a timzeone value configured?\n        if grep -q \"^default_time_zone[[:space:]]=\" \"${mysqlconfig}\"; then\n            echo -e \"MySQL database timezone defined in ${mysqlconfig}\"\n        else\n            timezone=${DB_TZ}\n            if [[ -z \"${DB_TZ}\" ]]; then\n                echo -e \"No timezone specified, using UTC\"\n                timezone=\"UTC\"\n            fi\n            echo -e \"Setting MySQL database timezone as ${timezone}${GREY}\"\n            mysql_tzinfo_to_sql /usr/share/zoneinfo 2>/dev/null | ${DB_CMD} -u root -D mysql -p${MYSQL_ROOT_PWD}\n            # Add the timzone value to the sanitsed server file section name.\n            sed -i -e \"/^\\[${config_section}\\]/a default_time_zone = ${timezone}\" \"${mysqlconfig}\"\n        fi\n    fi\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\n\n    # This below block should stay as \"localhost\" for all local MySQL install situations and it is driven by the $MYSQL_HOST setting. \n    # $GUAC_USERHost determines from WHERE the new ${GUAC_USER} will be able to login to the database (either from specific remote IPs \n    # or from localhost only.) \n    if [[ \"${MYSQL_HOST}\" != \"localhost\" ]]; then\n        GUAC_USERHost=\"%\"\n        echo -e \"${LYELLOW}${GUAC_USER} is set to accept db logins from any host, you may wish to limit this to specific IPs.${GREY}\"\n    else\n        GUAC_USERHost=\"localhost\"\n    fi\n\n    # Execute SQL code to create the Guacamole database\n    echo -e \"${GREY}Creating the Guacamole database...\"\n    SQLCODE=\"\nDROP DATABASE IF EXISTS ${GUAC_DB};\nCREATE DATABASE IF NOT EXISTS ${GUAC_DB};\nCREATE USER IF NOT EXISTS '${GUAC_USER}'@'${GUAC_USERHost}' IDENTIFIED BY \\\"${GUAC_PWD}\\\";\nGRANT SELECT,INSERT,UPDATE,DELETE ON ${GUAC_DB}.* TO '${GUAC_USER}'@'${GUAC_USERHost}';\nFLUSH PRIVILEGES;\"\n    echo ${SQLCODE} | $DB_CMD -u root -D mysql -h ${MYSQL_HOST} -P ${MYSQL_PORT}\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\n\n    # Add Guacamole schema to newly created database\n    echo -e \"${GREY}Adding database tables...\"\n    cat guacamole-auth-jdbc-${GUAC_VERSION}/mysql/schema/*.sql | $DB_CMD -u root -D ${GUAC_DB} -p${MYSQL_ROOT_PWD}\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Apply Secure MySQL installation settings\nif [[ \"${SECURE_MYSQL}\" = true ]] && [[ \"${INSTALL_MYSQL}\" = true ]]; then\n    echo -e \"${GREY}Applying mysql_secure_installation settings...${DGREY}\"\n    SECURE_MYSQL=$(expect -c \"\nset timeout 10\nspawn mysql_secure_installation\nexpect \\\"Enter current password for root (enter for none):\\\"\nsend \\\"$MYSQL_ROOT_PWD\\r\\\"\nexpect \\\"Switch to unix_socket authentication\\\"\nsend \\\"n\\r\\\"\nexpect \\\"Change the root password?\\\"\nsend \\\"n\\r\\\"\nexpect \\\"Remove anonymous users?\\\"\nsend \\\"y\\r\\\"\nexpect \\\"Disallow root login remotely?\\\"\nsend \\\"y\\r\\\"\nexpect \\\"Remove test database and access to it?\\\"\nsend \\\"y\\r\\\"\nexpect \\\"Reload privilege tables now?\\\"\nsend \\\"y\\r\\\"\nexpect eof\n\")\n    echo \"$SECURE_MYSQL\"\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Restart MySQL service\nif [[ \"${INSTALL_MYSQL}\" = true ]]; then\n    echo -e \"${GREY}Restarting MySQL service & enable at boot...\"\n    # Set MySQl to start at boot\n    systemctl enable mysql\n    systemctl restart mysql\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Create guacd.conf and localhost IP binding.\necho -e \"${GREY}Binding guacd to 127.0.0.1 port 4822...\"\ncat >/etc/guacamole/guacd.conf <<-\"EOF\"\n[server]\nbind_host = 127.0.0.1\nbind_port = 4822\nEOF\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Ensure guacd is started\necho -e \"${GREY}Starting guacd service & enable at boot...\"\n# Update the systemd unit file the default daemon to the chosen service account \nsudo sed -i \"s/\\bdaemon\\b/${GUACD_ACCOUNT}/g\" /etc/systemd/system/guacd.service\nsystemctl daemon-reload\nsystemctl enable guacd\nsystemctl stop guacd 2>/dev/null\nsystemctl start guacd\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Redirect the Tomcat URL to its root to avoid typing the extra /guacamole path (if not using a reverse proxy)\nif [[ \"${GUAC_URL_REDIR}\" = true ]] && [[ \"${INSTALL_NGINX}\" = false ]]; then\n    echo -e \"${GREY}Redirecting the Tomcat http root url to /guacamole...${DGREY}\"\n    systemctl stop ${TOMCAT_VERSION}\n    mv /var/lib/${TOMCAT_VERSION}/webapps/ROOT/index.html /var/lib/${TOMCAT_VERSION}/webapps/ROOT/index.html.old\n    touch /var/lib/${TOMCAT_VERSION}/webapps/ROOT/index.jsp\n    echo \"<% response.sendRedirect(\\\"/guacamole\\\");%>\" >>/var/lib/${TOMCAT_VERSION}/webapps/ROOT/index.jsp\n    systemctl start ${TOMCAT_VERSION}\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Update Linux firewall\necho -e \"${GREY}Updating firewall rules to allow only SSH and tcp 8080...\"\nufw default allow outgoing >/dev/null 2>&1\nufw default deny incoming >/dev/null 2>&1\nufw allow OpenSSH >/dev/null 2>&1\nufw allow 8080/tcp >/dev/null 2>&1\necho \"y\" | sudo ufw enable >/dev/null 2>&1\nufw logging off >/dev/null 2>&1 # Reduce firewall logging noise\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Cleanup\necho -e \"${GREY}Cleaning up Guacamole source files...${GREY}\"\nrm -rf guacamole-*\nrm -rf mysql-connector-j-*\nrm -rf mariadb_repo_setup\nunset MYSQL_PWD\napt-get -y remove expect &>>${INSTALL_LOG}\napt-get -y autoremove &>>${INSTALL_LOG}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\nfi\n\n# Done\necho -e ${NC}\n"
  },
  {
    "path": "3-install-nginx.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Add Nginx reverse proxy front end to default Guacamole install\n# For Ubuntu / Debian / Raspbian\n# 3 of 4\n# David Harrop\n# August 2023\n#######################################################################################################################\n\n# If run as standalone and not from the main installer script, check the below variables are correct.\n# To run standalone: sudo -E ./3-install-nginx.sh\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\n\necho\necho\necho -e \"${GREY}Installing Nginx...\"\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\n# Below variables are automatically updated by the 1-setup.sh script with the respective values given at install (manually update if blank)\nPROXY_SITE=\nINSTALL_LOG=\nGUAC_URL=\n\n# Install Nginx\nspinner() {\n  local pid=$1\n  local delay=0.15\n  local spinstr='|/-\\'\n  tput civis\n  while ps -p $pid > /dev/null; do\n    for i in $(seq 0 3); do\n      tput sc\n      printf \"[%c]\" \"${spinstr:$i:1}\"\n      tput rc\n      sleep $delay\n    done\n  done\n  tput cnorm\n  printf \"       \"\n  tput rc\n}\napt-get update -qq &> /dev/null && apt-get install nginx -qq -y &>>${INSTALL_LOG} &\ncommand_pid=$!\nspinner $command_pid\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\necho -e \"${GREY}Configuring Nginx as a reverse proxy for Guacamole's Apache Tomcat front end...${DGREY}\"\n# Configure /etc/nginx/sites-available/(local dns site name)\ncat <<EOF | tee /etc/nginx/sites-available/$PROXY_SITE\nserver {\n    listen 80 default_server;\n    server_name $GUAC_URL;\n    location / {\n        proxy_pass $GUAC_URL;\n        proxy_buffering off;\n        proxy_http_version 1.1;\n        proxy_set_header X-Forwarded-For \\$proxy_add_x_forwarded_for;\n        proxy_set_header Upgrade \\$http_upgrade;\n        proxy_set_header Connection \\$http_connection;\n        access_log off;\n    }\n}\nEOF\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Force nginx to require tls1.2 and above\nsed -i -e '/ssl_protocols/s/^/#/' /etc/nginx/nginx.conf\nsed -i \"/SSL Settings/a \\        ssl_protocols TLSv1.2 TLSv1.3;\" /etc/nginx/nginx.conf\n\n# Symlink new reverse proxy site config from sites-available to sites-enabled\nln -s /etc/nginx/sites-available/$PROXY_SITE /etc/nginx/sites-enabled/\n\n# Make sure the default Nginx site is unlinked\nunlink /etc/nginx/sites-enabled/default\n\n# Do mandatory Nginx tweaks for logging actual client IPs through a proxy IP of 127.0.0.1 - DO NOT CHANGE COMMAND FORMATTING!\necho -e \"${GREY}Configuring Apache Tomcat valve for pass through of client IPs to Guacamole logs...${GREY}\"\nsed -i '/pattern=\"%h %l %u %t &quot;%r&quot; %s %b\"/a        \\        <!-- Allow host IP to pass through to guacamole.-->\\n        <Valve className=\"org.apache.catalina.valves.RemoteIpValve\"\\n               internalProxies=\"127\\.0\\.0\\.1|0:0:0:0:0:0:0:1\"\\n               remoteIpHeader=\"x-forwarded-for\"\\n               remoteIpProxiesHeader=\"x-forwarded-by\"\\n               protocolHeader=\"x-forwarded-proto\" />' /etc/$TOMCAT_VERSION/server.xml\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Allow large file transfers through Nginx\nsed -i '/client_max_body_size/d' /etc/nginx/nginx.conf  # remove this line if it already exists to prevent duplicates\nsed -i \"/Basic Settings/a \\        client_max_body_size 1000000000M;\" /etc/nginx/nginx.conf # Add larger file transfer size, should be enough!\necho -e \"${GREY}Boosting Nginx's 'maximum body size' parameter to allow large file transfers...${GREY}\"\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Update general ufw rules so force traffic via reverse proxy. Only Nginx and SSH will be available over the network.\necho -e \"${GREY}Updating firewall rules to allow only SSH and tcp 80/443...\"\nufw default allow outgoing >/dev/null 2>&1\nufw default deny incoming >/dev/null 2>&1\nufw allow OpenSSH >/dev/null 2>&1\nufw allow 80/tcp >/dev/null 2>&1\nufw delete allow 8080/tcp >/dev/null 2>&1\necho \"y\" | sudo ufw enable >/dev/null 2>&1\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Reload everything\necho -e \"${GREY}Restaring Guacamole & Ngnix...\"\nsystemctl restart $TOMCAT_VERSION\nsystemctl restart guacd\nsystemctl restart nginx\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\nfi\n\n# Done\necho -e ${NC}\n"
  },
  {
    "path": "4a-install-tls-self-signed-nginx.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Add self-signed TLS certificates to Guacamole with Nginx reverse proxy\n# For Ubuntu / Debian / Raspbian\n# 4a of 4\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n# This script can be run multiple times to either install or update TLS settings and certificates.\n\n# Change the name of the site or add/renew TLS certs by specifying command line arguments [dns.name] [cert-lifetime] [IP]\n# e.g. sudo -E ./4a-install-tls-self-signed-nginx.sh proxy.domain.local 365 192.168.1.50\n\n# Alternatively, run the script without any command arguments and the default variables below will apply\n# e.g. sudo -E ./4a-install-tls-self-signed-nginx.sh\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\n# Check if user is root or sudo\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\n\n# Set default certificate file destinations.\nDIR_SSL_CERT=\"/etc/nginx/ssl/cert\"\nDIR_SSL_KEY=\"/etc/nginx/ssl/private\"\n\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\n# Below variables are automatically updated by the 1-setup.sh script with the respective values given at install (manually update if blank)\nDOWNLOAD_DIR=\nCERT_COUNTRY=\nCERT_STATE=\nCERT_LOCATION=\nCERT_ORG=\nCERT_OU=\nGUAC_URL=\nINSTALL_LOG=\nPROXY_SITE=\nCERT_DAYS=\nDEFAULT_IP=\nRSA_KEYLENGTH=\n\n# Create a place to save the certs so we don't overwrite any earlier versions\nCERT_DIR_NAME=tls-certs-$(date +%y.%m.%d)\nCERT_DIR=$DOWNLOAD_DIR/$CERT_DIR_NAME\nmkdir -p $CERT_DIR\ncd $CERT_DIR\n\n# Setup script cmd line arguments for proxy site and certificate days\nTLSNAME=$1\nTLSDAYS=$2\nTLSIP=$3\n\n# Assume the values set by the main installer if the script is run without any command line options\nif [[ -z \"$1\" ]] || [[ -z \"$2\" ]] || [[ -z \"$3\" ]]; then\n    TLSNAME=$PROXY_SITE\n    TLSDAYS=$CERT_DAYS\n    TLSIP=$DEFAULT_IP\nfi\n\necho\necho\necho -e \"${LGREEN}Setting up self-signed TLS certificates for Nginx...${GREY}\"\necho\n\n# Make directories to place TLS Certificate if they don't exist\nif [[ ! -d $DIR_SSL_KEY ]]; then\n    mkdir -p $DIR_SSL_KEY\nfi\n\nif [[ ! -d $DIR_SSL_CERT ]]; then\n    mkdir -p $DIR_SSL_CERT\nfi\n\necho -e \"${GREY}New self-signed TLS certificate attributes are shown below...${DGREY}\"\n# Display the new TLS cert parameters.\ncat <<EOF | tee cert_attributes.txt\n[req]\ndistinguished_name  = req_distinguished_name\nx509_extensions     = v3_req\nprompt              = no\nstring_mask         = utf8only\n\n[req_distinguished_name]\nC                   = $CERT_COUNTRY\nST                  = $CERT_STATE\nL                   = $CERT_LOCATION\nO                   = $CERT_ORG\nOU                  = $CERT_OU\nCN                  = *.$(echo $TLSNAME | cut -d. -f2-)\n\n[v3_req]\nkeyUsage            = nonRepudiation, digitalSignature, keyEncipherment\nextendedKeyUsage    = serverAuth, clientAuth, codeSigning, emailProtection\nsubjectAltName      = @alt_names\n\n[alt_names]\nDNS.1               = $TLSNAME\nDNS.2               = *.$(echo $TLSNAME | cut -d. -f2-)\nIP.1                = $TLSIP\nEOF\n\necho\necho -e \"${GREY}Creating a new Nginx TLS Certificate...\"\nopenssl req -x509 -nodes -newkey rsa:$RSA_KEYLENGTH -keyout $TLSNAME.key -out $TLSNAME.crt -days $TLSDAYS -config cert_attributes.txt\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Place TLS Certificate into the defined application path\ncp $TLSNAME.key $DIR_SSL_KEY/$TLSNAME.key\ncp $TLSNAME.crt $DIR_SSL_CERT/$TLSNAME.crt\n\n# Create a PFX formatted key for easier import to Windows hosts\necho -e \"${GREY}Converting client certificate to Windows pfx format...${GREY}\"\nopenssl pkcs12 -export -out $TLSNAME.pfx -inkey $TLSNAME.key -in $TLSNAME.crt -password pass:1234\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Change of permissions so certs can be copied via WinSCP.\nchown $SUDO_USER:root $TLSNAME.pfx\nchown $SUDO_USER:root $TLSNAME.crt\nchown $SUDO_USER:root $TLSNAME.key\n\n# Backup the previous configuration\nif [ -f \"/etc/nginx/sites-enabled/${TLSNAME}\" ]; then\n    echo -e \"${GREY}Backing up previous Nginx proxy config to $DOWNLOAD_DIR/${PROXY_SITE}-nginx.bak\"\n    cp -f /etc/nginx/sites-enabled/${TLSNAME} $DOWNLOAD_DIR/${TLSNAME}-nginx.bak\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Warning: Failed to copy the Nginx site config.${GREY}\" 1>&2\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\nfi\n\n# Update Nginx config to accept the new certificates\necho -e \"${GREY}Configuring Nginx proxy to use the self-signed TLS certificate and setting up HTTP redirect...${DGREY}\"\ncat <<EOF | tee /etc/nginx/sites-available/$TLSNAME\nserver {\n    # HTTPS site\n    listen 443 ssl;\n    server_name _;\n    location / {\n        proxy_pass $GUAC_URL;\n        proxy_buffering off;\n        proxy_http_version 1.1;\n        proxy_set_header X-Forwarded-For \\$proxy_add_x_forwarded_for;\n        proxy_set_header Upgrade \\$http_upgrade;\n        proxy_set_header Connection \\$http_connection;\n        access_log off;\n    }\n    ssl_certificate      /etc/nginx/ssl/cert/$TLSNAME.crt;\n    ssl_certificate_key  /etc/nginx/ssl/private/$TLSNAME.key;\n    ssl_session_cache shared:SSL:1m;\n    ssl_session_timeout  5m;\n}\n\nserver {\n    # Redirect all other traffic to the HTTPS site\n    listen 80 default_server;\n    location / {\n        return 301 https://\\$host\\$request_uri;\n    }\n}\nEOF\n\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Find all enabled sites containing the $GUAC_URL and remove them to avoid conflicts\nfor x in /etc/nginx/sites-enabled/*; do\n    # Check inside each enabled site to see if the $GUAC_URL exists.\n    if [[ -f \"${x}\" ]]; then\n        if grep -qE \"${GUAC_URL}\" \"${x}\"; then\n            found_sites+=(\"${x}\")\n        fi\n    fi\ndone\n\n# Unlink all previous sites pointed to $GUAC_URL\nif [ \"${#found_sites[@]}\" -gt 0 ]; then\n    for guacUrl in \"${found_sites[@]}\"; do\n        unlink \"${guacUrl}\"\n    done\nfi\n\n# Link to enable the new site configuration\nln -s /etc/nginx/sites-available/$TLSNAME /etc/nginx/sites-enabled/ >/dev/null 2>&1\n\n# Update general ufw rules so force traffic via reverse proxy. Only Nginx and SSH will be available over the network.\necho -e \"${GREY}Updating firewall rules to allow only SSH and tcp 80/443...\"\nufw default allow outgoing >/dev/null 2>&1\nufw default deny incoming >/dev/null 2>&1\nufw allow OpenSSH >/dev/null 2>&1\nufw allow 80/tcp >/dev/null 2>&1\nufw allow 443/tcp >/dev/null 2>&1\necho \"y\" | sudo ufw enable >/dev/null 2>&1\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Reload everything and tidy up\necho -e \"${GREY}Restaring Guacamole & Ngnix...\"\nsystemctl restart $TOMCAT_VERSION\nsystemctl restart guacd\nsystemctl restart nginx\nrm -f cert_attributes.txt\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# A simple hack to display special characters in a cut & paste-able format directly to stdout.\nSHOWASTEXT1='$mypwd'\nSHOWASTEXT2='\"Cert:\\LocalMachine\\Root\"'\n\nprintf \"${GREY}+-------------------------------------------------------------------------------------------------------------\n${LGREEN}+ WINDOWS CLIENT SELF SIGNED TLS BROWSER CONFIG - SAVE THIS BEFORE CONTINUING!${GREY}\n+\n+ 1. In $CERT_DIR is a Windows version of the new certificate ${LYELLOW}$TLSNAME.pfx${GREY}\n+ 2. Import this PFX file into your Windows client with the below PowerShell commands (as Administrator):\n\\n\"\necho -e \"${SHOWASTEXT1} = ConvertTo-SecureString -String \"1234\" -Force -AsPlainText\"\necho -e \"Import-pfxCertificate -FilePath $TLSNAME.pfx -Password \"${SHOWASTEXT1}\" -CertStoreLocation \"${SHOWASTEXT2}\"\"\nprintf \"${GREY}+-------------------------------------------------------------------------------------------------------------\n${LGREEN}+ LINUX CLIENT SELF SIGNED TLS BROWSER CONFIG - SAVE THIS BEFORE CONTINUING!${GREY}\n+\n+ 1. In $CERT_DIR is a new Linux native OpenSSL certificate ${LYELLOW}$TLSNAME.crt${GREY}\n+ 2. Import the CRT file into your Linux client certificate store with the below command:\n\\n\"\necho -e \"(If certutil is not installed, run apt-get install libnss3-tools)\"\necho -e \"mkdir -p \\$HOME/.pki/nssdb && certutil -d \\$HOME/.pki/nssdb -N\"\necho -e \"certutil -d sql:\\$HOME/.pki/nssdb -A -t \"CT,C,c\" -n $TLSNAME -i $TLSNAME.crt\"\nprintf \"+-------------------------------------------------------------------------------------------------------------\\n\"\necho -e \"${LYELLOW}The above TLS browser config instructions are saved in ${LGREEN}$INSTALL_LOG${GREY}\"\n\n# Done\necho -e ${NC}\n"
  },
  {
    "path": "4b-install-tls-letsencrypt-nginx.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Add Let's Encrypt TLS Certificates to Guacamole with Nginx reverse proxy\n# For Ubuntu / Debian / Raspbian\n# 4b of 4\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n# If run as standalone and not from the main installer script, check the below variables are correct.\n# To run standalone: sudo -E ./4b-install-tls-letsencrypt-nginx.sh\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\n# Below variables are automatically updated by the 1-setup.sh script with the respective values given at install (manually update if blank)\nDOWNLOAD_DIR=\nPROXY_SITE=\nGUAC_URL=\nLE_DNS_NAME=\nLE_EMAIL=\nINSTALL_LOG=\n\necho\necho\necho -e \"${GREY}Installing Nginx & Lets Encrypt Certbot...\"\nspinner() {\n  local pid=$1\n  local delay=0.15\n  local spinstr='|/-\\'\n  tput civis\n  while ps -p $pid > /dev/null; do\n    for i in $(seq 0 3); do\n      tput sc\n      printf \"[%c]\" \"${spinstr:$i:1}\"\n      tput rc\n      sleep $delay\n    done\n  done\n  tput cnorm\n  printf \"       \"\n  tput rc\n}\napt-get update -qq &> /dev/null && apt-get install nginx certbot python3-certbot-nginx -qq -y &>>${INSTALL_LOG} &\ncommand_pid=$!\nspinner $command_pid\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Backup the current Nginx config\necho\necho -e \"${GREY}Backing up previous Nginx proxy to $DOWNLOAD_DIR/$PROXY_SITE-nginx.bak\"\ncp /etc/nginx/sites-enabled/${PROXY_SITE} $DOWNLOAD_DIR/${PROXY_SITE}-nginx.bak\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Configure Nginx to accept the new certificates\necho -e \"${GREY}Configuring Nginx proxy for Let's Encrypt TLS and setting up automatic HTTP redirect...${GREY}\"\ncat >/etc/nginx/sites-available/$PROXY_SITE <<EOL\nserver {\n    listen 80 default_server;\n    #listen [::]:80 default_server;\n    root /var/www/html;\n    index index.html index.htm index.nginx-debian.html;\n    server_name $PROXY_SITE;\n    location / {\n        proxy_pass $GUAC_URL;\n        proxy_buffering off;\n        proxy_http_version 1.1;\n        proxy_set_header X-Forwarded-For \\$proxy_add_x_forwarded_for;\n        proxy_set_header Upgrade \\$http_upgrade;\n        proxy_set_header Connection \\$http_connection;\n        access_log off;\n    }\n}\nEOL\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Update general ufw rules to force traffic via reverse proxy. Only Nginx and SSH will be available over the network.\necho -e \"${GREY}Updating firewall rules to allow only SSH and tcp 80/443...\"\nufw default allow outgoing >/dev/null 2>&1\nufw default deny incoming >/dev/null 2>&1\nufw allow OpenSSH >/dev/null 2>&1\nufw allow 80/tcp >/dev/null 2>&1\nufw allow 443/tcp >/dev/null 2>&1\necho \"y\" | sudo ufw enable >/dev/null 2>&1\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Reload the new Nginx config so as certbot can read the new config and update it\nsystemctl restart nginx\n\n# Run certbot to create and associate certificates with current public IP (must have tcp 80 and 443 open to work!)\ncertbot --nginx -n -d $LE_DNS_NAME --email $LE_EMAIL --agree-tos --redirect --hsts\necho -e\necho -e \"${GREY}Let's Encrypt successfully installed, but check for any errors above (DNS & firewall are the usual culprits).${GREY}\"\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Select a random daily time to schedule a daily check for a Let's Encrypt certificate due to expire in next 30 days.\n# If due to expire within a 30 day window, certbot will attempt to renew automatically each day.\necho -e \"${GREY}Scheduling automatic certificate renewals for certificates with < 30 days till expiry.)${GREY}\"\n#Dump out the current crontab\ncrontab -l >cron_1\n# Remove any previosly added certbot renewal entries\nsed -i '/# certbot renew/d' cron_1\n# Randomly choose a daily update schedule and append this to the cron schedule\nHOUR=$(shuf -i 0-23 -n 1)\nMINUTE=$(shuf -i 0-59 -n 1)\necho \"${MINUTE} ${HOUR} * * * /usr/bin/certbot renew --quiet --pre-hook 'systemctl stop nginx' --post-hook 'systemctl start nginx'\" >>cron_1\n# Overwrite old cron settings and cleanup\ncrontab cron_1\nrm cron_1\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Reload everything once again\necho -e \"${GREY}Restarting Guacamole & Ngnix...\"\nsystemctl restart $TOMCAT_VERSION\nsystemctl restart guacd\nsystemctl restart nginx\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\nfi\n\n# Done\necho -e ${NC}\n"
  },
  {
    "path": "ACTIVE-DIRECTORY-HOW-TO.md",
    "content": "## Integrating Guacamole With Active Directory\n\n### :arrows_clockwise: **Step 1: Ensure two-way LDAP traffic is available to the Guacamole application server**\n\n- If Guacamole is operating in a separate network from your Active Directory Servers, allow TCP 389 between all Guacamole application servers and all Active Directory Domain Controllers nominated in the config script settings below.\n\n### :key: **Step 2: Establish the required accounts to bind with Active Directory**\n\n- An account with only **Domain Users** rights is sufficient for Guacamole to read and bind with Active Directory. \n\n   - a. In the Guacamole application, create a new Guacamole account with full admin rights to the Guacamole application, e.g. `guacbind-ad`, and assign it an appropriately strong password. (Then log in with this new account and disable the default guacadmin account)\n   - b. Create a new Active Directory domain account with EXACTLY THE SAME NAME as the new full admin account named above, only this time assign a DIFFERENT strong password than what was used above. \n\n### :pencil: **Step 3: Edit the provided configuration script to reflect your specific Active Directory environment**\n\nBelow is the EXACT format to follow in editing the `$USER_HOME_DIR/guac-setup/add-ldap-auth-guacamole.sh` script. Be careful not to introduce new lines, spaces at the ends of lines or carriage returns. Anything outside of this format will cause the LDAP auth extension to fail. You have been warned! \n\n```\nldap-hostname: dc1.yourdomain.com dc2.yourdomain.com dc3.yourdomain.com\nldap-port: 389\nldap-username-attribute: sAMAccountName\nldap-encryption-method: none\nldap-search-bind-dn: guacbind-ad@yourdomain.com\nldap-search-bind-password: guacbind-ad-password\nldap-config-base-dn: dc=yourdomain,dc=com\nldap-user-base-dn: OU=SomeOU,DC=yourdomain,DC=com\nldap-user-search-filter:(objectClass=user)(!(objectCategory=computer))\nldap-max-search-results:200\nmysql-auto-create-accounts: true\n```\n\n**Edit only the following values from the above example to suit your environment, then save the add-ldap-auth-guacamole.sh script:**\n\n```\nldap-hostname:\nldap-search-bind-dn:\nldap-search-bind-password:\nldap-config-base-dn:\nldap-user-base-dn:\nmysql-auto-create-accounts: true\nldap-max-search-results:200\n```\n\n- **Important note on `ldap-user-base-dn:`** This value sets a position in the directory as a relative root to search within. All Guacamole users to be authenticated by Active Directory must be placed in a lower position within the directory tree than this value. This line can be added multiple times to more efficiently search across multiple branches of a directory tree.\n\n- **Important note on `ldap-max-search-results:`** Yes, there is no space before the default `:200` value. In larger environments managing the directory efficiently requires that we don't query every object in the tree for every user lookup. You may need to adjust this number depending on the number of objects in the above relative root search path.\n\n- **Important note on `mysql-auto-create-accounts:`** This line is optional and can be deleted if using Active Directory authentication without Guacamole's implementation of MFA. This line ensures that all Active Directory user accounts will have a matching user account created in the Guacamole database at thier first Guacmaole logon with thier AD accout. Only if Gucamole's MFA feature is to be provisioned is a local Guacamole account required, and automating this step can aid MFA deployment. If you want to provision Guacamole MFA access to just a limited selection of Active Diretory users, you may remove this line and manually create the passwordless Guacamole database local account pairings as needed. [See below for more.](https://github.com/itiligent/Guacamole-Install/blob/main/ACTIVE-DIRECTORY-HOW-TO.md#busts_in_silhouette-manually-creating-and-configuring-new-guacamole-users-for-active-directory-authentication-with-mfa) \n\n#### If your AD has TLS implemented via a self signed certificate you must also apply the extra TLS tasks A to E below, else skip to Step 4 ... For more info see [#18](https://github.com/itiligent/Guacamole-Install/issues/18)\n\nTLS task A. Adjust this line in the above template for add-ldap-auth-guacamole.sh (Values can be none, ssl or stattls) \n```\nldap-encryption-method: starttls \n```\nTLS task B. Next, you must obtain your AD TLS cert. \n```\nopenssl s_client -connect X.X.X.X:389 \\\n              -starttls ldap \\\n              -showcerts < /dev/null | \\\n              openssl x509 -text | \\\n              sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'\n```\nTLS task C. Copy the certificate contents from -----BEGIN CERTIFICATE----- to -----END CERTIFICATE----- and paste this into a file (e.g. adcert.pem as per below)\n```\nsudo nano /etc/ssl/certs/adcert.pem  # then paste certificate output\n```\n\nTLS task D. Now import the AD cert file into the Java keystore\n```\nsudo keytool -importcert -alias adcert \\\n\t-file /etc/ssl/certs/adcert.pem \\\n\t-keystore /usr/lib/jvm/java-11-openjdk-amd64/lib/security/cacerts \\\n\t-storepass changeit \\\n\t-noprompt\n```\nTLS task E. Restart Apache Tomcat\n````\nTOMCAT=$(ls /etc/ | grep tomcat) && sudo systemctl restart ${TOMCAT}\n````\n\n### :computer: **Step 4: Run the (now customised) LDAP configuration script**\n\n```shell\nsudo $USER_HOME_DIR/guac-setup/add-ldap-auth-guacamole.sh\n```\n\n\n\n### :door: **Step 5: Log on to Guacamole with the new guacbind-ad account**\n\n- When logging in to Guacamole as the new Active Directory account and password created above, that domain user is passed through to Guacamole as both a Guacamole admin and a Domain User. If all is working correctly, all the users located below the directory tree position set in **ldap-user-base-dn** will be listed under **Settings | Users** of the Guacamole management console.\n\n### :busts_in_silhouette: **Manually creating and configuring new Guacamole users for Active Directory authentication with MFA.**\n\n- If not using the **mysql-auto-create-accounts** directive, manually re-create the exact user account names in Guacamole as those in the directory that you wish to give specific local adminstrative permissions and/or provision Guacamole's MFA access. **DO NOT configure a Guacamole password for any users that will be exclusively authenticating via Active directory**. Guacamole database local user accounts without a password are first given an MFA challenge by the local Guacamole application (Only where the local passwordless Guacamole account is configured for MFA) and then will be brokered to Active Directory for their Kerberos authentication challenge. Guacamole database local user accounts that are given passwords in Guacamole will always refer to the local database account for authentication, never Active Directory. This design allows for a matrix of local, domain, MFA & non-MFA access use cases to be deployed.\n\n### :key: **Logging in using Gucamole local vs. domain guacbind-ad account**\n\n- As described above, logging on with the Guacamole admin user password will authenticate with the local Guacamole admin account, conversely if the Guacamole admin domain account password is given, the domain account is authenticated via Active Directory and then passed through as authorized to administer Guacamole. It may sometimes be necessary to log on with the local Guacamole admin account to manage some application functions, but be aware that when doing so you will not be able to view and search the user list from Active Directory. Only when logged on with the domain version of the Guacamole admin account can domain user permissions to various Guacamole sessions and objects be delegated and managed.\n\n### :gear: **Creating a quasi Single Sign-On user experience for Windows RDP access**\n\n- Create a Global Security domain group (e.g., Guac_Users) and populate it with selected domain users as required. \n- Now add this new security group to the built-in “Remote Desktop Users” domain group.\n- Next, for each connection profile you wish to create the SSO experience and behavior, _parameter_ _tokens_ must be used in place of hard-coded usernames and password values as follows... \n  - Add the parameter token `${GUAC_USERNAME}` to the Username field for each connection profile\n  - Add the parameter token `${GUAC_PASSWORD}` to the Password field for each connection profile\n- If the user has been given directory rights to the Guacamole session object, Guacamole will first authenticate the user to the Guacamole application (via a brokered Active Directory challenge) and then seamlessly pass the user's same domain credentials through to the Guacamole remote desktop session, thus avoiding any further remote desktop authentication prompts.\n- For more info on other dynamic connection settings see [Guacamole Documentation](https://guacamole.apache.org/doc/gug/configuring-guacamole.html#parameter-tokens)\n- Additional extensions are required for full SSO, but because centralised authentication / authorisation extensions require a bespoke approach to service providers and login behaviors, the SSO features are currently beyond the scope of this project. Here's some links for info on configuring [SAML](https://guacamole.apache.org/doc/gug/saml-auth.html#) and [OpenID Connect](https://guacamole.apache.org/doc/gug/openid-auth.html)\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU AFFERO GENERAL PUBLIC LICENSE\n                       Version 3, 19 November 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU Affero General Public License is a free, copyleft license for\nsoftware and other kinds of works, specifically designed to ensure\ncooperation with the community in the case of network server software.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nour General Public Licenses are intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  Developers that use our General Public Licenses protect your rights\nwith two steps: (1) assert copyright on the software, and (2) offer\nyou this License which gives you legal permission to copy, distribute\nand/or modify the software.\n\n  A secondary benefit of defending all users' freedom is that\nimprovements made in alternate versions of the program, if they\nreceive widespread use, become available for other developers to\nincorporate.  Many developers of free software are heartened and\nencouraged by the resulting cooperation.  However, in the case of\nsoftware used on network servers, this result may fail to come about.\nThe GNU General Public License permits making a modified version and\nletting the public access it on a server without ever releasing its\nsource code to the public.\n\n  The GNU Affero General Public License is designed specifically to\nensure that, in such cases, the modified source code becomes available\nto the community.  It requires the operator of a network server to\nprovide the source code of the modified version running there to the\nusers of that server.  Therefore, public use of a modified version, on\na publicly accessible server, gives the public access to the source\ncode of the modified version.\n\n  An older license, called the Affero General Public License and\npublished by Affero, was designed to accomplish similar goals.  This is\na different license, not a version of the Affero GPL, but Affero has\nreleased a new version of the Affero GPL which permits relicensing under\nthis license.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU Affero General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Remote Network Interaction; Use with the GNU General Public License.\n\n  Notwithstanding any other provision of this License, if you modify the\nProgram, your modified version must prominently offer all users\ninteracting with it remotely through a computer network (if your version\nsupports such interaction) an opportunity to receive the Corresponding\nSource of your version by providing access to the Corresponding Source\nfrom a network server at no charge, through some standard or customary\nmeans of facilitating copying of software.  This Corresponding Source\nshall include the Corresponding Source for any work covered by version 3\nof the GNU General Public License that is incorporated pursuant to the\nfollowing paragraph.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the work with which it is combined will remain governed by version\n3 of the GNU General Public License.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU Affero General Public License from time to time.  Such new versions\nwill be similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU Affero General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU Affero General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU Affero General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU Affero General Public License as published\n    by the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU Affero General Public License for more details.\n\n    You should have received a copy of the GNU Affero General Public License\n    along with this program.  If not, see <https://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If your software can interact with users remotely through a computer\nnetwork, you should also make sure that it provides a way for users to\nget its source.  For example, if your program is a web application, its\ninterface could display a \"Source\" link that leads users to an archive\nof the code.  There are many ways you could offer source, and different\nsolutions will be better for different programs; see section 13 for the\nspecific requirements.\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU AGPL, see\n<https://www.gnu.org/licenses/>.\n\n"
  },
  {
    "path": "README.md",
    "content": "<div align=\"center\">\r\n\r\n![GitHub release version](https://img.shields.io/github/v/release/itiligent/Easy-Guacamole-Installer?style=flat-square&color=orange&labelColor=black)\r\n![GitHub stars](https://img.shields.io/github/stars/itiligent/Easy-Guacamole-Installer?style=flat-square&color=yellow&labelColor=black)\r\n![GitHub forks](https://img.shields.io/github/forks/itiligent/Easy-Guacamole-Installer?style=flat-square&color=blue&labelColor=black)\r\n\r\n# 🥑 Easy Guacamole Installer\r\n\r\n\r\n\r\n</div>\r\n\r\n<p align=\"center\">\r\n<a href=\"https://www.paypal.com/donate/?business=PSZ878JBJDMB8&amount=10&no_recurring=0&item_name=Thankyou+for+your+support+in+maintaining+this+project&currency_code=AUD\">\r\n  <img src=\"https://github.com/itiligent/Guacamole-Install/raw/main/.github/ISSUE_TEMPLATE/paypal-donate-button.png\" width=\"125\" />\r\n</a>\r\n</p>\r\n\r\n## Introduction\r\n\r\n#### v1.6.0 is working. Issues and notes are tracked in https://github.com/itiligent/Easy-Guacamole-Installer/issues/78\r\n\r\nThis install script automatically sets up a Guacamole jump-host with optional for TLS reverse proxy (self-signed or Let's Encrypt), Active Directory integration, multi-factor authentication, Quick Connect & History Recording Storage UI enhancements. Other options also include a custom UI dark themed template, auto database backups, email alerts and internal hardening options including fail2ban for defence against brute force attacks. There is also facility for tiered enterprise deployment similar to [Amazon's Guacamole Bastion Cluster](http://netcubed-ami.s3-website-us-east-1.amazonaws.com/guaws/v2.3.1/cluster/).\r\n\r\n## Automatic Installation\r\n\r\n🚀 Move to you your home directory, paste the below link, then follow the prompts (**do NOT run as root, the script will prompt for sudo**): \r\n\r\n```shell\r\nwget https://raw.githubusercontent.com/itiligent/Guacamole-Install/main/1-setup.sh && chmod +x 1-setup.sh && ./1-setup.sh\r\n```\r\n---\r\n\r\n## Prerequisites\r\n\r\n📋 **You will need:**\r\n  - **Supported OS: Debian 12 or 13** | **Ubuntu LTS 22.x or 24.x** | **Raspbian**\r\n  - **1 CPU core + 2GB RAM for every 25 users (plus minimum RAM & disk space for your selected OS).**\r\n- **Open TCP ports: 22, 80, and 443 (no other services using 80, 8080 & 443)**\r\n- **For both TLS reverse proxy options you will need a PRIVATE DNS record for the internal proxy site, and an additional PUBLIC DNS record for the Let's Encrypt option.**\r\n- **Sudo & wget packages installed**\r\n- **The user running `1-setup.sh` must have sudo permissions.**\r\n\r\n---\r\n\r\n## Setup Script Menu\r\n\r\n🔧 **The main `1-setup.sh` script guides the installation with the following steps:**\r\n\r\n1. Setup the system hostname & local DNS name (Local DNS must be consistent for TLS proxy).\r\n2. Select either a local MySQL install or use a pre-existing local or remote MySQL instance.\r\n3. Pick an authentication extension: DUO, TOTP, LDAP/Active Directory, or none.\r\n4. Select optional console features: Quick Connect & History Recorded Storage UI integrations.\r\n5. Select the Guacamole front end: Nginx reverse proxy (HTTP or HTTPS) or use the native Guacamole interface on port 8080.\r\n   - If you opt to install Nginx with self-signed TLS:\r\n     - New server & client browser certificates are saved to `$HOME/guac-setup/tls-certs/[date-time]/`.\r\n     - Optionally follow on-screen instructions for client certificate import to avoid https browser warnings.\r\n\r\n---\r\n\r\n## Customising The Build\r\n\r\n⚙️ **To customise the many available script options:**\r\n\r\n- Exit `1-setup.sh` at the first prompt.\r\n- All configurable script options are shown under **Silent setup options** at the start of `1-setup.sh`. \r\n- Certain combinations of the **Silent setup options** will allow for a fully unattended install supporting mass deployment or highly customised docker builds.\r\n- Re-run your edited script locally after making changes (do not re-run the automatic install web link - see below). \r\n\r\n**Other custom install notes:**\r\n- **Caution:** Re-running the auto-installer link re-downloads the suite of scripts which will overwrite any custom script edits. You must run 1-setup.sh LOCALLY after editing. If any child scripts are edited, their corresponding download links in 1-setup.sh script must also be commented out.\r\n- Upgrade scripts are **automatically customised with your specifc installation settings** for consistent future updates.\r\n- Nginx reverse proxy is configured to default to at least TLS 1.2. For ancient systems, see commented sections of the `/etc/nginx/nginx.conf` file after install.\r\n- A daily MySQL backup job is automatically configured under the script owner's crontab.\r\n- The Quick Connect option brings some extra security implications, be aware of potential risks in your environment.\r\n\r\n**Post-install manual hardening options:**\r\n\r\n- `add-fail2ban.sh`: Adds a lockdown policy for Guacamole to guard against brute force password attacks.\r\n- `add-tls-guac-daemon.sh`: Wraps internal traffic between the guac server & guac application in TLS.\r\n- `add-auth-ldap.sh`: Template script for simplified Active Directory integration.\r\n- `add-smtp-relay-o365.sh`: Template script for email alert integration with MSO65 (BYO app password).\r\n\r\n---\r\n\r\n## Branding The Guacamole UI Theme\r\n\r\n🎨 **Follow the theme and branding instructions** [here](https://github.com/itiligent/Guacamole-Install/tree/main/guac-custom-theme-builder). To revert to the default theme, simply delete the branding.jar file from `/etc/guacamole/extensions`, clear your browser cache and restart.\r\n\r\n---\r\n\r\n## Managing Self-Signed TLS Certs With Nginx\r\n\r\n**To renew self-signed certificates or change the reverse proxy local DNS name/IP address:** \r\n- Re-run `4a-install-tls-self-signed-nginx.sh` to create a new Nginx certificate (new browser client certificates will also be created for re-import). Always clear your browser cache after changing certificates.\r\n\r\n---\r\n\r\n## Active Directory Integration\r\n\r\n🔑 See [here](https://github.com/itiligent/Guacamole-Install/blob/main/ACTIVE-DIRECTORY-HOW-TO.md).\r\n\r\n---\r\n\r\n## SS0 Extensions (Radius, Base, CAS, OpenID, SAML, Dist)\r\n🔑 See [here](https://github.com/itiligent/Guacamole-Installer/blob/main/SSO-EXTENSIONS-HOW-TO.md)\r\n\r\n---\r\n\r\n## Upgrading Guacamole\r\n\r\n🌐 To upgrade Guacamole, edit `upgrade-guacamole.sh` to reflect the latest versions of Guacamole & MySQL connector/J before running. This script will automatically update TOTP, DUO, LDAP, Quick Connect, and History Recorded Storage extensions if present.\r\n\r\n---\r\n\r\n## High Availability Deployment\r\n\r\n- 👔 **For a separate DATABASE layer:** Use the `install-mysql-backend-only.sh` [here](https://github.com/itiligent/Guacamole-Install/tree/main/guac-enterprise-build) to install a standalone instance of the Guacamole MySQL database.\r\n- 👔 **For a separate APPLICATION layer:** Run `1-setup.sh` and point new installations to your separate database instance. Just say **no** to the \"Install MySQL locally\" option and any other local reverse proxy install options.\r\n- 👔 **For a separate FRONT END layer:** Use the included Nginx installer scripts to build out a separate Nginx front end layer, and then apply your preferred TLS load balancing technique. Alternatively, AWS/Azure/GCP load balancers or [HA Proxy](https://www.haproxy.org/) may provide superior session persistence & affinity compared to [Open Source Nginx](https://www.nginx.com/products/nginx/compare-models/).\r\n\r\n---\r\n\r\n### Script Download Manifest\r\n\r\n📦 **The autorun link downloads these files into `$HOME/guac-setup`:**\r\n\r\n- `1-setup.sh`: The parent setup script.\r\n- `2-install-guacamole.sh`: Guacamole source build & installer script.\r\n- `3-install-nginx.sh`: Nginx installation script.\r\n- `4a-install-tls-self-signed-nginx.sh`: Install/refresh self-signed TLS certificates script.\r\n- `4b-install-tls-letsencrypt-nginx.sh`: Let's Encrypt for Nginx installer script.\r\n- `add-auth-duo.sh`: Duo MFA extension install script.\r\n- `add-auth-ldap.sh`: Active Directory extension installer template script.\r\n- `add-auth-totp.sh`: TOTP MFA extension installer script.\r\n- `add-xtra-quickconnect.sh`: Quick Connect console extension installer script.\r\n- `add-xtra-histrecstore.sh`: History Recorded Storage extension installer script.\r\n- `add-smtp-relay-o365.sh`: Script for O365 SMTP auth relay setup (BYO app password).\r\n- `add-tls-guac-daemon.sh`: Wrap internal traffic between guacd server & Guacamole web app in TLS.\r\n- `add-fail2ban.sh`: Fail2ban (& Guacamole protection policy) installer script.\r\n- `backup-guacamole.sh`: MySQL backup setup script.\r\n- `upgrade-guacamole.sh`: Guacamole application, extension, and MySQL connector upgrade script.\r\n- `branding.jar`: Base template for customizing Guacamole's UI theme.\r\n\r\n😄🥑\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n"
  },
  {
    "path": "SSO-EXTENSIONS-HOW-TO.md",
    "content": "\n\n\n### How to build all Guacamole client extensions:\nLicensing prevents some extensions being supplied in binary form, therefore these must be built from source. To achieve this, follow the exact order below on a fresh Linux system **WITHOUT JVM INSTALLED**. \n\n#### 1. Obtain the specific JDK dependency\nDownload jdk-8u411-linux-x64.tar.gz from [Oracle](https://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html) (needs an Oracle sign in, select the Linux x64 compressed archive and copy it to your Linux home dir) A backup of this file is achived [here]( https://1drv.ms/u/s!Asccp3ag4RnQj-dAGYyfqwf-Rf5mTg?e=uRy1DM).\n\n### 2. Install the JDK\n```\nsudo mkdir -p /usr/lib/jvm\nsudo tar zxvf jdk-8u411-linux-x64.tar.gz -C /usr/lib/jvm\nsudo update-alternatives --install \"/usr/bin/java\" \"java\" \"/usr/lib/jvm/jdk1.8.0_411/bin/java\" 1\nsudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_411/bin/java\n```\n### 3. Clone Guacamole client source\n```sudo apt update && sudo apt -y install git\ngit clone https://github.com/apache/guacamole-client.git\ncd guacamole-client\ngit checkout 1.5.5 # or whatever version\n```\n### 4. Install Maven and build all the client binaries (with Radius support)\n```\nsudo apt -y install maven\nmvn clean package -Plgpl-extensions\n```\nBuild output should show:\n```\n[INFO] Reactor Summary for guacamole-client 1.5.5:\n[INFO] guacamole-client ................................... SUCCESS [ 18.363 s]\n[INFO] guacamole-common ................................... SUCCESS [ 10.902 s]\n[INFO] guacamole-ext ...................................... SUCCESS [  6.032 s]\n[INFO] guacamole-common-js ................................ SUCCESS [ 14.552 s]\n[INFO] guacamole .......................................... SUCCESS [01:04 min]\n[INFO] extensions ......................................... SUCCESS [  0.132 s]\n[INFO] guacamole-auth-duo ................................. SUCCESS [  5.207 s]\n[INFO] guacamole-auth-header .............................. SUCCESS [  0.793 s]\n[INFO] guacamole-auth-jdbc ................................ SUCCESS [  0.143 s]\n[INFO] guacamole-auth-jdbc-base ........................... SUCCESS [  3.314 s]\n[INFO] guacamole-auth-jdbc-mysql .......................... SUCCESS [  1.208 s]\n[INFO] guacamole-auth-jdbc-postgresql ..................... SUCCESS [  1.008 s]\n[INFO] guacamole-auth-jdbc-sqlserver ...................... SUCCESS [  1.004 s]\n[INFO] guacamole-auth-jdbc-dist ........................... SUCCESS [  1.072 s]\n[INFO] guacamole-auth-json ................................ SUCCESS [  2.648 s]\n[INFO] guacamole-auth-ldap ................................ SUCCESS [  8.882 s]\n[INFO] guacamole-auth-quickconnect ........................ SUCCESS [  1.704 s]\n[INFO] guacamole-auth-sso ................................. SUCCESS [  0.132 s]\n[INFO] guacamole-auth-sso-base ............................ SUCCESS [  0.667 s]\n[INFO] guacamole-auth-sso-cas ............................. SUCCESS [  5.205 s]\n[INFO] guacamole-auth-sso-openid .......................... SUCCESS [  1.237 s]\n[INFO] guacamole-auth-sso-saml ............................ SUCCESS [  3.801 s]\n[INFO] guacamole-auth-sso-dist ............................ SUCCESS [  1.312 s]\n[INFO] guacamole-auth-totp ................................ SUCCESS [  2.780 s]\n[INFO] guacamole-history-recording-storage ................ SUCCESS [  0.646 s]\n[INFO] guacamole-vault .................................... SUCCESS [  0.117 s]\n[INFO] guacamole-vault-base ............................... SUCCESS [  1.005 s]\n[INFO] guacamole-vault-ksm ................................ SUCCESS [  5.242 s]\n[INFO] guacamole-vault-dist ............................... SUCCESS [  1.050 s]\n[INFO] guacamole-auth-radius .............................. SUCCESS [ 11.777 s] \n[INFO] guacamole-example .................................. SUCCESS [  2.080 s]\n[INFO] guacamole-playback-example ......................... SUCCESS [  0.883 s]\n[INFO] ------------------------------------------------------------------------\n[INFO] BUILD SUCCESS\n[INFO] ------------------------------------------------------------------------\n[INFO] Total time:  02:59 min\n[INFO] Finished at: 2024-10-29T11:38:19+11:00\n[INFO] ------------------------------------------------------------------------\n```\n\n### 5 Move your new extension to the Guacamole server  \n1. As sudo, copy the new `extension.jar` file (found in `guacamole-client/extensions/guacamole-auth-radius/target/`) to `/etc/guacamole/extensions` on your Guacamole server.\n2. Adjust permissions on the new `extension.jar` file with `sudo chmod 664 /etc/guacamole/extensions/extension.jar`\n3. Restart and continue configuring the new extension as per the Guacmole official documentation [here](https://guacamole.apache.org/doc/gug/).\n"
  },
  {
    "path": "guac-custom-theme-builder/META-INF/MANIFEST.MF",
    "content": "Manifest-Version: 1.0\nName: branding\nSpecification-Title: Custom Guacamole Theme CSS\nSpecification-Version: 1.0\nImplementation-Title: Custom Guacamole Theme CSS\nImplementation-Version: 1.0\n\n\n"
  },
  {
    "path": "guac-custom-theme-builder/README.MD",
    "content": "\n## Custom branding & theme instructions ##\n\n1. Install the Java JDK: `sudo apt update && sudo apt -y install default-jdk`\n3. Modify `custom-theme.css` ,`guac-manifest.json`, `en.json` & `META-INF` as desired & add your logos to the images directory. (Logos must be .png files.) \n4. To commit your changes, run the below commands from within the custom-theme-builder directory, then refresh your browser to re-login to Guacamole:\n```\n# Run within the custom-theme-builder directory \njar cfmv branding.jar META-INF/MANIFEST.MF guac-manifest.json css images translations META-INF\nsudo mv branding.jar /etc/guacamole/extensions \nsudo chmod 664 /etc/guacamole/extensions/branding.jar \nTOMCAT=$(ls /etc/ | grep tomcat)\nsudo systemctl restart guacd && sudo systemctl restart ${TOMCAT}\n```\n\n## Theme customisation hints: ##\n  - Do not change any of the theme's directory structure or file names. File contents can be carefully edited according to the following constraints:\n      - `META-INF/MANIFEST.MF`: All values in here can be updated, **BUT** be aware that `Name: branding` is linked to the commands above e.g. `Name: branding` expects `branding.jar` as the .jar filename\n      - `guac-manifest.json`: The \"name:\" value in here can be changed to anything **BUT** the `\"namespace\" : \"custom-namespace\"` value MUST match the namespace image path line found in `custom-theme.css`, eg:\n```\n.login-ui .login-dialog .logo {\n    background-image: url('app/ext/custom-namespace/images/logo.png');\n    width: 7em;\n    height:\t7em;\n    -webkit-background-size: 7em auto;\n\n}\n```\n  - It is preferable to give css a range of logo sizes as shown in the template. The \"smallIcon\" value in `guac-manifest.json` is used for browser tab favicons. As such this file can be kept to < 80x80 pixels. The example used is 64x64 pixels.\n  - Within `custom-theme.css`, you may need to experiment with the the height and width values under `.login-ui .login-dialog .logo` to scale your particular logo neatly within the dialog box. Another option is to make the login dialog box larger. Under `.login-ui .login-dialog`, experiment with adding a `max-width: 4in;` or similar. There's a ton of css options available and this template is just starting point, Google is your friend!\n  - An easy way to debug and preview potential style changes is to tweak various values by setting your browser to developer mode. \n  - Your changes may occasionally appear not to update, if so clear your browser cache before doing any further debugging.\n"
  },
  {
    "path": "guac-custom-theme-builder/css/custom-theme.css",
    "content": "/* Colour codes used */\n/*    Guacamole grassy green: #88bf5b */\n/*    Warning red #ff2233 */\n/*    Main background charcoal #3f3f3f */\n/*    Input fields dark charcoal #2b2b2b */\n/*    Login dialog background black #000000 */\n/*    All text: #ececec */\n\n\n/* General Style */\nbody {\n    color: #ececec;\n    background-color: #3f3f3f;\n}\npre {\n    color: #ececec;\n    background-color: #2b2b2b;\n    border: 1px solid #000000;\n}\n\na[href]:visited {\n    color: #88bf5b;\n}\na[href] {\n    color: #88bf5b;\n}\n\ndiv.location,\ninput[type=text],\ninput[type=email],\ninput[type=number],\ninput[type=password],\ntextarea {\n    background-color: #2b2b2b;\n    color: #ececec;\n}\n\n\n/* Login */\ndiv.login-ui {\n    color: #ececec;\n    background-color: #3f3f3f;\n}\n.login-ui .login-fields .labeled-field input:focus {\n    background-color: #3f3f3f;\n    color: #ececec;\n}\n\n.login-ui .login-fields .labeled-field {\n    background-color: #3f3f3f;\n    color: #ececec;\n}\n\n.login-ui .login-dialog .logo {\n    background-image: url('app/ext/custom-namespace/images/logo.png');\n    width: 7em;\n    height:\t7em;\n    -webkit-background-size: 7em auto;\n\n}\n\n.login-ui .login-dialog {\n    background-color: #000000;\n    color: #ececec;\n}\n\n.login-ui .login-dialog .version .app-name {\n    font-weight: 300;\n    text-transform: none;\n    text-align: center;\n    font-size: 2.25em;\n    color: #ececec;\n    font-family: arial black, sans-serif;\n}\n\ndiv.logged-out-modal .ng-scope {\n    color: #ececec;\n    background-color: #000000;\n}\n\ndiv.logged-out-modal .ng-scope button {\n    color: #ececec;\n    background-color: #3f3f3f;\n    border: 1px solid #ececec;\n}\n\ndiv.modal-contents {\n    color: #ececec;\n    background-color: #3f3f3f;\n}\n\n.logged-out-modal guac-modal {\n    color: #ececec;\n    background-color: #3f3f3f;\n}\n\ndiv.notification.ng.scope {\n    border: 1px solid #ececec;\n}\n\n.notification.error {\n    background-color: #ff2233;\n}\n\n.client-status-modal .notification.error {\n    background-color: #ff2233;\n}\n\nbutton.danger {\n    background: #ff2233;\n }\n\n.login-ui.error p.login-error {\n    color: #ececec;\n    background-color: #ff2233;\n}\n\n\n/* Home */\n.recent-connections .connection:hover {\n    background-color: #88bf5b;\n}\n\n.menu-dropdown .menu-contents {\n    background-color: #2b2b2b;\n}\n.menu-dropdown .menu-contents li a {\n    color: #ececec;\n}\n.menu-dropdown .menu-contents li a:hover {\n    background-color: #88bf5b;\n}\n\n.list-item.selected {\n    background: #88bf5b\n}\n.list-item:not(.selected) .caption:hover {\n    background-color: #88bf5b;\n}\n.list-item .name {\n    color: #ececec;\n}\n\n.settings.connections .connection-list .new-sharing-profile {\n    opacity: .6;\n}\n\n.notification {\n    color: #ececec;\n    background-color: #2b2b2b;\n}\n\n\n/* Menus */\n.menu {\n    color: #ececec;\n    background-color: #3f3f3f;\n}\n\n.clipboard,\n.clipboard-service-target {\n    background-color: #2b2b2b;\n    color: #88bf5b;\n}\n\n.menu-dropdown .menu-contents li a.danger {\n    color: #ececec;\n    font-weight: 700;\n    background-color: #ff2233;\n}\n\n/* Connections */\n#connection-warning {\n    background-color: #3f3f3f;\n}\n\n.transfer-manager {\n    background-color: #2b2b2b;\n}\n.transfer.error {\n    background-color: #ff2233;\n}\n\n\n/* Settings */\n.page-tabs .page-list li a[href],\n.section-tabs li a {\n    color: #ececec;\n}\n.page-tabs .page-list li a[href]:hover,\n.section-tabs li a:hover {\n    background-color: #88bf5b;\n}\n.page-tabs .page-list li a[href]:visited {\n    color: #ececec;\n}\n\n.settings table.session-list tr.session:hover {\n    background-color: #88bf5b;\n}\n\n.location-chooser .dropdown {\n    background-color: #2b2b2b;\n}\n\n.settings.connectionHistory a.history-session-recording {\n    color: #88bf5b;\n}\n\n.settings.connectionHistory a.history-session-recording:after {\n    opacity: .0;\n}\n\n.user a,\n.user-group a,\n.connection a,\n.connection-group a {\n    color: #ececec;\n}\n.user a:hover,\n.user-group a:hover,\n.connection a:hover,\n.connection-group a:hover {\n    color: #ececec;\n}\n.user a:visited,\n.user-group a:visited,\n.connection a:visited,\n.connection-group a:visited {\n    color: #ececec;\n}\n\n.manage-user .notice.read-only {\n    color: #ececec;\n    background-color: #2b2b2b;\n}\n\n#filesystem-menu .header.breadcrumbs .breadcrumb:hover {\n    background-color: #88bf5b;\n}\n\n#guac-menu #zoom-out:hover,\n#guac-menu #zoom-in:hover {\n    background-color: #88bf5b;\n}\n"
  },
  {
    "path": "guac-custom-theme-builder/guac-manifest.json",
    "content": "{\n\n        \"guacamoleVersion\" : \"*\",\n        \"name\" : \"Custom Guacamole Theme\",\n        \"namespace\" : \"custom-namespace\",\n        \"smallIcon\" : \"images/logo-64.png\",\n        \"largeIcon\" : \"images/logo-144.png\",\n        \"translations\" : [ \n        \"translations/en.json\"\n     ],\n\n     \"css\" : [\n                \"css/custom-theme.css\"\n         ],\n\n     \"resources\" : {\n                \"images/logo.png\" : \"image/png\",\n                \"images/logo-64.png\" : \"image/png\",\n                \"images/logo-144.png\" : \"image/png\"\n         }\n}\n\n"
  },
  {
    "path": "guac-custom-theme-builder/translations/en.json",
    "content": "{\n    \"NAME\" : \"English\",\n\t\t\n    \"APP\":{\n\t\n\t\"NAME\" : \"Itiligent\" \n\t  }\n}\n"
  },
  {
    "path": "guac-enterprise-build/install-mysql-backend-only.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Guacamole MySQL backend install script. (For split DB and guacamole application layers.\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# September 2023\n#######################################################################################################################\n\n# This script is for separating the Guacamole architecture into a scaled out three tiered system.\n# Layer 1 = DATABASE - This script\n# Layer 2 = GUAC SERVER & APPLICATION - use the main setup script, and select remote MYSQL DB option.\n# Layer 3 = FRONT END REV PROXY (Potentially load balanced & HA) - Up to you!\n\n#######################################################################################################################\n# Script pre-flight checks and settings ###############################################################################\n#######################################################################################################################\n\nclear\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\n# Check if user is root or sudo\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\n\n# Check to see if any previous version of build/install files exist, if so stop and check to be safe.\nif [[ \"$(find . -maxdepth 1 \\( -name 'guacamole-*' -o -name 'mysql-connector-j-*' \\))\" != \"\" ]]; then\n    echo\n    echo -e \"${LRED}Possible previous install files detected. Please review and remove old guacamole install files before proceeding.${GREY}\" 1>&2\n    echo\n    exit 1\nfi\n\n#######################################################################################################################\n# Initial environment setup ###########################################################################################\n#######################################################################################################################\n\n#Setup download and temp directory paths\nUSER_HOME_DIR=$(eval echo ~${SUDO_USER})\nDOWNLOAD_DIR=$USER_HOME_DIR/guac-setup\n\n# Setup directory locations\nmkdir -p $DOWNLOAD_DIR\nchown -R $SUDO_USER:root $DOWNLOAD_DIR\n\n# Version of Guacamole auth jdbc database schema to use\nGUAC_VERSION=\"1.5.5\"\n\n# Set preferred Apache CDN download link)\nGUAC_SOURCE_LINK=\"http://apache.org/dyn/closer.cgi?action=download&filename=guacamole/${GUAC_VERSION}\"\n\n# Install log Location\nINSTALL_LOG=\"${DOWNLOAD_DIR}/mysql_install.log\"\n\nclear\n\n# Script branding header\necho\necho -e \"${GREYB}Guacamole Backend MySQL Setup.\"\necho -e \"             ${LGREEN}Powered by Itiligent\"\necho\necho\n\n#######################################################################################################################\n# Setup options. ######################################################################################################\n#######################################################################################################################\n\nBACKEND_MYSQL=\"true\"       # True: For separated MySQL layer. False/blank: Add MySQL to existing guac server (replace XML user map)\nFRONTEND_NET=\"\"            # IPs guac server can login from. Blank = any IP or wildcard 192.168.1.% (ignored if BACKEND_SQL=\"false\")\nMYSQL_BIND_ADDR=\"0.0.0.0\"  # Binds MySQL instance to this IP. (127.0.0.1, a specific IP or 0.0.0.0) (ignored if BACKEND_SQL=\"false\")\nSECURE_MYSQL=\"true\"        # Apply the mysql secure configuration tool (true/false)\nMYSQL_PORT=\"3306\"          # Default is 3306\nGUAC_DB=\"guacamole_db\"     # Default is guacamole_db\nGUAC_USER=\"guacamole_user\" # Default is guacamole_user\nGUAC_PWD=\"test\"            # Requires an entry\nMYSQL_ROOT_PWD=\"test\"      # Requires an entry.\nDB_TZ=$(cat /etc/timezone) # Typically system default (cat /etc/timezone) or change to \"UTC\" if required.\nMYSQL_VERSION=\"\"           # Blank \"\" will use distro default MySQL packages. Enter a specific MySQL version for official Maria repo eg. 11.1.2. See https://mariadb.org/mariadb/all-releases/ for available versions.\n\n# For a remotely accessed back end DB instance, keep this script set to BACKEND_MYSQL=\"true\".\n# Other options are fairly straight forward. For a typical back end server only the $FRONTEND_NET and $MYSQL_BIND_ADDR\n# values may need closer attention.\n\n# This script can also accommodate DR or migration scenarios: E.g Migration away from XML user mappings, PostGres to MySQL etc).\n# To install a new MySQL database on the same server as the Guacamole application, set BACKEND_MYSQL=\"false\" &\n# MYSQL_BIND_ADDR=\"127.0.0.1\". See bottom of this script for some remaining DB migration actions.\n\n#######################################################################################################################\n# Start install actions  ##############################################################################################\n#######################################################################################################################\n\n# Standardise on a lexicon for the different MySQL package options\nif [[ -z \"${MYSQL_VERSION}\" ]]; then\n    # Use Linux distro default version.\n    MYSQLPKG=\"default-mysql-server default-mysql-client mysql-common\"\n    DB_CMD=\"mysql\" # mysql command is depricated\nelse\n    # Use official mariadb.org repo\n    MYSQLPKG=\"mariadb-server mariadb-client mariadb-common\"\n    DB_CMD=\"mariadb\" # mysql command is depricated on newer versions\nfi\n\n# Update everything but don't do the annoying prompts during apt installs\necho -e \"${GREY}Updating base Linux OS...\"\nexport DEBIAN_FRONTEND=noninteractive\napt-get update -qq &>>${INSTALL_LOG}\napt-get upgrade -qq -y &>>${INSTALL_LOG}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\ncd $DOWNLOAD_DIR\n\n# Add the official MariaDB repo\nif [[ -n \"${MYSQL_VERSION}\" ]]; then\n    apt-get -qq -y install curl gnupg2 &>>${INSTALL_LOG}\n    curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup &>>${INSTALL_LOG}\n    bash mariadb_repo_setup --mariadb-server-version=$MYSQL_VERSION &>>${INSTALL_LOG}\nfi\n\n# Download and extract the Guacamole SQL authentication extension containing the database schema\necho -e \"${GREY}Downloading Guacamole database source files...\"\nwget -q --show-progress -O guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed to download guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz\" 1>&2\n    echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz\"\n    exit 1\nelse\n    tar -xzf guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz\nfi\necho -e \"${LGREEN}Downloaded guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz${GREY}\"\n\necho\necho -e \"${GREY}Installing MySQL packages...\"\napt-get -qq -y install ${MYSQLPKG} &>>${INSTALL_LOG}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Set the MySQL root password without a reliance on debconf (may not be present in all distros).\necho -e \"${GREY}Setting MySQL root password...\"\nSQLCODE=\"\nFLUSH PRIVILEGES;\nALTER USER 'root'@'localhost' IDENTIFIED BY '$MYSQL_ROOT_PWD';\"\necho ${SQLCODE} | $DB_CMD -u root\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# A simple method to find the correct file containing the default MySQL timezone setting from a potential list of candidates.\n# and then update that timzone value. Add to this array if your distro uses a different path to the .cnf contaiing the default_time_zone value.\nfor x in /etc/mysql/mariadb.conf.d/50-server.cnf \\\n    /etc/mysql/mysql.conf.d/mysqld.cnf \\\n    /etc/mysql/my.cnf; do\n    # Check inside each candidate to see if a [mysqld] or [mariadbd] section exists, assign $x the correct filename.\n    if [[ -e \"${x}\" ]]; then\n        if grep -qE '^\\[(mysqld|mariadbd)\\]$' \"${x}\"; then\n            mysqlconfig=\"${x}\"\n            # Reduce any duplicated section names, then sanitise the [ ] special characters for sed below)\n            config_section=$(grep -m 1 -E '^\\[(mysqld|mariadbd)\\]$' \"${x}\" | sed 's/\\[\\(.*\\)\\]/\\1/')\n            break\n        fi\n    fi\ndone\n\n# Set the MySQL Timezone\nif [[ -z \"${mysqlconfig}\" ]]; then\n    echo -e \"${GREY}Couldn't detect MySQL config file - you will need to manually configure database timezone settings\"\nelse\n    # Is there already a timzeone value configured?\n    if grep -q \"^default_time_zone[[:space:]]=\" \"${mysqlconfig}\"; then\n        echo -e \"MySQL database timezone defined in ${mysqlconfig}\"\n    else\n        timezone=${DB_TZ}\n        if [[ -z \"${DB_TZ}\" ]]; then\n            echo -e \"Couldn't find system timezone, using UTC$\"\n            timezone=\"UTC\"\n        fi\n        echo -e \"Setting MySQL database timezone as ${timezone}${GREY}\"\n        mysql_tzinfo_to_sql /usr/share/zoneinfo 2>/dev/null | ${DB_CMD} -u root -D mysql -p${MYSQL_ROOT_PWD}\n        # Add the timzone value to the sanitsed server file section name.\n        sed -i -e \"/^\\[${config_section}\\]/a default_time_zone = ${timezone}\" \"${mysqlconfig}\"\n    fi\nfi\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Establish the appropriate form of Guacamole user account access (remote or localhost login permissions)\necho -e \"${GREY}Setting up database access parameters for the Guacamole user ...\"\nif [[ \"${BACKEND_MYSQL}\" = true ]] && [[ -z \"${FRONTEND_NET}\" ]]; then\n    echo -e \"${LYELLOW}${GUAC_USER} is set to accept db logins from any host, you may wish to limit this to specific IPs.${GREY}\"\n    GUAC_USERHost=\"%\" # Allow guacamole access from all IPs where $FRONTEND_NET is left blank\nelif [[ \"${BACKEND_MYSQL}\" = true ]] && [[ -n \"${FRONTEND_NET}\" ]]; then\n    echo -e \"${LYELLOW}${GUAC_USER} is set to accept db logins from ${FRONTEND_NET}.${GREY}\"\n    GUAC_USERHost=\"${FRONTEND_NET}\" # Allow guacamole access from the given value in $FRONTEND_NET\nelif [[ \"${BACKEND_MYSQL}\" = false ]] || [[ -z \"${BACKEND_MYSQL}\" ]]; then\n    echo -e \"${LYELLOW}${GUAC_USER} is set to accept db logins from localhost only.${GREY}\"\n    GUAC_USERHost=localhost # Assume a localhost only install\n    MYSQL_BIND_ADDR=\"127.0.0.1\"\nelse\n    echo -e \"${LYELLOW}${GUAC_USER} is set to accept db logins from localhost only.${GREY}\"\n    GUAC_USERHost=localhost # Assume a localhost only install\nfi\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Set the MySQL binding IP address according to setup variables given.\necho -e \"${GREY}Setting MySQL IP address binding to ${MYSQL_BIND_ADDR}...\"\nsed -i \"s/^bind-address[[:space:]]*=[[:space:]]*.*/bind-address = ${MYSQL_BIND_ADDR}/g\" ${mysqlconfig}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Create the new Guacamole database\necho -e \"${GREY}Creating the Guacamole database...\"\nSQLCODE=\"\nDROP DATABASE IF EXISTS ${GUAC_DB};\nCREATE DATABASE IF NOT EXISTS ${GUAC_DB};\nCREATE USER IF NOT EXISTS '${GUAC_USER}'@'${GUAC_USERHost}' IDENTIFIED BY \\\"${GUAC_PWD}\\\";\nGRANT SELECT,INSERT,UPDATE,DELETE ON ${GUAC_DB}.* TO '${GUAC_USER}'@'${GUAC_USERHost}';\nFLUSH PRIVILEGES;\"\n# Execute SQL code\necho ${SQLCODE} | $DB_CMD -u root -D mysql -p${MYSQL_ROOT_PWD}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Add Guacamole's schema code to newly created database\necho -e \"${GREY}Adding the Guacamole database schema...\"\ncat guacamole-auth-jdbc-${GUAC_VERSION}/mysql/schema/*.sql | $DB_CMD -u root -D ${GUAC_DB} -p${MYSQL_ROOT_PWD}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Apply Secure MySQL installation settings\nif [[ \"${SECURE_MYSQL}\" = true ]]; then\n    apt-get -qq -y install expect &>>${INSTALL_LOG}\n    echo -e \"${GREY}Applying mysql_secure_installation settings...${DGREY}\"\n    SECURE_MYSQL=$(expect -c \"\nset timeout 10\nspawn mysql_secure_installation\nexpect \\\"Enter current password for root (enter for none):\\\"\nsend \\\"$MYSQL_ROOT_PWD\\r\\\"\nexpect \\\"Switch to unix_socket authentication\\\"\nsend \\\"n\\r\\\"\nexpect \\\"Change the root password?\\\"\nsend \\\"n\\r\\\"\nexpect \\\"Remove anonymous users?\\\"\nsend \\\"y\\r\\\"\nexpect \\\"Disallow root login remotely?\\\"\nsend \\\"y\\r\\\"\nexpect \\\"Remove test database and access to it?\\\"\nsend \\\"y\\r\\\"\nexpect \\\"Reload privilege tables now?\\\"\nsend \\\"y\\r\\\"\nexpect eof\n\")\n    echo \"$SECURE_MYSQL\"\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Restart & enable MySQL service at boot\necho -e \"${GREY}Restarting MySQL service & enable at boot...\"\nsystemctl enable mysql\nsystemctl restart mysql\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Cleanup\necho -e \"${GREY}Cleaning up install files...${GREY}\"\napt-get -y remove expect &>>${INSTALL_LOG}\napt-get -y autoremove &>>${INSTALL_LOG}\nrm -rf guacamole-*\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${LOG_LOCATION}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Done\necho\nprintf \"${LGREEN}Guacamole ${GUAC_VERSION} MySQL backend install complete! \\n${NC}\"\necho -e ${NC}\n\n#######################################################################################################################\n# Additional migration steps for adding MySQL to an existing Guacamole application server\n#######################################################################################################################\n\n# Download and upgrade Guacamole SQL authentication extension\n#wget -q --show-progress -O guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz\n#tar -xzf guacamole-auth-jdbc-${GUAC_VERSION}.tar.gz\n#rm /etc/guacamole/extensions/guacamole-auth-jdbc-*.jar\n#mv -f guacamole-auth-jdbc-${GUAC_VERSION}/mysql/guacamole-auth-jdbc-mysql-${GUAC_VERSION}.jar /etc/guacamole/extensions/\n#chmod 664 /etc/guacamole/extensions/guacamole-auth-jdbc-mysql-${GUAC_VERSION}.jar\n\n# Download MySQL connector/j\n# MYSQLJCON=\"8.1.0\"\n#wget -q --show-progress -O mysql-connector-j-${MYSQLJCON}.tar.gz https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-j-${MYSQLJCON}.tar.gz\n#tar -xzf mysql-connector-j-${MYSQLJCON}.tar.gz\n#rm /etc/guacamole/lib/mysql-connector-java.jar\n#mv -f mysql-connector-j-${MYSQLJCON}/mysql-connector-j-${MYSQLJCON}.jar /etc/guacamole/lib/mysql-connector-java.jar\n\n# Configure guacamole.properties file\n#rm -f /etc/guacamole/guacamole.properties\n#touch /etc/guacamole/guacamole.properties\n#echo \"mysql-hostname: ${MYSQL_HOST}\" >>/etc/guacamole/guacamole.properties\n#echo \"mysql-port: ${MYSQL_PORT}\" >>/etc/guacamole/guacamole.properties\n#echo \"mysql-database: ${GUAC_DB}\" >>/etc/guacamole/guacamole.properties\n#echo \"mysql-username: ${GUAC_USER}\" >>/etc/guacamole/guacamole.properties\n#echo \"mysql-password: ${GUAC_PWD}\" >>/etc/guacamole/guacamole.properties\n"
  },
  {
    "path": "guac-enterprise-build/upgrade-mysql-backend-only.sh",
    "content": "#!/bin/bash\n######################################################################################################################\n# Guacamole appliance mysql upgrade script\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n### IMPORTANT ###\n# Update you MySQL database packages separately first via your package manager first \n# You only need to run this script if the Guacamole schema have changed between versions (this has not been updated since late 2021 with 1.0, suggesting \n# that Guacamole is now quite mature and changes may be rare in future. \n# To acertain if there are schema changes required for an upgraded version, check inside the guacamole-auth-jdbc-GUAC_VERSION.tar.gz \n# file under /mysql/schema/upgrade/ to find any relevant updates. Only run this script if there are. \n\n#######################################################################################################################\n# Script pre-flight checks and settings ###############################################################################\n#######################################################################################################################\n\nclear\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\n# Check if user is root or sudo\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\n\n# Check to see if any previous version of build/install files exist, if so stop and check to be safe.\nif [[ \"$(find . -maxdepth 1 \\( -name 'guacamole-*' -o -name 'mysql-connector-j-*' \\))\" != \"\" ]]; then\n    echo\n    echo -e \"${LRED}Possible previous install files detected. Please review and remove old guacamole install files before proceeding.${GREY}\" 1>&2\n    echo\n    exit 1\nfi\n\n#######################################################################################################################\n# Initial environment setup ###########################################################################################\n#######################################################################################################################\n\n#Setup download and temp directory paths\nUSER_HOME_DIR=$(eval echo ~${SUDO_USER})\nDOWNLOAD_DIR=$USER_HOME_DIR/guac-setup\n\n# Setup directory locations\nmkdir -p $DOWNLOAD_DIR\nchown -R $SUDO_USER:root $DOWNLOAD_DIR\n\n# Version of Guacamole to upgrade to. See https://guacamole.apache.org/releases/ for latest version info.\nNEW_GUAC_VERSION=\"1.5.5\"\n\n# The currently installed Guacamole schema version is needed to evaluate the required schema upgrades.\nOLD_GUAC_VERSION=\"1.5.4\"\n\n# Set preferred Apache CDN download link)\nGUAC_SOURCE_LINK=\"http://apache.org/dyn/closer.cgi?action=download&filename=guacamole/${NEW_GUAC_VERSION}\"\n\n# Install log Location\nINSTALL_LOG=\"${DOWNLOAD_DIR}/mysql_upgrade.log\"\n\n# Database details\nGUAC_DB=\"guacamole_db\"\nMYSQL_ROOT_PWD=\"test\"\n\nclear\n\n# Script branding header\necho\necho -e \"${GREYB}Guacamole Backend MySQL Schema UPGRADE.\"\necho -e \"                      ${LGREEN}Powered by Itiligent${GREY}\"\necho\necho\n\n#######################################################################################################################\n# Start install actions  ##############################################################################################\n#######################################################################################################################\n\n\n# Download and extract the Guacamole SQL authentication extension containing the database schema\nwget -q --show-progress -O guacamole-auth-jdbc-${NEW_GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-jdbc-${NEW_GUAC_VERSION}.tar.gz\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed to download guacamole-auth-jdbc-${NEW_GUAC_VERSION}.tar.gz\" 1>&2\n    echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-jdbc-${NEW_GUAC_VERSION}.tar.gz\"\n    exit 1\nelse\n    tar -xzf guacamole-auth-jdbc-${NEW_GUAC_VERSION}.tar.gz\nfi\n\necho\n# Get list of SQL Upgrade Files\necho -e \"${GREY}Upgrading MySQL Schema...\"\nUPGRADEFILES=($(ls -1 guacamole-auth-jdbc-${NEW_GUAC_VERSION}/mysql/schema/upgrade/ | sort -V))\n\n# Compare SQL Upgrage Files against old version, apply upgrades as needed\nfor FILE in ${UPGRADEFILES[@]}; do\n    FILEVERSION=$(echo ${FILE} | grep -oP 'upgrade-pre-\\K[0-9\\.]+(?=\\.)')\n    if [[ $(echo -e \"${FILEVERSION}\\n${OLD_GUAC_VERSION}\" | sort -V | head -n1) == ${OLD_GUAC_VERSION} && ${FILEVERSION} != ${OLD_GUAC_VERSION} ]]; then\n        echo \"Patching ${GUAC_DB} with ${FILE}\"\n        mariadb -u root -D ${GUAC_DB} -p${MYSQL_ROOT_PWD} <guacamole-auth-jdbc-${NEW_GUAC_VERSION}/mysql/schema/upgrade/${FILE} &>>${INSTALL_LOG}\n    fi\ndone\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}SQL upgrade failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Restart MySQL service\necho -e \"${GREY}Restarting MySQL service...\"\nsystemctl restart mysql\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Cleanup\necho -e \"${GREY}Clean up install files...${GREY}\"\nrm -rf guacamole-*\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Done\nprintf \"${LGREEN}Guacamole ${NEW_GUAC_VERSION} schema upgrade complete - check log for details! \\n${NC}\"\necho -e ${NC}\n"
  },
  {
    "path": "guac-management/backup-guacamole.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Guacamole MySQL Database Backup\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\nclear\n\nexport PATH=/bin:/usr/bin:/usr/local/bin\nTODAY=$(date +%Y-%m-%d)\n# Below variables are automatically updated by the 1-setup.sh script with the respective values given at install (manually update if blank)\nMYSQL_HOST=\nMYSQL_PORT=\nGUAC_USER=\nGUAC_PWD=\nGUAC_DB=\nDB_BACKUP_DIR=\nBACKUP_EMAIL=\nBACKUP_RETENTION=\n\n# Protect disk space and remove backups older than {BACKUP_RETENTION} days\nfind ${DB_BACKUP_DIR} -type f -name \"*.gz\" -mtime +${BACKUP_RETENTION} -delete\n\n# Backup code\nmkdir -p ${DB_BACKUP_DIR}\necho\necho -e \"${LGREEN}Backup started for database - ${GUAC_DB}\"\necho\n\nmysqldump -h ${MYSQL_HOST} \\\n    -P ${MYSQL_PORT} \\\n    -u ${GUAC_USER} \\\n    -p\"${GUAC_PWD}\" \\\n    ${GUAC_DB} \\\n    --single-transaction --quick --lock-tables=false >${DB_BACKUP_DIR}/${GUAC_DB}-${TODAY}.sql\nSQLFILE=${DB_BACKUP_DIR}/${GUAC_DB}-${TODAY}.sql\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Backup failed.${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}Backup completed ok.${GREY}\"\n    echo\nfi\ngzip -f ${SQLFILE}\n# Error check and email alerts\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Backup failed.${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}${GUAC_DB} backup was successfully copied to ${DB_BACKUP_DIR}\"\n    echo \"${GUAC_DB} backup was successfully copied to $DB_BACKUP_DIR\" | mailx -s \"Guacamole backup \" ${BACKUP_EMAIL}\nfi\n\necho -e ${NC}\n"
  },
  {
    "path": "guac-management/refresh-tls-self-signed.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Create or refresh self signed TLS certificates for Nginx (or others)\n# For Ubuntu / Debian / Rasbpian\n# David Harrop\n# September 2023\n#######################################################################################################################\n\n# If run with with no command arguments, the ${PROXY_SITE}, ${CERT_DAYS} & ${Default_IP) values used during the \n# the original install are applied. To keep these run: sudo ./refresh-tls-self-signed-nginx.sh\n#\n# This script can also be run with custom command line arguments for use with any TLS application:\n#      Command arguments are formatted as: [command] [FQDN] [cert-lifetime] [IP]\n#      e.g. sudo ./refresh-tls-self-signed-nginx.sh webserver.domain.local 365 192.168.1.1\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\n# Check if user is root or sudo\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    echo\n    exit 1\nfi\n\necho\necho\necho -e \"${LGREEN}Cresting self signed TLS certificates for Nginx...${GREY}\"\necho\n\n# Create a place to save the certs so we don't overwrite any earlier versions\nUSER_HOME_DIR=$(eval echo ~${SUDO_USER})\nCERT_DIR_NAME=tls-certs-$(date +%y.%m.%d)\nCERT_DIR=$USER_HOME_DIR/guac-setup/$CERT_DIR_NAME\nmkdir -p $CERT_DIR\ncd $CERT_DIR\n\n# Set default certificate file destinations. Change these for other TLS applications.\nDIR_SSL_KEY=\"/etc/nginx/ssl/private\"\nDIR_SSL_CERT=\"/etc/nginx/ssl/cert\"\n\n# Cmd line arguments for dns name, certificate days and IP address\nTLSNAME=$1\nTLSDAYS=$2\nTLSIP=$3\n\n# Below variables are automatically updated by the 1-setup.sh script with the respective values given at install (manually update if blank)\nCERT_COUNTRY=\nCERT_STATE=\nCERT_LOCATION=\nCERT_ORG=\nCERT_OU=\nPROXY_SITE=\nCERT_DAYS=\nDEFAULT_IP=\nRSA_KEYLENGTH=\n\n# Assume the values set by the main installer if the script is run without any command line options\nif [[ -z \"$1\" ]] || [[ -z \"$2\" ]] || [[ -z \"$3\" ]]; then\n    TLSNAME=$PROXY_SITE\n    TLSDAYS=$CERT_DAYS\n    TLSIP=$DEFAULT_IP\nfi\n\n# Make directories to place TLS Certificate if they don't exist\nif [[ ! -d $DIR_SSL_KEY ]]; then\n    mkdir -p $DIR_SSL_KEY\nfi\n\nif [[ ! -d $DIR_SSL_CERT ]]; then\n    mkdir -p $DIR_SSL_CERT\nfi\n\necho -e \"${GREY}New self signed TLS certificate attributes are shown below...${DGREY}\"\n# Display the new TLS cert parameters.\ncat <<EOF | tee cert_attributes.txt\n[req]\ndistinguished_name  = req_distinguished_name\nx509_extensions     = v3_req\nprompt              = no\nstring_mask         = utf8only\n\n[req_distinguished_name]\nC                   = $CERT_COUNTRY\nST                  = $CERT_STATE\nL                   = $CERT_LOCATION\nO                   = $CERT_ORG\nOU                  = $CERT_OU\nCN                  = *.$(echo $TLSNAME | cut -d. -f2-)\n\n[v3_req]\nkeyUsage            = nonRepudiation, digitalSignature, keyEncipherment\nextendedKeyUsage    = serverAuth, clientAuth, codeSigning, emailProtection\nsubjectAltName      = @alt_names\n\n[alt_names]\nDNS.1               = $TLSNAME\nDNS.2               = *.$(echo $TLSNAME | cut -d. -f2-)\nIP.1                = $TLSIP\nEOF\n\necho\n# Create the new certificates\necho -e \"${GREY}Creating a new TLS Certificate...\"\nopenssl req -x509 -nodes -newkey rsa:$RSA_KEYLENGTH -keyout $TLSNAME.key -out $TLSNAME.crt -days $TLSDAYS -config cert_attributes.txt\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed.${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Place TLS Certificate into the defined application path\ncp $TLSNAME.key $DIR_SSL_KEY/$TLSNAME.key\ncp $TLSNAME.crt $DIR_SSL_CERT/$TLSNAME.crt\n\n# Create a PFX formatted key for easier import to Windows hosts and change permissions to enable copying elsewhere\necho -e \"${GREY}Converting client certificates for Windows & Linux...${GREY}\"\nopenssl pkcs12 -export -out $TLSNAME.pfx -inkey $TLSNAME.key -in $TLSNAME.crt -password pass:1234\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed.${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Change of permissions so certs can be copied via WinSCP.\nchown -R $SUDO_USER:root $CERT_DIR\n\n# Reload everything\necho -e \"${GREY}New certificate created, restating Guacamole & Ngnix...\"\nTOMCAT=$(ls /etc/ | grep tomcat)\nsystemctl restart $TOMCAT\nsystemctl restart guacd\nsystemctl restart nginx\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed.${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Hack to assist with displaying \"$\" symbols and \" ' quotes in a (cut/paste-able) bash screen output format\nSHOWASTEXT1='$mypwd'\nSHOWASTEXT2='\"Cert:\\LocalMachine\\Root\"'\n\nprintf \"${GREY}+-------------------------------------------------------------------------------------------------------------\n${LGREEN}+ WINDOWS CLIENT SELF SIGNED TLS BROWSER CONFIG - SAVE THIS BEFORE CONTINUING!${GREY}\n+\n+ 1. In ${CERT_DIR} is a Windows version of the new certificate ${LYELLOW}$TLSNAME.pfx${GREY}\n+ 2. Import this PFX file into your Windows client with the below Powershell commands (as Administrator):\n\\n\"\necho -e \"${SHOWASTEXT1} = ConvertTo-SecureString -String \"1234\" -Force -AsPlainText\"\necho -e \"Import-pfxCertificate -FilePath $TLSNAME.pfx -Password \"${SHOWASTEXT1}\" -CertStoreLocation \"${SHOWASTEXT2}\"\"\nprintf \"${GREY}+-------------------------------------------------------------------------------------------------------------\n${LGREEN}+ LINUX CLIENT SELF SIGNED TLS BROWSER CONFIG - SAVE THIS BEFORE CONTINUING!${GREY}\n+\n+ 1. In ${CERT_DIR} is a new Linux native OpenSSL certificate ${LYELLOW}$TLSNAME.crt${GREY}\n+ 2. Import the CRT file into your Linux client certificate store with the below command:\n\\n\"\necho -e \"(If certutil is not installed, run apt-get install libnss3-tools)\"\necho -e \"mkdir -p $HOME/.pki/nssdb && certutil -d $HOME/.pki/nssdb -N\"\necho -e \"certutil -d sql:$HOME/.pki/nssdb -A -t \"CT,C,c\" -n $TLSNAME -i $TLSNAME.crt\"\nprintf \"+-------------------------------------------------------------------------------------------------------------\\n\"\n\nrm -f cert_attributes.txt\n\n# Done\necho -e ${NC}\n"
  },
  {
    "path": "guac-management/useful-config-info.txt",
    "content": "#########################\nConnection setup tips:\n#########################\n# Quick connection syntax (Windows 10 RDP)\n    rdp://user@xxx.xxx.xxx.xxx/?security=nla&ignore-cert=true\n\n# To view links to recorded sessions from within the connection history page:\n    1. Install the history-recording-storage option\n    2. For each connection configuration profile, in the Screen Recording section set:\n          Recording Path = ${HISTORY_PATH}/${HISTORY_UUID}\n          Automatically create recording path = tick\n\n# To create a quasi SSO pass through for LDAP and others, for each connection configuration profile:\n    Add ${GUAC_USERNAME} to the Username field for each connection profile\n    Add ${GUAC_PASSWORD} to the Password field for each connection profile\n\n\n####################\nGuacamole Debug mode\n####################\nsudo systemctl stop guacd && sudo /usr/local/sbin/guacd -L debug -f  #Verbose logs will start in the console.\n\n\n################################################\nSwitch to Debian Testing repo \n(upgrade/bugfix beyond a current stable package)\n################################################\nsudo apt update && sudo apt upgrade -y # Update first \nsudo cp /etc/apt/sources.list sources.list.backup # Backup sources list \nsudo sed -i 's/bullseye/testing/g' /etc/apt/sources.list # Switch to testing \n\nsudo nano /etc/apt/sources.list # Now manually edit\n\tcomment out all lines having \"security.debian.org\" \n\tcomment out all lines that end with \"updates\"\n\tadd this line: deb http://security.debian.org testing-security main\n\nsudo apt update && sudo apt-get install --only-upgrade libssh2-1-dev # update an individual package\n\n\n\n###############################################\nAudit Guacamole Connections and User access.\n###############################################\nmysql -u root -p guacamole_db\nselect \n    guacamole_entity.name, \n    guacamole_connection.connection_name, \n    guacamole_connection_permission.permission \nfrom \n    guacamole_connection \n    left join guacamole_connection_permission on guacamole_connection_permission.connection_id = guacamole_connection.connection_id \n    left join guacamole_entity on guacamole_entity.entity_id = guacamole_connection_permission.entity_id \nwhere \n    guacamole_connection_permission.permission = 'READ' \n    and guacamole_entity.name != 'guacadmin';\nQuit to exit\n\n\n###############################################\n# Manually reset TOTP configuration for a user \n###############################################\n# This is likely not needed beyond in Gucamole 1.40 as the gui provides an option to reset. Kept for reference.\nmysql -u root -p\nuse guacamole_db;\nSELECT user_id FROM guacamole_user INNER JOIN guacamole_entity ON guacamole_entity.entity_id = guacamole_user.entity_id WHERE guacamole_entity.name = 'guacadmin';\nUPDATE guacamole_user_attribute SET attribute_value='false' WHERE attribute_name = 'guac-totp-key-confirmed' and user_id = '1';\nquit;\n\n\n###############################################\n# Quick troubleshoot SQL commands\n###############################################\n# Login\nsudo mysql -u root -p\n\n# Check time zone\nSELECT @@time_zone;\n\n# Rename user from local to remove access\nuse guacamole_db;\nRENAME USER '${GUAC_USER}'@'%' TO '${GUAC_USER}'@'xx.xx.xx.%';\n\n# Check user access\nSELECT user,host FROM mysql.user;\nSHOW GRANTS FOR guacamole_user;\n\n#########################\nNginx load / DoS testing \n#########################\nhttps://ourcodeworld.com/articles/read/949/how-to-perform-a-dos-attack-slow-http-with-slowhttptest-test-your-server-slowloris-protection-in-kali-linux\nslowhttptest -c 10000 -H -g -o ./output_file -i 3 -r 500 -t GET -u http://jumpbox.domain.com -x 24 -p 2\n\n\n#####################################################\nAllow local browser microphone redirect without TLS\n#####################################################\nchrome://flags/#unsafely-treat-insecure-origin-as-secure\n\n\n#####################################################\nBuild Custom Console\n####################################################\n# clone and edit source\nsudo apt update && sudo apt install git\ngit clone https://github.com/apache/guacamole-client.git\nWdit the en.json file to the values you need\n\n# Install Older Java 8 prerequisites\nhttps://www.oracle.com/java/technologies/javase/javase8u211-later-archive-downloads.html (needs oracle sign in)\nsudo mkdir -p /usr/lib/jvm\nsudo tar zxvf jdk-8u411-linux-x64.tar.gz -C /usr/lib/jvm\nsudo update-alternatives --install \"/usr/bin/java\" \"java\" \"/usr/lib/jvm/jdk1.8.0_411/bin/java\" 1\nsudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_411/bin/java\n\n# Install maven to build the new war file\nsudo apt install maven\ncd ~/guacamole-client\nmvn package\nnew .war file is found in guacamole-client/guacamole/target\n\n# Install the bew .war file into Guacamole\nsudo mv -f guacamole-1.5.5.war /etc/guacamole/guacamole.war # copy and rename the new war file\nsudo chmod 664 /etc/guacamole/guacamole.war\nsudo ln -sf /etc/guacamole/guacamole.war /var/lib/tomcat9/webapps/\nsudo systemctl restart tomcat9 && sudo systemctl restart guacd\n"
  },
  {
    "path": "guac-optional-features/add-auth-duo.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Add Duo (MFA) support to Guacamole\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n# If run as standalone and not from the main installer script, check the below variables are correct.\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\nclear\n\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LGREEN}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\nGUAC_VERSION=$(grep -oP 'Guacamole.API_VERSION = \"\\K[0-9\\.]+' /var/lib/${TOMCAT_VERSION}/webapps/guacamole/guacamole-common-js/modules/Version.js)\nGUAC_SOURCE_LINK=\"http://apache.org/dyn/closer.cgi?action=download&filename=guacamole/${GUAC_VERSION}\"\n\necho\nwget -q --show-progress -O guacamole-auth-duo-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-duo-${GUAC_VERSION}.tar.gz\ntar -xzf guacamole-auth-duo-${GUAC_VERSION}.tar.gz\nmv -f guacamole-auth-duo-${GUAC_VERSION}/guacamole-auth-duo-${GUAC_VERSION}.jar /etc/guacamole/extensions/\nchmod 664 /etc/guacamole/extensions/guacamole-auth-duo-${GUAC_VERSION}.jar\necho -e \"${LGREEN}Installed guacamole-auth-duo-${GUAC_VERSION}${GREY}\"\necho \"duo-integration-key: \" >>/etc/guacamole/guacamole.properties\necho \"duo-secret-key: \" >>/etc/guacamole/guacamole.properties\necho \"duo-api-hostname: \" >>/etc/guacamole/guacamole.properties\necho \"duo-application-key: \" >>/etc/guacamole/guacamole.properties\necho\nsystemctl restart ${TOMCAT_VERSION}\nsystemctl restart guacd\n\necho -e \"${LYELLOW}You must now set up your online Duo account with a new 'Web SDK' application.\"\necho\necho \"Next you must copy the API settings from your Duo account into /etc/guacamole/guacamole.properties in the EXACT below format.\"\necho -e \"Be VERY careful to avoid extra trailing spaces or other line feed characters when pasting!${GREY}\"\necho\necho \"duo-integration-key: ??????????\"\necho \"duo-api-hostname: ??????????\"\necho \"duo-secret-key: ??????????\"\necho \"duo-application-key: (this is locally created - run 'pwgen 40 1' to manually generate this 40 char random value)\"\necho\necho \"Once this change is complete, restart Guacamole with sudo systemctl restart ${TOMCAT_VERSION}\"\n\nrm -rf guacamole-*\n\necho\necho -e ${NC}\n"
  },
  {
    "path": "guac-optional-features/add-auth-ldap.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Add Active Directory integration with Guacamole\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n# If run as standalone and not from the main installer script, check the below variables are correct.\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\nclear\n\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\n\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\nGUAC_VERSION=$(grep -oP 'Guacamole.API_VERSION = \"\\K[0-9\\.]+' /var/lib/${TOMCAT_VERSION}/webapps/guacamole/guacamole-common-js/modules/Version.js)\nGUAC_SOURCE_LINK=\"http://apache.org/dyn/closer.cgi?action=download&filename=guacamole/${GUAC_VERSION}\"\n\necho\necho -e \"${LYELLOW}Have you updated this script to reflect your Active Directory settings?${NC}\"\n\nread -p \"Do you want to proceed? (yes/no) \" yn\necho\ncase $yn in\ny) echo Beginning LDAP auth config... ;;\nn)\n    echo exiting...\n    exit\n    ;;\n*)\n    echo invalid response\n    exit 1\n    ;;\nesac\n\necho\nwget -q --show-progress -O guacamole-auth-ldap-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-ldap-${GUAC_VERSION}.tar.gz\ntar -xzf guacamole-auth-ldap-${GUAC_VERSION}.tar.gz\nmv -f guacamole-auth-ldap-${GUAC_VERSION}/guacamole-auth-ldap-${GUAC_VERSION}.jar /etc/guacamole/extensions/\nchmod 664 /etc/guacamole/extensions/guacamole-auth-ldap-${GUAC_VERSION}.jar\necho -e \"${LGREEN}Installed guacamole-auth-ldap-${GUAC_VERSION}${GREY}\"\necho\necho Adding the below config to /etc/guacamole/guacamole.properties\ncat <<EOF | sudo tee -a /etc/guacamole/guacamole.properties\nldap-hostname: dc1.yourdomain.com dc2.yourdomain.com\nldap-port: 389\nldap-username-attribute: sAMAccountName\nldap-encryption-method: none\nldap-search-bind-dn: ad-account@yourdomain.com\nldap-search-bind-password: ad-account-password\nldap-config-base-dn: dc=domain,dc=com\nldap-user-base-dn: OU=SomeOU,DC=domain,DC=com\nldap-user-search-filter:(objectClass=user)(!(objectCategory=computer))\nldap-max-search-results:200\nEOF\n\nsystemctl restart ${TOMCAT_VERSION}\nsystemctl restart guacd\n\nrm -rf guacamole-*\n\necho\necho \"Done!\"\necho -e ${NC}\n"
  },
  {
    "path": "guac-optional-features/add-auth-totp.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Add TOTP (MFA) support for Guacamole\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n# If run as standalone and not from the main installer script, check the below variables are correct.\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\nclear\n\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\n\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\nGUAC_VERSION=$(grep -oP 'Guacamole.API_VERSION = \"\\K[0-9\\.]+' /var/lib/${TOMCAT_VERSION}/webapps/guacamole/guacamole-common-js/modules/Version.js)\nGUAC_SOURCE_LINK=\"http://apache.org/dyn/closer.cgi?action=download&filename=guacamole/${GUAC_VERSION}\"\n\necho\nwget -q --show-progress -O guacamole-auth-totp-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-totp-${GUAC_VERSION}.tar.gz\ntar -xzf guacamole-auth-totp-${GUAC_VERSION}.tar.gz\nmv -f guacamole-auth-totp-${GUAC_VERSION}/guacamole-auth-totp-${GUAC_VERSION}.jar /etc/guacamole/extensions/\nchmod 664 /etc/guacamole/extensions/guacamole-auth-totp-${GUAC_VERSION}.jar\necho -e \"${LGREEN}Installed guacamole-auth-totp-${GUAC_VERSION}${GREY}\"\n\nsystemctl restart ${TOMCAT_VERSION}\nsystemctl restart guacd\n\nrm -rf guacamole-*\n\necho\necho \"Done!\"\necho -e ${NC}\n"
  },
  {
    "path": "guac-optional-features/add-fail2ban.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Add fail2ban restrictions to Guacamole\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# December 2024\n#######################################################################################################################\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\nclear\n\n# Check if user is root or sudo\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LGREEN}Please run this script as sudo or root${NC}\" 1>&2\n\techo\n    exit 1\nfi\n\n# Initialise variables\nFAIL2BAN_BASE=\"\"\nFAIL2BAN_GUAC=\"\"\nFAIL2BAN_NGINX=\"\"\nFAIL2BAN_SSH=\"\"\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\nTOMCAT_SERVICE_FILE=\"/usr/lib/systemd/system/$TOMCAT_VERSION.service\"\n# Tomcat service file logging lines that must exist\nOUTPUT_LINE=\"StandardOutput=append:/var/log/$TOMCAT_VERSION/catalina.out\"\nERROR_LINE=\"StandardError=append:/var/log/$TOMCAT_VERSION/catalina.out\"\n\n#Clean up from any previous runs\nrm -f /tmp/fail2ban.temp1\nrm -f /tmp/fail2ban.temp2\nrm -f /tmp/ip_list.txt\nrm -f /tmp/netaddr.txt\n\n#######################################################################################################################\n# Start setup prompts #################################################################################################\n#######################################################################################################################\n\n# Prompt to install fail2ban base package with no policy as yet, default of yes\nif [[ -z ${FAIL2BAN_BASE} ]]; then\n    echo\n    echo -e -n \"${LGREEN}Install Fail2ban base package? [default y]: ${GREY}\"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Nn]$ ]]; then\n        FAIL2BAN_BASE=false\n    else\n        FAIL2BAN_BASE=true\n    fi\nfi\n\n# Prompt to install Guacamole fail2ban config defaults, default of no\nif [[ -z ${FAIL2BAN_GUAC} ]] && [[ \"${FAIL2BAN_BASE}\" = true ]]; then\n    echo -e -n \"${GREY}POLICY: Apply Guacamole fail2ban security policy? (Y/n) [default y]:${GREY}\"\n    read PROMPT\n    if [[ ${PROMPT} =~ ^[Nn]$ ]]; then\n        FAIL2BAN_GUAC=false\n    else\n        FAIL2BAN_GUAC=true\n    fi\nfi\n\n# Prompt to install Nginx fail2ban config defaults , default of no - NOT IMPLEMENTED YET\n#if [[ -z ${FAIL2BAN_NGINX} ]] && [[ \"${FAIL2BAN_BASE}\" = true ]]; then\n#    echo -e -n \"${GREY}POLICY: Apply Nginx fail2ban security policy? (y/n) [default n]:${GREY}\"\n#    read PROMPT\n#    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n#        FAIL2BAN_NGINX=true\n#    else\n#        FAIL2BAN_NGINX=false\n#    fi\n#fi\n\n# Prompt to install SSH fail2ban config defaults , default of no - NOT IMPLEMENTED YET\n#if [[ -z ${FAIL2BAN_SSH} ]] && [[ \"${FAIL2BAN_BASE}\" = true ]]; then\n#    echo -e -n \"${GREY}POLICY: Apply SSH fail2ban security policy? (y/n) [default n]:${GREY}\"\n#    read PROMPT\n#    if [[ ${PROMPT} =~ ^[Yy]$ ]]; then\n#        FAIL2BAN_SSH=true\n#    else\n#        FAIL2BAN_SSH=false\n#    fi\n#fi\n\n#######################################################################################################################\n# Fail2ban base setup #################################################################################################\n#######################################################################################################################\n\n# Install base fail2ban base application, and whitelist the local subnet as the starting baseline (no policy defined yet)\nif [[ \"${FAIL2BAN_BASE}\" = true ]]; then\necho\n    #Update and install fail2ban (and john for management of config file updates, and not overwrite any existing settings)\n    apt-get update -qq \n    apt-get install fail2ban john -qq -y\n\n    # Create the basic jail.local template local subnet whitelist\n\techo\n    cat >/tmp/fail2ban.temp1 <<EOF\n[DEFAULT]\ndestemail = yourname@example.com\nsender = yourname@example.com\naction = %(action_mwl)s\nignoreip =\n\n[sshd]\nbackend = systemd\nenabled = true\nEOF\n\n    # We need to discover all interfaces to ascertain what network ranges to add to fail2ban \"ignoreip\" policy override defaults\n    ip -o addr show up primary scope global | while read -r num dev fam addr rest; do echo ${addr%*}; done | cat >/tmp/ip_list.txt\n\n    # Loop the list of discovered ips and extract the subnet ID addresses for each interface\n    FILE=/tmp/ip_list.txt\n    LINES=$(cat $FILE)\n    for LINE in $LINES; do\n\n        tonum() {\n            if [[ $LINE =~ ([[:digit:]]+)\\.([[:digit:]]+)\\.([[:digit:]]+)\\.([[:digit:]]+) ]]; then\n                addr=$(((${BASH_REMATCH[1]} << 24) + (${BASH_REMATCH[2]} << 16) + (${BASH_REMATCH[3]} << 8) + ${BASH_REMATCH[4]}))\n                eval \"$2=\\$addr\"\n            fi\n        }\n        toaddr() {\n            b1=$((($1 & 0xFF000000) >> 24))\n            b2=$((($1 & 0xFF0000) >> 16))\n            b3=$((($1 & 0xFF00) >> 8))\n            b4=$(($1 & 0xFF))\n            eval \"$2=\\$b1.\\$b2.\\$b3.\\$b4\"\n        }\n\n        if [[ $LINE =~ ^([0-9\\.]+)/([0-9]+)$ ]]; then\n            # CIDR notation\n            IPADDR=${BASH_REMATCH[1]}\n            NETMASKLEN=${BASH_REMATCH[2]}\n            PREFIX=$NETMASKLEN\n            zeros=$((32 - NETMASKLEN))\n            NETMASKNUM=0\n            for ((i = 0; i < $zeros; i++)); do\n                NETMASKNUM=$(((NETMASKNUM << 1) ^ 1))\n            done\n            NETMASKNUM=$((NETMASKNUM ^ 0xFFFFFFFF))\n            toaddr $NETMASKNUM NETMASK\n        else\n            IPADDR=${1:-192.168.1.1}\n            NETMASK=${2:-255.255.255.0}\n        fi\n\n        tonum $IPADDR IPADDRNUM\n        tonum $NETMASK NETMASKNUM\n\n        # The logic to calculate network and broadcast\n        INVNETMASKNUM=$((0xFFFFFFFF ^ NETMASKNUM))\n        NETWORKNUM=$((IPADDRNUM & NETMASKNUM))\n        BROADCASTNUM=$((INVNETMASKNUM | NETWORKNUM))\n\n        toaddr $NETWORKNUM NETWORK\n        toaddr $BROADCASTNUM BROADCAST\n\n        # Reverse engineer the subnet ID from the calcualted IP address and subnet prefix\n        IFS=. read -r i1 i2 i3 i4 <<<\"$IPADDR\"\n        IFS=. read -r m1 m2 m3 m4 <<<\"$NETMASK\"\n\n        # Lay out the subnet ID address as a variable\n        printf -v NETADDR \"%d.%d.%d.%d\" \"$((i1 & m1))\" \"$((i2 & m2))\" \"$((i3 & m3))\" \"$((i4 & m4))\"\n\n        #Dump out the calcualted subnet IDs to a file\n        echo $NETADDR\"/\"$NETMASKLEN | tr '\\n' ' ' | cat >>/tmp/netaddr.txt\n\n    done\n\nfi\n\nif [[ \"${FAIL2BAN_BASE}\" = true ]]; then\n    # Now the above loop is done, append the single loopback address to all the discovered the subnet IDs in a single line\n    sed -i 's/^/127.0.0.1\\/24 /' /tmp/netaddr.txt\n\n    # Finally assemble the entire syntax of the ignoreip whitelist for insertion into the base fail2ban config\n    SED_IGNORE=$(echo \"ignoreip = \")\n    SED_NETADDR=$(cat /tmp/netaddr.txt)\n\tsed -i \"s|ignoreip \\=|${SED_IGNORE}${SED_NETADDR}|g\" /tmp/fail2ban.temp1\n\n    # Move the new base fail2ban config to the jail.local file\n    touch /etc/fail2ban/jail.local\n\n    # Apply the base config, keeping any pre-existing settings\n\tsudo bash -c 'cat /tmp/fail2ban.temp1 > /etc/fail2ban/jail.local'\n\n    # bounce the service to reload the new config\n    systemctl restart fail2ban\n\t\n\t# Display the new config\n\techo \"New base /etc/fail2ban/jail.local config:\"\n\tcat /etc/fail2ban/jail.local\n\n    echo\n    echo -e \"${LGREEN}Fail2ban base installed...${GREY}\"\n    echo\n\nelse\n    echo -e \"${LGREEN}Fail2ban setup cancelled.${GREY}\"\n\nfi\n\n#######################################################################################################################\n# Fail2ban optional policy setup items ################################################################################\n#######################################################################################################################\n\n\nif [[ \"${FAIL2BAN_GUAC}\" = true ]]; then\n    # Create the Guacamole jail.local policy template\n    cat >/tmp/fail2ban.temp2 <<EOF\n\n[guacamole]\nenabled = true\nport = http,https\nlogpath = /var/log/$TOMCAT_VERSION/catalina.out\nbantime = 10m\nfindtime = 60m\nmaxretry = 5\nEOF\n\n    # Apply the new Guacamole jail config\n\tsudo bash -c 'cat /tmp/fail2ban.temp2 >> /etc/fail2ban/jail.local'\n\n    # Backup the default Fail2ban Guacamole filter\n    cp /etc/fail2ban/filter.d/guacamole.conf /etc/fail2ban/filter.d/guacamole.conf.bak\n\n    # Remove the default log search regex\n    sudo bash -c 'sed -e \"/Authentication attempt from/ s/^#*/#/\" -i /etc/fail2ban/filter.d/guacamole.conf'\n\n    # Create a new log search regex specific for tomcat logs (as a variable due to complexity of characters for sed syntax)\n    REGEX='failregex = ^.*WARN  o\\.a\\.g\\.r\\.auth\\.AuthenticationService - Authentication attempt from <HOST> for user \"[^\"]*\" failed\\.$'\n    #Insert the new regex\n    sed -i -e \"/Authentication attempt from/a ${REGEX}\" /etc/fail2ban/filter.d/guacamole.conf\nfi\n\n    # Clean up\n    rm -f /tmp/fail2ban.temp1\n\trm -f /tmp/fail2ban.temp2\n    rm -f /tmp/ip_list.txt\n    rm -f /tmp/netaddr.txt\n\tapt-get -y remove john > /dev/null 2>&1\n\tapt-get -y autoremove > /dev/null 2>&1\n\n# Display the updated config\necho \"Updated jail.local with Guacamole filter policy:\"\ncat /etc/fail2ban/jail.local\n\n# make sure Tomcat catalina logs are configured\nif [[ ! -f \"$TOMCAT_SERVICE_FILE\" ]]; then\n    echo \"Error: $TOMCAT_SERVICE_FILE not found, exiting...\"\n    exit 1\nelse\n    if grep -q \"^$OUTPUT_LINE\" \"$TOMCAT_SERVICE_FILE\" && grep -q \"^$ERROR_LINE\" \"$TOMCAT_SERVICE_FILE\"; then\n        echo \"Required lines already exist in $TOMCAT_SERVICE_FILE. No changes made.\"\n    else\n        # Add lines if they don't already exist\n\t\tsed -i \"/^\\[Service\\]/a $OUTPUT_LINE\\n$ERROR_LINE\" \"$TOMCAT_SERVICE_FILE\"\n\t\tsystemctl daemon-reload\n\t\tsystemctl restart fail2ban\n\t\tsystemctl restart guacd\n\t\tsystemctl restart ${TOMCAT_VERSION}\n        echo \"Lines were added successfully to $TOMCAT_SERVICE_FILE.\"\n    fi\nfi\n\n   # Done\n    echo\n\techo -e \"${LGREEN}Guacamole security policy applied, but NOT YET ENABLED FOR LOCAL NETWORK(S) ${GREY}\\n- Local network(s) ${SED_NETADDR}are currently whitelisted from all IP bans.\\n- To alter this whitelist, edit /etc/fail2ban/jail.local then sudo systemctl restart fail2ban\"\n\n############## Start Fail2ban NGINX security policy option ###############\n#if [[ \"${FAIL2BAN_NGINX}\" = true ]]; then\n#    echo -e \"${LGREEN}Nginx Fail2ban policy not implemented yet.${GREY}\"\n#    echo\n#fi\n\n############### Start Fail2ban SSH security policy option ################\n#if [[ \"${FAIL2BAN_SSH}\" = true ]]; then\n#    echo -e \"${LGREEN}SSH Fail2ban policy not implemented yet..${GREY}\"\n#    echo\n#fi\n\n#Done\necho -e ${NC}\n"
  },
  {
    "path": "guac-optional-features/add-smtp-relay-o365.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# SMTP relay with Office 365 Setup\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n# Prerequisites:\n# An office 365 account with a mailbox (NON ADMIN!!)\n# An app password created for the above office 365 user at https://mysignins.microsoft.com/security-info\n# SMTP Auth enabled for that user under \"manage mail apps\" in the Office365 admin centre.\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\n# Check if user is root or sudo\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\n\nclear\n\nSENDER=$SUDO_USER\nSERVER=$(uname -n)\n# Below variables are automatically updated by the 1-setup.sh script with the respective values given at install (manually update if blank)\nLOCAL_DOMAIN=\n\necho\necho -e \"${LYELLOW}SMTP relay for Office365 setup...${LGREEN}\"\n\n# Install Posfix\necho\necho -e \"${GREY}Installing Postfix with non-interactive defaults...\"\napt-get update -qq\nDEBIAN_FRONTEND=\"noninteractive\" apt-get install postfix mailutils -qq -y >/dev/null 2>&1\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Postfix install failed. ${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\nfi\n\n# Get the Office365 smtp authentication credentials\necho\necho -e \"${LYELLOW}An Office365 account email account is needed for SMTP relay authentication...${LGREEN}\"\necho\nread -p \"Enter O365 SMTP auth enabled email : \" SMTP_EMAIL\nread -s -p \"Enter the SMTP auth account 'app password': \" APP_PWD\necho\necho\n\n# Remove some default Postifx config items that conflict with new entries\nsed -i '/relayhost/d' /etc/postfix/main.cf\nsed -i '/smtp_tls_security_level=may/d' /etc/postfix/main.cf\n\n# For simple relay outbound only, limit Postfix to just loopback and IPv4\nsed -i 's/inet_interfaces = all/inet_interfaces = loopback-only/g' /etc/postfix/main.cf\nsed -i \"s/inet_protocols = all/inet_protocols = ipv4/g\" /etc/postfix/main.cf\n\necho -e \"${GREY}Configuring Postfix for O365 SMTP relay and TLS auth...\"\n# Add the new Office365 SMTP auth with TLS settings\ncat <<EOF | sudo tee -a /etc/postfix/main.cf >/dev/null 2>&1\nrelayhost = [smtp.office365.com]:587\nsmtp_use_tls = yes\nsmtp_always_send_ehlo = yes\nsmtp_sasl_auth_enable = yes\nsmtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd\nsmtp_sasl_security_options = noanonymous\nsmtp_sasl_tls_security_options = noanonymous\nsmtp_tls_security_level = encrypt\nsmtp_generic_maps = hash:/etc/postfix/generic\nsmtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt\nEOF\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Postfix restart failed. ${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Setup the password file and postmap\ntouch /etc/postfix/sasl_passwd\ncat <<EOF | sudo tee -a /etc/postfix/sasl_passwd >/dev/null 2>&1\n[smtp.office365.com]:587 ${SMTP_EMAIL}:${APP_PWD}\nEOF\nchown root:root /etc/postfix/sasl_passwd\nchmod 0600 /etc/postfix/sasl_passwd\npostmap /etc/postfix/sasl_passwd\n\n# Setup the generic map file\ntouch /etc/postfix/generic\ncat <<EOF | sudo tee -a /etc/postfix/generic >/dev/null 2>&1\nroot@${SERVER} ${SMTP_EMAIL}\n${SENDER}@${SERVER} ${SMTP_EMAIL}\n@${LOCAL_DOMAIN} ${SMTP_EMAIL}\nEOF\nchown root:root /etc/postfix/generic\nchmod 0600 /etc/postfix/generic\npostmap /etc/postfix/generic\n\n# Restart and test\necho -e \"${GREY}Restarting Postfix...\"\nsystemctl restart postfix\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Postfix restart failed. ${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\nfi\n\necho\nread -p \"Enter an email address to test that email relay is working : \" TEST_EMAIL\necho \"This is a test email\" | mail -s \"SMTP Auth Relay Is Working is working\" ${TEST_EMAIL} -a \"FROM:${SMTP_EMAIL}\"\necho -e \"${LGREEN}Test message sent..\"\necho -e ${NC}\n"
  },
  {
    "path": "guac-optional-features/add-tls-guac-daemon.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Harden Guacd <-> Guac client traffic in TLS wrapper\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n# To delete and reissue a new cert\n# sudo keytool -delete -alias guacd -noprompt -cacerts -storepass changeit -file guacd.crt\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\n# Check if user is root or sudo\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\n\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\nRSA_KEY_LENGTH=2048\n# Below variables are automatically updated by the 1-setup.sh script with the respective values given at install (manually update if blank)\nCERT_COUNTRY=\nCERT_STATE=\nCERT_LOCATION=\nCERT_ORG=\nCERT_OU=\nCERT_DAYS=\n\nclear\n\n# Create the special directory for guacd tls certificate and key.\nmkdir -p /etc/guacamole/ssl\necho\ncat <<EOF | tee cert_attributes.txt\n[req]\ndistinguished_name  = req_distinguished_name\nx509_extensions     = v3_req\nprompt              = no\nstring_mask         = utf8only\n\n[req_distinguished_name]\nC                   = $CERT_COUNTRY\nST                  = $CERT_STATE\nL                   = $CERT_LOCATION\nO                   = $CERT_ORG\nOU                  = $CERT_OU\nCN                  = localhost\n\n[v3_req]\nkeyUsage            = nonRepudiation, digitalSignature, keyEncipherment\nextendedKeyUsage    = serverAuth, clientAuth, codeSigning, emailProtection\nsubjectAltName      = @alt_names\n\n[alt_names]\nDNS.1               = localhost\nIP.1                = 127.0.0.1\nEOF\n\n# Create the self signing request, certificate & key. \n# If splitting guacd (backend) and guacamole (front end) across separate systems, run this command on guacd and then copy certs to the same location on guacamole server.\n# Also consider omitting the setting -config cert_attributes.txt or IP.1 = 0.0.0.0 for future ip address changes if splitting.\nopenssl req -x509 -nodes -days $CERT_DAYS -newkey rsa:$RSA_KEY_LENGTH -keyout /etc/guacamole/ssl/guacd.key -out /etc/guacamole/ssl/guacd.crt -config cert_attributes.txt\nrm -f cert_attributes.txt\n\n# Point Guacamole config file to certificate and key. (If splitting, run this on guacd after changing bind_ host to 0.0.0.0 ).\ncp /etc/guacamole/guacd.conf /etc/guacamole/guacd.conf.bak\ncat <<EOF | sudo tee /etc/guacamole/guacd.conf\n[server]\nbind_host = 127.0.0.1\nbind_port = 4822\n[ssl]\nserver_certificate = /etc/guacamole/ssl/guacd.crt\nserver_key = /etc/guacamole/ssl/guacd.key\nEOF\n\n# Enable TLS backend (Add this to guacamole server front end if splitting)\ncat <<EOF | sudo tee -a /etc/guacamole/guacamole.properties\nguacd-ssl: true\nEOF\n\n# Fix required permissions as guacd only runs as daemon (Run on both systems if splitting)\nchown daemon:daemon /etc/guacamole/ssl\nchown daemon:daemon /etc/guacamole/ssl/guacd.key\nchown daemon:daemon /etc/guacamole/ssl/guacd.crt\nchmod 644 /etc/guacamole/ssl/guacd.crt\nchmod 644 /etc/guacamole/ssl/guacd.key\n\n# Add the new certificate into the Java Runtime certificate store and set JRE to trust it. (Run on guacamole server front end if splitting)\ncd /etc/guacamole/ssl\nkeytool -importcert -alias guacd -noprompt -cacerts -storepass changeit -file guacd.crt\n\nsystemctl restart guacd\nsystemctl restart ${TOMCAT_VERSION}\n\necho\necho \"Done!\"\necho -e ${NC}\n"
  },
  {
    "path": "guac-optional-features/add-xtra-histrecstor.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Add History Recorded Storage extension for Guacamole\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# September 2023\n#######################################################################################################################\n\n# If run as standalone and not from the main installer script, check the below variables are correct.\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\nclear\n\n# Check if user is root or sudo\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\n\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\nGUAC_VERSION=$(grep -oP 'Guacamole.API_VERSION = \"\\K[0-9\\.]+' /var/lib/${TOMCAT_VERSION}/webapps/guacamole/guacamole-common-js/modules/Version.js)\nGUAC_SOURCE_LINK=\"http://apache.org/dyn/closer.cgi?action=download&filename=guacamole/${GUAC_VERSION}\"\nHISTREC_PATH_DEFAULT=/var/lib/guacamole/recordings # Apache default\n\nwhile true; do\n    echo\n    read -p \"Enter recorded storage path [Enter for default ${HISTREC_PATH_DEFAULT}]: \" HISTREC_PATH\n    [[ \"${HISTREC_PATH}\" = \"\" ]] || [[ \"${HISTREC_PATH}\" != \"\" ]] && break\ndone\n# If no custom path is given, lets assume the default path on hitting enter\nif [[ -z \"${HISTREC_PATH}\" ]]; then\n    HISTREC_PATH=\"${HISTREC_PATH_DEFAULT}\"\nfi\necho\n\n# Download Guacamole history recording storage extension\nwget -q --show-progress -O guacamole-history-recording-storage-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-history-recording-storage-${GUAC_VERSION}.tar.gz\ntar -xzf guacamole-history-recording-storage-${GUAC_VERSION}.tar.gz\n\n# Move history recording storage extension files\nmv -f guacamole-history-recording-storage-${GUAC_VERSION}/guacamole-history-recording-storage-${GUAC_VERSION}.jar /etc/guacamole/extensions/\nchmod 664 /etc/guacamole/extensions/guacamole-history-recording-storage-${GUAC_VERSION}.jar\n#Setup the default recording path\nmkdir -p ${HISTREC_PATH}\nchown daemon:tomcat ${HISTREC_PATH}\nchmod 2750 ${HISTREC_PATH}\necho \"recording-search-path: ${HISTREC_PATH}\" >>/etc/guacamole/guacamole.properties\necho -e \"${LGREEN}Installed guacamole-history-recording-storage-${GUAC_VERSION}${GREY}\"\n\nsystemctl restart ${TOMCAT_VERSION}\nsystemctl restart guacd\n\nrm -rf guacamole-*\n\necho\necho \"Done!\"\necho -e ${NC}\n"
  },
  {
    "path": "guac-optional-features/add-xtra-quickconnect.sh",
    "content": "#!/bin/bash\n#######################################################################################################################\n# Add Quick Connect extension to Guacamole\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# September 2023\n#######################################################################################################################\n\n# If run as standalone and not from the main installer script, check the below variables are correct.\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\nclear\n\n# Check if user is root or sudo\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    exit 1\nfi\n\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\nGUAC_VERSION=$(grep -oP 'Guacamole.API_VERSION = \"\\K[0-9\\.]+' /var/lib/${TOMCAT_VERSION}/webapps/guacamole/guacamole-common-js/modules/Version.js)\nGUAC_SOURCE_LINK=\"http://apache.org/dyn/closer.cgi?action=download&filename=guacamole/${GUAC_VERSION}\"\n\necho\nwget -q --show-progress -O guacamole-auth-quickconnect-${GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-quickconnect-${GUAC_VERSION}.tar.gz\ntar -xzf guacamole-auth-quickconnect-${GUAC_VERSION}.tar.gz\nmv -f guacamole-auth-quickconnect-${GUAC_VERSION}/guacamole-auth-quickconnect-${GUAC_VERSION}.jar /etc/guacamole/extensions/\nchmod 664 /etc/guacamole/extensions/guacamole-auth-quickconnect-${GUAC_VERSION}.jar\necho -e \"${LGREEN}Installed guacamole-auth-quickconnect-${GUAC_VERSION}${GREY}\"\n\nsystemctl restart ${TOMCAT_VERSION}\nsystemctl restart guacd\n\nrm -rf guacamole-*\n\necho\necho \"Done!\"\necho -e ${NC}\n"
  },
  {
    "path": "upgrade-guacamole.sh",
    "content": "#!/bin/bash\n######################################################################################################################\n# Guacamole appliance upgrade script\n# For Ubuntu / Debian / Raspbian\n# David Harrop\n# April 2023\n#######################################################################################################################\n\n#######################################################################################################################\n# Script pre-flight checks and settings ###############################################################################\n#######################################################################################################################\n\nclear\n\n# Prepare text output colours\nGREY='\\033[0;37m'\nDGREY='\\033[0;90m'\nGREYB='\\033[1;37m'\nLRED='\\033[0;91m'\nLGREEN='\\033[0;92m'\nLYELLOW='\\033[0;93m'\nNC='\\033[0m' #No Colour\n\n# Check if user is root or sudo\nif ! [[ $(id -u) = 0 ]]; then\n    echo\n    echo -e \"${LRED}Please run this script as sudo or root${NC}\" 1>&2\n    echo\n    exit 1\nfi\n\n# Check to see if any previous version of build/install files exist, if so stop and check to be safe.\nif [[ \"$(find . -maxdepth 1 \\( -name 'guacamole-*' -o -name 'mysql-connector-j-*' \\))\" != \"\" ]]; then\n    echo\n    echo -e \"${LRED}Possible previous install files detected. Please review and remove old guacamole install files before proceeding.${GREY}\" 1>&2\n    echo\n    exit 1\nfi\n\n#######################################################################################################################\n# Initial environment setup ###########################################################################################\n#######################################################################################################################\n\n#Setup download and temp directory paths\nUSER_HOME_DIR=$(eval echo ~${SUDO_USER})\nDOWNLOAD_DIR=$USER_HOME_DIR/guac-setup\n\n# Setup directory locations\nmkdir -p $DOWNLOAD_DIR\nchown -R $SUDO_USER:root $DOWNLOAD_DIR\n\n# Version of Guacamole to upgrade to. See https://guacamole.apache.org/releases/ for latest version info.\nNEW_GUAC_VERSION=\"1.6.0\"\n\n# MySQL Connector/J version. See https://dev.mysql.com/downloads/connector/j/ for latest version number.\nNEW_MYSQLJCON=\"9.3.0\"\n\n# Get the currently installed Tomcat version.\nTOMCAT_VERSION=$(ls /etc/ | grep tomcat)\n\n# Get the currently installed Guacamole version\nOLD_GUAC_VERSION=$(grep -oP 'Guacamole.API_VERSION = \"\\K[0-9\\.]+' /var/lib/${TOMCAT_VERSION}/webapps/guacamole/guacamole-common-js/modules/Version.js)\n\n# Set preferred Apache CDN download link\nGUAC_SOURCE_LINK=\"http://apache.org/dyn/closer.cgi?action=download&filename=guacamole/${NEW_GUAC_VERSION}\"\n\n# Install log Location\nINSTALL_LOG=\"${DOWNLOAD_DIR}/guacamole_${NEW_GUAC_VERSION}_upgrade.log\"\n\n# Below variables are automatically updated by the 1-setup.sh script with the respective values given at install (manually update if blank)\nINSTALL_MYSQL=\nMYSQL_HOST=\nMYSQL_PORT=\nGUAC_USER=\nGUAC_PWD=\nGUAC_DB=\nMYSQL_ROOT_PWD=\nRDP_SHARE_HOST=\nRDP_SHARE_LABEL=\nRDP_PRINTER_LABEL=\nGUACD_ACCOUNT=\n\n# Standardise on a distro version identification lexicon\nsource /etc/os-release\nID=$ID\nVERSION_ID=$VERSION_ID\nVERSION_CODENAME=$VERSION_CODENAME\n\n# Workaround for issue #31\nif [[ \"${ID,,}\" = \"debian\" && \"${VERSION_CODENAME,,}\" = *\"bullseye\"* ]] || [[ \"${ID,,}\" = \"ubuntu\" && \"${VERSION_CODENAME,,}\" = *\"focal\"* ]]; then\n    IFS='.' read -ra guac_version_parts <<< \"${GUAC_VERSION}\"\n    major=\"${guac_version_parts[0]}\"\n    minor=\"${guac_version_parts[1]}\"\n    patch=\"${guac_version_parts[2]}\"\n    # Assume this will be correctly fixed in 1.5.5 and is a 1.5.4 specific bug. Uncomment 2nd line if issue persists >=1.5.4 (See https://issues.apache.org/jira/browse/GUACAMOLE-1892))\n\tif (( major == 1 && minor == 5 && patch == 4 )); then\n\t#if (( major > 1 || (major == 1 && minor > 5) || ( major == 1 && minor == 5 && patch >= 4 ) )); then\n      export LDFLAGS=\"-lrt\"\n    fi\nfi\n\n# Script branding header\necho\necho -e \"${GREYB}Guacamole Appliance Auto Upgrade Script\"\necho -e \"                             ${LGREEN}Powered by Itiligent\"\necho\n\n#######################################################################################################################\n# Start upgrade actions  ##############################################################################################\n#######################################################################################################################\n\nsudo apt-get update -qq\napt-get upgrade -qq -y\napt-get -qq -y install build-essential\n\n# Stop tomcat and guacd\nsystemctl stop ${TOMCAT_VERSION}\nsystemctl stop guacd\n\ncd $DOWNLOAD_DIR\n\necho\necho -e \"${GREY}Downloading updated Guacamole source files and beginning Guacamole ${OLD_GUAC_VERSION} to ${NEW_GUAC_VERSION} upgrade...\"\nwget -q --show-progress -O guacamole-${NEW_GUAC_VERSION}.war ${GUAC_SOURCE_LINK}/binary/guacamole-${NEW_GUAC_VERSION}.war\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed to download guacamole-${NEW_GUAC_VERSION}.war\" 1>&2\n    echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-${NEW_GUAC_VERSION}.war${GREY}\"\n    exit 1\nelse\n    rm /etc/guacamole/guacamole.war\n    mv -f guacamole-${NEW_GUAC_VERSION}.war /etc/guacamole/guacamole.war\n    chmod 664 /etc/guacamole/guacamole.war\nfi\necho -e \"${LGREEN}Upgraded Guacamole client to version ${NEW_GUAC_VERSION}${GREY}\"\n\n# Download and upgrade Guacamole SQL authentication extension\nwget -q --show-progress -O guacamole-auth-jdbc-${NEW_GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-jdbc-${NEW_GUAC_VERSION}.tar.gz\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed to download guacamole-auth-jdbc-${NEW_GUAC_VERSION}.tar.gz\" 1>&2\n    echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-jdbc-${NEW_GUAC_VERSION}.tar.gz\"\n    exit 1\nelse\n    tar -xzf guacamole-auth-jdbc-${NEW_GUAC_VERSION}.tar.gz\n    rm /etc/guacamole/extensions/guacamole-auth-jdbc-*.jar\n    mv -f guacamole-auth-jdbc-${NEW_GUAC_VERSION}/mysql/guacamole-auth-jdbc-mysql-${NEW_GUAC_VERSION}.jar /etc/guacamole/extensions/\n    chmod 664 /etc/guacamole/extensions/guacamole-auth-jdbc-mysql-${NEW_GUAC_VERSION}.jar\nfi\necho -e \"${LGREEN}Upgraded Guacamole SQL jdbc to version ${NEW_GUAC_VERSION}${GREY}\"\n\n# Download MySQL connector/j\nwget -q --show-progress -O mysql-connector-j-${NEW_MYSQLJCON}.tar.gz https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-j-${NEW_MYSQLJCON}.tar.gz\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed to download mysql-connector-j-${NEW_MYSQLJCON}.tar.gz\" 1>&2\n    echo -e \"https://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-j-${NEW_MYSQLJCON}}.tar.gz${GREY}\"\n    exit 1\nelse\n    tar -xzf mysql-connector-j-${NEW_MYSQLJCON}.tar.gz\n    rm /etc/guacamole/lib/mysql-connector-java.jar\n    mv -f mysql-connector-j-${NEW_MYSQLJCON}/mysql-connector-j-${NEW_MYSQLJCON}.jar /etc/guacamole/lib/mysql-connector-java.jar\nfi\necho -e \"${LGREEN}Upgraded MySQL connector/j to ${NEW_MYSQLJCON}${GREY}\"\n\n# Download Guacamole Server\nwget -q --show-progress -O guacamole-server-${NEW_GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/source/guacamole-server-${NEW_GUAC_VERSION}.tar.gz\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed to download guacamole-server-${NEW_GUAC_VERSION}.tar.gz\" 1>&2\n    echo -e \"${GUAC_SOURCE_LINK}/source/guacamole-server-${NEW_GUAC_VERSION}.tar.gz${GREY}\"\n    exit 1\nelse\n    tar -xzf guacamole-server-${NEW_GUAC_VERSION}.tar.gz\nfi\necho -e \"${LGREEN}Downloaded guacamole-server-${NEW_GUAC_VERSION}.tar.gz${GREY}\"\n\n# Add customised RDP share names and printer labels, remove Guacamole default labelling\nsed -i -e 's/IDX_CLIENT_NAME, \"Guacamole RDP\"/IDX_CLIENT_NAME, \"'\"${RDP_SHARE_HOST}\"'\"/' ${DOWNLOAD_DIR}/guacamole-server-${NEW_GUAC_VERSION}/src/protocols/rdp/settings.c\nsed -i -e 's/IDX_DRIVE_NAME, \"Guacamole Filesystem\"/IDX_DRIVE_NAME, \"'\"${RDP_SHARE_LABEL}\"'\"/' ${DOWNLOAD_DIR}/guacamole-server-${NEW_GUAC_VERSION}/src/protocols/rdp/settings.c\nsed -i -e 's/IDX_PRINTER_NAME, \"Guacamole Printer\"/IDX_PRINTER_NAME, \"'\"${RDP_PRINTER_LABEL}\"'\"/' ${DOWNLOAD_DIR}/guacamole-server-${NEW_GUAC_VERSION}/src/protocols/rdp/settings.c\n\n# Make and install guacd (Guacamole-Server)\ncd guacamole-server-${NEW_GUAC_VERSION}/\necho\necho -e \"${GREY}Compiling Guacamole-Server ${NEW_GUAC_VERSION} from source with with GCC $(gcc --version | head -n1 | grep -oP '\\)\\K.*' | awk '{print $1}'), this might take a few minutes...${GREY}\"\n# Fix for warnings see #222 https://github.com/MysticRyuujin/guac-install/issues/222\nexport CFLAGS=\"-Wno-error\"\n# Configure Guacamole Server source\n./configure --with-systemd-dir=/etc/systemd/system &>>${INSTALL_LOG}\nif [[ $? -ne 0 ]]; then\n    echo \"Failed to configure guacamole-server\"\n    echo \"Trying again with --enable-allow-freerdp-snapshots\"\n    ./configure --with-systemd-dir=/etc/systemd/system --enable-allow-freerdp-snapshots\n    if [[ $? -ne 0 ]]; then\n        echo \"Failed to configure guacamole-server - again\"\n        exit\n    fi\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\necho -e \"${GREY}Running make and building the upgraded Guacamole-Server application...\"\nmake &>>${INSTALL_LOG}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\necho -e \"${GREY}Installing the upgraded Guacamole-Server...\"\nmake install &>>${INSTALL_LOG}\nldconfig\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\ncd ..\n\n# Don't run the SQL upgrade commands if original setup option was set to remote MySQL instance. - Use separate DB update script.\nif [[ \"${INSTALL_MYSQL}\" = true ]]; then\n    # Get list of SQL Upgrade Files\n    echo -e \"${GREY}Upgrading MySQL Schema...\"\n    UPGRADEFILES=($(ls -1 guacamole-auth-jdbc-${NEW_GUAC_VERSION}/mysql/schema/upgrade/ | sort -V))\n\n    # Compare SQL Upgrage Files against old version, apply upgrades as needed\n    for FILE in ${UPGRADEFILES[@]}; do\n        FILEVERSION=$(echo ${FILE} | grep -oP 'upgrade-pre-\\K[0-9\\.]+(?=\\.)')\n        if [[ $(echo -e \"${FILEVERSION}\\n${OLD_GUAC_VERSION}\" | sort -V | head -n1) == ${OLD_GUAC_VERSION} && ${FILEVERSION} != ${OLD_GUAC_VERSION} ]]; then\n            echo \"Patching ${GUAC_DB} with ${FILE}\"\n\n    \t\tif [[ ! -z \"$MYSQL_ROOT_PWD\" ]]; then\n                \tmysql -u root -p${MYSQL_ROOT_PWD} -D ${GUAC_DB} -h ${MYSQL_HOST} -P ${MYSQL_PORT} <guacamole-auth-jdbc-${NEW_GUAC_VERSION}/mysql/schema/upgrade/${FILE} &>>${INSTALL_LOG}\n            \telse\n\t\t\tmysql -u root -D ${GUAC_DB} -h ${MYSQL_HOST} -P ${MYSQL_PORT} <guacamole-auth-jdbc-${NEW_GUAC_VERSION}/mysql/schema/upgrade/${FILE} &>>${INSTALL_LOG}\n\t    \tfi\n        fi\n    done\n    if [[ $? -ne 0 ]]; then\n        echo -e \"${LRED}SQL upgrade failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n        exit 1\n    else\n        echo -e \"${LGREEN}OK${GREY}\"\n        echo\n    fi\nfi\n\n# Check for TOTP extension and upgrade if found\nfor file in /etc/guacamole/extensions/guacamole-auth-totp*.jar; do\n    if [[ -f $file ]]; then\n        echo -e \"${LGREEN}TOTP authentication extension was found, upgrading...${GREY}\"\n        rm /etc/guacamole/extensions/guacamole-auth-totp*.jar &>>${INSTALL_LOG}\n        wget -q --show-progress -O guacamole-auth-totp-${NEW_GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-totp-${NEW_GUAC_VERSION}.tar.gz\n        if [[ $? -ne 0 ]]; then\n            echo -e \"${LRED}Failed to download guacamole-auth-totp-${NEW_GUAC_VERSION}.tar.gz\" 1>&2\n            echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-totp-${NEW_GUAC_VERSION}.tar.gz\"\n            exit 1\n        fi\n        tar -xzf guacamole-auth-totp-${NEW_GUAC_VERSION}.tar.gz &>>${INSTALL_LOG}\n        mv -f guacamole-auth-totp-${NEW_GUAC_VERSION}/guacamole-auth-totp-${NEW_GUAC_VERSION}.jar /etc/guacamole/extensions/ &>>${INSTALL_LOG}\n        chmod 664 /etc/guacamole/extensions/guacamole-auth-totp-${NEW_GUAC_VERSION}.jar\n        echo -e \"${LGREEN}Upgraded TOTP extension to version ${NEW_GUAC_VERSION}${GREY}\"\n        echo\n        break\n    fi\ndone\n\n# Check for DUO extension and upgrade if found\nfor file in /etc/guacamole/extensions/guacamole-auth-duo*.jar; do\n    if [[ -f $file ]]; then\n        echo -e \"${LGREEN}DUO authentication extension was found, upgrading...${GREY}\"\n        rm /etc/guacamole/extensions/guacamole-auth-duo*.jar &>>${INSTALL_LOG}\n        wget -q --show-progress -O guacamole-auth-duo-${NEW_GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-duo-${NEW_GUAC_VERSION}.tar.gz\n        if [[ $? -ne 0 ]]; then\n            echo -e \"${LRED}Failed to download guacamole-auth-duo-${NEW_GUAC_VERSION}.tar.gz\" 1>&2\n            echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-duo-${NEW_GUAC_VERSION}.tar.gz\"\n            exit 1\n        fi\n        tar -xzf guacamole-auth-duo-${NEW_GUAC_VERSION}.tar.gz &>>${INSTALL_LOG}\n        mv -f guacamole-auth-duo-${NEW_GUAC_VERSION}/guacamole-auth-duo-${NEW_GUAC_VERSION}.jar /etc/guacamole/extensions/ &>>${INSTALL_LOG}\n        chmod 664 /etc/guacamole/extensions/guacamole-auth-duo-${NEW_GUAC_VERSION}.jar\n        echo -e \"${LGREEN}Upgraded DUO extension to version ${NEW_GUAC_VERSION}${GREY}\"\n        echo\n        break\n    fi\ndone\n\n# Check for LDAP extension and upgrade if found\nfor file in /etc/guacamole/extensions/guacamole-auth-ldap*.jar; do\n    if [[ -f $file ]]; then\n        echo -e \"${LGREEN}LDAP authentication extension was found, upgrading...${GREY}\"\n        rm /etc/guacamole/extensions/guacamole-auth-ldap*.jar &>>${INSTALL_LOG}\n        wget -q --show-progress -O guacamole-auth-ldap-${NEW_GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-ldap-${NEW_GUAC_VERSION}.tar.gz\n        if [[ $? -ne 0 ]]; then\n            echo -e \"${LRED}Failed to download guacamole-auth-ldap-${NEW_GUAC_VERSION}.tar.gz\" 1>&2\n            echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-ldap-${NEW_GUAC_VERSION}.tar.gz\"\n            exit 1\n        fi\n        tar -xzf guacamole-auth-ldap-${NEW_GUAC_VERSION}.tar.gz &>>${INSTALL_LOG}\n        mv -f guacamole-auth-ldap-${NEW_GUAC_VERSION}/guacamole-auth-ldap-${NEW_GUAC_VERSION}.jar /etc/guacamole/extensions/ &>>${INSTALL_LOG}\n        chmod 664 /etc/guacamole/extensions/guacamole-auth-ldap-${NEW_GUAC_VERSION}.jar\n        echo -e \"${LGREEN}Upgraded LDAP extension to version ${NEW_GUAC_VERSION}${GREY}\"\n        echo\n        break\n    fi\ndone\n\n# Check for Quick Connection extension and upgrade if found\nfor file in /etc/guacamole/extensions/guacamole-auth-quickconnect*.jar; do\n    if [[ -f $file ]]; then\n        echo -e \"${LGREEN}Quick Connect extension was found, upgrading...${GREY}\"\n        rm /etc/guacamole/extensions/guacamole-auth-quickconnect*.jar &>>${INSTALL_LOG}\n        wget -q --show-progress -O guacamole-auth-quickconnect-${NEW_GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-auth-quickconnect-${NEW_GUAC_VERSION}.tar.gz\n        if [[ $? -ne 0 ]]; then\n            echo -e \"${LRED}Failed to download guacamole-auth-quickconnect-${NEW_GUAC_VERSION}.tar.gz\" 1>&2\n            echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-auth-quickconnect-${NEW_GUAC_VERSION}.tar.gz\"\n            exit 1\n        fi\n        tar -xzf guacamole-auth-quickconnect-${NEW_GUAC_VERSION}.tar.gz &>>${INSTALL_LOG}\n        mv -f guacamole-auth-quickconnect-${NEW_GUAC_VERSION}/guacamole-auth-quickconnect-${NEW_GUAC_VERSION}.jar /etc/guacamole/extensions/ &>>${INSTALL_LOG}\n        chmod 664 /etc/guacamole/extensions/guacamole-auth-quickconnect-${NEW_GUAC_VERSION}.jar\n        echo -e \"${LGREEN}Upgraded Quick Connect extension to version ${NEW_GUAC_VERSION}${GREY}\"\n        echo\n        break\n    fi\ndone\n\n# Check for History Recording Storage extension and upgrade if found\nfor file in /etc/guacamole/extensions/guacamole-history-recording-storage*.jar; do\n    if [[ -f $file ]]; then\n        echo -e \"${LGREEN}History Recording Storage extension was found, upgrading...${GREY}\"\n        rm /etc/guacamole/extensions/guacamole-history-recording-storage*.jar &>>${INSTALL_LOG}\n        wget -q --show-progress -O guacamole-history-recording-storage-${NEW_GUAC_VERSION}.tar.gz ${GUAC_SOURCE_LINK}/binary/guacamole-history-recording-storage-${NEW_GUAC_VERSION}.tar.gz\n        if [[ $? -ne 0 ]]; then\n            echo -e \"${LRED}Failed to download guacamole-history-recording-storage-${NEW_GUAC_VERSION}.tar.gz\" 1>&2\n            echo -e \"${GUAC_SOURCE_LINK}/binary/guacamole-history-recording-storage-${NEW_GUAC_VERSION}.tar.gz\"\n            exit 1\n        fi\n        tar -xzf guacamole-history-recording-storage-${NEW_GUAC_VERSION}.tar.gz &>>${INSTALL_LOG}\n        mv -f guacamole-history-recording-storage-${NEW_GUAC_VERSION}/guacamole-history-recording-storage-${NEW_GUAC_VERSION}.jar /etc/guacamole/extensions/ &>>${INSTALL_LOG}\n        chmod 664 /etc/guacamole/extensions/guacamole-history-recording-storage-${NEW_GUAC_VERSION}.jar\n        echo -e \"${LGREEN}Upgraded History Recording Storage extension to version ${NEW_GUAC_VERSION}${GREY}\"\n        echo\n        break\n    fi\ndone\n\n# Bring guacd and Tomcat back up\necho -e \"${GREY}Starting guacd and Tomcat services...\"\n\n# Reset freerdp profile permissions for storing certificates\nmkdir -p /home/\"${GUACD_ACCOUNT}\"/.config/freerdp\nchown ${GUACD_ACCOUNT}:${GUACD_ACCOUNT} /home/\"${GUACD_ACCOUNT}\"/.config/freerdp\n\n# Reset guacamole permissions\nmkdir -p /var/guacamole\nchown \"${GUACD_ACCOUNT}\":\"${GUACD_ACCOUNT}\" /var/guacamole\n\n# Reset the guacd systemd unit file's default service account \nsudo sed -i \"s/\\bdaemon\\b/${GUACD_ACCOUNT}/g\" /etc/systemd/system/guacd.service\nsystemctl daemon-reload\nsystemctl enable guacd\nsystemctl start guacd\nsystemctl start ${TOMCAT_VERSION}\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Cleanup\necho -e \"${GREY}Clean up install files...${GREY}\"\nsudo apt -y remove build-essential\nrm -rf guacamole-*\nrm -rf mysql-connector-j-*\nsudo apt-get -y autoremove\nif [[ $? -ne 0 ]]; then\n    echo -e \"${LRED}Failed. See ${INSTALL_LOG}${GREY}\" 1>&2\n    exit 1\nelse\n    echo -e \"${LGREEN}OK${GREY}\"\n    echo\nfi\n\n# Done\nprintf \"${LGREEN}Guacamole ${NEW_GUAC_VERSION} upgrade complete! \\n${NC}\"\necho -e ${NC}\n"
  }
]