Files
WebAPP/public/index.php
Rhino 2e24a40d68 Stand: SMTP-Test, Admin-Mail-Tab, Notifiable-Fix, Lazy-Quill
- Fix: Notifiable-Trait zum User-Model hinzugefuegt (behebt notify()-500er)
- Installer: SMTP-Verbindungstest mit EsmtpTransport + Ueberspringen-Link
- Admin: Neuer E-Mail-Tab mit SMTP-Konfiguration + Verbindungstest
- Admin: Lazy Quill-Initialisierung (nur sichtbare Locale wird geladen)
- Uebersetzungen: 17 neue Mail-Keys in allen 6 Sprachen

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 07:30:37 +01:00

305 lines
15 KiB
PHP
Executable File

<?php
define('LARAVEL_START', microtime(true));
// Vor Installation: Fehler anzeigen statt weisser Seite.
// Nach Installation uebernimmt Laravels Error-Handler.
if (!file_exists(__DIR__ . '/../storage/installed')) {
error_reporting(E_ALL);
ini_set('display_errors', '1');
}
// ─── Pre-Flight Check (vor Laravel-Bootstrap) ────────────────
// Stellt sicher, dass alle Voraussetzungen erfuellt sind, bevor
// Laravel bootet. Verhindert den 500er-Fehler bei Erstinstallation.
// Nach erfolgreicher Installation (storage/installed existiert)
// wird dieser Block komplett uebersprungen.
$basePath = __DIR__ . '/..';
if (!file_exists($basePath . '/storage/installed')) {
$errors = [];
$permissionErrors = [];
$phpErrors = [];
$extensionErrors = [];
$fileErrors = [];
// 1. PHP-Version pruefen (>= 8.2)
if (version_compare(PHP_VERSION, '8.2.0', '<')) {
$phpErrors[] = 'PHP 8.2 oder hoeher wird benoetigt. Aktuell installiert: PHP ' . PHP_VERSION;
}
// 2. Pflicht-Extensions pruefen
$requiredExtensions = [
'pdo' => 'Datenbankanbindung',
'mbstring' => 'Zeichenkodierung (Unicode)',
'openssl' => 'Verschluesselung',
'tokenizer' => 'PHP-Code-Analyse',
'xml' => 'XML-Verarbeitung',
'ctype' => 'Zeichentyp-Pruefung',
'fileinfo' => 'Dateityp-Erkennung',
'dom' => 'HTML/XML-Verarbeitung',
];
foreach ($requiredExtensions as $ext => $desc) {
if (!extension_loaded($ext)) {
$extensionErrors[] = $ext . ' (' . $desc . ')';
}
}
// 3. Verzeichnisse anlegen und Berechtigungen pruefen/reparieren
$writableDirs = [
'storage',
'storage/app',
'storage/framework',
'storage/framework/cache',
'storage/framework/cache/data',
'storage/framework/sessions',
'storage/framework/views',
'storage/logs',
'bootstrap/cache',
];
foreach ($writableDirs as $relDir) {
$fullPath = $basePath . '/' . $relDir;
// Verzeichnis erstellen, falls es nicht existiert
if (!is_dir($fullPath)) {
@mkdir($fullPath, 0775, true);
}
// Berechtigungen reparieren, falls nicht beschreibbar
if (is_dir($fullPath) && !is_writable($fullPath)) {
@chmod($fullPath, 0775);
}
// Immer noch nicht beschreibbar? → Fehler melden
if (!is_dir($fullPath) || !is_writable($fullPath)) {
$permissionErrors[] = $relDir;
}
}
// 4. .env-Datei erstellen (aus .env.example kopieren)
$envPath = $basePath . '/.env';
if (!file_exists($envPath) && file_exists($basePath . '/.env.example')) {
@copy($basePath . '/.env.example', $envPath);
}
if (!file_exists($envPath)) {
$fileErrors[] = 'Die Konfigurationsdatei .env konnte nicht erstellt werden.';
}
// 5. APP_KEY generieren, falls leer — MUSS vor Laravel-Bootstrap passieren,
// weil der EncryptionServiceProvider (eager Index 3) den Key beim Booten braucht,
// aber AppServiceProvider (eager Index 14) ihn sonst zu spaet setzen wuerde.
if (file_exists($envPath)) {
$envContent = file_get_contents($envPath);
if (preg_match('/^APP_KEY=\s*$/m', $envContent)) {
$key = 'base64:' . base64_encode(random_bytes(32));
$envContent = preg_replace('/^APP_KEY=\s*$/m', 'APP_KEY=' . $key, $envContent);
file_put_contents($envPath, $envContent);
}
}
// 6. Veralteten Config-/Routen-Cache loeschen (enthalten absolute Pfade
// vom Entwicklungsrechner). services.php und packages.php bleiben —
// diese enthalten nur Klassennamen und sind umgebungsunabhaengig.
foreach (['config.php', 'routes-v7.php'] as $cacheFile) {
$cachePath = $basePath . '/bootstrap/cache/' . $cacheFile;
if (file_exists($cachePath)) {
@unlink($cachePath);
}
}
// 7. vendor/-Ordner pruefen
if (!file_exists($basePath . '/vendor/autoload.php')) {
$fileErrors[] = 'Der Ordner "vendor/" fehlt oder ist unvollstaendig. Bitte alle Dateien erneut hochladen.';
}
// Alle Fehler sammeln
if (!empty($phpErrors)) $errors = array_merge($errors, $phpErrors);
if (!empty($extensionErrors)) $errors[] = '__extensions__';
if (!empty($permissionErrors)) $errors[] = '__permissions__';
if (!empty($fileErrors)) $errors = array_merge($errors, $fileErrors);
// Bei Fehlern: Eigenstaendige HTML-Seite anzeigen (kein Laravel noetig)
if (!empty($errors)) {
http_response_code(503);
?>
<!DOCTYPE html>
<html lang="de" dir="ltr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Installation — Systemcheck</title>
<script src="https://cdn.tailwindcss.com"></script>
<link rel="icon" href="/favicon.ico">
</head>
<body class="min-h-screen bg-gray-100 flex flex-col">
<main class="flex-1 flex items-center justify-center px-4 py-12">
<div class="w-full max-w-2xl">
<div class="text-center mb-6">
<img src="/images/logo_sg_woelfe.png" alt="Logo" class="mx-auto h-20 mb-3" onerror="this.style.display='none'">
<h1 class="text-xl font-bold text-gray-900">Installation</h1>
</div>
<div class="bg-white rounded-lg shadow-md p-6">
<div class="flex items-start gap-3 mb-4">
<svg class="w-6 h-6 text-amber-500 mt-0.5 flex-shrink-0" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"/>
</svg>
<div>
<h2 class="text-lg font-semibold text-gray-900">Systemvoraussetzungen nicht erfuellt</h2>
<p class="text-sm text-gray-600 mt-1">
Bevor die Installation starten kann, muessen folgende Probleme behoben werden:
</p>
</div>
</div>
<div class="space-y-4">
<?php if (!empty($phpErrors)): ?>
<div class="bg-red-50 border border-red-200 rounded-md p-4">
<h3 class="font-medium text-red-800 text-sm mb-1">PHP-Version</h3>
<?php foreach ($phpErrors as $err): ?>
<p class="text-sm text-red-700"><?php echo htmlspecialchars($err); ?></p>
<?php endforeach; ?>
<p class="text-xs text-red-600 mt-2">
<strong>Loesung:</strong> Wechsle in deinem Hosting-Panel (z.B. cPanel, Plesk)
auf PHP 8.2 oder hoeher. Die Einstellung findest du meistens unter
&bdquo;PHP-Version&ldquo; oder &bdquo;PHP Selector&ldquo;.
</p>
</div>
<?php endif; ?>
<?php if (!empty($extensionErrors)): ?>
<div class="bg-red-50 border border-red-200 rounded-md p-4">
<h3 class="font-medium text-red-800 text-sm mb-1">Fehlende PHP-Extensions</h3>
<p class="text-sm text-red-700">
Folgende PHP-Erweiterungen werden benoetigt, sind aber nicht aktiviert:
</p>
<ul class="mt-1 ml-4 list-disc text-sm text-red-700">
<?php foreach ($extensionErrors as $ext): ?>
<li><?php echo htmlspecialchars($ext); ?></li>
<?php endforeach; ?>
</ul>
<p class="text-xs text-red-600 mt-2">
<strong>Loesung:</strong> Aktiviere die fehlenden Extensions in deinem Hosting-Panel
unter &bdquo;PHP-Extensions&ldquo; oder &bdquo;PHP Modules&ldquo;.
</p>
</div>
<?php endif; ?>
<?php if (!empty($permissionErrors)): ?>
<div class="bg-red-50 border border-red-200 rounded-md p-4">
<h3 class="font-medium text-red-800 text-sm mb-1">Fehlende Schreibberechtigungen</h3>
<p class="text-sm text-red-700">
Folgende Verzeichnisse muessen beschreibbar sein (Berechtigungen: 775):
</p>
<ul class="mt-1 ml-4 list-disc text-sm text-red-700 font-mono">
<?php foreach ($permissionErrors as $dir): ?>
<li><?php echo htmlspecialchars($dir); ?>/</li>
<?php endforeach; ?>
</ul>
<div class="mt-3 text-xs text-red-600 space-y-2">
<p><strong>Loesung per FTP-Programm</strong> (z.B. FileZilla, WinSCP):</p>
<ol class="ml-4 list-decimal space-y-0.5">
<li>Verbinde dich mit dem Server per FTP</li>
<li>Navigiere zum Installationsordner</li>
<li>Rechtsklick auf den Ordner &bdquo;storage&ldquo; &rarr; &bdquo;Dateiberechtigungen&ldquo;</li>
<li>Setze die Berechtigungen auf <strong>775</strong></li>
<li>Aktiviere &bdquo;In Unterverzeichnisse einsteigen&ldquo;</li>
<li>Wiederhole dies fuer den Ordner &bdquo;bootstrap/cache&ldquo;</li>
</ol>
<p class="mt-2"><strong>Loesung per Hosting-Panel</strong> (cPanel / Plesk):</p>
<ol class="ml-4 list-decimal space-y-0.5">
<li>Oeffne den &bdquo;Dateimanager&ldquo; in deinem Hosting-Panel</li>
<li>Navigiere zum Installationsordner</li>
<li>Klicke auf &bdquo;storage&ldquo; &rarr; &bdquo;Berechtigungen aendern&ldquo;</li>
<li>Setze die Berechtigungen auf <strong>775</strong> (rekursiv)</li>
<li>Wiederhole dies fuer &bdquo;bootstrap/cache&ldquo;</li>
</ol>
</div>
</div>
<?php endif; ?>
<?php if (!empty($fileErrors)): ?>
<div class="bg-red-50 border border-red-200 rounded-md p-4">
<h3 class="font-medium text-red-800 text-sm mb-1">Fehlende Dateien</h3>
<?php foreach ($fileErrors as $err): ?>
<p class="text-sm text-red-700"><?php echo htmlspecialchars($err); ?></p>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div class="mt-6 flex justify-center">
<a href="/"
class="px-5 py-2 text-sm font-medium text-white bg-blue-600 rounded-md hover:bg-blue-700 transition inline-flex items-center gap-2">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15"/>
</svg>
Erneut pruefen
</a>
</div>
</div>
</div>
</main>
<footer class="text-center py-3 text-xs text-gray-400">
Handball WebApp &mdash; Systemcheck
</footer>
</body>
</html>
<?php
exit;
}
}
// ─── Laravel Bootstrap ───────────────────────────────────────
// Alles in try-catch wrappen, damit auch Fehler beim Autoloading
// sichtbar werden (PHP-FPM unterdrueckt display_errors).
try {
// Determine if the application is in maintenance mode...
if (file_exists($maintenance = __DIR__.'/../storage/framework/maintenance.php')) {
require $maintenance;
}
// Register the Composer autoloader...
require __DIR__.'/../vendor/autoload.php';
// Bootstrap Laravel and handle the request...
/** @var \Illuminate\Foundation\Application $app */
$app = require_once __DIR__.'/../bootstrap/app.php';
$app->handleRequest(\Illuminate\Http\Request::capture());
} catch (\Throwable $e) {
// 503 statt 500: Einige Hoster (ProxyErrorOverride) ersetzen bei 500
// die Antwort mit einer eigenen Fehlerseite, die unsere Ausgabe versteckt.
http_response_code(503);
// Nur vor Installation Fehlerdetails anzeigen
if (!file_exists(__DIR__ . '/../storage/installed')) {
echo '<!DOCTYPE html><html lang="de"><head><meta charset="UTF-8">';
echo '<meta name="viewport" content="width=device-width, initial-scale=1.0">';
echo '<title>Startfehler</title>';
echo '<script src="https://cdn.tailwindcss.com"></script></head>';
echo '<body class="min-h-screen bg-gray-100 flex items-center justify-center p-4">';
echo '<div class="max-w-2xl w-full bg-white rounded-lg shadow-md p-6">';
echo '<h1 class="text-lg font-bold text-red-700 mb-3">Fehler beim Starten der Anwendung</h1>';
echo '<div class="bg-red-50 border border-red-200 rounded p-4 mb-4">';
// Urspruenglichen Fehler anzeigen (nicht den kaskadierenden Folgefehler)
$rootCause = $e;
while ($rootCause->getPrevious() !== null) {
$rootCause = $rootCause->getPrevious();
}
echo '<p class="text-sm font-medium text-red-800">' . htmlspecialchars($rootCause->getMessage()) . '</p>';
echo '<p class="text-xs text-red-600 mt-1">Datei: ' . htmlspecialchars($rootCause->getFile()) . ':' . $rootCause->getLine() . '</p>';
echo '</div>';
if ($rootCause !== $e) {
echo '<div class="bg-yellow-50 border border-yellow-200 rounded p-3 mb-3">';
echo '<p class="text-xs text-yellow-800">Folgefehler: ' . htmlspecialchars($e->getMessage()) . '</p>';
echo '</div>';
}
echo '<details class="mb-4"><summary class="text-sm text-gray-600 cursor-pointer">Stack-Trace anzeigen</summary>';
echo '<pre class="mt-2 text-xs bg-gray-50 p-3 rounded overflow-x-auto max-h-64 overflow-y-auto">';
echo htmlspecialchars($rootCause->getTraceAsString());
echo '</pre></details>';
echo '<a href="/" class="inline-block px-4 py-2 text-sm font-medium text-white bg-blue-600 rounded hover:bg-blue-700">Erneut versuchen</a>';
echo '</div></body></html>';
}
}