@samitouri / QOSami-HFS / commits / 285c0cdb

fix: missing error on missing certificate

Massimo Melina committed Dec 10, 2023 at 18:33 UTC 285c0cdb784b955c6e446d778c41da59a8359e0a
2 files changed +23 -24
admin/src/InternetPage.ts
+5 -6
@@ -4,11 +4,11 @@ import { CardMembership, HomeWorkTwoTone, Lock, Public, PublicTwoTone, RestartAl
4 SvgIconComponent } from '@mui/icons-material'
5 import { apiCall, useApiEx } from './api'
6 import { closeDialog, DAY, formatTimestamp, wait, wantArray, with_ } from '@hfs/shared'
7 -import { PORT_DISABLED, prefix, Flex, LinkBtn, isIP, Btn, modifiedSx, IconBtn, CFG } from './misc'
7 +import { PORT_DISABLED, Flex, LinkBtn, isIP, Btn, modifiedSx, IconBtn, CFG } from './misc'
8 import { alertDialog, confirmDialog, promptDialog, toast, waitDialog } from './dialog'
9 import { BoolField, Form, FormProps, MultiSelectField, NumberField, SelectField } from '@hfs/mui-grid-form'
10 import md from './md'
11 -import { isCertError } from './OptionsPage'
11 +import { suggestMakingCert } from './OptionsPage'
12 import { changeBaseUrl } from './FileForm'
13 import { getNatInfo } from '../../src/nat'
14 import { ALL, WITH_IP } from './countries'
@@ -99,10 +99,9 @@ export default function InternetPage() {
99 const disabled = https?.port === PORT_DISABLED
100 const error = https?.error
101 return element || status.element || h(TitleCard, { title: "HTTPS", icon: Lock, color: https?.listening && !error ? 'success' : 'warning' },
102 - isCertError(error) && h(Alert, { severity: 'warning' }, error),
103 - prefix("Error: ", error)
104 - || disabled && h(LinkBtn, { onClick: notEnabled }, "Not enabled"),
105 - cert.element || with_(cert.data, c => c.none ? "No certificate configured" : h(Box, {},
102 + error ? h(Alert, { severity: 'warning' }, error) :
103 + (disabled && h(LinkBtn, { onClick: notEnabled }, "Not enabled")),
104 + cert.element || with_(cert.data, c => c.none ? h(LinkBtn, { onClick: () => suggestMakingCert().then(cert.reload) }, "No certificate configured") : h(Box, {},
105 h(CardMembership, { fontSize: 'small', sx: { mr: 1, verticalAlign: 'middle' } }), "Current certificate",
106 h('ul', {},
107 h('li', {}, "Domain: ", c.altNames?.join(' + ') ||'-'),
src/listen.ts
+18 -18
@@ -93,25 +93,25 @@ const considerHttps = debounceAsync(async () => {
93 )
94 if (port >= 0) {
95 const cert = getCertObject()
96 - if (!cert) return
97 - const cn = cert.subject?.CN
98 - if (cn)
99 - console.log("certificate loaded for", cn)
100 - const now = new Date()
101 - const from = new Date(cert.validFrom)
102 - const to = new Date(cert.validTo)
103 - updateError() // error will change at from and to dates of the certificate
104 - const cancelTo = runAt(to.getTime(), updateError)
105 - const cancelFrom = runAt(from.getTime(), updateError)
106 - httpsSrv.on('close', () => {
107 - cancelTo()
108 - cancelFrom()
109 - })
110 - function updateError() {
111 - if (!httpsSrv) return
112 - httpsSrv.error = from > now ? "certificate not valid yet" : to < now ? "certificate expired" : undefined
96 + if (cert) {
97 + const cn = cert.subject?.CN
98 + if (cn)
99 + console.log("certificate loaded for", cn)
100 + const now = new Date()
101 + const from = new Date(cert.validFrom)
102 + const to = new Date(cert.validTo)
103 + updateError() // error will change at from and to dates of the certificate
104 + const cancelTo = runAt(to.getTime(), updateError)
105 + const cancelFrom = runAt(from.getTime(), updateError)
106 + httpsSrv.on('close', () => {
107 + cancelTo()
108 + cancelFrom()
109 + })
110 + function updateError() {
111 + if (!httpsSrv) return
112 + httpsSrv.error = from > now ? "certificate not valid yet" : to < now ? "certificate expired" : undefined
113 + }
114 }
114 -
115 const namesForOutput: any = { cert: 'certificate', private_key: 'private key' }
116 const missing = httpsNeeds.find(x => !x.get())?.key()
117 if (missing)