From 0cea51e5a3aedd9faefc6029d6d0b28fe86c3db1 Mon Sep 17 00:00:00 2001 From: throwaway Date: Mon, 8 Jan 2024 23:14:27 -0800 Subject: [PATCH 1/2] generate 4get config from env variables --- Dockerfile | 4 +- apache/conf.d/ssl.conf | 19 ++++++++++ docker-compose.yaml | 6 ++- docker/docker-entrypoint.sh | 4 ++ docker/gen_config.php | 74 +++++++++++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 4 deletions(-) create mode 100644 apache/conf.d/ssl.conf create mode 100644 docker/gen_config.php diff --git a/Dockerfile b/Dockerfile index bff4532..fbea318 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,14 +2,14 @@ FROM alpine:latest WORKDIR /var/www/html/4get RUN apk update && apk upgrade -RUN apk add apache2-ssl php82-fileinfo php82-openssl php82-iconv php82-common php82-dom php82-curl curl php82-pecl-apcu php82-apache2 imagemagick php82-pecl-imagick +RUN apk add php apache2-ssl php82-fileinfo php82-openssl php82-iconv php82-common php82-dom php82-curl curl php82-pecl-apcu php82-apache2 imagemagick php82-pecl-imagick php-mbstring COPY ./apache/httpd.conf /etc/apache2/httpd.conf +COPY ./apache/conf.d/ssl.conf /etc/apache2/conf.d/ssl.conf COPY . . RUN chmod 777 /var/www/html/4get/icons -VOLUME ["/etc/4get/certs"] EXPOSE 80 EXPOSE 443 diff --git a/apache/conf.d/ssl.conf b/apache/conf.d/ssl.conf new file mode 100644 index 0000000..7b0dd15 --- /dev/null +++ b/apache/conf.d/ssl.conf @@ -0,0 +1,19 @@ +LoadModule ssl_module modules/mod_ssl.so +LoadModule socache_shmcb_module modules/mod_socache_shmcb.so + +SSLRandomSeed startup file:/dev/urandom 512 +SSLRandomSeed connect builtin + +Listen 443 + +SSLCipherSuite HIGH:MEDIUM:!MD5:!RC4:!3DES:!ADH +SSLProxyCipherSuite HIGH:MEDIUM:!MD5:!RC4:!3DES:!ADH +SSLHonorCipherOrder on + +SSLProtocol all -SSLv3 +SSLProxyProtocol all -SSLv3 + +SSLPassPhraseDialog builtin + +SSLSessionCache "shmcb:/var/cache/mod_ssl/scache(512000)" +SSLSessionCacheTimeout 300 diff --git a/docker-compose.yaml b/docker-compose.yaml index a5eaf35..d3ffe62 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,3 +1,4 @@ +# example docker-compose.yaml version: "3.7" services: @@ -5,8 +6,8 @@ services: image: luuul/4get:latest restart: always environment: - - FOURGET_SERVER_NAME=beak.chat - - FOURGET_SERVER_ADMIN_EMAIL="you@example.com" + - FOURGET_VERSION=6 + - FOURGET_SERVER_NAME=4get.ca ports: - "80:80" @@ -15,3 +16,4 @@ services: volumes: - /etc/letsencrypt/live/domain.tld:/etc/4get/certs - ./banners:/var/www/html/4get/banner + - ./captcha:/var/www/html/4get/data/captcha diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 89bd7cf..bbb8229 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -14,6 +14,10 @@ if [ ! -f /etc/4get/certs/cert.pem ] || [ ! -f /etc/4get/certs/chain.pem ] || [ mv /etc/apache2/httpd.conf_temp /etc/apache2/httpd.conf fi + +php82 ./docker/gen_config.php + + echo "4get is running" exec httpd -DFOREGROUND diff --git a/docker/gen_config.php b/docker/gen_config.php new file mode 100644 index 0000000..71fd721 --- /dev/null +++ b/docker/gen_config.php @@ -0,0 +1,74 @@ + getConstants()); + +$env = getenv(); +$fourget_env = array_filter($env, function($v, $k) { + return str_starts_with($k, "FOURGET"); +}, ARRAY_FILTER_USE_BOTH); + + +foreach($fourget_env as $key => $val) { + $target_key = preg_replace('/^FOURGET_/', '', $key); + $config[$target_key] = $val; +}; + +function type_to_string($n) { + $type = gettype($n); + if ($type === "NULL") { + return "null"; + } + if ($type === "boolean") { + return $n ? 'true' : 'false'; + } + if ($type === "string") { + return "\"$n\""; + } + if ($type === "array") { + return json_encode($n); + } + return $n; +} + + +function detect_captcha_dirs() { + $captcha_dir = "/var/www/html/4get/data/captcha/"; + $categories = (array_map(function ($n) { + return explode("/", $n)[7]; + }, glob($captcha_dir . "*"))); + + + $result = array_map(function($category) { + return [$category, count(glob("/var/www/html/4get/data/captcha/" . $category . "/*" ))]; + }, $categories); + + return $result; +} + + +$special_keys = ["CAPTCHA_DATASET"]; + +$output = " $val){ + if(!in_array($key, $special_keys)) { +$output = $output . "\tconst " . $key . " = " . type_to_string($val) . ";\n"; +continue; + } + + +if($key === "CAPTCHA_DATASET") { + $output = $output . "\tconst " . $key . " = " . type_to_string(detect_captcha_dirs()) . ";\n"; + } + +} + +$output = $output . "}\n"; +$output = $output . "?>"; + +file_put_contents("./data/config.php", $output); +?> From 3fad201c3bb36a3f3738e38df644e165a3ca1102 Mon Sep 17 00:00:00 2001 From: throwaway Date: Mon, 8 Jan 2024 23:25:41 -0800 Subject: [PATCH 2/2] update docker instructions --- README.md | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 7930cba..42c5d22 100644 --- a/README.md +++ b/README.md @@ -163,13 +163,21 @@ docker run -d -p 443:443 -e FOURGET_SERVER_NAME="4get.ca" -e FOURGET_SERVER_ADMI replace enviroment variables FOURGET_SERVER_NAME and FOURGET_SERVER_ADMIN_EMAIL with relevant values if the certificate files are not mounted to /etc/4get/certs the service listens to port 80 + the certificate directory expects files named `cert.pem`, `chain.pem`, `privkey.pem` + ## Install using Docker Compose + copy `docker-compose.yaml` -create a directory with images named `banners` for example and mount to `/var/www/html/4get/banner` -to serve custom banners +to serve custom banners create a directory named `banners` for example with images and mount to `/var/www/html/4get/banner` + +to serve captcha images create a directory named `captchas` for example containing subfolders with images and mount to `/var/www/html/4get/data/captcha` + +any environment variables prefixed with `FOURGET_` will be added to the generated config +the entrypoint will automatically set the `CAPTCHA_DATASET` value for you based on directory names and number of files in each + ``` version: "3.7" @@ -189,9 +197,10 @@ services: volumes: - /etc/letsencrypt/live/domain.tld:/etc/4get/certs - ./banners:/var/www/html/4get/banner + - ./captchas:/var/www/html/4get/data/captcha ``` -Replace relevant values and start with `docker-compose up -d` +Replace relevant values and start with `docker compose up -d` ## Install on Caddy