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
|
||||
* 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";
|
||||
@@ -28,6 +29,7 @@ function arg(name, fallback = undefined) {
|
||||
|
||||
const port = Number(arg("port", process.env.REMCHILD_PORT ?? 8799));
|
||||
const allowNonLan = arg("allow-non-lan", false) !== false;
|
||||
const allowAll = arg("allow-all", false) !== false;
|
||||
const historyFile = arg("history", join(HERE, "clients.jsonl"));
|
||||
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. */
|
||||
function allowed(address) {
|
||||
if (allowAll) return true;
|
||||
if (configured.length === 0) return isLan(address);
|
||||
return configured.includes(address);
|
||||
}
|
||||
@@ -111,7 +114,7 @@ const server = net.createServer(socket => {
|
||||
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)`);
|
||||
socket.end(JSON.stringify({ type: "reject", reason: "non-lan locked" }) + "\n");
|
||||
return;
|
||||
@@ -212,9 +215,12 @@ const server = net.createServer(socket => {
|
||||
server.listen(port, () => {
|
||||
console.log(`[remchild] listening on 0.0.0.0:${port}`);
|
||||
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", () => {
|
||||
|
||||
Reference in New Issue
Block a user