fix: admin/internet: wrong message if https has an error
Massimo Melina committed
Dec 10, 2023 at 14:57 UTC
7598eb9cf6f344e2add6b0d3797198b60983008c
3 files changed
+10
-8
admin/src/InternetPage.ts
+8
-6
@@ -4,7 +4,7 @@ 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 { Flex, LinkBtn, isIP, Btn, modifiedSx, IconBtn, CFG } from './misc'
7
+import { PORT_DISABLED, prefix, 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'
@@ -91,15 +91,17 @@ export default function InternetPage() {
91
}
92
93
function httpsBox() {
94
- const { error, listening } = status.data?.https ||{}
94
const [values, setValues] = useState<any>()
95
const cert = useApiEx('get_cert')
96
useEffect(() => { apiCall('get_config', { only: ['acme_domain', 'acme_email', 'acme_renew'] }).then(setValues) } , [])
97
if (!status || !values) return h(CircularProgress)
99
- return element || status.element || h(TitleCard, { title: "HTTPS", icon: Lock, color: listening && !error ? 'success' : 'warning' },
98
+ const { https } = status.data ||{}
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),
101
- !listening && h(LinkBtn, { onClick: notEnabled }, "Not enabled")
102
- || error && "For HTTPS to work, you need a valid certificate",
103
+ prefix("Error: ", error)
104
+ || disabled && h(LinkBtn, { onClick: notEnabled }, "Not enabled"),
105
cert.element || with_(cert.data, c => h(Box, {},
106
h(CardMembership, { fontSize: 'small', sx: { mr: 1, verticalAlign: 'middle' } }), "Current certificate",
107
h('ul', {},
@@ -141,7 +143,7 @@ export default function InternetPage() {
143
await apiCall('make_cert', { domain, altNames, email: values.acme_email }, { timeout: 20_000 })
144
.then(async () => {
145
await alertDialog("Certificate created", 'success')
144
- if (!listening)
146
+ if (disabled)
147
await notEnabled()
148
cert.reload()
149
}, alertDialog)
src/cross-const.ts
+1
@@ -9,6 +9,7 @@ export const FRONTEND_URI = SPECIAL_URI + 'frontend/'
9
export const ADMIN_URI = SPECIAL_URI + 'admin/'
10
export const API_URI = SPECIAL_URI + 'api/'
11
export const PLUGINS_PUB_URI = SPECIAL_URI + 'plugins/'
12
+export const PORT_DISABLED = -1
13
14
export const HTTP_OK = 200
15
export const HTTP_NO_CONTENT = 204
src/listen.ts
+1
-2
@@ -9,7 +9,7 @@ import { networkInterfaces } from 'os';
9
import { newConnection } from './connections'
10
import open from 'open'
11
import { debounceAsync, ipForUrl, objSameKeys, onlyTruthy, runAt, wait, waitFor } from './misc'
12
-import { ADMIN_URI, argv, DEV, IS_WINDOWS } from './const'
12
+import { PORT_DISABLED, ADMIN_URI, argv, DEV, IS_WINDOWS } from './const'
13
import findProcess from 'find-process'
14
import { anyAccountCanLoginAdmin } from './adminApis'
15
import _ from 'lodash'
@@ -159,7 +159,6 @@ for (const cfg of httpsNeeds) {
159
})
160
}
161
162
-const PORT_DISABLED = -1
162
export const httpsPortCfg = defineConfig('https_port', PORT_DISABLED)
163
httpsPortCfg.sub(considerHttps)
164
listenInterface.sub(considerHttps)