diff --git a/Readme.md b/Readme.md index 46a8a84..996b647 100644 --- a/Readme.md +++ b/Readme.md @@ -423,6 +423,11 @@ bleiben lediglich für hCaptcha offen, falls es aktiviert wird. Ordner wie > werden die `.htaccess`-Dateien ignoriert. Das mitgelieferte Docker-Image > erledigt das bereits. +> **Caddy liest keine `.htaccess`.** Läuft das Tool hinter Caddy, müssen die +> Regeln in den Caddyfile – eine fertige Vorlage liegt unter +> [`docs/Caddyfile.example`](docs/Caddyfile.example). Besonders wichtig ist +> dort die Sperre, die PHP-Dateien unterhalb von `uploads/` nicht ausführt. + Für **Nginx** entspricht das: ```nginx @@ -476,7 +481,6 @@ GRANT SELECT, INSERT, UPDATE, DELETE ON unifi_voucher.* TO 'unifi_voucher'@'loca - Redirect URI in Azure AD prüfen - Client ID, Secret und Tenant ID kontrollieren -- Diagnose unter `m365_debug.php` (nur als Admin erreichbar) --- diff --git a/admin/api_keys.php b/admin/api_keys.php index ccc0c24..7c7fc9a 100644 --- a/admin/api_keys.php +++ b/admin/api_keys.php @@ -42,17 +42,17 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['create_key'])) { } } -if (isset($_GET['toggle']) && isset($_GET['token']) && $auth->validateCsrfToken($_GET['token'])) { - $row = $db->fetchOne("SELECT is_active FROM api_keys WHERE id = ?", [(int)$_GET['toggle']]); +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['toggle_key']) && $auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { + $row = $db->fetchOne("SELECT is_active FROM api_keys WHERE id = ?", [(int)($_POST['key_id'] ?? 0)]); if ($row) { - $db->query("UPDATE api_keys SET is_active = ? WHERE id = ?", [$row['is_active'] ? 0 : 1, (int)$_GET['toggle']]); + $db->query("UPDATE api_keys SET is_active = ? WHERE id = ?", [$row['is_active'] ? 0 : 1, (int)($_POST['key_id'] ?? 0)]); $success = __('api_status_updated'); } } -if (isset($_GET['delete']) && isset($_GET['token']) && $auth->validateCsrfToken($_GET['token'])) { - $db->query("DELETE FROM api_keys WHERE id = ?", [(int)$_GET['delete']]); - $auth->writeAuditLog($_SESSION['user_id'], 'api_key_delete', 'api_key', (int)$_GET['delete'], 'API-Key gelöscht'); +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_key']) && $auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { + $db->query("DELETE FROM api_keys WHERE id = ?", [(int)($_POST['key_id'] ?? 0)]); + $auth->writeAuditLog($_SESSION['user_id'], 'api_key_delete', 'api_key', (int)($_POST['key_id'] ?? 0), 'API-Key gelöscht'); $success = __('api_deleted'); } @@ -127,8 +127,12 @@ $adminBase = ''; - - + (int)$k['id']], $csrf, + htmlspecialchars($k['is_active'] ? __('api_action_block') : __('api_action_unblock')), + 'btn btn-secondary btn-sm') ?> + (int)$k['id']], $csrf, + htmlspecialchars(__('btn_delete')), + 'btn btn-danger-soft btn-sm', __('api_delete_confirm')) ?> diff --git a/admin/backup.php b/admin/backup.php index bc4bfa6..e2bf628 100644 --- a/admin/backup.php +++ b/admin/backup.php @@ -7,6 +7,7 @@ require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../includes/Database.php'; require_once __DIR__ . '/../includes/Auth.php'; require_once __DIR__ . '/../includes/I18n.php'; +require_once __DIR__ . '/../includes/Kiosk.php'; $auth = new Auth(); $auth->requireAdmin(); @@ -23,13 +24,25 @@ if (isset($_GET['export']) && isset($_GET['token']) && $auth->validateCsrfToken( $export = [ 'meta' => [ 'app' => 'unifi-voucher-tool', - 'version' => '2.2.0', + 'version' => trim((string)@file_get_contents(dirname(__DIR__) . '/VERSION')), 'exported_at'=> date('c'), 'note' => 'Site-Passwörter sind mit dem APP_KEY dieser Installation verschlüsselt.', ], 'settings' => $db->fetchAll("SELECT setting_key, setting_value FROM settings"), 'sites' => $db->fetchAll("SELECT name, site_id, unifi_controller_url, unifi_username, unifi_password, is_active, public_access FROM sites"), 'voucher_templates' => $db->fetchAll("SELECT name, max_uses, expire_minutes, description, qos_rate_max_down, qos_rate_max_up, qos_usage_quota, is_active FROM voucher_templates"), + // Display-Seiten samt Token: sonst zeigen aufgehängte QR-Codes nach + // einem Restore ins Leere. Site und Profil werden über den Namen + // verknüpft, weil die IDs auf der Zielinstallation andere sind. + 'kiosks' => $db->fetchAll( + "SELECT k.name, k.token, k.headline, k.subline, k.logo_url, k.background_url, + k.bg_overlay, k.accent_color, k.card_style, k.daily_limit, + k.cooldown_seconds, k.display_seconds, k.is_active, + s.name AS site_name, t.name AS template_name + FROM kiosks k + INNER JOIN sites s ON s.id = k.site_id + LEFT JOIN voucher_templates t ON t.id = k.template_id" + ), ]; $auth->writeAuditLog($_SESSION['user_id'], 'config_export', 'config', null, 'Konfiguration exportiert'); header('Content-Type: application/json'); @@ -53,7 +66,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['import'])) { $importSites = isset($_POST['import_sites']); $importTemplates = isset($_POST['import_templates']); $importSettings = isset($_POST['import_settings']); - $counts = ['settings' => 0, 'sites' => 0, 'templates' => 0]; + $importKiosks = isset($_POST['import_kiosks']); + $counts = ['settings' => 0, 'sites' => 0, 'templates' => 0, 'kiosks' => 0]; try { if ($importSettings && !empty($data['settings'])) { @@ -94,9 +108,49 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['import'])) { } } } + if ($importKiosks && !empty($data['kiosks'])) { + foreach ($data['kiosks'] as $k) { + $site = $db->fetchOne("SELECT id FROM sites WHERE name = ?", [$k['site_name'] ?? '']); + if (!$site) { + continue; // ohne passende Site ergibt die Display-Seite keinen Sinn + } + $templateId = null; + if (!empty($k['template_name'])) { + $tpl = $db->fetchOne("SELECT id FROM voucher_templates WHERE name = ?", [$k['template_name']]); + $templateId = $tpl['id'] ?? null; + } + + $exists = $db->fetchOne("SELECT id FROM kiosks WHERE token = ?", [$k['token'] ?? '']); + $values = [ + (int)$site['id'], $templateId, $k['name'], $k['headline'] ?? null, $k['subline'] ?? null, + $k['logo_url'] ?? null, $k['background_url'] ?? null, (int)($k['bg_overlay'] ?? 45), + $k['accent_color'] ?? null, ($k['card_style'] ?? 'light') === 'dark' ? 'dark' : 'light', + (int)($k['daily_limit'] ?? 100), (int)($k['cooldown_seconds'] ?? 20), + (int)($k['display_seconds'] ?? 90), (int)($k['is_active'] ?? 1), + ]; + + if ($exists) { + $db->query( + "UPDATE kiosks SET site_id=?, template_id=?, name=?, headline=?, subline=?, logo_url=?, + background_url=?, bg_overlay=?, accent_color=?, card_style=?, daily_limit=?, + cooldown_seconds=?, display_seconds=?, is_active=? WHERE id=?", + array_merge($values, [(int)$exists['id']]) + ); + } else { + $db->query( + "INSERT INTO kiosks (site_id, template_id, name, headline, subline, logo_url, background_url, + bg_overlay, accent_color, card_style, daily_limit, cooldown_seconds, display_seconds, + is_active, token, created_by) + VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", + array_merge($values, [$k['token'] ?? Kiosk::newToken(), $_SESSION['user_id'] ?? null]) + ); + } + $counts['kiosks']++; + } + } $auth->writeAuditLog($_SESSION['user_id'], 'config_import', 'config', null, 'Konfiguration importiert'); - $success = str_replace(['{settings}', '{sites}', '{templates}'], - [(string)$counts['settings'], (string)$counts['sites'], (string)$counts['templates']], + $success = str_replace(['{settings}', '{sites}', '{templates}', '{kiosks}'], + [(string)$counts['settings'], (string)$counts['sites'], (string)$counts['templates'], (string)$counts['kiosks']], __('backup_imported')); } catch (Exception $e) { $error = 'Import-Fehler: ' . $e->getMessage(); @@ -141,6 +195,7 @@ $adminBase = ''; + diff --git a/admin/integrations.php b/admin/integrations.php index cfc7c83..74a3bd3 100644 --- a/admin/integrations.php +++ b/admin/integrations.php @@ -77,6 +77,12 @@ $oidcScopes = $db->getSetting('oidc_scopes', 'openid profile email'); $oidcSecretSet = $db->getSetting('oidc_client_secret', '') !== ''; $dailyLimit = (int)$db->getSetting('user_daily_voucher_limit', 0); $trustedProxy = $db->getSetting('trusted_proxy', ''); + +// Hinweis, wenn die Anfrage offensichtlich über einen Proxy kam, aber keiner +// eingetragen ist: dann zählt das Rate-Limit alle Gäste als eine Adresse. +$remoteAddr = (string)($_SERVER['REMOTE_ADDR'] ?? ''); +$proxyWarning = trim($trustedProxy) === '' + && (!empty($_SERVER['HTTP_X_FORWARDED_FOR']) || !empty($_SERVER['HTTP_X_REAL_IP'])); $webhookEnabled = $db->getSetting('webhook_enabled', '0') === '1'; $webhookUrl = $db->getSetting('webhook_url', ''); $cleanupExpired = (int)$db->getSetting('cleanup_expired_days', 0); @@ -134,6 +140,15 @@ $adminBase = '';

X-Forwarded-For

+ +
+ + +
+ +
+
+
diff --git a/admin/kiosks.php b/admin/kiosks.php index 50019af..769ba4c 100644 --- a/admin/kiosks.php +++ b/admin/kiosks.php @@ -128,15 +128,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['renew_token'])) { } } -if (isset($_GET['delete'], $_GET['token'])) { - if ($auth->validateCsrfToken($_GET['token'])) { - $old = $db->fetchOne("SELECT logo_url, background_url FROM kiosks WHERE id = ?", [(int)$_GET['delete']]); +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_kiosk'])) { + if ($auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { + $deleteId = (int)($_POST['kiosk_id'] ?? 0); + $old = $db->fetchOne("SELECT logo_url, background_url FROM kiosks WHERE id = ?", [$deleteId]); if ($old) { Upload::delete((string)($old['logo_url'] ?? '')); Upload::delete((string)($old['background_url'] ?? '')); } - $db->execute("DELETE FROM kiosks WHERE id = ?", [(int)$_GET['delete']]); - $auth->writeAuditLog($_SESSION['user_id'], 'kiosk_deleted', 'kiosk', (int)$_GET['delete'], ''); + $db->execute("DELETE FROM kiosks WHERE id = ?", [$deleteId]); + $auth->writeAuditLog($_SESSION['user_id'], 'kiosk_deleted', 'kiosk', $deleteId, ''); $success = __('kiosks_deleted'); } else { $error = __('error_csrf'); @@ -270,12 +271,9 @@ $adminBase = ''; - - - + (int)$k['id']], $csrf, + '', + 'btn btn-danger-soft btn-sm', __('kiosks_delete_confirm'), __('btn_delete')) ?>
diff --git a/admin/sites.php b/admin/sites.php index 23b0e14..a45d0a9 100644 --- a/admin/sites.php +++ b/admin/sites.php @@ -8,6 +8,7 @@ require_once __DIR__ . '/../includes/Database.php'; require_once __DIR__ . '/../includes/Auth.php'; require_once __DIR__ . '/../includes/UniFiController.php'; require_once __DIR__ . '/../includes/I18n.php'; +require_once __DIR__ . '/../includes/Ui.php'; $auth = new Auth(); $auth->requireAdmin(); @@ -71,9 +72,9 @@ if ($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['add_site'])) { } // Delete site -if (isset($_GET['delete']) && isset($_GET['token'])) { - if ($auth->validateCsrfToken($_GET['token'])) { - $delId = (int)$_GET['delete']; +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_site'])) { + if ($auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { + $delId = (int)($_POST['site_id'] ?? 0); $db->query("DELETE FROM sites WHERE id=?", [$delId]); $auth->writeAuditLog($_SESSION['user_id'],'site_delete','site',$delId,'Site gelöscht'); $success = __('sites_deleted'); @@ -81,11 +82,11 @@ if (isset($_GET['delete']) && isset($_GET['token'])) { } // Toggle site -if (isset($_GET['toggle']) && isset($_GET['token'])) { - if ($auth->validateCsrfToken($_GET['token'])) { - $site = $db->fetchOne("SELECT is_active FROM sites WHERE id=?", [(int)$_GET['toggle']]); +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['toggle_site'])) { + if ($auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { + $site = $db->fetchOne("SELECT is_active FROM sites WHERE id=?", [(int)($_POST['site_id'] ?? 0)]); if ($site) { - $db->query("UPDATE sites SET is_active=? WHERE id=?", [$site['is_active']?0:1,(int)$_GET['toggle']]); + $db->query("UPDATE sites SET is_active=? WHERE id=?", [$site['is_active']?0:1,(int)($_POST['site_id'] ?? 0)]); $success = 'Site-Status aktualisiert!'; } } else { $error = __('error_csrf'); } @@ -160,16 +161,12 @@ $currentPage = 'sites'; class="btn btn-secondary btn-sm"> - - - - - - - + $site['id']], $auth->getCsrfToken(), + ' ' + . htmlspecialchars($site['is_active'] ? __('sites_deactivate') : __('sites_activate'))) ?> + $site['id']], $auth->getCsrfToken(), + '', + 'btn btn-danger-soft btn-sm', __('js_confirm_delete_site'), __('btn_delete')) ?> diff --git a/admin/templates.php b/admin/templates.php index 292675d..9681df1 100644 --- a/admin/templates.php +++ b/admin/templates.php @@ -7,6 +7,7 @@ require_once __DIR__ . '/../config.php'; require_once __DIR__ . '/../includes/Database.php'; require_once __DIR__ . '/../includes/Auth.php'; require_once __DIR__ . '/../includes/I18n.php'; +require_once __DIR__ . '/../includes/Ui.php'; $auth = new Auth(); $auth->requireAdmin(); @@ -79,9 +80,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_template'])) { } // Profil löschen -if (isset($_GET['delete']) && isset($_GET['token'])) { - if ($auth->validateCsrfToken($_GET['token'])) { - $db->execute("DELETE FROM voucher_templates WHERE id = ?", [(int)$_GET['delete']]); +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_template'])) { + if ($auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { + $db->execute("DELETE FROM voucher_templates WHERE id = ?", [(int)($_POST['template_id'] ?? 0)]); $success = __('templates_deleted'); } else { $error = __('error_csrf'); @@ -175,9 +176,9 @@ $adminBase = ''; - + $t['id']], $auth->getCsrfToken(), + '', + 'btn btn-danger-soft btn-small', __('js_confirm_delete_template'), __('btn_delete')) ?> diff --git a/admin/users.php b/admin/users.php index 557bb55..b489447 100644 --- a/admin/users.php +++ b/admin/users.php @@ -8,6 +8,7 @@ require_once __DIR__ . '/../includes/Database.php'; require_once __DIR__ . '/../includes/Auth.php'; require_once __DIR__ . '/../includes/Mailer.php'; require_once __DIR__ . '/../includes/I18n.php'; +require_once __DIR__ . '/../includes/Ui.php'; $auth = new Auth(); $auth->requireAdmin(); @@ -21,9 +22,9 @@ $error = ''; $success = ''; // Send password reset link -if (isset($_GET['send_reset']) && isset($_GET['token'])) { - if ($auth->validateCsrfToken($_GET['token'])) { - $targetUser = $db->fetchOne("SELECT * FROM users WHERE id=? AND is_active=1 AND password_hash IS NOT NULL", [(int)$_GET['send_reset']]); +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['send_reset'])) { + if ($auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { + $targetUser = $db->fetchOne("SELECT * FROM users WHERE id=? AND is_active=1 AND password_hash IS NOT NULL", [(int)($_POST['user_id'] ?? 0)]); if ($targetUser) { try { $db->execute("DELETE FROM password_reset_tokens WHERE user_id=?", [$targetUser['id']]); @@ -118,11 +119,11 @@ if ($_SERVER['REQUEST_METHOD']==='POST' && isset($_POST['add_user'])) { } // Delete user -if (isset($_GET['delete']) && isset($_GET['token'])) { - if ($auth->validateCsrfToken($_GET['token'])) { - $deleteId = (int)$_GET['delete']; +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_user'])) { + if ($auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { + $deleteId = (int)($_POST['user_id'] ?? 0); if ($deleteId === (int)$_SESSION['user_id']) { - $error = 'Sie können sich nicht selbst löschen'; + $error = __('users_self_delete'); } else { $db->query("DELETE FROM users WHERE id=?", [$deleteId]); $auth->writeAuditLog($_SESSION['user_id'], 'user_delete', 'user', $deleteId, 'Benutzer gelöscht'); @@ -132,27 +133,27 @@ if (isset($_GET['delete']) && isset($_GET['token'])) { } // Toggle user active -if (isset($_GET['toggle']) && isset($_GET['token'])) { - if ($auth->validateCsrfToken($_GET['token'])) { - $toggleId = (int)$_GET['toggle']; +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['toggle_user'])) { + if ($auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { + $toggleId = (int)($_POST['user_id'] ?? 0); if ($toggleId === (int)$_SESSION['user_id']) { - $error = 'Sie können sich nicht selbst deaktivieren'; + $error = __('users_self_disable'); } else { $user = $db->fetchOne("SELECT is_active FROM users WHERE id=?", [$toggleId]); if ($user) { $newStatus = $user['is_active'] ? 0 : 1; $db->query("UPDATE users SET is_active=? WHERE id=?", [$newStatus, $toggleId]); - $success = 'Benutzer-Status aktualisiert!'; + $success = __('users_status_updated'); } } } else { $error = __('error_csrf'); } } // 2FA eines Benutzers zurücksetzen (Admin-Hilfe bei verlorenem Authenticator) -if (isset($_GET['reset_2fa']) && isset($_GET['token'])) { - if ($auth->validateCsrfToken($_GET['token'])) { - $auth->disableTotp((int)$_GET['reset_2fa']); - $success = '2FA des Benutzers wurde zurückgesetzt.'; +if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['reset_2fa'])) { + if ($auth->validateCsrfToken($_POST['csrf_token'] ?? '')) { + $auth->disableTotp((int)($_POST['user_id'] ?? 0)); + $success = __('users_2fa_reset'); } else { $error = __('error_csrf'); } } @@ -256,29 +257,27 @@ $currentPage = 'users'; - - - + $user['id']], $auth->getCsrfToken(), + '', + 'btn btn-secondary btn-sm', '', + $user['is_active'] ? __('sites_deactivate') : __('sites_activate')) ?> - - - + $user['id']], $auth->getCsrfToken(), + '', + 'btn btn-warning btn-sm', + str_replace('{email}', $user['email'], __('users_reset_confirm')), + __('users_reset_pw')) ?> - - - + $user['id']], $auth->getCsrfToken(), + '', + 'btn btn-secondary btn-sm', + str_replace('{email}', $user['email'], __('users_2fa_confirm')), + __('users_2fa_reset_title')) ?> - - - + $user['id']], $auth->getCsrfToken(), + '', + 'btn btn-danger-soft btn-sm', __('js_confirm_delete_user'), __('btn_delete')) ?> diff --git a/docs/Caddyfile.example b/docs/Caddyfile.example new file mode 100644 index 0000000..cef9cf8 --- /dev/null +++ b/docs/Caddyfile.example @@ -0,0 +1,47 @@ +# Beispiel-Konfiguration für Caddy 2. +# +# Wichtig: Caddy liest **keine** .htaccess-Dateien. Die Regeln aus der +# mitgelieferten .htaccess (Sicherheits-Header, Sperre für interne Ordner, +# keine PHP-Ausführung in uploads/) müssen hier stehen, sonst greifen sie nicht. + +wlan.example.com { + root * /var/www/unifi-voucher-tool + encode zstd gzip + + # --- Sicherheits-Header ------------------------------------------------- + header { + X-Content-Type-Options "nosniff" + X-Frame-Options "SAMEORIGIN" + Referrer-Policy "strict-origin-when-cross-origin" + Permissions-Policy "geolocation=(), microphone=(), camera=()" + # Alle Assets liegen lokal; externe Quellen nur für hCaptcha, + # falls es in den Einstellungen aktiviert wurde. + Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' https://js.hcaptcha.com https://*.hcaptcha.com; style-src 'self' 'unsafe-inline' https://*.hcaptcha.com; img-src 'self' data: https:; font-src 'self'; connect-src 'self' https://*.hcaptcha.com; frame-src https://*.hcaptcha.com; frame-ancestors 'self'; base-uri 'self'; form-action 'self'" + -Server + } + + # --- Interne Ordner und Dateien nicht ausliefern ------------------------- + @intern path /includes/* /tools/* /tests/* /updater/storage/* /updater/migrations/* /.git/* + respond @intern 404 + + @geheim path /config.php /database.sql /composer.json /composer.lock /phpunit.xml.dist /phpstan.neon /VERSION + respond @geheim 404 + + # --- Hochgeladene Dateien niemals als Programm ausführen ----------------- + # Ohne diese Regel würde eine als Bild getarnte PHP-Datei ausgeführt. + @uploads_php path_regexp ^/uploads/.*\.(php|phtml|phar)$ + respond @uploads_php 403 + + # --- PHP ---------------------------------------------------------------- + php_fastcgi unix//run/php/php8.3-fpm.sock { + # Nur echte PHP-Dateien an FPM geben + split .php + } + + file_server + + log { + output file /var/log/caddy/unifi-voucher-tool.log + format json + } +} diff --git a/docs/screenshots/admin-dashboard-dark.png b/docs/screenshots/admin-dashboard-dark.png index bddf25e..a6d5491 100644 Binary files a/docs/screenshots/admin-dashboard-dark.png and b/docs/screenshots/admin-dashboard-dark.png differ diff --git a/docs/screenshots/admin-dashboard.png b/docs/screenshots/admin-dashboard.png index d2d2073..82d09b8 100644 Binary files a/docs/screenshots/admin-dashboard.png and b/docs/screenshots/admin-dashboard.png differ diff --git a/docs/screenshots/api-keys.png b/docs/screenshots/api-keys.png index e625ae6..2603b9e 100644 Binary files a/docs/screenshots/api-keys.png and b/docs/screenshots/api-keys.png differ diff --git a/docs/screenshots/integrations.png b/docs/screenshots/integrations.png index 060706d..688aec1 100644 Binary files a/docs/screenshots/integrations.png and b/docs/screenshots/integrations.png differ diff --git a/docs/screenshots/kiosks-admin.png b/docs/screenshots/kiosks-admin.png index 7cbb1f4..f36783c 100644 Binary files a/docs/screenshots/kiosks-admin.png and b/docs/screenshots/kiosks-admin.png differ diff --git a/docs/screenshots/kiosks-form.png b/docs/screenshots/kiosks-form.png index 4654091..6ce7a0d 100644 Binary files a/docs/screenshots/kiosks-form.png and b/docs/screenshots/kiosks-form.png differ diff --git a/docs/screenshots/settings-branding.png b/docs/screenshots/settings-branding.png index c27f6d2..faa7bca 100644 Binary files a/docs/screenshots/settings-branding.png and b/docs/screenshots/settings-branding.png differ diff --git a/docs/screenshots/settings-login.png b/docs/screenshots/settings-login.png index 2004b02..6ed55e6 100644 Binary files a/docs/screenshots/settings-login.png and b/docs/screenshots/settings-login.png differ diff --git a/docs/screenshots/settings.png b/docs/screenshots/settings.png index 4a468cf..853ec54 100644 Binary files a/docs/screenshots/settings.png and b/docs/screenshots/settings.png differ diff --git a/docs/screenshots/two-factor.png b/docs/screenshots/two-factor.png index d743781..de4b1cb 100644 Binary files a/docs/screenshots/two-factor.png and b/docs/screenshots/two-factor.png differ diff --git a/docs/screenshots/vouchers.png b/docs/screenshots/vouchers.png index e878ec8..9bd5852 100644 Binary files a/docs/screenshots/vouchers.png and b/docs/screenshots/vouchers.png differ diff --git a/includes/Database.php b/includes/Database.php index 00ab48d..e8f22cb 100644 --- a/includes/Database.php +++ b/includes/Database.php @@ -1,79 +1,119 @@ -pdo = new PDO( - "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4", - DB_USER, - DB_PASS, - [ - PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, - PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, - PDO::ATTR_EMULATE_PREPARES => false - ] - ); - } catch (PDOException $e) { - die("Datenbankverbindung fehlgeschlagen: " . $e->getMessage()); - } - } - - public static function getInstance() { - if (self::$instance === null) { - self::$instance = new self(); - } - return self::$instance; - } - - public function getConnection() { - return $this->pdo; - } - - // Helper-Methode für Queries - public function query($sql, $params = []) { - $stmt = $this->pdo->prepare($sql); - $stmt->execute($params); - return $stmt; - } - - // Helper für einzelnen Datensatz - public function fetchOne($sql, $params = []) { - $stmt = $this->query($sql, $params); - return $stmt->fetch(); - } - - // Helper für mehrere Datensätze - public function fetchAll($sql, $params = []) { - $stmt = $this->query($sql, $params); - return $stmt->fetchAll(); - } - - // Helper für Insert/Update mit Rückgabe der ID - public function execute($sql, $params = []) { - $this->query($sql, $params); - return $this->pdo->lastInsertId(); - } - - // Settings-Helper - public function getSetting($key, $default = null) { - if (array_key_exists($key, $this->settingsCache)) { - return $this->settingsCache[$key] ?? $default; - } - $result = $this->fetchOne("SELECT setting_value FROM settings WHERE setting_key = ?", [$key]); - $value = $result ? $result['setting_value'] : null; - $this->settingsCache[$key] = $value; - return $value ?? $default; - } - - public function setSetting($key, $value) { - $this->query( - "INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) - ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)", - [$key, $value] - ); - $this->settingsCache[$key] = $value; - } +pdo = new PDO( + "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=utf8mb4", + DB_USER, + DB_PASS, + [ + PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + PDO::ATTR_EMULATE_PREPARES => false + ] + ); + } catch (PDOException $e) { + // Details nur ins Log: die Meldung enthaelt Host, Datenbankname + // und je nach Treiber weitere Interna. + error_log('Datenbankverbindung fehlgeschlagen: ' . $e->getMessage()); + throw new RuntimeException('database_unavailable', 0, $e); + } + } + + public static function getInstance() { + if (self::$instance === null) { + try { + self::$instance = new self(); + } catch (RuntimeException $e) { + // Auf der Kommandozeile (Cron, Tests) weiterreichen, im Web + // eine verstaendliche Seite zeigen statt einer weissen Seite. + if (PHP_SAPI === 'cli') { + throw $e; + } + self::renderUnavailable(); + } + } + return self::$instance; + } + + /** + * Schlichte Fehlerseite ohne Abhaengigkeiten – zum Zeitpunkt des Aufrufs + * steht weder Datenbank noch Spracheinstellung zur Verfuegung. + */ + private static function renderUnavailable(): void { + if (!headers_sent()) { + http_response_code(503); + header('Retry-After: 30'); + header('Content-Type: text/html; charset=utf-8'); + } + + echo '' + . '' + . 'Dienst vorübergehend nicht verfügbar
' + . '

Dienst vorübergehend nicht verfügbar

' + . '

Die Datenbank ist gerade nicht erreichbar. Bitte in einem Moment erneut versuchen – ' + . 'Details stehen im Server-Log.

' + . '
'; + exit; + } + + public function getConnection() { + return $this->pdo; + } + + // Helper-Methode für Queries + public function query($sql, $params = []) { + $stmt = $this->pdo->prepare($sql); + $stmt->execute($params); + return $stmt; + } + + // Helper für einzelnen Datensatz + public function fetchOne($sql, $params = []) { + $stmt = $this->query($sql, $params); + return $stmt->fetch(); + } + + // Helper für mehrere Datensätze + public function fetchAll($sql, $params = []) { + $stmt = $this->query($sql, $params); + return $stmt->fetchAll(); + } + + // Helper für Insert/Update mit Rückgabe der ID + public function execute($sql, $params = []) { + $this->query($sql, $params); + return $this->pdo->lastInsertId(); + } + + // Settings-Helper + public function getSetting($key, $default = null) { + if (array_key_exists($key, $this->settingsCache)) { + return $this->settingsCache[$key] ?? $default; + } + $result = $this->fetchOne("SELECT setting_value FROM settings WHERE setting_key = ?", [$key]); + $value = $result ? $result['setting_value'] : null; + $this->settingsCache[$key] = $value; + return $value ?? $default; + } + + public function setSetting($key, $value) { + $this->query( + "INSERT INTO settings (setting_key, setting_value) VALUES (?, ?) + ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value)", + [$key, $value] + ); + $this->settingsCache[$key] = $value; + } } \ No newline at end of file diff --git a/includes/Ui.php b/includes/Ui.php index b7faa7a..0c0d5b4 100644 --- a/includes/Ui.php +++ b/includes/Ui.php @@ -116,6 +116,44 @@ class Ui . ''; } + /** + * Kleines Formular für eine verändernde Aktion. + * + * Löschen und Umschalten liefen früher über Links mit CSRF-Token in der + * URL – das landet in Server-Logs, Referer-Headern und der Chronik. + * Deshalb POST, auch wenn es im Markup etwas mehr ist. + * + * @param string $action Name des Submit-Feldes (z. B. 'delete_site') + * @param array $fields weitere versteckte Felder, z. B. ['site_id' => 4] + * @param string $inner Inhalt des Knopfes (HTML) + */ + public static function actionForm( + string $action, + array $fields, + string $csrf, + string $inner, + string $class = 'btn btn-secondary btn-sm', + string $confirm = '', + string $title = '' + ): string { + $esc = static fn ($text) => htmlspecialchars((string)$text, ENT_QUOTES); + + $hidden = ''; + foreach ($fields as $name => $value) { + $hidden .= ''; + } + + $attr = ''; + if ($confirm !== '') { + $attr = ' onsubmit="return confirm(\'' . str_replace("'", "\\'", $confirm) . '\');"'; + } + $titleAttr = $title !== '' ? ' title="' . $esc($title) . '" aria-label="' . $esc($title) . '"' : ''; + + return '
' . $hidden + . '
'; + } + /** * Bildfeld mit Vorschau, Upload und URL-Eingabe. * Wird von den Einstellungen und der Kiosk-Verwaltung genutzt. diff --git a/install.php b/install.php index 679f6f1..b8db310 100644 --- a/install.php +++ b/install.php @@ -161,7 +161,7 @@ if ($step === 5 && $_SERVER['REQUEST_METHOD'] === 'POST') { // .htaccess erstellen (ohne Rewrite Rules die Probleme machen) $htaccess = "# UniFi Voucher System\n\n"; $htaccess .= "# Security\n"; - $htaccess .= "\n"; + $htaccess .= "\n"; $htaccess .= " Order Allow,Deny\n"; $htaccess .= " Deny from all\n"; $htaccess .= "\n\n"; diff --git a/lang/de.php b/lang/de.php index 7b07a87..2e696ed 100644 --- a/lang/de.php +++ b/lang/de.php @@ -393,7 +393,7 @@ return [ 'backup_opt_sites' => 'Sites', 'backup_opt_templates' => 'Voucher-Profile', 'backup_import_confirm' => 'Import jetzt durchführen?', - 'backup_imported' => 'Import abgeschlossen: {settings} Einstellungen, {sites} Sites, {templates} Profile.', + 'backup_imported' => 'Import abgeschlossen: {settings} Einstellungen, {sites} Sites, {templates} Profile, {kiosks} Display-Seiten.', 'rep_title' => 'Reporting', 'rep_subtitle' => 'Auswertungen nach Zeitraum, Site und Benutzer.', 'rep_period' => 'Zeitraum', @@ -537,6 +537,16 @@ return [ 'kiosks_card_light' => 'Hell', 'kiosks_card_dark' => 'Dunkel', 'kiosks_card_hint' => 'Auf Fotos wirkt die dunkle Karte meist ruhiger.', + 'backup_opt_kiosks' => 'Display-Seiten', + 'users_self_delete' => 'Sie können sich nicht selbst löschen.', + 'users_self_disable' => 'Sie können sich nicht selbst deaktivieren.', + 'users_status_updated' => 'Benutzer-Status aktualisiert.', + 'users_2fa_reset' => '2FA des Benutzers wurde zurückgesetzt.', + 'users_reset_confirm' => 'Passwort-Reset-Link senden an {email}?', + 'users_2fa_confirm' => '2FA für {email} zurücksetzen?', + 'users_2fa_reset_title' => '2FA zurücksetzen', + 'int_proxy_warning' => 'Diese Anfrage kam über einen Proxy, es ist aber kein vertrauenswürdiger Proxy eingetragen. Rate-Limits und Audit-Log sehen dadurch für alle Gäste dieselbe IP-Adresse ({ip}).', + 'int_proxy_suggestion' => 'Vorschlag anhand dieser Anfrage:', 'settings_tab_general' => 'Allgemein', 'settings_tab_defaults' => 'Voucher-Standards', 'settings_tab_cron' => 'Cron-Sync', diff --git a/lang/en.php b/lang/en.php index b3bf315..9ccc759 100644 --- a/lang/en.php +++ b/lang/en.php @@ -393,7 +393,7 @@ return [ 'backup_opt_sites' => 'Sites', 'backup_opt_templates' => 'Voucher profiles', 'backup_import_confirm' => 'Run the import now?', - 'backup_imported' => 'Import finished: {settings} settings, {sites} sites, {templates} profiles.', + 'backup_imported' => 'Import finished: {settings} settings, {sites} sites, {templates} profiles, {kiosks} display pages.', 'rep_title' => 'Reporting', 'rep_subtitle' => 'Analytics by period, site and user.', 'rep_period' => 'Period', @@ -537,6 +537,16 @@ return [ 'kiosks_card_light' => 'Light', 'kiosks_card_dark' => 'Dark', 'kiosks_card_hint' => 'On photos the dark card usually looks calmer.', + 'backup_opt_kiosks' => 'Display pages', + 'users_self_delete' => 'You cannot delete your own account.', + 'users_self_disable' => 'You cannot deactivate your own account.', + 'users_status_updated' => 'User status updated.', + 'users_2fa_reset' => 'Two-factor authentication has been reset for this user.', + 'users_reset_confirm' => 'Send a password reset link to {email}?', + 'users_2fa_confirm' => 'Reset two-factor authentication for {email}?', + 'users_2fa_reset_title' => 'Reset two-factor authentication', + 'int_proxy_warning' => 'This request arrived through a proxy, but no trusted proxy is configured. Rate limits and the audit log therefore see the same IP address for every guest ({ip}).', + 'int_proxy_suggestion' => 'Suggestion based on this request:', 'settings_tab_general' => 'General', 'settings_tab_defaults' => 'Voucher Defaults', 'settings_tab_cron' => 'Cron Sync', diff --git a/login_simple.php b/login_simple.php deleted file mode 100644 index 449d11e..0000000 --- a/login_simple.php +++ /dev/null @@ -1,186 +0,0 @@ -getMessage(); -} - -try { - if (!file_exists(__DIR__ . '/includes/Database.php')) { - throw new Exception('includes/Database.php nicht gefunden'); - } - require_once __DIR__ . '/includes/Database.php'; -} catch (Exception $e) { - $loadErrors[] = "Database: " . $e->getMessage(); -} - -try { - if (!file_exists(__DIR__ . '/includes/Auth.php')) { - throw new Exception('includes/Auth.php nicht gefunden'); - } - require_once __DIR__ . '/includes/Auth.php'; -require_once __DIR__ . '/includes/Ui.php'; -} catch (Exception $e) { - $loadErrors[] = "Auth: " . $e->getMessage(); -} - -// Wenn Ladefehler aufgetreten sind, zeige sie an -if (!empty($loadErrors)) { - die('

Fehler beim Laden der Dateien

'); -} - -// Ab hier normal weiter -try { - $auth = new Auth(); -} catch (Exception $e) { - die('

Fehler bei Auth-Initialisierung

' . $e->getMessage() . '

'); -} - -// Wenn bereits eingeloggt, weiterleiten -if ($auth->isLoggedIn()) { - header('Location: index.php'); - exit; -} - -$error = ''; -$success = ''; - -// Login-Verarbeitung -if ($_SERVER['REQUEST_METHOD'] === 'POST') { - try { - $email = $_POST['email'] ?? ''; - $password = $_POST['password'] ?? ''; - - if (empty($email) || empty($password)) { - $error = 'Bitte E-Mail und Passwort eingeben'; - } elseif ($auth->login($email, $password)) { - header('Location: index.php'); - exit; - } else { - $error = 'Ungültige E-Mail oder Passwort'; - } - } catch (Exception $e) { - $error = 'Login-Fehler: ' . $e->getMessage(); - } -} - -try { - $db = Database::getInstance(); - $appTitle = $db->getSetting('app_title', 'UniFi Voucher System'); - $logoUrl = $db->getSetting('logo_url', ''); - $m365Enabled = !empty($db->getSetting('m365_client_id')) && - !empty($db->getSetting('m365_client_secret')) && - !empty($db->getSetting('m365_tenant_id')); - $publicAccess = $db->getSetting('public_access', 0); - - // M365 OAuth URL generieren falls aktiviert - $m365LoginUrl = ''; - if ($m365Enabled) { - $clientId = $db->getSetting('m365_client_id'); - $tenantId = $db->getSetting('m365_tenant_id'); - - // Dynamische Redirect URI basierend auf aktuellem Pfad - $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; - $host = $_SERVER['HTTP_HOST']; - $scriptPath = dirname($_SERVER['SCRIPT_NAME']); - $scriptPath = $scriptPath === '/' ? '' : $scriptPath; - $redirectUri = $protocol . '://' . $host . $scriptPath . '/m365_callback.php'; - - $params = [ - 'client_id' => $clientId, - 'response_type' => 'code', - 'redirect_uri' => $redirectUri, - 'response_mode' => 'query', - 'scope' => 'openid profile email User.Read', - 'state' => bin2hex(random_bytes(16)) - ]; - - $_SESSION['m365_state'] = $params['state']; - - $m365LoginUrl = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/authorize?" . http_build_query($params); - } -} catch (Exception $e) { - die('

Datenbankfehler

' . $e->getMessage() . '

'); -} -?> - - - - - - Login - <?= htmlspecialchars($appTitle) ?> - - - - -
- - - -

- - -

Melden Sie sich an, um fortzufahren

- - -
- - - -
- - -
-
- - -
- -
- - -
- - -
- - -
oder
- - Mit Microsoft 365 anmelden - - - - - - - - -
- System-Status:
- PHP Version:
- Session Status:
- Eingeloggt: isLoggedIn() ? 'Ja' : 'Nein' ?> -
-
- - \ No newline at end of file diff --git a/m365_debug.php b/m365_debug.php deleted file mode 100644 index 0327561..0000000 --- a/m365_debug.php +++ /dev/null @@ -1,74 +0,0 @@ -requireAdmin(); - -$db = Database::getInstance(); - -// M365 Einstellungen abrufen -$clientId = $db->getSetting('m365_client_id', ''); -$clientSecret = $db->getSetting('m365_client_secret', ''); -$tenantId = $db->getSetting('m365_tenant_id', ''); - -// Dynamische URLs -$protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; -$host = $_SERVER['HTTP_HOST']; -$scriptPath = dirname($_SERVER['SCRIPT_NAME']); -$scriptPath = $scriptPath === '/' ? '' : $scriptPath; -$redirectUri = $protocol . '://' . $host . $scriptPath . '/m365_callback.php'; - -?> - - - - - - M365 Debug - - - - - -

🔍 Microsoft 365 OAuth Debug

- -
-

1. Konfiguration Status

-

Client ID: ✓ Gesetzt' : '✗ Fehlt' ?>

-

Client Secret: ✓ Gesetzt' : '✗ Fehlt' ?>

-

Tenant ID: ✓ Gesetzt' : '✗ Fehlt' ?>

-
- -
-

2. Redirect URI

-

Diese URI muss exakt in der Azure-App-Registrierung hinterlegt sein:

-
-
- -
-

3. Hinweise

- -
- - \ No newline at end of file