123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- <?php
- include "/var/www/html/4get/data/config.php";
- $refl = new ReflectionClass('config');
- $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);
- $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 = "<?php\n // This file was generated by docker/gen_config.php\n";
- $output = $output . "class config {\n";
- foreach(($merged_config) as $key => $val){
- if(!in_array($key, $special_keys)) {
- $stored_value = $val;
-
-
-
-
-
-
-
- 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);
- ?>
|