MeshCentral Router update system.
Ylian Saint-Hilaire committed
Nov 2, 2020 at 21:41 UTC
b2aceb029800d0aeb96e6c2038ed1e1fef7c3d6a
5 files changed
+60
-1
agents/MeshCentralAssistant.exe
Binary files /dev/null and b/agents/MeshCentralAssistant.exe differ
agents/MeshCentralRouter.exe
Binary files a/agents/MeshCentralRouter.exe and b/agents/MeshCentralRouter.exe differ
meshcentral.js
+42
@@ -57,6 +57,7 @@ function CreateMeshCentralServer(config, args) {
57
obj.defaultMeshCores = {};
58
obj.defaultMeshCoresDeflate = {};
59
obj.defaultMeshCoresHash = {};
60
+ obj.meshToolsBinaries = {}; // Mesh Tools Binaries, ToolName --> { hash:(sha384 hash), size:(binary size), path:(binary path) }
61
obj.meshAgentBinaries = {}; // Mesh Agent Binaries, Architecture type --> { hash:(sha384 hash), size:(binary size), path:(binary path) }
62
obj.meshAgentInstallScripts = {}; // Mesh Install Scripts, Script ID -- { hash:(sha384 hash), size:(binary size), path:(binary path) }
63
obj.multiServer = null;
@@ -1296,6 +1297,9 @@ function CreateMeshCentralServer(config, args) {
1297
}
1298
}
1299
1300
+ // Load the list of MeshCentral tools
1301
+ obj.updateMeshTools();
1302
+
1303
// Load the list of mesh agents and install scripts
1304
if (obj.args.noagentupdate == 1) { for (i in obj.meshAgentsArchitectureNumbers) { obj.meshAgentsArchitectureNumbers[i].update = false; } }
1305
obj.updateMeshAgentsTable(function () {
@@ -2078,6 +2082,44 @@ function CreateMeshCentralServer(config, args) {
2082
}
2083
};
2084
2085
+ // List of possible mesh agent install scripts
2086
+ var meshToolsList = {
2087
+ 'MeshCentralRouter': { localname: 'MeshCentralRouter.exe', dlname: 'winrouter' },
2088
+ 'MeshCentralAssistant': { localname: 'MeshCentralAssistant.exe', dlname: 'winassistant' }
2089
+ };
2090
+
2091
+ // Update the list of available mesh agents
2092
+ obj.updateMeshTools = function () {
2093
+ for (var toolname in meshToolsList) {
2094
+ var toolpath = obj.path.join(__dirname, 'agents', meshToolsList[toolname].localname);
2095
+ var stream = null;
2096
+ try {
2097
+ stream = obj.fs.createReadStream(toolpath);
2098
+ stream.on('data', function (data) { this.hash.update(data, 'binary'); this.hashx += data.length; });
2099
+ stream.on('error', function (data) {
2100
+ // If there is an error reading this file, make sure this agent is not in the agent table
2101
+ if (obj.meshToolsBinaries[this.toolname] != null) { delete obj.meshToolsBinaries[this.toolname]; }
2102
+ });
2103
+ stream.on('end', function () {
2104
+ // Add the agent to the agent table with all information and the hash
2105
+ obj.meshToolsBinaries[this.toolname] = {};
2106
+ obj.meshToolsBinaries[this.toolname].hash = this.hash.digest('hex');
2107
+ obj.meshToolsBinaries[this.toolname].hashx = this.hashx;
2108
+ obj.meshToolsBinaries[this.toolname].path = this.agentpath;
2109
+ obj.meshToolsBinaries[this.toolname].url = ((obj.args.notls == true) ? 'http://' : 'https://') + obj.certificates.CommonName + ':' + ((typeof obj.args.aliasport == 'number') ? obj.args.aliasport : obj.args.port) + '/meshagents?meshaction=' + this.dlname;
2110
+ var stats = null;
2111
+ try { stats = obj.fs.statSync(this.agentpath); } catch (e) { }
2112
+ if (stats != null) { obj.meshToolsBinaries[this.toolname].size = stats.size; }
2113
+ });
2114
+ stream.toolname = toolname;
2115
+ stream.agentpath = toolpath;
2116
+ stream.dlname = meshToolsList[toolname].dlname;
2117
+ stream.hash = obj.crypto.createHash('sha384', stream);
2118
+ stream.hashx = 0;
2119
+ } catch (e) { }
2120
+ }
2121
+ };
2122
+
2123
// List of possible mesh agent install scripts
2124
var meshAgentsInstallScriptList = {
2125
1: { id: 1, localname: 'meshinstall-linux.sh', rname: 'meshinstall.sh', linux: true },
meshuser.js
+6
@@ -4999,6 +4999,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
4999
try { ws.send(JSON.stringify({ action: 'amtsetupbin', file: Buffer.from(bin, 'binary').toString('base64') })); } catch (ex) { }
5000
break;
5001
}
5002
+ case 'meshToolInfo': {
5003
+ if (typeof command.name != 'string') break;
5004
+ var info = parent.parent.meshToolsBinaries[command.name];
5005
+ try { ws.send(JSON.stringify({ action: 'meshToolInfo', name: command.name, hash: info.hash, size: info.size, url: info.url })); } catch (ex) { }
5006
+ break;
5007
+ }
5008
default: {
5009
// Unknown user action
5010
console.log('Unknown action from user ' + user.name + ': ' + command.action + '.');
webserver.js
+12
-1
@@ -4177,7 +4177,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4177
} else if (req.query.meshaction != null) {
4178
if ((domain.loginkey != null) && (domain.loginkey.indexOf(req.query.key) == -1)) { res.sendStatus(404); return; } // Check 3FA URL key
4179
var user = obj.users[req.session.userid];
4180
- if (user == null) { res.sendStatus(404); return; }
4180
+ if (user == null) {
4181
+ var c = obj.parent.decodeCookie(req.query.auth, obj.parent.loginCookieEncryptionKey);
4182
+ if ((c == null) || (c.userid == null)) { res.sendStatus(404); return; }
4183
+ user = obj.users[c.userid];
4184
+ if (user == null) { res.sendStatus(404); return; }
4185
+ }
4186
if ((req.query.meshaction == 'route') && (req.query.nodeid != null)) {
4187
obj.db.Get(req.query.nodeid, function (err, nodes) {
4188
if (nodes.length != 1) { res.sendStatus(401); return; }
@@ -4225,6 +4230,12 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4230
setContentDispositionHeader(res, 'application/octet-stream', 'MeshCentralRouter.exe', null, 'MeshCentralRouter.exe');
4231
try { res.sendFile(p); } catch (e) { res.sendStatus(404); }
4232
} else { res.sendStatus(404); }
4233
+ } else if (req.query.meshaction == 'winassistant') {
4234
+ var p = obj.path.join(__dirname, 'agents', 'MeshCentralAssistant.exe');
4235
+ if (obj.fs.existsSync(p)) {
4236
+ setContentDispositionHeader(res, 'application/octet-stream', 'MeshCentralAssistant.exe', null, 'MeshCentralAssistant.exe');
4237
+ try { res.sendFile(p); } catch (e) { res.sendStatus(404); }
4238
+ } else { res.sendStatus(404); }
4239
} else {
4240
res.sendStatus(401);
4241
}