Added previous login view in My Users tab for administrators.

This commit is contained in:
Ylian Saint-Hilaire 2021-02-26 14:26:09 -08:00
parent f6949415f2
commit 739c282060
4 changed files with 2642 additions and 2602 deletions

View File

@ -5385,12 +5385,28 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
}
case 'previousLogins': {
// TODO: Make a better database call to get filtered data.
db.GetUserEvents([user._id], domain.id, user._id.split('/')[2], function (err, docs) {
if (err != null) return;
var e = [];
for (var i in docs) { if ((docs[i].msgArgs) && ((docs[i].action == 'authfail') || (docs[i].action == 'login'))) { e.push({ t: docs[i].time, m: docs[i].msgid, a: docs[i].msgArgs }); } }
try { ws.send(JSON.stringify({ action: 'previousLogins', events: e })); } catch (ex) { }
});
if (command.userid == null) {
// Get previous logins for self
db.GetUserEvents([user._id], domain.id, user._id.split('/')[2], function (err, docs) {
if (err != null) return;
var e = [];
for (var i in docs) { if ((docs[i].msgArgs) && ((docs[i].action == 'authfail') || (docs[i].action == 'login'))) { e.push({ t: docs[i].time, m: docs[i].msgid, a: docs[i].msgArgs }); } }
try { ws.send(JSON.stringify({ action: 'previousLogins', events: e })); } catch (ex) { }
});
} else {
// Get previous logins for specific userid
if (user.siteadmin === SITERIGHT_ADMIN) {
var splitUser = command.userid.split('/');
if ((obj.crossDomain === true) || (splitUser[1] === domain.id)) {
db.GetUserEvents([command.userid], splitUser[1], splitUser[2], function (err, docs) {
if (err != null) return;
var e = [];
for (var i in docs) { if ((docs[i].msgArgs) && ((docs[i].action == 'authfail') || (docs[i].action == 'login'))) { e.push({ t: docs[i].time, m: docs[i].msgid, a: docs[i].msgArgs }); } }
try { ws.send(JSON.stringify({ action: 'previousLogins', userid: command.userid, events: e })); } catch (ex) { }
});
}
}
}
break;
}
default: {

File diff suppressed because it is too large Load Diff

View File

@ -1561,9 +1561,10 @@
x += '<div style=max-height:260px;overflow-y:scroll;overflow-x:hidden>';
for (var i in message.events) {
var m = message.events[i].m;
if (m == 107) { m = "Valid login"; c = 'BBD1BB'; }
else if (m == 108) { m = "Invalid password"; c = 'E1BBBB'; }
else if (m == 110) { m = "Invalid 2FA"; c = 'DD9DC3'; }
if (m == 107) { m = "Valid login"; c = 'BBD1BB'; xx = ''; }
else if (m == 108) { m = "Invalid 2FA"; c = 'DD9DC3'; xx = 'x'; }
else if (m == 109) { m = "Locked account"; c = 'E1BBBB'; xx = 'x'; }
else if (m == 110) { m = "Invalid password"; c = 'E1BBBB'; xx = 'x'; }
x += '<div style=width:260px;background-color:#' + c + ';border-radius:6px;margin-bottom:4px;padding:4px><div><b>' + EscapeHtml(m) + '</b><br />' + printDateTime(new Date(message.events[i].t)) + '</div><div style=font-size:x-small>' + EscapeHtml(message.events[i].a.join(', ')) + '</div></div></tr>';
}
x += '</div>';

View File

@ -3271,7 +3271,9 @@
break;
}
case 'previousLogins':{
if ((xxdialogMode == 2) && (xxdialogTag == 'previousLogins')) {
var tag = 'previousLogins';
if (message.userid != null) { tag += ':' + message.userid; }
if ((xxdialogMode == 2) && (xxdialogTag == tag)) {
var x = '', c = 'BBB', xx = '';
if (message.events.length == 0) {
x += 'No previous login.';
@ -3280,8 +3282,9 @@
for (var i in message.events) {
var m = message.events[i].m;
if (m == 107) { m = "Valid login"; c = 'BBD1BB'; xx = ''; }
else if (m == 108) { m = "Invalid password"; c ='E1BBBB'; xx = 'x'; }
else if (m == 110) { m = "Invalid 2FA"; c = 'DD9DC3'; xx = 'x'; }
else if (m == 108) { m = "Invalid 2FA"; c ='DD9DC3'; xx = 'x'; }
else if (m == 109) { m = "Locked account"; c ='E1BBBB'; xx = 'x'; }
else if (m == 110) { m = "Invalid password"; c = 'E1BBBB'; xx = 'x'; }
x += '<tr><td><img src=images/user-32' + xx + '.png height=32 width=32 style=float:left srcset="images/user-64' + xx + '.png 2x"><td><div style=width:300px;background-color:#' + c + ';border-radius:6px;margin-bottom:4px;padding:4px><div>' + printDateTime(new Date(message.events[i].t)) + ', <b>' + EscapeHtml(m) + '</b></div><div style=font-size:x-small>' + EscapeHtml(message.events[i].a.join(', ')) + '</div></div></tr>';
}
x += '</table></div>';
@ -12926,7 +12929,10 @@
if (userAdminRights) { x += '<a href=# style=cursor:pointer onclick=\'return p30showDeleteUserDialog()\' title="' + "Remove this user" + '">' + "Delete User" + '</a>'; }
x += '</div><div style=font-size:small>';
// If user admin rights and not SSPI/LDAP and UserID does not start with ~, show change password
if (userAdminRights && ((features & 0x00080000) == 0) && (user._id.split('/')[2][0] != '~')) { x += '<a href=# style=cursor:pointer onclick=\'return p30showUserChangePassDialog(' + multiFactor + ')\' title="' + "Change the password for this user" + '">' + "Change Password" + '</a>'; }
if (userAdminRights && ((features & 0x00080000) == 0) && (user._id.split('/')[2][0] != '~')) {
x += '<a href=# style=cursor:pointer onclick=\'return p30showUserChangePassDialog(' + multiFactor + ')\' title="' + "Change the password for this user" + '">' + "Change Password" + '</a>';
x += ' <a href=# style=cursor:pointer onclick=\'return p30viewPreviousLogins()\' title="' + "View previous logins for this user" + '">' + "Previous Logins" + '</a>';
}
x += '</div><br>'
QH('p30html3', x);
@ -13013,6 +13019,13 @@
meshserver.send(x);
}
// Display the previous logins of this user
function p30viewPreviousLogins() {
if (xxdialogMode) return;
setDialogMode(2, "Previous Logins", 1, null, "Loading...", 'previousLogins:' + currentUser._id);
meshserver.send({ action: 'previousLogins', userid: currentUser._id });
}
// Display the user's password change dialog box
function p30showUserChangePassDialog(multiFactor) {
if (xxdialogMode) return;