$app */ $app = require __DIR__ . '/src/bootstrap.php'; $config = $app['config']; $manager = $app['manager']; $service = $app['service']; $auth = new App\ManageAuth($config); $redirect = static function (): never { header('Location: manage.php', true, 303); exit; }; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $token = is_string($_POST['csrf'] ?? null) ? $_POST['csrf'] : ''; $action = is_string($_POST['action'] ?? null) ? $_POST['action'] : ''; $input = is_string($_POST['input'] ?? null) ? trim($_POST['input']) : ''; $url = is_string($_POST['url'] ?? null) ? trim($_POST['url']) : ''; $enabled = is_string($_POST['enabled'] ?? null) && $_POST['enabled'] === '1'; if (!$auth->enabled() || !$auth->checkCsrf($token)) { $auth->flash('err', 'Session expired — please try again.'); $redirect(); } if ($action === 'logout') { $auth->logout(); $auth->flash('ok', 'Signed out.'); $redirect(); } if ($action === 'login') { if (!$auth->login($input)) { $auth->flash('err', 'Wrong password.'); } $redirect(); } $result = $auth->authed() ? match ($action) { 'add_reddit' => $manager->addReddit($input), 'add_youtube' => $manager->addYouTube($input), 'toggle' => $manager->setEnabled($url, $enabled), 'remove' => $manager->remove($url), default => null, } : null; if ($result === null) { $auth->flash('err', 'Please sign in first.'); } else { $auth->flash($result['ok'] ? 'ok' : 'err', $result['message']); } $redirect(); } echo App\View::render('manage', [ 'config' => $config, 'auth' => $auth, 'feeds' => $auth->authed() ? $service->feedsStatus() : [], 'flash' => $auth->takeFlash(), ]);