From 9720f0758e5ba11e8d21f39c3aa82ad269cff2c1 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Thu, 14 Oct 2021 18:21:43 -0700 Subject: [PATCH] Completed per-device notification support. #3190 --- meshcentral.js | 18 +++++++++++++++--- meshuser.js | 7 +++++-- package.json | 17 +++++++++++++++-- views/default.handlebars | 16 +++++++++------- 4 files changed, 44 insertions(+), 14 deletions(-) diff --git a/meshcentral.js b/meshcentral.js index 14eb78e6..f1cfa48e 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -2095,21 +2095,33 @@ function CreateMeshCentralServer(config, args) { if ((mesh == null) || (mesh.links == null)) return; // Check if any user needs email notification + // TODO: Add user group support. for (var i in mesh.links) { if (i.startsWith('user/')) { const user = obj.webserver.users[i]; if ((user != null) && (user.email != null) && (user.emailVerified == true)) { + var notify = 0; + + // Device group notifications const meshLinks = user.links[meshid]; - if ((meshLinks != null) && (meshLinks.notify != null) && ((meshLinks.notify & 48) != 0)) { + if ((meshLinks != null) && (meshLinks.notify != null)) { notify |= meshLinks.notify; } + + // User notifications + if (user.notify != null) { + if (user.notify[meshid] != null) { notify |= user.notify[meshid]; } + if (user.notify[nodeid] != null) { notify |= user.notify[nodeid]; } + } + + if ((notify & 48) != 0) { if (stateSet == true) { - if ((meshLinks.notify & 16) != 0) { + if ((notify & 16) != 0) { mailserver.notifyDeviceConnect(user, meshid, nodeid, connectTime, connectType, powerState, serverid, extraInfo); } else { mailserver.cancelNotifyDeviceDisconnect(user, meshid, nodeid, connectTime, connectType, powerState, serverid, extraInfo); } } else if (stateSet == false) { - if ((meshLinks.notify & 32) != 0) { + if ((notify & 32) != 0) { mailserver.notifyDeviceDisconnect(user, meshid, nodeid, connectTime, connectType, powerState, serverid, extraInfo); } else { mailserver.cancelNotifyDeviceConnect(user, meshid, nodeid, connectTime, connectType, powerState, serverid, extraInfo); diff --git a/meshuser.js b/meshuser.js index 829570dd..96889455 100644 --- a/meshuser.js +++ b/meshuser.js @@ -2130,8 +2130,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // Handle any errors if (err != null) { if (command.responseid != null) { try { ws.send(JSON.stringify({ action: 'changemeshnotify', responseid: command.responseid, result: err })); } catch (ex) { } } break; } - // Change the notification (TODO: Add user group support, not sure how to do this here) - // TODO (UserGroups) + // Change the device group notification if (user.links[command.meshid]) { if (command.notify == 0) { delete user.links[command.meshid].notify; @@ -2140,6 +2139,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use } } + // Change user notification if needed, this is needed then a user has device rights thru a user group + if ((command.notify == 0) && (user.notify != null) && (user.notify[command.meshid] != null)) { delete user.notify[command.meshid]; } + if ((command.notify != 0) && (user.links[command.meshid] == null)) { if (user.notify == null) { user.notify = {} } user.notify[command.meshid] = command.notify; } + // Save the user parent.db.SetUser(user); diff --git a/package.json b/package.json index 5ab6666a..ca8524e9 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,9 @@ "sample-config-advanced.json" ], "dependencies": { + "@yetzt/nedb": "^1.8.0", + "archiver": "^4.0.2", + "archiver-zip-encrypted": "^1.0.10", "body-parser": "^1.19.0", "cbor": "~5.2.0", "compression": "^1.7.4", @@ -43,13 +46,23 @@ "express": "^4.17.0", "express-handlebars": "^3.1.0", "express-ws": "^4.0.0", + "image-size": "^1.0.0", "ipcheck": "^0.1.0", + "loadavg-windows": "^1.1.1", "minimist": "^1.2.5", + "mongodb": "^4.1.0", "multiparty": "^4.2.1", - "@yetzt/nedb": "^1.8.0", "node-forge": "^0.10.0", + "node-rdpjs-2": "^0.3.5", + "node-windows": "^0.1.4", + "nodemailer": "^6.7.0", + "otplib": "^10.2.3", + "saslprep": "^1.0.3", + "ssh2": "^1.5.0", + "web-push": "^3.4.5", "ws": "^5.2.3", - "yauzl": "^2.10.0" + "yauzl": "^2.10.0", + "yubikeyotp": "^0.2.0" }, "repository": { "type": "git", diff --git a/views/default.handlebars b/views/default.handlebars index 1d2161d4..db3d0dd1 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -2903,6 +2903,7 @@ // If our list of nodes may have changes, request the new list now. if (message.event.nodeListChange == userinfo._id) { meshserver.send({ action: 'nodes' }); } } + if (currentNode) { refreshDevice(currentNode._id); } if (users == null) break; // Check if the account is part of our user group @@ -2912,7 +2913,6 @@ delete users[message.event.account._id]; // No longer part of our groups, remove this user. } - if (currentNode) { refreshDevice(currentNode._id); } mainUpdate(4 | 16384); break; } @@ -7082,12 +7082,12 @@ if (xxdialogMode) return false; var devNotify = 0, fx = ((features2 & 0x00004000) && (userinfo.emailVerified))?1:0; if (userinfo.notify && userinfo.notify[currentNode._id]) { devNotify = userinfo.notify[currentNode._id]; } - var x = '
Web Page Notifications
'; + var x = '
' + "Web Page Notifications" + '
'; x += '
'; x += '
'; if (currentNode.intelamt != null) { fx += 2; x += '
'; } if (fx & 1) { - x += '
Email Notifications
'; + x += '
' + "Email Notifications" + '
'; x += '
'; x += '
'; } @@ -11398,7 +11398,8 @@ if ((userinfo.siteadmin == 0xFFFFFFFF) || ((userinfo.siteadmin & 1024) == 0)) { // Display user notification var meshNotify = 0, meshNotifyStr = []; - if (userinfo.links && userinfo.links[currentMesh._id] && userinfo.links[currentMesh._id].notify) { meshNotify = userinfo.links[currentMesh._id].notify; } + if (userinfo.links && userinfo.links[currentMesh._id] && userinfo.links[currentMesh._id].notify) { meshNotify |= userinfo.links[currentMesh._id].notify; } + if (userinfo.notify && userinfo.notify[currentMesh._id]) { meshNotify |= userinfo.notify[currentMesh._id]; } if (meshNotify & 2) { meshNotifyStr.push("Connect"); } if (meshNotify & 4) { meshNotifyStr.push("Disconnect"); } if (meshNotify & 8) { meshNotifyStr.push("Intel® AMT"); } @@ -12325,14 +12326,15 @@ if (xxdialogMode) return false; var meshNotify = 0; var emailNotify = ((features2 & 0x00004000) && (userinfo.emailVerified)); - if (userinfo.links && userinfo.links[currentMesh._id] && userinfo.links[currentMesh._id].notify) { meshNotify = userinfo.links[currentMesh._id].notify; } + if (userinfo.links && userinfo.links[currentMesh._id] && userinfo.links[currentMesh._id].notify) { meshNotify |= userinfo.links[currentMesh._id].notify; } + if (userinfo.notify && userinfo.notify[currentMesh._id]) { meshNotify |= userinfo.notify[currentMesh._id]; } //var x = "Notification settings must also be turned on in account settings." + '

'; - var x = '
Web Page Notifications
'; + var x = '
' + "Web Page Notifications" + '
'; x += '
'; x += '
'; x += '
'; if (emailNotify) { - x += '
Email Notifications
'; + x += '
' + "Email Notifications" + '
'; x += '
'; x += '
'; }