check all public IPs, not just one

Massimo Melina committed Oct 2, 2023 at 00:28 UTC bc39c8b08b08054d81e677101fc284071533b321
2 files changed +13 -11
admin/src/InternetPage.ts
+7 -4
@@ -154,10 +154,13 @@ export default function InternetPage() {
154 if (!verifyAgain && !await confirmDialog("This test will check if your server is working properly on the Internet")) return
155 setChecking(true)
156 try {
157 - const { success } = await apiCall('check_server', {})
158 - setCheckResult(success)
159 - if (success)
160 - return toast("Your server is responding correctly over the Internet", 'success')
157 + const res = await apiCall('check_server', {})
158 + if (res.some((x: any) => x.success)) {
159 + setCheckResult(true)
160 + const specify = res.every((x: any) => x.success) ? '' : ` with address ${res.map((x: any) => x.ip).join(' + ')}`
161 + return toast("Your server is responding correctly over the Internet" + specify, 'success')
162 + }
163 + setCheckResult(false)
164 if (wrongMap)
165 return fixPort().then(retry)
166 if (doubleNat)
src/api.net.ts
+6 -7
@@ -188,6 +188,7 @@ async function checkPort(ip: string, port: number) {
188 regexpSuccess: string
189 }
190 const prjInfo = await getProjectInfo()
191 + console.log(`checking server ${ip}:${port}`)
192 for (const services of _.chunk(_.shuffle<PortScannerService>(prjInfo.checkServerServices), 2)) {
193 try {
194 return Promise.any(services.map(async ({ url, body, selector, regexpSuccess, regexpFailure, ...rest }) => {
@@ -198,7 +199,7 @@ async function checkPort(ip: string, port: number) {
199 const failure = new RegExp(regexpFailure).test(res)
200 if (success === failure) throw console.debug('inconsistent:' + service) // this result cannot be trusted
201 console.debug(service, 'responded', success)
201 - return { success, service }
202 + return { success, service, ip, port }
203 }))
204 }
205 catch {}
@@ -233,15 +234,13 @@ const apis: ApiHandlers = {
234
235 async check_server({ port }) {
236 const { publicIps, internalPort, externalPort } = await getNatInfo()
236 - const ip = publicIps[0]
237 - if (!ip)
238 - return new ApiError(HTTP_SERVICE_UNAVAILABLE, 'cannot detect public ip')
237 + if (!publicIps.length)
238 + return new ApiError(HTTP_FAILED_DEPENDENCY, 'cannot detect public ip')
239 if (!internalPort)
240 return new ApiError(HTTP_FAILED_DEPENDENCY, 'no internal port')
241 port ||= externalPort || internalPort
242 - console.log(`checking server ${ip}:${port}`)
243 - return await checkPort(ip, port)
244 - || new ApiError(HTTP_SERVICE_UNAVAILABLE)
242 + const res = await promiseBestEffort(publicIps.map(ip => checkPort(ip, port)))
243 + return res.length ? res : new ApiError(HTTP_SERVICE_UNAVAILABLE)
244 },
245
246 async make_cert({domain, email}) {