- Alle Module nach /modules/ verschoben (dinos, plants, storymachine, test, _template) - .htaccess transparentes Routing fuer /modules/ eingerichtet - ModuleService Auto-Discovery auf /modules/ Verzeichnis angepasst - Original Web Audio Synthese (playOrganicFart) und Furzkissen-UI in modules/test/index.php wiederhergestellt - AGENTS.md Dokumentation aktualisiert
78 lines
2.6 KiB
PHP
78 lines
2.6 KiB
PHP
<?php
|
|
/**
|
|
* Modul-Bootstrap: Graceful Auth & Universeller Env-Loader
|
|
*
|
|
* - Auf philippurbschat.de: Prüft zentralen Login & Benutzerrechte über ../auth.php
|
|
* - Standalone-Betrieb: Läuft autark weiter, wenn ../auth.php nicht existiert
|
|
* - API-Keys: Liest zuerst lokale .env, greift bei Bedarf auf ../home/.env zu
|
|
*/
|
|
|
|
if (session_status() === PHP_SESSION_NONE) {
|
|
session_start();
|
|
}
|
|
|
|
// 1. Graceful Auth (im Webbetrieb)
|
|
$authCandidates = [
|
|
__DIR__ . '/../../auth.php',
|
|
__DIR__ . '/../auth.php'
|
|
];
|
|
foreach ($authCandidates as $authPath) {
|
|
if (file_exists($authPath) && php_sapi_name() !== 'cli') {
|
|
$current_project = basename(__DIR__);
|
|
require_once $authPath;
|
|
break;
|
|
}
|
|
}
|
|
|
|
// 2. Nutzer-Kontext
|
|
$currentUser = $_SESSION['user_email'] ?? 'Gast / Standalone';
|
|
$isAdmin = !empty($_SESSION['is_admin']);
|
|
|
|
// 3. Hierarchischer Env-Loader
|
|
if (!function_exists('module_env')) {
|
|
function module_env(string $key, ?string $default = null): ?string {
|
|
static $envCache = null;
|
|
|
|
if ($envCache === null) {
|
|
$envCache = [];
|
|
$candidates = [
|
|
__DIR__ . '/.env', // 1. Lokale Modul-Konfiguration
|
|
__DIR__ . '/../../home/.env', // 2. Wenn in /modules/<name>
|
|
__DIR__ . '/../home/.env', // 3. Wenn im Root
|
|
__DIR__ . '/../../.env',
|
|
__DIR__ . '/../.env'
|
|
];
|
|
|
|
foreach ($candidates as $file) {
|
|
if (file_exists($file)) {
|
|
$lines = file($file, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
if ($lines !== false) {
|
|
foreach ($lines as $line) {
|
|
$line = trim($line);
|
|
if ($line === '' || $line[0] === '#') continue;
|
|
if (strpos($line, '=') !== false) {
|
|
list($k, $v) = explode('=', $line, 2);
|
|
$cleanKey = trim($k);
|
|
// Frühere (spezifischere) Dateien haben Vorrang
|
|
if (!isset($envCache[$cleanKey])) {
|
|
$envCache[$cleanKey] = trim(trim($v), '"\'');
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (isset($envCache[$key])) {
|
|
return $envCache[$key];
|
|
}
|
|
|
|
$sysEnv = getenv($key);
|
|
if ($sysEnv !== false && $sysEnv !== '') {
|
|
return $sysEnv;
|
|
}
|
|
|
|
return $_ENV[$key] ?? $default;
|
|
}
|
|
}
|