From 59f1463a3f7af3fe35a23ab8fc0ac06d61d36a5d Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Fri, 13 Mar 2020 20:39:21 -0700 Subject: [PATCH] Email based 2FA almost completed. --- meshmail.js | 16 ++++++++ package.json | 2 +- pluginHandler.js | 5 +-- views/login-mobile.handlebars | 26 +++++++++++-- views/login.handlebars | 20 +++++++++- webserver.js | 69 +++++++++++++++++++++++++++++++---- 6 files changed, 121 insertions(+), 17 deletions(-) diff --git a/meshmail.js b/meshmail.js index f4dfdb03..05d0ae72 100644 --- a/meshmail.js +++ b/meshmail.js @@ -43,11 +43,13 @@ module.exports.CreateMeshMail = function (parent) { // Set default mail templates // You can override these by placing a file with the same name in "meshcentral-data/mail" // If the server hash many domains, just add the domainid to the file like this: 'account-check-customer1.html', 'mesh-invite-customer1.txt'. + obj.mailTemplates['account-login.html'] = '[[[SERVERNAME]]] - Account Login\r\n
[[[SERVERNAME]]] - Account Login

Your login token is: [[[TOKEN]]]

This token can only be used once and is valid for 5 minutes.

'; obj.mailTemplates['account-invite.html'] = '[[[SERVERNAME]]] - Account Invitation\r\n
[[[SERVERNAME]]] - Account Invitation

An account was created for you on server [[[SERVERNAME]]], you can access it now with:

   Username: [[[ACCOUNTNAME]]]
   Password: [[[PASSWORD]]]

Best regards,
[[[USERNAME]]]
'; obj.mailTemplates['account-check.html'] = '[[[SERVERNAME]]] - Email Verification\r\n
[[[SERVERNAME]]] - Verification

Hi [[[USERNAME]]], [[[SERVERNAME]]] is requesting email verification, click on the following link to complete the process.

Click here to verify your e-mail address.

If you did not initiate this request, please ignore this mail.
'; obj.mailTemplates['account-reset.html'] = '[[[SERVERNAME]]] - Account Reset\r\n
[[[SERVERNAME]]] - Verification

Hi [[[USERNAME]]], [[[SERVERNAME]]] is requesting an account password reset, click on the following link to complete the process.

Click here to reset your account password.

If you did not initiate this request, please ignore this mail.
'; obj.mailTemplates['mesh-invite.html'] = '[[[SERVERNAME]]] - Invitation\r\n
[[[SERVERNAME]]] - Agent Installation
[[[AREA-NAME]]]

Hello [[[NAME]]],

[[[/AREA-NAME]]]

User [[[USERNAME]]] on server [[[SERVERNAME]]] is requesting you to install software to start a remote control session.

[[[AREA-MSG]]]

Message: [[[MSG]]]

[[[/AREA-MSG]]][[[AREA-WINDOWS]]]

Click here to download the MeshAgent for Windows.

[[[/AREA-WINDOWS]]][[[AREA-OSX]]]

Click here to download the MeshAgent for Apple OSX.

[[[/AREA-OSX]]][[[AREA-LINUX]]]

For Linux, cut & paste the following in a terminal to install the agent:

wget -q "[[[SERVERURL]]]/meshagents?script=1" --no-check-certificate -O ./meshinstall.sh && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh [[[SERVERURL]]] \'[[[MESHIDHEX]]]\'

[[[/AREA-LINUX]]][[[AREA-LINK]]]

To install the software, click here and follow the instructions.

[[[/AREA-LINK]]]

If you did not initiate this request, please ignore this mail.

Best regards,
[[[USERNAME]]]
'; + obj.mailTemplates['account-login.txt'] = '[[[SERVERNAME]]] - Account Login\r\nYour login token is: [[[TOKEN]]]\r\n\r\nThis token can only be used once and is valid for 5 minutes.'; obj.mailTemplates['account-invite.txt'] = '[[[SERVERNAME]]] - Account Invitation\r\nAn account was created for you on server [[[SERVERNAME]]] ([[[SERVERURL]]]/), you can access it now with username \"[[[ACCOUNTNAME]]]\" and password \"[[[PASSWORD]]]\".\r\n\r\nBest regards,\r\n[[[USERNAME]]]'; obj.mailTemplates['account-check.txt'] = '[[[SERVERNAME]]] - Email Verification\r\nHi [[[USERNAME]]], [[[SERVERNAME]]] ([[[SERVERURL]]]) is performing an e-mail verification. Nagivate to the following link to complete the process:\r\n\r\n[[[SERVERURL]]]/checkmail?c=[[[COOKIE]]]\r\n\r\nIf you did not initiate this request, please ignore this mail.\r\n'; obj.mailTemplates['account-reset.txt'] = '[[[SERVERNAME]]] - Account Reset\r\nHi [[[USERNAME]]], [[[SERVERNAME]]] ([[[SERVERURL]]]) is requesting an account password reset. Nagivate to the following link to complete the process:\r\n\r\n[[[SERVERURL]]]/checkmail?c=[[[COOKIE]]]\r\n\r\nIf you did not initiate this request, please ignore this mail.'; @@ -133,6 +135,20 @@ module.exports.CreateMeshMail = function (parent) { sendNextMail(); }; + // Send account login mail / 2 factor token + obj.sendAccountLoginMail = function (domain, email, token) { + var template = getTemplateEx('account-login', domain); + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null) || (parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) return; // If the server name is not set, invitation not possible. + + // Set all the options. + var options = { email: email, servername: domain.title ? domain.title : 'MeshCentral', token: token }; + + // Send the email + console.log(options); + obj.pendingMails.push({ to: email, from: parent.config.smtp.from, subject: mailReplacements(template.htmlSubject, domain, options), text: mailReplacements(template.txt, domain, options), html: mailReplacements(template.html, domain, options) }); + sendNextMail(); + }; + // Send account invitation mail obj.sendAccountInviteMail = function (domain, username, accountname, email, password) { var template = getTemplateEx('account-invite', domain); diff --git a/package.json b/package.json index f369e8fc..14d8965f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.5.0-e", + "version": "0.5.0-f", "keywords": [ "Remote Management", "Intel AMT", diff --git a/pluginHandler.js b/pluginHandler.js index 4f871d9b..3d79c421 100644 --- a/pluginHandler.js +++ b/pluginHandler.js @@ -507,10 +507,9 @@ module.exports.pluginHandler = function (parent) { obj.removePlugin = function (id, func) { parent.db.getPlugin(id, function (err, docs) { var plugin = docs[0]; - var rimraf = null; - try { rimraf = require('rimraf'); } catch (ex) { } + var rimraf = require('rimraf'); let pluginPath = obj.parent.path.join(obj.pluginPath, plugin.shortName); - if (rimraf) rimraf.sync(pluginPath); + rimraf.sync(pluginPath); parent.db.deletePlugin(id, func); delete obj.plugins[plugin.shortName]; }); diff --git a/views/login-mobile.handlebars b/views/login-mobile.handlebars index bd47fcdc..fa900c5a 100644 --- a/views/login-mobile.handlebars +++ b/views/login-mobile.handlebars @@ -164,7 +164,10 @@
-
+
+ + +
@@ -238,7 +241,7 @@ -