Updated MeshCentral Assistant with self-update system.
Ylian Saint-Hilaire committed
Nov 3, 2020 at 18:44 UTC
1b590dba5e04c5e80eb4af842a45a7e7ed399cfa
6 files changed
+42
-2
agents/MeshCentralAssistant.exe
Binary files a/agents/MeshCentralAssistant.exe and b/agents/MeshCentralAssistant.exe differ
agents/meshcore.js
+7
@@ -218,6 +218,9 @@ function createMeshCore(agent) {
218
case 'sessions':
219
this._send({ cmd: 'sessions', sessions: tunnelUserCount });
220
break;
221
+ case 'meshToolInfo':
222
+ try { mesh.SendCommand({ action: 'meshToolInfo', name: data.name, hash: data.hash, cookie: data.cookie?true:false, pipe: true }); } catch (e) { }
223
+ break;
224
}
225
}
226
catch (e) { removeRegisteredApp(this); this.end(); return; }
@@ -1133,6 +1136,10 @@ function createMeshCore(agent) {
1136
r.corehashhex = getSHA384FileHash(coreDumpPath).toString('hex'); // Hash of core dump file
1137
}
1138
mesh.SendCommand(JSON.stringify(r));
1139
+ break;
1140
+ case 'meshToolInfo':
1141
+ if (data.pipe == true) { delete data.pipe; delete data.action; data.cmd = 'meshToolInfo'; broadcastToRegisteredApps(data); }
1142
+ break;
1143
default:
1144
// Unknown action, ignore it.
1145
break;
meshagent.js
+10
@@ -1397,6 +1397,16 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1397
}
1398
break;
1399
}
1400
+ case 'meshToolInfo': {
1401
+ if (typeof command.name != 'string') break;
1402
+ var info = parent.parent.meshToolsBinaries[command.name];
1403
+ if ((command.hash != null) && (info.hash == command.hash)) return;
1404
+ const responseCmd = { action: 'meshToolInfo', name: command.name, hash: info.hash, size: info.size, url: info.url };
1405
+ if (command.cookie === true) { responseCmd.url += ('&auth=' + parent.parent.encodeCookie({ download: info.dlname }, parent.parent.loginCookieEncryptionKey)); }
1406
+ if (command.pipe === true) { responseCmd.pipe = true; }
1407
+ try { ws.send(JSON.stringify(responseCmd)); } catch (ex) { }
1408
+ break;
1409
+ }
1410
default: {
1411
parent.agentStats.unknownAgentActionCount++;
1412
parent.parent.debug('agent', 'Unknown agent action (' + obj.remoteaddrport + '): ' + JSON.stringify(command) + '.');
meshcentral.js
+1
@@ -2106,6 +2106,7 @@ function CreateMeshCentralServer(config, args) {
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].dlname = this.dlname;
2110
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;
2111
var stats = null;
2112
try { stats = obj.fs.statSync(this.agentpath); } catch (e) { }
views/default.handlebars
+1
-1
@@ -13608,7 +13608,7 @@
13608
if (r.rights == 0xFFFFFFFF) { return 0xFFFFFFFF; } // User has full rights thru a device group link, stop here.
13609
rights = r.rights;
13610
}
13611
-
13611
+
13612
// Check permissions thru user groups
13613
var user = null;
13614
if (userid == userinfo._id) { user = userinfo; } else { if (users != null) { user = users[userid]; } }
webserver.js
+23
-1
@@ -4178,8 +4178,30 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
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) {
4181
+ // Check if we have an authentication cookie
4182
var c = obj.parent.decodeCookie(req.query.auth, obj.parent.loginCookieEncryptionKey);
4182
- if ((c == null) || (c.userid == null)) { res.sendStatus(404); return; }
4183
+ if (c == null) { res.sendStatus(404); return; }
4184
+
4185
+ // Download tools using a cookie
4186
+ if (c.download == req.query.meshaction) {
4187
+ if (req.query.meshaction == 'winrouter') {
4188
+ var p = obj.path.join(__dirname, 'agents', 'MeshCentralRouter.exe');
4189
+ if (obj.fs.existsSync(p)) {
4190
+ setContentDispositionHeader(res, 'application/octet-stream', 'MeshCentralRouter.exe', null, 'MeshCentralRouter.exe');
4191
+ try { res.sendFile(p); } catch (e) { res.sendStatus(404); }
4192
+ } else { res.sendStatus(404); }
4193
+ } else if (req.query.meshaction == 'winassistant') {
4194
+ var p = obj.path.join(__dirname, 'agents', 'MeshCentralAssistant.exe');
4195
+ if (obj.fs.existsSync(p)) {
4196
+ setContentDispositionHeader(res, 'application/octet-stream', 'MeshCentralAssistant.exe', null, 'MeshCentralAssistant.exe');
4197
+ try { res.sendFile(p); } catch (e) { res.sendStatus(404); }
4198
+ } else { res.sendStatus(404); }
4199
+ }
4200
+ return;
4201
+ }
4202
+
4203
+ // Check if the cookie authenticates a user
4204
+ if (c.userid == null) { res.sendStatus(404); return; }
4205
user = obj.users[c.userid];
4206
if (user == null) { res.sendStatus(404); return; }
4207
}