From 95fe938eebead8fa11d03fd902c199f6c234ac35 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Sat, 20 Sep 2025 15:14:41 +0200 Subject: [PATCH] Refactor and comment JS code --- installer/src/tplink.rs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/installer/src/tplink.rs b/installer/src/tplink.rs index f3fc4bf..faac84a 100644 --- a/installer/src/tplink.rs +++ b/installer/src/tplink.rs @@ -272,9 +272,19 @@ async fn handler(state: State, mut req: Request) -> Result { - Globals.models.PTModel.add({applicationName: "rayhunter-root", enableState: 1, entryId: 1, openPort: "2300-2400", openProtocol: "TCP", triggerPort: "$(busybox telnetd -l /bin/sh)", triggerProtocol: "TCP"}); + // Intentionally register rayhunter-daemon before rayhunter-root so that we are less + // likely to run into race conditions where rayhunter-root is launched, and the + // installer kills the server. In practice both HTTP requests may execute concurrently + // anyway. Globals.models.PTModel.add({applicationName: "rayhunter-daemon", enableState: 1, entryId: 2, openPort: "2400-2500", openProtocol: "TCP", triggerPort: "$(/etc/init.d/rayhunter_daemon start)", triggerProtocol: "TCP"}); - alert("Success! You can go back to the rayhunter installer."); + Globals.models.PTModel.add({applicationName: "rayhunter-root", enableState: 1, entryId: 1, openPort: "2300-2400", openProtocol: "TCP", triggerPort: "$(busybox telnetd -l /bin/sh)", triggerProtocol: "TCP"}); + + // Do not use alert(), instead replace page with success message. Using alert() will + // block the event loop in such a way that any background promises are blocked from + // progress too. For example: The HTTP requests to register our port triggers! + document.body.innerHTML = "

Success! You can go back to the rayhunter installer.

"; + + // We can stop polling now, presumably both requests are already inflight. window.clearInterval(window.rayhunterPoll); }, 1000);"#); response = Response::from_parts(parts, Body::from(Bytes::from(data)));