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
60
app/Support/Update/InstalledVersion.php
Normal file
60
app/Support/Update/InstalledVersion.php
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
<?php
|
||||
|
||||
namespace App\Support\Update;
|
||||
|
||||
use App\Version;
|
||||
use InvalidArgumentException;
|
||||
|
||||
/**
|
||||
* Installierter Stand als Git-Commit-SHA – bewusst in einer Datei, nicht in der
|
||||
* Datenbank, damit der Updater ihn auch lesen kann, wenn die DB hängt.
|
||||
* storage/ ist ein geschützter Pfad: ein Update überschreibt die Datei nie.
|
||||
*/
|
||||
class InstalledVersion
|
||||
{
|
||||
public function __construct(private readonly ?string $file = null) {}
|
||||
|
||||
public function current(): ?string
|
||||
{
|
||||
$sha = @file_get_contents($this->path());
|
||||
|
||||
return is_string($sha) && self::isSha(trim($sha)) ? strtolower(trim($sha)) : null;
|
||||
}
|
||||
|
||||
public function save(string $sha): void
|
||||
{
|
||||
if (! self::isSha($sha)) {
|
||||
throw new InvalidArgumentException('Ungültiger Commit-Stand: erwartet werden 40 Hex-Zeichen.');
|
||||
}
|
||||
|
||||
AtomicFile::write($this->path(), strtolower($sha));
|
||||
}
|
||||
|
||||
public function short(): ?string
|
||||
{
|
||||
return ($sha = $this->current()) ? substr($sha, 0, 7) : null;
|
||||
}
|
||||
|
||||
public function release(): string
|
||||
{
|
||||
return Version::VERSION;
|
||||
}
|
||||
|
||||
/**
|
||||
* „1.4.2 (a1b2c3d)“ bzw. nur „1.4.2“, solange kein Stand bekannt ist.
|
||||
*/
|
||||
public function full(): string
|
||||
{
|
||||
return $this->release().(($short = $this->short()) ? " ({$short})" : '');
|
||||
}
|
||||
|
||||
public static function isSha(string $value): bool
|
||||
{
|
||||
return (bool) preg_match('/^[0-9a-f]{40}$/i', $value);
|
||||
}
|
||||
|
||||
private function path(): string
|
||||
{
|
||||
return $this->file ?? storage_path('.version');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue