From 111639f86d92b86a6ef1296619ddf6356f66f561 Mon Sep 17 00:00:00 2001 From: Sebastian Knopp Date: Tue, 4 Aug 2020 11:35:44 +0200 Subject: [PATCH 1/8] override banian/php update script to work with custom vendor updates --- Dockerfile | 2 +- bin/update | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 bin/update diff --git a/Dockerfile b/Dockerfile index 867a0c9..fcbb491 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,6 @@ COPY conf/msmtp /etc/msmtp.default # Conf files RUN touch /etc/msmtp /etc/osticket.secret.txt /etc/cron.d/osticket && \ chown www-data:www-data /etc/msmtp /etc/osticket.secret.txt /etc/cron.d/osticket && \ - chown root:www-data /bin/vendor && chmod 770 /bin/vendor + chown root:www-data /bin/vendor /bin/update && chmod 770 /bin/vendor /bin/update VOLUME /var/www diff --git a/bin/update b/bin/update new file mode 100644 index 0000000..88a6f15 --- /dev/null +++ b/bin/update @@ -0,0 +1,66 @@ +#!/bin/bash +set -e + +LOCK_FILE=/update.lock + +# Check if lock file exists +if [ -f $LOCK_FILE ] ; then + # Check if really running + PID=`cat $LOCK_FILE` + if [ kill -s 0 $PID ] ; then + echo "$LOCK_FILE' with PID=$PID exists and running..." + exit 1 + fi + echo "Warn: Cleaning stale lock file..." +fi + +# Update lockfile with current PID +echo $$ > $LOCK_FILE + +# Fix +fix + +# Go to src +cd /var/www/src + +# Git repo +if [ ! -z $GIT_REPO ]; then + if [ -d .git ] ; then + run-as-www git pull + else + rmdir public + run-as-www git clone $GIT_REPO . + fi +fi + +# Composer +if [ -f composer.json ] ; then + run-as-www composer install --no-dev --no-interaction --no-progress --optimize-autoloader +fi + +# .env +if [ -f .env.example ] && [ ! -f .env ]; then + run-as-www cp -v .env.example .env +fi + +# Laravel +if [ -f artisan ] ; then + source .env + if [ -z $APP_KEY ]; then + run-as-www php artisan key:generate + fi + run-as-www php artisan migrate || true +fi + +# Yarn (do in background) +if [ -f yarn.lock ] ; then + yarn-build & +fi + +# User script +if [ -x /bin/vendor ] ; then + run-as-www vendor +fi + +# Remove lock file +rm /update.lock From 7c4d6ddba35e09b9420ad7820d0eb417444fcf95 Mon Sep 17 00:00:00 2001 From: Sebastian Knopp Date: Tue, 4 Aug 2020 11:36:34 +0200 Subject: [PATCH 2/8] updated parameters for osTicket manage.php script --- bin/vendor | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/vendor b/bin/vendor index 4adf9dd..26e0203 100644 --- a/bin/vendor +++ b/bin/vendor @@ -2,7 +2,7 @@ # Vendor script that runs on every container update event echo Deploying osTicket -php /var/www/src/manage.php deploy -gsv /var/www/src/public || exit 1 +php /var/www/src/manage.php deploy -sfCgv /var/www/src/public || exit 1 echo Install/Update osTicket php /bin/osticket-install.php || exit 1 From 072298768fca5b39ee7f25ce5eecf29f0fb82b0c Mon Sep 17 00:00:00 2001 From: Sebastian Knopp Date: Tue, 4 Aug 2020 11:37:34 +0200 Subject: [PATCH 3/8] added build routine to docker-compose, updated docker-compose to v3 --- docker-compose.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 344fe7b..521c7f8 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,18 +1,19 @@ -version: '2' +version: '3' services: osticket: + build: . image: osticket/osticket environment: - MYSQL_HOST=mysql - MYSQL_DATABASE=osticket - MYSQL_USER=osticket - MYSQL_PASSWORD=0T1cket - + # CHANGE ME - INSTALL_SECRET=secret - + - LANGUAGE=fa links: From b94a1eb1ac51d63fa7d3bacfd041f350bb9d5ec0 Mon Sep 17 00:00:00 2001 From: Sebastian Knopp Date: Tue, 4 Aug 2020 13:14:44 +0200 Subject: [PATCH 4/8] fixed directory constants for current setup version --- bin/osticket-install.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/bin/osticket-install.php b/bin/osticket-install.php index 4805a33..96e85a1 100644 --- a/bin/osticket-install.php +++ b/bin/osticket-install.php @@ -4,11 +4,12 @@ //Script settings -define('INSTALL_DIR','/var/www/src/public'); -define('SETUP_DIR',INSTALL_DIR.'/../setup'); // use git setup -define('INC_DIR',INSTALL_DIR.'/include'); -define('INSTALL_CONFIG',INC_DIR.'/ost-sampleconfig.php'); -define('OSTICKET_CONFIGFILE',INC_DIR.'/ost-config.php'); +define('INSTALL_DIR','/var/www/src/public/'); +define('SETUP_DIR',INSTALL_DIR.'../setup/'); // use git setup +define('INC_DIR',SETUP_DIR.'inc/'); +define('INCLUDE_DIR',INSTALL_DIR.'include/'); +define('INSTALL_CONFIG',INCLUDE_DIR.'ost-sampleconfig.php'); +define('OSTICKET_CONFIGFILE',INCLUDE_DIR.'ost-config.php'); define('MAIL_CONFIG','/etc/msmtp.default'); define('MAIL_CONFIG_FILE','/etc/msmtp'); @@ -73,8 +74,8 @@ function convertStrToBool($varName, $default) { // Require files (must be done before any output to avoid session start warnings) // $_SERVER['HTTP_ACCEPT_LANGUAGE'] = LANGUAGE; chdir(SETUP_DIR); -require SETUP_DIR.'/setup.inc.php'; -require SETUP_DIR.'/inc/class.installer.php'; +require SETUP_DIR.'setup.inc.php'; +require SETUP_DIR.'inc/class.installer.php'; /************************* Mail Configuration *******************************************/ echo "Configuring mail settings\n"; From 29d500ad61535bff81b0ac0bd4350cd0027be18d Mon Sep 17 00:00:00 2001 From: Sebastian Knopp Date: Sat, 10 Oct 2020 11:52:45 +0200 Subject: [PATCH 5/8] updating nginx configuration for osticket requirements, fixes path_info override through try_files --- Dockerfile | 1 + conf/default.conf | 76 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 conf/default.conf diff --git a/Dockerfile b/Dockerfile index fcbb491..c019392 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,6 +13,7 @@ ENV GIT_REPO=https://github.com/osTicket/osTicket COPY bin /bin COPY conf/supervisord /etc/supervisor/conf.d/osticket.conf COPY conf/msmtp /etc/msmtp.default +COPY conf/default.conf /etc/nginx/conf.d/default.conf # Conf files RUN touch /etc/msmtp /etc/osticket.secret.txt /etc/cron.d/osticket && \ diff --git a/conf/default.conf b/conf/default.conf new file mode 100644 index 0000000..157a9e1 --- /dev/null +++ b/conf/default.conf @@ -0,0 +1,76 @@ +# Default Server +server { + # Port that the web server will listen on. + listen 80 default; + + # Host that will serve this project. + server_name _; + + # The location of our projects public directory. + root /var/www/src/public; + + # Index + index index.php index.html; + + try_files $uri $uri/ /index.php?$query_string; + + set $path_info2 ""; + + location ~ /include { + deny all; + return 403; + } + + if ($request_uri ~ "^/api(/[^\?]+)") { + set $path_info2 $1; + } + + location ~ ^/api/(?:tickets|tasks).*$ { + try_files $uri $uri/ /api/http.php?$query_string; + } + + if ($request_uri ~ "^/scp/.*\.php(/[^\?]+)") { + set $path_info2 $1; + } + + if ($request_uri ~ "^/.*\.php(/[^\?]+)") { + set $path_info2 $1; + } + + location ~ ^/scp/ajax.php/.*$ { + try_files $uri $uri/ /scp/ajax.php?$query_string; + } + + location ~ ^/ajax.php/.*$ { + try_files $uri $uri/ /ajax.php?$query_string; + } + + location / { + try_files $uri $uri/ index.php; + } + + location ~ \.php$ { + include snippets/fastcgi-php.conf; + fastcgi_param PATH_INFO $path_info2; + fastcgi_param HTTPS $fe_https; + fastcgi_pass unix:/run/php/php-fpm.sock; + } + + location ~ /\.ht {deny all;} +} + +# Status server +server { + listen 8080; + + location /nginx_status { + stub_status on; + access_log off; + } + + location ~ ^/(status|ping)$ { + include fastcgi_params; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_pass unix:/run/php/php-fpm.sock; + } +} From df49eea34c764e23e74965f123db97a83c4a38d0 Mon Sep 17 00:00:00 2001 From: Sebastian Knopp Date: Sun, 11 Oct 2020 14:16:49 +0200 Subject: [PATCH 6/8] made ROOT_PATH config parameter usable through docker --- bin/osticket-install.php | 9 +++++++-- docker-compose.yml | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/bin/osticket-install.php b/bin/osticket-install.php index 96e85a1..194e247 100644 --- a/bin/osticket-install.php +++ b/bin/osticket-install.php @@ -47,7 +47,8 @@ 'smtp_pass' => getenv("SMTP_PASSWORD"), 'cron_interval' => getenv("CRON_INTERVAL") ?: 5, 'siri' => getenv("INSTALL_SECRET"), - 'config' => getenv("INSTALL_CONFIG") ?: INSTALL_CONFIG, + 'root_path' => getenv("ROOT_PATH"), + 'config' => getenv("INSTALL_CONFIG") ?: INSTALL_CONFIG, ); // Helper functions @@ -72,7 +73,7 @@ function convertStrToBool($varName, $default) { } // Require files (must be done before any output to avoid session start warnings) -// $_SERVER['HTTP_ACCEPT_LANGUAGE'] = LANGUAGE; +// $_SERVER['HTTP_ACCEPT_LANGUAGE'] = LANGUAGE; chdir(SETUP_DIR); require SETUP_DIR.'setup.inc.php'; require SETUP_DIR.'inc/class.installer.php'; @@ -193,6 +194,10 @@ function convertStrToBool($varName, $default) { $configFile= str_replace('%CONFIG-DBPASS',$vars['dbpass'],$configFile); $configFile= str_replace('%CONFIG-PREFIX',$vars['prefix'],$configFile); $configFile= str_replace('%CONFIG-SIRI',$vars['siri'],$configFile); +if($vars['root_path']){ + $configFile = str_replace("# define('ROOT_PATH', '/support/');","define('ROOT_PATH', '".$vars['root_path']."');",$configFile); +} + if (!file_put_contents($installer->getConfigFile(), $configFile)) { err("Failed to write configuration file"); } diff --git a/docker-compose.yml b/docker-compose.yml index 521c7f8..7193269 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,6 +16,7 @@ services: - LANGUAGE=fa + - ROOT_PATH=/ links: - mysql:mysql ports: From 5e64ee0308131d66365d3993aedf795f690f2ae9 Mon Sep 17 00:00:00 2001 From: Sebastian Knopp Date: Sun, 11 Oct 2020 17:20:59 +0200 Subject: [PATCH 7/8] added support for hosting under subdirectory paths in nginx --- Dockerfile | 2 +- README.md | 4 ++++ bin/update | 7 +++++++ conf/default.conf | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index c019392..c4c745f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,7 +13,7 @@ ENV GIT_REPO=https://github.com/osTicket/osTicket COPY bin /bin COPY conf/supervisord /etc/supervisor/conf.d/osticket.conf COPY conf/msmtp /etc/msmtp.default -COPY conf/default.conf /etc/nginx/conf.d/default.conf +COPY conf/default.conf /tmp/default.conf.template # Conf files RUN touch /etc/msmtp /etc/osticket.secret.txt /etc/cron.d/osticket && \ diff --git a/README.md b/README.md index fef828b..a1f08a4 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,10 @@ specified in the admin control panel, you need to specify both to the value you' # Environmental Variables +`ROOT_PATH` + +If you want to host osTicket under a subdirectory path of your domain you must set this path here, so osTicket can properly reference it's source files. Defaults to `/`. + `INSTALL_SECRET` Secret string value for OST installation. A random value is generated on start-up and persisted within the container if this is not provided. diff --git a/bin/update b/bin/update index 88a6f15..405d886 100644 --- a/bin/update +++ b/bin/update @@ -20,6 +20,13 @@ echo $$ > $LOCK_FILE # Fix fix +cp /tmp/default.conf.template /etc/nginx/conf.d/default.conf +# configure nginx for possible ROOT_PATH +if [ ! -z $ROOT_PATH ] && [ "$ROOT_PATH" != '/' ]; then + nginx_rewrite="location ^~ $ROOT_PATH { rewrite ^$ROOT_PATH(.*)\$ /\$1 last;}" + sed -i "s|# %APPEND_REDIRECT_HERE%|$nginx_rewrite|g" /etc/nginx/conf.d/default.conf +fi + # Go to src cd /var/www/src diff --git a/conf/default.conf b/conf/default.conf index 157a9e1..17a0111 100644 --- a/conf/default.conf +++ b/conf/default.conf @@ -12,6 +12,8 @@ server { # Index index index.php index.html; + # %APPEND_REDIRECT_HERE% + try_files $uri $uri/ /index.php?$query_string; set $path_info2 ""; From b4c506d0ecc50ccdfd95e0a533603480738150c1 Mon Sep 17 00:00:00 2001 From: Sebastian Knopp Date: Sun, 11 Oct 2020 17:22:10 +0200 Subject: [PATCH 8/8] setting helpdesk_url through docker envs --- README.md | 4 ++++ bin/osticket-install.php | 10 +++++++++- docker-compose.yml | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a1f08a4..d6a918c 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,10 @@ specified in the admin control panel, you need to specify both to the value you' # Environmental Variables +`HOST` + +Sets the 'host' part of the osTicket URL in database, eg. for links in ticket mails. + `ROOT_PATH` If you want to host osTicket under a subdirectory path of your domain you must set this path here, so osTicket can properly reference it's source files. Defaults to `/`. diff --git a/bin/osticket-install.php b/bin/osticket-install.php index 194e247..fd91fb1 100644 --- a/bin/osticket-install.php +++ b/bin/osticket-install.php @@ -47,6 +47,7 @@ 'smtp_pass' => getenv("SMTP_PASSWORD"), 'cron_interval' => getenv("CRON_INTERVAL") ?: 5, 'siri' => getenv("INSTALL_SECRET"), + 'host' => getenv("HOST"), 'root_path' => getenv("ROOT_PATH"), 'config' => getenv("INSTALL_CONFIG") ?: INSTALL_CONFIG, ); @@ -224,5 +225,12 @@ function convertStrToBool($varName, $default) { echo "System Language Set\n"; } -// Install finished +// Update helpdesk_url +echo "Setting helpdesk url to ".$vars['host']."\n"; +$sql = "UPDATE `".$vars['prefix']."config` SET `value`='".$vars['host'].$vars['root_path']."' WHERE `key`='helpdesk_url'"; +if (db_query($sql, false)) { + echo "helpdesk url Set\n"; +} + +// Install finished echo "Install Script finished!\n"; diff --git a/docker-compose.yml b/docker-compose.yml index 7193269..e1b90d9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,6 +16,7 @@ services: - LANGUAGE=fa + - HOST=localhost:80 - ROOT_PATH=/ links: - mysql:mysql