Add flags to meshes to prefer agentname when synced and to override synced name temporarily (#6809)

* Add flags to meshes to prefer agentname when synced and to override synced name temporarily * automatically enable sub-options * change caption * apply changes to bootstrap UI

Daniel Hammerschmidt committed Apr 12, 2025 at 11:14 UTC 5f68458cc5218e536e822c679ee35a02f98887c4
3 files changed +45 -4
meshagent.js
+6 -1
@@ -807,7 +807,12 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) {
807 if (device.agent.ver != obj.agentInfo.agentVersion) { device.agent.ver = obj.agentInfo.agentVersion; change = 1; changes.push('agent version'); }
808 if (device.agent.id != obj.agentInfo.agentId) { device.agent.id = obj.agentInfo.agentId; change = 1; changes.push('agent type'); }
809 if ((device.agent.caps & 24) != (obj.agentInfo.capabilities & 24)) { device.agent.caps = obj.agentInfo.capabilities; change = 1; changes.push('agent capabilities'); } // If agent console or javascript support changes, update capabilities
810 - if (mesh.flags && (mesh.flags & 2) && (device.name != obj.agentInfo.computerName)) { device.name = obj.agentInfo.computerName; change = 1; } // We want the server name to be sync'ed to the hostname
810 + // We want the server name to be sync'ed to the hostname or the --agentName
811 + // (flag 16 allows to override the name until next connection)
812 + if (mesh.flags && (mesh.flags & 2)) {
813 + var preferredName = (mesh.flags & 8) && obj.agentName || obj.agentInfo.computerName;
814 + if (device.name != preferredName) {device.name = preferredName; change = 1; }
815 + }
816 if (device.ip != obj.remoteaddr) { device.ip = obj.remoteaddr; change = 1; }
817
818 if (change == 1) {
views/default.handlebars
+20 -2
@@ -1,4 +1,4 @@
1 -<!DOCTYPE html>
1 +<!DOCTYPE html>
2 <html lang="en" dir="ltr" xmlns="http://www.w3.org/1999/xhtml">
3 <head>
4 <meta http-equiv="X-UA-Compatible" content="IE=edge" />
@@ -7497,7 +7497,7 @@
7497 // Add node name
7498 var nname = EscapeHtml(node.name), nnameEx;
7499 if (nname.length == 0) { nname = '<i>' + "None" + '</i>'; }
7500 - if (((meshrights & 4) != 0) && ((!mesh.flags) || ((mesh.flags & 2) == 0))) { nname = '<span tabindex=0 title="' + "Click here to edit the server-side device name" + '" onclick=showEditNodeValueDialog(0) onkeyup="if (event.key == \'Enter\') showEditNodeValueDialog(0)" style=cursor:pointer>' + nname + ' <img class=hoverButton src="images/link5.png" /></span>'; }
7500 + if (((meshrights & 4) != 0) && ((!mesh.flags) || ((mesh.flags & 2) == 0 || (mesh.flags & 16)))) { nname = '<span tabindex=0 title="' + "Click here to edit the server-side device name" + '" onclick=showEditNodeValueDialog(0) onkeyup="if (event.key == \'Enter\') showEditNodeValueDialog(0)" style=cursor:pointer>' + nname + ' <img class=hoverButton src="images/link5.png" /></span>'; }
7501 nnameEx = nname;
7502 if (mesh) { nname += '<span style=color:#AAA;font-size:small> - ' + EscapeHtml(mesh.name) + '</span>'; }
7503 QH('p10deviceName', nname);
@@ -13586,6 +13586,8 @@
13586 if (currentMesh.flags) {
13587 if (currentMesh.flags & 1) { meshFeatures.push("Auto-Remove"); }
13588 if (currentMesh.flags & 2) { meshFeatures.push((currentMesh.mtype == 4)?"Port Name Sync":"Hostname Sync"); }
13589 + if (currentMesh.flags & 8) { meshFeatures.push("prefer --agentname"); }
13590 + if (currentMesh.flags & 16) { meshFeatures.push("allow override"); }
13591 if ((serverinfo.devGroupSessionRecording == 1) && (currentMesh.flags & 4)) { meshFeatures.push("Record Sessions"); }
13592 }
13593 if ((typeof currentMesh.expireDevs == 'number') && (currentMesh.expireDevs > 0)) { meshFeatures.push("Remove inactive"); }
@@ -14067,6 +14069,10 @@
14069 }
14070 if ((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) {
14071 x += '<div><label><input type=checkbox id=d20flag2 onchange=p20editmeshfeaturesValidate() ' + ((flags & 2) ? 'checked' : '') + '>' + ((currentMesh.mtype == 4)?"Sync server device name to port name":"Sync server device name to hostname") + '</label><br></div>';
14072 + if (currentMesh.mtype == 2) {
14073 + x += '<div style="margin-left:8px"><label><input type=checkbox id=d20flag8 onchange=p20editmeshfeaturesValidate() ' + ((flags & 8) ? 'checked' : '') + '>' + "Prefer value of --agentName" + '</label><br></div>';
14074 + x += '<div style="margin-left:8px"><label><input type=checkbox id=d20flag16 onchange=p20editmeshfeaturesValidate() ' + ((flags & 16) ? 'checked' : '') + '>' + "Allow to override server device name until next connection" + '</label><br></div>';
14075 + }
14076 x += '<div><label><input type=checkbox id=d20flag1 onchange=p20editmeshfeaturesValidate() ' + ((flags & 1) ? 'checked' : '') + '>' + "Remove device on disconnect" + '</label><br></div>';
14077 }
14078 x += '<div><label><input type=checkbox id=d20expireDevice onchange=p20editmeshfeaturesValidate() ' + ((expire > 0) ? 'checked' : '') + '>' + "Automatically remove inactive devices" + '</label><br></div>';
@@ -14087,6 +14093,16 @@
14093 function p20editmeshfeaturesValidate() {
14094 var flags = 0, ok = true;
14095 if (((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) && (Q('d20flag1').checked)) { flags += 1; }
14096 + if (currentMesh.mtype == 2) {
14097 + if (Q('d20flag2').checked) {
14098 + flags += 2;
14099 + if (event.currentTarget.id == 'd20flag2') { Q('d20flag8').checked = true; Q('d20flag16').checked = true; }
14100 + }
14101 + for (const flag of [8, 16]) {
14102 + const element = Q('d20flag' + flag);
14103 + if ((element.checked = element.checked && !(element.disabled = !(flags & 2)))) { flags += flag; }
14104 + }
14105 + }
14106 QE('d20expireDevice', (flags & 1) == 0);
14107 var x = ((flags & 1) == 0) && Q('d20expireDevice').checked;
14108 QV('d20expireDeviceDev', x);
@@ -14099,6 +14115,8 @@
14115 if ((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) {
14116 if (Q('d20flag1').checked) { flags += 1; }
14117 if (Q('d20flag2').checked) { flags += 2; }
14118 + if (Q('d20flag8').checked) { flags += 8; }
14119 + if (Q('d20flag16').checked) { flags += 16; }
14120 }
14121 if ((serverinfo.devGroupSessionRecording == 1) && (currentMesh.mtype != 4)) { if (Q('d20flag4').checked) { flags += 4; } }
14122 var expireDevs = 0;
views/default3.handlebars
+19 -1
@@ -8168,7 +8168,7 @@
8168 // Add node name
8169 var nname = EscapeHtml(node.name), nnameEx;
8170 if (nname.length == 0) { nname = '<i>' + "None" + '</i>'; }
8171 - if (((meshrights & 4) != 0) && ((!mesh.flags) || ((mesh.flags & 2) == 0))) { nname = '<span tabindex=0 title="' + "Click here to edit the server-side device name" + '" onclick=showEditNodeValueDialog(0) onkeyup="if (event.key == \'Enter\') showEditNodeValueDialog(0)" role="button">' + nname + ' <i class="fa-solid fa-pencil fa-2xs"/></i></span>'; }
8171 + if (((meshrights & 4) != 0) && ((!mesh.flags) || ((mesh.flags & 2) == 0 || (mesh.flags & 16)))) { nname = '<span tabindex=0 title="' + "Click here to edit the server-side device name" + '" onclick=showEditNodeValueDialog(0) onkeyup="if (event.key == \'Enter\') showEditNodeValueDialog(0)" role="button">' + nname + ' <i class="fa-solid fa-pencil fa-2xs"/></i></span>'; }
8172 nnameEx = nname;
8173 if (mesh) { nname += '<span style=color:#AAA;font-size:small> - ' + EscapeHtml(mesh.name) + '</span>'; }
8174 QH('p10deviceName', nname);
@@ -14628,6 +14628,8 @@
14628 if (currentMesh.flags) {
14629 if (currentMesh.flags & 1) { meshFeatures.push("Auto-Remove"); }
14630 if (currentMesh.flags & 2) { meshFeatures.push((currentMesh.mtype == 4) ? "Port Name Sync" : "Hostname Sync"); }
14631 + if (currentMesh.flags & 8) { meshFeatures.push("prefer --agentname"); }
14632 + if (currentMesh.flags & 16) { meshFeatures.push("allow override"); }
14633 if ((serverinfo.devGroupSessionRecording == 1) && (currentMesh.flags & 4)) { meshFeatures.push("Record Sessions"); }
14634 }
14635 if ((typeof currentMesh.expireDevs == 'number') && (currentMesh.expireDevs > 0)) { meshFeatures.push("Remove inactive"); }
@@ -15144,6 +15146,10 @@
15146 }
15147 if ((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) {
15148 x += '<div class="form-check"><label><input type=checkbox id=d20flag2 class="form-check-input me-2" onchange=p20editmeshfeaturesValidate() ' + ((flags & 2) ? 'checked' : '') + '>' + ((currentMesh.mtype == 4) ? "Sync server device name to port name" : "Sync server device name to hostname") + '</label><br></div>';
15149 + if (currentMesh.mtype == 2) {
15150 + x += '<div style="margin-left:12px"><label><input type=checkbox id=d20flag8 class="form-check-input me-2" onchange=p20editmeshfeaturesValidate() ' + ((flags & 8) ? 'checked' : '') + '>' + "Prefer value of --agentName" + '</label><br></div>';
15151 + x += '<div style="margin-left:12px"><label><input type=checkbox id=d20flag16 class="form-check-input me-2" onchange=p20editmeshfeaturesValidate() ' + ((flags & 16) ? 'checked' : '') + '>' + "Allow to override server device name until next connection" + '</label><br></div>';
15152 + }
15153 x += '<div class="form-check"><label><input type=checkbox id=d20flag1 class="form-check-input me-2" onchange=p20editmeshfeaturesValidate() ' + ((flags & 1) ? 'checked' : '') + '>' + "Remove device on disconnect" + '</label><br></div>';
15154 }
15155 x += '<div class="form-check"><label><input type=checkbox id=d20expireDevice class="form-check-input me-2" onchange=p20editmeshfeaturesValidate() ' + ((expire > 0) ? 'checked' : '') + '>' + "Automatically remove inactive devices" + '</label><br></div>';
@@ -15165,6 +15171,16 @@
15171 function p20editmeshfeaturesValidate() {
15172 var flags = 0, ok = true;
15173 if (((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) && (Q('d20flag1').checked)) { flags += 1; }
15174 + if (currentMesh.mtype == 2) {
15175 + if (Q('d20flag2').checked) {
15176 + flags += 2;
15177 + if (event.currentTarget.id == 'd20flag2') { Q('d20flag8').checked = true; Q('d20flag16').checked = true; }
15178 + }
15179 + for (const flag of [8, 16]) {
15180 + const element = Q('d20flag' + flag);
15181 + if ((element.checked = element.checked && !(element.disabled = !(flags & 2)))) { flags += flag; }
15182 + }
15183 + }
15184 QE('d20expireDevice', (flags & 1) == 0);
15185 var x = ((flags & 1) == 0) && Q('d20expireDevice').checked;
15186 QV('d20expireDeviceDev', x);
@@ -15177,6 +15193,8 @@
15193 if ((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) {
15194 if (Q('d20flag1').checked) { flags += 1; }
15195 if (Q('d20flag2').checked) { flags += 2; }
15196 + if (Q('d20flag8').checked) { flags += 8; }
15197 + if (Q('d20flag16').checked) { flags += 16; }
15198 }
15199 if ((serverinfo.devGroupSessionRecording == 1) && (currentMesh.mtype != 4)) { if (Q('d20flag4').checked) { flags += 4; } }
15200 var expireDevs = 0;