1
0
Fork 0
mirror of https://github.com/Ylianst/MeshCentral.git synced 2025-03-09 15:40:18 +00:00

Added device notes support

This commit is contained in:
Ylian Saint-Hilaire 2018-04-12 18:14:03 -07:00
parent bcb7100ced
commit 4080abd217
14 changed files with 114 additions and 18 deletions

View file

@ -713,9 +713,11 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
// Check if this user has rights to do this
if (mesh.links[user._id] == null || ((mesh.links[user._id].rights & 4) == 0)) return;
// Delete this node including network interface information and events
obj.db.Remove(node._id);
obj.db.Remove('if' + node._id);
// Delete this node including network interface information, events and timeline
obj.db.Remove(node._id); // Remove node with that id
obj.db.Remove('if' + node._id); // Remove interface information
obj.db.Remove('nt' + node._id); // Remove notes
obj.db.RemoveNode(node._id); // Remove all entries with node:id
// Event node deletion
var change = 'Removed device ' + node.name + ' from mesh ' + mesh.name;
@ -994,6 +996,54 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
}
break;
}
case 'setNotes':
{
// Argument validation
if (obj.common.validateString(command.nodeid, 1, 1024) == false) break; // Check nodeid
if ((command.nodeid.split('/').length != 3) || (command.nodeid.split('/')[1] != domain.id)) return; // Invalid domain, operation only valid for current domain
// Check if this user has rights on this nodeid to set notes
obj.db.Get(command.nodeid, function (err, nodes) { // TODO: Make a NodeRights(user) method that also does not do a db call if agent is connected (???)
if (nodes.length == 1) {
var meshlinks = user.links[nodes[0].meshid];
if ((meshlinks) && (meshlinks.rights) && (meshlinks.rights & obj.parent.MESHRIGHT_SETNOTES != 0)) {
// Set the node's notes
if (obj.common.validateString(command.notes, 1) == false) {
obj.db.Remove('nt' + command.nodeid); // Delete the note for this node
} else {
obj.db.Set({ _id: 'nt' + command.nodeid, value: command.notes }); // Set the note for this node
}
}
}
});
break;
}
case 'getNotes':
{
// Argument validation
if (obj.common.validateString(command.nodeid, 1, 1024) == false) break; // Check nodeid
if ((command.nodeid.split('/').length != 3) || (command.nodeid.split('/')[1] != domain.id)) return; // Invalid domain, operation only valid for current domain
// Get the device
obj.db.Get(command.nodeid, function (err, nodes) {
if (nodes.length != 1) { ws.send(JSON.stringify({ action: 'getnetworkinfo', nodeid: command.nodeid, netif: null })); return; }
var node = nodes[0];
// Get the mesh for this device
var mesh = obj.parent.meshes[node.meshid];
if (mesh) {
// Check if this user has rights to do this
if (mesh.links[user._id] == null || (mesh.links[user._id].rights == 0)) { return; }
// Get the notes about this node
obj.db.Get('nt' + command.nodeid, function (err, notes) {
if (notes.length != 1) { ws.send(JSON.stringify({ action: 'getNotes', nodeid: command.nodeid, notes: null })); return; }
ws.send(JSON.stringify({ action: 'getNotes', nodeid: command.nodeid, notes: notes[0].value }));
});
}
});
break;
}
}
});