Initial commit
This commit is contained in:
22
www/.php/auth.inc
Normal file
22
www/.php/auth.inc
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
require "credentials.inc";
|
||||
|
||||
function http_401_unauthorized(): 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");
|
||||
}
|
||||
|
||||
function authenticate(string $client): void {
|
||||
global $CREDENTIALS;
|
||||
$credentials = $CREDENTIALS[$client];
|
||||
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']])
|
||||
{
|
||||
http_401_unauthorized();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user