47 lines
1.5 KiB
PHP
47 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
require_once dirname(__DIR__, 5) . '/src/App/bootstrap.php';
|
|
require_once dirname(__DIR__, 5) . '/modules/mining-checker/bootstrap.php';
|
|
|
|
use Modules\MiningChecker\Legacy\LegacyModuleStore;
|
|
use Modules\MiningChecker\Legacy\UserScope;
|
|
use ModulesCore\ModuleHttp;
|
|
|
|
session_start();
|
|
|
|
$projectRoot = dirname(__DIR__, 5);
|
|
ModuleHttp::requireDesktopAccess($projectRoot, true);
|
|
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
|
|
$store = new LegacyModuleStore($projectRoot, UserScope::current());
|
|
$method = strtoupper((string) ($_SERVER['REQUEST_METHOD'] ?? 'GET'));
|
|
|
|
if ($method === 'GET') {
|
|
echo json_encode($store->loadAuth(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
exit;
|
|
}
|
|
|
|
if ($method === 'PUT') {
|
|
$raw = file_get_contents('php://input');
|
|
$payload = json_decode($raw !== false ? $raw : '', true);
|
|
$payload = is_array($payload) ? $payload : [];
|
|
|
|
$users = preg_split('/[\s,;]+/', (string) ($payload['users'] ?? '')) ?: [];
|
|
$groups = preg_split('/[\s,;]+/', (string) ($payload['groups'] ?? '')) ?: [];
|
|
|
|
$store->saveAuth([
|
|
'required' => (bool) ($payload['required'] ?? true),
|
|
'users' => array_values(array_filter(array_map('trim', $users))),
|
|
'groups' => array_values(array_filter(array_map('trim', $groups))),
|
|
]);
|
|
|
|
echo json_encode($store->loadAuth(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
exit;
|
|
}
|
|
|
|
http_response_code(405);
|
|
echo json_encode(['error' => 'Methode nicht erlaubt.'], JSON_UNESCAPED_UNICODE);
|