summaryrefslogtreecommitdiff
path: root/docker
diff options
context:
space:
mode:
authorlolcat <will@lolcat.ca>2024-04-19 22:23:33 +0000
committerlolcat <will@lolcat.ca>2024-04-19 22:23:33 +0000
commit9e18327df69542e07fad2ef471a3ebdbe9b08ae8 (patch)
treeb970a16d73e4a0f90a0e30228270c9d798fe79fd /docker
parent55a093925fbcca4bbee38f1185a6ccb1584fd4c3 (diff)
parente31b9494af16bf833d14b6256ca055fa94b6f77b (diff)
Merge pull request 'Docker update documentation, php, and modify gen_config.php' (#8) from docker_update_php into master
Reviewed-on: https://git.lolcat.ca/lolcat/4get/pulls/8
Diffstat (limited to 'docker')
-rwxr-xr-xdocker/docker-entrypoint.sh19
-rw-r--r--docker/gen_config.php31
2 files changed, 33 insertions, 17 deletions
diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh
index 0a41ddd..bdb706a 100755
--- a/docker/docker-entrypoint.sh
+++ b/docker/docker-entrypoint.sh
@@ -1,14 +1,23 @@
#!/bin/sh
set -e
-if [ ! -f /etc/4get/certs/fullchain.pem ] || [ ! -f /etc/4get/certs/privkey.pem ]; then
- echo "Using http configuration"
- cp /etc/apache2/http.conf /etc/apache2/httpd.conf
-else
+
+# remove quotes from variable if present
+FOURGET_PROTO="${FOURGET_PROTO%\"}"
+FOURGET_PROTO="${FOURGET_PROTO#\"}"
+
+# make lowercase
+FOURGET_PROTO=`echo $FOURGET_PROTO | awk '{print tolower($0)}'`
+
+
+if [ "$FOURGET_PROTO" = "https" ] || [ -f /etc/4get/certs/fullchain.pem ] || [ -f /etc/4get/certs/privkey.pem ]; then
echo "Using https configuration"
cp /etc/apache2/https.conf /etc/apache2/httpd.conf
+else
+ echo "Using http configuration"
+ cp /etc/apache2/http.conf /etc/apache2/httpd.conf
fi
-php82 ./docker/gen_config.php
+php ./docker/gen_config.php
echo "4get is running"
diff --git a/docker/gen_config.php b/docker/gen_config.php
index cb12e3a..cc43916 100644
--- a/docker/gen_config.php
+++ b/docker/gen_config.php
@@ -3,19 +3,21 @@
include "/var/www/html/4get/data/config.php";
$refl = new ReflectionClass('config');
-$config = ($refl->getConstants());
+$from_config = ($refl->getConstants());
+$from_env = array();
$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] = trim($val, '\'"');
+ $from_env[$target_key] = trim($val, '\'"');
};
+$merged_config = array_merge($from_config, $from_env);
+
function type_to_string($n) {
$type = gettype($n);
if ($type === "NULL") {
@@ -52,26 +54,31 @@ function detect_captcha_dirs() {
}
-$special_keys = ["CAPTCHA_DATASET", "INSTANCES"];
+$special_keys = ["PROTO", "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){
+foreach(($merged_config) as $key => $val){
if(!in_array($key, $special_keys)) {
-$output = $output . "\tconst " . $key . " = " . type_to_string($val) . ";\n";
-continue;
+
+ // conversion between arrays and comma separated env value.
+ // If original type of field is array and there is a type mismatch such as when a comma separted string is passed,
+ // then split on comma if string and not numeric
+ if(gettype($from_config[$key]) != gettype($val) && !is_numeric($val)) {
+ $data = gettype($val) === "string" ? explode(",", $val) : $val;
+ $output = $output . "\tconst " . $key . " = " . type_to_string($data) . ";\n";
+ } else {
+ $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";
}
- if($key === "INSTANCES") {
- $instances_list = gettype($val) === "string" ? explode(",", $val) : $val;
- $output = $output . "\tconst " . $key . " = " . type_to_string($instances_list) . ";\n";
- }
-
}
$output = $output . "}\n";