mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-11-22 04:33:16 +03:00
Completed Discord integration (#4651)
This commit is contained in:
parent
6f234f83fc
commit
3761a93961
@ -681,6 +681,7 @@
|
||||
<Folder Include="typings\globals\ajv\" />
|
||||
<Folder Include="typings\globals\async\" />
|
||||
<Folder Include="typings\globals\axios\" />
|
||||
<Folder Include="typings\globals\big-integer\" />
|
||||
<Folder Include="typings\globals\busboy\" />
|
||||
<Folder Include="typings\globals\connect-redis\" />
|
||||
<Folder Include="typings\globals\cookie-session\" />
|
||||
@ -695,6 +696,7 @@
|
||||
<Folder Include="typings\globals\he\" />
|
||||
<Folder Include="typings\globals\hooker\" />
|
||||
<Folder Include="typings\globals\http-errors\" />
|
||||
<Folder Include="typings\globals\ip\" />
|
||||
<Folder Include="typings\globals\is-plain-object\" />
|
||||
<Folder Include="typings\globals\jsbn\" />
|
||||
<Folder Include="typings\globals\klaw\" />
|
||||
@ -711,6 +713,7 @@
|
||||
<Folder Include="typings\globals\once\" />
|
||||
<Folder Include="typings\globals\passport\" />
|
||||
<Folder Include="typings\globals\pg-pool\" />
|
||||
<Folder Include="typings\globals\rx-lite\" />
|
||||
<Folder Include="typings\globals\split2\" />
|
||||
<Folder Include="typings\globals\sprintf-js\" />
|
||||
<Folder Include="typings\globals\sqlite3\" />
|
||||
@ -724,6 +727,7 @@
|
||||
<TypeScriptCompile Include="typings\globals\ajv\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\async\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\axios\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\big-integer\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\busboy\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\connect-redis\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\cookie-session\index.d.ts" />
|
||||
@ -738,6 +742,7 @@
|
||||
<TypeScriptCompile Include="typings\globals\he\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\hooker\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\http-errors\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\ip\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\is-plain-object\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\jsbn\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\klaw\index.d.ts" />
|
||||
@ -754,6 +759,7 @@
|
||||
<TypeScriptCompile Include="typings\globals\once\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\passport\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\pg-pool\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\rx-lite\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\split2\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\sprintf-js\index.d.ts" />
|
||||
<TypeScriptCompile Include="typings\globals\sqlite3\index.d.ts" />
|
||||
|
@ -6,7 +6,7 @@ MeshCentral supports messaging platforms so that users can register a messaging
|
||||
|
||||
## Telegram Setup
|
||||
|
||||
Currently only Telegram is supported. You will need to provide MeshCentral with the necessary login information so that MeshCentral can authenticate and connect to the Telegram servers and start sending notifications. For Telegram, both user and bot login is supported with bot login being the more typical way to go. The configuration in the config.json for a bot login looks like this:
|
||||
For Telegram integration, you will need to provide MeshCentral with the necessary login information so that MeshCentral can authenticate and connect to the Telegram servers and start sending notifications. For Telegram, both user and bot login is supported with bot login being the more typical way to go. The configuration in the config.json for a bot login looks like this:
|
||||
|
||||
```json
|
||||
{
|
||||
@ -59,6 +59,27 @@ MeshCentral Telegram client is bot connected.
|
||||
|
||||
Note the last line, indicating it's connected as a bot.
|
||||
|
||||
## Discord Setup
|
||||
|
||||
For Discord integration, you need to provide MeshCentral with a bot application token so that MeshCentral can login and send notifications to users. The Discord bot will need to be joined to one or more Discord servers and users will need to join at at least one Discord server that is in common with the bot to receive notifications.
|
||||
|
||||
There are many tutorials online on how to create a Discord bot and get the login token. For example follow the [two first sections of this tutorial](https://www.freecodecamp.org/news/create-a-discord-bot-with-javascript-nodejs/). The "How to Create a Discord Bot Account" section will show how to create a bot and get the token, the "How to Invite Your Bot to Join a Server" section shows how to join the bot to a Discord server.
|
||||
|
||||
Once you have the Discord bot login token, the config.json Discord configuration looks like this:
|
||||
|
||||
```json
|
||||
{
|
||||
"messaging": {
|
||||
"discord": {
|
||||
"serverurl": "https://discord.gg/xxxxxxxxx",
|
||||
"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Once users will need to join the same Discord server as the bot, the optional "serverurl" can be used to give the users a URL link to join the server, this can be a server invitation link or some other URL with instructions.
|
||||
|
||||
## User Setup
|
||||
|
||||
Once a messaging system is setup with MeshCentral, users will be able to register their handle and verify that they own that account by typing in a 6 digit code.
|
||||
|
@ -1370,6 +1370,15 @@
|
||||
"apihash": { "type": "string" },
|
||||
"session": { "type": "string" }
|
||||
}
|
||||
},
|
||||
"discord": {
|
||||
"type": "object",
|
||||
"description": "Configure Discord messaging system",
|
||||
"properties": {
|
||||
"serverurl": { "type": "string", "format": "uri", "description": "An optional HTTP link to the discord server the user must join to get notifications." },
|
||||
"token": { "type": "string", "description": "A Discord bot token that MeshCentral will use to login to Discord." }
|
||||
},
|
||||
"required": [ "token" ]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ module.exports.CreateServer = function (parent) {
|
||||
obj.providers = 0; // 1 = Telegram, 2 = Signal, 4 = Discord
|
||||
obj.telegramClient = null;
|
||||
obj.discordClient = null;
|
||||
obj.discordUrl = null;
|
||||
|
||||
// Telegram client setup
|
||||
if (parent.config.messaging.telegram) {
|
||||
@ -93,7 +94,6 @@ module.exports.CreateServer = function (parent) {
|
||||
if (parent.config.messaging.discord) {
|
||||
// Validate Discord configuration values
|
||||
var discordOK = true;
|
||||
if (typeof parent.config.messaging.discord.inviteurl != 'string') { console.log('Invalid or missing Discord invite URL.'); discordOK = false; }
|
||||
if (typeof parent.config.messaging.discord.token != 'string') { console.log('Invalid or missing Discord token.'); discordOK = false; }
|
||||
|
||||
if (discordOK) {
|
||||
@ -113,6 +113,7 @@ module.exports.CreateServer = function (parent) {
|
||||
discordClient.on('ready', function() {
|
||||
console.log(`MeshCentral Discord client is connected as ${discordClient.user.tag}!`);
|
||||
obj.discordClient = discordClient;
|
||||
obj.discordUrl = parent.config.messaging.discord.serverurl;
|
||||
obj.providers += 4; // Enable Discord messaging
|
||||
});
|
||||
|
||||
|
@ -575,7 +575,10 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
|
||||
if (domain.passwordrequirements.lock2factor == true) { serverinfo.lock2factor = true; } // Indicate 2FA change are not allowed
|
||||
if (typeof domain.passwordrequirements.maxfidokeys == 'number') { serverinfo.maxfidokeys = domain.passwordrequirements.maxfidokeys; }
|
||||
}
|
||||
if (parent.parent.msgserver != null) { serverinfo.userMsgProviders = parent.parent.msgserver.providers; }
|
||||
if (parent.parent.msgserver != null) { // Setup messaging providers information
|
||||
serverinfo.userMsgProviders = parent.parent.msgserver.providers;
|
||||
if (parent.parent.msgserver.discordUrl != null) { serverinfo.discordUrl = parent.parent.msgserver.discordUrl; }
|
||||
}
|
||||
|
||||
// Build the mobile agent URL, this is used to connect mobile devices
|
||||
var agentServerName = parent.getWebServerName(domain, req);
|
||||
|
10
package.json
10
package.json
@ -37,19 +37,27 @@
|
||||
"sample-config-advanced.json"
|
||||
],
|
||||
"dependencies": {
|
||||
"@yetzt/nedb": "^1.8.0",
|
||||
"archiver": "^5.3.1",
|
||||
"body-parser": "^1.19.0",
|
||||
"cbor": "~5.2.0",
|
||||
"compression": "^1.7.4",
|
||||
"cookie-session": "^1.4.0",
|
||||
"discord.js": "^14.6.0",
|
||||
"express": "^4.17.0",
|
||||
"express-handlebars": "^5.3.5",
|
||||
"express-ws": "^4.0.0",
|
||||
"input": "^1.0.1",
|
||||
"ipcheck": "^0.1.0",
|
||||
"loadavg-windows": "^1.1.1",
|
||||
"minimist": "^1.2.5",
|
||||
"multiparty": "^4.2.1",
|
||||
"@yetzt/nedb": "^1.8.0",
|
||||
"mysql": "^2.18.1",
|
||||
"node-forge": "^1.0.0",
|
||||
"node-windows": "^0.1.4",
|
||||
"otplib": "^10.2.3",
|
||||
"ssh2": "^1.11.0",
|
||||
"telegram": "^2.13.6",
|
||||
"ws": "^5.2.3",
|
||||
"yauzl": "^2.10.0"
|
||||
},
|
||||
|
@ -616,10 +616,14 @@
|
||||
"url": "http://example.com/sms.ashx?phone={{phone}}&message={{message}}"
|
||||
},
|
||||
"_messaging": {
|
||||
"telegram": {
|
||||
"_telegram": {
|
||||
"apiid": 0,
|
||||
"apihash": "hexBalue",
|
||||
"session": "base64Value"
|
||||
"apihash": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
|
||||
"session": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
},
|
||||
"_discord": {
|
||||
"serverurl": "https://discord.gg/xxxxxxxxx",
|
||||
"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx.xxxxxxxxxxxxxxxxxxxxxxxxxxxx"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11981,7 +11981,7 @@
|
||||
} else {
|
||||
x = '<table style=width:100%><tr><td style=width:56px;vertical-align:top><img src="images/messaging40.png" style=padding:8px>';
|
||||
x += '<td>' + "Enter your messaging service and handle. Once verified, this server can send you login verification and other notifications." + '<br /><br />';
|
||||
var y = '<select id=d2serviceselect style=width:160px;margin-left:8px>';
|
||||
var y = '<select id=d2serviceselect style=width:160px;margin-left:8px onchange=account_manageMessagingValidate()>';
|
||||
if ((serverinfo.userMsgProviders & 1) != 0) { y += '<option value=1>' + "Telegram" + '</option>'; }
|
||||
if ((serverinfo.userMsgProviders & 2) != 0) { y += '<option value=2>' + "Signal Messenger" + '</option>'; }
|
||||
if ((serverinfo.userMsgProviders & 4) != 0) { y += '<option value=4>' + "Discord" + '</option>'; }
|
||||
@ -11989,13 +11989,18 @@
|
||||
x += '<table><tr><td>' + "Service" + '<td>' + y;
|
||||
x += '<tr><td>' + "Handle" + '<td><input maxlength=64 style=width:160px;margin-left:8px id=d2handleinput onKeyUp=account_manageMessagingValidate() onkeypress="if (event.key==\'Enter\') account_manageMessagingValidate(1)">';
|
||||
x += '</table>';
|
||||
if (serverinfo.discordUrl) { x += '<div id=d2discordurl style=display:none><br /><a href=' + serverinfo.discordUrl + ' target="_discord">' + "Join this Discord server to receive notifications." + '</a></div>' }
|
||||
setDialogMode(2, "Messaging Notifications", 3, account_manageMessagingAdd, x, 'verifyMessaging');
|
||||
Q('d2handleinput').focus();
|
||||
account_manageMessagingValidate();
|
||||
}
|
||||
}
|
||||
|
||||
function account_manageMessagingValidate(x) { var ok = (Q('d2handleinput').value.length > 0); QE('idx_dlgOkButton', ok); if ((x == 1) && ok) { dialogclose(1); } }
|
||||
function account_manageMessagingValidate(x) {
|
||||
if (serverinfo.discordUrl) { QV('d2discordurl', Q('d2serviceselect').value == 4); }
|
||||
if (Q('d2serviceselect').value == 4) { Q('d2handleinput')['placeholder'] = "Username:0000"; } else { Q('d2handleinput')['placeholder'] = "Username"; }
|
||||
var ok = (Q('d2handleinput').value.length > 0); QE('idx_dlgOkButton', ok); if ((x == 1) && ok) { dialogclose(1); }
|
||||
}
|
||||
function account_manageMessagingAdd() { if (Q('d2handleinput').value.length == 0) return; QE('d2handleinput', false); meshserver.send({ action: 'verifyMessaging', service: Q('d2serviceselect').value, handle: Q('d2handleinput').value }); }
|
||||
function account_manageMessagingConfirm(b, tag) { meshserver.send({ action: 'confirmMessaging', code: Q('d2phoneCodeInput').value, cookie: tag }); }
|
||||
function account_manageMessagingRemove() { if (Q('d2delPhone').checked) { meshserver.send({ action: 'removeMessaging' }); } }
|
||||
@ -15850,9 +15855,8 @@
|
||||
function p30editMessaging() {
|
||||
if (xxdialogMode) return;
|
||||
var x = '<table style=width:100%><tr><td style=width:56px;vertical-align:top><img src="images/messaging40.png" style=padding:8px>';
|
||||
x += '<td style=width:100%>' + "Messaging account for this user." + '<br />' + "Leave blank for none.";
|
||||
|
||||
var y = '<select id=d2serviceselect style=width:160px;margin-left:8px>';
|
||||
x += '<td style=width:100%>' + "Messaging account for this user.";
|
||||
var y = '<select id=d2serviceselect style=width:160px;margin-left:8px onchange=p30editMessagingValidate()><option value=0>' + "None" + '</option>';
|
||||
if ((serverinfo.userMsgProviders & 1) != 0) { y += '<option value=1>' + "Telegram" + '</option>'; }
|
||||
if ((serverinfo.userMsgProviders & 2) != 0) { y += '<option value=2>' + "Signal Messenger" + '</option>'; }
|
||||
if ((serverinfo.userMsgProviders & 4) != 0) { y += '<option value=4>' + "Discord" + '</option>'; }
|
||||
@ -15860,18 +15864,26 @@
|
||||
x += '<table style=margin-top:12px><tr><td>' + "Service" + '<td>' + y;
|
||||
x += '<tr><td>' + "Handle" + '<td><input maxlength=64 style=width:160px;margin-left:8px id=d2handleinput onKeyUp=p30editMessagingValidate() onkeypress="if (event.key==\'Enter\') p30editMessagingValidate(1)">';
|
||||
x += '</table>';
|
||||
|
||||
if (serverinfo.discordUrl) { x += '<div id=d2discordurl style=display:none><br /><a href=' + serverinfo.discordUrl + ' target="_discord">' + "Join this Discord server to receive notifications." + '</a></div>' }
|
||||
setDialogMode(2, "Messaging Notifications", 3, p30editMessagingEx, x, 'verifyMessaging');
|
||||
Q('d2handleinput').focus();
|
||||
if (userinfo.msghandle) {
|
||||
if (userinfo.msghandle.startsWith('telegram:') && ((serverinfo.userMsgProviders & 1) != 0)) { Q('d2serviceselect').value = 1; Q('d2handleinput').value = userinfo.msghandle.substring(10); }
|
||||
if (userinfo.msghandle.startsWith('discord:') && ((serverinfo.userMsgProviders & 4) != 0)) { Q('d2serviceselect').value = 4; Q('d2handleinput').value = userinfo.msghandle.substring(8); }
|
||||
}
|
||||
p30editMessagingValidate();
|
||||
}
|
||||
|
||||
function p30editMessagingValidate(x) { if (x == 1) { dialogclose(1); } }
|
||||
function p30editMessagingValidate(x) {
|
||||
QE('d2handleinput', Q('d2serviceselect').value != 0);
|
||||
if (serverinfo.discordUrl) { QV('d2discordurl', Q('d2serviceselect').value == 4); }
|
||||
if (x == 1) { dialogclose(1); }
|
||||
}
|
||||
|
||||
// Send to the server the user's messaging account
|
||||
function p30editMessagingEx() {
|
||||
var handle = null;
|
||||
if (Q('d2handleinput').value == '') { handle = ''; }
|
||||
if ((Q('d2handleinput').value == '') || (Q('d2serviceselect').value == 0)) { handle = ''; }
|
||||
else if (Q('d2serviceselect').value == 1) { handle = 'telegram:@' + Q('d2handleinput').value; }
|
||||
else if (Q('d2serviceselect').value == 4) { handle = 'discord:' + Q('d2handleinput').value; }
|
||||
if (handle != null) { meshserver.send({ action: 'edituser', id: currentUser._id, msghandle: handle }); }
|
||||
|
Loading…
Reference in New Issue
Block a user