Added MeshAgent Account Image support.
Ylian Saint-Hilaire committed
May 16, 2021 at 01:25 UTC
e97e844c82c2aa520ce7102affb30cbef978bec5
2 files changed
+34
-1
agents/meshcore.js
+14
-1
@@ -261,6 +261,9 @@ obj.DAIPC.on('connection', function (c) {
261
case 'meshToolInfo':
262
try { mesh.SendCommand({ action: 'meshToolInfo', name: data.name, hash: data.hash, cookie: data.cookie ? true : false, pipe: true }); } catch (e) { }
263
break;
264
+ case 'getUserImage':
265
+ try { mesh.SendCommand({ action: 'getUserImage', userid: data.userid, pipe: true }); } catch (e) { }
266
+ break;
267
case 'console':
268
if (debugConsole) {
269
var args = splitArgs(data.value);
@@ -281,7 +284,9 @@ function broadcastSessionsToRegisteredApps(x) {
284
// Send this object to all registered local applications
285
function broadcastToRegisteredApps(x) {
286
if ((obj.DAIPC == null) || (obj.DAIPC._daipc == null)) return;
284
- for (var i in obj.DAIPC._daipc) { if (obj.DAIPC._daipc[i]._registered != null) { obj.DAIPC._daipc[i]._send(x); } }
287
+ for (var i in obj.DAIPC._daipc) {
288
+ if (obj.DAIPC._daipc[i]._registered != null) { obj.DAIPC._daipc[i]._send(x); }
289
+ }
290
}
291
292
// Send this object to a specific registered local applications
@@ -1277,6 +1282,10 @@ function handleServerCommand(data) {
1282
downloadFile(data);
1283
}
1284
break;
1285
+ case 'getUserImage':
1286
+ if (data.pipe == true) { delete data.pipe; delete data.action; data.cmd = 'getUserImage'; broadcastToRegisteredApps(data); }
1287
+ if (data.tag == 'info') { sendConsoleText(JSON.stringify(data, null, 2)); }
1288
+ break;
1289
case 'wget': // Server uses this command to tell the agent to download a file using HTTPS/GET and place it in a given path. This is used for one-to-many file uploads.
1290
agentFileHttpPendingRequests.push(data);
1291
serverFetchFile();
@@ -2861,6 +2870,10 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
2870
response = "MeshCentral Assistant is not supported on this platform.";
2871
}
2872
break;
2873
+ case 'userimage':
2874
+ require('MeshAgent').SendCommand({ action: 'getUserImage', sessionid: sessionid, userid: args['_'][0], tag: 'info' });
2875
+ response = 'ok';
2876
+ break;
2877
case 'agentupdate':
2878
require('MeshAgent').SendCommand({ action: 'agentupdate', sessionid: sessionid });
2879
break;
meshagent.js
+20
@@ -1600,6 +1600,26 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1600
1601
break;
1602
}
1603
+ case 'getUserImage': {
1604
+ // Validate input
1605
+ if (typeof command.userid != 'string') return;
1606
+ var useridsplit = command.userid.split('/');
1607
+ if ((useridsplit.length != 3) || (useridsplit[1] != domain.id)) return;
1608
+
1609
+ // Add the user's real name if present
1610
+ var u = parent.users[command.userid];
1611
+ if (u == null) return;
1612
+ if (u.realname) { command.realname = u.realname; }
1613
+
1614
+ // An agent can only request images of accounts with rights to the device.
1615
+ if (parent.GetNodeRights(command.userid, obj.dbMeshKey, obj.dbNodeKey) != 0) {
1616
+ parent.db.Get('im' + command.userid, function (err, images) {
1617
+ if ((err == null) && (images != null) && (images.length == 1)) { command.image = images[0].image; }
1618
+ obj.send(JSON.stringify(command));
1619
+ });
1620
+ }
1621
+ break;
1622
+ }
1623
default: {
1624
parent.agentStats.unknownAgentActionCount++;
1625
parent.parent.debug('agent', 'Unknown agent action (' + obj.remoteaddrport + '): ' + JSON.stringify(command) + '.');