mirror of
https://github.com/Ylianst/MeshCentral.git
synced 2024-12-24 06:05:53 -05:00
Bug fixes on SMTP account verification
This commit is contained in:
parent
72ee422623
commit
b171750f65
@ -355,6 +355,7 @@ function CreateMeshCentralServer() {
|
||||
// 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.verify();
|
||||
//obj.mailserver.sendMail('ylian.saint-hilaire@intel.com', 'Test Subject', 'This is a sample test', 'This is a <b>sample</b> html test');
|
||||
}
|
||||
|
||||
@ -365,6 +366,12 @@ function CreateMeshCentralServer() {
|
||||
obj.DispatchEvent(['*'], obj, { etype: 'server', action: 'started', msg: 'Server started' })
|
||||
|
||||
obj.debug(1, 'Server started');
|
||||
|
||||
/*
|
||||
obj.db.GetUserWithVerifiedEmail('', 'ylian.saint-hilaire@intel.com', function (err, docs) {
|
||||
console.log(JSON.stringify(docs));
|
||||
});
|
||||
*/
|
||||
});
|
||||
});
|
||||
});
|
||||
|
18
meshmail.js
18
meshmail.js
@ -24,8 +24,9 @@ module.exports.CreateMeshMain = function (parent) {
|
||||
var 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';
|
||||
|
||||
// Setup mail server
|
||||
var options = { host: parent.config.smtp.host, secure: false, tls: { rejectUnauthorized: false } };
|
||||
var options = { host: parent.config.smtp.host, secure: (parent.config.smtp.tls == true), tls: { rejectUnauthorized: false } };
|
||||
if (parent.config.smtp.port != null) { options.port = parent.config.smtp.port; }
|
||||
if ((parent.config.smtp.user != null) && (parent.config.smtp.pass != null)) { options.auth = { user: parent.config.smtp.user, pass: parent.config.smtp.pass }; }
|
||||
obj.smtpServer = nodemailer.createTransport(options);
|
||||
|
||||
// Perform all e-mail substitution
|
||||
@ -73,8 +74,19 @@ module.exports.CreateMeshMain = function (parent) {
|
||||
sendNextMail(); // Send the next mail
|
||||
} else {
|
||||
obj.retry++;
|
||||
//console.log('SMTP server failed, will try again in a minute (' + obj.retry + ').');
|
||||
setTimeout(sendNextMail, 60000); // Wait and try again
|
||||
console.log('SMTP server failed: ' + err.response);
|
||||
if (obj.retry < 6) { setTimeout(sendNextMail, 60000); } // Wait and try again
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Send out the next mail in the pending list
|
||||
obj.verify = function() {
|
||||
obj.smtpServer.verify(function (err, info) {
|
||||
if (err == null) {
|
||||
console.log('SMTP mail server ' + parent.config.smtp.host + ' working as expected.');
|
||||
} else {
|
||||
console.log('SMTP mail server ' + parent.config.smtp.host + ' failed: ' + err.response);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
11
meshuser.js
11
meshuser.js
@ -261,6 +261,12 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
|
||||
var x = command.email.split('@');
|
||||
if ((x.length == 2) && (x[0].length > 0) && (x[1].split('.').length > 1) && (x[1].length > 2)) {
|
||||
if (obj.parent.users[req.session.userid].email != command.email) {
|
||||
// Check if this email is already validated on a different account
|
||||
obj.db.GetUserWithVerifiedEmail(domain.id, command.email, function (err, docs) {
|
||||
if (docs.length > 0) {
|
||||
// Notify the duplicate email error
|
||||
ws.send(JSON.stringify({ action: 'msg', type: 'notify', value: 'Failed to change email address, another account already using: <b>' + EscapeHtml(command.email) + '</b>.' }));
|
||||
} else {
|
||||
// Update the user's email
|
||||
var oldemail = user.email;
|
||||
user.email = command.email;
|
||||
@ -278,6 +284,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
|
||||
delete userinfo.passtype;
|
||||
obj.parent.parent.DispatchEvent(['*', 'server-users', user._id], obj, { etype: 'user', username: userinfo.name, account: userinfo, action: 'accountchange', msg: 'Changed email of user ' + userinfo.name + ' from ' + oldemail + ' to ' + user.email, domain: domain.id })
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -960,5 +968,8 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain) {
|
||||
ws.send(JSON.stringify(files));
|
||||
}
|
||||
|
||||
function EscapeHtml(x) { if (typeof x == "string") return x.replace(/&/g, '&').replace(/>/g, '>').replace(/</g, '<').replace(/"/g, '"').replace(/'/g, '''); if (typeof x == "boolean") return x; if (typeof x == "number") return x; }
|
||||
function EscapeHtmlBreaks(x) { if (typeof x == "string") return x.replace(/&/g, '&').replace(/>/g, '>').replace(/</g, '<').replace(/"/g, '"').replace(/'/g, ''').replace(/\r/g, '<br />').replace(/\n/g, '').replace(/\t/g, ' '); if (typeof x == "boolean") return x; if (typeof x == "number") return x; }
|
||||
|
||||
return obj;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "meshcentral",
|
||||
"version": "0.1.0-m",
|
||||
"version": "0.1.0-o",
|
||||
"keywords": [
|
||||
"Remote Management",
|
||||
"Intel AMT",
|
||||
|
@ -167,8 +167,8 @@
|
||||
<div id="p2AccountActions">
|
||||
<p><strong><img alt="" width=150 height=103 src=images/mainaccount.png style=margin-bottom:10px;margin-right:20px;float:right />Account actions</strong></p>
|
||||
<p style="margin-left:40px">
|
||||
<a onclick="account_showChangeEmail()" style="cursor:pointer">Change email address</a><br />
|
||||
<span id="verifyEmailId" style="display:none"><a onclick="account_showVerifyEmail()" style="cursor:pointer">Verify email</a><br /></span>
|
||||
<a onclick="account_showChangeEmail()" style="cursor:pointer">Change email address</a><br />
|
||||
<a onclick="account_showChangePassword()" style="cursor:pointer">Change password</a><br />
|
||||
<a onclick="account_showDeleteAccount()" style="cursor:pointer">Delete account</a><br />
|
||||
</p>
|
||||
@ -493,7 +493,10 @@
|
||||
<table cellpadding=0 cellspacing=10 style="width:100%">
|
||||
<tr>
|
||||
<td style="text-align:left"></td>
|
||||
<td style="text-align:right"><a href="terms">Terms & Privacy</a></td>
|
||||
<td style="text-align:right">
|
||||
<a id="verifyEmailId2" style="color:yellow;margin-left:3px;cursor:pointer" onclick="account_showVerifyEmail()">Verify Email</a>
|
||||
<a style="margin-left:3px" href="terms">Terms & Privacy</a>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@ -786,6 +789,7 @@
|
||||
userinfo = message.userinfo;
|
||||
updateSiteAdmin();
|
||||
QV('verifyEmailId', (userinfo.emailVerified !== true) && (userinfo.email != null) && (serverinfo.emailcheck == true));
|
||||
QV('verifyEmailId2', (userinfo.emailVerified !== true) && (userinfo.email != null) && (serverinfo.emailcheck == true));
|
||||
break;
|
||||
}
|
||||
case 'users': {
|
||||
@ -859,6 +863,12 @@
|
||||
addNotification(n);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (message.type == 'notify') { // This is a notification message.
|
||||
var n = { text:message.value };
|
||||
if (message.tag != undefined) { n.tag = message.tag; }
|
||||
addNotification(n);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -930,6 +940,7 @@
|
||||
userinfo = message.event.account;
|
||||
if (oldsiteadmin != newsiteadmin) updateSiteAdmin();
|
||||
QV('verifyEmailId', (userinfo.emailVerified !== true) && (userinfo.email != null) && (serverinfo.emailcheck == true));
|
||||
QV('verifyEmailId2', (userinfo.emailVerified !== true) && (userinfo.email != null) && (serverinfo.emailcheck == true));
|
||||
}
|
||||
if (users == null) break;
|
||||
users[message.event.account._id] = message.event.account;
|
||||
|
Loading…
Reference in New Issue
Block a user