Compare commits

...

2 Commits

Author SHA1 Message Date
3e078d5344 Merge branch 'main' of gitea.iten.pro:edi/iten.pro
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 11s
2026-04-01 16:18:19 +02:00
35f152632e Added auth test
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 11s
2026-04-01 16:15:04 +02:00
2 changed files with 50 additions and 0 deletions

View File

@@ -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
View 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;