Files
cwsvJudo/homepage/participo/api/inc/bootstrap.php
2025-12-07 20:40:33 +01:00

53 lines
1.6 KiB
PHP

<?php
/// @file common settings and includes for the participo api
/** @var array $CONFIG basic configurations (defined via bootstraping) */
/** @var array $SECRETS passwords and other stuff worth of protection (defined via bootstraping) */
require_once "bootstrap.php";
require_once "participoLib/event.php";
participo::init($CONFIG["cwsvJudo"], $SECRETS["cwsvJudo"]);
/// - set locale to german
setlocale(LC_ALL, "de_DE@euro", "de_DE", "de", "ge");
/// - extend the include search path for
set_include_path(
implode(PATH_SEPARATOR, [
get_include_path(),
/// - user defined libs (e.g. participo)
"../lib",
/// - config files (we reuse the participo-wide configuration)
"..",
]),
);
/// - participo configuration
require_once "config/participo.php";
/// - data base credentials
require_once "local/cwsvJudo.php";
/// - since this is a rest api implementation we can assume each endpoint needs dbAccess
require_once "participoLib/dbConnector.php";
function authorize()
{
$allowKey = null;
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 || !$allowKey->isValidFor("api")) {
die(
json_encode([
"success" => false,
"reason" => "apiKey not sufficient or no api key provided",
])
);
}
}