Self-Updater und Lizenzprüfung

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>
This commit is contained in:
Friederich Loheide 2026-09-26 06:02:19 +00:00
parent a36752e09a
commit 43244d751a
41 changed files with 3184 additions and 3 deletions

View file

@ -0,0 +1,65 @@
<?php
namespace App\Support\Update;
use App\Support\License\VendorHttp;
use App\Support\Settings;
use InvalidArgumentException;
use Throwable;
/**
* Update-Kanäle: Auswahl persistiert in den Einstellungen (Standard „stable“),
* Factory für den Client des aktiven oder eines übergebenen Kanals.
*/
class Channels
{
public function __construct(
private readonly Settings $settings,
private readonly VendorHttp $http,
) {}
/**
* @return array<string, string> Schlüssel => Bezeichnung
*/
public function all(): array
{
return collect(config('updater.channels'))->map(fn (array $c) => $c['label'])->all();
}
public function active(): string
{
try {
$channel = $this->settings->get('updater.channel');
} catch (Throwable) {
$channel = null; // Datenbank nicht erreichbar – Standardkanal.
}
return is_string($channel) && $this->exists($channel) ? $channel : config('updater.default_channel', 'stable');
}
public function setActive(string $channel): void
{
$this->assertExists($channel);
$this->settings->set('updater.channel', $channel);
}
public function client(?string $channel = null): UpdateClient
{
$channel ??= $this->active();
$this->assertExists($channel);
return new UpdateClient($this->http, config("updater.channels.{$channel}.url"));
}
public function exists(string $channel): bool
{
return is_array(config("updater.channels.{$channel}"));
}
private function assertExists(string $channel): void
{
if (! $this->exists($channel)) {
throw new InvalidArgumentException("Unbekannter Update-Kanal: {$channel}");
}
}
}