mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2025-03-09 15:40:18 +00:00
Added batch group move, support for agent custom cores.
This commit is contained in:
parent
137cfcd0ae
commit
eae67b9985
4 changed files with 66 additions and 43 deletions
66
meshuser.js
66
meshuser.js
|
@ -1160,43 +1160,49 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||
}
|
||||
case 'changeDeviceMesh':
|
||||
{
|
||||
if (obj.common.validateString(command.nodeid, 1, 256) == false) break; // Check nodeid string
|
||||
if (obj.common.validateString(command.meshid, 1, 256) == false) break; // Check meshid string
|
||||
if (obj.common.validateStrArray(command.nodeids, 1, 256) == false) break; // Check nodeid strings
|
||||
if (obj.common.validateString(command.meshid, 1, 256) == false) break; // Check target meshid string
|
||||
|
||||
obj.db.Get(command.nodeid, function (err, nodes) {
|
||||
if (nodes.length != 1) return;
|
||||
var node = nodes[0];
|
||||
// For each nodeid, change the group
|
||||
for (var i = 0; i < command.nodeids.length; i++) {
|
||||
obj.db.Get(command.nodeids[i], function (err, nodes) {
|
||||
if (nodes.length != 1) return;
|
||||
var node = nodes[0];
|
||||
|
||||
// Check if already in the right mesh
|
||||
if (node.meshid == command.meshid) return;
|
||||
// Check if already in the right mesh
|
||||
if (node.meshid == command.meshid) return;
|
||||
|
||||
// Make sure that we have rights on both source and destination mesh
|
||||
var sourceMeshRights = user.links[node.meshid].rights;
|
||||
var targetMeshRights = user.links[command.meshid].rights;
|
||||
if (((sourceMeshRights & 4) == 0) || ((targetMeshRights & 4) == 0)) return;
|
||||
// Make sure both source and target mesh are the same type
|
||||
try { if (obj.parent.meshes[node.meshid].mtype != obj.parent.meshes[command.meshid].mtype) return; } catch (e) { return; };
|
||||
|
||||
// Perform the switch, start by saving the node with the new meshid.
|
||||
var oldMeshId = node.meshid;
|
||||
node.meshid = command.meshid;
|
||||
obj.db.Set(node);
|
||||
// Make sure that we have rights on both source and destination mesh
|
||||
var sourceMeshRights = user.links[node.meshid].rights;
|
||||
var targetMeshRights = user.links[command.meshid].rights;
|
||||
if (((sourceMeshRights & 4) == 0) || ((targetMeshRights & 4) == 0)) return;
|
||||
|
||||
// If the device is connected on this server, switch it now.
|
||||
var agentSession = obj.parent.wsagents[command.nodeid];
|
||||
if (agentSession != null) { agentSession.dbMeshKey = command.meshid; agentSession.meshid = command.meshid.split('/')[2]; }
|
||||
// Perform the switch, start by saving the node with the new meshid.
|
||||
var oldMeshId = node.meshid;
|
||||
node.meshid = command.meshid;
|
||||
obj.db.Set(node);
|
||||
|
||||
// Add the connection state
|
||||
var state = obj.parent.parent.GetConnectivityState(node._id);
|
||||
if (state) {
|
||||
node.conn = state.connectivity;
|
||||
node.pwr = state.powerState;
|
||||
if ((state.connectivity & 1) != 0) { var agent = obj.parent.wsagents[node._id]; if (agent != null) { node.agct = agent.connectTime; } }
|
||||
if ((state.connectivity & 2) != 0) { var cira = obj.parent.parent.mpsserver.ciraConnections[node._id]; if (cira != null) { node.cict = cira.tag.connectTime; } }
|
||||
}
|
||||
// If the device is connected on this server, switch it now.
|
||||
var agentSession = obj.parent.wsagents[node._id];
|
||||
if (agentSession != null) { agentSession.dbMeshKey = command.meshid; agentSession.meshid = command.meshid.split('/')[2]; }
|
||||
|
||||
// Event the node change
|
||||
var newMesh = obj.parent.meshes[command.meshid];
|
||||
obj.parent.parent.DispatchEvent(['*', oldMeshId, command.meshid], obj, { etype: 'node', username: user.name, action: 'nodemeshchange', nodeid: node._id, node: node, oldMeshId: oldMeshId, newMeshId: command.meshid, msg: 'Moved device ' + node.name + ' to group ' + newMesh.name, domain: domain.id });
|
||||
});
|
||||
// Add the connection state
|
||||
var state = obj.parent.parent.GetConnectivityState(node._id);
|
||||
if (state) {
|
||||
node.conn = state.connectivity;
|
||||
node.pwr = state.powerState;
|
||||
if ((state.connectivity & 1) != 0) { var agent = obj.parent.wsagents[node._id]; if (agent != null) { node.agct = agent.connectTime; } }
|
||||
if ((state.connectivity & 2) != 0) { var cira = obj.parent.parent.mpsserver.ciraConnections[node._id]; if (cira != null) { node.cict = cira.tag.connectTime; } }
|
||||
}
|
||||
|
||||
// Event the node change
|
||||
var newMesh = obj.parent.meshes[command.meshid];
|
||||
obj.parent.parent.DispatchEvent(['*', oldMeshId, command.meshid], obj, { etype: 'node', username: user.name, action: 'nodemeshchange', nodeid: node._id, node: node, oldMeshId: oldMeshId, newMeshId: command.meshid, msg: 'Moved device ' + node.name + ' to group ' + newMesh.name, domain: domain.id });
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
case 'removedevices':
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue