Completed per-device notification support. #3190
Ylian Saint-Hilaire committed
Oct 14, 2021 at 18:21 UTC
9720f0758e5ba11e8d21f39c3aa82ad269cff2c1
4 files changed
+44
-14
meshcentral.js
+15
-3
@@ -2095,21 +2095,33 @@ function CreateMeshCentralServer(config, args) {
2095
if ((mesh == null) || (mesh.links == null)) return;
2096
2097
// Check if any user needs email notification
2098
+ // TODO: Add user group support.
2099
for (var i in mesh.links) {
2100
if (i.startsWith('user/')) {
2101
const user = obj.webserver.users[i];
2102
if ((user != null) && (user.email != null) && (user.emailVerified == true)) {
2103
+ var notify = 0;
2104
+
2105
+ // Device group notifications
2106
const meshLinks = user.links[meshid];
2103
- if ((meshLinks != null) && (meshLinks.notify != null) && ((meshLinks.notify & 48) != 0)) {
2107
+ if ((meshLinks != null) && (meshLinks.notify != null)) { notify |= meshLinks.notify; }
2108
+
2109
+ // User notifications
2110
+ if (user.notify != null) {
2111
+ if (user.notify[meshid] != null) { notify |= user.notify[meshid]; }
2112
+ if (user.notify[nodeid] != null) { notify |= user.notify[nodeid]; }
2113
+ }
2114
+
2115
+ if ((notify & 48) != 0) {
2116
if (stateSet == true) {
2105
- if ((meshLinks.notify & 16) != 0) {
2117
+ if ((notify & 16) != 0) {
2118
mailserver.notifyDeviceConnect(user, meshid, nodeid, connectTime, connectType, powerState, serverid, extraInfo);
2119
} else {
2120
mailserver.cancelNotifyDeviceDisconnect(user, meshid, nodeid, connectTime, connectType, powerState, serverid, extraInfo);
2121
}
2122
}
2123
else if (stateSet == false) {
2112
- if ((meshLinks.notify & 32) != 0) {
2124
+ if ((notify & 32) != 0) {
2125
mailserver.notifyDeviceDisconnect(user, meshid, nodeid, connectTime, connectType, powerState, serverid, extraInfo);
2126
} else {
2127
mailserver.cancelNotifyDeviceConnect(user, meshid, nodeid, connectTime, connectType, powerState, serverid, extraInfo);
meshuser.js
+5
-2
@@ -2130,8 +2130,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2130
// Handle any errors
2131
if (err != null) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'changemeshnotify', responseid: command.responseid, result: err })); } catch (ex) { } } break; }
2132
2133
- // Change the notification (TODO: Add user group support, not sure how to do this here)
2134
- // TODO (UserGroups)
2133
+ // Change the device group notification
2134
if (user.links[command.meshid]) {
2135
if (command.notify == 0) {
2136
delete user.links[command.meshid].notify;
@@ -2140,6 +2139,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
2139
}
2140
}
2141
2142
+ // Change user notification if needed, this is needed then a user has device rights thru a user group
2143
+ if ((command.notify == 0) && (user.notify != null) && (user.notify[command.meshid] != null)) { delete user.notify[command.meshid]; }
2144
+ if ((command.notify != 0) && (user.links[command.meshid] == null)) { if (user.notify == null) { user.notify = {} } user.notify[command.meshid] = command.notify; }
2145
+
2146
// Save the user
2147
parent.db.SetUser(user);
2148
package.json
+15
-2
@@ -36,6 +36,9 @@
36
"sample-config-advanced.json"
37
],
38
"dependencies": {
39
+ "@yetzt/nedb": "^1.8.0",
40
+ "archiver": "^4.0.2",
41
+ "archiver-zip-encrypted": "^1.0.10",
42
"body-parser": "^1.19.0",
43
"cbor": "~5.2.0",
44
"compression": "^1.7.4",
@@ -43,13 +46,23 @@
46
"express": "^4.17.0",
47
"express-handlebars": "^3.1.0",
48
"express-ws": "^4.0.0",
49
+ "image-size": "^1.0.0",
50
"ipcheck": "^0.1.0",
51
+ "loadavg-windows": "^1.1.1",
52
"minimist": "^1.2.5",
53
+ "mongodb": "^4.1.0",
54
"multiparty": "^4.2.1",
49
- "@yetzt/nedb": "^1.8.0",
55
"node-forge": "^0.10.0",
56
+ "node-rdpjs-2": "^0.3.5",
57
+ "node-windows": "^0.1.4",
58
+ "nodemailer": "^6.7.0",
59
+ "otplib": "^10.2.3",
60
+ "saslprep": "^1.0.3",
61
+ "ssh2": "^1.5.0",
62
+ "web-push": "^3.4.5",
63
"ws": "^5.2.3",
52
- "yauzl": "^2.10.0"
64
+ "yauzl": "^2.10.0",
65
+ "yubikeyotp": "^0.2.0"
66
},
67
"repository": {
68
"type": "git",
views/default.handlebars
+9
-7
@@ -2903,6 +2903,7 @@
2903
// If our list of nodes may have changes, request the new list now.
2904
if (message.event.nodeListChange == userinfo._id) { meshserver.send({ action: 'nodes' }); }
2905
}
2906
+ if (currentNode) { refreshDevice(currentNode._id); }
2907
if (users == null) break;
2908
2909
// Check if the account is part of our user group
@@ -2912,7 +2913,6 @@
2913
delete users[message.event.account._id]; // No longer part of our groups, remove this user.
2914
}
2915
2915
- if (currentNode) { refreshDevice(currentNode._id); }
2916
mainUpdate(4 | 16384);
2917
break;
2918
}
@@ -7082,12 +7082,12 @@
7082
if (xxdialogMode) return false;
7083
var devNotify = 0, fx = ((features2 & 0x00004000) && (userinfo.emailVerified))?1:0;
7084
if (userinfo.notify && userinfo.notify[currentNode._id]) { devNotify = userinfo.notify[currentNode._id]; }
7085
- var x = '<div style="border-bottom: 1px solid #888;margin-bottom:3px">Web Page Notifications</div>';
7085
+ var x = '<div style="border-bottom: 1px solid #888;margin-bottom:3px">' + "Web Page Notifications" + '</div>';
7086
x += '<div><label><input id=p20notifyIntelDeviceConnect type=checkbox />' + "Device connections" + '</label></div>';
7087
x += '<div><label><input id=p20notifyIntelDeviceDisconnect type=checkbox />' + "Device disconnections" + '</label></div>';
7088
if (currentNode.intelamt != null) { fx += 2; x += '<div><label><input id=p20notifyIntelAmtKvmActions type=checkbox />' + "Intel® AMT desktop and serial events" + '</label></div>'; }
7089
if (fx & 1) {
7090
- x += '<br /><div style="border-bottom: 1px solid #888;margin-bottom:3px">Email Notifications</div>';
7090
+ x += '<br /><div style="border-bottom: 1px solid #888;margin-bottom:3px">' + "Email Notifications" + '</div>';
7091
x += '<div><label><input id=p20enotifyIntelDeviceConnect type=checkbox />' + "Device connections" + '</label></div>';
7092
x += '<div><label><input id=p20enotifyIntelDeviceDisconnect type=checkbox />' + "Device disconnections" + '</label></div>';
7093
}
@@ -11398,7 +11398,8 @@
11398
if ((userinfo.siteadmin == 0xFFFFFFFF) || ((userinfo.siteadmin & 1024) == 0)) {
11399
// Display user notification
11400
var meshNotify = 0, meshNotifyStr = [];
11401
- if (userinfo.links && userinfo.links[currentMesh._id] && userinfo.links[currentMesh._id].notify) { meshNotify = userinfo.links[currentMesh._id].notify; }
11401
+ if (userinfo.links && userinfo.links[currentMesh._id] && userinfo.links[currentMesh._id].notify) { meshNotify |= userinfo.links[currentMesh._id].notify; }
11402
+ if (userinfo.notify && userinfo.notify[currentMesh._id]) { meshNotify |= userinfo.notify[currentMesh._id]; }
11403
if (meshNotify & 2) { meshNotifyStr.push("Connect"); }
11404
if (meshNotify & 4) { meshNotifyStr.push("Disconnect"); }
11405
if (meshNotify & 8) { meshNotifyStr.push("Intel® AMT"); }
@@ -12325,14 +12326,15 @@
12326
if (xxdialogMode) return false;
12327
var meshNotify = 0;
12328
var emailNotify = ((features2 & 0x00004000) && (userinfo.emailVerified));
12328
- if (userinfo.links && userinfo.links[currentMesh._id] && userinfo.links[currentMesh._id].notify) { meshNotify = userinfo.links[currentMesh._id].notify; }
12329
+ if (userinfo.links && userinfo.links[currentMesh._id] && userinfo.links[currentMesh._id].notify) { meshNotify |= userinfo.links[currentMesh._id].notify; }
12330
+ if (userinfo.notify && userinfo.notify[currentMesh._id]) { meshNotify |= userinfo.notify[currentMesh._id]; }
12331
//var x = "Notification settings must also be turned on in account settings." + '<br /><br />';
12330
- var x = '<div style="border-bottom: 1px solid #888;margin-bottom:3px">Web Page Notifications</div>';
12332
+ var x = '<div style="border-bottom: 1px solid #888;margin-bottom:3px">' + "Web Page Notifications" + '</div>';
12333
x += '<div><label><input id=p20notifyIntelDeviceConnect type=checkbox />' + "Device connections" + '</label></div>';
12334
x += '<div><label><input id=p20notifyIntelDeviceDisconnect type=checkbox />' + "Device disconnections" + '</label></div>';
12335
x += '<div><label><input id=p20notifyIntelAmtKvmActions type=checkbox />' + "Intel® AMT desktop and serial events" + '</label></div>';
12336
if (emailNotify) {
12335
- x += '<br /><div style="border-bottom: 1px solid #888;margin-bottom:3px">Email Notifications</div>';
12337
+ x += '<br /><div style="border-bottom: 1px solid #888;margin-bottom:3px">' + "Email Notifications" + '</div>';
12338
x += '<div><label><input id=p20enotifyIntelDeviceConnect type=checkbox />' + "Device connections" + '</label></div>';
12339
x += '<div><label><input id=p20enotifyIntelDeviceDisconnect type=checkbox />' + "Device disconnections" + '</label></div>';
12340
}