Add a testing allow-all mode to the remchild server
This commit is contained in:
@@ -8,6 +8,7 @@
|
|||||||
*
|
*
|
||||||
* Run: node remchild/server/server.mjs --port 8799 --ips 127.0.0.1,192.168.1.5
|
* Run: node remchild/server/server.mjs --port 8799 --ips 127.0.0.1,192.168.1.5
|
||||||
* node remchild/server/server.mjs --allow-non-lan --ips 203.0.113.7
|
* node remchild/server/server.mjs --allow-non-lan --ips 203.0.113.7
|
||||||
|
* node remchild/server/server.mjs --allow-all # testing: any address
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
import { appendFileSync, existsSync, mkdirSync, readFileSync } from "node:fs";
|
||||||
@@ -28,6 +29,7 @@ function arg(name, fallback = undefined) {
|
|||||||
|
|
||||||
const port = Number(arg("port", process.env.REMCHILD_PORT ?? 8799));
|
const port = Number(arg("port", process.env.REMCHILD_PORT ?? 8799));
|
||||||
const allowNonLan = arg("allow-non-lan", false) !== false;
|
const allowNonLan = arg("allow-non-lan", false) !== false;
|
||||||
|
const allowAll = arg("allow-all", false) !== false;
|
||||||
const historyFile = arg("history", join(HERE, "clients.jsonl"));
|
const historyFile = arg("history", join(HERE, "clients.jsonl"));
|
||||||
const configFile = arg("config", join(HERE, "config.json"));
|
const configFile = arg("config", join(HERE, "config.json"));
|
||||||
|
|
||||||
@@ -55,6 +57,7 @@ function isLan(address) {
|
|||||||
|
|
||||||
/** The allowlist rule: known IPs only; non-LAN entries need the launch flag. */
|
/** The allowlist rule: known IPs only; non-LAN entries need the launch flag. */
|
||||||
function allowed(address) {
|
function allowed(address) {
|
||||||
|
if (allowAll) return true;
|
||||||
if (configured.length === 0) return isLan(address);
|
if (configured.length === 0) return isLan(address);
|
||||||
return configured.includes(address);
|
return configured.includes(address);
|
||||||
}
|
}
|
||||||
@@ -111,7 +114,7 @@ const server = net.createServer(socket => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (configured.length && !isLan(address) && allowNonLan !== true) {
|
if (!allowAll && configured.length && !isLan(address) && allowNonLan !== true) {
|
||||||
console.log(`[remchild] rejected ${address} (non-LAN address needs --allow-non-lan)`);
|
console.log(`[remchild] rejected ${address} (non-LAN address needs --allow-non-lan)`);
|
||||||
socket.end(JSON.stringify({ type: "reject", reason: "non-lan locked" }) + "\n");
|
socket.end(JSON.stringify({ type: "reject", reason: "non-lan locked" }) + "\n");
|
||||||
return;
|
return;
|
||||||
@@ -212,9 +215,12 @@ const server = net.createServer(socket => {
|
|||||||
server.listen(port, () => {
|
server.listen(port, () => {
|
||||||
console.log(`[remchild] listening on 0.0.0.0:${port}`);
|
console.log(`[remchild] listening on 0.0.0.0:${port}`);
|
||||||
console.log(
|
console.log(
|
||||||
`[remchild] allowlist: ${configured.length ? configured.join(", ") : "LAN only (no list configured)"}`
|
`[remchild] allowlist: ${
|
||||||
|
allowAll ? "ALL (testing mode)" : configured.length ? configured.join(", ") : "LAN only (no list configured)"
|
||||||
|
}`
|
||||||
);
|
);
|
||||||
if (allowNonLan === true) console.log("[remchild] non-LAN addresses are unlocked");
|
if (allowAll) console.log("[remchild] WARNING: every address is accepted; there is no auth");
|
||||||
|
else if (allowNonLan === true) console.log("[remchild] non-LAN addresses are unlocked");
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on("SIGINT", () => {
|
process.on("SIGINT", () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user