*/ public function requirements(): array { $checks = []; $checks[] = $this->check( 'PHP-Version', version_compare(PHP_VERSION, self::MIN_PHP, '>='), 'PHP '.PHP_VERSION, 'Benötigt wird mindestens PHP '.self::MIN_PHP.'. Die Version lässt sich meist in der Verwaltung des Hosters umstellen.', ); $missing = array_values(array_filter(self::REQUIRED_EXTENSIONS, fn (string $ext) => ! extension_loaded($ext))); $checks[] = $this->check( 'PHP-Erweiterungen', $missing === [], 'Alle vorhanden', 'Es fehlen: '.implode(', ', $missing).'. Bitte beim Hoster aktivieren.', ); $gd = function_exists('gd_info') ? gd_info() : []; $formats = array_filter(['JPEG' => $gd['JPEG Support'] ?? false, 'PNG' => $gd['PNG Support'] ?? false, 'WebP' => $gd['WebP Support'] ?? false], fn ($supported) => ! $supported); $checks[] = $this->check( 'Bildverarbeitung (GD)', $gd !== [] && $formats === [], 'JPEG, PNG und WebP', $gd === [] ? 'Die PHP-Erweiterung „gd“ fehlt – Profilbilder und Titelbilder lassen sich nicht hochladen.' : 'GD kann kein '.implode(', ', array_keys($formats)).' – Profilbilder und Titelbilder lassen sich so nicht hochladen. Bitte beim Hoster eine GD-Version mit '.implode(', ', array_keys($formats)).'-Unterstützung aktivieren.', ); $checks[] = [ 'label' => 'Ausgehende Verbindungen', 'status' => function_exists('curl_init') || ini_get('allow_url_fopen') ? self::OK : self::WARNING, 'message' => function_exists('curl_init') ? 'cURL verfügbar' : 'Weder cURL noch allow_url_fopen – Updates sind so nicht möglich.', ]; foreach (['storage' => storage_path(), 'bootstrap/cache' => base_path('bootstrap/cache'), 'public/uploads' => public_path('uploads')] as $label => $path) { $checks[] = $this->check( "Schreibrechte: {$label}", $this->writable($path), 'Beschreibbar', "Das Verzeichnis {$label} muss für den Webserver beschreibbar sein.", ); } $checks[] = [ 'label' => 'Schreibrechte für Updates', 'status' => $this->writable(base_path('app')) && $this->writable(base_path('vendor')) && $this->writable(public_path('build')) ? self::OK : self::WARNING, 'message' => $this->writable(base_path('app')) ? 'Programmdateien sind beschreibbar – Aktualisierungen per Klick funktionieren.' : 'Programmdateien sind nicht beschreibbar – Aktualisierungen per Klick sind so nicht möglich.', ]; return $checks; } /** * Alle Prüfungen für die Seite „Systemzustand“. * * @return array> */ public function all(): array { return [ 'Voraussetzungen' => $this->requirements(), 'Leistung und Grenzen' => $this->performance(), 'Betrieb' => $this->operations(), 'Sicherheit' => $this->security(), ]; } /** * @return list */ private function performance(): array { $opcache = function_exists('opcache_get_status') && @opcache_get_status(false); $memory = self::bytes((string) ini_get('memory_limit')); $upload = min(self::bytes((string) ini_get('upload_max_filesize')), self::bytes((string) ini_get('post_max_size'))); return [ [ 'label' => 'OPcache', 'status' => $opcache ? self::OK : self::WARNING, 'message' => $opcache ? 'Aktiv' : 'Nicht aktiv – das Portal läuft deutlich langsamer. Bitte beim Hoster aktivieren.', ], [ 'label' => 'Arbeitsspeicher (memory_limit)', 'status' => $memory === -1 || $memory >= 128 * 1024 ** 2 ? self::OK : self::WARNING, 'message' => ini_get('memory_limit').($memory !== -1 && $memory < 128 * 1024 ** 2 ? ' – empfohlen sind mindestens 128M.' : ''), ], [ 'label' => 'Maximale Upload-Größe', 'status' => $upload === -1 || $upload >= 8 * 1024 ** 2 ? self::OK : self::WARNING, 'message' => ini_get('upload_max_filesize').' / '.ini_get('post_max_size').($upload !== -1 && $upload < 8 * 1024 ** 2 ? ' – für Fotos sind mindestens 8M empfohlen.' : ''), ], $this->databaseCheck(), ]; } /** * @return list */ private function operations(): array { $beats = app(BackgroundTasks::class)->heartbeats(); $cron = max($beats['cron'] ?? 0, $beats['webcron'] ?? 0); $pseudo = $beats['pseudo'] ?? 0; $background = match (true) { now()->getTimestamp() - $cron < 600 => ['status' => self::OK, 'message' => 'Läuft per '.(($beats['cron'] ?? 0) >= ($beats['webcron'] ?? 0) ? 'Cron' : 'Web-Cron').', zuletzt '.$this->ago($cron).'.'], $pseudo > 0 => ['status' => self::WARNING, 'message' => 'Läuft nur beim Seitenaufruf (Pseudo-Cron), zuletzt '.$this->ago($pseudo).'. Zuverlässiger ist ein Cronjob.'], default => ['status' => self::WARNING, 'message' => 'Noch kein Lauf erkannt. Bitte einen Cronjob einrichten (siehe unten).'], }; try { $pending = count(app(Migrations::class)->pending()); } catch (Throwable) { $pending = null; } $license = app(LicenseStore::class); $code = $license->lastStatus()['error_code'] ?? null; return [ ['label' => 'Hintergrundaufgaben', ...$background], [ 'label' => 'Datenbank-Migrationen', 'status' => $pending === 0 ? self::OK : ($pending === null ? self::ERROR : self::WARNING), 'message' => match (true) { $pending === null => 'Status kann nicht gelesen werden.', $pending === 0 => 'Alle angewendet.', default => "{$pending} ausstehend – unter „Aktualisierung“ ausführen.", }, ], [ 'label' => 'Lizenz', 'status' => ! $license->hasLicense() || $code ? self::WARNING : self::OK, 'message' => match (true) { ! $license->hasLicense() => 'Keine Lizenz hinterlegt – Updates sind nicht möglich.', $code !== null => ServerMessages::for(new ServerError($code, 0, $code)), default => 'Hinterlegt.', }, ], [ 'label' => 'Wartungsmodus', 'status' => app(MaintenanceFlag::class)->isActive() ? self::WARNING : self::OK, 'message' => app(MaintenanceFlag::class)->isActive() ? 'Aktiv – es läuft gerade eine Aktualisierung.' : 'Aus', ], ]; } /** * @return list */ private function security(): array { $https = str_starts_with((string) config('app.url'), 'https://'); return [ [ 'label' => 'Fehlerdetails (APP_DEBUG)', 'status' => match (true) { config('app.debug') && app()->isProduction() => self::ERROR, (bool) config('app.debug') => self::WARNING, default => self::OK, }, 'message' => config('app.debug') ? 'Eingeschaltet – im Betrieb unbedingt ausschalten, sonst werden interne Details angezeigt.' : 'Ausgeschaltet', ], [ 'label' => 'Verschlüsselte Verbindung', 'status' => $https ? self::OK : self::WARNING, 'message' => $https ? 'Das Portal läuft über HTTPS.' : 'APP_URL beginnt nicht mit https:// – Anmeldedaten würden unverschlüsselt übertragen.', ], [ 'label' => 'Anwendungsschlüssel', 'status' => filled(config('app.key')) ? self::OK : self::ERROR, 'message' => filled(config('app.key')) ? 'Gesetzt' : 'APP_KEY fehlt.', ], ]; } /** * @return array{label: string, status: string, message: string} */ private function databaseCheck(): array { try { $version = (string) DB::selectOne('select version() as v')->v; $mariadb = str_contains(strtolower($version), 'mariadb'); $number = preg_replace('/^(\d+\.\d+\.\d+).*$/', '$1', $version); $ok = version_compare($number, $mariadb ? '10.6.0' : '8.0.0', '>='); return [ 'label' => 'Datenbank', 'status' => $ok ? self::OK : self::WARNING, 'message' => ($mariadb ? 'MariaDB ' : 'MySQL ').$number.($ok ? '' : ' – unterstützt werden MySQL ab 8.0 und MariaDB ab 10.6.'), ]; } catch (Throwable) { return ['label' => 'Datenbank', 'status' => self::ERROR, 'message' => 'Keine Verbindung.']; } } /** * @return array{label: string, status: string, message: string} */ private function check(string $label, bool $ok, string $okMessage, string $errorMessage): array { return ['label' => $label, 'status' => $ok ? self::OK : self::ERROR, 'message' => $ok ? $okMessage : $errorMessage]; } private function writable(string $path): bool { return is_dir($path) ? is_writable($path) : is_writable(dirname($path)); } private function ago(int $timestamp): string { return Carbon::createFromTimestamp($timestamp)->locale('de')->diffForHumans(); } public static function bytes(string $value): int { $value = trim($value); if ($value === '' || $value === '-1') { return -1; } $number = (int) $value; return match (strtolower(substr($value, -1))) { 'g' => $number * 1024 ** 3, 'm' => $number * 1024 ** 2, 'k' => $number * 1024, default => $number, }; } }