More work on device connect/disconnect email notifications.

This commit is contained in:
Ylian Saint-Hilaire 2021-10-11 09:38:30 -07:00
parent 8696e1c12f
commit 20b17b64b7
3 changed files with 36 additions and 1 deletions

View File

@ -27,6 +27,7 @@ module.exports.CreateMeshMail = function (parent, domain) {
obj.verifyemail = false; obj.verifyemail = false;
obj.domain = domain; obj.domain = domain;
//obj.mailTemplates = {}; //obj.mailTemplates = {};
const sortCollator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
const constants = (obj.parent.crypto.constants ? obj.parent.crypto.constants : require('constants')); // require('constants') is deprecated in Node 11.10, use require('crypto').constants instead. const constants = (obj.parent.crypto.constants ? obj.parent.crypto.constants : require('constants')); // require('constants') is deprecated in Node 11.10, use require('crypto').constants instead.
function EscapeHtml(x) { if (typeof x == "string") return x.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;'); if (typeof x == "boolean") return x; if (typeof x == "number") return x; } function EscapeHtml(x) { if (typeof x == "string") return x.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;'); if (typeof x == "boolean") return x; if (typeof x == "number") return x; }
@ -612,6 +613,10 @@ module.exports.CreateMeshMail = function (parent, domain) {
} }
} }
// Sort the notifications
connections.sort(sortCollator.compare);
disconnections.sort(sortCollator.compare);
// TODO: Send the email // TODO: Send the email
//console.log('sendDeviceNotifications', connections, disconnections); //console.log('sendDeviceNotifications', connections, disconnections);

View File

@ -5663,6 +5663,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
'dropallcira': [serverUserCommandDropAllCira, ""], 'dropallcira': [serverUserCommandDropAllCira, ""],
'dupagents': [serverUserCommandDupAgents, ""], 'dupagents': [serverUserCommandDupAgents, ""],
'email': [serverUserCommandEmail, ""], 'email': [serverUserCommandEmail, ""],
'emailnotifications': [serverUserCommandEmailNotifications, ""],
'firebase': [serverUserCommandFirebase, ""], 'firebase': [serverUserCommandFirebase, ""],
'heapdump': [serverUserCommandHeapDump, ""], 'heapdump': [serverUserCommandHeapDump, ""],
'heapdump2': [serverUserCommandHeapDump2, ""], 'heapdump2': [serverUserCommandHeapDump2, ""],
@ -6053,6 +6054,22 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
} }
} }
function serverUserCommandEmailNotifications(cmdData) {
if (domain.mailserver == null) {
cmdData.result = "No email service enabled.";
} else {
var x = '';
for (var userid in domain.mailserver.deviceNotifications) {
x += userid + '\r\n';
for (var nodeid in domain.mailserver.deviceNotifications[userid].nodes) {
const info = domain.mailserver.deviceNotifications[userid].nodes[nodeid];
x += ' ' + info.mn + ', ' + info.nn + ', c:' + (info.c ? info.c : 0) + ', d:' + (info.d ? info.d : 0) + '\r\n';
}
}
cmdData.result = ((x == '')?'None':x);
}
}
function serverUserCommandLe(cmdData) { function serverUserCommandLe(cmdData) {
if (parent.parent.letsencrypt == null) { if (parent.parent.letsencrypt == null) {
cmdData.result = "Let's Encrypt not in use."; cmdData.result = "Let's Encrypt not in use.";

View File

@ -36,6 +36,8 @@
"sample-config-advanced.json" "sample-config-advanced.json"
], ],
"dependencies": { "dependencies": {
"archiver": "^4.0.2",
"archiver-zip-encrypted": "^1.0.10",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"cbor": "~5.2.0", "cbor": "~5.2.0",
"compression": "^1.7.4", "compression": "^1.7.4",
@ -43,13 +45,24 @@
"express": "^4.17.0", "express": "^4.17.0",
"express-handlebars": "^3.1.0", "express-handlebars": "^3.1.0",
"express-ws": "^4.0.0", "express-ws": "^4.0.0",
"image-size": "^1.0.0",
"ipcheck": "^0.1.0", "ipcheck": "^0.1.0",
"loadavg-windows": "^1.1.1",
"minimist": "^1.2.0", "minimist": "^1.2.0",
"mongodb": "^4.1.0",
"multiparty": "^4.2.1", "multiparty": "^4.2.1",
"nedb": "^1.8.0", "nedb": "^1.8.0",
"node-forge": "^0.10.0", "node-forge": "^0.10.0",
"node-rdpjs-2": "^0.3.5",
"node-windows": "^1.0.0-beta.6",
"nodemailer": "^6.6.5",
"otplib": "^10.2.3",
"saslprep": "^1.0.3",
"ssh2": "^1.4.0",
"web-push": "^3.4.5",
"ws": "^5.2.3", "ws": "^5.2.3",
"yauzl": "^2.10.0" "yauzl": "^2.10.0",
"yubikeyotp": "^0.2.0"
}, },
"repository": { "repository": {
"type": "git", "type": "git",