Added AgentKey support, #3468

Ylian Saint-Hilaire committed Jan 16, 2022 at 13:59 UTC b352cc84095c31970553bcc34980d72542ac91a2
4 files changed +5
meshcentral-config-schema.json
+1
@@ -303,6 +303,7 @@
303 "userQuota": { "type": "integer" },
304 "meshQuota": { "type": "integer" },
305 "loginKey": { "type": [ "string", "array" ], "items": { "type": "string" }, "default": null, "description": "Requires that users add the value ?key=xxx in the URL in order to see the web site." },
306 + "agentKey": { "type": [ "string", "array" ], "items": { "type": "string" }, "default": null, "description": "Requires that agents add the value ?key=xxx in the URL in order to connect. This is not automatic and needs to be manually added in the meshagent.msh file." },
307 "ipkvm": { "type": "boolean", "default": false, "description": "Set to true to enable IP KVM device support in this domain." },
308 "minify": { "type": "boolean", "default": false, "description": "When enabled, the server will send reduced sided web pages." },
309 "newAccounts": { "type": "boolean", "default": false, "description": "When set to true, allow new user accounts to be created from the login page." },
meshcentral.js
+2
@@ -1242,6 +1242,8 @@ function CreateMeshCentralServer(config, args) {
1242 obj.config.domains[i].id = i;
1243 if (typeof obj.config.domains[i].loginkey == 'string') { obj.config.domains[i].loginkey = [obj.config.domains[i].loginkey]; }
1244 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; }
1245 + if (typeof obj.config.domains[i].agentkey == 'string') { obj.config.domains[i].agentkey = [obj.config.domains[i].agentkey]; }
1246 + 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; }
1247 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(','); } }
1248 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(','); } }
1249 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(','); } }
sample-config-advanced.json
+1
@@ -149,6 +149,7 @@
149 "_AutoRemoveInactiveDevices": 37,
150 "_DeviceSearchBarServerAndClientName": false,
151 "_loginKey": [ "abc", "123" ],
152 + "_agentKey": [ "abc", "123" ],
153 "_newAccounts": true,
154 "_newAccountsUserGroups": [ "ugrp//xxxxxxxxxxxxxxxxx" ],
155 "_userNameIsEmail": true,
webserver.js
+1
@@ -6282,6 +6282,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates, doneF
6282 obj.app.ws(url + 'agent.ashx', function (ws, req) {
6283 var domain = checkAgentIpAddress(ws, req);
6284 if (domain == null) { parent.debug('web', 'Got agent connection with bad domain or blocked IP address ' + req.clientIp + ', holding.'); return; }
6285 + if (domain.agentkey && ((req.query.key == null) || (domain.agentkey.indexOf(req.query.key) == -1))) { return; } // If agent key is required and not provided or not valid, just hold the websocket and do nothing.
6286 //console.log('Agent connect: ' + req.clientIp);
6287 try { obj.meshAgentHandler.CreateMeshAgent(obj, obj.db, ws, req, obj.args, domain); } catch (e) { console.log(e); }
6288 });