1
Fork 0
mirror of https://git.lolcat.ca/lolcat/4get.git synced 2024-12-24 23:56:34 -05:00

generate 4get config from env variables

This commit is contained in:
throwaway 2024-01-08 23:14:27 -08:00
parent ed5a992354
commit 0cea51e5a3
5 changed files with 103 additions and 4 deletions

View file

@ -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

19
apache/conf.d/ssl.conf Normal file
View file

@ -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

View file

@ -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

View file

@ -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

74
docker/gen_config.php Normal file
View file

@ -0,0 +1,74 @@
<?php
include "/var/www/html/4get/data/config.php";
$refl = new ReflectionClass('config');
$config = ($refl->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 = "<?php\n // This file was generated by docker/gen_config.php\n";
$output = $output . "class config {\n";
foreach(($config) as $key => $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);
?>