diff --git a/www/_func.php b/www/_func.php new file mode 100644 index 0000000..eeee87a --- /dev/null +++ b/www/_func.php @@ -0,0 +1,70 @@ +single( + "SELECT id, attempts + FROM admin_login_attempts + WHERE ip_address = ?", + "s", + [$ip] + ); + + if (!$entry) { + // Erster Fehlversuch + $sql->set( + "INSERT INTO admin_login_attempts (ip_address, attempts, last_attempt) + VALUES (?, 1, NOW())", + "s", + [$ip] + ); + return; + } + + $attempts = (int)$entry['attempts'] + 1; + + if ($attempts >= 3) { + $sql->set( + "UPDATE admin_login_attempts + SET attempts = ?, + locked_until = DATE_ADD(NOW(), INTERVAL 1 HOUR), + last_attempt = NOW() + WHERE id = ?", + "ii", + [$attempts, $entry['id']] + ); + } else { + $sql->set( + "UPDATE admin_login_attempts + SET attempts = ?, + last_attempt = NOW() + WHERE id = ?", + "ii", + [$attempts, $entry['id']] + ); + } +} +function isIpLocked(string $ip, $sql): bool { + global $sql; + $entry = $sql->single( + "SELECT locked_until + FROM admin_login_attempts + WHERE ip_address = ? + AND locked_until IS NOT NULL + AND locked_until > NOW()", + "s", + [$ip] + ); + + return (bool)$entry; +} +function clearLoginAttempts(string $ip, $sql): void { + global $sql; + $sql->set( + "DELETE FROM admin_login_attempts WHERE ip_address = ?", + "s", + [$ip] + ); +} + + +?> \ No newline at end of file diff --git a/www/_sql.php b/www/_sql.php index 474060f..16c5c8b 100644 --- a/www/_sql.php +++ b/www/_sql.php @@ -171,4 +171,6 @@ class SQL { // echo 'DESTROY'; } } + +$sql = new SQL(); ?> \ No newline at end of file diff --git a/www/admin.php b/www/admin.php new file mode 100644 index 0000000..57386ea --- /dev/null +++ b/www/admin.php @@ -0,0 +1,236 @@ + true, + 'cookie_httponly' => true +]); + +$ip = $_SERVER['REMOTE_ADDR']; + +/** + * 🔒 IP-Sperre prüfen + */ +if (isIpLocked($ip, $sql)) { + http_response_code(403); + exit('Zu viele Fehlversuche. IP für 1 Stunde gesperrt.'); +} + +/** + * 🔐 LOGIN (wenn nicht eingeloggt) + */ +if (!($_SESSION['is_admin'] ?? false)) { + + if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $user = $_POST['username'] ?? ''; + $pass = $_POST['password'] ?? ''; + + $admin = $sql->single( + "SELECT * FROM admin_users WHERE username = ?", + "s", + [$user] + ); + + if (!$admin || !password_verify($pass, $admin['password_hash'])) { + registerFailedLogin($ip, $sql); + $error = 'Ungültige Zugangsdaten'; + } else { + clearLoginAttempts($ip, $sql); + $_SESSION['is_admin'] = true; + $_SESSION['admin_id'] = $admin['id']; + header('Location: admin.php'); + exit; + } + } + + // 🔑 Login-Formular + ?> + + +
+ += htmlspecialchars($uuid) ?>
+ + Gespeichert ✔'; ?> + + + + + + + get("SELECT * FROM identities ORDER BY id DESC"); +$tokens = $sql->get("SELECT * FROM access_tokens ORDER BY created_at DESC"); + +?> + + + + +