mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
Added device location
This commit is contained in:
parent
888e8dedef
commit
41125c66ee
6 changed files with 1429 additions and 2 deletions
42
meshagent.js
42
meshagent.js
|
@ -393,7 +393,12 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
|||
case 'location':
|
||||
{
|
||||
// Sent by the agent to update location information
|
||||
console.log(JSON.stringify(command));
|
||||
if ((command.type == 'publicip') && (typeof command.value == 'object') && (command.value.ip) && (command.value.loc)) {
|
||||
var x = {};
|
||||
x.publicip = command.value.ip;
|
||||
x.iploc = command.value.loc;
|
||||
ChangeAgentLocationInfo(x);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -451,6 +456,41 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
|
|||
});
|
||||
}
|
||||
|
||||
// Change the current core information string and event it
|
||||
function ChangeAgentLocationInfo(command) {
|
||||
if ((command == undefined) || (command == null)) return; // Safety, should never happen.
|
||||
|
||||
// Check that the mesh exists
|
||||
obj.db.Get(obj.dbMeshKey, function (err, meshes) {
|
||||
if (meshes.length != 1) return;
|
||||
var mesh = meshes[0];
|
||||
// Get the node and change it if needed
|
||||
obj.db.Get(obj.dbNodeKey, function (err, nodes) {
|
||||
if (nodes.length != 1) return;
|
||||
var device = nodes[0];
|
||||
if (device.agent) {
|
||||
var changes = [], change = 0;
|
||||
|
||||
// Check if anything changes
|
||||
if ((command.publicip) && (device.publicip != command.publicip)) { device.publicip = command.publicip; change = 1; changes.push('public ip'); }
|
||||
if ((command.iploc) && (device.iploc != command.iploc)) { device.iploc = command.iploc; change = 1; changes.push('ip location'); }
|
||||
|
||||
// If there are changes, save and event
|
||||
if (change == 1) {
|
||||
obj.db.Set(device);
|
||||
|
||||
// Event the node change
|
||||
var event = { etype: 'node', action: 'changenode', nodeid: obj.dbNodeKey, domain: domain.id, msg: 'Changed device ' + device.name + ' from mesh ' + mesh.name + ': ' + changes.join(', ') };
|
||||
var device2 = obj.common.Clone(device);
|
||||
if (device2.intelamt && device2.intelamt.pass) delete device2.intelamt.pass; // Remove the Intel AMT password before eventing this.
|
||||
event.node = device;
|
||||
obj.parent.parent.DispatchEvent(['*', device.meshid], obj, event);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Update the mesh agent tab in the database
|
||||
function ChangeAgentTag(tag) {
|
||||
if (tag.length == 0) { tag = undefined; }
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue