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
Release / release (push) Failing after 8s
This commit is contained in:
1 parent
a649331aa2
commit
a7bfabcb89
97 files changed
+4498
-1834
No files matched your search
@@ -0,0 +1,187 @@
|
||||
import Settings from '@mui/icons-material/Settings'
|
||||
import { Alert, Box, Button, Chip, IconButton, Stack, Tooltip, Typography } from '@mui/material'
|
||||
import { useCallback, useEffect, useState, type ReactNode } from 'react'
|
||||
import AcmeSettingsDialog, { PROVIDER_LABELS } from './AcmeSettingsDialog.tsx'
|
||||
import { when } from './BackupSummary.tsx'
|
||||
import HttpsSettingsDialog, { CERTIFICATE_LABELS } from './HttpsSettingsDialog.tsx'
|
||||
import ImportDialog from './ImportDialog.tsx'
|
||||
import PfxDialog from './PfxDialog.tsx'
|
||||
import { Pairs, Section, text } from './ServerPanel.tsx'
|
||||
import { saveFile } from './saveFile.ts'
|
||||
import {
|
||||
DETAILS_SHAPE, HTTPS_CSR_SHAPE, HTTPS_IMPORTED_SHAPE, HTTPS_SETTINGS_SHAPE, request, type HttpsCertificate, type HttpsChange,
|
||||
type HttpsSettings, type RouterDetails,
|
||||
} from './api.ts'
|
||||
|
||||
/**
|
||||
* The Server tab of the Certificates page, the server's HTTPS from /config and /https/settings: whether HTTPS is on and
|
||||
* for which name, with a chip while the certificate has another source than ACME and a button that opens
|
||||
* HttpsSettingsDialog; the certificate of a source other than ACME, and, for one of another CA, Generate CSR, Import
|
||||
* certificate and Import PFX; the ACME CA with a chip while it is Let's Encrypt's staging environment and a button that
|
||||
* opens AcmeSettingsDialog; and Caddy, its version and the state of caddy.service. Until the first setup
|
||||
* chooses the source, the HTTPS row says so and the served self-signed certificate is shown. Read when it is shown; the
|
||||
* page's Refresh shows it again.
|
||||
*/
|
||||
export default function ServerCertificatePanel() {
|
||||
const [details, setDetails] = useState<RouterDetails | null>(null)
|
||||
const [certificate, setCertificate] = useState<HttpsCertificate | null>(null)
|
||||
const [reading, setReading] = useState(true)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [note, setNote] = useState<string | null>(null)
|
||||
const [settings, setSettings] = useState<{ dialog: 'https' | 'acme'; settings: HttpsSettings } | null>(null)
|
||||
const [importing, setImporting] = useState<'certificate' | 'pfx' | null>(null)
|
||||
|
||||
const refresh = useCallback(async () => {
|
||||
setReading(true)
|
||||
try {
|
||||
const [nextDetails, nextHttps] = await Promise.all([
|
||||
request<RouterDetails>('GET', '/config', DETAILS_SHAPE),
|
||||
request<{ certificate?: HttpsCertificate }>('GET', '/https/settings', HTTPS_SETTINGS_SHAPE),
|
||||
])
|
||||
setDetails(nextDetails)
|
||||
setCertificate(nextHttps.certificate ?? null)
|
||||
setError(null)
|
||||
} catch (caught) {
|
||||
setError(`The server did not give its HTTPS settings: ${(caught as Error).message}`)
|
||||
} finally {
|
||||
setReading(false)
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
void refresh()
|
||||
}, [refresh])
|
||||
|
||||
/** Reads the server's https section from /https/settings and opens HttpsSettingsDialog or AcmeSettingsDialog with it. */
|
||||
async function open(dialog: 'https' | 'acme') {
|
||||
setError(null)
|
||||
try {
|
||||
setSettings({ dialog, settings: (await request<{ settings: HttpsSettings }>('GET', '/https/settings', HTTPS_SETTINGS_SHAPE)).settings })
|
||||
} catch (caught) {
|
||||
setError(`The server did not give its HTTPS settings: ${(caught as Error).message}`)
|
||||
}
|
||||
}
|
||||
|
||||
/** Sends a change of HttpsSettingsDialog or AcmeSettingsDialog to /https/settings and closes the dialog. */
|
||||
async function save(values: HttpsChange) {
|
||||
await request('PUT', '/https/settings', HTTPS_SETTINGS_SHAPE, values)
|
||||
setSettings(null)
|
||||
setNote('The server runs its setup again, which applies the change.')
|
||||
void refresh()
|
||||
}
|
||||
|
||||
/** Saves a new CSR for the server's FQDN, to be signed by another CA. */
|
||||
async function downloadCsr() {
|
||||
setError(null)
|
||||
try {
|
||||
const { csr } = await request<{ csr: string }>('POST', '/https/csr', HTTPS_CSR_SHAPE)
|
||||
saveFile(`${certificate?.subject ?? 'server'}.csr`, csr, 'application/pkcs10')
|
||||
void refresh()
|
||||
} catch (caught) {
|
||||
setError(`The server made no CSR: ${(caught as Error).message}`)
|
||||
}
|
||||
}
|
||||
|
||||
const https = details?.configuration.https
|
||||
const fqdn = String(details?.configuration.wan?.local_fqdn ?? '')
|
||||
const httpsOn = https?.enabled === true
|
||||
const chosen = certificate !== null && certificate.source !== ''
|
||||
const other = httpsOn && certificate !== null && certificate.source !== 'acme'
|
||||
|
||||
return (
|
||||
<Box>
|
||||
{error && <Alert severity="warning" sx={{ mb: 2 }} onClose={() => setError(null)}>{error}</Alert>}
|
||||
{note && <Alert severity="info" sx={{ mb: 2 }} onClose={() => setNote(null)}>{note}</Alert>}
|
||||
{details === null ? (
|
||||
<Typography variant="body2" color="text.secondary">{reading ? 'Reading the server\'s HTTPS settings.' : 'The server\'s HTTPS settings are not read.'}</Typography>
|
||||
) : (
|
||||
<Section title="HTTPS">
|
||||
<Pairs
|
||||
rows={[
|
||||
['HTTPS', (
|
||||
<Stack key="https" direction="row" sx={{ alignItems: 'center', gap: 1, flexWrap: 'wrap' }}>
|
||||
<span>{httpsOn ? (fqdn ? `on, for ${fqdn}` : 'on, but wan.local_fqdn is not set') : 'off'}</span>
|
||||
{other && certificate.source !== '' && <Chip size="small" label={CERTIFICATE_LABELS[certificate.source]} color={certificate.served === certificate.source ? 'default' : 'warning'} />}
|
||||
{httpsOn && !chosen && <Typography variant="body2" color="text.secondary">certificate chosen by the next setup</Typography>}
|
||||
<Tooltip title="HTTPS certificate">
|
||||
<IconButton size="small" aria-label="HTTPS certificate" onClick={() => void open('https')}>
|
||||
<Settings fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</Stack>
|
||||
)],
|
||||
...(other ? [['HTTPS certificate', (
|
||||
<Stack key="certificate" sx={{ gap: 0.5 }}>
|
||||
<span>
|
||||
{certificate.subject
|
||||
? `${certificate.served === certificate.source || !chosen ? '' : 'self-signed until the chosen one is available: '}${certificate.subject}, issued by ${certificate.issuer ?? '-'}, expires ${when(certificate.expires)}`
|
||||
: 'none yet'}
|
||||
</span>
|
||||
{certificate.source === 'external' && (
|
||||
<Stack direction="row" sx={{ gap: 1, flexWrap: 'wrap' }}>
|
||||
<Button size="small" variant="outlined" onClick={() => void downloadCsr()}>
|
||||
{certificate.pending ? 'New CSR' : 'Generate CSR'}
|
||||
</Button>
|
||||
<Button size="small" variant="outlined" disabled={!certificate.pending} onClick={() => setImporting('certificate')}>
|
||||
Import certificate
|
||||
</Button>
|
||||
<Button size="small" variant="outlined" onClick={() => setImporting('pfx')}>
|
||||
Import PFX
|
||||
</Button>
|
||||
</Stack>
|
||||
)}
|
||||
</Stack>
|
||||
)] as [string, ReactNode]] : []),
|
||||
['ACME CA', (
|
||||
<Stack key="acme" direction="row" sx={{ alignItems: 'center', gap: 1, flexWrap: 'wrap' }}>
|
||||
<span>{PROVIDER_LABELS[https?.acme_provider as keyof typeof PROVIDER_LABELS] ?? text(https?.acme_provider)}</span>
|
||||
{https?.acme_provider === 'letsencrypt' && https?.acme_staging === true && <Chip size="small" label="Let's Encrypt staging" color="warning" />}
|
||||
<Tooltip title="ACME CA settings">
|
||||
<IconButton size="small" aria-label="ACME CA settings" onClick={() => void open('acme')}>
|
||||
<Settings fontSize="small" />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
</Stack>
|
||||
)],
|
||||
['Caddy', (
|
||||
<Stack key="caddy" direction="row" sx={{ alignItems: 'center', gap: 1, flexWrap: 'wrap' }}>
|
||||
<span>{details.caddy ? details.caddy.version : 'not installed'}</span>
|
||||
{details.caddy?.service && <Chip size="small" label={details.caddy.service} color={details.caddy.service === 'active' ? 'success' : 'warning'} />}
|
||||
</Stack>
|
||||
)],
|
||||
]}
|
||||
/>
|
||||
</Section>
|
||||
)}
|
||||
|
||||
{settings?.dialog === 'https' && <HttpsSettingsDialog current={settings.settings} onCancel={() => setSettings(null)} onSave={save} />}
|
||||
{settings?.dialog === 'acme' && <AcmeSettingsDialog current={settings.settings} onCancel={() => setSettings(null)} onSave={save} />}
|
||||
{importing === 'certificate' && (
|
||||
<ImportDialog
|
||||
title="Import the HTTPS certificate"
|
||||
message="The certificate another CA signed for the server's CSR, followed by its chain."
|
||||
label="Certificate"
|
||||
begin="-----BEGIN CERTIFICATE-----"
|
||||
onCancel={() => setImporting(null)}
|
||||
onSave={async (value) => {
|
||||
await request('PUT', '/https/certificate', HTTPS_IMPORTED_SHAPE, { certificate: value })
|
||||
setImporting(null)
|
||||
setNote('The server runs its setup again, which serves the certificate.')
|
||||
void refresh()
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{importing === 'pfx' && (
|
||||
<PfxDialog
|
||||
onCancel={() => setImporting(null)}
|
||||
onSave={async (pfx, password) => {
|
||||
await request('PUT', '/https/pfx', HTTPS_IMPORTED_SHAPE, { pfx, password })
|
||||
setImporting(null)
|
||||
setNote('The server runs its setup again, which serves the certificate.')
|
||||
void refresh()
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user