Härtung: Backup vollständig, Caddy-Konfiguration, POST statt GET
All checks were successful
CI / PHP Lint (pull_request) Successful in 35s
CI / PHP Lint-1 (pull_request) Successful in 34s
CI / Unit Tests & Static Analysis (pull_request) Successful in 38s
CI / PHP Lint (push) Successful in 34s
CI / PHP Lint-1 (push) Successful in 32s
CI / Unit Tests & Static Analysis (push) Successful in 36s

Backup (das war eine echte Lücke): admin/backup.php sicherte nur
Einstellungen, Sites und Profile – die Display-Seiten fehlten. Nach einem
Restore wären alle Kiosk-Links weg gewesen und aufgehängte QR-Codes hätten
ins Leere gezeigt. Sie werden jetzt mitgesichert, inklusive Token, damit
vorhandene Aufkleber weiter funktionieren; Site und Profil werden über den
Namen verknüpft, weil die IDs auf der Zielinstallation andere sind.

Caddy: die mitgelieferte .htaccess wird von Caddy nicht gelesen – damit
griffen weder die Sicherheits-Header noch die Sperre, die PHP unterhalb
von uploads/ verbietet. docs/Caddyfile.example enthält beides, die README
verweist darauf.

Verändernde Aktionen laufen jetzt über POST statt über Links mit
CSRF-Token in der URL (Sites, Benutzer, Profile, API-Schlüssel, Display-
Seiten). Token in URLs landen in Server-Logs, Referer-Headern und der
Browser-Chronik. Neuer Helfer Ui::actionForm() hält das Markup kurz.

Entfernt: login_simple.php und m365_debug.php. login_simple.php war eine
zweite Login-Implementierung, die den Rückgabewert von Auth::login() als
Boolean behandelte – 'totp_required' und 'rate_limited' sind truthy, also
wurde auf index.php weitergeleitet, ohne dass eine Sitzung bestand. Kein
Bypass (setUserSession lief nicht), aber genau die Art Altlast, aus der
später einer wird.

Database::getInstance() bricht nicht mehr mit die() samt PDO-Meldung ab
(die Host und Datenbanknamen enthält), sondern zeigt im Web eine
schlichte 503-Seite und wirft auf der Kommandozeile weiter.

Neu: Warnung im Tab "Integration & Wartung", wenn eine Anfrage über einen
Proxy kam, aber kein vertrauenswürdiger Proxy eingetragen ist – dann
sehen Rate-Limit und Audit-Log für alle Gäste dieselbe IP.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
Friederich Loheide 2026-09-24 11:09:28 +00:00
parent 3a09e35097
commit f26684b128
27 changed files with 381 additions and 423 deletions

View file

@ -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 = '';
<td class="muted" data-label="<?= __('api_col_last_used') ?>"><?= $k['last_used_at'] ? date('d.m.Y H:i', strtotime($k['last_used_at'])) : '–' ?></td>
<td class="muted" data-label="<?= __('api_col_created_by') ?>"><?= htmlspecialchars($k['creator'] ?? '–') ?></td>
<td style="text-align:right;white-space:nowrap;">
<a class="a-link" href="?toggle=<?= (int)$k['id'] ?>&token=<?= urlencode($csrf) ?>"><?= $k['is_active'] ? __('api_action_block') : __('api_action_unblock') ?></a>
<a class="a-link" style="color:var(--danger);" href="?delete=<?= (int)$k['id'] ?>&token=<?= urlencode($csrf) ?>" onclick="return confirm('<?= __('api_delete_confirm') ?>');"><?= __('btn_delete') ?></a>
<?= Ui::actionForm('toggle_key', ['key_id' => (int)$k['id']], $csrf,
htmlspecialchars($k['is_active'] ? __('api_action_block') : __('api_action_unblock')),
'btn btn-secondary btn-sm') ?>
<?= Ui::actionForm('delete_key', ['key_id' => (int)$k['id']], $csrf,
htmlspecialchars(__('btn_delete')),
'btn btn-danger-soft btn-sm', __('api_delete_confirm')) ?>
</td>
</tr>
<?php endforeach; ?>

View file

