2024-01-09 02:14:27 -05:00
|
|
|
<?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);
|
2024-01-17 05:07:21 -05:00
|
|
|
$config[$target_key] = trim($val, '\'"');
|
2024-01-09 02:14:27 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
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") {
|
2024-02-17 16:33:06 -05:00
|
|
|
return json_encode($n, JSON_UNESCAPED_SLASHES);
|
2024-01-09 02:14:27 -05:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
?>
|