diff --git a/db.js b/db.js index 0c552139..386a1d54 100644 --- a/db.js +++ b/db.js @@ -99,6 +99,7 @@ module.exports.CreateDB = function (args, datapath) { obj.StoreEvent = function (ids, source, event) { obj.file.insert(event); } obj.GetEvents = function (ids, domain, func) { if (obj.databaseType == 1) { obj.file.find({ type: 'event', domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).exec(func); } else { obj.file.find({ type: 'event', domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }, func) } } obj.GetEventsWithLimit = function (ids, domain, limit, func) { if (obj.databaseType == 1) { obj.file.find({ type: 'event', domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit).exec(func); } else { obj.file.find({ type: 'event', domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit, func); } } + obj.GetNodeEventsWithLimit = function (nodeid, domain, limit, func) { if (obj.databaseType == 1) { obj.file.find({ type: 'event', domain: domain, nodeid: nodeid }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit).exec(func); } else { obj.file.find({ type: 'event', domain: domain, ids: { $in: ids } }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit, func); } } obj.RemoveMesh = function (id) { obj.file.remove({ mesh: id }, { multi: true }); obj.file.remove({ _id: id }); obj.file.remove({ _id: 'nt' + id }); } obj.RemoveAllEvents = function (domain) { obj.file.remove({ type: 'event', domain: domain }, { multi: true }); } obj.MakeSiteAdmin = function (username, domain) { obj.Get('user/' + domain + '/' + username, function (err, docs) { if (docs.length == 1) { docs[0].siteadmin = 0xFFFFFFFF; obj.Set(docs[0]); } }); } diff --git a/meshuser.js b/meshuser.js index ff2d9bf0..c54ab1b1 100644 --- a/meshuser.js +++ b/meshuser.js @@ -278,18 +278,34 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { } case 'events': { - // Setup the event filter - var filter = user.subscriptions; + // User filtered events if ((command.user != null) && ((user.siteadmin & 2) != 0)) { // SITERIGHT_MANAGEUSERS - // TODO: Add the meshes command.user has access to - filter = ['user/' + domain.id + '/' + command.user.toLowerCase()]; - } - if ((command.limit == null) || (typeof command.limit != 'number')) { - // Send the list of all events for this session - obj.db.GetEvents(filter, domain.id, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } }); - } else { + // TODO: Add the meshes command.user has access to (???) + var filter = ['user/' + domain.id + '/' + command.user.toLowerCase()]; + if ((command.limit == null) || (typeof command.limit != 'number')) { + // Send the list of all events for this session + obj.db.GetEvents(filter, domain.id, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } }); + } else { + // Send the list of most recent events for this session, up to 'limit' count + obj.db.GetEventsWithLimit(filter, domain.id, command.limit, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } }); + } + } else if (obj.common.validateString(command.nodeid, 0, 128) == true) { // Device filtered events + // TODO: Check that the user has access to this nodeid + var limit = 10000; + if (obj.common.validateInt(command.limit, 1, 60000) == true) { limit = command.limit; } + // Send the list of most recent events for this session, up to 'limit' count - obj.db.GetEventsWithLimit(filter, domain.id, command.limit, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } }); + obj.db.GetNodeEventsWithLimit(command.nodeid, domain.id, limit, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, nodeid: command.nodeid, tag: command.tag })); } catch (ex) { } }); + } else { + // All events + var filter = user.subscriptions; + if ((command.limit == null) || (typeof command.limit != 'number')) { + // Send the list of all events for this session + obj.db.GetEvents(filter, domain.id, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } }); + } else { + // Send the list of most recent events for this session, up to 'limit' count + obj.db.GetEventsWithLimit(filter, domain.id, command.limit, function (err, docs) { if (err != null) return; try { ws.send(JSON.stringify({ action: 'events', events: docs, user: command.user, tag: command.tag })); } catch (ex) { } }); + } } break; } @@ -443,6 +459,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { var chguserid = 'user/' + domain.id + '/' + command.name.toLowerCase(), chguser = obj.parent.users[chguserid], change = 0; if (chguser) { if (obj.common.validateString(command.email, 1, 256) && (chguser.email != command.email)) { chguser.email = command.email; change = 1; } + if ((command.emailVerified === true || command.emailVerified === false) && (chguser.emailVerified != command.emailVerified)) { chguser.emailVerified = command.emailVerified; change = 1; } if (obj.common.validateInt(command.quota, 0) && (command.quota != chguser.quota)) { chguser.quota = command.quota; if (chguser.quota == null) { delete chguser.quota; } change = 1; } if ((user.siteadmin == 0xFFFFFFFF) && obj.common.validateInt(command.siteadmin) && (chguser.siteadmin != command.siteadmin)) { chguser.siteadmin = command.siteadmin; change = 1 } if (change == 1) { diff --git a/package.json b/package.json index 2d3eb6ae..f533e18b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.1.6-l", + "version": "0.1.6-m", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default.handlebars b/views/default.handlebars index ba8a56e3..53214564 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -35,9 +35,10 @@
Terminal
Desktop
Files
-
Console
+
Events
+
Console

- + +