Feat : Tailscale

This commit is contained in:
decolua
2026-04-11 11:36:33 +07:00
parent 838d9a7a04
commit ed17a8ffac
18 changed files with 1433 additions and 388 deletions
+29
View File
@@ -3,6 +3,7 @@ const fs = require("fs");
const path = require("path");
const dns = require("dns");
const { promisify } = require("util");
const { execSync } = require("child_process");
const { log, err } = require("./logger");
const { TARGET_HOSTS, URL_PATTERNS, getToolForHost } = require("./config");
const { DATA_DIR, MITM_DIR } = require("./paths");
@@ -218,6 +219,34 @@ const server = https.createServer(sslOptions, async (req, res) => {
}
});
// Kill any process occupying LOCAL_PORT before binding
function killPort(port) {
try {
const pids = execSync(`lsof -ti :${port}`, { encoding: "utf-8" }).trim();
if (!pids) return;
const pidList = pids.split("\n");
pidList.forEach(pid => {
try {
process.kill(Number(pid), "SIGKILL");
} catch (e) {
err(`Failed to kill PID ${pid}: ${e.message}`);
throw e;
}
});
log(`Killed ${pidList.length} process(es) on port ${port}`);
} catch (e) {
// lsof exits with status 1 when no process found — that's fine
if (e.status !== 1) throw e;
}
}
try {
killPort(LOCAL_PORT);
} catch (e) {
err(`Cannot kill process on port ${LOCAL_PORT}: ${e.message}`);
process.exit(1);
}
server.listen(LOCAL_PORT, () => log(`🚀 Server ready on :${LOCAL_PORT}`));
server.on("error", (e) => {