files: Fix authentication on upload
This commit is contained in:
@ -1,27 +1,33 @@
|
||||
<?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: 20');
|
||||
exit("401 Unauthorized :(\n");
|
||||
}
|
||||
|
||||
function authenticate(): void {
|
||||
global $CREDENTIALS;
|
||||
if (!isset($_SEVER['PHP_AUTH_USER']) || !isset($_SEVER['PHP_AUTH_PW']) ||
|
||||
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']])
|
||||
{
|
||||
header('Status: 401');
|
||||
header('WWW-Authenticate: Basic realm="Elwig"');
|
||||
exit("401 Unauthorized :(\n");
|
||||
http_401_unauthorized();
|
||||
}
|
||||
}
|
||||
|
||||
function authenticate_client(string $client): void {
|
||||
global $CLIENT_CREDENTIALS;
|
||||
$credentials = $CLIENT_CREDENTIALS[$client];
|
||||
if (!isset($_SERVER['PHP_AUTH_USER']) || !isset($_SERVER['PHP_AUTH_PW']) ||
|
||||
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']])
|
||||
{
|
||||
header('Status: 401');
|
||||
header('WWW-Authenticate: Basic realm="Elwig"');
|
||||
exit("401 Unauthorized :(\n");
|
||||
http_401_unauthorized();
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
|
||||
$name = substr($_SERVER['PATH_INFO'], 1);
|
||||
if (str_contains($name, "..") || str_contains($name, "/")) {
|
||||
header('Status: 403');
|
||||
header('Content-Type: text/plain');
|
||||
header('Content-Length: 17');
|
||||
exit("403 Forbidden :(\n");
|
||||
}
|
||||
|
||||
@ -17,11 +19,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
|
||||
fclose($fp);
|
||||
fclose($upload);
|
||||
|
||||
header('Status: 200');
|
||||
header('Content-Type: text/plain');
|
||||
header('Content-Length: 10');
|
||||
exit("200 OK :)\n");
|
||||
} else if ($_SERVER['REQUEST_METHOD'] !== 'GET' && $_SERVER['REQUEST_METHOD'] !== 'HEAD') {
|
||||
header('Status: 405');
|
||||
header('Content-Length: 0');
|
||||
exit();
|
||||
header('Allow: GET, HEAD, PUT');
|
||||
header('Content-Type: text/plain');
|
||||
header('Content-Length: 26');
|
||||
exit("405 Method Not Allowed :(\n");
|
||||
}
|
||||
|
||||
global $getProd;
|
||||
|
Reference in New Issue
Block a user