- Rückmeldungen an den Hersteller (docs/specs/feedback.md): Fehlerbericht und
Funktionswunsch, nur freigeschaltete Wege, Idempotency-Key je Meldung,
Warteschlange mit höchstens fünf Versuchen, 422 am Feld, 429 mit Wartezeit,
404 blendet den Weg aus, Referenznummer und „Meine Rückmeldungen“,
sichtbare technische Angaben und Datenschutzhinweis über dem Absendeknopf
- Hintergrundaufgaben ohne Dauerprozess: Cron, Web-Cron (/cron/{token}) oder
Pseudo-Cron nach dem Seitenaufruf; Queue in kurzen Häppchen
- Seite „Systemzustand“ mit Voraussetzungen, Grenzen, Betrieb, Sicherheit und
Anleitung für den Cronjob
- Web-Installer (Systemprüfung → Datenbank → Administrator), legt .env und
Anwendungsschlüssel selbst an, arbeitet vor der Einrichtung ohne Datenbank
- Datenbank-Benachrichtigungen im Admin-Bereich
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
160 lines
6.7 KiB
PHP
160 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\User;
|
|
use App\Support\Audit;
|
|
use App\Support\EnvFile;
|
|
use App\Support\Installation;
|
|
use App\Support\License\LicenseStore;
|
|
use App\Support\Settings;
|
|
use App\Support\SiteHealth;
|
|
use App\Support\Update\Migrations;
|
|
use Illuminate\Http\RedirectResponse;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Artisan;
|
|
use Illuminate\Validation\Rules\Password;
|
|
use Illuminate\View\View;
|
|
use PDO;
|
|
use Throwable;
|
|
|
|
/**
|
|
* Web-Installer: Systemprüfung → Datenbank → Administrator. Nur erreichbar,
|
|
* solange die Installation nicht eingerichtet ist.
|
|
*/
|
|
class InstallController extends Controller
|
|
{
|
|
public function __construct()
|
|
{
|
|
abort_if(Installation::isInstalled(), 404);
|
|
}
|
|
|
|
public function requirements(SiteHealth $health): View
|
|
{
|
|
$checks = $health->requirements();
|
|
|
|
return view('install.requirements', [
|
|
'checks' => $checks,
|
|
'canContinue' => collect($checks)->doesntContain('status', SiteHealth::ERROR) && is_file(app()->environmentFilePath()),
|
|
'envWritable' => is_file(app()->environmentFilePath()) && is_writable(app()->environmentFilePath()),
|
|
]);
|
|
}
|
|
|
|
public function database(): View
|
|
{
|
|
return view('install.database', [
|
|
'values' => [
|
|
'host' => config('database.connections.mysql.host', 'localhost'),
|
|
'port' => config('database.connections.mysql.port', 3306),
|
|
'database' => config('database.connections.mysql.database'),
|
|
'username' => config('database.connections.mysql.username'),
|
|
],
|
|
]);
|
|
}
|
|
|
|
public function saveDatabase(Request $request): RedirectResponse
|
|
{
|
|
$data = $request->validate([
|
|
'host' => ['required', 'string', 'max:255'],
|
|
'port' => ['required', 'integer', 'between:1,65535'],
|
|
'database' => ['required', 'string', 'max:64'],
|
|
'username' => ['required', 'string', 'max:255'],
|
|
'password' => ['nullable', 'string', 'max:255'],
|
|
], attributes: ['host' => 'Server', 'port' => 'Port', 'database' => 'Datenbank', 'username' => 'Benutzer', 'password' => 'Passwort']);
|
|
|
|
try {
|
|
$pdo = new PDO(
|
|
"mysql:host={$data['host']};port={$data['port']};dbname={$data['database']};charset=utf8mb4",
|
|
$data['username'],
|
|
$data['password'] ?? '',
|
|
[PDO::ATTR_TIMEOUT => 5, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION],
|
|
);
|
|
$version = (string) $pdo->query('select version()')->fetchColumn();
|
|
} catch (Throwable $e) {
|
|
return back()->withInput($request->except('password'))
|
|
->withErrors(['host' => 'Verbindung fehlgeschlagen: '.$this->pdoMessage($e->getMessage())]);
|
|
}
|
|
|
|
$mariadb = str_contains(strtolower($version), 'mariadb');
|
|
$number = preg_replace('/^(\d+\.\d+\.\d+).*$/', '$1', $version);
|
|
|
|
if (! version_compare($number, $mariadb ? '10.6.0' : '8.0.0', '>=')) {
|
|
return back()->withInput($request->except('password'))
|
|
->withErrors(['host' => ($mariadb ? 'MariaDB ' : 'MySQL ').$number.' wird nicht unterstützt. Benötigt wird MySQL ab 8.0 oder MariaDB ab 10.6.']);
|
|
}
|
|
|
|
EnvFile::set(app()->environmentFilePath(), [
|
|
'APP_URL' => $request->getSchemeAndHttpHost().$request->getBaseUrl(),
|
|
'DB_CONNECTION' => 'mysql',
|
|
'DB_HOST' => $data['host'],
|
|
'DB_PORT' => (string) $data['port'],
|
|
'DB_DATABASE' => $data['database'],
|
|
'DB_USERNAME' => $data['username'],
|
|
'DB_PASSWORD' => $data['password'] ?? '',
|
|
]);
|
|
|
|
return redirect('/install/konto');
|
|
}
|
|
|
|
public function account(): View|RedirectResponse
|
|
{
|
|
return view('install.account');
|
|
}
|
|
|
|
public function saveAccount(Request $request, Settings $settings, LicenseStore $license, Migrations $migrations): RedirectResponse
|
|
{
|
|
$data = $request->validate([
|
|
'portal_name' => ['required', 'string', 'max:60'],
|
|
'first_name' => ['required', 'string', 'max:100'],
|
|
'last_name' => ['required', 'string', 'max:100'],
|
|
'email' => ['required', 'email', 'max:255'],
|
|
'password' => ['required', 'confirmed', Password::min(10)->letters()->numbers()],
|
|
'license_email' => ['nullable', 'email', 'max:255', 'required_with:license_key'],
|
|
'license_key' => ['nullable', 'string', 'max:500', 'required_with:license_email'],
|
|
], attributes: [
|
|
'portal_name' => 'Name des Portals', 'first_name' => 'Vorname', 'last_name' => 'Nachname',
|
|
'email' => 'E-Mail-Adresse', 'password' => 'Passwort',
|
|
'license_email' => 'Lizenz-E-Mail', 'license_key' => 'Lizenzschlüssel',
|
|
]);
|
|
|
|
@set_time_limit(300);
|
|
|
|
try {
|
|
Artisan::call('migrate', ['--force' => true]);
|
|
} catch (Throwable $e) {
|
|
return back()->withInput($request->except('password', 'password_confirmation', 'license_key'))
|
|
->withErrors(['portal_name' => 'Die Datenbank konnte nicht eingerichtet werden: '.$e->getMessage()]);
|
|
}
|
|
|
|
$admin = User::query()->updateOrCreate(['email' => strtolower($data['email'])], [
|
|
'first_name' => $data['first_name'],
|
|
'last_name' => $data['last_name'],
|
|
'password' => $data['password'],
|
|
'is_admin' => true,
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$settings->set('branding.portal_name', $data['portal_name']);
|
|
|
|
if (filled($data['license_email'] ?? null)) {
|
|
$license->setLicense($data['license_email'], $data['license_key']);
|
|
}
|
|
|
|
$license->deviceId();
|
|
file_put_contents(storage_path('.migrations-fingerprint'), $migrations->fingerprint());
|
|
Installation::markInstalled();
|
|
Audit::log('install.completed', ['portal_name' => $data['portal_name']], $admin->id);
|
|
|
|
return redirect('/login')->with('status', 'Die Einrichtung ist abgeschlossen. Sie können sich jetzt anmelden.');
|
|
}
|
|
|
|
private function pdoMessage(string $message): string
|
|
{
|
|
return match (true) {
|
|
str_contains($message, 'Access denied') => 'Benutzername oder Passwort sind falsch, oder der Benutzer hat keinen Zugriff auf diese Datenbank.',
|
|
str_contains($message, 'Unknown database') => 'Die Datenbank existiert nicht. Bitte zuerst beim Hoster anlegen.',
|
|
str_contains($message, 'getaddrinfo'), str_contains($message, 'Connection refused'), str_contains($message, 'timed out') => 'Der Datenbankserver ist nicht erreichbar. Bitte Server und Port prüfen.',
|
|
default => $message,
|
|
};
|
|
}
|
|
}
|