@samitouri / QOSami-HFS / commits / cc8aecc8

admin/internet: let continue with certificate even if domain fails the check

Massimo Melina committed Oct 4, 2023 at 22:37 UTC cc8aecc834537f591c05f4935949fd9df821541e
3 files changed +6 -3
admin/src/InternetPage.ts
+3
@@ -82,6 +82,9 @@ export default function InternetPage() {
82 if (fresh && !await confirmDialog("Your certificate is still good", { confirmText: "Make a new one anyway" }))
83 return
84 if (!await confirmDialog("HFS must temporarily serve HTTP on public port 80, and your router must be configured or this operation will fail")) return
85 + const res = await apiCall('check_domain', { domain }).catch(e =>
86 + confirmDialog(String(e), { confirmText: "Continue anyway" }) )
87 + if (res === false) return
88 await apiCall('make_cert', { domain, email: values.acme_email }, { timeout: 20_000 })
89 .then(async () => {
90 await alertDialog("Certificate created", 'success')
src/api.net.ts
+2 -3
@@ -3,7 +3,7 @@
3 import { ApiError, ApiHandlers } from './apiMiddleware'
4 import { Client } from 'nat-upnp-ts'
5 import {
6 - HTTP_BAD_REQUEST, HTTP_FAILED_DEPENDENCY, HTTP_OK, HTTP_SERVER_ERROR, HTTP_SERVICE_UNAVAILABLE,
6 + HTTP_BAD_REQUEST, HTTP_FAILED_DEPENDENCY, HTTP_OK, HTTP_SERVER_ERROR, HTTP_SERVICE_UNAVAILABLE, HTTP_PRECONDITION_FAILED,
7 IS_MAC, IS_WINDOWS
8 } from './const'
9 import _ from 'lodash'
@@ -120,12 +120,11 @@ async function checkDomain(domain: string) {
120 const domainIpsThisVersion = domainIps.filter(x => isIPv6(x) === v6)
121 const ipsThisVersion = publicIps.filter(x => isIPv6(x) === v6)
122 if (domainIpsThisVersion.length && ipsThisVersion.length && !_.intersection(domainIpsThisVersion, ipsThisVersion).length)
123 - throw new ApiError(HTTP_FAILED_DEPENDENCY, `configure your domain to point to ${ipsThisVersion} (currently on ${domainIpsThisVersion[0]}) – a change can take hours to be effective`)
123 + throw new ApiError(HTTP_PRECONDITION_FAILED, `configure your domain to point to ${ipsThisVersion} (currently on ${domainIpsThisVersion[0]}) – a change can take hours to be effective`)
124 }
125 }
126
127 async function generateSSLCert(domain: string, email?: string) {
128 - await checkDomain(domain)
128 // will answer challenge through our koa app (if on port 80) or must we spawn a dedicated server?
129 const { upnp, externalPort } = await getNatInfo()
130 const { http } = await getServerStatus()
src/const.ts
+1
@@ -41,6 +41,7 @@ export const HTTP_NOT_FOUND = 404
41 export const HTTP_METHOD_NOT_ALLOWED = 405
42 export const HTTP_NOT_ACCEPTABLE = 406
43 export const HTTP_CONFLICT = 409
44 +export const HTTP_PRECONDITION_FAILED = 412
45 export const HTTP_PAYLOAD_TOO_LARGE = 413
46 export const HTTP_RANGE_NOT_SATISFIABLE = 416
47 export const HTTP_FOOL = 418