Some checks failed
CI / PHP Lint-1 (push) Successful in 43s
CI / PHP Lint (push) Successful in 45s
CI / PHP Lint (pull_request) Successful in 38s
CI / Unit Tests & Static Analysis (push) Failing after 43s
CI / PHP Lint-1 (pull_request) Successful in 40s
CI / Unit Tests & Static Analysis (pull_request) Failing after 41s
Aktualisierung per Klick im Administrationsbereich, ohne Zugang zum Server. Der bisherige Updater lud ein ZIP und entpackte es ungeprüft über die Produktion; das ist vollständig ersetzt. Neu in updater/: - Version: Release-Version als Konstante, installierter Commit-SHA in storage/.version (Datei, nicht Datenbank - der Updater muss den Stand auch bei hängender Datenbank lesen können) - Progress: Fortschrittsdatei mit eigenem Fehlerzustand (pct = -1) und Verfallszeit, damit ein abgestürzter Lauf den nächsten nicht blockiert - Maintenance: Wartungsmarkierung mit Ablauf, die sich beim Prüfen selbst aufräumt - ProxyClient: nur HTTPS, Zertifikatsprüfung an, begrenzte Weiterleitungen, 503 mirror_pending/not_released als Bitte um Geduld - Updater: Prüfsumme gegen X-Content-Sha256, zweistufiger ZIP-Slip-Schutz, geschützte Pfade, atomares Schreiben je Datei, nie löschen - AutoMigrate: zieht Migrationen beim ersten Seitenaufruf nach, nur bei geändertem Fingerabdruck und mit Sperre gegen Parallellauf - guard.php: Wartungs-Wächter für die Einstiegsseiten, JSON für die Schnittstellen; ausgenommen bleiben Update-Seite, Anmeldung und Health-Check - Changelog: zerlegt CHANGELOG.md und rendert Markdown ohne unsichere Links Oberfläche: Seite "Aktualisierung" mit Stand, Kanal, Suche, Fortschritt, Migrationsliste und Versionsgeschichte. Der Datenschutzhinweis steht dauerhaft neben der Schaltfläche, nicht in einem Dialog. Fehlt changelog_preview in der Antwort, bleibt es bei "neue Fassung verfügbar" - kein leerer Kasten, kein erfundener Ersatztext. Commit-Texte werden nirgends angezeigt. Außerdem (Punkt 2 der Liste): - cron_test.php entfernt: ohne jede Anmeldung erreichbar, meldete Datenbankfehler samt Meldung und die Spalten der vouchers-Tabelle - test.php verweigert ohne config.php die Auskunft; bisher lief die Diagnose auf einer frisch entpackten Installation ohne Anmeldung PHPStan prüft jetzt den gesamten updater/-Ordner. 18 neue Tests (93 Tests, 243 Assertions), Ablauf gegen den echten Update-Dienst durchgespielt. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
165 lines
5.5 KiB
PHP
165 lines
5.5 KiB
PHP
<?php
|
|
namespace Updater;
|
|
|
|
/**
|
|
* Bedient die Update-Endpunkte.
|
|
*
|
|
* Routing-Anpassung: Dieses Projekt hat keinen Router - die Auslieferung ist
|
|
* datei-basiert. Die Endpunkte der Vorlage bilden wir deshalb ueber
|
|
* admin/update_api.php mit dem Parameter `action` ab:
|
|
*
|
|
* POST /admin/update/check -> POST admin/update_api.php?action=check
|
|
* POST /admin/update/install -> POST admin/update_api.php?action=install
|
|
* GET /admin/update/progress -> GET admin/update_api.php?action=progress
|
|
* POST /admin/update/channel -> POST admin/update_api.php?action=channel
|
|
* POST /admin/update/migrations -> POST admin/update_api.php?action=migrations
|
|
*
|
|
* Alle Endpunkte setzen einen angemeldeten Administrator voraus; alle
|
|
* schreibenden zusaetzlich ein gueltiges CSRF-Token.
|
|
*/
|
|
class UpdateController
|
|
{
|
|
/** @var \Database */
|
|
private $db;
|
|
/** @var \Auth */
|
|
private $auth;
|
|
|
|
public function __construct(\Database $db, \Auth $auth)
|
|
{
|
|
$this->db = $db;
|
|
$this->auth = $auth;
|
|
}
|
|
|
|
public function handle(string $action): void
|
|
{
|
|
try {
|
|
switch ($action) {
|
|
case 'check':
|
|
$this->requirePost();
|
|
$this->json($this->check());
|
|
break;
|
|
case 'install':
|
|
$this->requirePost();
|
|
$this->json($this->install());
|
|
break;
|
|
case 'progress':
|
|
$this->json($this->progress());
|
|
break;
|
|
case 'channel':
|
|
$this->requirePost();
|
|
$this->json($this->channel());
|
|
break;
|
|
case 'migrations':
|
|
$this->requirePost();
|
|
$this->json($this->migrations());
|
|
break;
|
|
default:
|
|
http_response_code(404);
|
|
$this->json(['ok' => false, 'error' => 'Unbekannter Endpunkt.']);
|
|
}
|
|
} catch (RetryLaterException $e) {
|
|
http_response_code(503);
|
|
header('Retry-After: ' . $e->retryAfter);
|
|
$this->json(['ok' => false, 'retry' => true, 'retry_after' => $e->retryAfter, 'error' => $e->getMessage()]);
|
|
} catch (\Throwable $e) {
|
|
http_response_code(500);
|
|
$this->json(['ok' => false, 'error' => $e->getMessage()]);
|
|
}
|
|
}
|
|
|
|
// ----------------------------------------------------------------- Aktionen
|
|
|
|
private function check(): array
|
|
{
|
|
$updater = UpdaterFactory::create($this->db, new AuditLogger($this->db));
|
|
$result = $updater->check();
|
|
$result['ok'] = true;
|
|
$result['current_release'] = Version::RELEASE;
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function install(): array
|
|
{
|
|
if (Progress::isRunning()) {
|
|
return ['ok' => false, 'error' => 'Es laeuft bereits eine Aktualisierung.'];
|
|
}
|
|
|
|
// Der Ablauf laeuft serverseitig weiter, auch wenn der Browser die
|
|
// Verbindung kappt - die Oberflaeche fragt nur den Fortschritt ab.
|
|
@set_time_limit(0);
|
|
ignore_user_abort(true);
|
|
|
|
$updater = UpdaterFactory::create($this->db, new AuditLogger($this->db));
|
|
$result = $updater->installUpdate($_SESSION['user_id'] ?? null);
|
|
$result['ok'] = $result['success'];
|
|
|
|
return $result;
|
|
}
|
|
|
|
private function progress(): array
|
|
{
|
|
$progress = Progress::get();
|
|
|
|
return [
|
|
'ok' => true,
|
|
'pct' => $progress['pct'],
|
|
'step' => $progress['step'],
|
|
'text' => $progress['text'],
|
|
'running' => Progress::isRunning(),
|
|
'maintenance' => Maintenance::isActive(),
|
|
];
|
|
}
|
|
|
|
private function channel(): array
|
|
{
|
|
$channel = (string)($_POST['channel'] ?? '');
|
|
if (!isset(Updater::CHANNELS[$channel])) {
|
|
http_response_code(400);
|
|
|
|
return ['ok' => false, 'error' => 'Unbekannter Kanal.'];
|
|
}
|
|
|
|
UpdaterFactory::saveChannel($channel);
|
|
(new AuditLogger($this->db))->log('update_channel_changed', ['channel' => $channel], $_SESSION['user_id'] ?? null);
|
|
|
|
return ['ok' => true, 'channel' => $channel];
|
|
}
|
|
|
|
private function migrations(): array
|
|
{
|
|
$updater = UpdaterFactory::create($this->db, new AuditLogger($this->db));
|
|
$done = $updater->runMigrations();
|
|
(new AuditLogger($this->db))->log('update_migrations_run', ['count' => count($done)], $_SESSION['user_id'] ?? null);
|
|
|
|
return [
|
|
'ok' => true,
|
|
'applied' => $done,
|
|
'count' => count($done),
|
|
'status' => $updater->migrationStatus(),
|
|
];
|
|
}
|
|
|
|
// ------------------------------------------------------------------ Helfer
|
|
|
|
private function requirePost(): void
|
|
{
|
|
if (($_SERVER['REQUEST_METHOD'] ?? 'GET') !== 'POST') {
|
|
http_response_code(405);
|
|
$this->json(['ok' => false, 'error' => 'Nur POST erlaubt.']);
|
|
exit;
|
|
}
|
|
if (!$this->auth->validateCsrfToken($_POST['csrf_token'] ?? '')) {
|
|
http_response_code(403);
|
|
$this->json(['ok' => false, 'error' => 'Sicherheitstoken ungueltig. Seite neu laden.']);
|
|
exit;
|
|
}
|
|
}
|
|
|
|
private function json(array $data): void
|
|
{
|
|
header('Content-Type: application/json; charset=utf-8');
|
|
header('Cache-Control: no-store');
|
|
echo json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
|
|
}
|
|
}
|