Version 1.6 - Strato Verzeichnis unterhalb tc-ingelfingen

This commit is contained in:
Erik Thiele
2026-05-23 23:32:00 +02:00
parent 54ae12771e
commit 7c5790e856
6 changed files with 69 additions and 32 deletions

View File

@@ -115,6 +115,26 @@ function appUrl(): string
return $scheme . '://' . $host;
}
function basePath(): string
{
$scriptName = $_SERVER['SCRIPT_NAME'] ?? '/index.php';
$dir = rtrim(str_replace('\\', '/', dirname($scriptName)), '/');
return $dir === '' ? '' : $dir;
}
function appPath(string $path = ''): string
{
$base = basePath();
if ($path === '') {
return $base === '' ? '/' : $base . '/';
}
if ($path[0] === '?') {
return ($base === '' ? '/' : $base . '/') . $path;
}
$path = ltrim($path, '/');
return $base === '' ? '/' . $path : $base . '/' . $path;
}
function sendPasswordResetMail(array $smtpConfig, string $toEmail, string $resetUrl): bool
{
if (($smtpConfig['from_email'] ?? '') === '') {
@@ -497,7 +517,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
addAuditLog($pdo, (int)$found['id'], 'Anmeldung erfolgreich.');
session_regenerate_id(true);
$_SESSION['user'] = ['id' => (int)$found['id'], 'firstname' => $found['firstname'] ?? '', 'lastname' => $found['lastname'] ?? '', 'name' => displayName($found), 'email' => $found['email'], 'role' => $found['role']];
header('Location: /?page=dashboard');
header('Location: ' . appPath('?page=home'));
exit;
}
$error = 'Login fehlgeschlagen.';
@@ -557,7 +577,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$stmt->execute([(int)$resetRow['user_id']]);
addAuditLog($pdo, (int)$resetRow['user_id'], 'Passwort über Reset-Link neu gesetzt.');
$_SESSION['login_notice'] = 'Passwort erfolgreich zurueckgesetzt. Bitte anmelden.';
header('Location: /?page=login');
header('Location: ' . appPath('?page=login'));
exit;
}
}
@@ -827,6 +847,16 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$error = 'Log-Export ist ohne Datenbank nicht verfuegbar.';
}
if ($user && $action === 'clear_audit_logs' && $user['role'] === 'admin') {
if ($pdo) {
$pdo->exec('TRUNCATE TABLE audit_logs');
addAuditLog($pdo, (int)$user['id'], 'Audit-Log geleert.');
$notice = 'Logeintraege wurden geloescht.';
} else {
$error = 'Logeintraege koennen ohne Datenbank nicht geloescht werden.';
}
}
if ($user && $action === 'import_sql_dump' && $user['role'] === 'admin') {
if (!$pdo) {
$error = 'SQL-Wiederherstellung ist ohne Datenbank nicht verfuegbar.';
@@ -928,7 +958,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if ($user && $action === 'logout') {
addAuditLog($pdo, (int)$user['id'], 'Abmeldung erfolgt.');
session_destroy();
header('Location: /?page=login');
header('Location: ' . appPath('?page=login'));
exit;
}
}