files: Add statistics page
This commit is contained in:
@@ -1,21 +1,44 @@
|
||||
<?php
|
||||
require "credentials.inc";
|
||||
|
||||
function http_401_unauthorized(): void {
|
||||
function http_401_unauthorized(?string $mode = null): void {
|
||||
header('Status: 401');
|
||||
header('WWW-Authenticate: Basic realm="Elwig"');
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
header('Content-Length: 17');
|
||||
exit("401 Unauthorized\n");
|
||||
if ($mode === 'text' || $mode === 'ascii') {
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
header('Content-Length: 17');
|
||||
echo "401 Unauthorized\n";
|
||||
} else {
|
||||
header('Content-Length: 0');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
function authenticate(): void {
|
||||
function http_403_forbidden(?string $mode = null): void {
|
||||
header('Status: 403');
|
||||
header('WWW-Authenticate: Basic realm="Elwig"');
|
||||
if ($mode === 'text' || $mode === 'ascii') {
|
||||
header('Content-Type: text/plain; charset=UTF-8');
|
||||
header('Content-Length: 14');
|
||||
echo "403 Forbidden\n";
|
||||
} else {
|
||||
header('Content-Length: 0');
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
function authenticate(array $scope, ?string $mode = null): void {
|
||||
global $CREDENTIALS;
|
||||
if (!array_key_exists('PHP_AUTH_USER', $_SERVER) ||
|
||||
!array_key_exists('PHP_AUTH_PW', $_SERVER) ||
|
||||
!array_key_exists($_SERVER['PHP_AUTH_USER'], $CREDENTIALS) ||
|
||||
$_SERVER['PHP_AUTH_PW'] !== $CREDENTIALS[$_SERVER['PHP_AUTH_USER']])
|
||||
!array_key_exists($_SERVER['PHP_AUTH_USER'], $CREDENTIALS))
|
||||
{
|
||||
http_401_unauthorized();
|
||||
http_401_unauthorized($mode);
|
||||
}
|
||||
$cred = $CREDENTIALS[$_SERVER['PHP_AUTH_USER']];
|
||||
if ($_SERVER['PHP_AUTH_PW'] !== $cred[1]) {
|
||||
http_401_unauthorized($mode);
|
||||
} else if (!in_array($cred[0], $scope)) {
|
||||
http_403_forbidden($mode);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,5 +5,5 @@ global $CREDENTIALS;
|
||||
$GITEA_TOKEN = 'token';
|
||||
|
||||
$CREDENTIALS = [
|
||||
'username' => 'password',
|
||||
'username' => ['scope', 'password'],
|
||||
];
|
||||
|
||||
7
www/.php/devices.sample.inc
Normal file
7
www/.php/devices.sample.inc
Normal file
@@ -0,0 +1,7 @@
|
||||
<?php
|
||||
global $DEVICES;
|
||||
$DEVICES = [
|
||||
'TOKEN' => [
|
||||
'DESKTOP-0123456' => 'Office PC',
|
||||
],
|
||||
];
|
||||
Reference in New Issue
Block a user