MCPcopy Create free account
hub / github.com/rejetto/hfs / httpsBox

Function httpsBox

admin/src/InternetPage.ts:172–254  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

170 }
171
172 function httpsBox() {
173 const [values, setValues] = useState<any>()
174 const cert = useApiEx('get_cert')
175 useEffect(() => { apiCall('get_config', { only: ['acme_domain', 'acme_renew'] }).then(setValues) } , [])
176 const [saving, setSaving] = useState(false)
177 if (!values) return h(CircularProgress)
178 const { https } = status.data ||{}
179 const disabled = https?.port === PORT_DISABLED
180 const error = https?.error
181 return status.element || h(TitleCard, { title: "HTTPS", icon: Lock, color: https?.listening && !error ? 'success' : 'warning' },
182 error ? h(Alert, { severity: 'warning' }, error) :
183 (disabled && h(LinkBtn, { onClick: notEnabled }, "Not enabled")),
184 cert.element || with_(cert.data, c => c.none ? h(LinkBtn, { onClick: noCertClick }, "No certificate configured") : h(Box, {},
185 h(CardMembership, { fontSize: 'small', sx: { mr: 1, verticalAlign: 'middle' } }), "Current certificate",
186 h('ul', {},
187 h('li', {}, "Domain: ", c.altNames?.join(' + ') ||'-'),
188 h('li', {}, "Issuer: ", c.issuer?.O || h('i', {}, 'self-signed')),
189 h('li', {}, "Validity: ", ['validFrom', 'validTo'].map(k => formatTimestamp(c[k])).join(' – ')),
190 )
191 )),
192 h(Divider),
193 h(Form, {
194 gap: 1,
195 gridProps: {rowSpacing:1},
196 values,
197 set(v, k) {
198 setValues((was: any) => {
199 const values = { ...was, [k]: v }
200 setSaving(true)
201 apiCall('set_config', { values }).finally(() => setSaving(false))
202 return values
203 })
204 },
205 fields: [
206 md("Generate certificate using [Let's Encrypt](https://letsencrypt.org)"),
207 {
208 k: 'acme_domain',
209 label: "Domain for certificate",
210 sm: values.acme_domain?.length > 30 ? 12 : 6,
211 required: true,
212 multiline: true,
213 fromField: x => x.replaceAll('\n', ','),
214 toField: x => x.replaceAll(',', '\n'),
215 helperText: md("Example: your.domain.com\nMultiple domains on separate lines")
216 },
217 {
218 k: 'acme_renew',
219 label: "Automatic renew one month before expiration",
220 comp: BoolField,
221 disabled: !values.acme_domain
222 },
223 with_(status.data.acmeRenewError, x => x && h(Alert, { severity: 'error' }, x)),
224 ],
225 save: {
226 children: "Request",
227 startIcon: h(Send),
228 ...saving && { loading: true },
229 async onClick() {

Callers 1

InternetPageFunction · 0.85

Calls 6

useApiExFunction · 0.90
apiCallFunction · 0.90
formatTimestampFunction · 0.90
hFunction · 0.85
with_Function · 0.85
mdFunction · 0.85

Tested by

no test coverage detected