Füge Unterstützung für IP-Sperre und verbessere die Anmeldefunktionalität hinzu; aktualisiere .gitignore, Dockerfile und Datenbankschema
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1 +1,2 @@
|
|||||||
www/secret.php
|
www/secret.php
|
||||||
|
www/_user.php
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ FROM php:8.2-apache
|
|||||||
RUN a2enmod rewrite
|
RUN a2enmod rewrite
|
||||||
|
|
||||||
# PHP-Extensions für MariaDB
|
# PHP-Extensions für MariaDB
|
||||||
RUN docker-php-ext-install pdo pdo_mysql
|
RUN docker-php-ext-install mysqli pdo pdo_mysql
|
||||||
|
|
||||||
# VHost kopieren
|
# VHost kopieren
|
||||||
COPY vhost.conf /etc/apache2/sites-available/000-default.conf
|
COPY vhost.conf /etc/apache2/sites-available/000-default.conf
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ CREATE TABLE access_tokens (
|
|||||||
uuid CHAR(36) NOT NULL UNIQUE,
|
uuid CHAR(36) NOT NULL UNIQUE,
|
||||||
expires_at DATETIME NULL,
|
expires_at DATETIME NULL,
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
notes TEXT NULL,
|
||||||
FOREIGN KEY (identity_id)
|
FOREIGN KEY (identity_id)
|
||||||
REFERENCES identities(id)
|
REFERENCES identities(id)
|
||||||
ON DELETE CASCADE
|
ON DELETE CASCADE
|
||||||
@@ -53,3 +54,13 @@ CREATE TABLE files (
|
|||||||
REFERENCES access_tokens(id)
|
REFERENCES access_tokens(id)
|
||||||
ON DELETE SET NULL
|
ON DELETE SET NULL
|
||||||
) ENGINE=InnoDB;
|
) ENGINE=InnoDB;
|
||||||
|
|
||||||
|
CREATE TABLE admin_login_attempts (
|
||||||
|
id INT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
ip_address VARCHAR(45) NOT NULL,
|
||||||
|
attempts INT NOT NULL DEFAULT 1,
|
||||||
|
locked_until DATETIME NULL,
|
||||||
|
last_attempt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
UNIQUE KEY (ip_address)
|
||||||
|
);
|
||||||
|
|
||||||
|
|||||||
3
www/_user.php.example
Normal file
3
www/_user.php.example
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<?php
|
||||||
|
$admin_user = 'admin';
|
||||||
|
$admin_password = 'password';
|
||||||
@@ -1,36 +1,34 @@
|
|||||||
<?php
|
<?php
|
||||||
require '_sql.php';
|
require '_sql.php';
|
||||||
require '_func.php';
|
require '_func.php';
|
||||||
|
require '_user.php';
|
||||||
|
|
||||||
session_start([
|
session_start();
|
||||||
'use_strict_mode' => true,
|
|
||||||
'cookie_httponly' => true
|
|
||||||
]);
|
|
||||||
|
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
||||||
/**
|
|
||||||
* 🔒 IP-Sperre prüfen
|
|
||||||
*/
|
|
||||||
if (isIpLocked($ip, $sql)) {
|
if (isIpLocked($ip, $sql)) {
|
||||||
http_response_code(403);
|
http_response_code(403);
|
||||||
exit('Zu viele Fehlversuche. IP für 1 Stunde gesperrt.');
|
exit('Zu viele Fehlversuche. IP für 1 Stunde gesperrt.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 🔐 LOGIN (wenn nicht eingeloggt)
|
|
||||||
*/
|
|
||||||
if (!($_SESSION['is_admin'] ?? false)) {
|
if (!($_SESSION['is_admin'] ?? false)) {
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$user = $_POST['username'] ?? '';
|
$user = $_POST['username'] ?? '';
|
||||||
$pass = $_POST['password'] ?? '';
|
$pass = $_POST['password'] ?? '';
|
||||||
|
|
||||||
$admin = $sql->single(
|
if (
|
||||||
"SELECT * FROM admin_users WHERE username = ?",
|
$user !== $admin_user ||
|
||||||
"s",
|
$pass !== $admin_password
|
||||||
[$user]
|
) {
|
||||||
);
|
registerFailedLogin($ip, $sql);
|
||||||
|
$error = 'Ungültige Zugangsdaten';
|
||||||
|
} else {
|
||||||
|
clearLoginAttempts($ip, $sql);
|
||||||
|
$_SESSION['is_admin'] = true;
|
||||||
|
header('Location: admin.php');
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$admin || !password_verify($pass, $admin['password_hash'])) {
|
if (!$admin || !password_verify($pass, $admin['password_hash'])) {
|
||||||
registerFailedLogin($ip, $sql);
|
registerFailedLogin($ip, $sql);
|
||||||
@@ -75,27 +73,15 @@ if (!($_SESSION['is_admin'] ?? false)) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* ✅ AB HIER: ADMIN EINGELOGGT
|
|
||||||
*/
|
|
||||||
|
|
||||||
$uuid = $_GET['uuid'] ?? null;
|
$uuid = $_GET['uuid'] ?? null;
|
||||||
|
|
||||||
/**
|
|
||||||
* 🧩 UUID-Editor
|
|
||||||
*/
|
|
||||||
if ($uuid) {
|
if ($uuid) {
|
||||||
|
|
||||||
// Token laden
|
|
||||||
$token = $sql->single(
|
$token = $sql->single(
|
||||||
"SELECT * FROM access_tokens WHERE uuid = ?",
|
"SELECT * FROM access_tokens WHERE uuid = ?",
|
||||||
"s",
|
"s",
|
||||||
[$uuid]
|
[$uuid]
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* 🆕 UUID existiert noch nicht → an feste Identität hängen
|
|
||||||
*/
|
|
||||||
if (!$token) {
|
if (!$token) {
|
||||||
$sql->set(
|
$sql->set(
|
||||||
"INSERT INTO access_tokens (identity_id, uuid)
|
"INSERT INTO access_tokens (identity_id, uuid)
|
||||||
@@ -111,9 +97,6 @@ if ($uuid) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 🔄 Speichern
|
|
||||||
*/
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$issuedTo = $_POST['issued_to'] ?? '';
|
$issuedTo = $_POST['issued_to'] ?? '';
|
||||||
$fields = $_POST['fields'] ?? [];
|
$fields = $_POST['fields'] ?? [];
|
||||||
|
|||||||
Reference in New Issue
Block a user