camera - (real) remote control, brandschutz - configurable course, dashboard - vbb licensed API (a real vbb license, how cool)
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
require_once $_SERVER['DOCUMENT_ROOT'] . '/intranet_repo/general_files/initialise.php';
|
||||
require_once __DIR__ . '/util/camera_remote_helpers.php';
|
||||
|
||||
header('Content-Type: application/json; charset=utf-8');
|
||||
|
||||
function camera_remote_response(int $status, array $payload): never
|
||||
{
|
||||
http_response_code($status);
|
||||
echo json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
||||
camera_remote_response(405, ['ok' => false, 'error' => 'Methode nicht erlaubt.']);
|
||||
}
|
||||
if (!camera_remote_is_authorized(is_array($groups ?? null) ? $groups : [])) {
|
||||
camera_remote_response(403, ['ok' => false, 'error' => 'Keine Berechtigung für die Kamera-Fernbedienung.']);
|
||||
}
|
||||
|
||||
try {
|
||||
camera_remote_verify_csrf($_POST['csrf_token'] ?? null);
|
||||
$action = is_string($_POST['action'] ?? null) ? $_POST['action'] : '';
|
||||
camera_remote_run($action);
|
||||
camera_remote_response(200, ['ok' => true]);
|
||||
} catch (InvalidArgumentException $exception) {
|
||||
camera_remote_response(400, ['ok' => false, 'error' => $exception->getMessage()]);
|
||||
} catch (RuntimeException $exception) {
|
||||
camera_remote_response(503, ['ok' => false, 'error' => $exception->getMessage()]);
|
||||
} catch (Throwable $exception) {
|
||||
error_log('Camera Remote: ' . $exception->getMessage());
|
||||
camera_remote_response(500, ['ok' => false, 'error' => 'Der Kamerabefehl konnte nicht ausgeführt werden.']);
|
||||
}
|
||||
Reference in New Issue
Block a user