feature: the package installs the Router Manager, which is no longer a package of its own.
Release / release (push) Failing after 4s

This commit is contained in:
slawek committed 2026-11-14 12:52:44 +01:00
1 parent 6d90441bee
commit 8efe21bfa6
129 files changed
+17381 -104

No files matched your search

+204
View File
@@ -0,0 +1,204 @@
import Edit from '@mui/icons-material/Edit'
import PlayArrow from '@mui/icons-material/PlayArrow'
import Refresh from '@mui/icons-material/Refresh'
import { Alert, Box, Button, Table, TableBody, TableCell, TableHead, TablePagination, TableRow } from '@mui/material'
import { useCallback, useEffect, useRef, useState } from 'react'
import BackupDialog from './BackupDialog.tsx'
import { BackupChip, TARGET_LABELS, backupRows, when } from './BackupSummary.tsx'
import { Pairs, Section, bytes } from './RouterPanel.tsx'
import SearchField, { matches } from './SearchField.tsx'
import Toolbar from './Toolbar.tsx'
import { ApiError, BACKUP_KEEPS, BACKUP_SCHEDULES, BACKUP_SETTINGS_SHAPE, BACKUP_SHAPE, STARTED_SHAPE, request, type Backup } from './api.ts'
/** The note shown after a change, which the router applies when vpn-router-setup has run again. */
const APPLIED = 'The router applies the change in the background.'
/** Seconds between reads while a backup runs or is starting. */
const WATCH_SECONDS = 3
/**
* The router's backups: the settings, the last run and the local archives, searched by name and time and shown a page at
* a time; edit the settings and start a backup now.
* While a backup runs, or after Run now until it has ended, the tab reads every WATCH_SECONDS.
*/
export default function BackupPanel() {
const [backup, setBackup] = useState<Backup | null>(null)
const [error, setError] = useState<string | null>(null)
const [unavailable, setUnavailable] = useState(false)
const [note, setNote] = useState<string | null>(null)
const [busy, setBusy] = useState(false)
const [editing, setEditing] = useState(false)
const [watching, setWatching] = useState(false)
const [search, setSearch] = useState('')
const [page, setPage] = useState(0)
const [rows, setRows] = useState(10)
// The start of the last run when Run now was pressed; watching ends once a later run has ended.
const startedBefore = useRef<string | null>(null)
const refresh = useCallback(async () => {
try {
const found = await request<Backup>('GET', '/backup', BACKUP_SHAPE)
setBackup(found)
setError(null)
setUnavailable(false)
if (found.state && found.state.result !== 'running' && found.state.started !== startedBefore.current) {
setWatching(false)
}
} catch (caught) {
const failure = caught as ApiError
setBackup(null)
setUnavailable(failure.status === 404)
setError(failure.message)
setWatching(false)
}
}, [])
useEffect(() => {
void refresh()
}, [refresh])
const running = backup?.state?.result === 'running'
useEffect(() => {
if (!watching && !running) {
return
}
const timer = window.setInterval(() => void refresh(), WATCH_SECONDS * 1000)
return () => window.clearInterval(timer)
}, [refresh, watching, running])
async function runNow() {
setBusy(true)
try {
startedBefore.current = backup?.state?.started ?? null
await request('POST', '/backup/run', STARTED_SHAPE)
setWatching(true)
setError(null)
} catch (caught) {
setError((caught as Error).message)
} finally {
setBusy(false)
}
}
const archives = (backup?.archives ?? []).filter((archive) => matches(search, [archive.name, when(archive.time)]))
// The page shown stays within the archives found, which a refresh may make fewer.
const shownPage = Math.min(page, Math.max(0, Math.ceil(archives.length / rows) - 1))
const settings = backup?.settings
const local = settings?.target === 'local'
const keeps = settings ? BACKUP_KEEPS.slice(BACKUP_SCHEDULES.indexOf(settings.schedule as (typeof BACKUP_SCHEDULES)[number])) : []
return (
<Box component="section">
<Toolbar description="Backups of the router's configuration, keys, users and metrics.">
<Button variant="contained" startIcon={<Edit />} disabled={busy || backup === null} onClick={() => setEditing(true)}>
Edit
</Button>
<Button variant="outlined" startIcon={<PlayArrow />} disabled={busy || backup === null || running || watching} onClick={() => void runNow()}>
Run now
</Button>
<Button variant="outlined" startIcon={<Refresh />} disabled={busy} onClick={() => void refresh()}>
Refresh
</Button>
</Toolbar>
{error && <Alert severity={unavailable ? 'info' : 'error'} sx={{ mb: 2, whiteSpace: 'pre-line' }}>{error}</Alert>}
{note && <Alert severity="info" sx={{ mb: 2 }} onClose={() => setNote(null)}>{note}</Alert>}
{backup && settings && !local && !backup.client && (
<Alert severity="warning" sx={{ mb: 2 }}>
proxmox-backup-client is not installed on the router; install proxmox-backup-client-static from Proxmox's client repository.
</Alert>
)}
{backup && settings && local && settings.rclone_remote && !(backup.rclone.installed && backup.rclone.config) && (
<Alert severity="warning" sx={{ mb: 2 }}>
{backup.rclone.installed ? 'The router has no /etc/vpn-router/rclone.conf.' : 'rclone is not installed on the router.'} The cloud copy fails until it has.
</Alert>
)}
{backup && settings && (
<Box sx={{ display: 'grid', gap: 2, gridTemplateColumns: { xs: '1fr', md: '1fr 1fr' } }}>
<Section title="Settings">
<Pairs
rows={[
['Scheduled backups', settings.enabled ? 'on' : 'off'],
['Schedule', settings.schedule],
['Target', TARGET_LABELS[settings.target] ?? settings.target],
['Metrics database', settings.metrics ? 'included' : 'not included'],
...(local
? [
['Folder', settings.path],
['Kept', keeps.map((keep) => `${settings[keep]} ${keep.slice(5)}`).join(', ')],
['Cloud copy', settings.rclone_remote ? `${settings.rclone_mode} to ${settings.rclone_remote}` : 'none'],
] satisfies [string, string][]
: [
['Repository', settings.pbs_repository || '-'],
['Token secret', settings.pbs_password_set ? 'set' : 'missing'],
['Fingerprint', settings.pbs_fingerprint || '-'],
['Namespace', settings.pbs_namespace || '-'],
['Encryption key file', settings.pbs_keyfile || 'none'],
] satisfies [string, string][]),
]}
/>
</Section>
<Section title="Last run">
<Box sx={{ mb: 1 }}><BackupChip state={backup.state} /></Box>
<Pairs rows={backupRows(backup)} />
</Section>
{local && (
<Section title="Local archives" wide>
<Box sx={{ mb: 1 }}>
<SearchField value={search} onChange={(value) => { setSearch(value); setPage(0) }} />
</Box>
<Box sx={{ overflowX: 'auto' }}>
<Table size="small">
<TableHead>
<TableRow>
<TableCell>Archive</TableCell>
<TableCell>Time</TableCell>
<TableCell align="right">Size</TableCell>
</TableRow>
</TableHead>
<TableBody>
{archives.length === 0 && (
<TableRow>
<TableCell colSpan={3} sx={{ color: 'text.secondary' }}>None.</TableCell>
</TableRow>
)}
{archives.slice(shownPage * rows, (shownPage + 1) * rows).map((archive) => (
<TableRow key={archive.name} hover>
<TableCell sx={{ fontFamily: 'monospace' }}>{archive.name}</TableCell>
<TableCell>{when(archive.time)}</TableCell>
<TableCell align="right">{bytes(archive.size)}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</Box>
<TablePagination
component="div"
count={archives.length}
page={shownPage}
rowsPerPage={rows}
rowsPerPageOptions={[10, 25, 50, 100]}
onPageChange={(_event, next) => setPage(next)}
onRowsPerPageChange={(event) => { setRows(Number(event.target.value)); setPage(0) }}
/>
</Section>
)}
</Box>
)}
{editing && backup && (
<BackupDialog
backup={backup}
onCancel={() => setEditing(false)}
onSave={async (next, password) => {
await request('PUT', '/backup', BACKUP_SETTINGS_SHAPE, password === '' ? next : { ...next, pbs_password: password })
setEditing(false)
setNote(APPLIED)
await refresh()
}}
/>
)}
</Box>
)
}