feature: the package installs the Router Manager, which is no longer a package of its own.
Release / release (push) Failing after 4s
Release / release (push) Failing after 4s
This commit is contained in:
1 parent
6d90441bee
commit
8efe21bfa6
129 files changed
+17381
-104
No files matched your search
@@ -0,0 +1,178 @@
|
||||
import Description from '@mui/icons-material/Description'
|
||||
import Edit from '@mui/icons-material/Edit'
|
||||
import Refresh from '@mui/icons-material/Refresh'
|
||||
import { Alert, Box, Button, Chip, Stack } from '@mui/material'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import RemoteAccessDialog from './RemoteAccessDialog.tsx'
|
||||
import Toolbar from './Toolbar.tsx'
|
||||
import WireGuardConfigDialog from './WireGuardConfigDialog.tsx'
|
||||
import WireGuardPeers from './WireGuardPeers.tsx'
|
||||
import { Copyable, Grid, IPSEC_HEADS, Pairs, Section, bytes, ipsecRows, text } from './RouterPanel.tsx'
|
||||
import {
|
||||
DETAILS_SHAPE, REMOTE_ACCESS_LABELS, REMOTE_ACCESS_SECTION_SHAPES, REMOTE_ACCESS_SHAPE, STATUS_SHAPE, USERS_SHAPE, request,
|
||||
type RemoteAccess, type RemoteAccessSystem, type RouterDetails, type RouterStatus, type Users,
|
||||
} from './api.ts'
|
||||
|
||||
/** What each system describes, above its panels. */
|
||||
const DESCRIPTIONS: Record<RemoteAccessSystem, string> = {
|
||||
p2s: 'IKEv2 remote access.',
|
||||
openvpn: 'OpenVPN remote access.',
|
||||
wireguard: 'WireGuard remote access.',
|
||||
}
|
||||
|
||||
/**
|
||||
* The settings and the state of one remote access system of the router, from its /remote-access and /status/full: the
|
||||
* settings with Edit, whether setup runs the system, why an enabled one does not run, and its connected clients; for
|
||||
* IKEv2, from /config too, the IPsec security associations, child SAs, connections and connection children of all but
|
||||
* the site-to-site connections, that is of IKEv2 access; for WireGuard, from /users and /config too, the peers of the users, added and removed here (WireGuardPeers), and each
|
||||
* connection with its user, found by the peer's key, its IPs, endpoint, handshake and traffic. The router applies a
|
||||
* change in the background; Refresh reads the state again.
|
||||
*/
|
||||
export default function RemoteAccessPanel(props: { system: RemoteAccessSystem }) {
|
||||
const [access, setAccess] = useState<RemoteAccess | null>(null)
|
||||
const [status, setStatus] = useState<RouterStatus | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [busy, setBusy] = useState(false)
|
||||
const [editing, setEditing] = useState(false)
|
||||
const [showConfig, setShowConfig] = useState(false)
|
||||
// WireGuard's: the users with their peers, and the router's details with each peer's key, endpoint and traffic.
|
||||
const [users, setUsers] = useState<Users | null>(null)
|
||||
const [details, setDetails] = useState<RouterDetails | null>(null)
|
||||
const wireguard = props.system === 'wireguard'
|
||||
// IKEv2's: the router's details with its IPsec SAs and connections, those of IKEv2 access being all but site to site.
|
||||
const ikev2 = props.system === 'p2s'
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
setBusy(true)
|
||||
try {
|
||||
const [nextAccess, nextStatus, nextUsers, nextDetails] = await Promise.all([
|
||||
request<RemoteAccess>('GET', '/remote-access', REMOTE_ACCESS_SHAPE),
|
||||
request<RouterStatus>('GET', '/status/full', STATUS_SHAPE),
|
||||
wireguard ? request<Users>('GET', '/users', USERS_SHAPE) : null,
|
||||
wireguard || ikev2 ? request<RouterDetails>('GET', '/config', DETAILS_SHAPE) : null,
|
||||
])
|
||||
setAccess(nextAccess)
|
||||
setStatus(nextStatus)
|
||||
setUsers(nextUsers)
|
||||
setDetails(nextDetails)
|
||||
setError(null)
|
||||
} catch (caught) {
|
||||
setError((caught as Error).message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}, [wireguard, ikev2])
|
||||
|
||||
useEffect(() => {
|
||||
void refresh()
|
||||
}, [refresh])
|
||||
|
||||
async function save(settings: Record<string, unknown>) {
|
||||
await request('PUT', `/remote-access/${props.system}`, REMOTE_ACCESS_SECTION_SHAPES[props.system], settings)
|
||||
setEditing(false)
|
||||
await refresh()
|
||||
}
|
||||
|
||||
const system = props.system
|
||||
const settings = access?.[system]
|
||||
const running = access?.running[system] ?? false
|
||||
const rows: [string, string][] = !access ? [] : system === 'p2s'
|
||||
? [['Enabled', access.p2s.enabled ? 'yes' : 'no'], ['Address pool', text(access.p2s.address_pool)],
|
||||
['DNS domains', access.p2s.dns_domains.join(', ') || '-']]
|
||||
: system === 'openvpn'
|
||||
? [['Enabled', access.openvpn.enabled ? 'yes' : 'no'], ['Address pool', text(access.openvpn.address_pool)],
|
||||
['Port', `${access.openvpn.port}/${access.openvpn.protocol}`]]
|
||||
: [['Enabled', access.wireguard.enabled ? 'yes' : 'no'], ['Address of wg0', text(access.wireguard.address)],
|
||||
['UDP port', String(access.wireguard.listen_port)]]
|
||||
const clients = system === 'p2s' ? status?.p2s?.clients : system === 'openvpn' ? status?.openvpn?.clients : undefined
|
||||
const peers = status?.wireguard?.peers
|
||||
const siteToSite = new Set((details?.network.site_to_site ?? []).map((connection) => connection.name))
|
||||
const ipsec = ipsecRows(ikev2 ? details : null, (name) => !siteToSite.has(name))
|
||||
// An IPsec table is shown with rows, or with the note that the router could not read them.
|
||||
const shown = (rows: string[][] | undefined) => ikev2 && details !== null && (rows === undefined || rows.length > 0)
|
||||
|
||||
return (
|
||||
<Box component="section">
|
||||
<Toolbar description={DESCRIPTIONS[system]}>
|
||||
<Button variant="outlined" startIcon={<Edit />} disabled={!access || busy} onClick={() => setEditing(true)}>Edit</Button>
|
||||
<Button variant="outlined" startIcon={<Refresh />} disabled={busy} onClick={() => void refresh()}>Refresh</Button>
|
||||
</Toolbar>
|
||||
{error && <Alert severity="error" sx={{ mb: 2, whiteSpace: 'pre-line' }}>{error}</Alert>}
|
||||
{access && settings && settings.enabled && !running && (
|
||||
<Alert severity="warning" sx={{ mb: 2 }}>
|
||||
{system === 'wireguard'
|
||||
? 'WireGuard is enabled but does not run yet; the router applies a change within a moment.'
|
||||
: `${REMOTE_ACCESS_LABELS[system]} is enabled but does not run yet. It needs wan.local_fqdn${access.local_fqdn ? '' : ', which is not set,'} and the router's VPN server certificate of the P2S issuing CA; the router applies a change within a moment.`}
|
||||
</Alert>
|
||||
)}
|
||||
{access && (
|
||||
<Box sx={{ display: 'grid', gap: 2, gridTemplateColumns: { xs: '1fr', md: '1fr 1fr' } }}>
|
||||
<Section title="Settings"><Pairs rows={rows} /></Section>
|
||||
<Section title="State">
|
||||
<Pairs
|
||||
rows={[
|
||||
['Running', <Chip key="running" size="small" label={running ? 'running' : 'not running'} color={running ? 'success' : 'default'} />],
|
||||
...(system === 'wireguard'
|
||||
? [['Peers', peers === undefined || peers === null ? '-' : String(peers.length)] as [string, string]]
|
||||
: [['Connected clients', clients === undefined || clients === null ? '-' : String(clients)] as [string, string]]),
|
||||
]}
|
||||
/>
|
||||
</Section>
|
||||
{shown(ipsec.sas) && <Section title="IPsec security associations" wide><Grid head={IPSEC_HEADS.sas} rows={ipsec.sas} /></Section>}
|
||||
{shown(ipsec.childSas) && <Section title="IPsec child SAs" wide><Grid head={IPSEC_HEADS.childSas} rows={ipsec.childSas} /></Section>}
|
||||
{shown(ipsec.connections) && <Section title="IPsec connections" wide><Grid head={IPSEC_HEADS.connections} rows={ipsec.connections} /></Section>}
|
||||
{shown(ipsec.children) && <Section title="IPsec connection children" wide><Grid head={IPSEC_HEADS.children} rows={ipsec.children} /></Section>}
|
||||
{system === 'wireguard' && (
|
||||
<Section title="Server" wide>
|
||||
<Pairs
|
||||
rows={[
|
||||
['Public key', access.wireguard_server.public_key === null ? 'not made yet; setup makes it once WireGuard is enabled'
|
||||
: <Copyable key="key" value={access.wireguard_server.public_key} label="public key" />],
|
||||
['Endpoint', access.wireguard_server.endpoint ?? 'unknown: wan.local_fqdn is not set'],
|
||||
['Allowed IPs', text(access.wireguard_server.allowed_ips)],
|
||||
]}
|
||||
/>
|
||||
<Stack direction="row" sx={{ mt: 1, justifyContent: 'flex-end' }}>
|
||||
<Button
|
||||
size="small"
|
||||
variant="outlined"
|
||||
startIcon={<Description />}
|
||||
disabled={!access.wireguard_server.public_key || !access.wireguard_server.endpoint}
|
||||
onClick={() => setShowConfig(true)}
|
||||
>
|
||||
Show config
|
||||
</Button>
|
||||
</Stack>
|
||||
</Section>
|
||||
)}
|
||||
{system === 'wireguard' && <WireGuardPeers server={access.wireguard_server} users={users} onChanged={() => void refresh()} />}
|
||||
{system === 'wireguard' && running && (
|
||||
<Section title="Connections" wide>
|
||||
<Grid
|
||||
head={['User', 'IPs', 'Endpoint', 'Handshake', 'Received', 'Sent']}
|
||||
rows={details?.wireguard?.peers.map((peer) => {
|
||||
// A peer is a user's by its key; one added to wg0.conf by hand has no user.
|
||||
const owner = users?.users.find((user) => user.wireguard_peers.some((own) => own.public_key === peer.public_key))
|
||||
return [
|
||||
owner?.name ?? `- (${peer.public_key.slice(0, 8)}...)`,
|
||||
peer.allowed_ips.join(', '),
|
||||
peer.endpoint ?? '-',
|
||||
peer.handshake_seconds_ago === null ? 'none' : `${peer.handshake_seconds_ago} s ago`,
|
||||
bytes(peer.received_bytes),
|
||||
bytes(peer.sent_bytes),
|
||||
]
|
||||
}) ?? undefined}
|
||||
/>
|
||||
</Section>
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
{showConfig && access && (
|
||||
<WireGuardConfigDialog title="WireGuard configuration of a device" server={access.wireguard_server} ips={null} onClose={() => setShowConfig(false)} />
|
||||
)}
|
||||
{editing && access && (
|
||||
<RemoteAccessDialog system={system} current={access} onSave={save} onCancel={() => setEditing(false)} />
|
||||
)}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user