files: Add statistics page
This commit is contained in:
@@ -5,7 +5,7 @@ require "../.php/auth.inc";
|
||||
$ua = $_SERVER['HTTP_USER_AGENT'] ?? null;;
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
|
||||
authenticate();
|
||||
authenticate(['PUT'], 'text');
|
||||
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
|
||||
@@ -51,26 +51,6 @@ if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
|
||||
exit("405 Method Not Allowed\n");
|
||||
}
|
||||
|
||||
if ($_SERVER['PATH_INFO'] === '/stat') {
|
||||
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] !== 'elwig' || $_SERVER['PHP_AUTH_PW'] !== 'ganzGeheim123!') {
|
||||
header('Status: 401');
|
||||
header('WWW-Authenticate: Basic realm="Elwig"');
|
||||
header('Content-Length: 0');
|
||||
exit;
|
||||
}
|
||||
|
||||
header("Content-Type: text/html; charset=UTF-8");
|
||||
echo "<!DOCTYPE html><html lang='en'><head><title>Activity Statistics - Elwig</title><style>table{border-collapse:collapse;}th,td{border:1px solid black;padding:0.25em 0.5em;}</style></head><body><table>\n";
|
||||
echo "<tr><th>Timestamp</th><th>IP Address</th><th>Method</th><th>URI</th><th>Format</th><th>User Agent</th></tr>\n";
|
||||
passthru(<<<EOF
|
||||
cat .log.csv \
|
||||
| awk -F'|' -vOFS='|' '{\$1 = strftime("%F %T", $1); print $0}' \
|
||||
| sed 's:|:</td><td>:g;s:^:<tr><td>:g;s:$:</td></tr>:g'
|
||||
EOF);
|
||||
echo "</table></body></html>\n";
|
||||
exit;
|
||||
}
|
||||
|
||||
global $getProd;
|
||||
global $getVers;
|
||||
$getProd = null;
|
||||
@@ -94,7 +74,7 @@ $filesRaw = scandir('.');
|
||||
usort($filesRaw, 'version_compare');
|
||||
$files = [];
|
||||
foreach ($filesRaw as $file) {
|
||||
if (str_starts_with($file, ".") || str_ends_with($file, ".php")) continue;
|
||||
if (str_starts_with($file, ".") || str_ends_with($file, ".php") || !str_contains($file, ".")) continue;
|
||||
$files[$file] = [filesize($file), filemtime($file), filectime($file)];
|
||||
}
|
||||
|
||||
@@ -157,7 +137,7 @@ if ($format === 'json') {
|
||||
foreach ($entities as $name => [$prod, $vers, $url, $size, $mtime, $ctime, $mod, $cre]) {
|
||||
echo "$name\t" . number_format($size / 1024 / 1024, 1) . " MB\n";
|
||||
}
|
||||
} else if ($format === 'html') {
|
||||
} else {
|
||||
if (isset($getProd) && isset($getVers) && sizeof($entities) === 1) {
|
||||
header('Status: 303');
|
||||
header('Location: ' . $entities[array_key_first($entities)][2]);
|
||||
|
||||
Reference in New Issue
Block a user