custom block templates

This commit is contained in:
Tower committed 2026-06-02 18:27:50 +02:00
1 parent 5c4f0a161a
commit a48e99b454
7 files changed
+128 -4

No files matched your search

+28 -1
View File
@@ -11,6 +11,23 @@ class Logger {
return dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'logs';
}
private static $config = null;
/**
* Lädt die Konfiguration aus der env.ini
*/
private static function getConfig() {
if (self::$config === null) {
$configFile = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'env.ini';
if (file_exists($configFile)) {
self::$config = parse_ini_file($configFile);
} else {
self::$config = [];
}
}
return self::$config;
}
/**
* Protokolliert eine Nachricht in eine Datei.
*
@@ -19,6 +36,16 @@ class Logger {
* @param string $file Optional: Die Zieldatei im logs-Ordner.
*/
public static function log($message, $level = 'INFO', $file = 'system.log') {
$config = self::getConfig();
// Überprüfe Konfiguration für spezielle Logs
if ($file === 'access.log' && empty($config['LOG_ACCESS'])) {
return;
}
if ($file === 'blocked.log' && empty($config['LOG_SECURITY'])) {
return;
}
$logDir = self::getLogDir();
if (!is_dir($logDir)) {
@@ -73,4 +100,4 @@ class Logger {
$message = "$errstr in $errfile on line $errline";
self::log($message, $level, 'error.log');
}
}
}
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<title>403 Forbidden</title>
<style>
body { background: white; color: black; font-family: monospace; padding: 50px; }
h1 { border-bottom: 1px solid black; padding-bottom: 10px; }
pre { background: #eee; padding: 15px; }
</style>
</head>
<body>
<h1>403 Forbidden</h1>
<p>Access to this resource is denied.</p>
<hr>
<pre>
Status: Blocked
Source: <?php echo htmlspecialchars($ip); ?>
Time: <?php echo date('r'); ?>
</pre>
</body>
</html>
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Systemmeldung</title>
<style>
body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: #1a1a2e; color: #e94560; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
.card { background: #16213e; padding: 3rem; border-radius: 20px; text-align: center; box-shadow: 0 10px 30px rgba(0,0,0,0.5); border: 1px solid #0f3460; }
.icon { font-size: 4rem; margin-bottom: 1rem; }
h1 { margin: 0; font-weight: 300; letter-spacing: 2px; }
p { color: #95a5a6; margin-top: 1.5rem; }
.footer { margin-top: 2rem; font-size: 0.8rem; opacity: 0.5; color: white; }
</style>
</head>
<body>
<div class="card">
<div class="icon">🛡️</div>
<h1>ZUGRIFF GESPERRT</h1>
<p>Ihre Verbindung wurde aus Sicherheitsgründen unterbrochen.</p>
<div class="footer">ID: <?php echo htmlspecialchars($ip); ?> | <?php echo date('Y-m-d H:i:s'); ?></div>
</div>
</body>
</html>
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<html lang="de">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Zugriff verweigert</title>
<style>
body { font-family: sans-serif; background: #f4f4f4; color: #333; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
.container { background: white; padding: 2rem; border-radius: 8px; box-shadow: 0 4px 6px rgba(0,0,0,0.1); text-align: center; max-width: 400px; border-top: 5px solid #d9534f; }
h1 { color: #d9534f; margin-top: 0; }
p { line-height: 1.6; }
.ip { font-weight: bold; color: #777; font-size: 0.9rem; margin-top: 1rem; }
</style>
</head>
<body>
<div class="container">
<h1>403 - Zugriff verweigert</h1>
<p>Ihre IP-Adresse wurde aufgrund von Sicherheitsrichtlinien vorübergehend blockiert.</p>
<p>Bitte wenden Sie sich an den Administrator, falls Sie glauben, dass dies ein Fehler ist.</p>
<div class="ip">IP: <?php echo htmlspecialchars($ip); ?></div>
</div>
</body>
</html>
@@ -15,8 +15,21 @@ class BlockMiddleware implements MiddlewareInterface {
$ip = Client::ip();
if (in_array($ip, $blockedIps)) {
Logger::log("Blocked IP attempt: $ip", 'SECURITY', 'blocked.log');
// Lade Konfiguration für das Template
$configFile = dirname(__DIR__, 2) . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'env.ini';
$config = file_exists($configFile) ? parse_ini_file($configFile) : [];
$template = $config['BLOCK_PAGE_TEMPLATE'] ?? 'standard';
$templatePath = dirname(__DIR__) . DIRECTORY_SEPARATOR . 'Layout' . DIRECTORY_SEPARATOR . 'Block' . DIRECTORY_SEPARATOR . $template . '.php';
http_response_code(403);
die("Ihre IP-Adresse wurde blockiert.");
if (file_exists($templatePath)) {
include $templatePath;
} else {
die("Ihre IP-Adresse wurde blockiert.");
}
exit;
}
}
}
@@ -11,7 +11,17 @@ use MVC\Classes\Logger;
class EveryRequestMiddleware implements MiddlewareInterface {
public function handle() {
$ip = $_SERVER['REMOTE_ADDR'] ?? 'unknown';
$service = $_GET['service'] ?? 'home';
// Determine service logic consistent with index.php
$service = $_GET['service'] ?? null;
if ($service === null) {
$uri = parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH);
$service = trim($uri, '/');
if (empty($service)) {
$service = 'home';
}
}
Logger::log("IP: $ip - Service: $service", 'ACCESS', 'access.log');
}
}
+6 -1
View File
@@ -16,4 +16,9 @@ DB_LIVE_DATABASE = ""
[mail]
MAIL_FROM = "bruno.eckhardt07@gmail.com"
MAIL_TO = "bruno.eckhardt07@gmail.com"
MAIL_TO = "bruno.eckhardt07@gmail.com"
[logging]
LOG_ACCESS = false
LOG_SECURITY = true
BLOCK_PAGE_TEMPLATE = "standard"