Fixed wake feature.
Ylian Saint-Hilaire committed
Jul 15, 2020 at 13:04 UTC
98dc83c526f06597ff433b122ebafbf58d2b43d5
1 file changed
+11
-5
meshuser.js
+11
-5
@@ -3355,19 +3355,25 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
3355
db.Get('if' + node._id, function (err, nodeifs) {
3356
if ((nodeifs != null) && (nodeifs.length == 1)) {
3357
var macs = [], nodeif = nodeifs[0];
3358
- for (var j in nodeif.netif) { if (nodeif.netif[j].mac) { macs.push(nodeif.netif[j].mac); } }
3358
+ if (nodeif.netif) {
3359
+ for (var j in nodeif.netif) { if (nodeif.netif[j].mac && (nodeif.netif[j].mac != '00:00:00:00:00:00') && (macs.indexOf(nodeif.netif[j].mac) == -1)) { macs.push(nodeif.netif[j].mac); } }
3360
+ } else if (nodeif.netif2) {
3361
+ for (var j in nodeif.netif2) { for (var k in nodeif.netif2[j]) { if (nodeif.netif2[j][k].mac && (nodeif.netif2[j][k].mac != '00:00:00:00:00:00') && (macs.indexOf(nodeif.netif2[j][k].mac) == -1)) { macs.push(nodeif.netif2[j][k].mac); } } }
3362
+ }
3363
+ if (macs.length == 0) return;
3364
3365
// Have the server send a wake-on-lan packet (Will not work in WAN-only)
3366
if (parent.parent.meshScanner != null) { parent.parent.meshScanner.wakeOnLan(macs); }
3367
3363
- // Get the list of mesh this user as access to
3364
- var targetMeshes = [];
3365
- for (j in user.links) { targetMeshes.push(j); } // TODO: Include used security groups!!
3368
+ // Get the list of device groups this user as wake permissions on
3369
+ var targets = [], targetDeviceGroups = parent.GetAllMeshWithRights(user, MESHRIGHT_WAKEDEVICE);
3370
+ for (j in targetDeviceGroups) { targets.push(targetDeviceGroups[j]._id); }
3371
+ for (j in user.links) { if ((j.startsWith('node/')) && (typeof user.links[j].rights == 'number') && ((user.links[j].rights & MESHRIGHT_WAKEDEVICE) != 0)) { targets.push(j); } }
3372
3373
// Go thru all the connected agents and send wake-on-lan on all the ones in the target mesh list
3374
for (j in parent.wsagents) {
3375
var agent = parent.wsagents[j];
3370
- if ((targetMeshes.indexOf(agent.dbMeshKey) >= 0) && (agent.authenticated == 2)) {
3376
+ if ((agent.authenticated == 2) && ((targets.indexOf(agent.dbMeshKey) >= 0) || (targets.indexOf(agent.dbNodeKey) >= 0))) {
3377
//console.log('Asking agent ' + agent.dbNodeKey + ' to wake ' + macs.join(','));
3378
try { agent.send(JSON.stringify({ action: 'wakeonlan', macs: macs })); } catch (ex) { }
3379
}