Some checks failed
CI / PHP Lint (push) Waiting to run
CI / PHP Lint-1 (push) Waiting to run
CI / Unit Tests & Static Analysis (push) Waiting to run
CI / PHP Lint (pull_request) Has been cancelled
CI / PHP Lint-1 (pull_request) Has been cancelled
CI / Unit Tests & Static Analysis (pull_request) Has been cancelled
Frontend, Login/Installer/Updater und der komplette Admin-Bereich nutzen jetzt ein einziges Stylesheet (assets/global.css) statt pro Seite dupliziertem Inline-CSS. Design-System - Tokens für Flächen, Text, Linien, Marke, Status, Radien, Schatten und Layout-Maße; Dark Mode ausschließlich über Tokens (keine !important- Overrides mehr) - Komponenten: Buttons, Formularfelder, Cards, Tabellen, Badges, Alerts, Tabs, Pagination, Modals, Toasts, Statistik-Kacheln, Empty States - Schrift Inter mit System-Fallback Oberfläche - Admin-Shell neu: durchgehende Sidebar mit Marke, gruppierter Navigation und Benutzerbereich; schlanke Topbar mit Breadcrumb - Dashboard: ruhige KPI-Kacheln mit Icon-Chips, Charts an Theme-Farben gekoppelt - Öffentliche Voucher-Seite: App-Topbar, klare Formularstruktur und Ticket-Darstellung des erstellten Codes inkl. QR-Code - Login/Passwort/2FA: zweispaltiges Auth-Layout bzw. Fokus-Karten - Updater und Wartungsmodus im gleichen Look (Wartungsseite bleibt bewusst eigenständig ohne externe Abhängigkeiten) - Emoji-Icons in der UI durch Font-Awesome-Icons ersetzt Nebenbei behoben - Falscher SRI-Hash blockierte qrcode.min.js – QR-Codes wurden auf der Voucher-Seite und bei der 2FA-Einrichtung nie gerendert - assets/global.css wurde in mehreren Admin-Seiten über einen falschen Pfad eingebunden ($adminBase = '' statt '../') - TinyMCE lädt ohne API-Key jetzt die GPL-Variante von cdnjs – kein "valid API key required"-Banner mehr im Einstellungs-Editor - Tabellen in Cards scrollen horizontal statt zu überlaufen Screenshots in docs/screenshots neu erstellt, README aktualisiert (neuer Abschnitt "Design-System", Version 2.5.0). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
182 lines
8.3 KiB
PHP
182 lines
8.3 KiB
PHP
<?php
|
||
error_reporting(E_ALL);
|
||
ini_set('display_errors', 0);
|
||
ini_set('log_errors', 1);
|
||
|
||
require_once __DIR__ . '/../config.php';
|
||
require_once __DIR__ . '/../includes/Database.php';
|
||
require_once __DIR__ . '/../includes/Auth.php';
|
||
|
||
$auth = new Auth();
|
||
$auth->requireLogin();
|
||
|
||
$db = Database::getInstance();
|
||
$user = $auth->getCurrentUser();
|
||
$appTitle = $db->getSetting('app_title', 'UniFi Voucher System');
|
||
|
||
$error = '';
|
||
$success = '';
|
||
$backupCodes = []; // nur direkt nach Erzeugung gefüllt
|
||
$hasPassword = !empty($user['password_hash']);
|
||
$totpEnabled = !empty($user['totp_enabled']);
|
||
$setupRequired = isset($_GET['setup_required']);
|
||
|
||
// 2FA aktivieren (Code bestaetigen)
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['enable_totp'])) {
|
||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||
$error = 'Ungültiges Sicherheits-Token';
|
||
} else {
|
||
$secret = $_SESSION['totp_setup_secret'] ?? '';
|
||
$code = trim($_POST['code'] ?? '');
|
||
if ($secret === '') {
|
||
$error = 'Setup abgelaufen, bitte erneut starten.';
|
||
} elseif (!Totp::verify($secret, $code)) {
|
||
$error = 'Code ungültig. Bitte erneut versuchen.';
|
||
} else {
|
||
$backupCodes = $auth->enableTotp($user['id'], $secret);
|
||
unset($_SESSION['totp_setup_secret']);
|
||
$totpEnabled = true;
|
||
$user = $auth->getCurrentUser();
|
||
$success = 'Zwei-Faktor-Authentifizierung wurde aktiviert. Bitte Recovery-Codes sicher speichern!';
|
||
}
|
||
}
|
||
}
|
||
|
||
// Überall abmelden (andere Sessions beenden)
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['logout_others'])) {
|
||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||
$error = 'Ungültiges Sicherheits-Token';
|
||
} else {
|
||
$auth->logoutOtherSessions();
|
||
$success = 'Alle anderen Sitzungen wurden beendet.';
|
||
}
|
||
}
|
||
|
||
// Recovery-Codes neu erzeugen
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['regen_codes'])) {
|
||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||
$error = 'Ungültiges Sicherheits-Token';
|
||
} elseif (!empty($user['totp_enabled'])) {
|
||
$backupCodes = $auth->regenerateBackupCodes($user['id']);
|
||
$user = $auth->getCurrentUser();
|
||
$success = 'Neue Recovery-Codes erzeugt. Die alten sind jetzt ungültig.';
|
||
}
|
||
}
|
||
|
||
// 2FA deaktivieren
|
||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['disable_totp'])) {
|
||
if (!$auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||
$error = 'Ungültiges Sicherheits-Token';
|
||
} else {
|
||
$auth->disableTotp($user['id']);
|
||
$totpEnabled = false;
|
||
$success = 'Zwei-Faktor-Authentifizierung wurde deaktiviert.';
|
||
}
|
||
}
|
||
|
||
// Für die Setup-Ansicht ein Secret erzeugen (in Session halten bis bestätigt)
|
||
$setupSecret = '';
|
||
$otpUri = '';
|
||
if (!$totpEnabled && $hasPassword) {
|
||
$setupSecret = $_SESSION['totp_setup_secret'] ?? Totp::generateSecret();
|
||
$_SESSION['totp_setup_secret'] = $setupSecret;
|
||
$otpUri = Totp::provisioningUri($setupSecret, $user['email'], $appTitle);
|
||
}
|
||
$csrf = $auth->getCsrfToken();
|
||
$dbSessions = $db->getSetting('session_driver', 'php') === 'db';
|
||
$activeSessions = $dbSessions ? $auth->activeSessionCount() : 0;
|
||
?>
|
||
<!DOCTYPE html>
|
||
<html lang="de">
|
||
<head>
|
||
<meta charset="UTF-8">
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||
<title>Zwei-Faktor-Authentifizierung – <?= htmlspecialchars($appTitle) ?></title>
|
||
<?php if (!$totpEnabled && $hasPassword): ?>
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/qrcodejs/1.0.0/qrcode.min.js" integrity="sha512-CNgIRecGo7nphbeZ04Sc13ka07paqdeTu0WR1IM4kNcpmBAUSHSQX0FslNhTDadL4O5SAGapGt4FodqL8My0mA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
|
||
<?php endif; ?>
|
||
<link rel="preconnect" href="https://fonts.googleapis.com">
|
||
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap">
|
||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
|
||
<link rel="stylesheet" href="../assets/global.css">
|
||
<script>(function(){ const t=localStorage.getItem('theme')||'light'; document.documentElement.setAttribute('data-theme',t); })();</script>
|
||
</head>
|
||
<body class="app-body focus-page">
|
||
<div class="focus-card card">
|
||
<div class="focus-head">
|
||
<span class="focus-icon"><i class="fas fa-shield-halved"></i></span>
|
||
<div>
|
||
<h1>Zwei-Faktor-Authentifizierung</h1>
|
||
<p class="sub">Konto: <?= htmlspecialchars($user['email']) ?></p>
|
||
</div>
|
||
</div>
|
||
|
||
<?php if ($setupRequired && !$totpEnabled): ?>
|
||
<div class="alert alert-error">Aus Sicherheitsgründen ist 2FA für Administratoren verpflichtend. Bitte jetzt einrichten.</div>
|
||
<?php endif; ?>
|
||
<?php if ($error): ?><div class="alert alert-error"><?= htmlspecialchars($error) ?></div><?php endif; ?>
|
||
<?php if ($success): ?><div class="alert alert-ok"><?= htmlspecialchars($success) ?></div><?php endif; ?>
|
||
|
||
<?php if (!empty($backupCodes)): ?>
|
||
<div class="codes-box">
|
||
<strong><i class="fas fa-key"></i> Recovery-Codes</strong>
|
||
<p>Bewahren Sie diese sicher auf. Jeder Code funktioniert <em>einmal</em>, falls Sie keinen Zugriff auf Ihre App haben.</p>
|
||
<div class="codes">
|
||
<?php foreach ($backupCodes as $c): ?><span><?= htmlspecialchars($c) ?></span><?php endforeach; ?>
|
||
</div>
|
||
</div>
|
||
<?php endif; ?>
|
||
|
||
<?php if (!$hasPassword): ?>
|
||
<div class="status off"><i class="fas fa-circle-minus"></i> Nicht verfügbar</div>
|
||
<p class="sub">Ihr Konto meldet sich über Microsoft 365 an. 2FA wird dort in Ihrem Microsoft-Konto verwaltet.</p>
|
||
<?php elseif ($totpEnabled): ?>
|
||
<div class="status on"><i class="fas fa-circle-check"></i> Aktiv</div>
|
||
<p class="sub">Bei jeder Anmeldung wird zusätzlich ein Code aus Ihrer Authenticator-App abgefragt.<br>
|
||
Verbleibende Recovery-Codes: <strong><?= (int)$auth->backupCodesRemaining($user) ?></strong></p>
|
||
<form method="post" style="margin-bottom:10px;">
|
||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf) ?>">
|
||
<button type="submit" name="regen_codes" class="btn btn-secondary btn-lg btn-block">Recovery-Codes neu erzeugen</button>
|
||
</form>
|
||
<form method="post" onsubmit="return confirm('2FA wirklich deaktivieren?');">
|
||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf) ?>">
|
||
<button type="submit" name="disable_totp" class="btn btn-danger btn-lg btn-block">2FA deaktivieren</button>
|
||
</form>
|
||
<?php else: ?>
|
||
<div class="status off"><i class="fas fa-circle-minus"></i> Inaktiv</div>
|
||
<ol>
|
||
<li>Authenticator-App öffnen (Google Authenticator, Authy, Microsoft Authenticator …)</li>
|
||
<li>QR-Code scannen <em>oder</em> Secret manuell eingeben</li>
|
||
<li>Den angezeigten 6-stelligen Code unten eingeben</li>
|
||
</ol>
|
||
<div class="qr"><div id="qrcode"></div></div>
|
||
<div class="secret"><?= htmlspecialchars($setupSecret) ?></div>
|
||
<form method="post">
|
||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf) ?>">
|
||
<label for="code">6-stelliger Code</label>
|
||
<input type="text" id="code" name="code" class="code-input" inputmode="numeric" pattern="[0-9]*" maxlength="6" autocomplete="one-time-code" required placeholder="123456">
|
||
<button type="submit" name="enable_totp" class="btn btn-primary btn-lg btn-block" style="margin-top:14px;">2FA aktivieren</button>
|
||
</form>
|
||
<script>
|
||
new QRCode(document.getElementById('qrcode'), {
|
||
text: <?= json_encode($otpUri) ?>, width: 168, height: 168,
|
||
colorDark: '#101625', colorLight: '#ffffff',
|
||
correctLevel: QRCode.CorrectLevel.M
|
||
});
|
||
</script>
|
||
<?php endif; ?>
|
||
|
||
<?php if ($dbSessions): ?>
|
||
<hr>
|
||
<p class="sub">Aktive Sitzungen: <strong><?= (int)$activeSessions ?></strong></p>
|
||
<form method="post" onsubmit="return confirm('Alle anderen Sitzungen abmelden?');">
|
||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf) ?>">
|
||
<button type="submit" name="logout_others" class="btn btn-secondary btn-lg btn-block">Auf allen anderen Geräten abmelden</button>
|
||
</form>
|
||
<?php endif; ?>
|
||
|
||
<div class="auth-links"><a class="back-link" href="../index.php"><i class="fas fa-arrow-left"></i> Zurück</a></div>
|
||
</div>
|
||
</body>
|
||
</html>
|