admin/internet/verify: before trying port 1080, try same port
Massimo Melina committed
Sep 22, 2023 at 16:19 UTC
0f5459fe74f0687d1fbcbb8fe5fc87988e746a9f
1 file changed
+12
-7
admin/src/InternetPage.ts
+12
-7
@@ -28,8 +28,8 @@ export default function InternetPage() {
28
const doubleNat = nat?.externalIp && nat.externalIp !== nat.publicIp
29
useEffect(() => {
30
if (!verifyAgain || !nat || loading) return
31
- setVerifyAgain(false)
31
verify().then()
32
+ setVerifyAgain(false)
33
}, [verifyAgain, nat, loading])
34
return h(Flex, { vert: true, gap: '2em', maxWidth: '40em' },
35
h(Alert, { severity: 'info' }, "This page helps you making your server work on the Internet"),
@@ -147,7 +147,7 @@ export default function InternetPage() {
147
148
async function verify(): Promise<any> {
149
setCheckResult(undefined)
150
- if (!await confirmDialog("This test will check if your server is working properly on the Internet")) return
150
+ if (!verifyAgain && !await confirmDialog("This test will check if your server is working properly on the Internet")) return
151
setChecking(true)
152
try {
153
const { success } = await apiCall('check_server', {})
@@ -161,7 +161,11 @@ export default function InternetPage() {
161
const msg = "We couldn't reach your server from the Internet. "
162
if (nat.upnp && !nat.mapped)
163
return confirmDialog(msg + "Try port-forwarding on your router", { confirmText: "Fix it" }).then(go => {
164
- if (go) mapPort(Math.max(nat.internalPort, HIGHER_PORT), "Port forwarded").then(retry)
164
+ if (!go) return
165
+ try { mapPort(nat.internalPort, '', '') }
166
+ catch { mapPort(HIGHER_PORT, '') }
167
+ toast("Port forwarded, now verify again", 'success')
168
+ retry()
169
})
170
const { close } = alertDialog(h(Box, {}, msg + "Possible causes:", h('ul', {},
171
!nat.upnp && h('li', {}, "Your router may need to be configured. ", h(Link, { href: PORT_FORWARD_URL, target: 'help' }, "How?")),
@@ -210,7 +214,7 @@ export default function InternetPage() {
214
return mapPort(nat.externalPort, "Forwarding corrected")
215
}
216
213
- async function mapPort(external: number, msg='') {
217
+ async function mapPort(external: number, msg='', errMsg="Operation failed") {
218
setMapping(true)
219
try {
220
await apiCall('map_port', { external })
@@ -218,9 +222,10 @@ export default function InternetPage() {
222
if (msg) toast(msg, 'success')
223
}
224
catch(e) {
221
- const msg = "Operation failed"
222
- + (external && Math.min(external, nat.internalPort) ? ". Some routers refuse to work with ports under 1024." : '')
223
- await alertDialog(msg, 'error')
225
+ if (errMsg) {
226
+ const msg = errMsg + (external && Math.min(external, nat.internalPort) ? ". Some routers refuse to work with ports under 1024." : '')
227
+ await alertDialog(msg, 'error')
228
+ }
229
throw e
230
}
231
finally {