@ -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 = '';
<label class="chk"><input type="checkbox" name="import_settings" checked> <?= __('backup_opt_settings') ?></label>
<label class="chk"><input type="checkbox" name="import_sites" checked> <?= __('backup_opt_sites') ?></label>
<label class="chk"><input type="checkbox" name="import_templates" checked> <?= __('backup_opt_templates') ?></label>
<label class="chk"><input type="checkbox" name="import_kiosks" checked> <?= __('backup_opt_kiosks') ?></label>
<button class="btn btn-primary" type="submit" name="import" style="margin-top:12px;" onclick="return confirm('<?= __('backup_import_confirm') ?>');"><?= __('import_submit') ?></button>
</form>
</div>

View file

@ -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 = '';
<h2><?= __('int_proxy') ?></h2>
<p class="muted"><?= __('int_proxy_hint') ?> <code>X-Forwarded-For</code> <?= __('int_proxy_hint2') ?></p>
<input class="input" type="text" name="trusted_proxy" value="<?= htmlspecialchars($trustedProxy) ?>" placeholder="z.B. 10.0.0.1, 172.18.0.1">
<?php if ($proxyWarning): ?>
<div class="alert alert-warning" style="margin-top:12px;">
<i class="fas fa-triangle-exclamation" aria-hidden="true"></i>
<span>
<?= str_replace('{ip}', htmlspecialchars($remoteAddr), __('int_proxy_warning')) ?><br>
<?= __('int_proxy_suggestion') ?> <code><?= htmlspecialchars($remoteAddr) ?></code>
</span>
</div>
<?php endif; ?>
</div>
<div class="card">

View file

@ -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 = '';
<i class="fas fa-rotate" aria-hidden="true"></i> <?= __('kiosks_renew') ?>
</button>
</form>
<a class="btn btn-danger-soft btn-sm"
href="?delete=<?= (int)$k['id'] ?>&token=<?= urlencode($csrf) ?>"
onclick="return confirm('<?= __('kiosks_delete_confirm') ?>');"
title="<?= __('btn_delete') ?>" aria-label="<?= __('btn_delete') ?>">
<i class="fas fa-trash" aria-hidden="true"></i>
</a>
<?= Ui::actionForm('delete_kiosk', ['kiosk_id' => (int)$k['id']], $csrf,
'<i class="fas fa-trash" aria-hidden="true"></i>',
'btn btn-danger-soft btn-sm', __('kiosks_delete_confirm'), __('btn_delete')) ?>
</div>
</div>
<?php endforeach; ?>

View file

@ -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">
<i class="fas fa-edit" aria-hidden="true"></i> <?= __('btn_edit') ?>
</button>
<a href="?toggle=<?= $site['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
class="btn btn-secondary btn-sm">
<i class="fas fa-<?= $site['is_active'] ? 'pause' : 'play' ?>" aria-hidden="true"></i>
<?= $site['is_active'] ? __('sites_deactivate') : __('sites_activate') ?>
</a>
<a href="?delete=<?= $site['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
class="btn btn-danger-soft btn-sm"
onclick="return confirm('<?= __('js_confirm_delete_site') ?>')">
<i class="fas fa-trash" aria-hidden="true"></i>
</a>
<?= Ui::actionForm('toggle_site', ['site_id' => $site['id']], $auth->getCsrfToken(),
'<i class="fas fa-' . ($site['is_active'] ? 'pause' : 'play') . '" aria-hidden="true"></i> '
. htmlspecialchars($site['is_active'] ? __('sites_deactivate') : __('sites_activate'))) ?>
<?= Ui::actionForm('delete_site', ['site_id' => $site['id']], $auth->getCsrfToken(),
'<i class="fas fa-trash" aria-hidden="true"></i>',
'btn btn-danger-soft btn-sm', __('js_confirm_delete_site'), __('btn_delete')) ?>
</div>
</div>
<?php endforeach; ?>

View file

