Added device events and admin change of user email

Ylian Saint-Hilaire committed Apr 16, 2018 at 15:37 UTC 17e5000ef8e0302bd1213f8cc4fc40f83e0131dd
4 files changed +157 -20
db.js
+1
@@ -99,6 +99,7 @@ module.exports.CreateDB = function (args, datapath) {
99 obj.StoreEvent = function (ids, source, event) { obj.file.insert(event); }
100 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) } }
101 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); } }
102 + 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); } }
103 obj.RemoveMesh = function (id) { obj.file.remove({ mesh: id }, { multi: true }); obj.file.remove({ _id: id }); obj.file.remove({ _id: 'nt' + id }); }
104 obj.RemoveAllEvents = function (domain) { obj.file.remove({ type: 'event', domain: domain }, { multi: true }); }
105 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]); } }); }
meshuser.js
+27 -10
@@ -278,18 +278,34 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
278 }
279 case 'events':
280 {
281 - // Setup the event filter
282 - var filter = user.subscriptions;
281 + // User filtered events
282 if ((command.user != null) && ((user.siteadmin & 2) != 0)) { // SITERIGHT_MANAGEUSERS
284 - // TODO: Add the meshes command.user has access to
285 - filter = ['user/' + domain.id + '/' + command.user.toLowerCase()];
286 - }
287 - if ((command.limit == null) || (typeof command.limit != 'number')) {
288 - // Send the list of all events for this session
289 - 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) { } });
290 - } else {
283 + // TODO: Add the meshes command.user has access to (???)
284 + var filter = ['user/' + domain.id + '/' + command.user.toLowerCase()];
285 + if ((command.limit == null) || (typeof command.limit != 'number')) {
286 + // Send the list of all events for this session
287 + 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) { } });
288 + } else {
289 + // Send the list of most recent events for this session, up to 'limit' count
290 + 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) { } });
291 + }
292 + } else if (obj.common.validateString(command.nodeid, 0, 128) == true) { // Device filtered events
293 + // TODO: Check that the user has access to this nodeid
294 + var limit = 10000;
295 + if (obj.common.validateInt(command.limit, 1, 60000) == true) { limit = command.limit; }
296 +
297 // Send the list of most recent events for this session, up to 'limit' count
292 - 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) { } });
298 + 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) { } });
299 + } else {
300 + // All events
301 + var filter = user.subscriptions;
302 + if ((command.limit == null) || (typeof command.limit != 'number')) {
303 + // Send the list of all events for this session
304 + 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) { } });
305 + } else {
306 + // Send the list of most recent events for this session, up to 'limit' count
307 + 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) { } });
308 + }
309 }
310 break;
311 }
@@ -443,6 +459,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
459 var chguserid = 'user/' + domain.id + '/' + command.name.toLowerCase(), chguser = obj.parent.users[chguserid], change = 0;
460 if (chguser) {
461 if (obj.common.validateString(command.email, 1, 256) && (chguser.email != command.email)) { chguser.email = command.email; change = 1; }
462 + if ((command.emailVerified === true || command.emailVerified === false) && (chguser.emailVerified != command.emailVerified)) { chguser.emailVerified = command.emailVerified; change = 1; }
463 if (obj.common.validateInt(command.quota, 0) && (command.quota != chguser.quota)) { chguser.quota = command.quota; if (chguser.quota == null) { delete chguser.quota; } change = 1; }
464 if ((user.siteadmin == 0xFFFFFFFF) && obj.common.validateInt(command.siteadmin) && (chguser.siteadmin != command.siteadmin)) { chguser.siteadmin = command.siteadmin; change = 1 }
465 if (change == 1) {
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.1.6-l",
3 + "version": "0.1.6-m",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
views/default.handlebars
+128 -9
@@ -35,9 +35,10 @@
35 <div id="cxterminal" class="cmtext" onclick="cmaction(2)">Terminal</div>
36 <div id="cxdesktop" class="cmtext" onclick="cmaction(3)">Desktop</div>
37 <div id="cxfiles" class="cmtext" onclick="cmaction(4)">Files</div>
38 - <div id="cxconsole" class="cmtext" onclick="cmaction(5)">Console</div>
38 + <div id="cxevents" class="cmtext" onclick="cmaction(5)">Events</div>
39 + <div id="cxconsole" class="cmtext" onclick="cmaction(6)">Console</div>
40 <hr id="cxmgroupsplit" />
40 - <div id="cxmdesktop" class="cmtext" onclick="cmaction(6)" style=display:none>Multi-Desktop</div>
41 + <div id="cxmdesktop" class="cmtext" onclick="cmaction(7)" style=display:none>Multi-Desktop</div>
42 </div>
43 <div id="meshContextMenu" class="contextMenu" style="display: none; min-width: 0px">
44 <div id="cxselectall" class="cmtext" onclick="cmmeshaction(1)">Select All</div>
@@ -82,6 +83,7 @@
83 <td id=MainDevDesktop style=width:100px;height:24px;cursor:pointer class=style3 onclick=go(11)>Desktop</td>
84 <td id=MainDevTerminal style=width:100px;height:24px;cursor:pointer class=style3 onclick=go(12)>Terminal</td>
85 <td id=MainDevFiles style=width:100px;height:24px;cursor:pointer;display:none class=style3 onclick=go(13)>Files</td>
86 + <td id=MainDevEvents style=width:100px;height:24px;cursor:pointer class=style3 onclick=go(16)>Events</td>
87 <td id=MainDevAmt style=width:100px;height:24px;cursor:pointer class=style3 onclick=go(14)>Intel&reg; AMT</td>
88 <td id=MainDevConsole style=width:100px;height:24px;cursor:pointer class=style3 onclick=go(15)>Console</td>
89 <td class=style3 style=height:24px>&nbsp;</td>
@@ -547,6 +549,28 @@
549 </tr>
550 </table>
551 </div>
552 + <div id=p16 style=display:none>
553 + <div id="p16title"><h1><span id=p16deviceName></span> - Events</h1></div>
554 + <div style=width:100%;height:24px;background-color:#d3d9d6;margin-bottom:4px>
555 + <div class=style7 style=width:16px;height:100%;float:left>&nbsp;</div>
556 + <div class=h1 style=height:100%;float:left>&nbsp;</div>
557 + <!--<div class=style14 style=height:100%;float:left>&nbsp;&nbsp;<input id=p31deleteall type=button style=display:none value="Delete All..." />&nbsp;</div>-->
558 + <div class=style14 style=height:100%;float:left>&nbsp;&nbsp;<input type=button value=Refresh onclick=refreshDeviceEvents() />&nbsp;</div>
559 + <div class="auto-style1" style="height:100%;float:right">
560 + Show
561 + <select id=p16limitdropdown onchange=refreshDeviceEvents()>
562 + <option value=60>Last 60</option>
563 + <option value=120>Last 120</option>
564 + <option value=250>Last 250</option>
565 + <option value=500>Last 500</option>
566 + <option value=1000>Last 1000</option>
567 + </select>
568 + <div style="height:100%;width:20px;float:right;background-color:#ffffff"></div>
569 + <div class=h2 style=height:100%;float:right>&nbsp;</div>
570 + </div>
571 + </div>
572 + <div id=p16events style="max-height:600px;overflow-y:scroll"></div>
573 + </div>
574 <div id=p20 style=display:none>
575 <h1><span id=p20meshName></span> - General</h1>
576 <p id=p20info></p>
@@ -773,6 +797,7 @@
797 QV('p13title', !(hide & 8));
798 QV('p14title', !(hide & 8));
799 QV('p15title', !(hide & 8));
800 + QV('p16title', !(hide & 8));
801 }
802 p1updateInfo();
803
@@ -1073,7 +1098,10 @@
1098 break;
1099 }
1100 case 'events': {
1076 - if ((message.user != null) && (message.user == currentUser.name)) {
1101 + if ((message.nodeid != null) && (message.nodeid == currentNode._id)) {
1102 + currentDeviceEvents = message.events;
1103 + devevents_update();
1104 + } else if ((message.user != null) && (message.user == currentUser.name)) {
1105 currentUserEvents = message.events;
1106 userEvents_update();
1107 } else {
@@ -2077,8 +2105,9 @@
2105 if (action == 2) gotoDevice(nodeid, 12); // Desktop
2106 if (action == 3) gotoDevice(nodeid, 11); // Terminal
2107 if (action == 4) gotoDevice(nodeid, 13); // Files
2080 - if (action == 5) gotoDevice(nodeid, 15); // Console
2081 - if (action == 6) { Q('viewselect').value = 3; Q('viewselect').onchange(); Q('autoConnectDesktopCheckbox').checked = true; Q('autoConnectDesktopCheckbox').onclick(); } // Multi-Desktop
2108 + if (action == 5) gotoDevice(nodeid, 16); // Events
2109 + if (action == 6) gotoDevice(nodeid, 15); // Console
2110 + if (action == 7) { Q('viewselect').value = 3; Q('viewselect').onchange(); Q('autoConnectDesktopCheckbox').checked = true; Q('autoConnectDesktopCheckbox').onclick(); } // Multi-Desktop
2111 }
2112
2113 function cmmeshaction(action) {
@@ -2736,6 +2765,7 @@
2765 QH('p13deviceName', nname);
2766 QH('p14deviceName', nname);
2767 QH('p15deviceName', nname);
2768 + QH('p16deviceName', nname);
2769
2770 // Node attributes
2771 var x = '<table style=width:100%>';
@@ -2892,6 +2922,9 @@
2922 // Reset the desktop tools
2923 QV('DeskTools', false);
2924 showDeskToolsProcesses();
2925 +
2926 + // Ask for device events
2927 + refreshDeviceEvents();
2928 }
2929 setupDesktop(); // Always refresh the desktop, even if we are on the same device, we need to do some canvas switching.
2930 if (!panel) panel = 10;
@@ -4115,6 +4148,61 @@
4148 }
4149 }
4150
4151 + //
4152 + // DEVICE EVENTS
4153 + //
4154 +
4155 + var currentDeviceEvents = null;
4156 + function devevents_update() {
4157 + var x = '', dateHeader = null;
4158 + for (var i in currentDeviceEvents) {
4159 + var event = currentDeviceEvents[i];
4160 + var time = new Date(event.time);
4161 + if (time.toLocaleDateString() != dateHeader) {
4162 + if (dateHeader != null) x += '</table>';
4163 + x += '<table style=width:100% cellpadding=0 cellspacing=0><tr><td class=DevSt>' + time.toLocaleDateString() + '</td></tr>';
4164 + dateHeader = time.toLocaleDateString();
4165 + }
4166 + var icon = 'si3';
4167 + if (event.etype == 'user') icon = 'm2';
4168 + if (event.etype == 'server') icon = 'si3';
4169 +
4170 + var msg = event.msg.split('(R)').join('&reg;');
4171 + //if (event.username && event.username != userinfo.name) { msg += ': ' + event.username; }
4172 + x += '<tr><td><div class=bar18 style=height:18px;width:100%;font-size:medium>';
4173 + x += '<div style=float:left;height:18px;width:18px;background-color:white><div class=' + icon + ' style=width:16px;margin-top:1px;margin-left:2px;height:16px></div></div>';
4174 + x += '<div class=g1 style=height:18px;float:left></div><div class=g2 style=height:18px;float:right></div>';
4175 + x += '<div style=font-size:14px><span style=width:300px>' + time.toLocaleTimeString() + ' - ' + msg + '</span></div></div></td></tr>';
4176 + }
4177 + if (dateHeader != null) x += '</table>';
4178 + if (x == '') x = "<br><i>No Events Found</i><br><br>";
4179 + QH('p16events', x);
4180 + }
4181 +
4182 + /*
4183 + function showDeleteAllEventsDialog() {
4184 + if (xxdialogMode) return;
4185 + var x = "Delete all events in the server event log?<br /><br />";
4186 + x += "<input id=p3check type=checkbox onchange=validateDeleteAllEventsDialog() />Confirm";
4187 + setDialogMode(2, "Delete All Events", 3, showDeleteAllEventsDialogEx, x);
4188 + validateDeleteAllEventsDialog();
4189 + }
4190 +
4191 + function validateDeleteAllEventsDialog() {
4192 + QE('idx_dlgOkButton', Q('p3check').checked);
4193 + }
4194 +
4195 + function showDeleteAllEventsDialogEx(buttons, tag) {
4196 + meshserver.send({ action: 'clearevents' });
4197 + }
4198 + */
4199 +
4200 + function refreshDeviceEvents() {
4201 + //currentDeviceEvents = null;
4202 + //QH('p16events', '');
4203 + meshserver.send({ action: 'events', nodeid: currentNode._id, limit: parseInt(p16limitdropdown.value) });
4204 + }
4205 +
4206 //
4207 // CONSOLE
4208 //
@@ -4292,7 +4380,7 @@
4380 Q('dp2email').focus();
4381 }
4382
4295 - function account_validateEmail(e) {
4383 + function account_validateEmail(e, email) {
4384 var x = Q('dp2email').value.split('@');
4385 x = (x.length == 2) && (x[0].length > 0) && (x[1].split('.').length > 1) && (x[1].length > 2) && (Q('dp2email').value.length < 1024) && (Q('dp2email').value != userinfo.email);
4386 QE('idx_dlgOkButton', x);
@@ -5061,11 +5149,13 @@
5149
5150 // Show user attributes
5151 var x = '<div style=min-height:80px><table style=width:100%>';
5064 - if (user.email) x += addDeviceAttribute('Email', '<a style=cursor:pointer onclick=doemail(event,\"' + user.email + '\")>' + EscapeHtml(user.email) + '</a>');
5065 - x += addDeviceAttribute('Creation', new Date(user.creation).toLocaleString());
5066 - if (user.login) x += addDeviceAttribute('Last Login', new Date(user.login).toLocaleString());
5152 + var email = user.email?EscapeHtml(user.email):'<i>Not set</i>', everify = '';
5153 + if (serverinfo.emailcheck) { everify = ((user.emailVerified == true)?'':', Unverified'); }
5154 + x += addDeviceAttribute('Email', "<a style=cursor:pointer onclick=p30showUserEmailChangeDialog(event,\"" + userid + "\")>" + email + everify + '</a> <a style=cursor:pointer onclick=doemail(event,\"' + user.email + '\")><img src="images/link1.png" /></a>');
5155 x += addDeviceAttribute('Server Rights', "<a style=cursor:pointer onclick=showUserAdminDialog(event,\"" + userid + "\")>" + msg + "</a>");
5156 if (user.quota) x += addDeviceAttribute('Server Quota', EscapeHtml(parseInt(user.quota) / 1024) + ' k');
5157 + x += addDeviceAttribute('Creation', new Date(user.creation).toLocaleString());
5158 + if (user.login) x += addDeviceAttribute('Last Login', new Date(user.login).toLocaleString());
5159
5160 x += '</table></div><br />';
5161
@@ -5104,6 +5194,34 @@
5194 refreshUsersEvents();
5195 }
5196
5197 + // Display the user's email change dialog box
5198 + function p30showUserEmailChangeDialog(event) {
5199 + if (xxdialogMode) return;
5200 + var x = '';
5201 + x += addHtmlValue('Email', '<input id=dp30email style=width:230px maxlength=32 onchange=p30validateEmail() onkeyup=p30validateEmail() />');
5202 + if (serverinfo.emailcheck) { x += addHtmlValue('Status', '<select id=dp30verified style=width:230px onchange=p30validateEmail()><option value=0>Not verified</option><option value=1>Verified</option></select>'); }
5203 + setDialogMode(2, "Change Email for " + EscapeHtml(currentUser.name), 3, p30showUserEmailChangeDialogEx, x);
5204 + Q('dp30email').focus();
5205 + Q('dp30email').value = currentUser.email;
5206 + if (serverinfo.emailcheck) { Q('dp30verified').value = currentUser.emailVerified?1:0; }
5207 + p30validateEmail();
5208 + }
5209 +
5210 + // Perform validation on the user's email change dialog box
5211 + function p30validateEmail() {
5212 + var v = Q('dp30email').value, x = v.split('@');
5213 + x = (x.length == 2) && (x[0].length > 0) && (x[1].split('.').length > 1) && (x[1].length > 2) && (v.length < 1024) && ((v != userinfo.email) || ((serverinfo.emailcheck == true) && (Q('dp30verified').value != (userinfo.emailVerified?1:0))));
5214 + QE('idx_dlgOkButton', x);
5215 + }
5216 +
5217 + // Send to the server the new user's email address and validation status
5218 + function p30showUserEmailChangeDialogEx() {
5219 + var x = { action: 'edituser', name: currentUser.name, email: Q('dp30email').value };
5220 + if (serverinfo.emailcheck) { x.emailVerified = (Q('dp30verified').value == 1); }
5221 + meshserver.send(x);
5222 + }
5223 +
5224 + // Display the user's password change dialog box
5225 function p30showUserChangePassDialog() {
5226 if (xxdialogMode) return;
5227 var x = '';
@@ -5464,6 +5582,7 @@
5582 QS('MainDevDesktop').backgroundColor = ((x == 11) ? "#003366" : "#808080");
5583 QS('MainDevTerminal').backgroundColor = ((x == 12) ? "#003366" : "#808080");
5584 QS('MainDevFiles').backgroundColor = ((x == 13) ? "#003366" : "#808080");
5585 + QS('MainDevEvents').backgroundColor = ((x == 16) ? "#003366" : "#808080");
5586 QS('MainDevAmt').backgroundColor = ((x == 14) ? "#003366" : "#808080");
5587 QS('MainDevConsole').backgroundColor = ((x == 15) ? "#003366" : "#808080");
5588 QV('MeshSubMenuSpan', x >= 20 && x < 30);