From 6e19958a3709cca7731e262b92948ddfb688c754 Mon Sep 17 00:00:00 2001 From: Claude Date: Tue, 9 Jun 2026 19:43:13 +0000 Subject: [PATCH 1/3] =?UTF-8?q?Security-,=20Bugfix-=20und=20UX-=C3=9Cberar?= =?UTF-8?q?beitung=20auf=20Basis=20des=20Code-Reviews?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sicherheit: - Bulk-Erstellung serverseitig auf eingeloggte Nutzer beschränkt; expire_minutes wird validiert (anonym: nur Default/Template-Werte, eingeloggt: max. 1 Jahr) - IP-basiertes Rate-Limit über neue Tabelle request_throttle (Voucher-Erstellung + Passwort-Reset-Anfragen), Session-Fallback für Alt-Installationen; Migration 0002 - session_regenerate_id() nach Login, Secure-Cookie-Flag bei HTTPS - Admin-/Aktiv-Status wird pro Request live aus der DB geprüft (Rechteentzug & Deaktivierung wirken sofort); Schutz vor Selbst-Degradierung im Benutzer-Edit - Alle state-ändernden Admin-Aktionen von GET auf POST umgestellt (kein CSRF-Token mehr in URLs) - login_simple.php (Legacy, Debug-Leak) entfernt; cron_test.php nur noch für Admins; .htaccess auf Apache-2.4-Syntax inkl. cron_test.php - M365 Client Secret wird nicht mehr ins Formular zurückgegeben - Updater: Zip-Slip-/Pfad-Traversal-Schutz, Backup vor dem Anwenden mit automatischem Rollback bei Fehlern, AuditLogger-Bug behoben - cron_sync: Token-Vergleich mit hash_equals; login_attempts-Pruning - CSV-Export gegen Excel-Formula-Injection abgesichert Bugfixes: - M365-Login: Fallback auf userPrincipalName, wenn Graph kein 'mail' liefert (Nutzer ohne Exchange-Postfach konnten sich nie anmelden) - PRG-Pattern überall: F5 erzeugt keine Duplikat-Voucher und wiederholt keine Admin-Aktionen (Session-Flash-Messages) - QR-Code nicht mehr invertiert (schwarz auf weiß, scanbar) - Bulk-Erstellung nutzt den UniFi 'n'-Parameter: 1 API-Call statt n× Login + Voucherlisten-Abruf; exaktes Code-Matching per create_time statt "global neuester Voucher" - Mailer: doppelte Zeilenumbrüche behoben, AUTH nur mit Credentials, SMTP-Dot-Stuffing, CLI-sicherer EHLO-Host - forgot_password: System-URL-Auto-Detect (Reset-Link war sonst relativ/kaputt) + Rate-Limit - Audit-Log-Labels an tatsächliche Action-Keys angepasst; Voucher-Erstellung (einzeln & bulk) wird jetzt auditiert - Site-Edit testet die Verbindung auch ohne Passwortänderung UX/UI: - Alert-/Badge-Styles zentral in global.css mit Dark-Mode-Variablen (vorher 7× dupliziert mit hart codierten Hellfarben) - Sticky-Formulare + Tab-Erhalt nach Validierungsfehlern (Bulk), Settings kehren nach dem Speichern zum aktiven Tab zurück - Gültigkeit menschenlesbar (z.B. "8 Stunden" statt "480 Minuten") - Voucher-Name-Default "Gast/Guest" im öffentlichen Modus - Favicon auch auf Login-/öffentlichen Seiten - Verbindungstest-Button pro Site-Karte (Health-Check) - i18n-Pass: Confirm-Dialoge, Toasts, Fehl-/Erfolgsmeldungen in de/en - Sprachumschalter ohne fetch+reload (kein Re-Submit-Dialog) - A11y: Esc schließt Modals, aria-live für Toasts, aria-labels auf Icon-Buttons; APP_KEY-Warnbanner im Dashboard - Dashboard-Sync: set_time_limit passend zur Site-Anzahl; Voucher-Sync mit Map statt SELECT pro Voucher Tooling: - GitHub-Actions-Workflow: PHP-Lint aller Dateien + de/en-Key-Parität https://claude.ai/code/session_01KKVpVPJjrTKGoRgpJcySD4 --- .github/workflows/lint.yml | 30 ++ admin/audit_log.php | 26 +- admin/index.php | 15 +- admin/settings.php | 44 ++- admin/sites.php | 129 +++++-- admin/templates.php | 43 ++- admin/users.php | 114 +++--- admin/vouchers.php | 25 +- assets/global.css | 73 +++- assets/global.js | 15 +- cron_sync.php | 3 +- cron_test.php | 7 + database.sql | 10 + forgot_password.php | 26 +- includes/Auth.php | 63 +++- includes/Crypto.php | 5 + includes/Helpers.php | 53 +++ includes/Mailer.php | 43 ++- includes/UniFiController.php | 108 +++--- index.php | 216 +++++++++--- install.php | 7 +- lang/de.php | 59 +++- lang/en.php | 59 +++- login.php | 7 +- login_simple.php | 329 ------------------ m365_callback.php | 14 +- reset_password.php | 7 +- updater/README.md | 14 + updater/UpdateController.php | 5 +- updater/UpdateManager.php | 108 +++++- .../0002_voucher_request_throttle.sql | 11 + 31 files changed, 1040 insertions(+), 628 deletions(-) create mode 100644 .github/workflows/lint.yml create mode 100644 includes/Helpers.php delete mode 100644 login_simple.php create mode 100644 updater/migrations/0002_voucher_request_throttle.sql diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..4f2709a --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,30 @@ +name: Lint + +on: + push: + pull_request: + +jobs: + php-lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + - name: PHP Syntax-Check (alle Dateien) + run: | + set -e + fail=0 + while IFS= read -r f; do + php -l "$f" > /dev/null || fail=1 + done < <(git ls-files '*.php') + exit $fail + - name: Sprachdateien-Paritaet (de/en) + run: | + php -r ' + $de = require "lang/de.php"; $en = require "lang/en.php"; + $missing = array_merge(array_diff(array_keys($de), array_keys($en)), array_diff(array_keys($en), array_keys($de))); + if ($missing) { fwrite(STDERR, "Fehlende Keys: " . implode(", ", $missing) . "\n"); exit(1); } + echo "OK: " . count($de) . " Keys synchron\n"; + ' diff --git a/admin/audit_log.php b/admin/audit_log.php index 0af636a..1cfb77e 100644 --- a/admin/audit_log.php +++ b/admin/audit_log.php @@ -45,22 +45,23 @@ $users = $db->fetchAll("SELECT id, name FROM users WHERE is_active = 1 ORDER BY $currentPage = 'audit_log'; $adminBase = ''; +// WICHTIG: Die Keys muessen den tatsaechlich via writeAuditLog() geschriebenen +// Action-Namen entsprechen (user_create, site_edit, ...), sonst erscheinen +// die Eintraege als rohe Keys. $actionLabels = [ - 'voucher_created' => '🎫 Voucher erstellt', + 'voucher_create' => '🎫 Voucher erstellt', 'voucher_bulk' => '🎫 Bulk Voucher', 'user_login' => '🔐 Login', - 'user_logout' => '🚪 Logout', - 'user_created' => '👤 Benutzer erstellt', - 'user_updated' => '👤 Benutzer geändert', - 'user_deleted' => '👤 Benutzer gelöscht', - 'site_added' => '🌐 Site hinzugefügt', - 'site_updated' => '🌐 Site geändert', - 'site_deleted' => '🌐 Site gelöscht', - 'settings_saved' => '⚙️ Einstellungen gespeichert', + 'user_create' => '👤 Benutzer erstellt', + 'user_edit' => '👤 Benutzer geändert', + 'user_delete' => '👤 Benutzer gelöscht', + 'site_create' => '🌐 Site hinzugefügt', + 'site_edit' => '🌐 Site geändert', + 'site_delete' => '🌐 Site gelöscht', 'password_reset' => '🔑 Passwort-Reset', - 'template_created' => '📋 Profil erstellt', - 'template_updated' => '📋 Profil geändert', - 'template_deleted' => '📋 Profil gelöscht', + 'update_installed' => '🔄 Update installiert', + 'update_failed' => '🔄 Update fehlgeschlagen', + 'migrations_run' => '🗄️ Migrationen ausgeführt', ]; ?> @@ -81,7 +82,6 @@ $actionLabels = [ .table td { padding: 12px 15px; border-bottom: 1px solid var(--border-color); font-size: 13px; color: var(--text-primary); } .table tr:last-child td { border-bottom: none; } .table tr:hover td { background: var(--bg-hover); } - .badge { display: inline-block; padding: 3px 9px; border-radius: 5px; font-size: 11px; font-weight: 500; } .filter-bar { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; } .filter-bar select { padding: 9px 12px; border: 2px solid var(--border-color); border-radius: 8px; font-size: 13px; background: var(--bg-input); color: var(--text-primary); } .filter-bar select:focus { outline: none; border-color: var(--accent); } diff --git a/admin/index.php b/admin/index.php index e432205..6b8a32a 100644 --- a/admin/index.php +++ b/admin/index.php @@ -26,6 +26,9 @@ if (isset($_GET['ajax_stats'])) { $syncErrors = []; if ($syncFirst) { + // Mehrere Sites werden sequentiell synchronisiert (je bis zu ~15s + // bei Timeout) – PHP-Default von 30s reicht dann nicht. + @set_time_limit(30 + count($sites) * 20); foreach ($sites as $site) { try { $ctrl = new UniFiController($site['unifi_controller_url'], $site['unifi_username'], Crypto::decrypt($site['unifi_password']), $site['site_id']); @@ -122,11 +125,6 @@ $currentPage = 'dashboard'; .table th { text-align: left; padding: 11px 14px; background: var(--bg-table-head); color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; } .table td { padding: 13px 14px; border-bottom: 1px solid var(--border-color); color: var(--text-primary); font-size: 14px; } .table tr:last-child td { border-bottom: none; } - .badge { display: inline-block; padding: 3px 9px; border-radius: 5px; font-size: 11px; font-weight: 500; } - .badge-success { background: #d4edda; color: #155724; } - .badge-warning { background: #fff3cd; color: #856404; } - .badge-danger { background: #f8d7da; color: #721c24; } - .badge-info { background: var(--bg-badge-info); color: var(--text-badge-info); } .btn-primary { background: var(--accent); color: white; } .btn-primary:hover { background: var(--accent-hover); } .btn-success { background: var(--success); color: white; } @@ -161,6 +159,13 @@ $currentPage = 'dashboard'; @media(max-width:768px){ .main-content{ margin-left:0!important; } .stats-grid{ grid-template-columns:1fr 1fr; } } + +
+ + +
+ +