Files
cwsvJudo/homepage/participo/api/bootstrap.php
marko f28fa7b51b WIP: bring participo back - consistent use of bootstrap - formatting -
phpstan level 0 error free - fixes for kyu subpage - move mams into
participo framework - remove legacy `lib/db.php` usage - add attributer
admin function - add newsposter - fixing apiKey creation
2025-11-19 12:24:38 +01:00

53 lines
1.3 KiB
PHP

<?php
require_once "config.php";
if (!isset($HOME)) {
die("Missing HOME config!");
}
$CONFIG = json_decode(
json: file_get_contents(filename: join("/", [$HOME, ".local/config.json"])),
associative: true,
);
$SECRETS = json_decode(
json: file_get_contents(
filename: join("/", [$HOME, "/.local/secrets.json"]),
),
associative: true,
);
setlocale(LC_ALL, "de_DE@euro", "de_DE", "de", "ge");
$BASE_PATH = join("/", [$HOME, $CONFIG["cwsvJudo"]["http"]["serve_dir"]]);
set_include_path(
implode(PATH_SEPARATOR, [
get_include_path(),
$BASE_PATH,
join("/", [$BASE_PATH, "ressourcen"]),
join("/", [$BASE_PATH, "ressourcen", "phpLib"]),
join("/", [$HOME, "libs", "php"]),
"../lib/",
]),
);
function authorize()
{
var_dump($_SERVER);
if (array_key_exists("HTTP_AUTHORIZATION", $_SERVER)) {
if (!empty($_SERVER["HTTP_AUTHORIZATION"])) {
$auth = explode(" ", $_SERVER["HTTP_AUTHORIZATION"]);
if ($auth[0] = "Basic") {
$allowKey = ApiKey::loadFromDb($auth[1]);
}
}
}
if (!($allowKey ?? false) || !$allowKey->isValidFor("api")) {
die(
json_encode([
"success" => false,
"reason" => "apiKey not sufficient or no api key provided",
])
);
}
}