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,185 @@
|
||||
import Add from '@mui/icons-material/Add'
|
||||
import Cancel from '@mui/icons-material/Cancel'
|
||||
import CheckCircle from '@mui/icons-material/CheckCircle'
|
||||
import Delete from '@mui/icons-material/Delete'
|
||||
import Edit from '@mui/icons-material/Edit'
|
||||
import Refresh from '@mui/icons-material/Refresh'
|
||||
import {
|
||||
Alert, Box, Button, IconButton, Table, TableBody, TableCell, TableHead, TableRow, Tooltip, Typography,
|
||||
} from '@mui/material'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import ConfirmDialog, { type ConfirmDialogProps } from './ConfirmDialog.tsx'
|
||||
import { Section } from './RouterPanel.tsx'
|
||||
import SiteToSiteDialog from './SiteToSiteDialog.tsx'
|
||||
import Toolbar from './Toolbar.tsx'
|
||||
import {
|
||||
ApiError, REMOVED_SHAPE, SITE_TO_SITE_CONNECTION_SHAPE, SITE_TO_SITE_SHAPE, request, type SiteToSiteConnection,
|
||||
} 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; Established follows once the tunnel is up again.'
|
||||
|
||||
/**
|
||||
* The router's site-to-site connections: list with their remote peers, subnets, local identity mode, authentication
|
||||
* (whether a pre-shared key is set, or which CA the peer's certificate comes from) and whether the tunnel is
|
||||
* established; add, edit and remove. The router applies a change by
|
||||
* running its setup again, so the list is read again after each.
|
||||
*/
|
||||
export default function SiteToSitePanel() {
|
||||
const [connections, setConnections] = useState<SiteToSiteConnection[] | 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 [adding, setAdding] = useState(false)
|
||||
const [editing, setEditing] = useState<SiteToSiteConnection | null>(null)
|
||||
const [confirm, setConfirm] = useState<ConfirmDialogProps | null>(null)
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
setBusy(true)
|
||||
try {
|
||||
const found = await request<{ connections: SiteToSiteConnection[] }>('GET', '/site-to-site', SITE_TO_SITE_SHAPE)
|
||||
setConnections(found.connections)
|
||||
setError(null)
|
||||
setUnavailable(false)
|
||||
} catch (caught) {
|
||||
const failure = caught as ApiError
|
||||
setConnections(null)
|
||||
setUnavailable(failure.status === 404)
|
||||
setError(failure.message)
|
||||
} finally {
|
||||
setBusy(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
void refresh()
|
||||
}, [refresh])
|
||||
|
||||
function remove(connection: SiteToSiteConnection) {
|
||||
setConfirm({
|
||||
title: 'Remove site-to-site connection',
|
||||
message: `Remove ${connection.name}? Its tunnel is taken down.`,
|
||||
confirmLabel: 'Remove',
|
||||
destructive: true,
|
||||
onCancel: () => setConfirm(null),
|
||||
onConfirm: () => {
|
||||
setConfirm(null)
|
||||
setBusy(true)
|
||||
request('DELETE', `/site-to-site/${connection.name}`, REMOVED_SHAPE)
|
||||
.then(() => {
|
||||
setError(null)
|
||||
setNote(APPLIED)
|
||||
})
|
||||
.catch((caught: Error) => setError(caught.message))
|
||||
.finally(() => void refresh())
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<Box component="section">
|
||||
<Toolbar description="IPsec site-to-site connections.">
|
||||
<Button variant="contained" startIcon={<Add />} disabled={busy || connections === null} onClick={() => setAdding(true)}>
|
||||
Add connection
|
||||
</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>}
|
||||
|
||||
{connections && (
|
||||
<Section title="Site-to-site connections">
|
||||
<Box sx={{ overflowX: 'auto' }}>
|
||||
<Table size="small">
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>Name</TableCell>
|
||||
<TableCell>Remote peer</TableCell>
|
||||
<TableCell>Remote identity</TableCell>
|
||||
<TableCell>Remote CIDRs</TableCell>
|
||||
<TableCell>Local CIDRs</TableCell>
|
||||
<TableCell>Local identity mode</TableCell>
|
||||
<TableCell>Authentication</TableCell>
|
||||
<TableCell>Established</TableCell>
|
||||
<TableCell align="right">Actions</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{connections.length === 0 && (
|
||||
<TableRow>
|
||||
<TableCell colSpan={9} sx={{ color: 'text.secondary' }}>None.</TableCell>
|
||||
</TableRow>
|
||||
)}
|
||||
{connections.map((connection) => (
|
||||
<TableRow key={connection.name} hover>
|
||||
<TableCell>{connection.name}</TableCell>
|
||||
<TableCell>{connection.addrs.join(', ') || '-'}</TableCell>
|
||||
<TableCell>{connection.id || '-'}</TableCell>
|
||||
<TableCell sx={{ fontFamily: 'monospace' }}>{connection.cidrs.join(', ') || '-'}</TableCell>
|
||||
<TableCell sx={{ fontFamily: 'monospace' }}>{connection.local_cidrs.join(', ') || '-'}</TableCell>
|
||||
<TableCell>{connection.local_id_mode}</TableCell>
|
||||
<TableCell>
|
||||
{connection.auth === 'certificate'
|
||||
? `certificate, ${connection.remote_ca ? 'remote CA' : 'site-to-site CA'}`
|
||||
: connection.psk_file
|
||||
? <Tooltip title={connection.psk_file}><span>key from file</span></Tooltip>
|
||||
: connection.psk_set ? 'key set' : <Typography variant="body2" component="span" color="error">key missing</Typography>}
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
{connection.established === null
|
||||
? <Tooltip title="The router cannot tell."><span>-</span></Tooltip>
|
||||
: connection.established
|
||||
? <CheckCircle fontSize="small" color="success" aria-label="established" />
|
||||
: <Cancel fontSize="small" color="error" aria-label="not established" />}
|
||||
</TableCell>
|
||||
<TableCell align="right" sx={{ whiteSpace: 'nowrap' }}>
|
||||
<Tooltip title="Edit">
|
||||
<span>
|
||||
<IconButton size="small" disabled={busy} onClick={() => setEditing(connection)}><Edit fontSize="small" /></IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
<Tooltip title="Remove">
|
||||
<span>
|
||||
<IconButton size="small" color="error" disabled={busy} onClick={() => remove(connection)}><Delete fontSize="small" /></IconButton>
|
||||
</span>
|
||||
</Tooltip>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</Box>
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{adding && (
|
||||
<SiteToSiteDialog
|
||||
onCancel={() => setAdding(false)}
|
||||
onSave={async (name, settings, psk) => {
|
||||
await request('POST', '/site-to-site', SITE_TO_SITE_CONNECTION_SHAPE, { name, ...settings, psk })
|
||||
setAdding(false)
|
||||
setNote(APPLIED)
|
||||
await refresh()
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{editing && (
|
||||
<SiteToSiteDialog
|
||||
connection={editing}
|
||||
onCancel={() => setEditing(null)}
|
||||
onSave={async (_name, settings, psk) => {
|
||||
await request('PUT', `/site-to-site/${editing.name}`, SITE_TO_SITE_CONNECTION_SHAPE, psk === '' ? settings : { ...settings, psk })
|
||||
setEditing(null)
|
||||
setNote(APPLIED)
|
||||
await refresh()
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{confirm && <ConfirmDialog {...confirm} />}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user