mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
httpd: move the management VLAN into /vlanlist
Review feedback on #306. The value used to ride in /information.json and the picker fetched /vlanlist separately, so the page needed both requests to mean anything. /vlanlist now answers {"mgmt":N,"vlan":[...]} and the picker reads both from the one response. Both consumers in vlan.js were taught the new shape, and /information.json no longer carries mgmt_vlan. The truncation guard now reserves 141 bytes instead of 139: the closing grew to two bytes with the wrapping object, and the comma in front of a non-first entry was never counted, so the worst case could land one byte past outbuf even before this change. char_to_html() does not check. The comments added on this branch are gone as well, style.css and system.js both, since these files are served byte for byte. page_impl.rel stays at DSEG 5, OSEG 0, BSEG 3 and the image reports the same 10183 bytes of XDATA before and after.
This commit is contained in:
@@ -82,7 +82,6 @@ object, img {
|
|||||||
.isNOK{ color: #900;}
|
.isNOK{ color: #900;}
|
||||||
.isOK{ color: #090;}
|
.isOK{ color: #090;}
|
||||||
.ip{padding:8px 16px;margin-bottom: 1em;margin-left: 1em}
|
.ip{padding:8px 16px;margin-bottom: 1em;margin-left: 1em}
|
||||||
/* read-only values line up with the text inside the input fields */
|
|
||||||
.rotext{display:inline-block;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;}
|
.row {display: flex;}
|
||||||
.rcol {flex: 90%;}
|
.rcol {flex: 90%;}
|
||||||
|
|||||||
+5
-6
@@ -133,7 +133,7 @@ function fetchIP() {
|
|||||||
document.getElementById("gw").value=s.ip_gateway;
|
document.getElementById("gw").value=s.ip_gateway;
|
||||||
document.getElementById("hostname").value=s.hostname;
|
document.getElementById("hostname").value=s.hostname;
|
||||||
document.getElementById("model").textContent=s.hw_ver;
|
document.getElementById("model").textContent=s.hw_ver;
|
||||||
loadMgmtVlan(parseInt(s.mgmt_vlan, 10) || 0);
|
loadMgmtVlan();
|
||||||
clearInterval(systemInterval);
|
clearInterval(systemInterval);
|
||||||
// Fetch and populate the config textbox
|
// Fetch and populate the config textbox
|
||||||
fetchConfig().then((configText) => {
|
fetchConfig().then((configText) => {
|
||||||
@@ -170,14 +170,13 @@ window.addEventListener("load", function() {
|
|||||||
|
|
||||||
var mgmtVlanCurrent = 0;
|
var mgmtVlanCurrent = 0;
|
||||||
|
|
||||||
/* Populate the management-VLAN picker from the configured VLANs. If management
|
function loadMgmtVlan() {
|
||||||
* 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');
|
var sel = document.getElementById('mgmtvlan');
|
||||||
if (!sel) return;
|
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;
|
mgmtVlanCurrent = cur;
|
||||||
fetch('/vlanlist').then(function(r) { return r.json(); }).then(function(list) {
|
|
||||||
sel.innerHTML = '';
|
sel.innerHTML = '';
|
||||||
if (!cur) {
|
if (!cur) {
|
||||||
var none = document.createElement('option');
|
var none = document.createElement('option');
|
||||||
|
|||||||
+2
-2
@@ -110,7 +110,7 @@ async function loadVlanTable() {
|
|||||||
var resp;
|
var resp;
|
||||||
try { resp = await fetch('/vlanlist'); } catch(e) { return; }
|
try { resp = await fetch('/vlanlist'); } catch(e) { return; }
|
||||||
if (!resp.ok) return;
|
if (!resp.ok) return;
|
||||||
var vlans = await resp.json();
|
var vlans = (await resp.json()).vlan || [];
|
||||||
for (var i = 0; i < vlans.length; i++) {
|
for (var i = 0; i < vlans.length; i++) {
|
||||||
var v = vlans[i];
|
var v = vlans[i];
|
||||||
var vresp;
|
var vresp;
|
||||||
@@ -181,7 +181,7 @@ function loadVlanList() {
|
|||||||
sel.style.display = 'none';
|
sel.style.display = 'none';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var vlans = JSON.parse(this.responseText);
|
var vlans = JSON.parse(this.responseText).vlan || [];
|
||||||
if (!vlans.length) {
|
if (!vlans.length) {
|
||||||
sel.style.display = 'none';
|
sel.style.display = 'none';
|
||||||
return;
|
return;
|
||||||
|
|||||||
+6
-6
@@ -265,10 +265,7 @@ void send_basic_info(void)
|
|||||||
slen += strtox(outbuf + slen, BUILD_DATE);
|
slen += strtox(outbuf + slen, BUILD_DATE);
|
||||||
slen += strtox(outbuf + slen, "\",\"hw_ver\":\"");
|
slen += strtox(outbuf + slen, "\",\"hw_ver\":\"");
|
||||||
slen += strtox(outbuf + slen, machine.machine_name);
|
slen += strtox(outbuf + slen, machine.machine_name);
|
||||||
/* VLAN carrying switch management, 0 = untagged. */
|
slen += strtox(outbuf + slen, "\",\"flash_size\":\"");
|
||||||
slen += strtox(outbuf + slen, "\",\"mgmt_vlan\":");
|
|
||||||
itoa16_html(management_vlan);
|
|
||||||
slen += strtox(outbuf + slen, ",\"flash_size\":\"");
|
|
||||||
string_to_html(get_flash_size_str());
|
string_to_html(get_flash_size_str());
|
||||||
|
|
||||||
if (machine.n_sfp) {
|
if (machine.n_sfp) {
|
||||||
@@ -861,7 +858,9 @@ void send_vlanlist(void)
|
|||||||
uint8_t first = 1;
|
uint8_t first = 1;
|
||||||
|
|
||||||
slen = strtox(outbuf, HTTP_RESPONCE_JSON);
|
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++) {
|
for (i = 1; i < 4095; i++) {
|
||||||
if (vlan_get(i) < 0)
|
if (vlan_get(i) < 0)
|
||||||
@@ -869,7 +868,7 @@ void send_vlanlist(void)
|
|||||||
if (!(sfr_data[0] & 0x02)) /* bit 1: VLAN table entry valid */
|
if (!(sfr_data[0] & 0x02)) /* bit 1: VLAN table entry valid */
|
||||||
continue;
|
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;
|
break;
|
||||||
|
|
||||||
if (!first)
|
if (!first)
|
||||||
@@ -891,4 +890,5 @@ void send_vlanlist(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
char_to_html(']');
|
char_to_html(']');
|
||||||
|
char_to_html('}');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user