fix: the root CA is created by the server, an offline CA or a Simple CA service, chosen at setup; the shell can stay open in a tab of its own, the Docker page is offered only with Docker, and the test scripts are in bin/.
Release / release (push) Failing after 14m20s

This commit is contained in:
slawek committed 2026-11-23 06:45:23 +01:00
1 parent ff0c93ed73
commit a649331aa2
49 files changed
+1597 -637

No files matched your search

+17 -6
View File
@@ -20,6 +20,7 @@ import RemoteAccessPanel from './RemoteAccessPanel.tsx'
import ServerPanel from './ServerPanel.tsx'
import ServiceAccountsPanel from './ServiceAccountsPanel.tsx'
import SettingsButton from './SettingsButton.tsx'
import { useBrowserSettings } from './settings.ts'
import ShellPanel from './ShellPanel.tsx'
import SignIn from './SignIn.tsx'
import SystemPanel from './SystemPanel.tsx'
@@ -71,7 +72,8 @@ const HELP_KEY = 'linux-manager-ui.help'
* the Status panel, its metrics, its logs, its backups or the updates of its system's packages. A page shows one tab at a time, each read only while shown. An
* administrator switches pages with the page menu at the right end of the header; the button with the user's name,
* left of Sign out, opens the user's own account, and an administrator's shell button, left of it, the shell; pressed
* on their page, each returns to the page it was opened from. While files are open in the shell's editor, the editor
* on their page, each returns to the page it was opened from; with the browser setting shellNewTab the shell button opens
* the shell in a new tab instead. While files are open in the shell's editor, the editor
* button left of the shell button switches the Shell page between the terminal and the editor. The help button, between the theme switcher and the page menu, opens or closes the help on
* the right (HelpPanel) at the topic of the page and tab shown (HELP_TOPICS), the page moving left; the browser keeps
* whether it is open. A call answered 401 ends the session and asks for a sign-in again.
@@ -85,16 +87,19 @@ export default function App(props: { info: Info }) {
const [filesSite, setFilesSite] = useState<string | null>(null)
const [session, setSession] = useState<Session | null | undefined>(undefined)
const [role, setRole] = useState<{ name: string; admin: boolean } | null>(null)
// The router and the VPN components as router.enabled and vpn.enabled of /config; null while not known, when every page shows.
const [components, setComponents] = useState<{ router: boolean; vpn: boolean } | null>(null)
// The router and the VPN components as router.enabled and vpn.enabled of /config, and whether Docker is installed;
// null while not known, when every page shows.
const [components, setComponents] = useState<{ router: boolean; vpn: boolean; docker: boolean } | null>(null)
const routerOff = components?.router === false
const vpnOff = components?.vpn === false
const dockerMissing = components?.docker === false
const page = PAGE_PATHS.find((path) => path === window.location.pathname) ?? '/'
const userPage = page === USER_PATH
const admin = session && role?.name === session.name ? role.admin : undefined
// The account page is the page of every user who is not an administrator, and of an administrator at USER_PATH.
const accountShown = Boolean(session) && admin !== undefined && (userPage || !admin)
const [helpOpen, setHelpOpen] = useState(() => window.localStorage.getItem(HELP_KEY) === 'open')
const { shellNewTab } = useBrowserSettings()
// The files open in the Shell page's editor, and whether the editor is shown in place of the terminal.
const [editorFiles, setEditorFiles] = useState(0)
const [editorShown, setEditorShown] = useState(false)
@@ -142,6 +147,7 @@ export default function App(props: { info: Info }) {
.then((details) => setComponents({
router: details.configuration.router?.enabled === true,
vpn: details.configuration.vpn?.enabled === true,
docker: details.docker.installed,
}))
.catch(() => setComponents(null))
}, [admin])
@@ -208,7 +214,7 @@ export default function App(props: { info: Info }) {
<IconButton
aria-label="shell"
color={page === SHELL_PATH ? 'primary' : 'default'}
onClick={() => toggle(SHELL_PATH)}
onClick={() => (shellNewTab && page !== SHELL_PATH ? window.open(SHELL_PATH, '_blank') : toggle(SHELL_PATH))}
sx={page === SHELL_PATH ? { bgcolor: 'action.selected' } : undefined}
>
<Terminal />
@@ -237,7 +243,9 @@ export default function App(props: { info: Info }) {
</IconButton>
</Tooltip>
)}
{session && admin && <PageMenu path={page} hidden={vpnOff ? [REMOTE_ACCESS_PATH] : []} />}
{session && admin && (
<PageMenu path={page} hidden={[...(vpnOff ? [REMOTE_ACCESS_PATH] : []), ...(dockerMissing ? [DOCKER_PATH] : [])]} />
)}
</Stack>
</Stack>
{session === undefined && <CircularProgress />}
@@ -269,7 +277,10 @@ export default function App(props: { info: Info }) {
{sitesView === 'dns' && <DnsPanel />}
</>
)}
{session && admin && page === DOCKER_PATH && (
{session && admin && page === DOCKER_PATH && dockerMissing && (
<Typography color="text.secondary">Docker is not installed on this server.</Typography>
)}
{session && admin && page === DOCKER_PATH && !dockerMissing && (
<>
<Typography variant="h6" component="h2" sx={{ mb: 2 }}>Docker</Typography>
<DockerPanel />
+77 -34
View File
@@ -5,8 +5,8 @@ import Download from '@mui/icons-material/Download'
import Edit from '@mui/icons-material/Edit'
import Refresh from '@mui/icons-material/Refresh'
import Settings from '@mui/icons-material/Settings'
import Key from '@mui/icons-material/Key'
import UploadFile from '@mui/icons-material/UploadFile'
import WarningAmber from '@mui/icons-material/WarningAmber'
import {
Alert, Box, Button, Chip, IconButton, MenuItem, Stack, Tab, Table, TableBody, TableCell, TableHead, TableRow, Tabs, TextField,
Tooltip, Typography,
@@ -20,10 +20,12 @@ import IssuingCaDialog from './IssuingCaDialog.tsx'
import TemplateDialog from './TemplateDialog.tsx'
import Toolbar from './Toolbar.tsx'
import EkuDialog from './EkuDialog.tsx'
import PkiSettingsDialog, { PUBLISH_LABELS } from './PkiSettingsDialog.tsx'
import PkiSettingsDialog, { PUBLISH_LABELS, ROOT_SOURCE_LABELS } from './PkiSettingsDialog.tsx'
import { Pairs, Section } from './ServerPanel.tsx'
import SetupCodeDialog from './SetupCodeDialog.tsx'
import {
ApiError, BUNDLE_SHAPE, CA_IMPORTED_SHAPE, CRL_IMPORTED_SHAPE, CSR_SHAPE, ISSUED_SHAPE, PFX_SHAPE, PKI_SETTINGS_SHAPE, PKI_SHAPE, REVOKED_SHAPE,
TOKEN_SHAPE,
BUILTIN_TEMPLATES, REVOKE_REASONS, request, type Pki, type PkiCertificate, type PkiIssuingCa, type PkiTemplate,
} from './api.ts'
import { saveFile } from './saveFile.ts'
@@ -32,8 +34,11 @@ import { saveFile } from './saveFile.ts'
* built-in issuing CAs, the general-purpose ones. */
type View = 'root' | 'templates' | 'usages' | 'p2s' | 's2s' | 'issuing'
/** The built-in CAs, whose certificates the Issuing CAs tab leaves out. */
const BUILTIN_CAS = ['root', 'p2s', 's2s']
/** The built-in CAs and the Simple CA issuing CA above them, whose certificates the Issuing CAs tab leaves out. */
const BUILTIN_CAS = ['root', 'upstream', 'p2s', 's2s']
/** Where the root CRL came from. */
const CRL_SOURCE_LABELS: Record<string, string> = { signed: 'signed by the server', uploaded: 'uploaded', fetched: 'fetched from Simple CA' }
/** The note shown after a change, which the server applies when linux-manager-setup has run again. */
const APPLIED = 'The server applies the change in the background.'
@@ -67,8 +72,8 @@ const REASON_LABELS: Record<string, string> = {
* changed and removed there, with their certificates, filtered by CA. The warnings, Issue and Settings
* are above the tabs. Settings edits the pki section, Issue issues a certificate from a CSR or into a PFX file, a
* certificate of another system or of the server is revoked, an issuing CA waiting for the offline root gives its CSR
* and takes its signed certificate, and the root takes a CRL signed offline. The root key is managed on the server
* with linux-manager-ca only.
* and takes its signed certificate, the offline root takes its certificate and a CRL signed offline, and a Simple CA
* root takes a setup code for a new token.
*/
export default function CertificatesPanel() {
const [pki, setPki] = useState<Pki | null>(null)
@@ -83,6 +88,7 @@ export default function CertificatesPanel() {
const [issuing, setIssuing] = useState(false)
const [importing, setImporting] = useState<string | null>(null)
const [uploading, setUploading] = useState(false)
const [entering, setEntering] = useState(false)
const [confirm, setConfirm] = useState<ConfirmDialogProps | null>(null)
const [filter, setFilter] = useState('')
const [view, setView] = useState<View>('root')
@@ -195,7 +201,11 @@ export default function CertificatesPanel() {
function removeAuthority(name: string) {
setConfirm({
title: 'Remove issuing CA',
message: `Remove issuing CA ${name}? The server retires it and revokes its certificate on the root CRL; with the root offline, the root CRL is signed offline. Its certificates stay valid until they expire or are revoked.`,
message: `Remove issuing CA ${name}? The server retires it. ${{
local: 'It revokes its certificate on the root CRL.',
offline: 'Its certificate is revoked on the root CRL signed offline.',
'simple-ca': 'Its certificate is revoked in Simple CA.',
}[pki?.settings.root ?? 'local']} Its certificates stay valid until they expire or are revoked.`,
confirmLabel: 'Remove',
destructive: true,
onCancel: () => setConfirm(null),
@@ -314,7 +324,7 @@ export default function CertificatesPanel() {
</TableCell>
<TableCell align="right" sx={{ whiteSpace: 'nowrap' }}>
{authorityOf(certificate) && (
<Tooltip title="Download the CA bundle: the issuing CA and the root">
<Tooltip title="Download the CA bundle: the issuing CA and the CAs above it">
<span>
<IconButton size="small" disabled={busy} onClick={() => void downloadBundle(authorityOf(certificate)!.name)}>
<Download fontSize="small" />
@@ -356,8 +366,10 @@ export default function CertificatesPanel() {
/>
{authority.state === 'pending' && (
<Stack direction="row" sx={{ mt: 1, alignItems: 'center', justifyContent: 'flex-end', gap: 1 }}>
<Typography variant="body2" color="text.secondary">Waits for its certificate signed by the root:</Typography>
{pendingActions(name)}
<Typography variant="body2" color="text.secondary">
{pki?.settings.root === 'offline' ? 'Waits for its certificate signed by the root:' : 'Waits for its certificate signed by Simple CA.'}
</Typography>
{pki?.settings.root === 'offline' && pendingActions(name)}
</Stack>
)}
{authority.state === 'active' && (
@@ -407,34 +419,51 @@ export default function CertificatesPanel() {
{pki && view === 'root' && (
<Box sx={{ display: 'grid', gap: 2, gridTemplateColumns: { xs: '1fr', md: '1fr 1fr' } }}>
<Section title="Root CA">
{root ? (
{root && (
<>
<Pairs
rows={[
['Subject', root.subject],
['Source', root.source === 'simple-ca' ? `Simple CA, ${root.simple_ca_url}` : ROOT_SOURCE_LABELS[root.source]],
['State', <Chip size="small" label={root.state} color={STATE_COLORS[root.state] ?? 'default'} />],
['Subject', root.subject ?? '-'],
['Expires', when(root.expires)],
['Key', root.key ? (
<Box component="span" sx={{ display: 'inline-flex', alignItems: 'center', gap: 0.5 }}>
on the server
<Tooltip title="Keeping the root key off the server is recommended: linux-manager-ca root export-key, then linux-manager-ca root remove-key.">
<WarningAmber fontSize="small" color="warning" aria-label="The root key is on the server" />
</Tooltip>
</Box>
) : 'offline'],
['CRL valid until', when(root.crl_next_update)],
['CRL', root.crl_source === 'uploaded' ? 'uploaded' : root.crl_source === 'signed' ? 'signed by the server' : '-'],
['CRL', CRL_SOURCE_LABELS[root.crl_source ?? ''] ?? '-'],
...(root.upstream ? [
['Simple CA issuing CA', `${root.upstream.name}: ${root.upstream.subject}`],
['Its expiry', when(root.upstream.expires)],
['Its CRL valid until', when(root.upstream.crl_next_update)],
] as [string, string][] : []),
...(root.source === 'simple-ca' ? [['Token valid until', root.token_expires ? when(root.token_expires) : 'no token']] as [string, string][] : []),
]}
/>
{root.state === 'pending' && root.source === 'local' && (
<Typography variant="body2" color="text.secondary" sx={{ mt: 1 }}>The server creates it once a platform is chosen.</Typography>
)}
<Stack direction="row" sx={{ mt: 1, justifyContent: 'flex-end', gap: 1 }}>
<Button size="small" variant="outlined" startIcon={<Download />} disabled={busy} onClick={() => void downloadBundle('root')}>
Download root CA
</Button>
<Button size="small" variant="outlined" startIcon={<UploadFile />} disabled={busy} onClick={() => setUploading(true)}>
Upload CRL
</Button>
{root.state === 'active' && (
<Button size="small" variant="outlined" startIcon={<Download />} disabled={busy} onClick={() => void downloadBundle('root')}>
Download root CA
</Button>
)}
{root.source === 'offline' && root.state === 'pending' && (
<Button size="small" variant="outlined" startIcon={<UploadFile />} disabled={busy} onClick={() => setImporting('root')}>
Import root certificate
</Button>
)}
{root.source === 'offline' && root.state === 'active' && (
<Button size="small" variant="outlined" startIcon={<UploadFile />} disabled={busy} onClick={() => setUploading(true)}>
Upload CRL
</Button>
)}
{root.source === 'simple-ca' && (
<Button size="small" variant="outlined" startIcon={<Key />} disabled={busy} onClick={() => setEntering(true)}>
Enter setup code
</Button>
)}
</Stack>
</>
) : <Typography variant="body2" color="text.secondary">None yet; the server creates it once a platform is chosen.</Typography>}
)}
</Section>
<Section title="General">
<Pairs
@@ -447,7 +476,7 @@ export default function CertificatesPanel() {
/>
</Section>
<Section title="Issuing CA certificates" wide>
{certificateTable(pki.certificates.filter((certificate) => certificate.ca === 'root'))}
{certificateTable(pki.certificates.filter((certificate) => certificate.ca === 'root' || certificate.ca === 'upstream'))}
{pki.status.retired.length > 0 && (
<Typography variant="body2" color="text.secondary" sx={{ mt: 1 }}>
{`Retired: ${pki.status.retired.map((retired) => `${retired.name} (${when(retired.retired)})`).join(', ')}`}
@@ -622,9 +651,9 @@ export default function CertificatesPanel() {
<TableCell>{authority.templates.join(', ')}</TableCell>
<TableCell sx={{ wordBreak: 'break-all' }}>{authority.acme_url ?? (authority.acme ? 'waits for the certificate' : '-')}</TableCell>
<TableCell align="right" sx={{ whiteSpace: 'nowrap' }}>
{authority.state === 'pending' && pendingActions(authority.name)}
{authority.state === 'pending' && pki.settings.root === 'offline' && pendingActions(authority.name)}
{authority.state === 'active' && (
<Tooltip title="Download the CA bundle: the issuing CA and the root">
<Tooltip title="Download the CA bundle: the issuing CA and the CAs above it">
<span>
<IconButton size="small" disabled={busy} onClick={() => void downloadBundle(authority.name)}><Download fontSize="small" /></IconButton>
</span>
@@ -721,13 +750,15 @@ export default function CertificatesPanel() {
)}
{importing && (
<ImportDialog
title={`Import the certificate of ${importing}`}
message="The certificate of the issuing CA, signed by the root CA for the key of its CSR."
title={importing === 'root' ? 'Import the root certificate' : `Import the certificate of ${importing}`}
message={importing === 'root'
? 'The self-signed certificate of the offline root CA; the certificates of the issuing CAs are imported after it.'
: 'The certificate of the issuing CA, signed by the root CA for the key of its CSR.'}
label="Certificate"
begin="-----BEGIN CERTIFICATE-----"
onCancel={() => setImporting(null)}
onSave={async (certificate) => {
await request('PUT', `/ca/issuing/${importing}/certificate`, CA_IMPORTED_SHAPE, { certificate })
await request('PUT', importing === 'root' ? '/ca/root/certificate' : `/ca/issuing/${importing}/certificate`, CA_IMPORTED_SHAPE, { certificate })
setImporting(null)
setNote(APPLIED)
await refresh()
@@ -748,6 +779,18 @@ export default function CertificatesPanel() {
}}
/>
)}
{entering && root && (
<SetupCodeDialog
url={root.simple_ca_url ?? ''}
onCancel={() => setEntering(false)}
onSave={async (code) => {
await request('PUT', '/ca/root/setup-code', TOKEN_SHAPE, { code })
setEntering(false)
setNote(APPLIED)
await refresh()
}}
/>
)}
{confirm && <ConfirmDialog {...confirm} />}
</Box>
)
+1 -1
View File
@@ -85,7 +85,7 @@ export default function DnsSettingsDialog(props: {
value={ttl}
autoComplete="off"
error={ttlProblem !== ''}
helperText={ttlProblem || 'The TTL of the domains without their own.'}
helperText={ttlProblem || 'The default TTL of the records: used where neither the record nor its domain has one.'}
slotProps={{ htmlInput: { inputMode: 'numeric' } }}
onChange={(event) => setTtl(event.target.value.trim())}
sx={{ flex: 1 }}
+1 -1
View File
@@ -47,7 +47,7 @@ const PAGES: { path: string; label: string; icon: ReactNode }[] = [
/**
* A button naming the page shown, or Pages on the account and the shell page, whose menu opens the pages of an
* administrator but those of hidden, the pages of a component switched off.
* administrator but those of hidden, the pages of a component switched off or of software the server does not have.
*/
export default function PageMenu(props: { path: string; hidden: string[] }) {
const [anchor, setAnchor] = useState<HTMLElement | null>(null)
+37 -7
View File
@@ -3,7 +3,7 @@ import {
Typography,
} from '@mui/material'
import { useState, type FormEvent } from 'react'
import { PKI_KEYS, PKI_PUBLISH, type Pki, type PkiSettings, type PkiTemplate } from './api.ts'
import { PKI_KEYS, PKI_PUBLISH, type Pki, type PkiRootSource, type PkiSettings, type PkiTemplate } from './api.ts'
/** The labels of the publishing endpoints. */
export const PUBLISH_LABELS: Record<string, string> = {
@@ -13,11 +13,18 @@ export const PUBLISH_LABELS: Record<string, string> = {
'https-default': 'HTTPS on port 443, served by Caddy',
}
/** The labels of the sources of the root CA. */
export const ROOT_SOURCE_LABELS: Record<PkiRootSource, string> = {
local: 'Created by the server',
offline: 'Offline',
'simple-ca': 'Simple CA',
}
/** The name of an issuing CA or a template, as the server accepts it. */
export const NAME_PATTERN = /^[a-z][a-z0-9-]{0,30}$/
/** The names the issuing CAs of pki.issuing_cas cannot have. */
export const RESERVED = ['root', 'p2s', 's2s']
export const RESERVED = ['root', 'upstream', 'p2s', 's2s']
/** The longest common name of a CA, in characters. */
const CA_NAME_MAX = 64
@@ -35,6 +42,16 @@ export function nameProblem(value: string) {
return value.trim() === '' || value.trim().length > CA_NAME_MAX ? `1 to ${CA_NAME_MAX} characters.` : ''
}
/** The problem of the URL of a Simple CA service, or ''. */
export function urlProblem(value: string) {
try {
const url = new URL(value.trim())
return url.protocol === 'https:' && url.hostname !== '' && url.search === '' && url.hash === '' ? '' : 'An https:// URL.'
} catch {
return 'An https:// URL.'
}
}
/** A lifetime's problem, or ''. */
export function daysProblem(value: number) {
return !Number.isInteger(value) || value < 1 || value > DAYS_MAX ? `1 to ${DAYS_MAX} days.` : ''
@@ -43,9 +60,10 @@ export function daysProblem(value: number) {
/**
* A dialog that edits the server's pki section but the general-purpose issuing CAs, the templates and the custom
* extended key usages, which IssuingCaDialog, TemplateDialog and EkuDialog edit: the names, lifetimes and key type of
* the CAs, the validity of the CRLs and
* where certificates and CRLs are published. The server applies the names, lifetimes and key type when it creates a
* CA. onSave sends the settings; the dialog closes when it succeeds and shows the server's message when it fails.
* the CAs, the validity of the CRLs, where certificates and CRLs are published and, with a Simple CA root, the URL of
* the service. The source of the root is shown and not edited, as it is fixed once the root exists. The server applies
* the names, lifetimes and key type when it creates a CA. onSave sends the settings; the dialog closes when it
* succeeds and shows the server's message when it fails.
*/
export default function PkiSettingsDialog(props: {
pki: Pki
@@ -60,6 +78,7 @@ export default function PkiSettingsDialog(props: {
const blocked = [
nameProblem(settings.root_name), nameProblem(settings.p2s_name), nameProblem(settings.s2s_name),
daysProblem(settings.root_days), daysProblem(settings.ca_days), daysProblem(settings.crl_days), daysProblem(settings.root_crl_days),
settings.root === 'simple-ca' ? urlProblem(settings.simple_ca_url) : '',
].some((problem) => problem !== '')
async function submit(event: FormEvent) {
@@ -90,7 +109,18 @@ export default function PkiSettingsDialog(props: {
Names, lifetimes and the key type apply when the server creates a CA; URLs apply to the certificates signed afterwards.
</Typography>
<Typography variant="subtitle2">CAs</Typography>
{(['root', 'p2s', 's2s'] as const).map((name) => {
<TextField label="Root CA source" value={ROOT_SOURCE_LABELS[settings.root]} disabled helperText="Fixed once the root exists." />
{settings.root === 'simple-ca' && (
<TextField
label="Simple CA URL"
value={settings.simple_ca_url}
autoComplete="off"
error={urlProblem(settings.simple_ca_url) !== ''}
helperText={urlProblem(settings.simple_ca_url) || 'The service the server exchanges setup codes with and has its issuing CAs signed by.'}
onChange={(event) => change({ simple_ca_url: event.target.value.trim() })}
/>
)}
{(['root', 'p2s', 's2s'] as const).filter((name) => name !== 'root' || settings.root === 'local').map((name) => {
const option = `${name}_name` as 'root_name' | 'p2s_name' | 's2s_name'
return (
<TextField
@@ -144,7 +174,7 @@ export default function PkiSettingsDialog(props: {
type="number"
value={settings.root_crl_days}
error={daysProblem(settings.root_crl_days) !== ''}
helperText={daysProblem(settings.root_crl_days) || 'When the server signs it, with the root key on the server.'}
helperText={daysProblem(settings.root_crl_days) || 'When the server signs it, for a root the server created.'}
onChange={(event) => change({ root_crl_days: number(event.target.value) })}
/>
</Stack>
+9 -4
View File
@@ -1,12 +1,12 @@
import SettingsIcon from '@mui/icons-material/Settings'
import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, IconButton, MenuItem, Stack, TextField, Tooltip } from '@mui/material'
import { Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, FormControlLabel, FormHelperText, IconButton, MenuItem, Stack, Switch, TextField, Tooltip } from '@mui/material'
import { useState } from 'react'
import { DEFAULT_SETTINGS, REFRESH_CHOICES, refreshLabel, saveBrowserSettings, useBrowserSettings } from './settings.ts'
/**
* An icon button that opens the settings of this browser: how often the Overview and the Metrics tab read the server on
* their own, or manual, when they read only when opened and on Refresh. A change applies at once and is kept in the
* browser; Defaults sets every setting back.
* their own, or manual, when they read only when opened and on Refresh, and whether the shell button opens the shell in
* a new tab. A change applies at once and is kept in the browser; Defaults sets every setting back.
*/
export default function SettingsButton() {
const [open, setOpen] = useState(false)
@@ -44,11 +44,16 @@ export default function SettingsButton() {
>
{REFRESH_CHOICES.map((seconds) => <MenuItem key={seconds} value={seconds}>{refreshLabel(seconds)}</MenuItem>)}
</TextField>
<FormControlLabel
control={<Switch checked={settings.shellNewTab} onChange={(event) => saveBrowserSettings({ ...settings, shellNewTab: event.target.checked })} />}
label="Open the shell in a new tab"
/>
<FormHelperText sx={{ mt: -2 }}>The shell then stays open while other pages are opened in this tab.</FormHelperText>
</Stack>
</DialogContent>
<DialogActions>
<Button
onClick={() => saveBrowserSettings({ ...settings, routerRefresh: DEFAULT_SETTINGS.routerRefresh, metricsRefresh: DEFAULT_SETTINGS.metricsRefresh })}
onClick={() => saveBrowserSettings({ ...settings, routerRefresh: DEFAULT_SETTINGS.routerRefresh, metricsRefresh: DEFAULT_SETTINGS.metricsRefresh, shellNewTab: DEFAULT_SETTINGS.shellNewTab })}
>
Defaults
</Button>
+55
View File
@@ -0,0 +1,55 @@
import { Alert, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Stack, TextField } from '@mui/material'
import { useState, type FormEvent } from 'react'
/**
* A dialog that takes the one-time setup code of a sign-ca token of a Simple CA issuing CA, which the server exchanges
* for the token it has its issuing CAs signed with. onSave sends the code; the dialog closes when it succeeds and
* shows the server's message when it fails.
*/
export default function SetupCodeDialog(props: { url: string; onSave: (code: string) => Promise<void>; onCancel: () => void }) {
const [code, setCode] = useState('')
const [saving, setSaving] = useState(false)
const [error, setError] = useState<string | null>(null)
async function submit(event: FormEvent) {
event.preventDefault()
if (code.trim() === '') {
return
}
setSaving(true)
setError(null)
try {
await props.onSave(code.trim())
} catch (caught) {
setError((caught as Error).message)
setSaving(false)
}
}
return (
<Dialog open onClose={(_event, reason) => reason !== 'backdropClick' && props.onCancel()} maxWidth="sm" fullWidth slotProps={{ paper: { component: 'form', onSubmit: submit } }}>
<DialogTitle>Enter a Simple CA setup code</DialogTitle>
<DialogContent>
<Stack sx={{ gap: 2, pt: 1 }}>
{error && <Alert severity="error" sx={{ whiteSpace: 'pre-line' }}>{error}</Alert>}
<DialogContentText>
{`The one-time setup code of a sign-ca token of an issuing CA of ${props.url}. The server exchanges it for the token, which replaces the one it has.`}
</DialogContentText>
<TextField
label="Setup code"
value={code}
autoFocus
autoComplete="off"
helperText="Such as K7QF-M2XA-JP4D-W5ZR; it works once."
slotProps={{ htmlInput: { sx: { fontFamily: 'monospace' } } }}
onChange={(event) => setCode(event.target.value)}
/>
</Stack>
</DialogContent>
<DialogActions>
<Button onClick={props.onCancel}>Cancel</Button>
<Button type="submit" variant="contained" disabled={saving || code.trim() === ''}>Exchange</Button>
</DialogActions>
</Dialog>
)
}
+36 -9
View File
@@ -100,7 +100,8 @@ export type RouterDetails = {
listen_port: number | null
peers: { public_key: string; endpoint: string | null; allowed_ips: string[]; handshake_seconds_ago: number | null; received_bytes: number; sent_bytes: number }[]
} | null
docker: { exposed_ports: string[]; rules: string[] | null }
/** installed is whether docker.service is installed on the server. */
docker: { installed: boolean; exposed_ports: string[]; rules: string[] | null }
/** The PostgreSQL clusters of pg_lsclusters, with the main settings of each online one; null when pg_lsclusters fails. */
postgresql: {
clusters: { version: string; name: string; port: number | null; status: string; data_directory: string; settings: Record<string, string> | null }[]
@@ -375,15 +376,28 @@ export type PkiSettings = {
issuing_cas: Record<string, Partial<PkiIssuingCa>>
templates: Record<string, Partial<PkiTemplate>>
extended_key_usages: Record<string, string>
root: PkiRootSource
simple_ca_url: string
}
/** The root CA: whether its key is on the server, and where its CRL came from, signed by the server or uploaded. */
/** Where the root CA comes from, pki.root: the server creates it, an offline CA, or a Simple CA service. */
export type PkiRootSource = 'local' | 'offline' | 'simple-ca'
/**
* The root CA: its source, active or pending (waiting for its certificate), where its CRL came from (signed by the
* server, uploaded or fetched), and, with Simple CA, the service, the Simple CA issuing CA that signs the issuing CAs,
* and the expiry of the token.
*/
export type PkiRoot = {
subject: string
expires: string
key: boolean
source: PkiRootSource
state: string
subject: string | null
expires: string | null
crl_next_update: string | null
crl_source: string | null
simple_ca_url: string | null
upstream: { name: string; subject: string; expires: string; crl_next_update: string | null } | null
token_expires: string | null
}
/** An issuing CA: state is active, pending (waiting for the offline root) or missing. */
@@ -418,7 +432,7 @@ export type PkiCertificate = {
/**
* GET /ca: the pki section, every template with all its options, every extended key usage with its OID and whether it
* is built in, the root (null before it exists), the issuing CAs, the retired CAs and the warnings, and the
* is built in, the root, the issuing CAs, the retired CAs and the warnings, and the
* certificates issued, newest first.
*/
export type Pki = {
@@ -426,7 +440,7 @@ export type Pki = {
templates: Record<string, PkiTemplate>
extended_key_usages: Record<string, { oid: string; builtin: boolean }>
status: {
root: PkiRoot | null
root: PkiRoot
authorities: PkiAuthority[]
retired: { name: string; retired: string; serial: string | null }[]
warnings: string[]
@@ -701,7 +715,7 @@ export const DETAILS_SHAPE = object({
sent_bytes: number,
})),
})),
docker: object({ exposed_ports: list(string), rules: nullable(list(string)) }),
docker: object({ installed: boolean, exposed_ports: list(string), rules: nullable(list(string)) }),
postgresql: nullable(object({
clusters: list(object({
version: string,
@@ -908,6 +922,8 @@ const PKI_SETTINGS: Check = object({
issuing_cas: record(object({ name: optional(string), templates: optional(list(string)), acme: optional(boolean) })),
templates: record(isObject),
extended_key_usages: record(string),
root: string,
simple_ca_url: string,
})
const PKI_CERTIFICATE: Check = object({
serial: string,
@@ -926,7 +942,17 @@ export const PKI_SHAPE = object({
templates: record(PKI_TEMPLATE),
extended_key_usages: record(object({ oid: string, builtin: boolean })),
status: object({
root: nullable(object({ subject: string, expires: string, key: boolean, crl_next_update: nullable(string), crl_source: nullable(string) })),
root: object({
source: string,
state: string,
subject: nullable(string),
expires: nullable(string),
crl_next_update: nullable(string),
crl_source: nullable(string),
simple_ca_url: nullable(string),
upstream: nullable(object({ name: string, subject: string, expires: string, crl_next_update: nullable(string) })),
token_expires: nullable(string),
}),
authorities: list(object({
name: string,
common_name: string,
@@ -953,6 +979,7 @@ export const BUNDLE_SHAPE = object({ name: string, pem: string })
export const REVOKED_SHAPE: Check = (value) => PKI_CERTIFICATE(value) && object({ reissue: boolean })(value)
export const CA_IMPORTED_SHAPE = object({ name: string, subject: string, expires: string })
export const CRL_IMPORTED_SHAPE = object({ next_update: nullable(string) })
export const TOKEN_SHAPE = object({ upstream: string, expires: nullable(string) })
/** The remote access systems of the server: IKEv2 (p2s), OpenVPN and WireGuard. */
export const REMOTE_ACCESS_SYSTEMS = ['p2s', 'openvpn', 'wireguard'] as const
+5 -3
View File
@@ -2,9 +2,10 @@ import { useSyncExternalStore } from 'react'
/**
* The settings of this browser: the seconds between the automatic reads of the Overview and the Metrics tab, 0 for
* manual, and whether the WireGuard configuration dialog leaves out the lines a client fills in (wireguardPrefilled).
* manual, whether the WireGuard configuration dialog leaves out the lines a client fills in (wireguardPrefilled), and
* whether the shell button opens the shell in a new tab (shellNewTab).
*/
export type BrowserSettings = { routerRefresh: number; metricsRefresh: number; wireguardPrefilled: boolean }
export type BrowserSettings = { routerRefresh: number; metricsRefresh: number; wireguardPrefilled: boolean; shellNewTab: boolean }
/** The localStorage key of the settings. */
const KEY = 'linux-manager-ui.settings'
@@ -12,7 +13,7 @@ const KEY = 'linux-manager-ui.settings'
/** The event raised on window when the settings change in this tab. */
const CHANGED = 'linux-manager-ui-settings'
export const DEFAULT_SETTINGS: BrowserSettings = { routerRefresh: 10, metricsRefresh: 60, wireguardPrefilled: false }
export const DEFAULT_SETTINGS: BrowserSettings = { routerRefresh: 10, metricsRefresh: 60, wireguardPrefilled: false, shellNewTab: false }
/** The refresh choices of both tabs, in seconds; 0 is manual. */
export const REFRESH_CHOICES = [0, 5, 10, 30, 60, 300, 900]
@@ -45,6 +46,7 @@ function snapshot(): BrowserSettings {
routerRefresh: choice(stored.routerRefresh, REFRESH_CHOICES, DEFAULT_SETTINGS.routerRefresh),
metricsRefresh: choice(stored.metricsRefresh, REFRESH_CHOICES, DEFAULT_SETTINGS.metricsRefresh),
wireguardPrefilled: typeof stored.wireguardPrefilled === 'boolean' ? stored.wireguardPrefilled : DEFAULT_SETTINGS.wireguardPrefilled,
shellNewTab: typeof stored.shellNewTab === 'boolean' ? stored.shellNewTab : DEFAULT_SETTINGS.shellNewTab,
}
cached = { text, settings }
return settings