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
59
app/Support/Update/MaintenanceFlag.php
Normal file
59
app/Support/Update/MaintenanceFlag.php
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\Update;
|
||||
|
||||
/**
|
||||
* Wartungsmodus während eines Updates als Flag-Datei storage/.maintenance.
|
||||
*
|
||||
* Selbstheilend: Ein abgelaufenes „until“ wird beim Prüfen entfernt. Ohne das
|
||||
* würde ein Absturz mitten im Update die Installation dauerhaft sperren – und
|
||||
* niemand käme mehr an die Oberfläche, um den Modus abzuschalten.
|
||||
*/
|
||||
class MaintenanceFlag
|
||||
{
|
||||
public function __construct(private readonly ?string $file = null) {}
|
||||
|
||||
public function activate(int $maxSeconds = 600): void
|
||||
{
|
||||
AtomicFile::write($this->path(), json_encode([
|
||||
'since' => time(),
|
||||
'until' => time() + $maxSeconds,
|
||||
]));
|
||||
}
|
||||
|
||||
public function deactivate(): void
|
||||
{
|
||||
@unlink($this->path());
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
if (! is_file($this->path())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$data = json_decode((string) @file_get_contents($this->path()), true);
|
||||
$until = is_array($data) ? (int) ($data['until'] ?? 0) : 0;
|
||||
|
||||
if ($until <= time()) {
|
||||
$this->deactivate();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function retryAfter(): int
|
||||
{
|
||||
$data = json_decode((string) @file_get_contents($this->path()), true);
|
||||
$remaining = is_array($data) ? (int) ($data['until'] ?? 0) - time() : 0;
|
||||
|
||||
return max(5, min(60, $remaining));
|
||||
}
|
||||
|
||||
private function path(): string
|
||||
{
|
||||
return $this->file ?? storage_path('.maintenance');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue