Loheide-eu-mitarbeiterplatt.../app/Support/Update/InstalledVersion.php
Friederich Loheide 43244d751a 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>
2026-09-26 06:02:19 +00:00

60 lines
1.5 KiB
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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');
}
}