Improved email invite feature

Ylian Saint-Hilaire committed Sep 5, 2018 at 17:40 UTC b6bbe71c2a87cf48ec244351aec098d1fa1e87f3
6 files changed +54 -18
agents/meshagent_pi
Binary files a/agents/meshagent_pi and b/agents/meshagent_pi differ
meshcentral.js
+1 -2
@@ -460,9 +460,8 @@ function CreateMeshCentralServer(config, args) {
460
461 // Setup email server
462 if ((obj.config.smtp != null) && (obj.config.smtp.host != null) && (obj.config.smtp.from != null)) {
463 - obj.mailserver = require('./meshmail.js').CreateMeshMain(obj);
463 + obj.mailserver = require('./meshmail.js').CreateMeshMail(obj);
464 obj.mailserver.verify();
465 - //obj.mailserver.sendMail('ylian.saint-hilaire@intel.com', 'Test Subject', 'This is a sample test', 'This is a <b>sample</b> html test');
465 }
466
467 // Start periodic maintenance
meshmail.js
+40 -9
@@ -15,7 +15,7 @@
15 "use strict";
16
17 // Construct a MeshAgent object, called upon connection
18 -module.exports.CreateMeshMain = function (parent) {
18 +module.exports.CreateMeshMail = function (parent) {
19 var obj = {};
20 obj.pendingMails = [];
21 obj.parent = parent;
@@ -35,9 +35,9 @@ module.exports.CreateMeshMain = function (parent) {
35 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';
36
37 // Default account invite mail
38 - const accountInviteSubject = '[[[SERVERNAME]]] - Agent Installation Invitation';
39 - const accountInviteMailHtml = '<div style="font-family:Arial,Helvetica,sans-serif"><table style="background-color:#003366;color:lightgray;width:100%" cellpadding=8><tr><td><b style="font-size:20px;font-family:Arial,Helvetica,sans-serif">[[[SERVERNAME]]] - Agent Installation</b></td></tr></table><p>User [[[USERNAME]]] on server <a href="[[[SERVERURL]]]">[[[SERVERNAME]]]</a> is requesting that you install a remote management agent. WARNING: this will allow the requester to <u>take control of your computer</u>. If you wish to do this, click on the following link to download the agent.</p><p style="margin-left:30px"><a href="[[[CALLBACKURL]]]">Click here to download the MeshAgent for Windows.</a></p>If you did not know about this request, please ignore this mail.</div>';
40 - 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';
38 + const accountInviteSubject = '[[[SERVERNAME]]] - Invitation';
39 + const accountInviteMailHtml = '<div style="font-family:Arial,Helvetica,sans-serif"><table style="background-color:#003366;color:lightgray;width:100%" cellpadding=8><tr><td><b style="font-size:20px;font-family:Arial,Helvetica,sans-serif">[[[SERVERNAME]]] - Agent Installation</b></td></tr></table><p>[[[INTROHTML]]]User [[[USERNAME]]] on server <a href="[[[SERVERURL]]]">[[[SERVERNAME]]]</a> is requesting you to download the following software to start the remote control session.</p>[[[MSGHTML]]][[[AGENTHTML]]]<p>If you did not initiate this request, please ignore this mail.</p>Best regards,<br>[[[USERNAME]]]<br></div>';
40 + 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';
41
42 function EscapeHtml(x) { if (typeof x == "string") return x.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;'); if (typeof x == "boolean") return x; if (typeof x == "number") return x; }
43 //function EscapeHtmlBreaks(x) { if (typeof x == "string") return x.replace(/&/g, '&amp;').replace(/>/g, '&gt;').replace(/</g, '&lt;').replace(/"/g, '&quot;').replace(/'/g, '&apos;').replace(/\r/g, '<br />').replace(/\n/g, '').replace(/\t/g, '&nbsp;&nbsp;'); if (typeof x == "boolean") return x; if (typeof x == "number") return x; }
@@ -59,10 +59,25 @@ module.exports.CreateMeshMain = function (parent) {
59 url = 'http' + ((obj.parent.args.notls == null) ? 's' : '') + '://' + domain.dns + ':' + obj.parent.args.port + domain.url;
60 }
61 if (options) {
62 - if (options.cookie != null) { text = text.split('[[[CALLBACKURL]]]').join(url + 'checkmail?c=' + options.cookie); }
63 - if (options.meshid != null) { text = text.split('[[[CALLBACKURL]]]').join(url + 'meshagents?id=3&meshid=' + options.meshid.split('/')[2] + '&tag=mailto:' + EscapeHtml(email)); }
62 + if (options.cookie == null) { options.cookie = ''; }
63 + if (options.agentlinkhtml == null) { options.agentlinkhtml = ''; }
64 + if (options.agentlinktext == null) { options.agentlinktext = ''; }
65 + if (options.meshid == null) { options.meshid = ''; }
66 + if (options.introtext == null) { options.introtext = ''; }
67 + if (options.introhtml == null) { options.introhtml = ''; }
68 + if (options.msgtext == null) { options.msgtext = ''; }
69 + if (options.msghtml == null) { options.msghtml = ''; }
70 +
71 + text = text.split('[[[CALLBACKURL]]]').join(url + 'checkmail?c=' + options.cookie);
72 + text = text.split('[[[AGENTHTML]]]').join(options.agentlinkhtml);
73 + text = text.split('[[[AGENTTEXT]]]').join(options.agentlinktext);
74 + text = text.split('[[[MESHID]]]').join(options.meshid);
75 + text = text.split('[[[INTROTEXT]]]').join(options.introtext);
76 + text = text.split('[[[INTROHTML]]]').join(options.introhtml);
77 + text = text.split('[[[MSGTEXT]]]').join(options.msgtext);
78 + text = text.split('[[[MSGHTML]]]').join(options.msghtml);
79 }
65 - return text.split('[[[USERNAME]]]').join(username).split('[[[SERVERURL]]]').join(url).split('[[[SERVERNAME]]]').join(domain.title);
80 + return text.split('[[[USERNAME]]]').join(username).split('[[[SERVERURL]]]').join(url).split('[[[SERVERNAME]]]').join(domain.title).split('[[[EMAIL]]]').join(EscapeHtml(email)).split('[[[URL]]]').join(url);
81 }
82
83 // Send a mail
@@ -88,9 +103,25 @@ module.exports.CreateMeshMain = function (parent) {
103 };
104
105 // Send agent invite mail
91 - obj.sendAgentInviteMail = function (domain, username, email, meshid) {
106 + obj.sendAgentInviteMail = function (domain, username, email, meshid, name, os, msg) {
107 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.
93 - 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 }) });
108 + var options = { meshid: meshid.split('/')[2] };
109 + var agentLinkHtml = '';
110 + var agentLinkText = '';
111 + if (os == 0 || os == 1) { // All OS or Windows
112 + agentLinkHtml += '<p style="margin-left:30px"><a href="[[[SERVERURL]]]/meshagents?id=3&meshid=[[[MESHID]]]&tag=mailto:[[[EMAIL]]]">Click here to download the MeshAgent for Windows.</a></p>';
113 + 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';
114 + }
115 + if (os == 0 || os == 2) { // All OS or Linux
116 + agentLinkHtml += '<p>For Linux, cut & paste the following in a terminal to install the agent:<br/><pre style="margin-left:30px">wget -q [[[SERVERURL]]]/meshagents?script=1 --no-check-certificate -O ./meshinstall.sh && chmod 755 ./meshinstall.sh && sudo ./meshinstall.sh [[[SERVERURL]]] \'[[[MESHID]]]\'</pre></p>';
117 + 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';
118 + }
119 + options.agentlinkhtml = agentLinkHtml;
120 + options.agentlinktext = agentLinkText;
121 + if ((name != null) && (name != '')) { options.introtext = 'Hello ' + name + ',\r\n\r\n'; options.introhtml = '<p>Hello ' + name + ',</p>'; }
122 + if ((msg != null) && (msg != '')) { options.msgtext = '\r\n\r\nMessage: ' + msg + '\r\n\r\n'; options.msghtml = '<p>Message: <b>' + msg + '</b></p>'; }
123 + 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) };
124 + obj.pendingMails.push(mail);
125 sendNextMail();
126 };
127
meshuser.js
+1 -1
@@ -1109,7 +1109,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
1109 //if (mesh.links[user._id] == null || ((mesh.links[user._id].rights & 4) == 0)) return;
1110
1111 // Perform email invitation
1112 - obj.parent.parent.mailserver.sendAgentInviteMail(domain, user.name, command.email, command.meshid);
1112 + obj.parent.parent.mailserver.sendAgentInviteMail(domain, user.name, command.email, command.meshid, command.name, command.os, command.msg);
1113 }
1114 break;
1115 }
package.json
+1 -1
@@ -1,6 +1,6 @@
1 {
2 "name": "meshcentral",
3 - "version": "0.2.0-e",
3 + "version": "0.2.0-f",
4 "keywords": [
5 "Remote Management",
6 "Intel AMT",
views/default.handlebars
+11 -5
@@ -1842,7 +1842,7 @@
1842 if (mesh.mtype == 2) {
1843 r += ' <a style=cursor:pointer;font-size:10px title="Add a new computer to this mesh by installing the mesh agent." onclick=addAgentToMesh(\"' + mesh._id + '\")>Add Agent</a>';
1844 if (features & 64) {
1845 - r += ' <a style=cursor:pointer;font-size:10px title="Invite someone to install the mesh agent." onclick=inviteAgentToMesh(\"' + mesh._id + '\")>Invite</a>';
1845 + r += ' <a style=cursor:pointer;font-size:10px title="Invite someone to install the mesh agent on this mesh." onclick=inviteAgentToMesh(\"' + mesh._id + '\")>Invite</a>';
1846 }
1847 }
1848 return r;
@@ -1965,8 +1965,11 @@
1965 if (xxdialogMode) return;
1966 var mesh = meshes[meshid];
1967 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) + ".<br /><br />";
1968 - x += addHtmlValue('E-Mail', '<input id=agentInviteEmail style=width:240px onkeyup=validateAgentInvite()></input>');
1969 - setDialogMode(2, "Invite Mesh Agent", 3, performAgentInvite, x, meshid);
1968 + x += addHtmlValue('Name (optional)', '<input id=agentInviteName value="" style=width:230px maxlength=64 />');
1969 + x += addHtmlValue('Email', '<input id=agentInviteEmail style=width:230px placeholder="example@email.com" onkeyup=validateAgentInvite()></input>');
1970 + x += addHtmlValue('Operating System', '<select id=agentInviteNameOs style=width:236px><option value=1>Windows</option><option value=0>Windows or Linux</option><option value=2>Linux</option></select>');
1971 + x += addHtmlValue('Message<br />(optional)', '<textarea id=agentInviteMessage value="" style=width:230px;height:100px;resize:none maxlength=1024 /></textarea>');
1972 + setDialogMode(2, "Invite", 3, performAgentInvite, x, meshid);
1973 validateAgentInvite();
1974 }
1975
@@ -1975,7 +1978,7 @@
1978 }
1979
1980 function performAgentInvite(button, meshid) {
1978 - meshserver.send({ action: 'inviteAgent', meshid: meshid, email: Q('agentInviteEmail').value });
1981 + meshserver.send({ action: 'inviteAgent', meshid: meshid, email: Q('agentInviteEmail').value, name: Q('agentInviteName').value, os: Q('agentInviteNameOs').value, msg: Q('agentInviteMessage').value });
1982 }
1983
1984 function addAgentToMesh(meshid) {
@@ -4561,7 +4564,7 @@
4564
4565 function account_showChangeEmail() {
4566 if (xxdialogMode) return;
4564 - var x = "Change your account e-mail address here.<br /><br />";
4567 + var x = "Change your account email address here.<br /><br />";
4568 x += addHtmlValue('Email', '<input id=dp2email style=width:230px maxlength=256 onchange=account_validateEmail() onkeyup=account_validateEmail(event) />');
4569 setDialogMode(2, "Email Address Change", 3, account_changeEmail, x);
4570 if (userinfo.email != null) { Q('dp2email').value = userinfo.email; }
@@ -4737,6 +4740,9 @@
4740 }
4741 if (currentMesh.mtype == 2) {
4742 x += '<a onclick=addAgentToMesh(\"' + currentMesh._id + '\") style=cursor:pointer;margin-right:10px title="Add a new computer to this mesh by installing the mesh agent."><img src=images/icon-addnew.png border=0 height=12 width=12> Install</a>';
4743 + if (features & 64) {
4744 + x += '<a onclick=inviteAgentToMesh(\"' + currentMesh._id + '\") style=cursor:pointer;margin-right:10px title="Invite someone to install the mesh agent on this mesh."><img src=images/icon-addnew.png border=0 height=12 width=12> Invite</a>';
4745 + }
4746 }
4747 }
4748