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
148 lines
4.9 KiB
PHP
148 lines
4.9 KiB
PHP
<?php
|
||
namespace Updater;
|
||
|
||
/**
|
||
* UpdateController – bedient die Admin-Seite /admin/update sowie deren
|
||
* AJAX-Actions (check, install, progress, set_channel, migrations).
|
||
*
|
||
* Nutzt die vorhandenen Projekt-Klassen \Database und \Auth per Injection.
|
||
* Die eigentliche Logik liegt im UpdateManager; dieser Controller ist nur
|
||
* die duenne Auslieferungs-/Routing-Schicht.
|
||
*/
|
||
class UpdateController
|
||
{
|
||
/** @var \Database */
|
||
private $db;
|
||
/** @var \Auth */
|
||
private $auth;
|
||
/** @var UpdateManager */
|
||
private $manager;
|
||
/** @var AuditLogger */
|
||
private $audit;
|
||
|
||
public function __construct(\Database $db, \Auth $auth)
|
||
{
|
||
$this->db = $db;
|
||
$this->auth = $auth;
|
||
$this->audit = new AuditLogger($db);
|
||
$this->manager = UpdaterFactory::create($db, $this->audit);
|
||
}
|
||
|
||
public function handle(): void
|
||
{
|
||
$action = $_GET['action'] ?? $_POST['action'] ?? '';
|
||
switch ($action) {
|
||
case 'check': $this->actionCheck(); break;
|
||
case 'install': $this->actionInstall(); break;
|
||
case 'progress': $this->actionProgress(); break;
|
||
case 'set_channel': $this->actionSetChannel(); break;
|
||
case 'migrations': $this->actionMigrations(); break;
|
||
case 'run_migrations': $this->actionRunMigrations(); break;
|
||
default: $this->renderPage();
|
||
}
|
||
}
|
||
|
||
// ------------------------------------------------------------- AJAX-Actions
|
||
|
||
private function actionCheck(): void
|
||
{
|
||
try {
|
||
$this->json($this->manager->checkForUpdates());
|
||
} catch (\Throwable $e) {
|
||
$this->json(['error' => $e->getMessage()], 502);
|
||
}
|
||
}
|
||
|
||
private function actionInstall(): void
|
||
{
|
||
if (!$this->auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||
$this->json(['error' => 'Ungültiges Sicherheits-Token'], 403);
|
||
return;
|
||
}
|
||
// Session-Lock freigeben, damit parallele Progress-Polls nicht blockieren.
|
||
if (session_status() === PHP_SESSION_ACTIVE) {
|
||
session_write_close();
|
||
}
|
||
@set_time_limit(300);
|
||
$userId = $_SESSION['user_id'] ?? null;
|
||
$result = $this->manager->installUpdate($userId !== null ? (int)$userId : null);
|
||
$this->json($result, $result['success'] ? 200 : 500);
|
||
}
|
||
|
||
private function actionProgress(): void
|
||
{
|
||
// Kein CSRF noetig (read-only). Session-Lock sofort freigeben.
|
||
if (session_status() === PHP_SESSION_ACTIVE) {
|
||
session_write_close();
|
||
}
|
||
$this->json($this->manager->getProgress());
|
||
}
|
||
|
||
private function actionSetChannel(): void
|
||
{
|
||
if (!$this->auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||
$this->json(['error' => 'Ungültiges Sicherheits-Token'], 403);
|
||
return;
|
||
}
|
||
$channel = $_POST['channel'] ?? 'stable';
|
||
UpdaterFactory::saveChannel($channel);
|
||
$this->json(['success' => true, 'channel' => $channel]);
|
||
}
|
||
|
||
private function actionMigrations(): void
|
||
{
|
||
try {
|
||
$runner = new MigrationRunner(
|
||
$this->db->getConnection(),
|
||
__DIR__ . '/migrations',
|
||
__DIR__ . '/storage'
|
||
);
|
||
$this->json(['migrations' => $runner->status()]);
|
||
} catch (\Throwable $e) {
|
||
$this->json(['error' => $e->getMessage()], 500);
|
||
}
|
||
}
|
||
|
||
private function actionRunMigrations(): void
|
||
{
|
||
if (!$this->auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
||
$this->json(['error' => 'Ungültiges Sicherheits-Token'], 403);
|
||
return;
|
||
}
|
||
try {
|
||
$runner = new MigrationRunner(
|
||
$this->db->getConnection(),
|
||
__DIR__ . '/migrations',
|
||
__DIR__ . '/storage'
|
||
);
|
||
$applied = $runner->runPending(true);
|
||
if ($this->audit) {
|
||
$this->audit->log('migrations_run', ['applied' => $applied], $_SESSION['user_id'] ?? null);
|
||
}
|
||
$this->json(['success' => true, 'applied' => $applied, 'migrations' => $runner->status()]);
|
||
} catch (\Throwable $e) {
|
||
$this->json(['error' => $e->getMessage()], 500);
|
||
}
|
||
}
|
||
|
||
// ------------------------------------------------------------------- Render
|
||
|
||
private function renderPage(): void
|
||
{
|
||
$manager = $this->manager;
|
||
$auth = $this->auth;
|
||
$currentSha = $manager->getCurrentVersion();
|
||
$channel = $manager->getChannel();
|
||
$csrfToken = $auth->getCsrfToken();
|
||
require __DIR__ . '/templates/update.php';
|
||
}
|
||
|
||
private function json($data, int $status = 200): void
|
||
{
|
||
if (!headers_sent()) {
|
||
http_response_code($status);
|
||
header('Content-Type: application/json; charset=utf-8');
|
||
}
|
||
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
||
}
|
||
}
|