Update from xhtml to html and add /files/stat

This commit is contained in:
2025-09-17 16:03:45 +02:00
parent cc3c0cab45
commit 2007c21fe4
4 changed files with 63 additions and 40 deletions

View File

@@ -3,7 +3,7 @@ require "../.php/auth.inc";
require "../.php/credentials.inc";
global $GITEA_TOKEN;
if ($_SERVER['PHP_AUTH_USER'] !== 'elwig' || $_SERVER['PHP_AUTH_PW'] !== 'ganzGeheim123!') {
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] !== 'elwig' || $_SERVER['PHP_AUTH_PW'] !== 'ganzGeheim123!') {
http_401_unauthorized();
}

View File

@@ -2,6 +2,8 @@
require "../.php/format.inc";
require "../.php/auth.inc";
$ua = $_SERVER['HTTP_USER_AGENT'] ?? null;;
if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
authenticate();
@@ -49,6 +51,23 @@ 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!') {
http_401_unauthorized();
}
header("Content-Type: text/html; charset=UTF-8");
echo "<!DOCTYPE html><html lang='en'><head><style>table{border-collapse:collapse;}th,td{border:1px solid black;}</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;
@@ -56,7 +75,7 @@ $getVers = null;
$info = explode('/', $_SERVER['PATH_INFO']);
if (sizeof($info) > 1 && ($info[1] === 'elwig' || $info[1] === 'winziprint')) {
$getProd = $info[1];
$getVers = $info[2];
if (sizeof($info) > 2) $getVers = $info[2];
if (sizeof($info) > 3) {
header('Status: 404');
header('Content-Length: 0');
@@ -78,13 +97,18 @@ foreach ($filesRaw as $file) {
$entities = [];
foreach ($files as $name => [$size, $mtime, $ctime]) {
$p1 = strrpos($name, '-') + 1;
$p1 = strrpos($name, '-');
$p2 = strrpos($name, '.');
$vers = substr($name, $p1, $p2 - $p1);
$url = "https://elwig.at/files/$name";
if ($p1 === false || $p2 === false) {
$vers = null;
$prod = null;
} else {
$vers = substr($name, $p1 + 1, $p2 - $p1 - 1);
$prod = strtolower(substr($name, 0, $p1));
}
$mod = date(DATE_ATOM, $mtime);
$cre = date(DATE_ATOM, $ctime);
$prod = strtolower(substr($name, 0, $p1 - 1));
$entities[$name] = [
$prod,
$vers,
@@ -113,6 +137,8 @@ $entities = array_filter($entities, function($e) {
});
$format = get_fmt();
file_put_contents('.log.csv', time() . "|$_SERVER[REMOTE_ADDR]|$_SERVER[REQUEST_METHOD]|$_SERVER[REQUEST_URI]|$format|$ua\n", FILE_APPEND);
if ($format === 'json') {
header('Content-Type: application/json; charset=UTF-8');
echo "{\"data\": [\n";
@@ -135,10 +161,9 @@ if ($format === 'json') {
header('Content-Length: 0');
exit();
}
header('Content-Type: application/xhtml+xml; charset=UTF-8');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
header('Content-Type: text/html; charset=UTF-8');
?>
<html xmlns="http://www.w3.org/1999/xhtml" lang="de" prefix="og: https://ogp.me/ns#">
<html lang="de" prefix="og: https://ogp.me/ns#">
<head>
<meta charset="UTF-8"/>
<title>Downloads - Elwig</title>