feature: the VPN, the router, the name server and WebDAV are components switched on the System tab and installed on demand, Caddy from the Ubuntu archive is a dependency and serves every HTTP and HTTPS port, HTTPS is chosen at install, its certificate is of the Servers Issuing CA or self-signed by default, of ACME or of another CA, the issuing CAs are in one tab, a locked account is unlocked again, the name of a CA is fixed once the CA exists, and a run of setup is no longer cut short by a change.
Release / release (push) Failing after 8s

This commit is contained in:
slawek committed 2026-11-24 05:51:27 +01:00
1 parent a649331aa2
commit a7bfabcb89
97 files changed
+4498 -1834

No files matched your search

+225
View File
@@ -0,0 +1,225 @@
import { Alert, Box, Button, Chip, Dialog, DialogActions, DialogContent, DialogTitle, MenuItem, Stack, Table, TableBody, TableCell, TableRow, TextField, Typography } from '@mui/material'
import { useCallback, useEffect, useState, type FormEvent } from 'react'
import ConfirmDialog from './ConfirmDialog.tsx'
import { COMPONENTS_SHAPE, request, type Component } from './api.ts'
/** Seconds between two reads while a component is being installed. */
const POLL_SECONDS = 3
/** The name and what each component is. */
const LABELS: Record<Component['name'], [string, string]> = {
vpn: ['VPN', 'IKEv2, OpenVPN and WireGuard access for users, on the Remote Access page.'],
router: ['Router', 'Routing between the external and the internal interface, and site-to-site IPsec.'],
dns: ['Name server', 'PowerDNS, the primary name server of the server\'s domains, on the DNS page.'],
webdav: ['WebDAV', 'The folders of the web sites over WebDAV, with rclone behind Caddy.'],
}
/** The chip of a component's installation state. */
const STATE_COLORS: Record<Component['state'], 'default' | 'info' | 'success' | 'error'> = {
'not installed': 'default', installing: 'info', installed: 'success', failed: 'error',
}
/** An IPv4 address with its prefix length, as local.int_addr takes it. */
const ADDRESS_PREFIX = /^(\d{1,3}\.){3}\d{1,3}\/\d{1,2}$/
/** An IPv4 address. */
const ADDRESS = /^(\d{1,3}\.){3}\d{1,3}$/
/**
* The installable components of the server from /components, the VPN, the router, the name server and WebDAV, each
* with its switch and whether its packages are installed. Enable switches a component on, and the server installs its
* packages, which the panel follows every POLL_SECONDS seconds; Disable, after a confirmation, switches it off and
* keeps its packages. The router is offered only while the server has an interface for its internal side, and its
* Enable asks for that interface and, in manual mode, its address and gateway. onChange tells of every change made.
*/
export default function ComponentsPanel(props: { onChange?: () => void }) {
const [components, setComponents] = useState<Component[] | null>(null)
const [error, setError] = useState<string | null>(null)
const [busy, setBusy] = useState(false)
const [disabling, setDisabling] = useState<Component | null>(null)
const [router, setRouter] = useState<Component | null>(null)
const read = useCallback(async () => {
try {
setComponents((await request<{ components: Component[] }>('GET', '/components', COMPONENTS_SHAPE)).components)
} catch (caught) {
setError(`The server did not give its components: ${(caught as Error).message}`)
}
}, [])
useEffect(() => {
void read()
}, [read])
// A component switched on is followed while its packages are being installed or are still missing.
const pending = components?.some((item) => item.state === 'installing' || (item.enabled && item.state === 'not installed'))
useEffect(() => {
if (!pending) {
return
}
const timer = window.setInterval(() => void read(), POLL_SECONDS * 1000)
return () => window.clearInterval(timer)
}, [pending, read])
/** Sends the switch of a component, with the router's interface settings, and reads the answer. */
async function change(item: Component, body: Record<string, unknown>) {
setBusy(true)
setError(null)
try {
setComponents((await request<{ components: Component[] }>('PUT', `/components/${item.name}`, COMPONENTS_SHAPE, body)).components)
props.onChange?.()
} finally {
setBusy(false)
}
}
async function enable(item: Component) {
if (item.name === 'router') {
setRouter(item)
return
}
try {
await change(item, { enabled: true })
} catch (caught) {
setError((caught as Error).message)
}
}
return (
<Box>
{error && <Alert severity="error" sx={{ mb: 2, whiteSpace: 'pre-line' }} onClose={() => setError(null)}>{error}</Alert>}
{components === null ? (
<Typography variant="body2" color="text.secondary">The components are not read yet.</Typography>
) : (
<Table size="small">
<TableBody>
{components.map((item) => {
const [label, description] = LABELS[item.name]
const unavailable = item.name === 'router' && item.available === false
return (
<TableRow key={item.name}>
<TableCell sx={{ width: 160, fontWeight: 500 }}>{label}</TableCell>
<TableCell>
<Typography variant="body2">{description}</Typography>
{unavailable && (
<Typography variant="body2" color="text.secondary">It needs a second network interface; the server has only one.</Typography>
)}
{item.enabled && item.state === 'failed' && (
<Typography variant="body2" color="error">The installation failed; Enable tries again, and the Logs tab has its output.</Typography>
)}
</TableCell>
<TableCell sx={{ whiteSpace: 'nowrap' }}>
<Stack direction="row" sx={{ gap: 1, alignItems: 'center' }}>
<Chip size="small" label={item.enabled ? 'on' : 'off'} color={item.enabled ? 'success' : 'default'} variant="outlined" />
<Chip size="small" label={item.state} color={STATE_COLORS[item.state]} />
</Stack>
</TableCell>
<TableCell sx={{ width: 120, textAlign: 'right' }}>
{item.enabled && item.state !== 'failed' ? (
<Button size="small" variant="outlined" disabled={busy} onClick={() => setDisabling(item)}>Disable</Button>
) : (
<Button size="small" variant="contained" disabled={busy || unavailable} onClick={() => void enable(item)}>Enable</Button>
)}
</TableCell>
</TableRow>
)
})}
</TableBody>
</Table>
)}
{disabling && (
<ConfirmDialog
title={`Disable the ${LABELS[disabling.name][0]}`}
message="The component stops and its settings are kept; its packages stay installed."
confirmLabel="Disable"
destructive
onCancel={() => setDisabling(null)}
onConfirm={() => {
const item = disabling
setDisabling(null)
change(item, { enabled: false }).catch((caught: Error) => setError(caught.message))
}}
/>
)}
{router && (
<RouterDialog
component={router}
onCancel={() => setRouter(null)}
onSave={async (values) => {
await change(router, { enabled: true, ...values })
setRouter(null)
}}
/>
)}
</Box>
)
}
/**
* A dialog that switches the router on: the internal interface, chosen from the server's interfaces but the external
* one, and in manual mode its address with the prefix length and the gateway of the internal network; in auto mode the
* server detects them. onSave sends them; the dialog shows the server's message when it fails.
*/
function RouterDialog(props: {
component: Component
onSave: (values: { internal_interface: string; int_addr: string; int_gateway_ip: string }) => Promise<void>
onCancel: () => void
}) {
const choices = props.component.interfaces ?? []
const mode = props.component.mode ?? 'manual'
const [internal, setInternal] = useState(props.component.internal_interface && choices.includes(props.component.internal_interface)
? props.component.internal_interface : choices[0] ?? '')
const [address, setAddress] = useState(props.component.int_addr ?? '')
const [gateway, setGateway] = useState(props.component.int_gateway_ip ?? '')
const [saving, setSaving] = useState(false)
const [error, setError] = useState<string | null>(null)
const manual = mode === 'manual'
const addressProblem = manual && !ADDRESS_PREFIX.test(address) ? 'An IPv4 address with its prefix length, such as 10.1.1.4/24.' : ''
const gatewayProblem = manual && !ADDRESS.test(gateway) ? 'An IPv4 address.' : ''
const blocked = (mode !== 'auto' && internal === '') || addressProblem !== '' || gatewayProblem !== ''
async function submit(event: FormEvent) {
event.preventDefault()
if (blocked) {
return
}
setSaving(true)
setError(null)
try {
await props.onSave({ internal_interface: mode === 'auto' ? '' : internal, int_addr: manual ? address : '', int_gateway_ip: manual ? gateway : '' })
} catch (caught) {
setError((caught as Error).message)
setSaving(false)
}
}
return (
<Dialog open onClose={(_event, reason) => reason !== 'backdropClick' && props.onCancel()} maxWidth="xs" fullWidth slotProps={{ paper: { component: 'form', onSubmit: submit } }}>
<DialogTitle>Enable the router</DialogTitle>
<DialogContent>
<Stack sx={{ gap: 2, pt: 1 }}>
{error && <Alert severity="error" sx={{ whiteSpace: 'pre-line' }}>{error}</Alert>}
{mode === 'auto' ? (
<Typography variant="body2" color="text.secondary">In auto mode the server detects the internal interface, its address and its gateway.</Typography>
) : (
<TextField select label="Internal interface" value={internal} onChange={(event) => setInternal(event.target.value)}>
{choices.map((name) => <MenuItem key={name} value={name}>{name}</MenuItem>)}
</TextField>
)}
{manual && (
<>
<TextField label="Address on the internal network" value={address} autoComplete="off" error={address !== '' && addressProblem !== ''} helperText={addressProblem || ' '} onChange={(event) => setAddress(event.target.value.trim())} />
<TextField label="Gateway of the internal network" value={gateway} autoComplete="off" error={gateway !== '' && gatewayProblem !== ''} helperText={gatewayProblem || ' '} onChange={(event) => setGateway(event.target.value.trim())} />
</>
)}
</Stack>
</DialogContent>
<DialogActions>
<Button onClick={props.onCancel} disabled={saving}>Cancel</Button>
<Button type="submit" variant="contained" disabled={saving || blocked}>Enable</Button>
</DialogActions>
</Dialog>
)
}