Server crash fix, improved authlog.

Ylian Saint-Hilaire committed Apr 20, 2020 at 02:44 UTC 955e6f168efbdddb6f51e41147da5fb2c85718c2
5 files changed +39 -6
meshuser.js
+31 -1
@@ -1245,6 +1245,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1245 if (user.groups) { for (var i in user.groups) { targets.push('server-users:' + i); } }
1246 parent.parent.DispatchEvent(targets, obj, message);
1247
1248 + // Log in the auth log
1249 + if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' changed email from ' + oldemail + ' to ' + user.email); }
1250 +
1251 // Send the verification email
1252 if (parent.parent.mailserver != null) { parent.parent.mailserver.sendAccountCheckMail(domain, user.name, user.email, parent.getLanguageCodes(req)); }
1253 }
@@ -1388,6 +1391,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1391
1392 if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'deleteuser', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
1393
1394 + // Log in the auth log
1395 + if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' deleted user account ' + deluser.name); }
1396 +
1397 break;
1398 }
1399 case 'userbroadcast':
@@ -1491,6 +1497,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1497 }
1498 if (parent.db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to create the user. Another event will come.
1499 parent.parent.DispatchEvent(targets, obj, event);
1500 +
1501 + // Log in the auth log
1502 + if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' created user account ' + newuser.name); }
1503 }, newuser);
1504 }
1505 }
@@ -1592,6 +1601,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1601 parent.parent.mailserver.sendAccountInviteMail(domain, user.name, newusername, command.email.toLowerCase(), command.pass, parent.getLanguageCodes(req));
1602 }
1603
1604 + // Log in the auth log
1605 + if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' created user account ' + newuser.name); }
1606 +
1607 // OK Response
1608 if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'adduser', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
1609 } else {
@@ -1783,6 +1795,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1795 // Event any pending events, these must be sent out after the group creation event is displatched.
1796 for (var i in pendingDispatchEvents) { var ev = pendingDispatchEvents[i]; parent.parent.DispatchEvent(ev[0], ev[1], ev[2]); }
1797
1798 + // Log in the auth log
1799 + if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' created user group ' + ugrp.name); }
1800 +
1801 try { ws.send(JSON.stringify({ action: 'createusergroup', responseid: command.responseid, result: 'ok', ugrpid: ugrpid, links: ugrp.links })); } catch (ex) { }
1802 });
1803 break;
@@ -1839,6 +1854,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
1854 var event = { etype: 'ugrp', userid: user._id, username: user.name, ugrpid: group._id, action: 'deleteusergroup', msg: change, domain: domain.id };
1855 if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the mesh. Another event will come.
1856 parent.parent.DispatchEvent(['*', group._id, user._id], obj, event);
1857 +
1858 + // Log in the auth log
1859 + if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' deleted user group ' + group.name); }
1860 });
1861 break;
1862 }
@@ -2066,6 +2084,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2084
2085 // Send user notification of password change
2086 displayNotificationMessage('Password changed.', 'Account Settings', 'ServerNotify');
2087 +
2088 + // Log in the auth log
2089 + if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' changed this password'); }
2090 }
2091 }, 0);
2092 } else {
@@ -2117,6 +2138,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2138 var event = { etype: 'user', userid: user._id, username: user.name, account: parent.CloneSafeUser(chguser), action: 'accountchange', msg: 'Changed account credentials.', domain: domain.id };
2139 if (db.changeStream) { event.noact = 1; } // If DB change stream is active, don't use this event to change the user. Another event will come.
2140 parent.parent.DispatchEvent(targets, obj, event);
2141 +
2142 + // Log in the auth log
2143 + if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' changed account password of user ' + chguser.name); }
2144 } else {
2145 // Report that the password change failed
2146 // TODO
@@ -2276,6 +2300,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2300 var event = { etype: 'mesh', userid: user._id, username: user.name, meshid: meshid, name: command.meshname, mtype: command.meshtype, desc: command.desc, action: 'createmesh', links: links, msg: 'Device group created: ' + command.meshname, domain: domain.id };
2301 parent.parent.DispatchEvent(['*', meshid, user._id], obj, event); // Even if DB change stream is active, this event must be acted upon.
2302
2303 + // Log in the auth log
2304 + if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' created device group ' + mesh.name); }
2305 +
2306 try { ws.send(JSON.stringify({ action: 'createmesh', responseid: command.responseid, result: 'ok', meshid: meshid, links: links })); } catch (ex) { }
2307 });
2308 break;
@@ -2365,6 +2392,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2392 db.RemoveMeshDocuments(command.meshid);
2393 // TODO: We are possibly deleting devices that users will have links to. We need to clean up the broken links from on occasion.
2394
2395 + // Log in the auth log
2396 + if (parent.parent.authlog) { parent.parent.authLog('https', 'User ' + user.name + ' deleted device group ' + mesh.name); }
2397 +
2398 if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'deletemesh', responseid: command.responseid, result: 'ok' })); } catch (ex) { } }
2399 break;
2400 }
@@ -2479,7 +2509,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2509 if (newuserid == obj.user._id) { msgs.push("Can't change self"); continue; }
2510
2511 var targetMeshRights = 0;
2482 - if (newuser.links[command.meshid]) { targetMeshRights = newuser.links[command.meshid].rights; }
2512 + if ((newuser.links != null) && (newuser.links[command.meshid] != null) && (newuser.links[command.meshid].rights != null)) { targetMeshRights = newuser.links[command.meshid].rights; }
2513 if ((targetMeshRights == 0xFFFFFFFF) && (selfMeshRights != 0xFFFFFFFF)) { msgs.push("Can't change rights of device group administrator"); continue; } // A non-admin can't kick out an admin
2514
2515 if (command.remove === true) {
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.5.8",
3 + "version": "0.5.9",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
sample-config.json
+3 -2
@@ -56,8 +56,9 @@
56 "_MpsTlsOffload": true,
57 "_No2FactorAuth": true,
58 "_Log": "main,web,webrequest,cert",
59 - "_syslog": true,
60 - "_syslogjson": true,
59 + "_syslog": "meshcentral",
60 + "_syslogauth": "meshcentral-auth",
61 + "_syslogjson": "meshcentral-json",
62 "_WebRtConfig": {
63 "iceServers": [
64 { "urls": "stun:stun.services.mozilla.com" },
translate/translate.json
+1 -1
@@ -29577,4 +29577,4 @@
29577 ]
29578 }
29579 ]
29580 -}
29580 +}
\ No newline at end of file
views/default.handlebars
+3 -1
@@ -8392,7 +8392,9 @@
8392 for (var i in sortedusers) {
8393 var trash = '', r = sortedusers[i].rights, rights = makeDeviceGroupRightsString(r), icon = 2;
8394 if ((sortedusers[i].id != userinfo._id) && (meshrights == 0xFFFFFFFF || (((meshrights & 2) != 0)))) {
8395 - trash = '<a href=# onclick=\'return p20deleteUser(event,"' + encodeURIComponent(sortedusers[i].id) + '")\' title=\"' + "Remove user rights to this device group" + '\" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>';
8395 + if ((meshrights == 0xFFFFFFFF) || (currentMesh.links[sortedusers[i].id].rights != 0xFFFFFFFF)) {
8396 + trash = '<a href=# onclick=\'return p20deleteUser(event,"' + encodeURIComponent(sortedusers[i].id) + '")\' title=\"' + "Remove user rights to this device group" + '\" style=cursor:pointer><img src=images/trash.png border=0 height=10 width=10></a>';
8397 + }
8398 rights = '<span tabindex=0 style=cursor:pointer onclick=p20viewuser("' + encodeURIComponent(sortedusers[i].id) + '") onkeypress="if (event.key==\'Enter\') p20viewuser(\'' + encodeURIComponent(sortedusers[i].id) + '\')">' + rights + ' <img class=hoverButton style=cursor:pointer src=images/link5.png></span>';
8399 }
8400 if (sortedusers[i].id.startsWith('ugrp/')) { icon = 4; }