23 lines
696 B
PHP
23 lines
696 B
PHP
<?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();
|
|
}
|
|
}
|