Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m30s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m28s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m31s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m36s
CI / PHP 8.3 / mysql:8.0 (pull_request) Failing after 1m45s
CI / PHP 8.4 / mysql:8.0 (pull_request) Failing after 1m44s
CI / PHP 8.3 / mysql:8.4 (pull_request) Failing after 1m35s
CI / PHP 8.4 / mysql:8.4 (pull_request) Failing after 1m38s
CI / Build-Artefakte aktuell (pull_request) Successful in 54s
- Rollen mit globalen Rechten und Rechten für einzelne Objekte (z. B. „Beiträge schreiben in Kategorie MAV-Info“); Rollen sind additiv, Zuweisungen merken sich ihre Herkunft (manuell oder später Identity-Provider-Gruppe) - Systemrolle „Administration“ ersetzt users.is_admin (Migration übernimmt bestehende Administratoren); nicht löschbar, man kann sie sich nicht selbst entziehen - Rechte je Person vorberechnet und gecacht, Versionszähler invalidiert bei Änderungen - Gate-Anbindung: registrierte Rechte entscheidet das Rechtesystem, Objektregeln die Policies; Admin-Seiten und Plugin-Ressourcen hinter passenden Rechten - Redaktion nach Kategorie: Schreiben und Veröffentlichen getrennt, Liste im Admin auf eigene Kategorien beschränkt, ohne Veröffentlichungsrecht bleibt ein Beitrag Entwurf - Zielgruppen (Rolle/Abteilung/Standort) für Kategorien und Termine als indizierte SQL-Bedingung in Listen, Detailseiten, Kacheln und .ics-Export - Admin: Rollen-Verwaltung, „Rechte prüfen“, Redaktion und Sichtbarkeit direkt an Kategorie bzw. Termin - Kern-Ressourcen explizit registriert, damit nach Updates liegengebliebene alte Dateien nicht doppelt geladen werden - docs/PLUGINS.md für Plugin-Entwicklung; Demo-Rolle „MAV“ Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
162 lines
6.7 KiB
PHP
162 lines
6.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Models\Role;
|
|
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_active' => true,
|
|
]);
|
|
|
|
$admin->syncManualRoles([Role::administration()->id]);
|
|
$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);
|
|
|
|
// Kein Flash: Ab jetzt liegen die Sitzungen in der Datenbank, die bisherige Sitzung ist weg.
|
|
return redirect('/login?eingerichtet=1');
|
|
}
|
|
|
|
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,
|
|
};
|
|
}
|
|
}
|