Improved relay device groups.
This commit is contained in:
parent
1a64a11d29
commit
707cae6aab
39
meshuser.js
39
meshuser.js
|
@ -2073,6 +2073,17 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||
|
||||
parent.parent.RemoveEventDispatchId(command.meshid); // Remove all subscriptions to this mesh
|
||||
|
||||
// Notify the devices that they have changed relay roles
|
||||
if (mesh.relayid != null) {
|
||||
// Get the node and the rights for this node
|
||||
parent.GetNodeWithRights(domain, user, mesh.relayid, function (node, rights, visible) {
|
||||
if (node == null) return;
|
||||
var event = { etype: 'node', userid: user._id, username: user.name, action: 'changenode', nodeid: node._id, domain: domain.id, msg: 'No longer a relay for ' + mesh.name + '.', msgid: 152, msgArgs: [mesh.name], node: parent.CloneSafeNode(node) };
|
||||
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come.
|
||||
parent.parent.DispatchEvent(parent.CreateNodeDispatchTargets(node.meshid, node._id, [user._id]), obj, event);
|
||||
});
|
||||
}
|
||||
|
||||
// Mark the mesh as deleted
|
||||
mesh.deleted = new Date(); // Mark the time this mesh was deleted, we can expire it at some point.
|
||||
db.Set(mesh); // We don't really delete meshes because if a device connects to is again, we will un-delete it.
|
||||
|
@ -2128,9 +2139,15 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||
if ((common.validateInt(command.consent) == true) && (command.consent != mesh.consent)) { if (change != '') change += ' and consent changed'; else change += 'Device group "' + mesh.name + '" consent changed'; changesids.push(4); mesh.consent = command.consent; }
|
||||
if ((common.validateInt(command.expireDevs, 0, 2000) == true) && (command.expireDevs != mesh.expireDevs)) { if (change != '') change += ' and auto-remove changed'; else change += 'Device group "' + mesh.name + '" auto-remove changed'; changesids.push(5); if (command.expireDevs == 0) { delete mesh.expireDevs; } else { mesh.expireDevs = command.expireDevs; } }
|
||||
|
||||
var oldRelayNodeId = null, newRelayNodeId = null;
|
||||
if ((typeof command.relayid == 'string') && (mesh.mtype == 3) && (mesh.relayid != null) && (command.relayid != mesh.relayid)) {
|
||||
var relayIdSplit = command.relayid.split('/');
|
||||
if ((relayIdSplit.length == 3) && (relayIdSplit[0] = 'node') && (relayIdSplit[1] == domain.id)) { if (change != '') { change += ' and device relay changed'; } else { change = 'Device relay changed'; } changesids.push(7); mesh.relayid = command.relayid; }
|
||||
if ((relayIdSplit.length == 3) && (relayIdSplit[0] = 'node') && (relayIdSplit[1] == domain.id)) {
|
||||
if (change != '') { change += ' and device relay changed'; } else { change = 'Device relay changed'; }
|
||||
changesids.push(7);
|
||||
oldRelayNodeId = mesh.relayid;
|
||||
newRelayNodeId = mesh.relayid = command.relayid;
|
||||
}
|
||||
}
|
||||
|
||||
// See if we need to change device group invitation codes
|
||||
|
@ -2170,6 +2187,26 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
|||
parent.parent.DispatchEvent(parent.CreateMeshDispatchTargets(mesh, [user._id]), obj, event);
|
||||
}
|
||||
|
||||
// Notify the devices that they have changed relay roles
|
||||
if (oldRelayNodeId != null) {
|
||||
// Get the node and the rights for this node
|
||||
parent.GetNodeWithRights(domain, user, oldRelayNodeId, function (node, rights, visible) {
|
||||
if (node == null) return;
|
||||
var event = { etype: 'node', userid: user._id, username: user.name, action: 'changenode', nodeid: node._id, domain: domain.id, msg: 'No longer a relay for ' + mesh.name + '.', msgid: 152, msgArgs: [mesh.name], node: parent.CloneSafeNode(node) };
|
||||
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come.
|
||||
parent.parent.DispatchEvent(parent.CreateNodeDispatchTargets(node.meshid, node._id, [user._id]), obj, event);
|
||||
});
|
||||
}
|
||||
if (newRelayNodeId != null) {
|
||||
// Get the node and the rights for this node
|
||||
parent.GetNodeWithRights(domain, user, newRelayNodeId, function (node, rights, visible) {
|
||||
if (node == null) return;
|
||||
var event = { etype: 'node', userid: user._id, username: user.name, action: 'changenode', nodeid: node._id, domain: domain.id, msg: 'Is a relay for ' + mesh.name + '.', msgid: 153, msgArgs: [mesh.name], node: parent.CloneSafeNode(node) };
|
||||
if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the node. Another event will come.
|
||||
parent.parent.DispatchEvent(parent.CreateNodeDispatchTargets(node.meshid, node._id, [user._id]), obj, event);
|
||||
});
|
||||
}
|
||||
|
||||
if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'editmesh', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -6957,6 +6957,11 @@
|
|||
x += addDeviceAttribute("Credentials", y.join(', '));
|
||||
}
|
||||
|
||||
// Relay for
|
||||
var relayFor = [];
|
||||
for (var i in meshes) { if (meshes[i].relayid == node._id) { relayFor.push('<a href=# onclick=gotoMesh("' + meshes[i]._id + '") style=cursor:pointer>' + EscapeHtml(meshes[i].name) + '</a>'); } }
|
||||
if (relayFor.length > 0) { x += addDeviceAttribute('<span title="' + "Device groups this device is a relay for" + '">' + "Relay for" + '</span>', relayFor.join(", ")); }
|
||||
|
||||
x += '</table><br />';
|
||||
// Show action button, only show if we have permissions 4, 8, 64
|
||||
if (((meshrights & (4 + 8 + 64)) != 0) && (node.mtype < 3) && ((node.agent == null) || (node.agent.id != 34))) { x += '<input type=button value="' + "Actions" + '" title="' + "Perform power actions on the device" + '" onclick=deviceActionFunction() />'; }
|
||||
|
@ -13613,7 +13618,9 @@
|
|||
148: "Started Web-SSH session \"{0}\".",
|
||||
149: "Started Web-SFTP session \"{0}\".",
|
||||
150: "Started Web-RDP session \"{0}\".",
|
||||
151: "Started Web-VNC session \"{0}\"." // Not in use yet
|
||||
151: "Started Web-VNC session \"{0}\".", // Not in use yet
|
||||
152: "No longer a relay for \"{0}\".",
|
||||
153: "Is a relay for \"{0}\".",
|
||||
};
|
||||
|
||||
var eventsShortMessageId = {
|
||||
|
|
Loading…
Reference in New Issue