Selbst-Updater neu gebaut, Diagnoseseiten abgesichert
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
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>
This commit is contained in:
parent
3a5b95119c
commit
25b8c51362
83 changed files with 2690 additions and 1042 deletions
341
admin/update.php
341
admin/update.php
|
|
@ -1,12 +1,17 @@
|
|||
<?php
|
||||
/**
|
||||
* Admin-Entry-Point fuer den Updater (URL: /admin/update.php).
|
||||
* Admin-Seite "Aktualisierung".
|
||||
*
|
||||
* Bewusst sehr duenn gehalten: laedt nur die Projekt-Basis + den isolierten
|
||||
* Updater-Bootstrap und delegiert alles an \Updater\UpdateController.
|
||||
* Zeigt den installierten Stand, den Kanal, gefundene Updates samt der
|
||||
* Abschnitte aus dem Aenderungsprotokoll, den Fortschritt einer laufenden
|
||||
* Aktualisierung, den Stand der Migrationen und die Versionsgeschichte.
|
||||
*
|
||||
* Beim Rueckbau des Updaters kann diese Datei mitgeloescht werden.
|
||||
* Die Endpunkte liegen in admin/update_api.php.
|
||||
*/
|
||||
// Kein Wartungs-Waechter: waehrend eines Updates muss genau diese Seite
|
||||
// erreichbar bleiben, sonst sieht niemand mehr den Fortschritt.
|
||||
require_once __DIR__ . '/../updater/bootstrap.php';
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 0);
|
||||
ini_set('log_errors', 1);
|
||||
|
|
@ -14,12 +19,334 @@ ini_set('log_errors', 1);
|
|||
require_once __DIR__ . '/../config.php';
|
||||
require_once __DIR__ . '/../includes/Database.php';
|
||||
require_once __DIR__ . '/../includes/Auth.php';
|
||||
require_once __DIR__ . '/../updater/bootstrap.php';
|
||||
require_once __DIR__ . '/../includes/I18n.php';
|
||||
|
||||
$auth = new Auth();
|
||||
$auth->requireAdmin();
|
||||
I18n::init();
|
||||
|
||||
$db = Database::getInstance();
|
||||
$appTitle = $db->getSetting('app_title', 'UniFi Voucher System');
|
||||
|
||||
$controller = new \Updater\UpdateController($db, $auth);
|
||||
$controller->handle();
|
||||
$channel = \Updater\UpdaterFactory::channel();
|
||||
$channelLabels = \Updater\UpdaterFactory::channelLabels();
|
||||
$installedSha = \Updater\Version::current();
|
||||
$release = \Updater\Version::RELEASE;
|
||||
$migrations = [];
|
||||
$migrationError = '';
|
||||
|
||||
try {
|
||||
$migrations = \Updater\UpdaterFactory::create($db)->migrationStatus();
|
||||
} catch (Throwable $e) {
|
||||
$migrationError = $e->getMessage();
|
||||
}
|
||||
$openMigrations = count(array_filter($migrations, static fn ($m) => !$m['applied']));
|
||||
|
||||
$changelog = \Updater\Changelog::sections();
|
||||
$privacyUrl = trim((string)$db->getSetting('privacy_url', ''));
|
||||
$csrf = $auth->getCsrfToken();
|
||||
$currentPage = 'update';
|
||||
$adminBase = '';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="<?= I18n::getLanguage() ?>">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title><?= __('update_title') ?> – <?= htmlspecialchars($appTitle) ?></title>
|
||||
<?php require __DIR__ . '/../includes/admin_nav.php'; ?>
|
||||
<div class="page-header">
|
||||
<div>
|
||||
<h1 class="page-title"><?= __('update_title') ?></h1>
|
||||
<p class="page-subtitle"><?= __('update_subtitle') ?></p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2><?= __('update_installed') ?></h2>
|
||||
<dl class="about-list">
|
||||
<dt><?= __('update_version') ?></dt>
|
||||
<dd><?= htmlspecialchars($release) ?><?= $installedSha ? ' <code>' . htmlspecialchars(substr($installedSha, 0, 7)) . '</code>' : '' ?></dd>
|
||||
|
||||
<dt><?= __('update_state') ?></dt>
|
||||
<dd>
|
||||
<?php if ($installedSha): ?>
|
||||
<code><?= htmlspecialchars($installedSha) ?></code>
|
||||
<?php else: ?>
|
||||
<span class="muted"><?= __('update_state_unknown') ?></span>
|
||||
<?php endif; ?>
|
||||
</dd>
|
||||
|
||||
<dt><?= __('update_channel') ?></dt>
|
||||
<dd><?= htmlspecialchars($channelLabels[$channel] ?? $channel) ?></dd>
|
||||
</dl>
|
||||
|
||||
<form method="post" id="channelForm" class="update-channel">
|
||||
<input type="hidden" name="csrf_token" value="<?= htmlspecialchars($csrf) ?>">
|
||||
<label for="channelSelect"><?= __('update_channel_change') ?></label>
|
||||
<div class="update-channel-row">
|
||||
<select name="channel" id="channelSelect" class="input">
|
||||
<?php foreach ($channelLabels as $key => $label): ?>
|
||||
<option value="<?= htmlspecialchars($key) ?>" <?= $key === $channel ? 'selected' : '' ?>><?= htmlspecialchars($label) ?></option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<button type="submit" class="btn btn-secondary"><?= __('update_channel_save') ?></button>
|
||||
</div>
|
||||
<p class="help-text"><?= __('update_channel_hint') ?></p>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2><?= __('update_search') ?></h2>
|
||||
<div class="update-actions">
|
||||
<button type="button" class="btn btn-primary" id="btnCheck">
|
||||
<i class="fas fa-magnifying-glass" aria-hidden="true"></i> <?= __('update_search_btn') ?>
|
||||
</button>
|
||||
<button type="button" class="btn btn-success" id="btnInstall" hidden>
|
||||
<i class="fas fa-download" aria-hidden="true"></i> <?= __('update_install_btn') ?>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div id="checkResult" class="update-result" hidden></div>
|
||||
|
||||
<div id="progressBox" class="update-progress" hidden>
|
||||
<div class="update-bar"><span id="progressBar" style="width:0%"></span></div>
|
||||
<p class="update-progress-text"><span id="progressPercent">0</span> % – <span id="progressText"></span></p>
|
||||
</div>
|
||||
|
||||
<!-- Datenschutzhinweis: steht dauerhaft dort, wo die Uebertragung
|
||||
ausgeloest wird - nicht in einem Dialog, den man wegklickt. -->
|
||||
<div class="update-privacy">
|
||||
<h3><?= __('update_privacy_title') ?></h3>
|
||||
<p><?= __('update_privacy_intro') ?></p>
|
||||
<ul>
|
||||
<li><?= __('update_privacy_item_state') ?></li>
|
||||
<li><?= __('update_privacy_item_tech') ?></li>
|
||||
</ul>
|
||||
<p><?= __('update_privacy_purpose') ?></p>
|
||||
<p><?= __('update_privacy_not') ?></p>
|
||||
<p class="muted"><?= __('update_privacy_retention') ?></p>
|
||||
<?php if ($privacyUrl !== ''): ?>
|
||||
<p><a href="<?= htmlspecialchars($privacyUrl) ?>" target="_blank" rel="noopener"><?= __('update_privacy_link') ?></a></p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2><?= __('update_migrations') ?></h2>
|
||||
<?php if ($migrationError !== ''): ?>
|
||||
<div class="alert alert-error"><?= htmlspecialchars($migrationError) ?></div>
|
||||
<?php else: ?>
|
||||
<p class="muted">
|
||||
<?= str_replace(['{total}', '{open}'], [(string)count($migrations), (string)$openMigrations], __('update_migrations_hint')) ?>
|
||||
</p>
|
||||
<div class="table-container">
|
||||
<table class="table table-stack">
|
||||
<thead>
|
||||
<tr>
|
||||
<th><?= __('update_migration_file') ?></th>
|
||||
<th><?= __('update_migration_state') ?></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($migrations as $migration): ?>
|
||||
<tr>
|
||||
<td data-label="<?= __('update_migration_file') ?>"><code><?= htmlspecialchars($migration['filename']) ?></code></td>
|
||||
<td data-label="<?= __('update_migration_state') ?>">
|
||||
<?php if ($migration['applied']): ?>
|
||||
<span class="badge badge-success"><i class="fas fa-check" aria-hidden="true"></i> <?= __('update_migration_applied') ?></span>
|
||||
<?php else: ?>
|
||||
<span class="badge badge-warning"><i class="fas fa-clock" aria-hidden="true"></i> <?= __('update_migration_open') ?></span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<button type="button" class="btn btn-secondary" id="btnMigrate" style="margin-top:14px;">
|
||||
<i class="fas fa-database" aria-hidden="true"></i> <?= __('update_migrations_btn') ?>
|
||||
</button>
|
||||
<span id="migrationResult" class="muted" style="margin-left:10px;"></span>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<div class="card">
|
||||
<h2><?= __('update_history') ?></h2>
|
||||
<?php if ($changelog === []): ?>
|
||||
<p class="muted"><?= __('update_history_empty') ?></p>
|
||||
<?php else: ?>
|
||||
<?php foreach ($changelog as $section): ?>
|
||||
<div class="changelog-entry">
|
||||
<h3><?= htmlspecialchars($section['heading']) ?></h3>
|
||||
<div class="changelog-body"><?= \Updater\Changelog::toHtml($section['text']) ?></div>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
</main>
|
||||
<script src="../assets/global.js"></script>
|
||||
<script>
|
||||
(function () {
|
||||
const csrf = <?= json_encode($csrf) ?>;
|
||||
const api = 'update_api.php';
|
||||
const text = <?= json_encode([
|
||||
'checking' => __('update_js_checking'),
|
||||
'current' => __('update_js_current'),
|
||||
'available' => __('update_js_available'),
|
||||
'behind' => __('update_js_behind'),
|
||||
'target' => __('update_js_target'),
|
||||
'installing' => __('update_js_installing'),
|
||||
'done' => __('update_js_done'),
|
||||
'failed' => __('update_js_failed'),
|
||||
'more' => __('update_js_more'),
|
||||
'switch' => __('update_js_channel_switch'),
|
||||
'confirm' => __('update_js_confirm'),
|
||||
'migrated' => __('update_js_migrated'),
|
||||
], JSON_UNESCAPED_UNICODE) ?>;
|
||||
|
||||
const btnCheck = document.getElementById('btnCheck');
|
||||
const btnInstall = document.getElementById('btnInstall');
|
||||
const btnMigrate = document.getElementById('btnMigrate');
|
||||
const result = document.getElementById('checkResult');
|
||||
const progress = document.getElementById('progressBox');
|
||||
const bar = document.getElementById('progressBar');
|
||||
const pct = document.getElementById('progressPercent');
|
||||
const status = document.getElementById('progressText');
|
||||
|
||||
function post(action, extra) {
|
||||
const body = new FormData();
|
||||
body.append('csrf_token', csrf);
|
||||
Object.entries(extra || {}).forEach(([k, v]) => body.append(k, v));
|
||||
return fetch(api + '?action=' + action, { method: 'POST', body: body })
|
||||
.then(r => r.json().catch(() => ({ ok: false, error: 'HTTP ' + r.status })));
|
||||
}
|
||||
|
||||
function escapeHtml(value) {
|
||||
const div = document.createElement('div');
|
||||
div.textContent = value == null ? '' : String(value);
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
function renderCheck(data) {
|
||||
result.hidden = false;
|
||||
if (!data.ok) {
|
||||
result.className = 'update-result alert alert-error';
|
||||
result.textContent = data.error || text.failed;
|
||||
return;
|
||||
}
|
||||
if (!data.has_update) {
|
||||
result.className = 'update-result alert alert-ok';
|
||||
result.textContent = text.current;
|
||||
btnInstall.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
let html = '<p><strong>' + escapeHtml(text.available) + '</strong></p><ul class="update-facts">';
|
||||
if (data.version) { html += '<li>' + escapeHtml(text.target) + ' ' + escapeHtml(data.version) + '</li>'; }
|
||||
if (data.latest_sha) { html += '<li><code>' + escapeHtml(data.latest_sha.substring(0, 7)) + '</code></li>'; }
|
||||
if (data.versions_behind > 0) {
|
||||
html += '<li>' + escapeHtml(text.behind.replace('{count}', data.versions_behind)) + '</li>';
|
||||
}
|
||||
if (data.channel_switch) {
|
||||
html += '<li>' + escapeHtml(text.switch
|
||||
.replace('{from}', data.channel_switch.from_channel)
|
||||
.replace('{to}', data.channel_switch.to_channel)) + '</li>';
|
||||
}
|
||||
html += '</ul>';
|
||||
|
||||
// Fehlt changelog_preview, bleibt es bei "neue Fassung verfuegbar" -
|
||||
// kein leerer Kasten, kein erfundener Ersatztext.
|
||||
if (Array.isArray(data.changelog) && data.changelog.length) {
|
||||
html += '<div class="update-changelog">';
|
||||
data.changelog.forEach(entry => {
|
||||
html += '<h4>' + escapeHtml(entry.heading || entry.version) + '</h4>';
|
||||
html += '<pre class="update-changelog-text">' + escapeHtml(entry.text) + '</pre>';
|
||||
});
|
||||
if (data.changelog_complete === false) {
|
||||
html += '<p><a href="<?= \Updater\Updater::CHANNELS['stable'] ?>/changelog" target="_blank" rel="noopener">'
|
||||
+ escapeHtml(text.more) + '</a></p>';
|
||||
}
|
||||
html += '</div>';
|
||||
}
|
||||
|
||||
result.className = 'update-result alert alert-info';
|
||||
result.innerHTML = html;
|
||||
btnInstall.hidden = false;
|
||||
}
|
||||
|
||||
let pollTimer = null;
|
||||
function poll() {
|
||||
fetch(api + '?action=progress')
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
progress.hidden = false;
|
||||
const value = Math.max(0, data.pct);
|
||||
bar.style.width = value + '%';
|
||||
pct.textContent = data.pct < 0 ? '–' : value;
|
||||
status.textContent = data.text || '';
|
||||
if (data.step === 'done') {
|
||||
window.clearInterval(pollTimer);
|
||||
window.setTimeout(() => window.location.reload(), 1500);
|
||||
}
|
||||
if (data.step === 'error') {
|
||||
window.clearInterval(pollTimer);
|
||||
btnInstall.disabled = false;
|
||||
}
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
|
||||
btnCheck.addEventListener('click', function () {
|
||||
btnCheck.disabled = true;
|
||||
result.hidden = false;
|
||||
result.className = 'update-result alert alert-info';
|
||||
result.textContent = text.checking;
|
||||
post('check').then(data => { renderCheck(data); btnCheck.disabled = false; });
|
||||
});
|
||||
|
||||
btnInstall.addEventListener('click', function () {
|
||||
if (!window.confirm(text.confirm)) { return; }
|
||||
btnInstall.disabled = true;
|
||||
progress.hidden = false;
|
||||
status.textContent = text.installing;
|
||||
pollTimer = window.setInterval(poll, 2000);
|
||||
poll();
|
||||
post('install').then(data => {
|
||||
if (!data.ok) {
|
||||
window.clearInterval(pollTimer);
|
||||
result.hidden = false;
|
||||
result.className = 'update-result alert alert-error';
|
||||
result.textContent = data.error || text.failed;
|
||||
btnInstall.disabled = false;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
if (btnMigrate) {
|
||||
btnMigrate.addEventListener('click', function () {
|
||||
btnMigrate.disabled = true;
|
||||
post('migrations').then(data => {
|
||||
const out = document.getElementById('migrationResult');
|
||||
out.textContent = data.ok ? text.migrated.replace('{count}', data.count) : (data.error || text.failed);
|
||||
btnMigrate.disabled = false;
|
||||
if (data.ok && data.count > 0) { window.setTimeout(() => window.location.reload(), 1200); }
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
document.getElementById('channelForm').addEventListener('submit', function (event) {
|
||||
event.preventDefault();
|
||||
post('channel', { channel: document.getElementById('channelSelect').value })
|
||||
.then(data => { if (data.ok) { window.location.reload(); } });
|
||||
});
|
||||
|
||||
// Laeuft beim Aufruf schon ein Update, direkt den Fortschritt zeigen.
|
||||
fetch(api + '?action=progress').then(r => r.json()).then(data => {
|
||||
if (data.running) { progress.hidden = false; pollTimer = window.setInterval(poll, 2000); poll(); }
|
||||
}).catch(() => {});
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue