From cdf958d29333d448f4521f4d2faa2592b58e9b27 Mon Sep 17 00:00:00 2001 From: lolcat Date: Sun, 10 Aug 2025 21:55:15 -0400 Subject: fix wikipedia crash --- docker/gen_config.php | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 docker/gen_config.php (limited to 'docker/gen_config.php') diff --git a/docker/gen_config.php b/docker/gen_config.php new file mode 100644 index 0000000..b9e7730 --- /dev/null +++ b/docker/gen_config.php @@ -0,0 +1,90 @@ + 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); + $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") { + return "null"; + } + if ($type === "boolean") { + return $n ? 'true' : 'false'; + } + if ($type === "string") { + if(is_numeric($n)) { + return $n; + } + return "\"$n\""; + } + if ($type === "array") { + return json_encode($n, JSON_UNESCAPED_SLASHES); + } + 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 = ["PROTO", "CAPTCHA_DATASET"]; + +$output = " $val){ + if(!in_array($key, $special_keys)) { + $stored_value = $val; + // conversion between arrays and comma separated env value. + // Handle case when original type of field is array and there is a type mismatch when a comma separted string is passed, + // then split on comma if string (and not numeric, boolean, null, etc) + // + // except in the case where the inital value in default config is null or boolean. Assuming null and boolean + // in default config will be never be assigned an array + + if(gettype($from_config[$key]) != gettype($val) && !is_numeric($val) && !is_null($from_config[$key]) && gettype($from_config[$key]) != "boolean") { + $stored_value = explode(",", $val); + } + $output = $output . "\tconst " . $key . " = " . type_to_string($stored_value) . ";\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); +?> -- cgit v1.2.3