More auto device removal fixes. #3089

This commit is contained in:
Ylian Saint-Hilaire 2021-09-01 22:30:43 -07:00
parent 7d25391f78
commit b2905bfe29
2 changed files with 54 additions and 53 deletions

6
db.js
View File

@ -156,9 +156,10 @@ module.exports.CreateDB = function (parent, func) {
var expireDays = -1; var expireDays = -1;
if (removeInactiveDevicesPerDomain[docs[j].domain]) { expireDays = removeInactiveDevicesPerDomain[docs[j].domain]; } if (removeInactiveDevicesPerDomain[docs[j].domain]) { expireDays = removeInactiveDevicesPerDomain[docs[j].domain]; }
const mesh = parent.webserver.meshes[docs[j].meshid]; const mesh = parent.webserver.meshes[docs[j].meshid];
if (mesh && (typeof mesh.expireDevs == 'number') && (expireDays > mesh.expireDevs)) { expireDays = mesh.expireDevs; } if (mesh && (typeof mesh.expireDevs == 'number')) { expireDays = mesh.expireDevs; }
var remove = false; var remove = false;
if ((expireDays > 0) && (expireDays < days)) { remove = true; } if (expireDays > 0) {
if (expireDays < days) { remove = true; }
if (cb) { if (showall || remove) { cb(docs[j]._id.substring(2) + ', ' + days + ' days, expire ' + expireDays + ' days' + (remove ? ', removing' : '')); } } if (cb) { if (showall || remove) { cb(docs[j]._id.substring(2) + ', ' + days + ' days, expire ' + expireDays + ' days' + (remove ? ', removing' : '')); } }
if (remove) { if (remove) {
// Check if this device is connected right now // Check if this device is connected right now
@ -219,6 +220,7 @@ module.exports.CreateDB = function (parent, func) {
} }
} }
} }
}
}); });
} }
} }

View File

@ -6255,7 +6255,6 @@ module.exports.CreateMeshUser = function (parent, db, ws, req, args, domain, use
cmdData.result = 'Usage: removeinactivedevices [showremoved|showall]'; cmdData.result = 'Usage: removeinactivedevices [showremoved|showall]';
} else { } else {
parent.db.removeInactiveDevices((arg == 'showall'), function (msg) { try { ws.send(JSON.stringify({ action: 'serverconsole', value: msg, tag: cmdData.command.tag })); } catch (ex) { } }); parent.db.removeInactiveDevices((arg == 'showall'), function (msg) { try { ws.send(JSON.stringify({ action: 'serverconsole', value: msg, tag: cmdData.command.tag })); } catch (ex) { } });
cmdData.result = 'Ok';
} }
} }