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:
parent
a36752e09a
commit
43244d751a
41 changed files with 3184 additions and 3 deletions
84
app/Support/License/LicenseService.php
Normal file
84
app/Support/License/LicenseService.php
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\License;
|
||||
|
||||
use App\Support\Update\Channels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
/**
|
||||
* Lizenzauskunft und Geräte-Abmeldung. Ein Lizenzfehler sperrt nie das Programm –
|
||||
* er wird angezeigt und protokolliert, mehr nicht.
|
||||
*/
|
||||
class LicenseService
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LicenseStore $store,
|
||||
private readonly Channels $channels,
|
||||
private readonly VendorHttp $http,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed> Antwort von /license (zusätzlich gespeichert)
|
||||
*
|
||||
* @throws ServerError
|
||||
*/
|
||||
public function check(): array
|
||||
{
|
||||
try {
|
||||
$info = $this->channels->client()->license();
|
||||
$this->store->rememberStatus($info);
|
||||
|
||||
return $info;
|
||||
} catch (ServerError $e) {
|
||||
Log::notice("Lizenzprüfung: {$e->errorCode}");
|
||||
$this->store->rememberStatus(null, $e->errorCode);
|
||||
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt den Geräteplatz dieser Installation frei.
|
||||
*
|
||||
* @throws ServerError
|
||||
*/
|
||||
public function releaseDevice(): void
|
||||
{
|
||||
$response = VendorHttp::guard(fn () => $this->http->request((int) config('updater.timeouts.json'), identifyDevice: false)
|
||||
->post(rtrim(config('updater.api_url'), '/').'/license/release-device?software='.config('updater.software')));
|
||||
|
||||
if (! $response->successful()) {
|
||||
throw VendorHttp::errorFrom($response);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Aufbereitete Lizenzdaten für die Anzeige (aus der letzten Prüfung).
|
||||
*
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function summary(): ?array
|
||||
{
|
||||
$info = $this->store->lastStatus()['info'] ?? null;
|
||||
|
||||
if (! is_array($info)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$license = $info['license'] ?? [];
|
||||
$unlimited = (bool) ($license['unlimited'] ?? false);
|
||||
$days = $license['days_remaining'] ?? null;
|
||||
|
||||
return [
|
||||
'status' => $license['status'] ?? null,
|
||||
// valid_until = null zusammen mit unlimited = true heißt UNBEFRISTET – kein Fehler.
|
||||
'unlimited' => $unlimited,
|
||||
'valid_until' => $license['valid_until'] ?? null,
|
||||
'days_remaining' => is_numeric($days) ? (int) $days : null,
|
||||
'expired' => ! $unlimited && (bool) ($license['expired'] ?? false),
|
||||
'expires_soon' => ! $unlimited && is_numeric($days) && (int) $days >= 0 && (int) $days < 30,
|
||||
'registered_to' => $info['registered_to'] ?? [],
|
||||
'devices' => $info['devices'] ?? [],
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue