mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Merge pull request #306 from DrDoof/mgmt-vlan-gui
system: show and set the management VLAN in System Settings
This commit is contained in:
@@ -145,6 +145,10 @@ var LANG = {
|
||||
sys_netmask: 'Netmask:',
|
||||
sys_gateway: 'Gateway:',
|
||||
sys_language: 'Language:',
|
||||
sys_mgmt_vlan: 'Management VLAN:',
|
||||
sys_mgmt_untagged: 'untagged',
|
||||
sys_mgmt_confirm: 'Move switch management to VLAN ',
|
||||
sys_mgmt_warn: 'The switch will start tagging its own traffic with that VLAN. If the port you are connected through does not carry it, this page becomes unreachable and the setting can only be undone over the console. Continue?',
|
||||
sys_ip_note: 'When updating the above settings, remember to point your browser to the new IP afterwards:',
|
||||
sys_update: 'Update Settings',
|
||||
sys_save_label: 'Save all current settings to Flash:',
|
||||
@@ -328,6 +332,10 @@ var LANG = {
|
||||
sys_netmask: 'ネットマスク:',
|
||||
sys_gateway: 'ゲートウェイ:',
|
||||
sys_language: '言語:',
|
||||
sys_mgmt_vlan: 'Management VLAN:',
|
||||
sys_mgmt_untagged: 'untagged',
|
||||
sys_mgmt_confirm: 'Move switch management to VLAN ',
|
||||
sys_mgmt_warn: 'The switch will start tagging its own traffic with that VLAN. If the port you are connected through does not carry it, this page becomes unreachable and the setting can only be undone over the console. Continue?',
|
||||
sys_ip_note: '上記設定を変更した場合は、ブラウザで新しい IP にアクセスしてください:',
|
||||
sys_update: '設定更新',
|
||||
sys_save_label: '現在の設定をフラッシュに保存:',
|
||||
@@ -511,6 +519,10 @@ var LANG = {
|
||||
sys_netmask: '子网掩码:',
|
||||
sys_gateway: '网关:',
|
||||
sys_language: '语言:',
|
||||
sys_mgmt_vlan: 'Management VLAN:',
|
||||
sys_mgmt_untagged: 'untagged',
|
||||
sys_mgmt_confirm: 'Move switch management to VLAN ',
|
||||
sys_mgmt_warn: 'The switch will start tagging its own traffic with that VLAN. If the port you are connected through does not carry it, this page becomes unreachable and the setting can only be undone over the console. Continue?',
|
||||
sys_ip_note: '更新上述设置后,请使用新的 IP 地址重新访问管理界面:',
|
||||
sys_update: '更新设置',
|
||||
sys_save_label: '将当前全部设置保存到 Flash:',
|
||||
|
||||
@@ -82,6 +82,7 @@ object, img {
|
||||
.isNOK{ color: #900;}
|
||||
.isOK{ color: #090;}
|
||||
.ip{padding:8px 16px;margin-bottom: 1em;margin-left: 1em}
|
||||
.rotext{display:inline-block;padding:8px 16px;margin-bottom: 1em;margin-left: 1em}
|
||||
.row {display: flex;}
|
||||
.rcol {flex: 90%;}
|
||||
.lcol {flex: 10%;}
|
||||
|
||||
+5
-1
@@ -32,7 +32,7 @@
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="lcol"> <label data-i18n="sys_model">Model:</label></div>
|
||||
<div class="rcol"><span id="model"></span></div>
|
||||
<div class="rcol"><span id="model" class="rotext"></span></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="lcol"> <label for="ip" data-i18n="sys_ip">IP address:</label></div>
|
||||
@@ -46,6 +46,10 @@
|
||||
<div class="lcol"> <label for="gw" data-i18n="sys_gateway">Gateway:</label></div>
|
||||
<div class="rcol"><input id="gw" class="ip" type="text" minlength="7" maxlength="15" size="15"/></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="lcol"> <label for="mgmtvlan" data-i18n="sys_mgmt_vlan">Management VLAN:</label></div>
|
||||
<div class="rcol"><select id="mgmtvlan" class="ip" onchange="mgmtVlanChanged()"></select></div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="lcol"> <label data-i18n="sys_language">Language:</label></div>
|
||||
<div class="rcol">
|
||||
|
||||
@@ -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();
|
||||
clearInterval(systemInterval);
|
||||
// Fetch and populate the config textbox
|
||||
fetchConfig().then((configText) => {
|
||||
@@ -165,3 +166,43 @@ window.addEventListener("load", function() {
|
||||
if (langSel) langSel.value = rtlLang;
|
||||
systemInterval = setInterval(fetchIP, 1000);
|
||||
});
|
||||
|
||||
|
||||
var mgmtVlanCurrent = 0;
|
||||
|
||||
function loadMgmtVlan() {
|
||||
var sel = document.getElementById('mgmtvlan');
|
||||
if (!sel) return;
|
||||
fetch('/vlanlist').then(function(r) { return r.json(); }).then(function(d) {
|
||||
var cur = d.mgmt || 0;
|
||||
var list = d.vlan || [];
|
||||
mgmtVlanCurrent = cur;
|
||||
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; });
|
||||
}
|
||||
|
||||
+2
-2
@@ -110,7 +110,7 @@ async function loadVlanTable() {
|
||||
var resp;
|
||||
try { resp = await fetch('/vlanlist'); } catch(e) { return; }
|
||||
if (!resp.ok) return;
|
||||
var vlans = await resp.json();
|
||||
var vlans = (await resp.json()).vlan || [];
|
||||
for (var i = 0; i < vlans.length; i++) {
|
||||
var v = vlans[i];
|
||||
var vresp;
|
||||
@@ -181,7 +181,7 @@ function loadVlanList() {
|
||||
sel.style.display = 'none';
|
||||
return;
|
||||
}
|
||||
var vlans = JSON.parse(this.responseText);
|
||||
var vlans = JSON.parse(this.responseText).vlan || [];
|
||||
if (!vlans.length) {
|
||||
sel.style.display = 'none';
|
||||
return;
|
||||
|
||||
+6
-2
@@ -26,6 +26,7 @@
|
||||
extern __code const struct machine machine;
|
||||
extern __xdata uint8_t outbuf[TCP_OUTBUF_SIZE];
|
||||
extern __xdata uint16_t slen;
|
||||
extern __xdata uint16_t management_vlan;
|
||||
extern __xdata uint16_t cont_len;
|
||||
extern __xdata uint32_t cont_addr;
|
||||
extern __code uint8_t * __code hex;
|
||||
@@ -857,7 +858,9 @@ void send_vlanlist(void)
|
||||
uint8_t first = 1;
|
||||
|
||||
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
||||
char_to_html('[');
|
||||
slen += strtox(outbuf + slen, "{\"mgmt\":");
|
||||
itoa16_html(management_vlan);
|
||||
slen += strtox(outbuf + slen, ",\"vlan\":[");
|
||||
|
||||
for (i = 1; i < 4095; i++) {
|
||||
if (vlan_get(i) < 0)
|
||||
@@ -865,7 +868,7 @@ void send_vlanlist(void)
|
||||
if (!(sfr_data[0] & 0x02)) /* bit 1: VLAN table entry valid */
|
||||
continue;
|
||||
|
||||
if (slen + 139 > TCP_OUTBUF_SIZE) /* 138 bytes worst-case entry + 1 byte for closing ']' */
|
||||
if (slen + 141 > TCP_OUTBUF_SIZE) /* comma + 138-byte worst-case entry + closing "]}" */
|
||||
break;
|
||||
|
||||
if (!first)
|
||||
@@ -887,4 +890,5 @@ void send_vlanlist(void)
|
||||
}
|
||||
|
||||
char_to_html(']');
|
||||
char_to_html('}');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user