commit 373bfe13aac87b6b910a55acdb6cf9d5c432c679 Author: root Date: Thu May 30 12:09:36 2024 +0000 init repo diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..14a49f4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +config/ +db-data/ diff --git a/composer-db.yml b/composer-db.yml new file mode 100644 index 0000000..4bf1b36 --- /dev/null +++ b/composer-db.yml @@ -0,0 +1,15 @@ +version: '3' +services: + guacdb: + container_name: guacamoledb + image: mariadb:10.9.5 + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: 'MariaDBRootPass' + MYSQL_DATABASE: 'guacamole_db' + MYSQL_USER: 'guacamole_user' + MYSQL_PASSWORD: 'MariaDBUserPass' + volumes: + - './db-data:/var/lib/mysql' +volumes: + db-data: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ebd53ad --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,40 @@ +version: '3' +services: + guacdb: + container_name: guacamoledb + image: mariadb:10.9.5 + restart: unless-stopped + environment: + MYSQL_ROOT_PASSWORD: 'MariaDBRootPass' + MYSQL_DATABASE: 'guacamole_db' + MYSQL_USER: 'guacamole_user' + MYSQL_PASSWORD: 'MariaDBUserPass' + volumes: + - './db-data:/var/lib/mysql' + guacd: + container_name: guacd + image: guacamole/guacd:1.5.5 + restart: unless-stopped + ports: + - 4822:4822 + guacamole: + container_name: guacamole + #image: guacamole/guacamole:1.5.5 + build: ./docker-guacamole-custom + restart: unless-stopped + ports: + - 8080:8080 + environment: + GUACD_HOSTNAME: "guacd" + MYSQL_HOSTNAME: "guacdb" + MYSQL_DATABASE: "guacamole_db" + MYSQL_USER: "guacamole_user" + MYSQL_PASSWORD: "MariaDBUserPass" + #TOTP_ENABLED: "true" + QUICKCONNECT_ENABLED: "true" + entrypoint: /opt/guacamole/bin/entrypoint.sh + depends_on: + - guacdb + - guacd +volumes: + db-data: diff --git a/docker-guacamole-custom/Dockerfile b/docker-guacamole-custom/Dockerfile new file mode 100644 index 0000000..d46f1ed --- /dev/null +++ b/docker-guacamole-custom/Dockerfile @@ -0,0 +1,36 @@ +FROM guacamole/guacamole:1.5.5 + +COPY files/start.sh /opt/guacamole/bin/start.sh +COPY files/entrypoint.sh /opt/guacamole/bin/entrypoint.sh +COPY files/inject-trigger.sh /opt/guacamole/bin/inject-trigger.sh +COPY files/quickconnect /opt/guacamole/quickconnect + +ARG RELEASE +ARG LAUNCHPAD_BUILD_ARCH +LABEL org.opencontainers.image.ref.name=ubuntu +LABEL org.opencontainers.image.version=22.04 +CMD ["/bin/bash"] +ENV JAVA_HOME=/opt/java/openjdk +ENV PATH=/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin +ENV LANG=en_US.UTF-8 LANGUAGE=en_US:en LC_ALL=en_US.UTF-8 +ENV JAVA_VERSION=jdk8u402-b06 +ENTRYPOINT ["/__cacert_entrypoint.sh"] +ENV CATALINA_HOME=/usr/local/tomcat +ENV PATH=/usr/local/tomcat/bin:/opt/java/openjdk/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +WORKDIR /usr/local/tomcat +ENV TOMCAT_NATIVE_LIBDIR=/usr/local/tomcat/native-jni-lib +ENV LD_LIBRARY_PATH=/usr/local/tomcat/native-jni-lib +ENV GPG_KEYS="05AB33110949707C93A279E3D3EFE6B686867BA6 07E48665A34DCAFAE522E5E6266191C37C037D42 47309207D818FFD8DCD3F83F1931D684307A10A5" +ENV TOMCAT_MAJOR=8 +ENV TOMCAT_VERSION=8.5.98 +ENV TOMCAT_SHA512=12f58114fe608fdc5f06e99a4ba01852396169f89d08e1ecf96ace36dd685c439519433e7750bfa7523f12c14788a3b5cb9ee3835dd1cce37e2cee121d69625e +EXPOSE 8080 +ENTRYPOINT [] +CMD ["catalina.sh" "run"] +WORKDIR /opt/guacamole +ARG UID=1001 +ARG GID=1001 +USER guacamole +EXPOSE 8080 +CMD ["/opt/guacamole/bin/start.sh"] diff --git a/docker-guacamole-custom/files/entrypoint.sh b/docker-guacamole-custom/files/entrypoint.sh new file mode 100755 index 0000000..4e676a4 --- /dev/null +++ b/docker-guacamole-custom/files/entrypoint.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +/opt/guacamole/bin/start.sh & + +# Esperar que o Tomcat esteja totalmente inicializado +while ! curl -sSf http://localhost:8080/guacamole >/dev/null; do + echo "Aguardando Tomcat iniciar..." + sleep 2 +done + +# Executar o script adicional +/opt/guacamole/bin/inject-trigger.sh + +# Manter o container em execução +wait + diff --git a/docker-guacamole-custom/files/inject-trigger.sh b/docker-guacamole-custom/files/inject-trigger.sh new file mode 100755 index 0000000..b08294e --- /dev/null +++ b/docker-guacamole-custom/files/inject-trigger.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +if [ -f /home/guacamole/tomcat/webapps/guacamole/templates.js ]; then + cat <> /home/guacamole/tomcat/webapps/guacamole/templates.js + \$(window).on('load', function() { + function getHashParam(param) { + var hash = window.location.hash.substr(1); + var hashParams = new URLSearchParams(hash.split('?')[1]); + return hashParams.get(param); + } + + setTimeout(function() { + var quickconnectValue = getHashParam('quickconnect'); + if (quickconnectValue) { + var \$field = \$('.quickconnect-field'); + \$field.val(quickconnectValue); + \$field.trigger('input'); + \$field.trigger('change'); + \$('.quickconnect-button').click(); + } + }, 500); + }); +EOF +fi + diff --git a/docker-guacamole-custom/files/quickconnect/guacamole-auth-quickconnect-1.5.5.jar b/docker-guacamole-custom/files/quickconnect/guacamole-auth-quickconnect-1.5.5.jar new file mode 100644 index 0000000..6d332c1 Binary files /dev/null and b/docker-guacamole-custom/files/quickconnect/guacamole-auth-quickconnect-1.5.5.jar differ diff --git a/docker-guacamole-custom/files/start.sh b/docker-guacamole-custom/files/start.sh new file mode 100755 index 0000000..c322f47 --- /dev/null +++ b/docker-guacamole-custom/files/start.sh @@ -0,0 +1,1231 @@ +#!/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 <