initial import

This commit is contained in:
www-data
2026-05-25 13:47:46 +02:00
parent 3e7f238cf4
commit 97f23260ed
32 changed files with 8898 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
<?php
/*
* Shared configuration for maximum base64 payload sizes.
*/
define('BASE64_CHUNK_CONFIG_FILE', __DIR__ . '/config/base64-chunks.php');
function base64_chunk_defaults()
{
return array(
'racket_zip_max_base64_kb' => 8192,
'package_zip_max_base64_kb' => 2048,
);
}
function load_base64_chunk_config()
{
$defaults = base64_chunk_defaults();
$config = is_file(BASE64_CHUNK_CONFIG_FILE)
? require BASE64_CHUNK_CONFIG_FILE
: array();
if (!is_array($config)) {
$config = array();
}
foreach ($defaults as $key => $default) {
$value = (int)($config[$key] ?? $default);
$config[$key] = $value > 0 ? $value : $default;
}
return array_intersect_key($config, $defaults);
}
function save_base64_chunk_config($config)
{
$defaults = base64_chunk_defaults();
$clean = array();
foreach ($defaults as $key => $default) {
$value = (int)($config[$key] ?? $default);
if ($value < 1) {
throw new InvalidArgumentException('Base64 chunk size must be at least 1 KiB.');
}
$clean[$key] = $value;
}
$php = "<?php\n" .
"/*\n" .
" * Maximale grootte van base64-payloads, in KiB.\n" .
" *\n" .
" * 1 KiB = 1024 bytes. De splitter rondt intern waar nodig naar beneden af\n" .
" * zodat de binaire chunks netjes naar base64 omgezet kunnen worden.\n" .
" */\n\n" .
"return " . var_export($clean, true) . ";\n";
$tmp = BASE64_CHUNK_CONFIG_FILE . '.tmp';
if (file_put_contents($tmp, $php, LOCK_EX) === false) {
throw new RuntimeException('Could not write temporary base64 chunk config.');
}
if (!rename($tmp, BASE64_CHUNK_CONFIG_FILE)) {
@unlink($tmp);
throw new RuntimeException('Could not replace base64 chunk config.');
}
}