Added View Self Events only device group permission.
Ylian Saint-Hilaire committed
Sep 18, 2019 at 12:05 UTC
3a161502b029c01f31467bd9d8be7c5e9f0267a3
4 files changed
+46
-12
db.js
+2
@@ -567,6 +567,7 @@ module.exports.CreateDB = function (parent, func) {
567
obj.GetUserEvents = function (ids, domain, username, func) { obj.eventsfile.find({ domain: domain, $or: [{ ids: { $in: ids } }, { username: username }] }).project({ type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).toArray(func); };
568
obj.GetUserEventsWithLimit = function (ids, domain, username, limit, func) { obj.eventsfile.find({ domain: domain, $or: [{ ids: { $in: ids } }, { username: username }] }).project({ type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit).toArray(func); };
569
obj.GetNodeEventsWithLimit = function (nodeid, domain, limit, func) { obj.eventsfile.find({ domain: domain, nodeid: nodeid }).project({ type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit).toArray(func); };
570
+ obj.GetNodeEventsSelfWithLimit = function (nodeid, domain, userid, limit, func) { obj.eventsfile.find({ domain: domain, nodeid: nodeid, userid: { $in: [userid, null] } }).project({ type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit).toArray(func); };
571
obj.RemoveAllEvents = function (domain) { obj.eventsfile.deleteMany({ domain: domain }, { multi: true }); };
572
obj.RemoveAllNodeEvents = function (domain, nodeid) { obj.eventsfile.deleteMany({ domain: domain, nodeid: nodeid }, { multi: true }); };
573
@@ -669,6 +670,7 @@ module.exports.CreateDB = function (parent, func) {
670
}
671
};
672
obj.GetNodeEventsWithLimit = function (nodeid, domain, limit, func) { if (obj.databaseType == 1) { obj.eventsfile.find({ domain: domain, nodeid: nodeid }, { type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit).exec(func); } else { obj.eventsfile.find({ domain: domain, nodeid: nodeid }, { type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit, func); } };
673
+ obj.GetNodeEventsSelfWithLimit = function (nodeid, domain, userid, limit, func) { if (obj.databaseType == 1) { obj.eventsfile.find({ domain: domain, nodeid: nodeid, userid: { $in: [userid, null] } }, { type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit).exec(func); } else { obj.eventsfile.find({ domain: domain, nodeid: nodeid }, { type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit, func); } };
674
obj.RemoveAllEvents = function (domain) { obj.eventsfile.remove({ domain: domain }, { multi: true }); };
675
obj.RemoveAllNodeEvents = function (domain, nodeid) { obj.eventsfile.remove({ domain: domain, nodeid: nodeid }, { multi: true }); };
676
meshagent.js
+3
-2
@@ -1206,12 +1206,13 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
1206
// Log a value in the event log
1207
if ((typeof command.msg == 'string') && (command.msg.length < 4096)) {
1208
var event = { etype: 'node', action: 'agentlog', nodeid: obj.dbNodeKey, domain: domain.id, msg: command.msg };
1209
+ var targets = ['*', obj.dbMeshKey];
1210
if (typeof command.userid == 'string') {
1211
var loguser = parent.users[command.userid];
1211
- if (loguser) { event.userid = command.userid; event.username = loguser.name; }
1212
+ if (loguser) { event.userid = command.userid; event.username = loguser.name; targets.push(command.userid); }
1213
}
1214
if ((typeof command.sessionid == 'string') && (command.sessionid.length < 500)) { event.sessionid = command.sessionid; }
1214
- parent.parent.DispatchEvent(['*', obj.dbMeshKey], obj, event);
1215
+ parent.parent.DispatchEvent(targets, obj, event);
1216
}
1217
break;
1218
}
meshuser.js
+36
-10
@@ -819,18 +819,44 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
819
});
820
}
821
} else if (common.validateString(command.nodeid, 0, 128) == true) { // Device filtered events
822
- // TODO: Check that the user has access to this nodeid
823
- var limit = 10000;
824
- if (common.validateInt(command.limit, 1, 60000) == true) { limit = command.limit; }
825
-
826
- // Send the list of most recent events for this session, up to 'limit' count
827
- db.GetNodeEventsWithLimit(command.nodeid, domain.id, limit, function (err, docs) {
828
- if (err != null) return;
829
- try { ws.send(JSON.stringify({ action: 'events', events: docs, nodeid: command.nodeid, tag: command.tag })); } catch (ex) { }
822
+ // Check that the user has access to this nodeid
823
+ if (obj.user.links == null) return;
824
+ db.Get(command.nodeid, function (err, nodes) {
825
+ if (nodes.length != 1) return;
826
+ const node = nodes[0];
827
+
828
+ var meshlink = obj.user.links[node.meshid];
829
+ if ((meshlink != null) && (meshlink.rights != 0)) {
830
+ // Put a limit on the number of returned entries if present
831
+ var limit = 10000;
832
+ if (common.validateInt(command.limit, 1, 60000) == true) { limit = command.limit; }
833
+
834
+ if ((meshlink.rights & 8192) != 0) {
835
+ // Send the list of most recent events for this nodeid that only apply to us, up to 'limit' count
836
+ db.GetNodeEventsSelfWithLimit(command.nodeid, domain.id, user._id, limit, function (err, docs) {
837
+ if (err != null) return;
838
+ try { ws.send(JSON.stringify({ action: 'events', events: docs, nodeid: command.nodeid, tag: command.tag })); } catch (ex) { }
839
+ });
840
+ } else {
841
+ // Send the list of most recent events for this nodeid, up to 'limit' count
842
+ db.GetNodeEventsWithLimit(command.nodeid, domain.id, limit, function (err, docs) {
843
+ if (err != null) return;
844
+ try { ws.send(JSON.stringify({ action: 'events', events: docs, nodeid: command.nodeid, tag: command.tag })); } catch (ex) { }
845
+ });
846
+ }
847
+ }
848
});
849
} else {
850
+ // Create a filter for device groups
851
+ if (obj.user.links == null) return;
852
+
853
// All events
833
- var filter = user.subscriptions;
854
+ var exGroupFilter2 = [], filter = [], filter2 = user.subscriptions;
855
+
856
+ // Remove MeshID's that we do not have rights to see events for
857
+ for (var link in obj.user.links) { if (((obj.user.links[link].rights & 8192) != 0) && ((obj.user.links[link].rights != 0xFFFFFFFF))) { exGroupFilter2.push(link); } }
858
+ for (var i in filter2) { if (exGroupFilter2.indexOf(filter2[i]) == -1) { filter.push(filter2[i]); } }
859
+
860
if ((command.limit == null) || (typeof command.limit != 'number')) {
861
// Send the list of all events for this session
862
db.GetEvents(filter, domain.id, function (err, docs) {
@@ -2192,7 +2218,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2218
if (node2.intelamt && node2.intelamt.pass) delete node2.intelamt.pass; // Remove the Intel AMT password before eventing this.
2219
event.node = node2;
2220
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.
2195
- parent.parent.DispatchEvent(['*', node.meshid], obj, event);
2221
+ parent.parent.DispatchEvent(['*', node.meshid, user._id], obj, event);
2222
}
2223
}
2224
});
views/default.handlebars
+5
@@ -7027,6 +7027,7 @@
7027
x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20meshserverfiles>Server Files</label><br>';
7028
x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20wakedevices>Wake Devices</label><br>';
7029
x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20editnotes>Edit Device Notes</label><br>';
7030
+ x += '<label><input type=checkbox onchange=p20validateAddMeshUserDialog() id=p20limitevents>Show Only Self Events</label><br>';
7031
x += '</div>';
7032
if (userid == null) {
7033
setDialogMode(2, "Add Users to Device Group", 3, p20showAddMeshUserDialogEx, x);
@@ -7052,6 +7053,7 @@
7053
if (meshrights & 32) { Q('p20meshserverfiles').checked = true; }
7054
if (meshrights & 64) { Q('p20wakedevices').checked = true; }
7055
if (meshrights & 128) { Q('p20editnotes').checked = true; }
7056
+ if (meshrights & 8192) { Q('p20limitevents').checked = true; }
7057
}
7058
}
7059
p20validateAddMeshUserDialog();
@@ -7105,6 +7107,7 @@
7107
QE('p20meshserverfiles', !Q('p20fulladmin').checked);
7108
QE('p20wakedevices', !Q('p20fulladmin').checked);
7109
QE('p20editnotes', !Q('p20fulladmin').checked);
7110
+ QE('p20limitevents', !Q('p20fulladmin').checked);
7111
QE('p20remoteview', !Q('p20fulladmin').checked && Q('p20remotecontrol').checked);
7112
QE('p20remotelimitedinput', !Q('p20fulladmin').checked && Q('p20remotecontrol').checked && !Q('p20remoteview').checked);
7113
QE('p20noterminal', !Q('p20fulladmin').checked && Q('p20remotecontrol').checked);
@@ -7131,6 +7134,7 @@
7134
if (Q('p20nofiles').checked == true) meshadmin += 1024;
7135
if (Q('p20noamt').checked == true) meshadmin += 2048;
7136
if (Q('p20remotelimitedinput').checked == true) meshadmin += 4096;
7137
+ if (Q('p20limitevents').checked == true) meshadmin += 8192;
7138
}
7139
7140
if (t == null) {
@@ -7165,6 +7169,7 @@
7169
if (((meshrights & 8) != 0) && (meshrights & 1024) != 0) r += ', No Files';
7170
if (((meshrights & 8) != 0) && (meshrights & 2048) != 0) r += ', No Intel® AMT';
7171
if (((meshrights & 8) != 0) && ((meshrights & 4096) != 0) && ((meshrights & 256) == 0)) r += ', Limited Input';
7172
+ if ((meshrights & 8192) != 0) r += ', Self Events Only';
7173
}
7174
r = r.substring(2);
7175
if (r == '') { r = 'No Rights'; }