From bb8e6d6511125d4ca9cbdc5bc591850410c35059 Mon Sep 17 00:00:00 2001 From: Ylian Saint-Hilaire Date: Tue, 9 Mar 2021 17:26:54 -0800 Subject: [PATCH] Fixed previous login dialog. --- db.js | 8 ++++---- meshdesktopmultiplex.js | 3 +-- meshuser.js | 9 ++++----- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/db.js b/db.js index 34922dfc..ea0acb08 100644 --- a/db.js +++ b/db.js @@ -1241,7 +1241,7 @@ module.exports.CreateDB = function (parent, func) { obj.GetEventsWithLimit = function (ids, domain, limit, func) { obj.eventsfile.find({ domain: domain, ids: { $in: ids } }).project({ type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit).toArray(func); }; obj.GetUserEvents = function (ids, domain, username, func) { obj.eventsfile.find({ domain: domain, $or: [{ ids: { $in: ids } }, { username: username }] }).project({ type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).toArray(func); }; obj.GetUserEventsWithLimit = function (ids, domain, username, limit, func) { obj.eventsfile.find({ domain: domain, $or: [{ ids: { $in: ids } }, { username: username }] }).project({ type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit).toArray(func); }; - obj.GetUserLoginEvents = function (domain, username, func) { obj.eventsfile.find({ domain: domain, action: { $in: ['authfail', 'login'] }, msgArgs: { $exists: true } }).project({ action: 1, time: 1, msgid: 1, msgArgs: 1 }).sort({ time: -1 }).toArray(func); }; + obj.GetUserLoginEvents = function (domain, userid, func) { obj.eventsfile.find({ domain: domain, action: { $in: ['authfail', 'login'] }, userid: userid, msgArgs: { $exists: true } }).project({ action: 1, time: 1, msgid: 1, msgArgs: 1 }).sort({ time: -1 }).toArray(func); }; obj.GetNodeEventsWithLimit = function (nodeid, domain, limit, func) { obj.eventsfile.find({ domain: domain, nodeid: nodeid }).project({ type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit).toArray(func); }; obj.GetNodeEventsSelfWithLimit = function (nodeid, domain, userid, limit, func) { obj.eventsfile.find({ domain: domain, nodeid: nodeid, userid: { $in: [userid, null] } }).project({ type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit).toArray(func); }; obj.RemoveAllEvents = function (domain) { obj.eventsfile.deleteMany({ domain: domain }, { multi: true }); }; @@ -1427,11 +1427,11 @@ module.exports.CreateDB = function (parent, func) { obj.eventsfile.find({ domain: domain, $or: [{ ids: { $in: ids } }, { username: username }] }, { type: 0, _id: 0, domain: 0, ids: 0, node: 0 }).sort({ time: -1 }).limit(limit, func); } }; - obj.GetUserLoginEvents = function (domain, username, func) { + obj.GetUserLoginEvents = function (domain, userid, func) { if (obj.databaseType == 1) { - obj.eventsfile.find({ domain: domain, action: { $in: ['authfail', 'login'] }, msgArgs: { $exists: true } }, { action: 1, time: 1, msgid: 1, msgArgs: 1 }).sort({ time: -1 }).exec(func); + obj.eventsfile.find({ domain: domain, action: { $in: ['authfail', 'login'] }, userid: userid, msgArgs: { $exists: true } }, { action: 1, time: 1, msgid: 1, msgArgs: 1 }).sort({ time: -1 }).exec(func); } else { - obj.eventsfile.find({ domain: domain, action: { $in: ['authfail', 'login'] }, msgArgs: { $exists: true } }, { action: 1, time: 1, msgid: 1, msgArgs: 1 }).sort({ time: -1 }, func); + obj.eventsfile.find({ domain: domain, action: { $in: ['authfail', 'login'] }, userid: userid, msgArgs: { $exists: true } }, { action: 1, time: 1, msgid: 1, msgArgs: 1 }).sort({ time: -1 }, func); } }; obj.GetNodeEventsWithLimit = function (nodeid, domain, limit, func) { if (obj.databaseType == 1) { obj.eventsfile.find({ domain: domain, nodeid: nodeid }, { type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit).exec(func); } else { obj.eventsfile.find({ domain: domain, nodeid: nodeid }, { type: 0, etype: 0, _id: 0, domain: 0, ids: 0, node: 0, nodeid: 0 }).sort({ time: -1 }).limit(limit, func); } }; diff --git a/meshdesktopmultiplex.js b/meshdesktopmultiplex.js index cc5c83c0..7e6e8cdf 100644 --- a/meshdesktopmultiplex.js +++ b/meshdesktopmultiplex.js @@ -564,12 +564,11 @@ function CreateDesktopMultiplexor(parent, domain, nodeid, func) { switch (command) { case 3: // Tile, check dimentions and store - if (data.length < 10) break; + if ((data.length < 10) || (obj.lastData == null)) break; var x = data.readUInt16BE(4), y = data.readUInt16BE(6); var dimensions = require('image-size')(data.slice(8)); var sx = (x / 16), sy = (y / 16), sw = (dimensions.width / 16), sh = (dimensions.height / 16); obj.counter++; - //console.log("Tile", x, y, dimensions.width, dimensions.height); // Keep a reference to this image & how many tiles it covers obj.images[obj.counter] = { next: null, prev: obj.lastData, data: jumboData }; diff --git a/meshuser.js b/meshuser.js index e0d4b624..9b84a8d7 100644 --- a/meshuser.js +++ b/meshuser.js @@ -5401,7 +5401,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use // Get previous logins for self if (db.GetUserLoginEvents) { // New way - db.GetUserLoginEvents(domain.id, user._id.split('/')[2], function (err, docs) { + db.GetUserLoginEvents(domain.id, user._id, function (err, docs) { if (err != null) return; var e = []; for (var i in docs) { e.push({ t: docs[i].time, m: docs[i].msgid, a: docs[i].msgArgs }); } @@ -5410,10 +5410,9 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use } else { // Old way db.GetUserEvents([user._id], domain.id, user._id.split('/')[2], function (err, docs) { - console.log(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 }); } } + for (var i in docs) { if ((docs[i].msgArgs) && (docs[i].userid == command.userid) && ((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) { } }); } @@ -5424,7 +5423,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use if ((obj.crossDomain === true) || (splitUser[1] === domain.id)) { if (db.GetUserLoginEvents) { // New way - db.GetUserLoginEvents(splitUser[1], splitUser[2], function (err, docs) { + db.GetUserLoginEvents(splitUser[1], user._id, function (err, docs) { if (err != null) return; var e = []; for (var i in docs) { e.push({ t: docs[i].time, m: docs[i].msgid, a: docs[i].msgArgs }); } @@ -5435,7 +5434,7 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use 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 }); } } + for (var i in docs) { if ((docs[i].msgArgs) && (docs[i].userid == command.userid) && ((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) { } }); }