Added MeshAgent Account Image support.

This commit is contained in:
Ylian Saint-Hilaire 2021-05-16 01:25:58 -07:00
parent 9eb9e54a24
commit e97e844c82
2 changed files with 34 additions and 1 deletions

View File

@ -261,6 +261,9 @@ obj.DAIPC.on('connection', function (c) {
case 'meshToolInfo':
try { mesh.SendCommand({ action: 'meshToolInfo', name: data.name, hash: data.hash, cookie: data.cookie ? true : false, pipe: true }); } catch (e) { }
break;
case 'getUserImage':
try { mesh.SendCommand({ action: 'getUserImage', userid: data.userid, pipe: true }); } catch (e) { }
break;
case 'console':
if (debugConsole) {
var args = splitArgs(data.value);
@ -281,7 +284,9 @@ function broadcastSessionsToRegisteredApps(x) {
// Send this object to all registered local applications
function broadcastToRegisteredApps(x) {
if ((obj.DAIPC == null) || (obj.DAIPC._daipc == null)) return;
for (var i in obj.DAIPC._daipc) { if (obj.DAIPC._daipc[i]._registered != null) { obj.DAIPC._daipc[i]._send(x); } }
for (var i in obj.DAIPC._daipc) {
if (obj.DAIPC._daipc[i]._registered != null) { obj.DAIPC._daipc[i]._send(x); }
}
}
// Send this object to a specific registered local applications
@ -1277,6 +1282,10 @@ function handleServerCommand(data) {
downloadFile(data);
}
break;
case 'getUserImage':
if (data.pipe == true) { delete data.pipe; delete data.action; data.cmd = 'getUserImage'; broadcastToRegisteredApps(data); }
if (data.tag == 'info') { sendConsoleText(JSON.stringify(data, null, 2)); }
break;
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.
agentFileHttpPendingRequests.push(data);
serverFetchFile();
@ -2861,6 +2870,10 @@ function processConsoleCommand(cmd, args, rights, sessionid) {
response = "MeshCentral Assistant is not supported on this platform.";
}
break;
case 'userimage':
require('MeshAgent').SendCommand({ action: 'getUserImage', sessionid: sessionid, userid: args['_'][0], tag: 'info' });
response = 'ok';
break;
case 'agentupdate':
require('MeshAgent').SendCommand({ action: 'agentupdate', sessionid: sessionid });
break;

View File

@ -1600,6 +1600,26 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
break;
}
case 'getUserImage': {
// Validate input
if (typeof command.userid != 'string') return;
var useridsplit = command.userid.split('/');
if ((useridsplit.length != 3) || (useridsplit[1] != domain.id)) return;
// Add the user's real name if present
var u = parent.users[command.userid];
if (u == null) return;
if (u.realname) { command.realname = u.realname; }
// An agent can only request images of accounts with rights to the device.
if (parent.GetNodeRights(command.userid, obj.dbMeshKey, obj.dbNodeKey) != 0) {
parent.db.Get('im' + command.userid, function (err, images) {
if ((err == null) && (images != null) && (images.length == 1)) { command.image = images[0].image; }
obj.send(JSON.stringify(command));
});
}
break;
}
default: {
parent.agentStats.unknownAgentActionCount++;
parent.parent.debug('agent', 'Unknown agent action (' + obj.remoteaddrport + '): ' + JSON.stringify(command) + '.');