Add header.inc and footer.inc

This commit is contained in:
2023-11-25 21:43:15 +01:00
parent 797205e7c5
commit 5ec627f0a6
5 changed files with 40 additions and 51 deletions

View File

@ -1,22 +1,11 @@
<?php
require "format.inc";
include "credentials.inc";
$TITLE = 'Mandanten';
$CREDENTIALS ??= [];
$clients = array_keys($CREDENTIALS);
$format = get_fmt();
$cred_file_name = 'credentials.txt';
$clients = [];
$names = [];
$passwords = [];
foreach (scandir('.clients/') as $file) {
if ($file === '.' || $file === '..') continue;
array_push($clients, $file);
$content = file_get_contents(".clients/$file/$cred_file_name");
if ($content) {
$creds = explode(":", explode("\n", $content)[0]);
$names[$file] = $creds[0];
$passwords[$file] = $creds[1];
}
}
$path = $_SERVER['PATH_INFO'];
if ($path == '') {
@ -36,7 +25,7 @@ if ($path == '') {
exit();
}
if ($format === 'text' || $format === 'html') {
if ($format === 'text') {
header('Content-Type: text/plain; charset=UTF-8');
foreach ($clients as $c)
echo "$c\n";
@ -52,7 +41,18 @@ if ($path == '') {
echo "\n]}\n";
} else if ($format === 'html') {
header('Content-Type: text/html; charset=UTF-8');
// TODO
require "header.inc"; ?>
<h1>Mandanten</h1>
<table>
<thead><tr><th>Name</th></tr></thead>
<tbody>
<?php foreach ($clients as $c) {
echo " <tr><td><a href='clients/$c'>$c</a></td></tr>\n";
} ?>
</tbody>
</table>
<p><a href="clients?format=json">JSON-Format</a></p>
<?php require "footer.inc";
}
exit();
}
@ -63,7 +63,9 @@ foreach ($clients as $c) {
header('Content-Type: text/plain; charset=UTF-8');
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_USER'] !== $names[$c] || $_SERVER['PHP_AUTH_PW'] !== $passwords[$c]) {
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
!array_key_exists($_SERVER['PHP_AUTH_USER'], $CREDENTIALS[$c]) || $_SERVER['PHP_AUTH_PW'] !== $CREDENTIALS[$c][$_SERVER['PHP_AUTH_USER']])
{
header('Status: 401');
header('WWW-Authenticate: Basic realm="Elwig"');
exit("401 Unauthorized :(\n");
@ -77,7 +79,7 @@ foreach ($clients as $c) {
header("Allow: GET");
exit("405 Method Not Allowed :(\n");
}
system("ls -Al .clients/$c/");
system("ls -Al .data/clients/$c/");
exit();
}
$file = substr($path, strlen("/$c/"));

View File

@ -1,5 +1,6 @@
<?php
require "../format.inc";
$TITLE = 'Downloads';
if ($_SERVER['PATH_INFO'] !== '') {
header('Status: 404');
@ -37,33 +38,15 @@ if ($format === 'json') {
}
} 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>
require "../header.inc"; ?>
<h1>Downloads</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Größe</th>
</tr>
</thead>
<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";
}
?>
<?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 }
<p><a href="files?format=json">JSON-Format</a></p>
<?php require "../footer.inc"; }

2
www/footer.inc Normal file
View File

@ -0,0 +1,2 @@
</body>
</html>

View File

@ -1,15 +1,10 @@
<!DOCTYPE html>
<html lang="de">
<head>
<title>Elwig - Elektronische Winzergenossenschaftsverwaltung</title>
<base href="/elwig/"/>
<title><?php if (!empty($TITLE)) echo "$TITLE - "; ?>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>Elwig</h1>
<h2>Elektronische Winzergenossenschaftsverwaltung</h2>
<a href="https://git.necronda.net/winzer">Source</a>
<a href="files/">Downloads</a>
</body>
</html>

7
www/index.php Normal file
View File

@ -0,0 +1,7 @@
<?php require "header.inc"; ?>
<h1>Elwig</h1>
<h2>Elektronische Winzergenossenschaftsverwaltung</h2>
<a href="https://git.necronda.net/winzer">Source</a><br/>
<a href="files/">Downloads</a><br/>
<a href="clients">Mandanten</a>
<?php require "footer.inc"; ?>