Started work on device inactivity removal, #2974.

Ylian Saint-Hilaire committed Jul 31, 2021 at 12:06 UTC 5765cc3fd7a1355d98be3fa050159421138699a1
1 file changed +31 -8
views/default.handlebars
+31 -8
@@ -11057,13 +11057,14 @@
11057 if (currentMesh.creation != null) { x += addHtmlValue("Creation Time", printDateTime(new Date(currentMesh.creation))); }
11058
11059 // Display features
11060 - if (currentMesh.mtype == 2) {
11060 + if (currentMesh.mtype < 3) {
11061 var meshFeatures = [];
11062 if (currentMesh.flags) {
11063 if (currentMesh.flags & 1) { meshFeatures.push("Auto-Remove"); }
11064 if (currentMesh.flags & 2) { meshFeatures.push("Hostname Sync"); }
11065 if ((serverinfo.devGroupSessionRecording == 1) && (currentMesh.flags & 4)) { meshFeatures.push("Record Sessions"); }
11066 }
11067 + if ((typeof currentMesh.expireDevs == 'number') && (currentMesh.expireDevs > 0)) { meshFeatures.push("Remove inactive"); }
11068 meshFeatures = meshFeatures.join(', ');
11069 if (meshFeatures == '') { meshFeatures = '<i>' + "None" + '</i>'; }
11070 x += addHtmlValue("Features", addLinkConditional(meshFeatures, 'p20editmeshfeatures()', meshrights & 1));
@@ -11456,19 +11457,41 @@
11457
11458 function p20editmeshfeatures() {
11459 if (xxdialogMode) return;
11459 - var flags = (currentMesh.flags)?currentMesh.flags:0;
11460 - var x = '<div><label><input type=checkbox id=d20flag1 ' + ((flags & 1) ? 'checked' : '') + '>' + "Remove device on disconnect" + '</label><br></div>';
11461 - x += '<div><label><input type=checkbox id=d20flag2 ' + ((flags & 2) ? 'checked' : '') + '>' + "Sync server device name to hostname" + '</label><br></div>';
11462 - if (serverinfo.devGroupSessionRecording == 1) { x += '<div><label><input type=checkbox id=d20flag4 ' + ((flags & 4) ? 'checked' : '') + '>' + "Record sessions" + '</label><br></div>'; }
11460 + var flags = (currentMesh.flags)?currentMesh.flags:0, x = '', expire = 0;
11461 + if ((typeof currentMesh.expireDevs == 'number') && (currentMesh.expireDevs > 0)) { expire = currentMesh.expireDevs; if (expire > 2000) { expire = 2000; } }
11462 + if (serverinfo.devGroupSessionRecording == 1) {
11463 + x += '<div><label><input type=checkbox id=d20flag4 onchange=p20editmeshfeaturesValidate() ' + ((flags & 4) ? 'checked' : '') + '>' + "Record sessions" + '</label><br></div>';
11464 + }
11465 + if (currentMesh.mtype == 2) {
11466 + x += '<div><label><input type=checkbox id=d20flag2 onchange=p20editmeshfeaturesValidate() ' + ((flags & 2) ? 'checked' : '') + '>' + "Sync server device name to hostname" + '</label><br></div>';
11467 + x += '<div><label><input type=checkbox id=d20flag1 onchange=p20editmeshfeaturesValidate() ' + ((flags & 1) ? 'checked' : '') + '>' + "Remove device on disconnect" + '</label><br></div>';
11468 + }
11469 + x += '<div><label><input type=checkbox id=d20expireDevice onchange=p20editmeshfeaturesValidate() ' + ((expire > 0) ? 'checked' : '') + '>' + "Automatically remove inactive devices" + '</label><br></div>';
11470 + x += '<div style=margin-left:20px id=d20expireDeviceDev>' + "Inactivate days until removal" + ' <label><input type=number inputmode=numeric onchange=p20editmeshfeaturesValidate() onkeyup=p20editmeshfeaturesValidate() onpaste=p20editmeshfeaturesValidate() onkeydown=p20editmeshfeaturesValidate() maxlength=4 min=1 max=2000 style=width:80px value=\"' + ((expire == 0)?30:expire) + '\" id=d20expireDeviceDays></label><br></div>';
11471 setDialogMode(2, "Edit Device Group Features", 3, p20editmeshfeaturesEx, x);
11472 + p20editmeshfeaturesValidate();
11473 + }
11474 +
11475 + function p20editmeshfeaturesValidate() {
11476 + var flags = 0, ok = true;
11477 + if ((currentMesh.mtype == 2) && (Q('d20flag1').checked)) { flags += 1; }
11478 + QE('d20expireDevice', (flags & 1) == 0);
11479 + var x = ((flags & 1) == 0) && Q('d20expireDevice').checked;
11480 + QV('d20expireDeviceDev', x);
11481 + if (x) { var y = parseInt(Q('d20expireDeviceDays').value); if (isNaN(y) || (y < 1) || (y > 2000) || (y != Q('d20expireDeviceDays').value)) { ok = false; } }
11482 + QE('idx_dlgOkButton', ok);
11483 }
11484
11485 function p20editmeshfeaturesEx() {
11486 var flags = 0;
11468 - if (Q('d20flag1').checked) { flags += 1; }
11469 - if (Q('d20flag2').checked) { flags += 2; }
11487 + if (currentMesh.mtype == 2) {
11488 + if (Q('d20flag1').checked) { flags += 1; }
11489 + if (Q('d20flag2').checked) { flags += 2; }
11490 + }
11491 if (serverinfo.devGroupSessionRecording == 1) { if (Q('d20flag4').checked) { flags += 4; } }
11471 - meshserver.send({ action: 'editmesh', meshid: currentMesh._id, flags: flags });
11492 + cmd.expireDevs = 0;
11493 + if (((flags & 1) == 0) && Q('d20expireDevice').checked) { expireDevs = parseInt(Q('d20expireDeviceDays').value); }
11494 + meshserver.send({ action: 'editmesh', meshid: currentMesh._id, flags: flags, expireDevs: expireDevs });
11495 }
11496
11497 function p20showAddMeshUserDialog(userid, selected) {