5d3cd1bdcf
- app.php: BASE_URL fuer *.geograsim.at war hart 'https://geograsim.at' -> auf v3.geograsim.at lud die Glossar-API cross-origin -> CORS/NetworkError ("Glossar konnte nicht geladen werden"). Jetzt BASE_URL='https://'.$host (same-origin auf jeder Umgebung; prod-neutral, geograsim.at bleibt gleich). - weltkueche/game.html: Zweit-Lieferant hiess pauschal „Nachbarland" — Frankreich ist aber kein Nachbar Oesterreichs. Jetzt „europaeisches Land in unserer Naehe". Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
118 lines
5.2 KiB
PHP
118 lines
5.2 KiB
PHP
<?php
|
|
/**
|
|
* GeoGraSim — App Configuration
|
|
* Umgebungserkennung und Grundkonstanten
|
|
*/
|
|
|
|
// API-Antworten dürfen NIE durch PHP-Warnings/Deprecations korrumpiert werden.
|
|
// Production: Errors gehen ins Log, niemals in den Output (sonst zerbricht JSON).
|
|
// Local: Errors weiter sichtbar zum Debuggen.
|
|
$_isApiCall = strpos($_SERVER['REQUEST_URI'] ?? '', '/api/') !== false;
|
|
$_isProd = (($_SERVER['HTTP_HOST'] ?? '') !== 'localhost');
|
|
if ($_isApiCall || $_isProd) {
|
|
ini_set('display_errors', '0');
|
|
ini_set('display_startup_errors', '0');
|
|
error_reporting(E_ALL & ~E_DEPRECATED & ~E_USER_DEPRECATED);
|
|
ini_set('log_errors', '1');
|
|
}
|
|
|
|
// Umgebungserkennung via Hostname
|
|
$host = $_SERVER['HTTP_HOST'] ?? $_SERVER['SERVER_NAME'] ?? 'localhost';
|
|
// Docker-Container oder fehlender Host = Production wenn .env.production existiert
|
|
$envProdExists = file_exists(dirname(__DIR__, 2) . '/.env.production');
|
|
define('IS_PRODUCTION', $host !== 'localhost' || ($envProdExists && !file_exists(dirname(__DIR__, 2) . '/.env.local')));
|
|
|
|
// BASE_PATH: konfigurierbar per Host
|
|
// geograsim.at → /
|
|
// staatsgeheimnis.at/geograsim/ → /geograsim
|
|
// localhost/geograsim/App/ → /geograsim/App
|
|
if (strpos($host, 'geograsim.at') !== false) {
|
|
define('BASE_PATH', '');
|
|
// BASE_URL folgt dem TATSÄCHLICHEN Host (geograsim.at, v3.geograsim.at, …),
|
|
// damit same-origin-Fetches (z.B. Glossar-API) auf jeder Umgebung greifen.
|
|
// Vorher war 'https://geograsim.at' hartcodiert → auf v3.geograsim.at wurde
|
|
// die API cross-origin geladen → CORS/NetworkError. Alle *.geograsim.at
|
|
// werden per TLS ausgeliefert, daher https.
|
|
define('BASE_URL', 'https://' . $host);
|
|
} elseif (strpos($host, 'staatsgeheimnis.at') !== false) {
|
|
define('BASE_PATH', '/geograsim');
|
|
define('BASE_URL', 'https://www.staatsgeheimnis.at/geograsim');
|
|
} else {
|
|
define('BASE_PATH', '/geograsim/App');
|
|
define('BASE_URL', 'http://localhost/geograsim/App');
|
|
}
|
|
define('APP_ROOT', dirname(__DIR__, 2));
|
|
|
|
// Composer-Autoloader (firebase/php-jwt, predis). Guard: erst ab dem
|
|
// JWT/Redis-Umbau vorhanden; fehlt er, läuft die App im Legacy-Session-Modus
|
|
// unverändert weiter.
|
|
if (is_file(APP_ROOT . '/vendor/autoload.php')) {
|
|
require_once APP_ROOT . '/vendor/autoload.php';
|
|
}
|
|
|
|
// Plattform-Limits — eine einzelne Sim-Session darf nie länger als 120 min
|
|
// dauern. Schützt DB vor absurden Werten (Tab über Nacht offen, Bug im
|
|
// Frontend-Zeit-Tracking, etc.). Backend-Cap ist defensive Garantie:
|
|
// auch wenn Frontend falsch rechnet, schreibt die DB max 7_200_000 ms.
|
|
// Idle-Pause vorgelagert im Frontend; dieser Cap ist die letzte Schranke.
|
|
if (!defined('GGS_MAX_SESSION_MS')) define('GGS_MAX_SESSION_MS', 7200000);
|
|
if (!defined('GGS_IDLE_THRESHOLD_MS')) define('GGS_IDLE_THRESHOLD_MS', 90000);
|
|
|
|
// .env laden
|
|
$envFile = IS_PRODUCTION
|
|
? APP_ROOT . '/.env.production'
|
|
: APP_ROOT . '/.env.local';
|
|
|
|
if (file_exists($envFile)) {
|
|
$lines = file($envFile, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
|
|
foreach ($lines as $line) {
|
|
$line = trim($line);
|
|
if ($line === '' || $line[0] === '#') continue;
|
|
if (strpos($line, '=') === false) continue;
|
|
[$key, $value] = explode('=', $line, 2);
|
|
$key = trim($key);
|
|
$value = trim($value);
|
|
if (!defined($key)) {
|
|
define($key, $value);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Defaults fuer lokale Entwicklung (XAMPP)
|
|
if (!defined('DB_HOST')) define('DB_HOST', 'localhost');
|
|
if (!defined('DB_NAME')) define('DB_NAME', 'geograsim');
|
|
if (!defined('DB_USER')) define('DB_USER', 'root');
|
|
if (!defined('DB_PASS')) define('DB_PASS', '');
|
|
if (!defined('DB_PORT')) define('DB_PORT', '3306');
|
|
|
|
// ── Auth-Backend (JWT + Redis Migration) ────────────────────────────────
|
|
// 'session' = Legacy (native PHP-Session-Dateien, wie bisher) — DEFAULT,
|
|
// damit sich am Live-System NICHTS ändert, bis der Cutover steht.
|
|
// 'jwt' = JWT-Access-Token (HttpOnly-Cookie) + Redis-Session/Refresh.
|
|
if (!defined('AUTH_BACKEND')) define('AUTH_BACKEND', 'session');
|
|
if (!defined('REDIS_URL')) define('REDIS_URL', 'tcp://127.0.0.1:6379');
|
|
if (!defined('JWT_TTL')) define('JWT_TTL', 900); // Access-Token: 15 min
|
|
if (!defined('JWT_REFRESH_TTL')) define('JWT_REFRESH_TTL', 2592000); // Refresh/Session: 30 Tage
|
|
// JWT_SECRET hat BEWUSST keinen Default — muss in .env gesetzt sein, sobald
|
|
// AUTH_BACKEND='jwt'. Jwt.php wirft sonst eine klare Exception.
|
|
|
|
/**
|
|
* Cockpit-URL je nach Login-Status:
|
|
* - Lehrkraft eingeloggt → /teacher
|
|
* - Schueler*in eingeloggt → /schueler
|
|
* - sonst → / (Plattform-Startseite)
|
|
*
|
|
* Wird von Sim-Wrappern benutzt, um den Logo- und Home-Button in der Sim
|
|
* auf das richtige Ziel umzubiegen. Idempotent — kann mehrfach aufgerufen
|
|
* werden.
|
|
*/
|
|
function cockpit_href(): string {
|
|
if (session_status() === PHP_SESSION_NONE) @session_start();
|
|
// über Session:: kanalisiert; Fallback auf $_SESSION, falls die Lib im
|
|
// Bootstrap-Kontext (nur app.php) noch nicht geladen ist.
|
|
$tid = class_exists('Session') ? Session::teacherId() : ($_SESSION['teacher_id'] ?? null);
|
|
if ($tid) return BASE_PATH . '/teacher';
|
|
if (!empty($_COOKIE['ggs_session'])) return BASE_PATH . '/schueler';
|
|
return BASE_PATH . '/';
|
|
}
|