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>
360 lines
20 KiB
PHP
360 lines
20 KiB
PHP
<x-filament-panels::page>
|
||
<style>
|
||
.ih-stack { display: grid; gap: 1.5rem; }
|
||
.ih-row { display: flex; flex-wrap: wrap; align-items: center; gap: .75rem 1.5rem; }
|
||
.ih-muted { color: rgb(107 114 128); font-size: .875rem; }
|
||
.ih-strong { font-weight: 600; }
|
||
.ih-big { font-size: 1.5rem; font-weight: 600; letter-spacing: -.01em; }
|
||
.ih-progress { height: .5rem; border-radius: 999px; background: rgb(229 231 235); overflow: hidden; }
|
||
.ih-progress > div { height: 100%; background: var(--primary-600); transition: width .4s ease; }
|
||
.ih-prose { font-size: .875rem; line-height: 1.6; }
|
||
.ih-prose ul { list-style: disc; padding-left: 1.25rem; margin: .25rem 0; }
|
||
.ih-prose p { margin: .25rem 0; }
|
||
.ih-prose a { color: var(--primary-600); text-decoration: underline; }
|
||
.ih-entry + .ih-entry { border-top: 1px solid rgb(229 231 235); padding-top: 1rem; margin-top: 1rem; }
|
||
.ih-privacy { font-size: .8125rem; line-height: 1.55; color: rgb(75 85 99); border-left: 3px solid rgb(209 213 219); padding: .25rem 0 .25rem 1rem; }
|
||
.ih-privacy ul { list-style: disc; padding-left: 1.25rem; margin: .5rem 0; }
|
||
.ih-privacy p { margin: .5rem 0; }
|
||
.ih-table { width: 100%; font-size: .875rem; border-collapse: collapse; }
|
||
.ih-table td { padding: .375rem 0; border-bottom: 1px solid rgb(243 244 246); }
|
||
.ih-grid2 { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(16rem, 1fr)); }
|
||
.ih-select { border: 1px solid rgb(209 213 219); border-radius: .5rem; padding: .375rem 2rem .375rem .75rem; font-size: .875rem; background-color: transparent; }
|
||
.dark .ih-muted, .dark .ih-privacy { color: rgb(156 163 175); }
|
||
.dark .ih-progress { background: rgb(55 65 81); }
|
||
.dark .ih-entry + .ih-entry, .dark .ih-table td { border-color: rgb(55 65 81); }
|
||
</style>
|
||
|
||
<script>
|
||
function updater({ csrf, progress, channel }) {
|
||
return {
|
||
csrf,
|
||
progress,
|
||
channel,
|
||
result: null,
|
||
error: null,
|
||
checking: false,
|
||
installing: false,
|
||
migrationMessage: '',
|
||
timer: null,
|
||
|
||
get busy() {
|
||
return this.checking || this.installing;
|
||
},
|
||
|
||
init() {
|
||
// Seite während eines laufenden Updates neu geladen: weiter beobachten.
|
||
if (!['idle', 'done', 'error'].includes(this.progress.step)) {
|
||
this.installing = true;
|
||
this.poll();
|
||
}
|
||
},
|
||
|
||
async post(url, body = {}) {
|
||
const response = await fetch(url, {
|
||
method: 'POST',
|
||
headers: { 'Content-Type': 'application/json', Accept: 'application/json', 'X-CSRF-TOKEN': this.csrf },
|
||
body: JSON.stringify(body),
|
||
});
|
||
|
||
return response.json().catch(() => ({ ok: false, message: `Unerwartete Antwort (HTTP ${response.status}).` }));
|
||
},
|
||
|
||
async check() {
|
||
this.checking = true;
|
||
this.error = null;
|
||
this.result = null;
|
||
|
||
try {
|
||
const data = await this.post('/admin/update/check');
|
||
data.ok ? (this.result = data.result) : (this.error = data.message);
|
||
|
||
if (data.license_input) {
|
||
this.error += ' Die Lizenzdaten können unten eingegeben werden.';
|
||
}
|
||
} catch (e) {
|
||
this.error = 'Die Update-Suche konnte nicht ausgeführt werden.';
|
||
} finally {
|
||
this.checking = false;
|
||
}
|
||
},
|
||
|
||
updateSummary() {
|
||
const r = this.result;
|
||
const parts = [];
|
||
|
||
parts.push(r.version ? `Version ${r.version} (${r.latest_short})` : `Stand ${r.latest_short}`);
|
||
|
||
if (r.released_at) {
|
||
parts.push(`veröffentlicht am ${new Date(r.released_at).toLocaleDateString('de-DE')}`);
|
||
}
|
||
|
||
if (r.versions_behind > 0) {
|
||
parts.push(`${r.versions_behind} Version(en) zurück`);
|
||
}
|
||
|
||
return parts.join(' · ');
|
||
},
|
||
|
||
async install() {
|
||
if (!confirm('Jetzt aktualisieren? Das Portal ist währenddessen kurz nicht erreichbar.')) {
|
||
return;
|
||
}
|
||
|
||
this.installing = true;
|
||
this.progress = { pct: 0, step: 'maintenance', text: 'Aktualisierung wird gestartet …' };
|
||
this.poll();
|
||
|
||
// Der Server arbeitet weiter, auch wenn diese Anfrage abbricht – maßgeblich ist der Fortschritt.
|
||
this.post('/admin/update/install').catch(() => {});
|
||
},
|
||
|
||
poll() {
|
||
clearTimeout(this.timer);
|
||
this.timer = setTimeout(async () => {
|
||
try {
|
||
const response = await fetch('/admin/update/progress', { headers: { Accept: 'application/json' } });
|
||
this.progress = await response.json();
|
||
} catch (e) {
|
||
// Kurzzeitig nicht erreichbar (z. B. beim Austausch der Dateien) – weiter versuchen.
|
||
}
|
||
|
||
if (this.progress.step === 'done') {
|
||
this.installing = false;
|
||
setTimeout(() => window.location.reload(), 1500);
|
||
} else if (this.progress.step === 'error') {
|
||
this.installing = false;
|
||
} else {
|
||
this.poll();
|
||
}
|
||
}, 2000);
|
||
},
|
||
|
||
async changeChannel() {
|
||
const data = await this.post('/admin/update/channel', { channel: this.channel });
|
||
this.result = null;
|
||
this.error = data.ok ? null : (data.message ?? 'Kanal konnte nicht gespeichert werden.');
|
||
},
|
||
|
||
async runMigrations() {
|
||
this.migrationMessage = 'Läuft …';
|
||
const data = await this.post('/admin/update/migrations');
|
||
this.migrationMessage = data.ok ? `${data.count} Migration(en) ausgeführt.` : data.message;
|
||
|
||
if (data.ok && data.count > 0) {
|
||
setTimeout(() => window.location.reload(), 1200);
|
||
}
|
||
},
|
||
};
|
||
}
|
||
</script>
|
||
|
||
<div
|
||
class="ih-stack"
|
||
x-data="updater({
|
||
csrf: @js(csrf_token()),
|
||
progress: @js($progress),
|
||
channel: @js($activeChannel),
|
||
})"
|
||
x-init="init()"
|
||
>
|
||
{{-- Version und Kanal --}}
|
||
<x-filament::section>
|
||
<div class="ih-row" style="justify-content: space-between">
|
||
<div>
|
||
<div class="ih-muted">Installierte Version</div>
|
||
<div class="ih-big">{{ $release }} @if ($shortSha)<span class="ih-muted" style="font-size: 1rem">({{ $shortSha }})</span>@endif</div>
|
||
</div>
|
||
<label class="ih-row" style="gap: .5rem">
|
||
<span class="ih-muted">Update-Kanal</span>
|
||
<select class="ih-select" x-model="channel" @change="changeChannel()" :disabled="busy">
|
||
@foreach ($channels as $key => $label)
|
||
<option value="{{ $key }}">{{ $label }}</option>
|
||
@endforeach
|
||
</select>
|
||
</label>
|
||
</div>
|
||
</x-filament::section>
|
||
|
||
{{-- Suche und Installation --}}
|
||
<x-filament::section heading="Nach Updates suchen">
|
||
<div class="ih-stack" style="gap: 1rem">
|
||
<div class="ih-row">
|
||
<x-filament::button icon="heroicon-o-magnifying-glass" x-on:click="check()" x-bind:disabled="busy">
|
||
Nach Updates suchen
|
||
</x-filament::button>
|
||
<x-filament::loading-indicator class="h-5 w-5" x-show="checking" x-cloak />
|
||
</div>
|
||
|
||
<template x-if="error">
|
||
<x-filament::callout color="danger" icon="heroicon-o-exclamation-triangle">
|
||
<x-slot name="description"><span x-text="error"></span></x-slot>
|
||
</x-filament::callout>
|
||
</template>
|
||
|
||
<template x-if="result && !result.has_update">
|
||
<x-filament::callout color="success" icon="heroicon-o-check-circle" heading="Sie verwenden die neueste Version." />
|
||
</template>
|
||
|
||
<template x-if="result && result.has_update">
|
||
<div class="ih-stack" style="gap: 1rem">
|
||
<x-filament::callout color="info" icon="heroicon-o-arrow-down-circle" heading="Neue Version verfügbar">
|
||
<x-slot name="description">
|
||
<span x-text="updateSummary()"></span>
|
||
<template x-if="result.channel_switch && result.channel_switch.direction === 'back'">
|
||
<span><br>Hinweis: Der Stand stammt aus einem anderen Kanal und ist älter als der installierte – das ist beim Zurückwechseln normal.</span>
|
||
</template>
|
||
</x-slot>
|
||
</x-filament::callout>
|
||
|
||
<template x-if="result.changelog.length">
|
||
<div>
|
||
<div class="ih-strong" style="margin-bottom: .5rem">Was ist neu?</div>
|
||
<template x-for="entry in result.changelog" :key="entry.heading">
|
||
<div class="ih-entry">
|
||
<div class="ih-strong" x-text="entry.heading"></div>
|
||
<div class="ih-prose" x-html="entry.html"></div>
|
||
</div>
|
||
</template>
|
||
<template x-if="!result.changelog_complete">
|
||
<p class="ih-muted" style="margin-top: .75rem">
|
||
Gekürzt – <a :href="result.changelog_url" target="_blank" rel="noopener" style="text-decoration: underline">vollständiges Änderungsprotokoll</a>
|
||
</p>
|
||
</template>
|
||
</div>
|
||
</template>
|
||
|
||
<div class="ih-row">
|
||
<x-filament::button color="success" icon="heroicon-o-arrow-path" x-on:click="install()" x-bind:disabled="busy">
|
||
Jetzt aktualisieren
|
||
</x-filament::button>
|
||
<span class="ih-muted">Das Portal zeigt währenddessen eine Wartungsseite.</span>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<template x-if="progress.step !== 'idle' && (installing || progress.step === 'error' || progress.step === 'done')">
|
||
<div class="ih-stack" style="gap: .5rem">
|
||
<div class="ih-row" style="justify-content: space-between">
|
||
<span x-text="progress.text"></span>
|
||
<span class="ih-muted" x-show="progress.pct >= 0" x-text="progress.pct + ' %'"></span>
|
||
</div>
|
||
<div class="ih-progress" x-show="progress.pct >= 0"><div :style="`width: ${Math.max(progress.pct, 3)}%`"></div></div>
|
||
<template x-if="progress.step === 'error'">
|
||
<x-filament::callout color="danger" icon="heroicon-o-x-circle" heading="Aktualisierung fehlgeschlagen">
|
||
<x-slot name="description"><span x-text="progress.text"></span> Die bisherige Version läuft weiter.</x-slot>
|
||
</x-filament::callout>
|
||
</template>
|
||
</div>
|
||
</template>
|
||
|
||
{{-- Datenschutzhinweis: dauerhaft sichtbar, Wortlaut nach Vorgabe (docs/specs/self-updater.md). --}}
|
||
<div class="ih-privacy">
|
||
<p>Bei der Suche nach Updates und beim Herunterladen einer neuen Fassung werden Daten an update.loheide.cloud übertragen. Übermittelt werden:</p>
|
||
<ul>
|
||
<li>die auf Ihrer Lizenz hinterlegte E-Mail-Adresse und der Lizenzschlüssel</li>
|
||
<li>eine Gerätekennung, die dieses Programm einmalig als Zufallszahl erzeugt hat (keine Hardwarekennung, keine Seriennummer) – damit wird gezählt, auf wie vielen Geräten die Lizenz genutzt wird</li>
|
||
<li>Rechnername, Betriebssystem und Programmversion, damit Sie Ihre Geräte im Kundenportal auseinanderhalten können</li>
|
||
<li>der bei Ihnen installierte Stand, damit die Gegenstelle weiß, was neu ist</li>
|
||
<li>technisch bedingt: Ihre IP-Adresse, Datum und Uhrzeit des Abrufs</li>
|
||
</ul>
|
||
<p>Zweck: Bereitstellung der Aktualisierung und Prüfung der Lizenz.</p>
|
||
<p>Nicht übertragen werden Inhalte aus diesem Programm: keine Dokumente, keine Datenbank, keine Eingaben. Die Verbindung ist verschlüsselt.</p>
|
||
</div>
|
||
</div>
|
||
</x-filament::section>
|
||
|
||
{{-- Lizenz --}}
|
||
<x-filament::section heading="Lizenz" description="Die Lizenz wird nur für den Bezug von Updates benötigt. Ein Lizenzproblem schränkt die Nutzung des Portals nicht ein.">
|
||
<div class="ih-stack" style="gap: 1.25rem">
|
||
@if ($licenseError || $licenseStatusError)
|
||
<x-filament::callout color="warning" icon="heroicon-o-exclamation-triangle" :description="$licenseError ?? $licenseStatusError" />
|
||
@endif
|
||
|
||
@if ($licenseSummary)
|
||
@if ($licenseSummary['expires_soon'])
|
||
<x-filament::callout color="warning" icon="heroicon-o-clock" heading="Lizenz läuft bald ab" :description="'Noch '.$licenseSummary['days_remaining'].' Tage. Updates stehen danach erst nach einer Verlängerung wieder zur Verfügung.'" />
|
||
@endif
|
||
|
||
<table class="ih-table">
|
||
<tr><td class="ih-muted">Registriert auf</td><td>{{ collect([$licenseSummary['registered_to']['company'] ?? null, $licenseSummary['registered_to']['contact_name'] ?? null])->filter()->implode(' · ') ?: '–' }}</td></tr>
|
||
<tr><td class="ih-muted">Laufzeit</td><td>
|
||
@if ($licenseSummary['unlimited'])
|
||
unbefristet
|
||
@elseif ($licenseSummary['expired'])
|
||
abgelaufen
|
||
@elseif ($licenseSummary['valid_until'])
|
||
bis {{ \Illuminate\Support\Carbon::parse($licenseSummary['valid_until'])->format('d.m.Y') }}@if ($licenseSummary['days_remaining'] !== null) (noch {{ $licenseSummary['days_remaining'] }} Tage)@endif
|
||
@else
|
||
–
|
||
@endif
|
||
</td></tr>
|
||
<tr><td class="ih-muted">Geräteplätze</td><td>{{ $licenseSummary['devices']['used'] ?? '?' }} von {{ $licenseSummary['devices']['max'] ?? '?' }} belegt</td></tr>
|
||
<tr><td class="ih-muted">Diese Installation</td><td>{{ $deviceLabel }}</td></tr>
|
||
</table>
|
||
@endif
|
||
|
||
<form wire:submit="saveLicense" class="ih-stack" style="gap: 1rem">
|
||
<div class="ih-grid2">
|
||
<label>
|
||
<span class="ih-muted">Lizenz-E-Mail</span>
|
||
<x-filament::input.wrapper :valid="! $errors->has('licenseEmail')">
|
||
<x-filament::input type="email" wire:model="licenseEmail" autocomplete="off" />
|
||
</x-filament::input.wrapper>
|
||
@error('licenseEmail') <span class="ih-muted" style="color: rgb(220 38 38)">{{ $message }}</span> @enderror
|
||
</label>
|
||
<label>
|
||
<span class="ih-muted">Lizenzschlüssel @if ($maskedKey)(hinterlegt: {{ $maskedKey }})@endif</span>
|
||
<x-filament::input.wrapper :valid="! $errors->has('licenseKey')">
|
||
<x-filament::input type="password" wire:model="licenseKey" autocomplete="off" :placeholder="$maskedKey ? 'Leer lassen, um ihn zu behalten' : ''" />
|
||
</x-filament::input.wrapper>
|
||
@error('licenseKey') <span class="ih-muted" style="color: rgb(220 38 38)">{{ $message }}</span> @enderror
|
||
</label>
|
||
</div>
|
||
<p class="ih-muted">Die Lizenz-E-Mail ist die Adresse, auf die die Lizenz ausgestellt ist – nicht zwingend Ihre eigene.</p>
|
||
<div class="ih-row">
|
||
<x-filament::button type="submit">Speichern und prüfen</x-filament::button>
|
||
@if ($hasLicense)
|
||
<x-filament::button color="gray" wire:click="checkLicense">Lizenz prüfen</x-filament::button>
|
||
<x-filament::button color="danger" outlined wire:click="releaseDevice" wire:confirm="Diese Installation bei der Lizenz abmelden? Der Geräteplatz wird frei, Updates sind danach erst nach erneuter Prüfung möglich.">
|
||
Diese Installation abmelden
|
||
</x-filament::button>
|
||
@endif
|
||
</div>
|
||
</form>
|
||
</div>
|
||
</x-filament::section>
|
||
|
||
{{-- Migrationen --}}
|
||
<x-filament::section heading="Datenbank" :description="$pendingMigrations ? $pendingMigrations.' ausstehende Migration(en)' : 'Alle Migrationen sind angewendet.'" collapsible :collapsed="! $pendingMigrations">
|
||
<div class="ih-stack" style="gap: 1rem">
|
||
<div class="ih-row">
|
||
<x-filament::button color="gray" icon="heroicon-o-circle-stack" x-on:click="runMigrations()" x-bind:disabled="busy">Migrationen ausführen</x-filament::button>
|
||
<span class="ih-muted" x-text="migrationMessage"></span>
|
||
</div>
|
||
<table class="ih-table">
|
||
@foreach ($migrations as $migration)
|
||
<tr>
|
||
<td style="font-family: ui-monospace, monospace; font-size: .8125rem">{{ $migration['name'] }}</td>
|
||
<td style="text-align: right">
|
||
<x-filament::badge :color="$migration['ran'] ? 'success' : 'warning'">{{ $migration['ran'] ? 'angewendet' : 'offen' }}</x-filament::badge>
|
||
</td>
|
||
</tr>
|
||
@endforeach
|
||
</table>
|
||
</div>
|
||
</x-filament::section>
|
||
|
||
{{-- Änderungsprotokoll --}}
|
||
<x-filament::section heading="Änderungsprotokoll" collapsible>
|
||
@forelse ($changelog as $section)
|
||
<div class="ih-entry">
|
||
<div class="ih-strong">Version {{ $section['heading'] }}</div>
|
||
<div class="ih-prose">{!! $section['html'] !!}</div>
|
||
</div>
|
||
@empty
|
||
<p class="ih-muted">Kein Änderungsprotokoll vorhanden.</p>
|
||
@endforelse
|
||
</x-filament::section>
|
||
</div>
|
||
|
||
</x-filament-panels::page>
|