Upload via GUI (267 Dateien)

This commit is contained in:
2026-10-19 18:05:57 +00:00
parent f3e53e6182
commit c800be9693
12 changed files with 2694 additions and 2082 deletions
+103 -35
View File
@@ -59,7 +59,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
usort($files, fn($a,$b) => filemtime($b)-filemtime($a));
foreach (array_slice($files, $keep) as $old) @unlink($old);
}
$verified = backup_verify_and_record($result['path']);
$verified = $result['verify'] ?? backup_verify_and_record($result['path']); // create_backup() hat schon automatisch geprüft
audit_log($staff['id'], "Manuelles Backup: {$result['filename']} ({$result['size']} MB)$ftpMsg");
flash($verified['ok'] ? 'success' : 'error', ($verified['ok'] ? "✅ Backup erstellt und geprüft: {$result['filename']} ({$result['size']} MB){$ftpMsg}"
: "Backup erstellt, aber NICHT wiederherstellbar: " . implode(' ', $verified['errors'])));
@@ -164,7 +164,7 @@ $backupDir = realpath(__DIR__ . '/../backups') ?: (dirname(__DIR__) . '/backup
$backupFiles = [];
if (is_dir($backupDir)) {
foreach (array_merge(glob($backupDir.'/backup_*.zip')?:[], glob($backupDir.'/backup_*.tar.gz')?:[]) as $f) {
$backupFiles[] = ['name'=>basename($f),'size'=>round(filesize($f)/1024/1024,2),'date'=>filemtime($f)];
$backupFiles[] = ['name'=>basename($f),'size'=>round(filesize($f)/1024/1024,2),'bytes'=>filesize($f),'date'=>filemtime($f)];
}
usort($backupFiles, fn($a,$b) => $b['date']-$a['date']);
}
@@ -172,11 +172,35 @@ $totalSize = array_sum(array_column($backupFiles, 'size'));
$lastAutoRun = get_setting('cron_process_backups_last_run');
$lastAutoBkp = bget('last_auto_backup');
$checkMap = json_decode((string) get_setting('backup_check_map', ''), true);
$checkMap = is_array($checkMap) ? $checkMap : [];
$rows = [];
foreach ($backupFiles as $b) $rows[] = $b + ['source' => 'local', 'badges' => [], 'actions' => ''];
// Plugins mit Reiter unter „Backup“ (zum Beispiel Synology NAS Backup) können Marken, Knöpfe und weitere Einträge (nur extern vorhandene Backups) ergänzen.
// Zeilen: name, size (MB), bytes, date, source ('local'|'extern'), badges (HTML-Liste), actions (HTML). Die Plugins sind für das Maskieren ihrer HTML-Ausgaben selbst verantwortlich.
if (function_exists('plugin_filter')) $rows = plugin_filter('backup.list.rows', $rows, ['backupDir' => $backupDir]);
usort($rows, fn($a, $b) => ($b['date'] ?? 0) <=> ($a['date'] ?? 0));
$ago = function (int $ts): string {
$d = time() - $ts;
if ($d < 90) return 'gerade eben';
if ($d < 3600) return 'vor ' . round($d / 60) . ' Min.';
if ($d < 86400) return 'vor ' . round($d / 3600) . ' Std.';
return 'vor ' . round($d / 86400) . ' Tagen';
};
$fmtMb = fn($mb) => $mb >= 1024 ? number_format($mb / 1024, 2, ',', '.') . ' GB' : number_format((float) $mb, $mb < 10 ? 2 : 0, ',', '.') . ' MB';
// Zahlen für die Kacheln oben: Backups auf dem Server und (über Plugins, zum Beispiel NAS) extern vorhandene
$externRows = array_values(array_filter($rows, fn($r) => ($r['source'] ?? 'local') !== 'local'));
$sizeAll = array_sum(array_map(fn($r) => (float) ($r['size'] ?? 0), $rows));
$sizeExtern = array_sum(array_map(fn($r) => (float) ($r['size'] ?? 0), $externRows));
$newestTs = $rows ? (int) max(array_map(fn($r) => (int) ($r['date'] ?? 0), $rows)) : 0;
$pageTitle = 'Backup';
$activePage = 'backup';
require __DIR__ . '/_header.php';
?>
<?= plugin_subpage_tabs('backup', $staff, 'parent') ?>
<div class="topbar">
<h1>💾 Backup</h1>
<form method="post" id="backup-form">
@@ -188,37 +212,80 @@ require __DIR__ . '/_header.php';
<!-- Statistiken -->
<div class="stat-grid" style="margin-bottom:20px">
<div class="stat-card"><div class="num"><?= count($backupFiles) ?></div><div class="lbl">Backups vorhanden</div></div>
<div class="stat-card"><div class="num"><?= $totalSize ?> MB</div><div class="lbl">Gesamtgröße</div></div>
<div class="stat-card"><div class="num"><?= $backupFiles ? date('d.m.Y', $backupFiles[0]['date']) : '–' ?></div><div class="lbl">Letztes Backup</div></div>
<div class="stat-card"><div class="num"><?= $lastAutoBkp ? date('d.m.Y', strtotime($lastAutoBkp)) : '–' ?></div><div class="lbl">Letztes Auto-Backup</div></div>
<div class="stat-card"><div class="num"><?= count($rows) ?></div><div class="lbl">Backups vorhanden</div>
<div class="lbl" style="text-transform:none;letter-spacing:0;margin-top:3px"><?= count($backupFiles) ?> auf dem Server<?= $externRows ? ' · ' . count($externRows) . ' nur extern (NAS)' : '' ?></div></div>
<div class="stat-card"><div class="num"><?= e($fmtMb($sizeAll)) ?></div><div class="lbl">Gesamtgröße</div>
<div class="lbl" style="text-transform:none;letter-spacing:0;margin-top:3px">Server: <?= e($fmtMb($totalSize)) ?><?= $externRows ? ' · extern: ' . e($fmtMb($sizeExtern)) : '' ?></div></div>
<div class="stat-card"><div class="num"><?= $newestTs ? e(date('d.m.Y', $newestTs)) : '–' ?></div><div class="lbl">Letztes Backup</div>
<div class="lbl" style="text-transform:none;letter-spacing:0;margin-top:3px"><?= $newestTs ? e(date('H:i', $newestTs)) . ' Uhr' : 'noch keins' ?></div></div>
<div class="stat-card"><div class="num"><?= $lastAutoBkp ? date('d.m.Y', strtotime($lastAutoBkp)) : '–' ?></div><div class="lbl">Letztes Auto-Backup</div>
<div class="lbl" style="text-transform:none;letter-spacing:0;margin-top:3px"><?= $lastAutoBkp ? e(date('H:i', strtotime($lastAutoBkp))) . ' Uhr' : ((bget('schedule') ?: 'disabled') === 'disabled' ? 'Zeitplan aus' : 'noch nicht gelaufen') ?></div></div>
</div>
<style>
.bk-list { display:flex; flex-direction:column; }
.bk-row { display:grid; grid-template-columns:minmax(0,1fr) auto auto; gap:6px 16px; align-items:center; padding:9px 4px; border-top:1px solid var(--border); }
.bk-row:first-child { border-top:0; }
.bk-name { min-width:0; }
.bk-name code { font-size:.82rem; word-break:break-all; }
.bk-meta { display:block; font-size:.76rem; color:var(--muted); margin-top:1px; }
.bk-badges { display:flex; gap:5px; flex-wrap:wrap; justify-content:flex-end; }
.bk-badge { font-size:.7rem; padding:2px 8px; border-radius:999px; border:1px solid var(--border); color:var(--muted); white-space:nowrap; }
.bk-badge.ok { color:#15803d; border-color:#bbf7d0; background:#f0fdf4; }
.bk-badge.bad { color:#b91c1c; border-color:#fecaca; background:#fef2f2; }
.bk-actions { display:flex; gap:5px; align-items:center; justify-content:flex-end; flex-wrap:nowrap; }
.bk-actions form { margin:0; }
.bk-btn { padding:4px 9px; font-size:.76rem; line-height:1.4; white-space:nowrap; cursor:pointer; list-style:none; }
.bk-btn::-webkit-details-marker { display:none; }
.bk-restore { position:relative; }
.bk-restore form.bk-pop { position:absolute; right:0; z-index:5; width:340px; padding:14px; background:var(--card-bg,#fff); border:1px solid var(--border); border-radius:10px; box-shadow:0 8px 24px rgba(0,0,0,.18); text-align:left; }
@media (max-width:820px) { .bk-row { grid-template-columns:1fr; } .bk-badges, .bk-actions { justify-content:flex-start; flex-wrap:wrap; } }
</style>
<!-- Backup-Liste -->
<div class="card" style="margin-bottom:20px">
<h3>Vorhandene Backups</h3>
<?php $lastCheck = json_decode((string) get_setting('backup_last_check', ''), true); if (is_array($lastCheck)): ?>
<p class="muted" style="font-size:.82rem; margin-top:-6px">Letzte Prüfung: <?= e(date('d.m.Y H:i', strtotime($lastCheck['at']))) ?> – <?= e($lastCheck['file']) ?>:
<strong style="color:<?= $lastCheck['ok'] ? '#15803d' : '#dc2626' ?>"><?= $lastCheck['ok'] ? 'wiederherstellbar' : 'nicht wiederherstellbar' ?></strong></p>
<?php endif; ?>
<?php if (!$backupFiles): ?>
<div style="display:flex; justify-content:space-between; align-items:baseline; gap:12px; flex-wrap:wrap">
<h3 style="margin:0">Vorhandene Backups</h3>
<?php $lastCheck = json_decode((string) get_setting('backup_last_check', ''), true); if (is_array($lastCheck)): ?>
<span class="muted" style="font-size:.8rem">Letzte Prüfung: <?= e(date('d.m.Y H:i', strtotime($lastCheck['at']))) ?> –
<strong style="color:<?= $lastCheck['ok'] ? '#15803d' : '#dc2626' ?>"><?= $lastCheck['ok'] ? 'wiederherstellbar' : 'nicht wiederherstellbar' ?></strong></span>
<?php endif; ?>
</div>
<?php if (!$rows): ?>
<div class="empty-state">Noch keine Backups vorhanden.</div>
<?php else: ?>
<table>
<thead><tr><th>Dateiname</th><th>Größe</th><th>Erstellt</th><th style="width:160px"></th></tr></thead>
<tbody>
<?php foreach ($backupFiles as $b): ?>
<tr>
<td style="font-family:monospace; font-size:.82rem"><?= e($b['name']) ?></td>
<td class="muted"><?= $b['size'] ?> MB</td>
<td class="muted"><?= date('d.m.Y H:i', $b['date']) ?></td>
<td style="display:flex; gap:6px; flex-wrap:wrap; align-items:flex-start">
<a href="/staff/backup_download.php?file=<?= urlencode($b['name']) ?>" class="btn secondary" style="padding:5px 10px; font-size:.78rem">⬇️ Download</a>
<div class="bk-list" style="margin-top:8px">
<?php foreach ($rows as $b):
$isLocal = ($b['source'] ?? 'local') === 'local';
$chk = $isLocal ? ($checkMap[$b['name']] ?? null) : null;
?>
<div class="bk-row">
<div class="bk-name">
<code><?= e($b['name']) ?></code>
<span class="bk-meta"><?= e($fmtMb($b['size'] ?? 0)) ?> · <?= e(date('d.m.Y H:i', (int) ($b['date'] ?? 0))) ?> (<?= e($ago((int) ($b['date'] ?? 0))) ?>)<?= !$isLocal ? ' · nicht auf diesem Server' : '' ?></span>
</div>
<div class="bk-badges">
<?php if ($isLocal && str_ends_with($b['name'], '.zip')): ?>
<?php if ($chk): ?>
<span class="bk-badge <?= $chk['ok'] ? 'ok' : 'bad' ?>" title="Geprüft am <?= e(date('d.m.Y H:i', strtotime($chk['at']))) ?>"><?= $chk['ok'] ? '✔ geprüft' : '✖ defekt' ?></span>
<?php else: ?>
<span class="bk-badge" title="Noch nicht auf Wiederherstellbarkeit geprüft">nicht geprüft</span>
<?php endif; ?>
<?php endif; ?>
<?php foreach ((array) ($b['badges'] ?? []) as $badge): ?><?= $badge ?><?php endforeach; ?>
</div>
<div class="bk-actions">
<?php if ($isLocal): ?>
<a href="/staff/backup_download.php?file=<?= urlencode($b['name']) ?>" class="btn secondary bk-btn" title="Backup herunterladen">⬇ Download</a>
<?php if (str_ends_with($b['name'], '.zip')): ?>
<form method="post" style="margin:0"><?= csrf_field() ?><input type="hidden" name="action" value="verify_backup"><input type="hidden" name="filename" value="<?= e($b['name']) ?>">
<button type="submit" class="btn secondary" style="padding:5px 10px; font-size:.78rem" title="Prüft, ob sich das Backup wiederherstellen lässt (verändert nichts)">✔️ Prüfen</button></form>
<details style="position:relative"><summary class="btn secondary" style="padding:5px 10px; font-size:.78rem; list-style:none; cursor:pointer">♻️ Wiederherstellen</summary>
<form method="post" style="position:absolute; right:0; z-index:5; width:340px; padding:14px; background:var(--card-bg,#fff); border:1px solid var(--border); border-radius:10px; box-shadow:0 8px 24px rgba(0,0,0,.18)">
<form method="post"><?= csrf_field() ?><input type="hidden" name="action" value="verify_backup"><input type="hidden" name="filename" value="<?= e($b['name']) ?>">
<button type="submit" class="btn secondary bk-btn" title="Prüft, ob sich das Backup wiederherstellen lässt (verändert nichts)">✔ Prüfen</button></form>
<?php endif; ?>
<?php endif; ?>
<?= $b['actions'] ?? '' ?>
<?php if ($isLocal && str_ends_with($b['name'], '.zip')): ?>
<details class="bk-restore"><summary class="btn secondary bk-btn" title="Datenbank und Dateien aus diesem Backup zurückspielen">♻ Wiederherstellen</summary>
<form method="post" class="bk-pop">
<?= csrf_field() ?><input type="hidden" name="action" value="restore_backup"><input type="hidden" name="filename" value="<?= e($b['name']) ?>">
<p style="font-size:.82rem; margin:0 0 8px"><strong>Achtung:</strong> Der aktuelle Stand der Datenbank wird durch den Stand dieses Backups ersetzt. Vorher wird automatisch ein Sicherheits-Backup erstellt. Programmdateien und die Konfiguration bleiben unverändert.</p>
<label style="display:block; font-weight:400"><input type="checkbox" name="database" value="1" checked style="width:auto"> Datenbank</label>
@@ -227,21 +294,21 @@ require __DIR__ . '/_header.php';
<input type="text" name="confirm" autocomplete="off" required>
<button type="submit" class="btn" style="margin-top:8px; background:var(--danger)">Jetzt wiederherstellen</button>
</form></details>
<?php endif; ?>
<form method="post" onsubmit="return confirm('Backup löschen?')" style="margin:0">
<?php endif; ?>
<?php if ($isLocal): ?>
<form method="post" onsubmit="return confirm('Dieses Backup auf dem Server löschen?')">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete_backup">
<input type="hidden" name="filename" value="<?= e($b['name']) ?>">
<button type="submit" class="btn secondary" style="padding:5px 10px; font-size:.78rem; border-color:var(--danger); color:var(--danger)">🗑️</button>
<button type="submit" class="btn secondary bk-btn" style="border-color:var(--danger); color:var(--danger)" title="Auf dem Server löschen">🗑</button>
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
</div>
<div style="display:grid; grid-template-columns:1fr 1fr; gap:20px; margin-bottom:20px">
<!-- Zeitplan -->
@@ -251,6 +318,7 @@ require __DIR__ . '/_header.php';
Cron-Job einrichten: <code>php <?= e(dirname(__DIR__)) ?>/cron/process_backups.php</code><br>
<?php if ($lastAutoRun): ?><span style="font-size:.78rem">Letzter Lauf: <?= format_dt($lastAutoRun) ?></span><?php endif; ?>
</p>
<p class="muted" style="font-size:.8rem; margin:0 0 12px">✔ Jedes Backup wird nach dem Erstellen automatisch auf Wiederherstellbarkeit geprüft; ältere werden regelmäßig erneut geprüft.</p>
<form method="post">
<?= csrf_field() ?>
<input type="hidden" name="action" value="save_schedule">