fix ip fliters from files #3401

Signed-off-by: si458 <simonsmith5521@gmail.com>

si458 committed Jun 20, 2024 at 22:34 UTC df91c90d33525214291aea2217d8220e5977bb1b
2 files changed +13 -9
meshcentral-config-schema.json
+8 -8
@@ -608,7 +608,7 @@
608 "array"
609 ],
610 "default": null,
611 - "description": "When set, only users from allowed IP address ranges can connect to the server. Example: \"192.168.2.100,192.168.1.0/24\""
611 + "description": "When set, only users from allowed IP address ranges can connect to the server. Example: \"192.168.2.100,192.168.1.0/24\" \"file:userAllowedIP.txt\""
612 },
613 "userBlockedIP": {
614 "type": [
@@ -616,7 +616,7 @@
616 "array"
617 ],
618 "default": null,
619 - "description": "When set, users from these denied IP address ranges will not be able to connect to the server. Example: \"192.168.2.100,192.168.1.0/24\""
619 + "description": "When set, users from these denied IP address ranges will not be able to connect to the server. Example: \"192.168.2.100,192.168.1.0/24\" \"file:userBlockedIP.txt\""
620 },
621 "agentAllowedIP": {
622 "type": [
@@ -624,7 +624,7 @@
624 "array"
625 ],
626 "default": null,
627 - "description": "When set, only agents from allowed IP address ranges can connect to the server. Example: \"192.168.2.100,192.168.1.0/24\""
627 + "description": "When set, only agents from allowed IP address ranges can connect to the server. Example: \"192.168.2.100,192.168.1.0/24\" \"file:agentAllowedIP.txt\""
628 },
629 "agentBlockedIP": {
630 "type": [
@@ -632,7 +632,7 @@
632 "array"
633 ],
634 "default": null,
635 - "description": "When set, agents from these denied IP address ranges will not be able to connect to the server. Example: \"192.168.2.100,192.168.1.0/24\""
635 + "description": "When set, agents from these denied IP address ranges will not be able to connect to the server. Example: \"192.168.2.100,192.168.1.0/24\" \"file:agentBlockedIP.txt\""
636 },
637 "authLog": {
638 "type": "string",
@@ -1967,7 +1967,7 @@
1967 "array"
1968 ],
1969 "default": null,
1970 - "description": "When set, only users from allowed IP address ranges can connect to the server. Example: \"192.168.2.100,192.168.1.0/24\""
1970 + "description": "When set, only users from allowed IP address ranges can connect to the server. Example: \"192.168.2.100,192.168.1.0/24\" \"file:userAllowedIP.txt\""
1971 },
1972 "userBlockedIP": {
1973 "type": [
@@ -1975,7 +1975,7 @@
1975 "array"
1976 ],
1977 "default": null,
1978 - "description": "When set, users from these denied IP address ranges will not be able to connect to the server. Example: \"192.168.2.100,192.168.1.0/24\""
1978 + "description": "When set, users from these denied IP address ranges will not be able to connect to the server. Example: \"192.168.2.100,192.168.1.0/24\" \"file:userBlockedIP.txt\""
1979 },
1980 "agentAllowedIP": {
1981 "type": [
@@ -1983,7 +1983,7 @@
1983 "array"
1984 ],
1985 "default": null,
1986 - "description": "When set, only agents from allowed IP address ranges can connect to the server. Example: \"192.168.2.100,192.168.1.0/24\""
1986 + "description": "When set, only agents from allowed IP address ranges can connect to the server. Example: \"192.168.2.100,192.168.1.0/24\" \"file:agentAllowedIP.txt\""
1987 },
1988 "agentBlockedIP": {
1989 "type": [
@@ -1991,7 +1991,7 @@
1991 "array"
1992 ],
1993 "default": null,
1994 - "description": "When set, agents from these denied IP address ranges will not be able to connect to the server. Example: \"192.168.2.100,192.168.1.0/24\""
1994 + "description": "When set, agents from these denied IP address ranges will not be able to connect to the server. Example: \"192.168.2.100,192.168.1.0/24\" \"file:agentBlockedIP.txt\""
1995 },
1996 "userSessionIdleTimeout": {
1997 "type": "integer",
meshcentral.js
+5 -1
@@ -1339,6 +1339,10 @@ function CreateMeshCentralServer(config, args) {
1339 if ((obj.config.domains[i].loginkey != null) && (obj.common.validateAlphaNumericArray(obj.config.domains[i].loginkey, 1, 128) == false)) { console.log("ERROR: Invalid login key, must be alpha-numeric string with no spaces."); process.exit(); return; }
1340 if (typeof obj.config.domains[i].agentkey == 'string') { obj.config.domains[i].agentkey = [obj.config.domains[i].agentkey]; }
1341 if ((obj.config.domains[i].agentkey != null) && (obj.common.validateAlphaNumericArray(obj.config.domains[i].agentkey, 1, 128) == false)) { console.log("ERROR: Invalid agent key, must be alpha-numeric string with no spaces."); process.exit(); return; }
1342 + obj.config.domains[i].userallowedip = obj.config.domains[i].userallowedip = readIpListFromFile(obj.config.domains[i].userallowedip);
1343 + obj.config.domains[i].userblockedip = obj.config.domains[i].userblockedip = readIpListFromFile(obj.config.domains[i].userblockedip);
1344 + obj.config.domains[i].agentallowedip = obj.config.domains[i].agentallowedip = readIpListFromFile(obj.config.domains[i].agentallowedip);
1345 + obj.config.domains[i].agentblockedip = obj.config.domains[i].agentblockedip = readIpListFromFile(obj.config.domains[i].agentblockedip);
1346 if (typeof obj.config.domains[i].userallowedip == 'string') { if (obj.config.domains[i].userallowedip == '') { delete obj.config.domains[i].userallowedip; } else { obj.config.domains[i].userallowedip = obj.config.domains[i].userallowedip.split(' ').join('').split(','); } }
1347 if (typeof obj.config.domains[i].userblockedip == 'string') { if (obj.config.domains[i].userblockedip == '') { delete obj.config.domains[i].userblockedip; } else { obj.config.domains[i].userblockedip = obj.config.domains[i].userblockedip.split(' ').join('').split(','); } }
1348 if (typeof obj.config.domains[i].agentallowedip == 'string') { if (obj.config.domains[i].agentallowedip == '') { delete obj.config.domains[i].agentallowedip; } else { obj.config.domains[i].agentallowedip = obj.config.domains[i].agentallowedip.split(' ').join('').split(','); } }
@@ -3762,7 +3766,7 @@ function CreateMeshCentralServer(config, args) {
3766 function readIpListFromFile(arg) {
3767 if ((typeof arg != 'string') || (!arg.startsWith('file:'))) return arg;
3768 var lines = null;
3765 - try { lines = obj.fs.readFileSync(obj.path.join(obj.datapath, arg.substring(5))).toString().split('\r\n').join('\r').split('\r'); } catch (ex) { }
3769 + try { lines = obj.fs.readFileSync(obj.path.join(obj.datapath, arg.substring(5))).toString().split(/\r?\n/).join('\r').split('\r'); } catch (ex) { }
3770 if (lines == null) return null;
3771 const validLines = [];
3772 for (var i in lines) { if ((lines[i].length > 0) && (((lines[i].charAt(0) > '0') && (lines[i].charAt(0) < '9')) || (lines[i].charAt(0) == ':'))) validLines.push(lines[i]); }