From 36d5ee3ddddac4fdb88292b562bda9ab5db85593 Mon Sep 17 00:00:00 2001 From: logicog Date: Tue, 16 Dec 2025 19:27:07 +0100 Subject: [PATCH] Add port speed page --- html/navigation.js | 2 +- html/ports.html | 21 +++++++++++ html/ports.js | 90 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 112 insertions(+), 1 deletion(-) create mode 100644 html/ports.html create mode 100644 html/ports.js diff --git a/html/navigation.js b/html/navigation.js index 0e38d7b..0444467 100644 --- a/html/navigation.js +++ b/html/navigation.js @@ -1,5 +1,6 @@ document.getElementById('sidebar').innerHTML = ""; - diff --git a/html/ports.html b/html/ports.html new file mode 100644 index 0000000..6b15e50 --- /dev/null +++ b/html/ports.html @@ -0,0 +1,21 @@ + + + + + FreeSwitchOS Port Configuration + + + +
+
+

Port Configuration

+
+ + +
Port Current Link SpeedSelected Speed Set SpeedSet DuplexApply
+ +
+
+ + + diff --git a/html/ports.js b/html/ports.js new file mode 100644 index 0000000..0396447 --- /dev/null +++ b/html/ports.js @@ -0,0 +1,90 @@ +function createPortTable() { + var tbl = document.getElementById('speedtable'); + if (tbl.rows.length <= 2 && numPorts) { + clearInterval(pTableInterval); + const sSelect = ''; + const dSelect = ''; + for (let i = 1; i <= numPorts; i++) { + if (pIsSFP[i-1]) + continue; + console.log("Table row: " + i + "pState: " + pState[i-2]); + const tr = tbl.insertRow(); + let td = tr.insertCell(); td.appendChild(document.createTextNode(`Port ${i}`)); + td = tr.insertCell(); td.innerHTML = linkS[pState[i] + 1]; + td = tr.insertCell(); td.innerHTML = "Unknown"; + td = tr.insertCell(); td.innerHTML = sSelect.replaceAll("speed_sel", "speed_sel_" + i); + td = tr.insertCell(); td.innerHTML = dSelect.replaceAll("duplex_sel", "duplex_sel_" + i); + var button = ''; + td = tr.insertCell(); + td.innerHTML = button; + } + } +} + +function updatePortTable() { + console.log("updatePortTable called"); + var tbl = document.getElementById('speedtable'); + if (tbl.rows.length <= 2 || !numPorts) + return; + for (let i = 1; i <= numPorts ; i++) { + if (pIsSFP[i-1]) + continue; + tbl.rows[i].cells[1].innerHTML = `${linkS[pState[i-1]+1]}`; + var td = tbl.rows[i].cells[2]; + var adv = pAdvertised[i-1]; + console.log("pAdvertised for " + i + " is " + adv); + if (pAdvertised[i-1] == 0) + td.innerHTML = "None"; + else if (adv == 0b100000) + td.innerHTML = "2.5GBit Full Duplex"; + else if (adv == 0b010000) + td.innerHTML = "1000MBit Full Duplex"; + else if (adv == 0b111111) + td.innerHTML = "AUTO"; + else if (adv == 0b000011) + td.innerHTML = "10MBit"; + else if (adv == 0b000100) + td.innerHTML = "100MBit Half Duplex"; + } +} + +async function applySpeed(port) { + var speed = document.getElementById('speed_sel_' + port).value; + var duplex = document.getElementById('duplex_sel_' + port).value; + var cmd = "port " + port + " "; + cmd = cmd + speed; + console.log("port " + port, ", speed: " + speed, ", duplex: ", duplex); + try { + const response = await fetch('/cmd', { + method: 'POST', + body: cmd + }); + console.log('Completed!', response); + if (duplex != "any") { + cmd = "port " + port + " duplex " + duplex; + const response = await fetch('/cmd', { + method: 'POST', + body: cmd + }); + console.log('Completed!', response); + } + } catch(err) { + console.error(`Error: ${err}`); + } +} + +window.addEventListener("load", function() { + const updatePortTableInterval = setInterval(updatePortTable, 1000); +}); + +const pTableInterval = setInterval(createPortTable, 1000);