@ -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 = '';
<td data-label="<?= __('label_actions') ?>">
<button onclick="openEditModal(<?= $t['id'] ?>, '<?= htmlspecialchars($t['name'], ENT_QUOTES) ?>', <?= (int)$t['max_uses'] ?>, <?= (int)$t['expire_minutes'] ?>, '<?= htmlspecialchars($t['description'] ?? '', ENT_QUOTES) ?>', <?= (int)$t['is_active'] ?>, <?= (int)($t['qos_rate_max_down'] ?? 0) ?>, <?= (int)($t['qos_rate_max_up'] ?? 0) ?>, <?= (int)($t['qos_usage_quota'] ?? 0) ?>)"
class="btn btn-secondary btn-small"><i class="fas fa-edit" aria-hidden="true"></i></button>
<a href="?delete=<?= $t['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
onclick="return confirm('<?= __('js_confirm_delete_template') ?>')"
class="btn btn-danger-soft btn-small"><i class="fas fa-trash" aria-hidden="true"></i></a>
<?= Ui::actionForm('delete_template', ['template_id' => $t['id']], $auth->getCsrfToken(),
'<i class="fas fa-trash" aria-hidden="true"></i>',
'btn btn-danger-soft btn-small', __('js_confirm_delete_template'), __('btn_delete')) ?>
</td>
</tr>
<?php endforeach; ?>

View file

@ -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';
<i class="fas fa-edit" aria-hidden="true"></i>
</button>
<?php if ($user['id'] != $_SESSION['user_id']): ?>
<a href="?toggle=<?= $user['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
class="btn btn-secondary btn-sm" title="<?= $user['is_active'] ? __('sites_deactivate') : __('sites_activate') ?>">
<i class="fas fa-<?= $user['is_active'] ? 'pause' : 'play' ?>" aria-hidden="true"></i>
</a>
<?= Ui::actionForm('toggle_user', ['user_id' => $user['id']], $auth->getCsrfToken(),
'<i class="fas fa-' . ($user['is_active'] ? 'pause' : 'play') . '" aria-hidden="true"></i>',
'btn btn-secondary btn-sm', '',
$user['is_active'] ? __('sites_deactivate') : __('sites_activate')) ?>
<?php if ($smtpEnabled && !empty($user['password_hash'])): ?>
<a href="?send_reset=<?= $user['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
class="btn btn-warning btn-sm" title="<?= __('users_reset_pw') ?>"
onclick="return confirm('Passwort-Reset-Link senden an <?= htmlspecialchars($user['email'], ENT_QUOTES) ?>?')">
<i class="fas fa-key" aria-hidden="true"></i>
</a>
<?= Ui::actionForm('send_reset', ['user_id' => $user['id']], $auth->getCsrfToken(),
'<i class="fas fa-key" aria-hidden="true"></i>',
'btn btn-warning btn-sm',
str_replace('{email}', $user['email'], __('users_reset_confirm')),
__('users_reset_pw')) ?>
<?php endif; ?>
<?php if (!empty($user['totp_enabled'])): ?>
<a href="?reset_2fa=<?= $user['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
class="btn btn-secondary btn-sm" title="2FA zurücksetzen"
onclick="return confirm('2FA für <?= htmlspecialchars($user['email'], ENT_QUOTES) ?> zurücksetzen?')">
<i class="fas fa-user-shield" aria-hidden="true"></i>
</a>
<?= Ui::actionForm('reset_2fa', ['user_id' => $user['id']], $auth->getCsrfToken(),
'<i class="fas fa-user-shield" aria-hidden="true"></i>',
'btn btn-secondary btn-sm',
str_replace('{email}', $user['email'], __('users_2fa_confirm')),
__('users_2fa_reset_title')) ?>
<?php endif; ?>
<a href="?delete=<?= $user['id'] ?>&token=<?= $auth->getCsrfToken() ?>"
class="btn btn-danger-soft btn-sm" title="<?= __('btn_delete') ?>"
onclick="return confirm('<?= __('js_confirm_delete_user') ?>')">
<i class="fas fa-trash" aria-hidden="true"></i>
</a>
<?= Ui::actionForm('delete_user', ['user_id' => $user['id']], $auth->getCsrfToken(),
'<i class="fas fa-trash" aria-hidden="true"></i>',
'btn btn-danger-soft btn-sm', __('js_confirm_delete_user'), __('btn_delete')) ?>
<?php endif; ?>
</div>
</td>