Added Pushover messaging integration (#4691)

This commit is contained in:
Ylian Saint-Hilaire 2022-10-30 11:28:24 -07:00
parent 3ea653cd03
commit e59fac4884
5 changed files with 43 additions and 7 deletions

View File

@ -4031,6 +4031,7 @@ function mainStart() {
if (config.messaging.telegram != null) { modules.push('telegram'); modules.push('input'); } if (config.messaging.telegram != null) { modules.push('telegram'); modules.push('input'); }
if (config.messaging.discord != null) { if (nodeVersion >= 17) { modules.push('discord.js@14.6.0'); } else { delete config.messaging.discord; addServerWarning('This NodeJS version does not support Discord.js.', 26); } } if (config.messaging.discord != null) { if (nodeVersion >= 17) { modules.push('discord.js@14.6.0'); } else { delete config.messaging.discord; addServerWarning('This NodeJS version does not support Discord.js.', 26); } }
if (config.messaging.xmpp != null) { modules.push('@xmpp/client'); } if (config.messaging.xmpp != null) { modules.push('@xmpp/client'); }
if (config.messaging.pushover != null) { modules.push('node-pushover'); }
} }
// Setup web based push notifications // Setup web based push notifications

View File

@ -62,19 +62,29 @@
} }
} }
// For Pushover
{
"messaging": {
"pushover": {
"token": "xxxxxxx"
}
}
}
*/ */
// Construct a messaging server object // Construct a messaging server object
module.exports.CreateServer = function (parent) { module.exports.CreateServer = function (parent) {
var obj = {}; var obj = {};
obj.parent = parent; obj.parent = parent;
obj.providers = 0; // 1 = Telegram, 2 = Signal, 4 = Discord, 8 = XMPP, 16 = CallMeBot obj.providers = 0; // 1 = Telegram, 2 = Signal, 4 = Discord, 8 = XMPP, 16 = CallMeBot, 32 = Pushover
obj.telegramClient = null; obj.telegramClient = null;
obj.discordClient = null; obj.discordClient = null;
obj.discordUrl = null; obj.discordUrl = null;
obj.xmppClient = null; obj.xmppClient = null;
var xmppXml = null; var xmppXml = null;
obj.callMeBotClient = null; obj.callMeBotClient = null;
obj.pushoverClient = null;
// Telegram client setup // Telegram client setup
if (parent.config.messaging.telegram) { if (parent.config.messaging.telegram) {
@ -192,6 +202,19 @@ module.exports.CreateServer = function (parent) {
obj.providers += 16; // Enable CallMeBot messaging obj.providers += 16; // Enable CallMeBot messaging
} }
// Pushover client setup (https://pushover.net)
if (parent.config.messaging.pushover) {
// Validate Pushover configuration values
var pushoverOK = true;
if (typeof parent.config.messaging.pushover.token != 'string') { console.log('Invalid or missing Pushover token.'); pushoverOK = false; }
if (pushoverOK) {
// Setup PushOver
obj.pushoverClient = true;
obj.providers += 32; // Enable Pushover messaging
}
}
// Send a direct message to a specific userid // Send a direct message to a specific userid
async function discordSendMsg(userId, message) { async function discordSendMsg(userId, message) {
const user = await obj.discordClient.users.fetch(userId).catch(function () { return null; }); const user = await obj.discordClient.users.fetch(userId).catch(function () { return null; });
@ -221,7 +244,7 @@ module.exports.CreateServer = function (parent) {
} }
// Send an user message // Send an user message
obj.sendMessage = function(to, msg, func) { obj.sendMessage = function(to, msg, domain, func) {
if ((to.startsWith('telegram:')) && (obj.telegramClient != null)) { // Telegram if ((to.startsWith('telegram:')) && (obj.telegramClient != null)) { // Telegram
async function sendTelegramMessage(to, msg, func) { async function sendTelegramMessage(to, msg, func) {
if (obj.telegramClient == null) return; if (obj.telegramClient == null) return;
@ -251,6 +274,10 @@ module.exports.CreateServer = function (parent) {
var url = 'https://api.callmebot.com/facebook/send.php?apikey=' + encodeURIComponent(toData[1]) + '&text=' + encodeURIComponent(msg); var url = 'https://api.callmebot.com/facebook/send.php?apikey=' + encodeURIComponent(toData[1]) + '&text=' + encodeURIComponent(msg);
require('https').get(url, function (r) { if (func != null) { func(r.statusCode == 200); } }); require('https').get(url, function (r) { if (func != null) { func(r.statusCode == 200); } });
} }
} else if ((to.startsWith('pushover:')) && (obj.pushoverClient != null)) { // Pushover
const Pushover = require('node-pushover');
const push = new Pushover({ token: parent.config.messaging.pushover.token, user: to.substring(9) });
push.send(domain.title ? domain.title : 'MeshCentral', msg, function (err, res) { if (func != null) { func(err == null); } });
} else { } else {
// No providers found // No providers found
func(false, "No messaging providers found for this message."); func(false, "No messaging providers found for this message.");
@ -324,7 +351,7 @@ module.exports.CreateServer = function (parent) {
sms = sms.split('[[1]]').join(verificationCode); sms = sms.split('[[1]]').join(verificationCode);
// Send the message // Send the message
obj.sendMessage(to, sms, func); obj.sendMessage(to, sms, domain, func);
}; };
// Send 2FA verification // Send 2FA verification
@ -339,7 +366,7 @@ module.exports.CreateServer = function (parent) {
sms = sms.split('[[1]]').join(verificationCode); sms = sms.split('[[1]]').join(verificationCode);
// Send the message // Send the message
obj.sendMessage(to, sms, func); obj.sendMessage(to, sms, domain, func);
}; };
return obj; return obj;

View File

@ -6570,7 +6570,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if (errMsg != null) { displayNotificationMessage(errMsg); return; } if (errMsg != null) { displayNotificationMessage(errMsg); return; }
parent.parent.msgserver.sendMessage(msguser.msghandle, command.msg, function (success, msg) { parent.parent.msgserver.sendMessage(msguser.msghandle, command.msg, domain, function (success, msg) {
if (success) { if (success) {
displayNotificationMessage("Message succesfuly sent.", null, null, null, 32); displayNotificationMessage("Message succesfuly sent.", null, null, null, 32);
} else { } else {
@ -6701,6 +6701,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if ((command.service == 4) && ((parent.parent.msgserver.providers & 4) != 0)) { handle = 'discord:' + command.handle; } if ((command.service == 4) && ((parent.parent.msgserver.providers & 4) != 0)) { handle = 'discord:' + command.handle; }
if ((command.service == 8) && ((parent.parent.msgserver.providers & 8) != 0)) { handle = 'xmpp:' + command.handle; } if ((command.service == 8) && ((parent.parent.msgserver.providers & 8) != 0)) { handle = 'xmpp:' + command.handle; }
if ((command.service == 16) && ((parent.parent.msgserver.providers & 16) != 0)) { handle = parent.parent.msgserver.callmebotUrlToHandle(command.handle); } if ((command.service == 16) && ((parent.parent.msgserver.providers & 16) != 0)) { handle = parent.parent.msgserver.callmebotUrlToHandle(command.handle); }
if ((command.service == 32) && ((parent.parent.msgserver.providers & 32) != 0)) { handle = 'pushover:' + command.handle; }
if (handle == null) return; if (handle == null) return;
// Send a verification message // Send a verification message
@ -6844,9 +6845,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
if ((parent.parent.msgserver.providers & 2) != 0) { r.push("Usage: MSG \"signal:UserHandle\" \"Message\"."); } if ((parent.parent.msgserver.providers & 2) != 0) { r.push("Usage: MSG \"signal:UserHandle\" \"Message\"."); }
if ((parent.parent.msgserver.providers & 4) != 0) { r.push("Usage: MSG \"discord:Username#0000\" \"Message\"."); } if ((parent.parent.msgserver.providers & 4) != 0) { r.push("Usage: MSG \"discord:Username#0000\" \"Message\"."); }
if ((parent.parent.msgserver.providers & 8) != 0) { r.push("Usage: MSG \"xmpp:username@server.com\" \"Message\"."); } if ((parent.parent.msgserver.providers & 8) != 0) { r.push("Usage: MSG \"xmpp:username@server.com\" \"Message\"."); }
if ((parent.parent.msgserver.providers & 32) != 0) { r.push("Usage: MSG \"pushover:userkey\" \"Message\"."); }
cmdData.result = r.join('\r\n'); cmdData.result = r.join('\r\n');
} else { } else {
parent.parent.msgserver.sendMessage(cmdData.cmdargs['_'][0], cmdData.cmdargs['_'][1], function (status, msg) { parent.parent.msgserver.sendMessage(cmdData.cmdargs['_'][0], cmdData.cmdargs['_'][1], domain, function (status, msg) {
if (typeof msg == 'string') { if (typeof msg == 'string') {
try { ws.send(JSON.stringify({ action: 'serverconsole', value: status ? ('Success: ' + msg) : ('Failed: ' + msg), tag: cmdData.command.tag })); } catch (ex) { } try { ws.send(JSON.stringify({ action: 'serverconsole', value: status ? ('Success: ' + msg) : ('Failed: ' + msg), tag: cmdData.command.tag })); } catch (ex) { }
} else { } else {

View File

@ -37,6 +37,7 @@
"sample-config-advanced.json" "sample-config-advanced.json"
], ],
"dependencies": { "dependencies": {
"@yetzt/nedb": "^1.8.0",
"archiver": "^5.3.1", "archiver": "^5.3.1",
"body-parser": "^1.19.0", "body-parser": "^1.19.0",
"cbor": "~5.2.0", "cbor": "~5.2.0",
@ -48,8 +49,8 @@
"ipcheck": "^0.1.0", "ipcheck": "^0.1.0",
"minimist": "^1.2.5", "minimist": "^1.2.5",
"multiparty": "^4.2.1", "multiparty": "^4.2.1",
"@yetzt/nedb": "^1.8.0",
"node-forge": "^1.0.0", "node-forge": "^1.0.0",
"node-pushover": "^1.0.0",
"ws": "^5.2.3", "ws": "^5.2.3",
"yauzl": "^2.10.0" "yauzl": "^2.10.0"
}, },

View File

@ -11986,6 +11986,7 @@
if ((serverinfo.userMsgProviders & 4) != 0) { y += '<option value=4>' + "Discord" + '</option>'; } if ((serverinfo.userMsgProviders & 4) != 0) { y += '<option value=4>' + "Discord" + '</option>'; }
if ((serverinfo.userMsgProviders & 8) != 0) { y += '<option value=8>' + "XMPP" + '</option>'; } if ((serverinfo.userMsgProviders & 8) != 0) { y += '<option value=8>' + "XMPP" + '</option>'; }
if ((serverinfo.userMsgProviders & 16) != 0) { y += '<option value=16>' + "CallMeBot" + '</option>'; } if ((serverinfo.userMsgProviders & 16) != 0) { y += '<option value=16>' + "CallMeBot" + '</option>'; }
if ((serverinfo.userMsgProviders & 32) != 0) { y += '<option value=32>' + "Pushover" + '</option>'; }
y += '</select>'; y += '</select>';
x += '<table><tr><td>' + "Service" + '<td>' + y; x += '<table><tr><td>' + "Service" + '<td>' + y;
x += '<tr><td>' + "Handle" + '<td><input maxlength=1024 style=width:160px;margin-left:8px id=d2handleinput onKeyUp=account_manageMessagingValidate() onkeypress="if (event.key==\'Enter\') account_manageMessagingValidate(1)">'; x += '<tr><td>' + "Handle" + '<td><input maxlength=1024 style=width:160px;margin-left:8px id=d2handleinput onKeyUp=account_manageMessagingValidate() onkeypress="if (event.key==\'Enter\') account_manageMessagingValidate(1)">';
@ -12004,6 +12005,7 @@
if (Q('d2serviceselect').value == 4) { Q('d2handleinput')['placeholder'] = "Username:0000"; } if (Q('d2serviceselect').value == 4) { Q('d2handleinput')['placeholder'] = "Username:0000"; }
else if (Q('d2serviceselect').value == 8) { Q('d2handleinput')['placeholder'] = "username@server.com"; } else if (Q('d2serviceselect').value == 8) { Q('d2handleinput')['placeholder'] = "username@server.com"; }
else if (Q('d2serviceselect').value == 16) { Q('d2handleinput')['placeholder'] = "https://api.callmebot.com/..."; } else if (Q('d2serviceselect').value == 16) { Q('d2handleinput')['placeholder'] = "https://api.callmebot.com/..."; }
else if (Q('d2serviceselect').value == 32) { Q('d2handleinput')['placeholder'] = "User key"; }
else { Q('d2handleinput')['placeholder'] = "Username"; } else { Q('d2handleinput')['placeholder'] = "Username"; }
var ok = (Q('d2handleinput').value.length > 0); QE('idx_dlgOkButton', ok); if ((x == 1) && ok) { dialogclose(1); } var ok = (Q('d2handleinput').value.length > 0); QE('idx_dlgOkButton', ok); if ((x == 1) && ok) { dialogclose(1); }
} }
@ -15867,6 +15869,7 @@
if ((serverinfo.userMsgProviders & 4) != 0) { y += '<option value=4>' + "Discord" + '</option>'; } if ((serverinfo.userMsgProviders & 4) != 0) { y += '<option value=4>' + "Discord" + '</option>'; }
if ((serverinfo.userMsgProviders & 8) != 0) { y += '<option value=8>' + "XMPP" + '</option>'; } if ((serverinfo.userMsgProviders & 8) != 0) { y += '<option value=8>' + "XMPP" + '</option>'; }
if ((serverinfo.userMsgProviders & 16) != 0) { y += '<option value=16>' + "CallMeBot" + '</option>'; } if ((serverinfo.userMsgProviders & 16) != 0) { y += '<option value=16>' + "CallMeBot" + '</option>'; }
if ((serverinfo.userMsgProviders & 32) != 0) { y += '<option value=32>' + "Pushover" + '</option>'; }
y += '</select>'; y += '</select>';
x += '<table style=margin-top:12px><tr><td>' + "Service" + '<td>' + y; x += '<table style=margin-top:12px><tr><td>' + "Service" + '<td>' + y;
x += '<tr><td>' + "Handle" + '<td><input maxlength=1024 style=width:160px;margin-left:8px id=d2handleinput onKeyUp=p30editMessagingValidate() onkeypress="if (event.key==\'Enter\') p30editMessagingValidate(1)">'; x += '<tr><td>' + "Handle" + '<td><input maxlength=1024 style=width:160px;margin-left:8px id=d2handleinput onKeyUp=p30editMessagingValidate() onkeypress="if (event.key==\'Enter\') p30editMessagingValidate(1)">';
@ -15886,6 +15889,7 @@
if ((toData[0] == 'whatsapp') && (toData.length == 3)) { Q('d2handleinput').value = 'https://api.callmebot.com/whatsapp.php?phone=' + decodeURIComponent(toData[1]) + '&apikey=' + decodeURIComponent(toData[2]); } if ((toData[0] == 'whatsapp') && (toData.length == 3)) { Q('d2handleinput').value = 'https://api.callmebot.com/whatsapp.php?phone=' + decodeURIComponent(toData[1]) + '&apikey=' + decodeURIComponent(toData[2]); }
if ((toData[0] == 'facebook') && (toData.length == 2)) { Q('d2handleinput').value = 'https://api.callmebot.com/facebook/send.php?apikey=' + decodeURIComponent(toData[1]); } if ((toData[0] == 'facebook') && (toData.length == 2)) { Q('d2handleinput').value = 'https://api.callmebot.com/facebook/send.php?apikey=' + decodeURIComponent(toData[1]); }
} }
if (userinfo.msghandle.startsWith('pushover:') && ((serverinfo.userMsgProviders & 32) != 0)) { Q('d2serviceselect').value = 32; Q('d2handleinput').value = userinfo.msghandle.substring(9); }
} }
p30editMessagingValidate(); p30editMessagingValidate();
} }
@ -15898,6 +15902,7 @@
else if (Q('d2serviceselect').value == 4) { Q('d2handleinput')['placeholder'] = "Username:0000"; } else if (Q('d2serviceselect').value == 4) { Q('d2handleinput')['placeholder'] = "Username:0000"; }
else if (Q('d2serviceselect').value == 8) { Q('d2handleinput')['placeholder'] = "username@server.com"; } else if (Q('d2serviceselect').value == 8) { Q('d2handleinput')['placeholder'] = "username@server.com"; }
else if (Q('d2serviceselect').value == 16) { Q('d2handleinput')['placeholder'] = "https://api.callmebot.com/..."; } else if (Q('d2serviceselect').value == 16) { Q('d2handleinput')['placeholder'] = "https://api.callmebot.com/..."; }
else if (Q('d2serviceselect').value == 32) { Q('d2handleinput')['placeholder'] = "User key"; }
else { Q('d2handleinput')['placeholder'] = "Username"; } else { Q('d2handleinput')['placeholder'] = "Username"; }
if (x == 1) { dialogclose(1); } if (x == 1) { dialogclose(1); }
} }