0) continue; if (!$first) $files .= ", "; $files .= "\"$name\": {\"compressed_size\": $compSize, \"uncompressed_size\": $uncompSize, \"crc32\": \"$hex\"}"; $first = false; } $files .= "}"; fclose($fp); return $files; } $path = $_SERVER['PATH_INFO']; if ($path == '') { if ($_SERVER['REQUEST_METHOD'] !== 'GET') { header('Status: 405'); header('Allow: GET'); if ($format === 'text') { header('Content-Type: text/plain; charset=UTF-8'); header('Content-Length: 23'); echo "405 Method Not Allowed\n"; } else if ($format === 'json') { header('Content-Type: application/json; charset=UTF-8'); header('Content-Length: 48'); echo "{\"errors\": [{\"message\": \"Method not allowed\"}]}\n"; } else { header('Content-Type: text/html; charset=UTF-8'); header('Content-Length: 0'); } exit(); } if ($format === 'text') { header('Content-Type: text/plain; charset=UTF-8'); foreach ($clients as $c) { $size = intval(exec("du -s .data/$c")); echo "$c ($size kB)\n"; } } else if ($format === 'json') { header('Content-Type: application/json; charset=UTF-8'); echo "{\"data\": ["; $first = true; foreach ($clients as $c) { if (!$first) echo ","; $size = intval(exec("du -s .data/$c")) * 1024; echo "\n {\"name\": \"$c\", \"disk_usage\": $size}"; $first = false; } echo "\n]}\n"; } else if ($format === 'html') { header('Content-Type: application/xhtml+xml; charset=UTF-8'); echo "\n"; ?> Mandanten - Elwig

Mandanten

Homepage

\n"; } ?>
NameUsage
$c$size kB

JSON-Format

format(DateTimeInterface::RFC3339) . '"'; $zwstid = "\"$parts[2]\""; } list($meta, $version) = get_zip_meta($path); if (str_ends_with($file, ".zip")) { $files = get_zip_files($path, $meta !== 'null' ? 2 : 0); } else { $files = "null"; } $version ??= "null"; echo " {\"name\": \"$file\", \"timestamp\": $datetime, \"zwstid\": $zwstid, \"meta\": $meta, \"files\": $files, " . "\"version\": $version, \"url\": \"$url\", \"size\": $size, \"created\": \"$cre\", \"modified\": \"$mod\"}"; $first = false; } echo "\n]}\n"; exit(); } $file = substr($path, strlen("/$c/")); $path = ".data/$c/$file"; if (!preg_match_all('/[A-Za-z0-9_.-]+/', $file) && !($file === '*' && $_SERVER['REQUEST_METHOD'] === 'DELETE')) { header('Status: 400'); header('Content-Length: 16'); exit("400 Bad Request\n"); } else if ($_SERVER['REQUEST_METHOD'] === 'GET' || $_SERVER['REQUEST_METHOD'] === 'HEAD') { $size = filesize($path); if ($size === false) { header('Status: 404'); header('Content-Length: 14'); exit("404 Not Found\n"); } $type = mime_content_type($path); header("Content-Type: $type"); header("Content-Disposition: attachment; filename=\"$file\""); header("Content-Length: $size"); if ($_SERVER['REQUEST_METHOD'] !== 'HEAD') readfile($path); } else if ($_SERVER['REQUEST_METHOD'] === 'PUT') { $upload = fopen("php://input", "r"); $fp = fopen("/tmp/upload-$file", "wb+"); if (!$upload || !$fp) { fclose($fp); fclose($upload); header('Status: 500'); header('Content-Length: 26'); exit("500 Internal Server Error\n"); } while ($data = fread($upload, 4096)) fwrite($fp, $data); fclose($fp); fclose($upload); if (!rename("/tmp/upload-$file", $path)) { header('Status: 500'); header('Content-Length: 26'); exit("500 Internal Server Error\n"); } header("Status: 201"); header('Content-Length: 12'); exit("201 Created\n"); } else if ($_SERVER['REQUEST_METHOD'] === 'DELETE') { if ($file === '*') { foreach (scandir(".data/$c/") as $f) { if (str_starts_with($f, ".") || str_ends_with($f, ".php") || str_ends_with($f, ".inc")) continue; if (unlink(".data/$c/$f") === false) { header("Status: 500"); exit("500 Internal Server Error\n"); } echo "Deleted $f\n"; } } else if (!is_file($path)) { header("Status: 404"); header("Content-Length: 14"); exit("404 Not Found\n"); } else if (unlink($path) === false) { header("Status: 500"); exit("500 Internal Server Error\n"); } exit("200 OK\n"); } else { header("Status: 405"); header("Allow: GET, PUT, DELETE"); header("Content-Length: 23"); exit("405 Method Not Allowed\n"); } exit(); } header("Status: 404"); if ($format === 'text') { header('Content-Type: text/plain; charset=UTF-8'); header('Content-Length: 14'); echo "404 Not Found\n"; } else if ($format === 'json') { header('Content-Type: application/json; charset=UTF-8'); header('Content-Length: 39'); echo "{\"errors\": [{\"message\": \"Not found\"}]}\n"; } else { header('Content-Type: text/html; charset=UTF-8'); header('Content-Length: 0'); } exit();