#!/bin/bash -e # # Licensed to the Apache Software Foundation (ASF) under one # or more contributor license agreements. See the NOTICE file # distributed with this work for additional information # regarding copyright ownership. The ASF licenses this file # to you under the Apache License, Version 2.0 (the # "License"); you may not use this file except in compliance # with the License. You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, # software distributed under the License is distributed on an # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. # ## ## @fn start.sh ## ## Automatically configures and starts Guacamole under Tomcat. Guacamole's ## guacamole.properties file will be automatically generated based on the ## linked database container (either MySQL, PostgreSQL or SQLServer) and the linked guacd ## container. The Tomcat process will ultimately replace the process of this ## script, running in the foreground until terminated. ## GUACAMOLE_HOME_TEMPLATE="$GUACAMOLE_HOME" GUACAMOLE_HOME="$HOME/.guacamole" GUACAMOLE_EXT="$GUACAMOLE_HOME/extensions" GUACAMOLE_LIB="$GUACAMOLE_HOME/lib" GUACAMOLE_PROPERTIES="$GUACAMOLE_HOME/guacamole.properties" ## ## Sets the given property to the given value within guacamole.properties, ## creating guacamole.properties first if necessary. ## ## @param NAME ## The name of the property to set. ## ## @param VALUE ## The value to set the property to. ## set_property() { NAME="$1" VALUE="$2" # Ensure guacamole.properties exists if [ ! -e "$GUACAMOLE_PROPERTIES" ]; then mkdir -p "$GUACAMOLE_HOME" echo "# guacamole.properties - generated `date`" > "$GUACAMOLE_PROPERTIES" fi # Set property echo "$NAME: $VALUE" >> "$GUACAMOLE_PROPERTIES" } ## ## Sets the given property to the given value within guacamole.properties only ## if a value is provided, creating guacamole.properties first if necessary. ## ## @param NAME ## The name of the property to set. ## ## @param VALUE ## The value to set the property to, if any. If omitted or empty, the ## property will not be set. ## set_optional_property() { NAME="$1" VALUE="$2" # Set the property only if a value is provided if [ -n "$VALUE" ]; then set_property "$NAME" "$VALUE" fi } # Print error message regarding missing required variables for MySQL authentication mysql_missing_vars() { cat <= 40 characters. ## associate_duo() { # Verify required parameters are present if [ -z "$DUO_INTEGRATION_KEY" ] || \ [ -z "$DUO_SECRET_KEY" ] || \ [ ${#DUO_APPLICATION_KEY} -lt 40 ] then cat < element xmlstarlet edit --inplace \ --insert '/Server/Service/Engine/Host/*' --type elem -n Valve \ --insert '/Server/Service/Engine/Host/Valve[not(@className)]' --type attr -n className -v org.apache.catalina.valves.RemoteIpValve \ $CATALINA_BASE/conf/server.xml # Allowed IPs if [ -z "$PROXY_ALLOWED_IPS_REGEX" ]; then echo "Using default Tomcat allowed IPs regex" else xmlstarlet edit --inplace \ --insert '/Server/Service/Engine/Host/Valve[@className="org.apache.catalina.valves.RemoteIpValve"]' \ --type attr -n internalProxies -v "$PROXY_ALLOWED_IPS_REGEX" \ $CATALINA_BASE/conf/server.xml fi # X-Forwarded-For if [ -z "$PROXY_IP_HEADER" ]; then echo "Using default Tomcat proxy IP header" else xmlstarlet edit --inplace \ --insert "/Server/Service/Engine/Host/Valve[@className='org.apache.catalina.valves.RemoteIpValve']" \ --type attr -n remoteIpHeader -v "$PROXY_IP_HEADER" \ $CATALINA_BASE/conf/server.xml fi # X-Forwarded-Proto if [ -z "$PROXY_PROTOCOL_HEADER" ]; then echo "Using default Tomcat proxy protocol header" else xmlstarlet edit --inplace \ --insert "/Server/Service/Engine/Host/Valve[@className='org.apache.catalina.valves.RemoteIpValve']" \ --type attr -n protocolHeader -v "$PROXY_PROTOCOL_HEADER" \ $CATALINA_BASE/conf/server.xml fi # X-Forwarded-By if [ -z "$PROXY_BY_HEADER" ]; then echo "Using default Tomcat proxy forwarded by header" else xmlstarlet edit --inplace \ --insert "/Server/Service/Engine/Host/Valve[@className='org.apache.catalina.valves.RemoteIpValve']" \ --type attr -n remoteIpProxiesHeader -v "$PROXY_BY_HEADER" \ $CATALINA_BASE/conf/server.xml fi } ## ## Adds api-session-timeout to guacamole.properties ## associate_apisessiontimeout() { set_optional_property "api-session-timeout" "$API_SESSION_TIMEOUT" } ## ## Starts Guacamole under Tomcat, replacing the current process with the ## Tomcat process. As the current process will be replaced, this MUST be the ## last function run within the script. ## start_guacamole() { # User-only writable CATALINA_BASE export CATALINA_BASE=$HOME/tomcat for dir in logs temp webapps work; do mkdir -p $CATALINA_BASE/$dir done cp -R /usr/local/tomcat/conf $CATALINA_BASE # Set up Tomcat RemoteIPValve if [ "$REMOTE_IP_VALVE_ENABLED" = "true" ]; then enable_remote_ip_valve fi # Install webapp ln -sf /opt/guacamole/guacamole.war $CATALINA_BASE/webapps/${WEBAPP_CONTEXT:-guacamole}.war # Start tomcat cd /usr/local/tomcat exec catalina.sh run } # # Start with a fresh GUACAMOLE_HOME # rm -Rf "$GUACAMOLE_HOME" # # Copy contents of provided GUACAMOLE_HOME template, if any # if [ -n "$GUACAMOLE_HOME_TEMPLATE" ]; then cp -a "$GUACAMOLE_HOME_TEMPLATE/." "$GUACAMOLE_HOME/" fi # # Create and define Guacamole lib and extensions directories # mkdir -p "$GUACAMOLE_EXT" mkdir -p "$GUACAMOLE_LIB" # # Point to associated guacd # # Use linked container for guacd if specified if [ -n "$GUACD_NAME" ]; then GUACD_HOSTNAME="$GUACD_PORT_4822_TCP_ADDR" GUACD_PORT="$GUACD_PORT_4822_TCP_PORT" fi # Use default guacd port if none specified GUACD_PORT="${GUACD_PORT-4822}" # Verify required guacd connection information is present if [ -z "$GUACD_HOSTNAME" -o -z "$GUACD_PORT" ]; then cat <