system: pick the management VLAN from System Settings

`vlan <id> mgmt` existed on the CLI, but nothing reported which VLAN
currently carries management, so the setting was invisible from the web UI -
the only way to find out was to read the startup config.

Report it in information.json and offer it where the other switch-wide
addressing settings live, between Gateway and Language, as a picker filled
from the configured VLANs. When management is untagged there is no VLAN to
select, so that state shows as a disabled entry rather than inventing an id
the switch would reject.

Confirm before applying, and say what will happen rather than echoing the
action back: the switch starts tagging its own frames, and if the port you
came in on does not carry that VLAN the page becomes unreachable and the way
back is the console. Cancelling puts the picker back where it was.
This commit is contained in:
d00f
2026-08-08 18:26:49 +02:00
parent 23f0ba995c
commit 1a55a134c7
4 changed files with 64 additions and 2 deletions
+42
View File
@@ -133,6 +133,7 @@ function fetchIP() {
document.getElementById("gw").value=s.ip_gateway;
document.getElementById("hostname").value=s.hostname;
document.getElementById("model").textContent=s.hw_ver;
loadMgmtVlan(parseInt(s.mgmt_vlan, 10) || 0);
clearInterval(systemInterval);
// Fetch and populate the config textbox
fetchConfig().then((configText) => {
@@ -165,3 +166,44 @@ window.addEventListener("load", function() {
if (langSel) langSel.value = rtlLang;
systemInterval = setInterval(fetchIP, 1000);
});
var mgmtVlanCurrent = 0;
/* Populate the management-VLAN picker from the configured VLANs. If management
* is untagged there is no VLAN to select, so show that as a disabled entry
* rather than inventing an id the switch would reject. */
function loadMgmtVlan(cur) {
var sel = document.getElementById('mgmtvlan');
if (!sel) return;
mgmtVlanCurrent = cur;
fetch('/vlanlist').then(function(r) { return r.json(); }).then(function(list) {
sel.innerHTML = '';
if (!cur) {
var none = document.createElement('option');
none.value = 0; none.disabled = true;
none.textContent = t('sys_mgmt_untagged');
sel.appendChild(none);
}
for (var i = 0; i < list.length; i++) {
var o = document.createElement('option');
o.value = list[i].id;
o.textContent = list[i].name ? (list[i].id + ' (' + list[i].name + ')') : list[i].id;
sel.appendChild(o);
}
sel.value = cur;
}).catch(function(err) { console.error('VLAN list failed:', err); });
}
function mgmtVlanChanged() {
var sel = document.getElementById('mgmtvlan');
var id = parseInt(sel.value, 10);
if (!id || id === mgmtVlanCurrent) return;
if (!confirm(t('sys_mgmt_confirm') + id + '.\n\n' + t('sys_mgmt_warn'))) {
sel.value = mgmtVlanCurrent;
return;
}
fetch('/cmd', { method: 'POST', body: 'vlan ' + id + ' mgmt' })
.then(function() { mgmtVlanCurrent = id; })
.catch(function(err) { console.error('Set management VLAN failed:', err); sel.value = mgmtVlanCurrent; });
}