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/"));