Initial commit
This commit is contained in:
69
www/files/index.php
Normal file
69
www/files/index.php
Normal file
@ -0,0 +1,69 @@
|
||||
<?php
|
||||
require "../format.inc";
|
||||
|
||||
if ($_SERVER['PATH_INFO'] !== '') {
|
||||
header('Status: 404');
|
||||
header('Content-Length: 0');
|
||||
exit();
|
||||
}
|
||||
|
||||
$files = [];
|
||||
foreach (scandir('.') as $file) {
|
||||
if ($file === '.' || $file === '..' || str_ends_with($file, ".php")) continue;
|
||||
$files[$file] = [filesize($file), filemtime($file), filectime($file)];
|
||||
}
|
||||
|
||||
$format = get_fmt();
|
||||
if ($format === 'json') {
|
||||
header('Content-Type: application/json; charset=UTF-8');
|
||||
echo "{\"status\": \"success\", \"data\": [\n";
|
||||
$first = true;
|
||||
foreach ($files as $name => [$size, $mtime, $ctime]) {
|
||||
if (!$first) echo ",\n";
|
||||
$p1 = strrpos($name, '-') + 1;
|
||||
$p2 = strrpos($name, '.');
|
||||
$vers = substr($name, $p1, $p2 - $p1);
|
||||
$url = "https://www.necronda.net/elwig/files/$name";
|
||||
$mod = date(DATE_ATOM, $mtime);
|
||||
$cre = date(DATE_ATOM, $ctime);
|
||||
echo " {\"version\": \"$vers\", \"name\": \"$name\", \"url\": \"$url\", \"size\": $size, \"created\": \"$cre\", \"modified\": \"$mod\"}";
|
||||
$first = false;
|
||||
}
|
||||
echo "\n]}\n";
|
||||
} else if ($format === 'text') {
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
foreach ($files as $name => [$size, $mtime, $ctime]) {
|
||||
echo "$name\t" . number_format($size / 1024 / 1024, 1) . " MB\n";
|
||||
}
|
||||
} else if ($format === 'html') {
|
||||
header('Content-Type: text/html; charset=UTF-8');
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="de">
|
||||
<head>
|
||||
<title>Downloads - Elwig - Elektronische Winzergenossenschaftsverwaltung</title>
|
||||
<meta charset="UTF-8"/>
|
||||
<link rel="icon" sizes="16x16 20x20 24x24 30x30 32x32 36x36 40x40 48x48 60x60 64x64 72x72 80x80 96x96 128x128 256x256" href="../res/elwig.ico"/>
|
||||
<link rel="stylesheet" href="../res/style.css"/>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Downloads</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Größe</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php
|
||||
foreach ($files as $name => [$size, $mtime, $ctime]) {
|
||||
echo " <tr><td><a href='$name'>$name</a></td><td>" . number_format($size / 1024 / 1024, 1) . " MB</td></tr>\n";
|
||||
}
|
||||
?>
|
||||
</tbody>
|
||||
</table>
|
||||
<p><a href="?format=json">JSON-Format</a></p>
|
||||
</body>
|
||||
</html>
|
||||
<?php }
|
Reference in New Issue
Block a user