From b992af2f9d8b577cffa47e3d33ab5fadcc9c673f Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Sun, 5 Apr 2020 12:44:25 -0700 Subject: [PATCH] More SMTP debugging messages, updated MeshCentral Router. --- agents/MeshCentralRouter.exe | Bin 1701528 -> 1701528 bytes meshmail.js | 59 +++++++++++++++++++++++++++++------ 2 files changed, 49 insertions(+), 10 deletions(-) diff --git a/agents/MeshCentralRouter.exe b/agents/MeshCentralRouter.exe index b10fd9d42554ddbc0b91f174ca4115fe95d219bf..a64f1c7bfd574bc4086ca247ca51a937dc0308d8 100644 GIT binary patch delta 4324 zcmaLa3sh4_8UWybAPEtBAff}%!6SHMT>qgp|wh#pil1~5hi zm5n@nV8L1*U2825BZ`XFinZ1QN-af~rBbL`DyXcF73=TYpPi#s`LCd5OW5~~E~{D;og8gnf1uo8us z)5+%HZE;GVKatq1Knz#C2qakm2)YtLGPZKKmBy3i4ED7KmWzO74>2TJi_9PFbqyMd zmIBznxvJg>V7odE|Jb%l+(Bg93KB0IQ%-vlP&k1E`w(;V-c+-^SX80e^JsuBiUy6a z+jONMJG?7c}06s%jRCo$;rNiKQ|^{764k3NHf$NC?#e zJxg8eErBUuTFBH-L-lMa({7yU6!`T+DkJQ4naWLtq03lIj+2=N8bK~79b8<_V%tZ} z;$}jxAU9MDs6S${SkxSt_Yu(g1_(pWg@Zz{0oNM`HG&$YKHR)F1+`dW0n`hz&4bk3 z`_L@N0ksHjtY9U|P)pz!L0{n_K7@A@SnMQLSPs!BtZ#sqn7ZQ4lTqSRON2}zwFC>U zf+9gpn3)7)6WK6FY}8yb)UIUmkgB;9=oOTVOIin-RWxRVT$gw*6^d4~%ojMBG-#pH zWBF8g)l+ypzXcA&7o9)~Qu)EGW zYETx45Ohhhn>z_maO^ z$_OqF640NABRmbrV(vVo{fhs@_;_VZz1hx?1lxm_+8+>16@1Qx`A?N&_fYV1OMtZf?Wp-#^cM@2upYw z;P$BRxJFpsNn-{u;VN+HzcQ6r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+hHD%GhgwCtJ!ZA`VO(rP?03@0)oZTxj$YQa>wNMmt8+DFL)8jmUBn-l z=(Jt*Z>M}`J5pA2Aw)fx7?X>oAxo5@>KbLJ{e;y$N>kb#@fHL4TJz;u``N_G4=<_7x#g2~Y##?OkS3AEmrxBd!uk_d&Z_Vaym zvWL4~HY+{$=VbrnUmkx|=+ano;Gxsxt`F8un-{PoGt~9#JMX@9Yi$RWMN`b4F^)B* zt@eVo&w|9nSjmnU_h0I-e)Qz_{R4^1&VSaKN1TtX7!*IWcgEGpC2) zlM|@{#;XtQm+BmD?Yv`M>UH#rO~}5S5hoY75BWW#N5tCy+^vhOTSPYOk`7z$X>~F& zYX1ILDZB2a-kt4pH8ji^1@(`X=hDH8PjJz)gN<^Y%9D*uKlrj z)xteHCk>hqSNlzAW!#QO=N{bnzI)3fjpj$YyvC?1yCWN3eo`q2x@D6cs~3M1t9f!M z^_%7phr^-evg@fM-|2Dww{N$dGwtq5=qTA5yLp;?`#7&|ujJcHqjT20Sa9ihRi5h~ zpUgJxb#sf`_Q~HT-&lWcW7p`Z=YQB5?|d;T{j*!yc83$D_3nEhSL@y_oZP6*I2%^G z)@+u=P33Zvyt44S-{)y+cUe}RGnpQ0oY8IHp&R7u=NB9hFu})FZr0xrY4}qhX3{}+ zQk9!~mGv2E;^597PK7*-jyv`EO!P-S!kZ*QWFTEcV5Cc^W^~BG=CI!`WL?H3-8t(~1AWUTrlb=b<-i_#bU%DX!YzC2Q5;kmc%+Rj($eO65JqT37p3r<9O A`2YX_ diff --git a/meshmail.js b/meshmail.js index 2b34d331..7227ec9e 100644 --- a/meshmail.js +++ b/meshmail.js @@ -42,6 +42,7 @@ module.exports.CreateMeshMail = function (parent) { // Get the correct mail template object function getTemplate(name, domain, lang) { + parent.debug('email', 'Getting mail template for: ' + name + ', lang: ' + lang); if (Array.isArray(lang)) { lang = lang[0]; } // TODO: For now, we only use the first language given. var r = {}, emailsPath = null; @@ -63,7 +64,7 @@ module.exports.CreateMeshMail = function (parent) { } // Get the english email - if (htmlfile == null) { + if ((htmlfile == null) || (txtfile == null)) { var pathHtml = obj.parent.path.join(emailsPath, name + '.html'); var pathTxt = obj.parent.path.join(emailsPath, name + '.txt'); if (obj.parent.fs.existsSync(pathHtml) && obj.parent.fs.existsSync(pathTxt)) { @@ -152,8 +153,16 @@ module.exports.CreateMeshMail = function (parent) { if (checked) { parent.debug('email', "Sending login token to " + email); + if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) { + parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible. + return; + } + var template = getTemplate('account-login', domain, language); - 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. + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) { + parent.debug('email', "Error: Failed to get mail template."); // Not email template found + return; + } // Set all the options. var options = { email: email, servername: domain.title ? domain.title : 'MeshCentral', token: token }; @@ -171,8 +180,16 @@ module.exports.CreateMeshMail = function (parent) { if (checked) { parent.debug('email', "Sending account invitation to " + email); + if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) { + parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible. + return; + } + var template = getTemplate('account-invite', domain, language); - 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. + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) { + parent.debug('email', "Error: Failed to get mail template."); // Not email template found + return; + } // Set all the options. var options = { username: username, accountname: accountname, email: email, servername: domain.title ? domain.title : 'MeshCentral', password: password }; @@ -190,8 +207,16 @@ module.exports.CreateMeshMail = function (parent) { if (checked) { parent.debug('email', "Sending email verification to " + email); + if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) { + parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible. + return; + } + var template = getTemplate('account-check', domain, language); - 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, no reset possible. + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) { + parent.debug('email', "Error: Failed to get mail template."); // Not email template found + return; + } // Set all the options. var options = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral' }; @@ -210,8 +235,16 @@ module.exports.CreateMeshMail = function (parent) { if (checked) { parent.debug('email', "Sending account password reset to " + email); + if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) { + parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible. + return; + } + var template = getTemplate('account-reset', domain, language); - 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, don't validate the email address. + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) { + parent.debug('email', "Error: Failed to get mail template."); // Not email template found + return; + } // Set all the options. var options = { username: username, email: email, servername: domain.title ? domain.title : 'MeshCentral' }; @@ -229,10 +262,16 @@ module.exports.CreateMeshMail = function (parent) { obj.checkEmail(email, function (checked) { if (checked) { parent.debug('email', "Sending agent install invitation to " + email); + + if ((parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) { + parent.debug('email', "Error: Server name not set."); // If the server name is not set, email not possible. + return; + } + var template = getTemplate('mesh-invite', domain, language); - if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null) || (parent.certificates == null) || (parent.certificates.CommonName == null) || (parent.certificates.CommonName.indexOf('.') == -1)) { - parent.debug('email', "Failed to get email template for " + email); - return; // If the server name is not set, don't validate the email address. + if ((template == null) || (template.htmlSubject == null) || (template.txtSubject == null)) { + parent.debug('email', "Error: Failed to get mail template."); // Not email template found + return; } // Set all the template replacement options and generate the final email text (both in txt and html formats). @@ -256,9 +295,9 @@ module.exports.CreateMeshMail = function (parent) { var mailToSend = obj.pendingMails[0]; obj.sendingMail = true; - //console.log('SMTP sending mail to ' + mailToSend.to + '.'); + parent.debug('email', 'SMTP sending mail to ' + mailToSend.to + '.'); obj.smtpServer.sendMail(mailToSend, function (err, info) { - //console.log(JSON.stringify(err), JSON.stringify(info)); + parent.debug('email', 'SMTP response: ' + JSON.stringify(err) + ', ' + JSON.stringify(info)); obj.sendingMail = false; if (err == null) { obj.pendingMails.shift();