diff --git a/agents/meshagent_pi b/agents/meshagent_pi index 867f41a3..4057ea86 100644 Binary files a/agents/meshagent_pi and b/agents/meshagent_pi differ diff --git a/meshcentral.js b/meshcentral.js index f2b6e43a..7d3e5e84 100644 --- a/meshcentral.js +++ b/meshcentral.js @@ -460,9 +460,8 @@ function CreateMeshCentralServer(config, args) { // Setup email server if ((obj.config.smtp != null) && (obj.config.smtp.host != null) && (obj.config.smtp.from != null)) { - obj.mailserver = require('./meshmail.js').CreateMeshMain(obj); + obj.mailserver = require('./meshmail.js').CreateMeshMail(obj); obj.mailserver.verify(); - //obj.mailserver.sendMail('ylian.saint-hilaire@intel.com', 'Test Subject', 'This is a sample test', 'This is a sample html test'); } // Start periodic maintenance diff --git a/meshmail.js b/meshmail.js index 96ba7e3a..11370a33 100644 --- a/meshmail.js +++ b/meshmail.js @@ -15,7 +15,7 @@ "use strict"; // Construct a MeshAgent object, called upon connection -module.exports.CreateMeshMain = function (parent) { +module.exports.CreateMeshMail = function (parent) { var obj = {}; obj.pendingMails = []; obj.parent = parent; @@ -35,9 +35,9 @@ module.exports.CreateMeshMain = function (parent) { const accountResetMailText = '[[[SERVERNAME]]] - Account Reset\r\n\r\nHi [[[USERNAME]]], [[[SERVERNAME]]] ([[[SERVERURL]]]) is requesting an account password reset. Nagivate to the following link to complete the process: [[[CALLBACKURL]]]\r\nIf you did not initiate this request, please ignore this mail.\r\n'; // Default account invite mail - const accountInviteSubject = '[[[SERVERNAME]]] - Agent Installation Invitation'; - const accountInviteMailHtml = '
[[[SERVERNAME]]] - Agent Installation

User [[[USERNAME]]] on server [[[SERVERNAME]]] is requesting that you install a remote management agent. WARNING: this will allow the requester to take control of your computer. If you wish to do this, click on the following link to download the agent.

Click here to download the MeshAgent for Windows.

If you did not know about this request, please ignore this mail.
'; - const accountInviteMailText = '[[[SERVERNAME]]] - Agent Installation Invitation\r\n\r\nUser [[[USERNAME]]] on server [[[SERVERNAME]]] ([[[SERVERURL]]]) is requesting you install a remote management agent. WARNING: This will allow the requester to take control of your computer. If you wish to do this, click on the following link to download the agent: [[[CALLBACKURL]]]\r\nIf you do not know about this request, please ignore this mail.\r\n'; + const accountInviteSubject = '[[[SERVERNAME]]] - Invitation'; + const accountInviteMailHtml = '
[[[SERVERNAME]]] - Agent Installation

[[[INTROHTML]]]User [[[USERNAME]]] on server [[[SERVERNAME]]] is requesting you to download the following software to start the remote control session.

[[[MSGHTML]]][[[AGENTHTML]]]

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

Best regards,
[[[USERNAME]]]
'; + const accountInviteMailText = '[[[SERVERNAME]]] - Agent Installation Invitation\r\n\r\n[[[INTROTEXT]]]User [[[USERNAME]]] on server [[[SERVERNAME]]] ([[[SERVERURL]]]) is requesting you to download the following software to start the remote control session. [[[MSGTEXT]]][[[AGENTTEXT]]]If you did not initiate this request, please ignore this mail.\r\n\r\nBest regards,\r\n[[[USERNAME]]]\r\n'; function EscapeHtml(x) { if (typeof x == "string") return x.replace(/&/g, '&').replace(/>/g, '>').replace(//g, '>').replace(/').replace(/\n/g, '').replace(/\t/g, '  '); if (typeof x == "boolean") return x; if (typeof x == "number") return x; } @@ -59,10 +59,25 @@ module.exports.CreateMeshMain = function (parent) { url = 'http' + ((obj.parent.args.notls == null) ? 's' : '') + '://' + domain.dns + ':' + obj.parent.args.port + domain.url; } if (options) { - if (options.cookie != null) { text = text.split('[[[CALLBACKURL]]]').join(url + 'checkmail?c=' + options.cookie); } - if (options.meshid != null) { text = text.split('[[[CALLBACKURL]]]').join(url + 'meshagents?id=3&meshid=' + options.meshid.split('/')[2] + '&tag=mailto:' + EscapeHtml(email)); } + if (options.cookie == null) { options.cookie = ''; } + if (options.agentlinkhtml == null) { options.agentlinkhtml = ''; } + if (options.agentlinktext == null) { options.agentlinktext = ''; } + if (options.meshid == null) { options.meshid = ''; } + if (options.introtext == null) { options.introtext = ''; } + if (options.introhtml == null) { options.introhtml = ''; } + if (options.msgtext == null) { options.msgtext = ''; } + if (options.msghtml == null) { options.msghtml = ''; } + + text = text.split('[[[CALLBACKURL]]]').join(url + 'checkmail?c=' + options.cookie); + text = text.split('[[[AGENTHTML]]]').join(options.agentlinkhtml); + text = text.split('[[[AGENTTEXT]]]').join(options.agentlinktext); + text = text.split('[[[MESHID]]]').join(options.meshid); + text = text.split('[[[INTROTEXT]]]').join(options.introtext); + text = text.split('[[[INTROHTML]]]').join(options.introhtml); + text = text.split('[[[MSGTEXT]]]').join(options.msgtext); + text = text.split('[[[MSGHTML]]]').join(options.msghtml); } - return text.split('[[[USERNAME]]]').join(username).split('[[[SERVERURL]]]').join(url).split('[[[SERVERNAME]]]').join(domain.title); + return text.split('[[[USERNAME]]]').join(username).split('[[[SERVERURL]]]').join(url).split('[[[SERVERNAME]]]').join(domain.title).split('[[[EMAIL]]]').join(EscapeHtml(email)).split('[[[URL]]]').join(url); } // Send a mail @@ -88,9 +103,25 @@ module.exports.CreateMeshMain = function (parent) { }; // Send agent invite mail - obj.sendAgentInviteMail = function (domain, username, email, meshid) { + obj.sendAgentInviteMail = function (domain, username, email, meshid, name, os, msg) { if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName == 'un-configured')) return; // If the server name is not set, can't do this. - obj.pendingMails.push({ to: email, from: parent.config.smtp.from, subject: mailReplacements(accountInviteSubject, domain, username, email), text: mailReplacements(accountInviteMailText, domain, username, email, { meshid: meshid }), html: mailReplacements(accountInviteMailHtml, domain, username, email, { meshid: meshid }) }); + var options = { meshid: meshid.split('/')[2] }; + var agentLinkHtml = ''; + var agentLinkText = ''; + if (os == 0 || os == 1) { // All OS or Windows + agentLinkHtml += '

