Umsetzung von docs/specs/self-updater.md für Laravel: - Installierter Stand als SHA in storage/.version, Fortschritt in storage/.update-progress, selbstheilender Wartungsmodus in storage/.maintenance - Update-Client je Kanal (stable/development), nur HTTPS, begrenzte Redirects, ZIP-Download per Stream mit PK- und SHA-256-Prüfung - Entpacken mit zweistufigem ZIP-Slip-Schutz, Übernahme mit geschützten Pfaden (atomar je Datei, nie löschen), Migrationen, Cache- und OPcache-Reset - Lizenzspeicher außerhalb der DB, Geräte-ID als Zufallszahl, rotierendes Gerätetoken wird bei jeder Antwort (auch Fehler und Downloads) sofort gespeichert - Lizenzfehler mit verständlichen Meldungen – sie sperren nie das Portal - Seite „Aktualisierung“ mit Kanal, Suche, Changelog-Vorschau, Fortschritt, Migrationen, Änderungsprotokoll, Lizenz und Datenschutzhinweis - Wartungs-Middleware (503 + Retry-After) und Auto-Migration per Fingerabdruck - Audit-Log für Updates, Kanalwechsel und Lizenzänderungen - Version 0.2.0 Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
131 lines
4.5 KiB
PHP
131 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages;
|
|
|
|
use App\Support\Audit;
|
|
use App\Support\License\LicenseService;
|
|
use App\Support\License\LicenseStore;
|
|
use App\Support\License\ServerError;
|
|
use App\Support\License\ServerMessages;
|
|
use App\Support\Update\Changelog;
|
|
use App\Support\Update\Channels;
|
|
use App\Support\Update\InstalledVersion;
|
|
use App\Support\Update\Migrations;
|
|
use App\Support\Update\UpdateProgress;
|
|
use BackedEnum;
|
|
use Filament\Notifications\Notification;
|
|
use Filament\Pages\Page;
|
|
use Filament\Support\Icons\Heroicon;
|
|
use Throwable;
|
|
use UnitEnum;
|
|
|
|
/**
|
|
* Seite „Aktualisierung“: Version, Kanal, Update-Suche und -Installation,
|
|
* Migrationen, Änderungsprotokoll und Lizenz (docs/specs/self-updater.md).
|
|
*/
|
|
class Updates extends Page
|
|
{
|
|
protected string $view = 'filament.pages.updates';
|
|
|
|
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedArrowPathRoundedSquare;
|
|
|
|
protected static string|UnitEnum|null $navigationGroup = 'System';
|
|
|
|
protected static ?int $navigationSort = 10;
|
|
|
|
protected static ?string $navigationLabel = 'Aktualisierung';
|
|
|
|
protected static ?string $title = 'Aktualisierung';
|
|
|
|
protected static ?string $slug = 'aktualisierung';
|
|
|
|
public string $licenseEmail = '';
|
|
|
|
public string $licenseKey = '';
|
|
|
|
public ?string $licenseError = null;
|
|
|
|
public function mount(LicenseStore $license): void
|
|
{
|
|
$this->licenseEmail = (string) $license->email();
|
|
}
|
|
|
|
public function saveLicense(LicenseStore $license, LicenseService $service): void
|
|
{
|
|
$this->validate([
|
|
'licenseEmail' => ['required', 'email', 'max:255'],
|
|
'licenseKey' => [$license->hasLicense() ? 'nullable' : 'required', 'string', 'max:500'],
|
|
], attributes: ['licenseEmail' => 'Lizenz-E-Mail', 'licenseKey' => 'Lizenzschlüssel']);
|
|
|
|
$license->setLicense($this->licenseEmail, filled($this->licenseKey) ? $this->licenseKey : (string) $license->key());
|
|
$this->licenseKey = '';
|
|
Audit::log('license.saved', ['email' => $this->licenseEmail]);
|
|
|
|
$this->checkLicense($service);
|
|
}
|
|
|
|
public function checkLicense(LicenseService $service): void
|
|
{
|
|
$this->licenseError = null;
|
|
|
|
try {
|
|
$service->check();
|
|
|
|
Notification::make()->success()->title('Lizenz geprüft')->send();
|
|
} catch (ServerError $e) {
|
|
$this->licenseError = ServerMessages::for($e);
|
|
} catch (Throwable $e) {
|
|
$this->licenseError = 'Die Lizenz konnte nicht geprüft werden: '.$e->getMessage();
|
|
}
|
|
}
|
|
|
|
public function releaseDevice(LicenseService $service, LicenseStore $license): void
|
|
{
|
|
try {
|
|
$service->releaseDevice();
|
|
Audit::log('license.device_released', ['device_label' => $license->deviceLabel()]);
|
|
|
|
Notification::make()
|
|
->success()
|
|
->title('Installation abgemeldet')
|
|
->body('Der Geräteplatz ist wieder frei. Updates sind erst nach erneuter Lizenzprüfung wieder möglich.')
|
|
->send();
|
|
} catch (ServerError $e) {
|
|
Notification::make()->danger()->title('Abmelden fehlgeschlagen')->body(ServerMessages::for($e))->send();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
protected function getViewData(): array
|
|
{
|
|
$version = app(InstalledVersion::class);
|
|
$license = app(LicenseStore::class);
|
|
$channels = app(Channels::class);
|
|
|
|
try {
|
|
$migrations = app(Migrations::class)->status();
|
|
} catch (Throwable) {
|
|
$migrations = [];
|
|
}
|
|
|
|
return [
|
|
'release' => $version->release(),
|
|
'shortSha' => $version->short(),
|
|
'channels' => $channels->all(),
|
|
'activeChannel' => $channels->active(),
|
|
'progress' => app(UpdateProgress::class)->get(),
|
|
'migrations' => $migrations,
|
|
'pendingMigrations' => count(array_filter($migrations, fn (array $m) => ! $m['ran'])),
|
|
'changelog' => app(Changelog::class)->sections(),
|
|
'hasLicense' => $license->hasLicense(),
|
|
'maskedKey' => ($key = $license->key()) ? str_repeat('•', 8).substr($key, -4) : null,
|
|
'licenseSummary' => app(LicenseService::class)->summary(),
|
|
'licenseStatusError' => ($code = $license->lastStatus()['error_code'] ?? null)
|
|
? ServerMessages::for(new ServerError($code, 0, $code))
|
|
: null,
|
|
'deviceLabel' => $license->deviceLabel(),
|
|
];
|
|
}
|
|
}
|