From 6b8acc16753f430567023bf55668c1d33db5e36a Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Mon, 31 Oct 2022 14:28:10 -0700 Subject: [PATCH] ntfy improvements. --- meshcentral-config-schema.json | 38 ++++++++++++++++++++++++++++++++++ meshmessaging.js | 3 ++- meshuser.js | 3 +++ views/default.handlebars | 5 +++-- 4 files changed, 46 insertions(+), 3 deletions(-) diff --git a/meshcentral-config-schema.json b/meshcentral-config-schema.json index 38526f89..ccdd562a 100644 --- a/meshcentral-config-schema.json +++ b/meshcentral-config-schema.json @@ -1379,6 +1379,44 @@ "token": { "type": "string", "description": "A Discord bot token that MeshCentral will use to login to Discord." } }, "required": [ "token" ] + }, + "xmpp": { + "type": "object", + "description": "Configure XMPP messaging system", + "properties": { + "service": { "type": "string", "description": "Host name of the XMPP server." }, + "credentials": { + "type": "object", + "description": "Login credentials for the XMPP server.", + "properties": { + "username": { "type": "string" }, + "password": { "type": "string" } + } + } + }, + "required": [ "credentials" ] + }, + "callmebot": { + "type": "boolean", + "default": false, + "description": "Enabled CallMeBot integration support." + }, + "pushover": { + "type": "object", + "description": "Configure Pushover messaging system", + "properties": { + "token": { "type": "string", "description": "A Pushover application token that MeshCentral will use to login." } + }, + "required": [ "token" ] + }, + "ntfy": { + "type": [ "boolean", "object" ], + "default": false, + "properties": { + "host": { "type": "string", "description": "Host name of the ntfy server." }, + "userurl": { "type": "string", "description": "A URL given to users to help them setup this service." } + }, + "description": "Enabled ntfy.sh integration support." } } } diff --git a/meshmessaging.js b/meshmessaging.js index 7390912a..c52adf3a 100644 --- a/meshmessaging.js +++ b/meshmessaging.js @@ -292,7 +292,8 @@ module.exports.CreateServer = function (parent) { 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 if ((to.startsWith('ntfy:')) && (obj.ntfyClient != null)) { // ntfy - const req = require('https').request(new URL('https://ntfy.sh/' + encodeURIComponent(to.substring(5))), { method: 'POST' }, function (res) { if (func != null) { func(true); } }); + const url = 'https://' + (((typeof parent.config.messaging.ntfy == 'object') && (typeof parent.config.messaging.ntfy.host == 'string')) ? parent.config.messaging.ntfy.host : 'ntfy.sh') + '/' + encodeURIComponent(to.substring(5)); + const req = require('https').request(new URL(url), { method: 'POST' }, function (res) { if (func != null) { func(true); } }); req.on('error', function (err) { if (func != null) { func(false); } }); req.end(msg); } else { diff --git a/meshuser.js b/meshuser.js index 4765f303..c06121ec 100644 --- a/meshuser.js +++ b/meshuser.js @@ -579,6 +579,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use serverinfo.userMsgProviders = parent.parent.msgserver.providers; if (parent.parent.msgserver.discordUrl != null) { serverinfo.discordUrl = parent.parent.msgserver.discordUrl; } } + if ((typeof parent.parent.config.messaging == 'object') && (typeof parent.parent.config.messaging.ntfy == 'object') && (typeof parent.parent.config.messaging.ntfy.userurl == 'string')) { // nfty user url + serverinfo.userMsgNftyUrl = parent.parent.config.messaging.ntfy.userurl; + } // Build the mobile agent URL, this is used to connect mobile devices var agentServerName = parent.getWebServerName(domain, req); diff --git a/views/default.handlebars b/views/default.handlebars index 25437763..9130f56a 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -11995,7 +11995,8 @@ if (serverinfo.discordUrl) { x += ''; } x += ''; x += ''; - x += ''; + console.log(serverinfo.userMsgNftyUrl); + x += ''; setDialogMode(2, "Messaging Notifications", 3, account_manageMessagingAdd, x, 'verifyMessaging'); Q('d2handleinput').focus(); account_manageMessagingValidate(); @@ -15884,7 +15885,7 @@ if (serverinfo.discordUrl) { x += '' } x += ''; x += ''; - x += ''; + x += ''; setDialogMode(2, "Messaging Notifications", 3, p30editMessagingEx, x, 'verifyMessaging'); Q('d2handleinput').focus(); if (userinfo.msghandle) {