Click here to download the MeshAgent for Windows.

'; + agentLinkText += 'For Windows, nagivate to the following link to complete the process:\r\n\r\n[[[SERVERURL]]]/meshagents?id=3&meshid=[[[MESHID]]]&tag=mailto:[[[EMAIL]]]\r\n\r\n'; + } + if (os == 0 || os == 2) { // All OS or Linux + agentLinkHtml += '

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]]] \'[[[MESHID]]]\'

'; + agentLinkText += 'For Linux, cut & paste the following in a terminal to install the agent:\r\n\r\nwget -q [[[SERVERURL]]]/meshagents?script=1 --no-check-certificate -O ./meshinstall.sh && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh [[[SERVERURL]]] \'[[[MESHID]]]\'\r\n\r\n'; + } + options.agentlinkhtml = agentLinkHtml; + options.agentlinktext = agentLinkText; + if ((name != null) && (name != '')) { options.introtext = 'Hello ' + name + ',\r\n\r\n'; options.introhtml = '

Hello ' + name + ',

'; } + if ((msg != null) && (msg != '')) { options.msgtext = '\r\n\r\nMessage: ' + msg + '\r\n\r\n'; options.msghtml = '

Message: ' + msg + '

'; } + var mail = { to: email, from: parent.config.smtp.from, subject: mailReplacements(accountInviteSubject, domain, username, email), text: mailReplacements(accountInviteMailText, domain, username, email, options), html: mailReplacements(accountInviteMailHtml, domain, username, email, options) }; + obj.pendingMails.push(mail); sendNextMail(); }; diff --git a/meshuser.js b/meshuser.js index a193e26b..1d54e958 100644 --- a/meshuser.js +++ b/meshuser.js @@ -1109,7 +1109,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) { //if (mesh.links[user._id] == null || ((mesh.links[user._id].rights & 4) == 0)) return; // Perform email invitation - obj.parent.parent.mailserver.sendAgentInviteMail(domain, user.name, command.email, command.meshid); + obj.parent.parent.mailserver.sendAgentInviteMail(domain, user.name, command.email, command.meshid, command.name, command.os, command.msg); } break; } diff --git a/package.json b/package.json index 4da15ac9..d057d185 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "meshcentral", - "version": "0.2.0-e", + "version": "0.2.0-f", "keywords": [ "Remote Management", "Intel AMT", diff --git a/views/default.handlebars b/views/default.handlebars index 777b24b7..74f1087a 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1842,7 +1842,7 @@ if (mesh.mtype == 2) { r += ' Add Agent'; if (features & 64) { - r += ' Invite'; + r += ' Invite'; } } return r; @@ -1965,8 +1965,11 @@ if (xxdialogMode) return; var mesh = meshes[meshid]; var x = "Invite someone to install the mesh agent. An email with be sent with the link to the mesh agent installation for " + EscapeHtml(mesh.name) + ".

"; - x += addHtmlValue('E-Mail', ''); - setDialogMode(2, "Invite Mesh Agent", 3, performAgentInvite, x, meshid); + x += addHtmlValue('Name (optional)', ''); + x += addHtmlValue('Email', ''); + x += addHtmlValue('Operating System', ''); + x += addHtmlValue('Message
(optional)', ''); + setDialogMode(2, "Invite", 3, performAgentInvite, x, meshid); validateAgentInvite(); } @@ -1975,7 +1978,7 @@ } function performAgentInvite(button, meshid) { - meshserver.send({ action: 'inviteAgent', meshid: meshid, email: Q('agentInviteEmail').value }); + meshserver.send({ action: 'inviteAgent', meshid: meshid, email: Q('agentInviteEmail').value, name: Q('agentInviteName').value, os: Q('agentInviteNameOs').value, msg: Q('agentInviteMessage').value }); } function addAgentToMesh(meshid) { @@ -4561,7 +4564,7 @@ function account_showChangeEmail() { if (xxdialogMode) return; - var x = "Change your account e-mail address here.

"; + var x = "Change your account email address here.

"; x += addHtmlValue('Email', ''); setDialogMode(2, "Email Address Change", 3, account_changeEmail, x); if (userinfo.email != null) { Q('dp2email').value = userinfo.email; } @@ -4737,6 +4740,9 @@ } if (currentMesh.mtype == 2) { x += ' Install'; + if (features & 64) { + x += ' Invite'; + } } }