diff --git a/Dockerfile b/Dockerfile index fcbb491..c4c745f 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 /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..d6a918c 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,14 @@ 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 `/`. + `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/osticket-install.php b/bin/osticket-install.php index 96e85a1..fd91fb1 100644 --- a/bin/osticket-install.php +++ b/bin/osticket-install.php @@ -47,7 +47,9 @@ 'smtp_pass' => getenv("SMTP_PASSWORD"), 'cron_interval' => getenv("CRON_INTERVAL") ?: 5, 'siri' => getenv("INSTALL_SECRET"), - 'config' => getenv("INSTALL_CONFIG") ?: INSTALL_CONFIG, + 'host' => getenv("HOST"), + 'root_path' => getenv("ROOT_PATH"), + 'config' => getenv("INSTALL_CONFIG") ?: INSTALL_CONFIG, ); // Helper functions @@ -72,7 +74,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 +195,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"); } @@ -219,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/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 new file mode 100644 index 0000000..17a0111 --- /dev/null +++ b/conf/default.conf @@ -0,0 +1,78 @@ +# 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; + + # %APPEND_REDIRECT_HERE% + + 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; + } +} diff --git a/docker-compose.yml b/docker-compose.yml index 521c7f8..e1b90d9 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -16,6 +16,8 @@ services: - LANGUAGE=fa + - HOST=localhost:80 + - ROOT_PATH=/ links: - mysql:mysql ports: