-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_security.php
More file actions
62 lines (52 loc) · 2.17 KB
/
Copy pathsetup_security.php
File metadata and controls
62 lines (52 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
header('Content-Type: text/plain; charset=utf-8');
require_once __DIR__ . '/config.php';
$sql = "
-- Tabellen für das Sicherheitssystem
CREATE TABLE IF NOT EXISTS admins (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
password_hash VARCHAR(255) NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS admin_tokens (
id INT AUTO_INCREMENT PRIMARY KEY,
token_hash VARCHAR(64) NOT NULL UNIQUE,
expires_at DATETIME NOT NULL,
created_at DATETIME DEFAULT CURRENT_TIMESTAMP,
INDEX idx_expires_at (expires_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
CREATE TABLE IF NOT EXISTS login_attempts (
id INT AUTO_INCREMENT PRIMARY KEY,
ip_address VARCHAR(45) NOT NULL,
success TINYINT(1) NOT NULL DEFAULT 0,
attempt_time DATETIME DEFAULT CURRENT_TIMESTAMP,
INDEX idx_ip_time (ip_address, attempt_time)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
";
try {
// Tabellen erstellen
$pdo->exec($sql);
echo "Tabellen erfolgreich erstellt oder bereits vorhanden.\n";
// Standard-Admin anlegen, falls noch nicht vorhanden
$stmt = $pdo->prepare('SELECT COUNT(*) FROM admins WHERE username = ?');
$stmt->execute(['admin']);
$count = $stmt->fetchColumn();
if ($count == 0) {
$password = 'admin123'; // Dieses Passwort sollte bei erster Änderung geändert werden
$hash = password_hash($password, PASSWORD_DEFAULT);
$stmt = $pdo->prepare('INSERT INTO admins (username, password_hash) VALUES (?, ?)');
$stmt->execute(['admin', $hash]);
echo "Standard-Administrator angelegt:\n";
echo " Benutzername: admin\n";
echo " Passwort: admin123\n";
echo " WICHTIG: Bitte ändern Sie das Passwort nach der ersten Anmeldung!\n";
} else {
echo "Administrator existiert bereits.\n";
}
} catch (PDOException $e) {
echo "Fehler: " . $e->getMessage() . "\n";
http_response_code(500);
}
?>