mirror of
				https://github.com/Ylianst/MeshCentral.git
				synced 2025-03-09 15:40:18 +00:00 
			
		
		
		
	Added previous login view in My Users tab for administrators.
This commit is contained in:
		
							parent
							
								
									f6949415f2
								
							
						
					
					
						commit
						739c282060
					
				
					 4 changed files with 2642 additions and 2602 deletions
				
			
		
							
								
								
									
										16
									
								
								meshuser.js
									
										
									
									
									
								
							
							
						
						
									
										16
									
								
								meshuser.js
									
										
									
									
									
								
							| 
						 | 
					@ -5385,12 +5385,28 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            case 'previousLogins': {
 | 
					            case 'previousLogins': {
 | 
				
			||||||
                // TODO: Make a better database call to get filtered data.
 | 
					                // TODO: Make a better database call to get filtered data.
 | 
				
			||||||
 | 
					                if (command.userid == null) {
 | 
				
			||||||
 | 
					                    // Get previous logins for self
 | 
				
			||||||
                    db.GetUserEvents([user._id], domain.id, user._id.split('/')[2], function (err, docs) {
 | 
					                    db.GetUserEvents([user._id], domain.id, user._id.split('/')[2], function (err, docs) {
 | 
				
			||||||
                        if (err != null) return;
 | 
					                        if (err != null) return;
 | 
				
			||||||
                        var e = [];
 | 
					                        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 }); } }
 | 
					                        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) { }
 | 
					                        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;
 | 
					                break;
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
            default: {
 | 
					            default: {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							| 
						 | 
					@ -1561,9 +1561,10 @@
 | 
				
			||||||
                            x += '<div style=max-height:260px;overflow-y:scroll;overflow-x:hidden>';
 | 
					                            x += '<div style=max-height:260px;overflow-y:scroll;overflow-x:hidden>';
 | 
				
			||||||
                            for (var i in message.events) {
 | 
					                            for (var i in message.events) {
 | 
				
			||||||
                                var m = message.events[i].m;
 | 
					                                var m = message.events[i].m;
 | 
				
			||||||
                                if (m == 107) { m = "Valid login"; c = 'BBD1BB'; }
 | 
					                                if (m == 107) { m = "Valid login"; c = 'BBD1BB'; xx = ''; }
 | 
				
			||||||
                                else if (m == 108) { m = "Invalid password"; c = 'E1BBBB'; }
 | 
					                                else if (m == 108) { m = "Invalid 2FA"; c = 'DD9DC3'; xx = 'x'; }
 | 
				
			||||||
                                else if (m == 110) { m = "Invalid 2FA"; c = 'DD9DC3'; }
 | 
					                                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 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>';
 | 
					                            x += '</div>';
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -3271,7 +3271,9 @@
 | 
				
			||||||
                    break;
 | 
					                    break;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                case 'previousLogins':{
 | 
					                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 = '';
 | 
					                        var x = '', c = 'BBB', xx = '';
 | 
				
			||||||
                        if (message.events.length == 0) {
 | 
					                        if (message.events.length == 0) {
 | 
				
			||||||
                            x += 'No previous login.';
 | 
					                            x += 'No previous login.';
 | 
				
			||||||
| 
						 | 
					@ -3280,8 +3282,9 @@
 | 
				
			||||||
                            for (var i in message.events) {
 | 
					                            for (var i in message.events) {
 | 
				
			||||||
                                var m = message.events[i].m;
 | 
					                                var m = message.events[i].m;
 | 
				
			||||||
                                if (m == 107) { m = "Valid login"; c = 'BBD1BB'; xx = ''; }
 | 
					                                if (m == 107) { m = "Valid login"; c = 'BBD1BB'; xx = ''; }
 | 
				
			||||||
                                else if (m == 108) { m = "Invalid password"; c ='E1BBBB'; xx = 'x'; }
 | 
					                                else if (m == 108) { m = "Invalid 2FA"; c ='DD9DC3'; xx = 'x'; }
 | 
				
			||||||
                                else if (m == 110) { 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 += '<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>';
 | 
					                            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>'; }
 | 
					            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>';
 | 
					            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 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>'
 | 
					            x += '</div><br>'
 | 
				
			||||||
            QH('p30html3', x);
 | 
					            QH('p30html3', x);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -13013,6 +13019,13 @@
 | 
				
			||||||
            meshserver.send(x);
 | 
					            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
 | 
					        // Display the user's password change dialog box
 | 
				
			||||||
        function p30showUserChangePassDialog(multiFactor) {
 | 
					        function p30showUserChangePassDialog(multiFactor) {
 | 
				
			||||||
            if (xxdialogMode) return;
 | 
					            if (xxdialogMode) return;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue