From 893b4a41598da1e012197c05ee56104c8815c409 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Wed, 8 Sep 2021 11:34:13 +0000 Subject: [PATCH] enhancing codepot/config/config.php to sense X-Fowarded-Host --- codepot/docker/Dockerfile.rocky84 | 5 +- codepot/docker/Dockerfile.ubnt2004 | 2 + codepot/docker/build-rocky84.sh | 1 - codepot/docker/build-ubnt2004.sh | 1 - codepot/docker/httpd-fg.sh | 52 ++++++++++++++++++- codepot/src/codepot/config/config.php | 5 ++ .../src/codepot/models/subversionmodel.php | 21 +------- 7 files changed, 64 insertions(+), 23 deletions(-) diff --git a/codepot/docker/Dockerfile.rocky84 b/codepot/docker/Dockerfile.rocky84 index d38a264d..d9701ddf 100644 --- a/codepot/docker/Dockerfile.rocky84 +++ b/codepot/docker/Dockerfile.rocky84 @@ -16,4 +16,7 @@ RUN dnf install -y php-devel subversion-devel perl-devel make COPY build-rocky84.sh /tmp RUN /tmp/build-rocky84.sh && rm -rf /tmp/* -CMD ["/usr/sbin/httpd-fg.sh"] +COPY httpd-fg.sh /usr/sbin/ + +##CMD ["/usr/sbin/httpd-fg.sh"] +ENTRYPOINT ["/usr/sbin/httpd-fg.sh"] diff --git a/codepot/docker/Dockerfile.ubnt2004 b/codepot/docker/Dockerfile.ubnt2004 index 6a486f14..69a17724 100644 --- a/codepot/docker/Dockerfile.ubnt2004 +++ b/codepot/docker/Dockerfile.ubnt2004 @@ -12,4 +12,6 @@ RUN apt update && \ COPY build-ubnt2004.sh /tmp RUN /tmp/build-ubnt2004.sh && rm -rf /tmp/* +COPY apache2-fg.sh /usr/sbin/ + CMD ["/usr/sbin/apache2-fg.sh"] diff --git a/codepot/docker/build-rocky84.sh b/codepot/docker/build-rocky84.sh index 1f2d2740..9e1c8d26 100755 --- a/codepot/docker/build-rocky84.sh +++ b/codepot/docker/build-rocky84.sh @@ -15,7 +15,6 @@ cd codepot && \ --with-cachedir=/var/cache/codepot \ --with-phpextdir=`php-config --extension-dir` \ make && make install && \ -install -m 0755 -D -t /usr/sbin docker/httpd-fg.sh && \ cd ../.. && \ rm -rf /var/lib/codepot/* && \ sed -ri -e 's|^database_hostname[[:space:]]*=[[:space:]]*"localhost"$|database_hostname = "/var/lib/codepot/codepot.db"|g' \ diff --git a/codepot/docker/build-ubnt2004.sh b/codepot/docker/build-ubnt2004.sh index 738b143f..062d2d75 100755 --- a/codepot/docker/build-ubnt2004.sh +++ b/codepot/docker/build-ubnt2004.sh @@ -14,7 +14,6 @@ cd codepot && \ --with-phpextdir=`php-config --extension-dir` \ --with-phpextinidir=`php-config --ini-dir | sed 's|/cli/|/apache2/|g'` && \ make && make install && \ -install -m 0755 -D -t /usr/sbin docker/apache2-fg.sh && \ cd ../.. && \ rm -rf /var/lib/codepot/* && \ sed -ri -e 's|^database_hostname[[:space:]]*=[[:space:]]*"localhost"$|database_hostname = "/var/lib/codepot/codepot.db"|g' \ diff --git a/codepot/docker/httpd-fg.sh b/codepot/docker/httpd-fg.sh index 2b1cd464..3c20ed57 100755 --- a/codepot/docker/httpd-fg.sh +++ b/codepot/docker/httpd-fg.sh @@ -1,6 +1,52 @@ #!/bin/bash set -e +SERVICE_PORT="" +while getopts ":hp:-:" oc +do + case "${oc}" in + -) + case "${OPTARG}" in + port) + opt=${OPTARG} + SERVICE_PORT="${!OPTIND}" + OPTIND=$(($OPTIND + 1)) + ;; + port=*) + SERVICE_PORT=${OPTARG#*=} + opt=${OPTARG%=$val} + ;; + + *) + echo "Warning: unknown option - $OPTARG" + ;; + esac + ;; + + h) + echo "-----------------------------------------------------------" + echo "This container runs a http service on port 80." + echo "Use an external reverse proxy to enable https as it doesn't" + echo "enable the HTTP service." + echo "Extra options allowed when running the container: " + echo " -h print this help message" + echo " -p number specify the port number" + echo " -port number specify the port number" + echo "-----------------------------------------------------------" + ;; + p) + SERVICE_PORT=${OPTARG#*=} + opt=${OPTARG%=$val} + ;; + + *) + echo "Warning: unknown option - $OPTARG" + ;; + esac +done +echo "${SERVICE_PORT}" | grep -q -E '^[[:digit:]]+$' || SERVICE_PORT="80" + + # Note: we don't just use "apache2ctl" here because it itself is just a shell-script wrapper around apache2 which provides extra functionality like "apache2ctl start" for launching apache2 in the background. # (also, when run as "apache2ctl ", it does not use "exec", which leaves an undesirable resident shell process) @@ -54,5 +100,9 @@ grep -F -q 'env[CODEPOT_CONFIG_FILE]' /etc/php-fpm.d/www.conf || { echo 'env[CODEPOT_CONFIG_FILE] = /var/lib/codepot/codepot.ini' >> /etc/php-fpm.d/www.conf } +## change the port number as specified on the command line +echo "Configuring to listen on the port [$SERVICE_PORT]" +sed -r -i "s|^Listen[[:space:]]+.*|Listen ${SERVICE_PORT}|g" /etc/httpd/conf/httpd.conf + php-fpm -exec httpd -DFOREGROUND "$@" +exec httpd -DFOREGROUND diff --git a/codepot/src/codepot/config/config.php b/codepot/src/codepot/config/config.php index aed613f8..e7c2c103 100644 --- a/codepot/src/codepot/config/config.php +++ b/codepot/src/codepot/config/config.php @@ -38,6 +38,11 @@ else $_SERVER['REQUEST_PROTOCOL'] = 'http'; } +if (array_key_exists('HTTP_X_FORWARDED_HOST', $_SERVER) && $_SERVER['HTTP_X_FORWARDED_HOST'] != '') +{ + $_SERVER['HTTP_HOST'] = $_SERVER['HTTP_X_FORWARDED_HOST']; +} + $config['base_url'] .= "://{$_SERVER['HTTP_HOST']}"; $config['base_url'] .= preg_replace('@/+$@','',dirname($_SERVER['SCRIPT_NAME'])).'/'; diff --git a/codepot/src/codepot/models/subversionmodel.php b/codepot/src/codepot/models/subversionmodel.php index 7ffa6a85..3d2554f1 100644 --- a/codepot/src/codepot/models/subversionmodel.php +++ b/codepot/src/codepot/models/subversionmodel.php @@ -2217,25 +2217,8 @@ class SubversionModel extends CodeRepoModel foreach ($hooks as $hook) { - // copy hook scripts to the top repository directory - // overwriting existing scripts are ok as they are - // just updated to the latest scripts anyway. - $contents = @file_get_contents("{$cfgdir}/${hook}"); - if ($contents === FALSE) - { - self::_deleteDirectory ($projdir); - return FALSE; - } - - if (@file_put_contents("{$repodir}/${hook}", str_replace('%API%', $api, $contents)) === FALSE) - { - self::_deleteDirectory ($projdir); - return FALSE; - } - - // install the hook script to the new project repository - if (@chmod("{$repodir}/{$hook}", 0755) === FALSE || - @symlink("../../{$hook}", "{$repodir}/{$projectid}/hooks/${hook}") === FALSE) + // install the hook script to the new project repository using symbolic links + if (@symlink("${cfgdir}/${hook}", "{$repodir}/{$projectid}/hooks/${hook}") === FALSE) { self::_deleteDirectory ($projdir); return FALSE;