requireAdmin(); I18n::init(); $db = Database::getInstance(); $appTitle = $db->getSetting('app_title', 'UniFi Voucher System'); $error = ''; $success = ''; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['save'])) { if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { $error = __('error_csrf'); } else { $db->setSetting('enforce_2fa_admins', isset($_POST['enforce_2fa_admins']) ? '1' : '0'); $cm = in_array($_POST['captcha_mode'] ?? 'off', ['off','math','hcaptcha'], true) ? $_POST['captcha_mode'] : 'off'; $db->setSetting('captcha_mode', $cm); $db->setSetting('captcha_site_key', trim($_POST['captcha_site_key'] ?? '')); if (!empty($_POST['captcha_secret'])) { $db->setSetting('captcha_secret', trim($_POST['captcha_secret'])); } $db->setSetting('user_daily_voucher_limit', max(0, (int)($_POST['user_daily_voucher_limit'] ?? 0))); $db->setSetting('trusted_proxy', trim($_POST['trusted_proxy'] ?? '')); $db->setSetting('webhook_enabled', isset($_POST['webhook_enabled']) ? '1' : '0'); $db->setSetting('webhook_url', trim($_POST['webhook_url'] ?? '')); $db->setSetting('cleanup_expired_days', max(0, (int)($_POST['cleanup_expired_days'] ?? 0))); $db->setSetting('cleanup_audit_days', max(0, (int)($_POST['cleanup_audit_days'] ?? 0))); $db->setSetting('cleanup_login_days', max(0, (int)($_POST['cleanup_login_days'] ?? 30))); $auth->writeAuditLog($_SESSION['user_id'], 'settings_update', 'config', null, 'Integration/Wartung gespeichert'); $success = 'Einstellungen gespeichert.'; } } if (isset($_GET['test_webhook']) && isset($_GET['token']) && $auth->validateCsrfToken($_GET['token'])) { Notifier::send('✅ Test-Benachrichtigung vom UniFi Voucher System.', ['type' => 'test']); $success = 'Test-Benachrichtigung gesendet (sofern Webhook aktiv & URL gültig).'; } $enforce2fa = $db->getSetting('enforce_2fa_admins', '0') === '1'; $captchaMode = $db->getSetting('captcha_mode', 'off'); $captchaSiteKey = $db->getSetting('captcha_site_key', ''); $captchaSecretSet = $db->getSetting('captcha_secret', '') !== ''; $dailyLimit = (int)$db->getSetting('user_daily_voucher_limit', 0); $trustedProxy = $db->getSetting('trusted_proxy', ''); $webhookEnabled = $db->getSetting('webhook_enabled', '0') === '1'; $webhookUrl = $db->getSetting('webhook_url', ''); $cleanupExpired = (int)$db->getSetting('cleanup_expired_days', 0); $cleanupAudit = (int)$db->getSetting('cleanup_audit_days', 0); $cleanupLogin = (int)$db->getSetting('cleanup_login_days', 30); $lastCleanup = $db->getSetting('last_cleanup', ''); $csrf = $auth->getCsrfToken(); $currentPage = 'integrations'; $adminBase = ''; ?>