mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-27 02:04:30 +03:00
Completed the Show Self Events Only feature.
This commit is contained in:
parent
c3d64a7c84
commit
0b7452abd8
65
agents/meshcore.min.js
vendored
65
agents/meshcore.min.js
vendored
@ -306,6 +306,7 @@ function createMeshCore(agent)
|
||||
var amtscanner = null;
|
||||
var nextTunnelIndex = 1;
|
||||
var amtPolicy = null;
|
||||
var apftunnel = null;
|
||||
|
||||
// Add to the server event log
|
||||
function MeshServerLog(msg, state) {
|
||||
@ -1667,7 +1668,7 @@ function createMeshCore(agent)
|
||||
var response = null;
|
||||
switch (cmd) {
|
||||
case 'help': { // Displays available commands
|
||||
response = 'Available commands: help, info, osinfo, args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtacm,\r\namtdeactivate, amtpolicy, getscript, getclip, setclip, log, av, cpuinfo, sysinfo.';
|
||||
response = 'Available commands: help, info, osinfo, args, print, type, dbget, dbset, dbcompact, eval, parseuri, httpget,\r\nwslist, wsconnect, wssend, wsclose, notify, ls, ps, kill, amt, netinfo, location, power, wakeonlan, scanwifi,\r\nscanamt, setdebug, smbios, rawsmbios, toast, lock, users, sendcaps, openurl, amtreset, amtccm, amtacm,\r\namtdeactivate, amtpolicy, getscript, getclip, setclip, log, av, cpuinfo, sysinfo, apf.';
|
||||
break;
|
||||
}
|
||||
/*
|
||||
@ -1853,6 +1854,25 @@ function createMeshCore(agent)
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'uninstallagent':
|
||||
var agentName = process.platform == 'win32' ? 'Mesh Agent' : 'meshagent';
|
||||
if (!require('service-manager').manager.getService(agentName).isMe())
|
||||
{
|
||||
response = 'Uininstall failed, this instance is not the service instance';
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
diagnosticAgent_uninstall();
|
||||
}
|
||||
catch(x)
|
||||
{
|
||||
}
|
||||
var js = "require('service-manager').manager.getService('" + agentName + "').stop(); require('service-manager').manager.uninstallService('" + agentName + "'); process.exit();";
|
||||
this.child = require('child_process').execFile(process.execPath, [process.platform == 'win32' ? (process.execPath.split('\\').pop()) : (process.execPath.split('/').pop()), '-b64exec', Buffer.from(js).toString('base64')], { type: 4, detached: true });
|
||||
}
|
||||
break;
|
||||
case 'notify': { // Send a notification message to the mesh
|
||||
if (args['_'].length != 1) {
|
||||
response = 'Proper usage: notify "message" [--session]'; // Display correct command usage
|
||||
@ -2271,6 +2291,49 @@ function createMeshCore(agent)
|
||||
if (diag) { diag.close(); diag = null; }
|
||||
break;
|
||||
}
|
||||
case 'apf': {
|
||||
if (meshCoreObj.intelamt!==null) {
|
||||
if (args['_'].length == 1) {
|
||||
if (args['_'][0] == 'on') {
|
||||
response = 'Starting APF tunnel'
|
||||
var apfarg = {
|
||||
mpsurl: mesh.ServerUrl.replace('agent.ashx','apf.ashx'),
|
||||
mpsuser: Buffer.from(mesh.ServerInfo.MeshID,'hex').toString('base64').substring(0,16),
|
||||
mpspass: Buffer.from(mesh.ServerInfo.MeshID,'hex').toString('base64').substring(0,16),
|
||||
mpskeepalive: 60000,
|
||||
clientname: require('os').hostname(),
|
||||
clientaddress: '127.0.0.1',
|
||||
clientuuid: meshCoreObj.intelamt.uuid
|
||||
};
|
||||
var tobj = { debug: false }; //
|
||||
apftunnel= require('apfclient')(tobj,apfarg);
|
||||
try {
|
||||
apftunnel.connect();
|
||||
response += "..success";
|
||||
} catch (e) {
|
||||
response += JSON.stringify(e);
|
||||
}
|
||||
} else if (args['_'][0] == 'off') {
|
||||
response = 'Stopping APF tunnel';
|
||||
try {
|
||||
apftunnel.disconnect();
|
||||
response += "..success";
|
||||
} catch (e) {
|
||||
response += JSON.stringify(e);
|
||||
}
|
||||
apftunnel=null;
|
||||
} else {
|
||||
response = 'Invalid command.\r\nCmd syntax: apf on|off';
|
||||
}
|
||||
} else {
|
||||
response = 'APF tunnel is '+ (apftunnel == null ? 'off': 'on' );
|
||||
}
|
||||
|
||||
} else {
|
||||
response = 'APF tunnel requires Intel AMT';
|
||||
}
|
||||
break;
|
||||
}
|
||||
default: { // This is an unknown command, return an error message
|
||||
response = 'Unknown command \"' + cmd + '\", type \"help\" for list of avaialble commands.';
|
||||
break;
|
||||
|
1
agents/modules_meshcore_min/apfclient.min.js
vendored
Normal file
1
agents/modules_meshcore_min/apfclient.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1024,7 +1024,7 @@ function CreateMeshCentralServer(config, args) {
|
||||
for (var i in obj.eventsDispatch[id]) {
|
||||
if (targets.indexOf(obj.eventsDispatch[id][i]) == -1) { // Check if we already displatched to this target
|
||||
targets.push(obj.eventsDispatch[id][i]);
|
||||
try { obj.eventsDispatch[id][i].HandleEvent(source, event); } catch (ex) {
|
||||
try { obj.eventsDispatch[id][i].HandleEvent(source, event, ids, id); } catch (ex) {
|
||||
console.log(ex, obj.eventsDispatch[id][i]);
|
||||
}
|
||||
}
|
||||
|
22
meshuser.js
22
meshuser.js
@ -230,13 +230,31 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
if (parent.parent.multiServer != null) { parent.parent.multiServer.DispatchMessage({ action: 'sessionStart', sessionid: ws.sessionId }); }
|
||||
|
||||
// Handle events
|
||||
ws.HandleEvent = function (source, event) {
|
||||
ws.HandleEvent = function (source, event, ids, id) {
|
||||
if (!event.domain || event.domain == domain.id) {
|
||||
try {
|
||||
if (event == 'close') { try { delete req.session; } catch (ex) { } obj.close(); }
|
||||
else if (event == 'resubscribe') { user.subscriptions = parent.subscribe(user._id, ws); }
|
||||
else if (event == 'updatefiles') { updateUserFiles(user, ws, domain); }
|
||||
else { ws.send(JSON.stringify({ action: 'event', event: event })); }
|
||||
else {
|
||||
// Because of the device group "Show Self Events Only", we need to do more checks here.
|
||||
if (id.startsWith('mesh/')) {
|
||||
// Check if we have rights to get this message. If we have limited events on this mesh, don't send the event to the user.
|
||||
var meshlink = obj.user.links[id];
|
||||
if ((meshlink != null) && ((meshlink.rights == 0xFFFFFFFF) || ((meshlink.rights & 8192) == 0) || (ids.indexOf(user._id) >= 0))) {
|
||||
// We have the device group rights to see this event or we are directly targetted by the event
|
||||
ws.send(JSON.stringify({ action: 'event', event: event }));
|
||||
} else {
|
||||
// Check if no other users are targeted by the event, if not, we can get this event.
|
||||
var userTarget = false;
|
||||
for (var i in ids) { if (ids[i].startsWith('user/')) { userTarget = true; } }
|
||||
if (userTarget == false) { ws.send(JSON.stringify({ action: 'event', event: event })); }
|
||||
}
|
||||
} else {
|
||||
// This is not a device group event, we can get this event.
|
||||
ws.send(JSON.stringify({ action: 'event', event: event }));
|
||||
}
|
||||
}
|
||||
} catch (e) { }
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user