From b4c489fba4f5eddb5d7ec62022d9b9ea4884968c Mon Sep 17 00:00:00 2001 From: Daniel Hammerschmidt Date: Tue, 25 Feb 2025 05:45:47 +0100 Subject: [PATCH 1/4] Add flags to meshes to prefer agentname when synced and to override synced name temporarily --- meshagent.js | 7 ++++++- views/default.handlebars | 18 +++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/meshagent.js b/meshagent.js index 7169b9ff..5ea181d9 100644 --- a/meshagent.js +++ b/meshagent.js @@ -807,7 +807,12 @@ module.exports.CreateMeshAgent = function (parent, db, ws, req, args, domain) { if (device.agent.ver != obj.agentInfo.agentVersion) { device.agent.ver = obj.agentInfo.agentVersion; change = 1; changes.push('agent version'); } if (device.agent.id != obj.agentInfo.agentId) { device.agent.id = obj.agentInfo.agentId; change = 1; changes.push('agent type'); } 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 - 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 + // We want the server name to be sync'ed to the hostname or the --agentName + // (flag 16 allows to override the name until next connection) + if (mesh.flags && (mesh.flags & 2)) { + var preferredName = (mesh.flags & 8) && obj.agentName || obj.agentInfo.computerName; + if (device.name != preferredName) {device.name = preferredName; change = 1; } + } if (device.ip != obj.remoteaddr) { device.ip = obj.remoteaddr; change = 1; } if (change == 1) { diff --git a/views/default.handlebars b/views/default.handlebars index 342bae84..6524af4b 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -7486,7 +7486,7 @@ // Add node name var nname = EscapeHtml(node.name), nnameEx; if (nname.length == 0) { nname = '' + "None" + ''; } - if (((meshrights & 4) != 0) && ((!mesh.flags) || ((mesh.flags & 2) == 0))) { nname = '' + nname + ' '; } + if (((meshrights & 4) != 0) && ((!mesh.flags) || ((mesh.flags & 2) == 0 || (mesh.flags & 16)))) { nname = '' + nname + ' '; } nnameEx = nname; if (mesh) { nname += ' - ' + EscapeHtml(mesh.name) + ''; } QH('p10deviceName', nname); @@ -13561,6 +13561,8 @@ if (currentMesh.flags) { if (currentMesh.flags & 1) { meshFeatures.push("Auto-Remove"); } if (currentMesh.flags & 2) { meshFeatures.push((currentMesh.mtype == 4)?"Port Name Sync":"Hostname Sync"); } + if (currentMesh.flags & 8) { meshFeatures.push("Prefer agentname"); } + if (currentMesh.flags & 16) { meshFeatures.push("Allow override"); } if ((serverinfo.devGroupSessionRecording == 1) && (currentMesh.flags & 4)) { meshFeatures.push("Record Sessions"); } } if ((typeof currentMesh.expireDevs == 'number') && (currentMesh.expireDevs > 0)) { meshFeatures.push("Remove inactive"); } @@ -14042,6 +14044,10 @@ } if ((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) { x += '

'; + if (currentMesh.mtype == 2) { + x += '

'; + x += '

'; + } x += '

'; } x += '

'; @@ -14062,6 +14068,14 @@ function p20editmeshfeaturesValidate() { var flags = 0, ok = true; if (((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) && (Q('d20flag1').checked)) { flags += 1; } + if (currentMesh.mtype == 2) { + if (Q('d20flag2').checked) { flags += 2; } + for (const flag of [8, 16]) { + const element = Q('d20flag' + flag); + element.disabled = !(flags & 2); + element.checked = (!element.disabled) && (element.checked); + } + } QE('d20expireDevice', (flags & 1) == 0); var x = ((flags & 1) == 0) && Q('d20expireDevice').checked; QV('d20expireDeviceDev', x); @@ -14074,6 +14088,8 @@ if ((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) { if (Q('d20flag1').checked) { flags += 1; } if (Q('d20flag2').checked) { flags += 2; } + if (Q('d20flag8').checked) { flags += 8; } + if (Q('d20flag16').checked) { flags += 16; } } if ((serverinfo.devGroupSessionRecording == 1) && (currentMesh.mtype != 4)) { if (Q('d20flag4').checked) { flags += 4; } } var expireDevs = 0; From df55245a797d9720c32027a534b909a009ea230d Mon Sep 17 00:00:00 2001 From: Daniel Hammerschmidt Date: Wed, 26 Feb 2025 18:00:43 +0100 Subject: [PATCH 2/4] automatically enable sub-options --- views/default.handlebars | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/views/default.handlebars b/views/default.handlebars index c16c059c..a6b10a1d 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -1,4 +1,4 @@ - + @@ -14069,11 +14069,13 @@ var flags = 0, ok = true; if (((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) && (Q('d20flag1').checked)) { flags += 1; } if (currentMesh.mtype == 2) { - if (Q('d20flag2').checked) { flags += 2; } + if (Q('d20flag2').checked) { + flags += 2; + if (event.currentTarget.id == 'd20flag2') { Q('d20flag8').checked = true; Q('d20flag16').checked = true; } + } for (const flag of [8, 16]) { const element = Q('d20flag' + flag); - element.disabled = !(flags & 2); - element.checked = (!element.disabled) && (element.checked); + if ((element.checked = element.checked && !(element.disabled = !(flags & 2)))) { flags += flag; } } } QE('d20expireDevice', (flags & 1) == 0); From 286cca6de7adaa78018f2c6e3e5dee03abe11ed1 Mon Sep 17 00:00:00 2001 From: Daniel Hammerschmidt Date: Wed, 26 Feb 2025 18:17:23 +0100 Subject: [PATCH 3/4] change caption --- views/default.handlebars | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/views/default.handlebars b/views/default.handlebars index a6b10a1d..e0c2b2e3 100644 --- a/views/default.handlebars +++ b/views/default.handlebars @@ -13561,8 +13561,8 @@ if (currentMesh.flags) { if (currentMesh.flags & 1) { meshFeatures.push("Auto-Remove"); } if (currentMesh.flags & 2) { meshFeatures.push((currentMesh.mtype == 4)?"Port Name Sync":"Hostname Sync"); } - if (currentMesh.flags & 8) { meshFeatures.push("Prefer agentname"); } - if (currentMesh.flags & 16) { meshFeatures.push("Allow override"); } + if (currentMesh.flags & 8) { meshFeatures.push("prefer --agentname"); } + if (currentMesh.flags & 16) { meshFeatures.push("allow override"); } if ((serverinfo.devGroupSessionRecording == 1) && (currentMesh.flags & 4)) { meshFeatures.push("Record Sessions"); } } if ((typeof currentMesh.expireDevs == 'number') && (currentMesh.expireDevs > 0)) { meshFeatures.push("Remove inactive"); } @@ -14045,8 +14045,8 @@ if ((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) { x += '

'; if (currentMesh.mtype == 2) { - x += '

'; - x += '

'; + x += '

'; + x += '

'; } x += '

'; } From 79fd2d664e4c7ada8e48b2c6b6d0c50b5156467f Mon Sep 17 00:00:00 2001 From: Daniel Hammerschmidt Date: Wed, 26 Feb 2025 18:20:56 +0100 Subject: [PATCH 4/4] apply changes to bootstrap UI --- views/default3.handlebars | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/views/default3.handlebars b/views/default3.handlebars index 5dda2d52..94a236ec 100644 --- a/views/default3.handlebars +++ b/views/default3.handlebars @@ -8155,7 +8155,7 @@ // Add node name var nname = EscapeHtml(node.name), nnameEx; if (nname.length == 0) { nname = '' + "None" + ''; } - if (((meshrights & 4) != 0) && ((!mesh.flags) || ((mesh.flags & 2) == 0))) { nname = '' + nname + ' '; } + if (((meshrights & 4) != 0) && ((!mesh.flags) || ((mesh.flags & 2) == 0 || (mesh.flags & 16)))) { nname = '' + nname + ' '; } nnameEx = nname; if (mesh) { nname += ' - ' + EscapeHtml(mesh.name) + ''; } QH('p10deviceName', nname); @@ -14603,6 +14603,8 @@ if (currentMesh.flags) { if (currentMesh.flags & 1) { meshFeatures.push("Auto-Remove"); } if (currentMesh.flags & 2) { meshFeatures.push((currentMesh.mtype == 4) ? "Port Name Sync" : "Hostname Sync"); } + if (currentMesh.flags & 8) { meshFeatures.push("prefer --agentname"); } + if (currentMesh.flags & 16) { meshFeatures.push("allow override"); } if ((serverinfo.devGroupSessionRecording == 1) && (currentMesh.flags & 4)) { meshFeatures.push("Record Sessions"); } } if ((typeof currentMesh.expireDevs == 'number') && (currentMesh.expireDevs > 0)) { meshFeatures.push("Remove inactive"); } @@ -15119,6 +15121,10 @@ } if ((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) { x += '

'; + if (currentMesh.mtype == 2) { + x += '

'; + x += '

'; + } x += '

'; } x += '

'; @@ -15140,6 +15146,16 @@ function p20editmeshfeaturesValidate() { var flags = 0, ok = true; if (((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) && (Q('d20flag1').checked)) { flags += 1; } + if (currentMesh.mtype == 2) { + if (Q('d20flag2').checked) { + flags += 2; + if (event.currentTarget.id == 'd20flag2') { Q('d20flag8').checked = true; Q('d20flag16').checked = true; } + } + for (const flag of [8, 16]) { + const element = Q('d20flag' + flag); + if ((element.checked = element.checked && !(element.disabled = !(flags & 2)))) { flags += flag; } + } + } QE('d20expireDevice', (flags & 1) == 0); var x = ((flags & 1) == 0) && Q('d20expireDevice').checked; QV('d20expireDeviceDev', x); @@ -15152,6 +15168,8 @@ if ((currentMesh.mtype == 2) || (currentMesh.mtype == 4)) { if (Q('d20flag1').checked) { flags += 1; } if (Q('d20flag2').checked) { flags += 2; } + if (Q('d20flag8').checked) { flags += 8; } + if (Q('d20flag16').checked) { flags += 16; } } if ((serverinfo.devGroupSessionRecording == 1) && (currentMesh.mtype != 4)) { if (Q('d20flag4').checked) { flags += 4; } } var expireDevs = 0;