Added auth test
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 11s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 11s
This commit is contained in:
@@ -1,3 +1,10 @@
|
|||||||
ErrorDocument 403 /403.html
|
ErrorDocument 403 /403.html
|
||||||
ErrorDocument 404 /404.html
|
ErrorDocument 404 /404.html
|
||||||
ErrorDocument 500 /500.html
|
ErrorDocument 500 /500.html
|
||||||
|
|
||||||
|
RewriteEngine On
|
||||||
|
|
||||||
|
# Prüfen, ob die aufgerufene URL mit /index-test beginnt
|
||||||
|
RewriteCond %{REQUEST_URI} ^/index-test(/.*)?$
|
||||||
|
# Umleitung auf das PHP-Skript, Übergabe des originalen Pfads als Parameter
|
||||||
|
RewriteRule ^(.*)$ /auth.php?route=$1 [QSA,L]
|
||||||
43
public/auth.php
Normal file
43
public/auth.php
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
session_start();
|
||||||
|
|
||||||
|
// 1. Authentifizierungsstatus prüfen (Hier erfolgt später die Authelia-OIDC-Integration)
|
||||||
|
// Für den initialen Test wird ein manueller Toggle simuliert
|
||||||
|
$is_logged_in = isset($_SESSION['authenticated']) && $_SESSION['authenticated'] === true;
|
||||||
|
|
||||||
|
// Zum Testen erzwingen wir den Login-Fehler, wenn die Session nicht gesetzt ist:
|
||||||
|
if (!$is_logged_in) {
|
||||||
|
header("HTTP/1.1 401 Unauthorized");
|
||||||
|
die("Zugriff verweigert. Die Authelia-Integration folgt hier.");
|
||||||
|
// Später: header('Location: /login.php'); exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. Angeforderten Dateipfad ermitteln
|
||||||
|
$route = $_GET['route'] ?? '';
|
||||||
|
$route = trim($route, '/');
|
||||||
|
|
||||||
|
$base_dir = realpath(__DIR__);
|
||||||
|
$target_file = $base_dir . '/' . $route;
|
||||||
|
|
||||||
|
// Astro generiert Seiten standardmäßig als Verzeichnis mit einer index.html
|
||||||
|
if (is_dir($target_file)) {
|
||||||
|
$target_file = rtrim($target_file, '/') . '/index.html';
|
||||||
|
} elseif (!str_ends_with($target_file, '.html') && file_exists($target_file . '/index.html')) {
|
||||||
|
$target_file .= '/index.html';
|
||||||
|
} elseif (!str_ends_with($target_file, '.html')) {
|
||||||
|
$target_file .= '.html';
|
||||||
|
}
|
||||||
|
|
||||||
|
// 3. Sicherheitsprüfung (Path Traversal verhindern) und Datei ausliefern
|
||||||
|
$real_target = realpath($target_file);
|
||||||
|
|
||||||
|
if ($real_target && file_exists($real_target) && strpos($real_target, $base_dir) === 0) {
|
||||||
|
header('Content-Type: text/html');
|
||||||
|
readfile($real_target);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fallback
|
||||||
|
header("HTTP/1.0 404 Not Found");
|
||||||
|
echo "404 - Geschützte Datei nicht gefunden";
|
||||||
|
exit;
|
||||||
Reference in New Issue
Block a user