Add port speed page

This commit is contained in:
logicog
2025-12-22 23:28:50 +01:00
parent 6441e85752
commit 36d5ee3ddd
3 changed files with 112 additions and 1 deletions
+1 -1
View File
@@ -1,5 +1,6 @@
document.getElementById('sidebar').innerHTML = document.getElementById('sidebar').innerHTML =
"<ul><li><a href='index.html'>Overview</a></li>" "<ul><li><a href='index.html'>Overview</a></li>"
+ "<li><a href='ports.html'>Port Configuration</a></li>"
+ "<li><a href='stat.html'>Port Statistics</a></li>" + "<li><a href='stat.html'>Port Statistics</a></li>"
+ "<li><a href='vlan.html'>VLAN</a></li>" + "<li><a href='vlan.html'>VLAN</a></li>"
+ "<li><a href='mirror.html'>Mirroring</a></li>" + "<li><a href='mirror.html'>Mirroring</a></li>"
@@ -7,4 +8,3 @@ document.getElementById('sidebar').innerHTML =
+ "<li><a href='eee.html'>EEE</a></li>" + "<li><a href='eee.html'>EEE</a></li>"
+ "<li><a href='system.html'>System Settings</a></li>" + "<li><a href='system.html'>System Settings</a></li>"
+ "<li><a href='update.html'>Firmware Update</a></li></ul>"; + "<li><a href='update.html'>Firmware Update</a></li></ul>";
+21
View File
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>
<script src="/main.js"></script>
<link rel="stylesheet" href="style.css">
<title>FreeSwitchOS Port Configuration</title>
</head>
<body>
<nav id="sidebar"></nav>
<div style="margin-left:16%;padding:1px 16px;height:1000px;">
<div id="ports"></div>
<h1>Port Configuration</h1>
<form id="vform" action="/vlan.html">
<table id="speedtable">
<tr> <th>Port</th> <th>Current Link Speed</th><th>Selected Speed</th> <th>Set Speed</th><th>Set Duplex</th><th>Apply</th></tr>
</table>
<script src="/ports.js"></script>
</form>
</div>
<script src="/navigation.js"></script>
</body>
</html>
+90
View File
@@ -0,0 +1,90 @@
function createPortTable() {
var tbl = document.getElementById('speedtable');
if (tbl.rows.length <= 2 && numPorts) {
clearInterval(pTableInterval);
const sSelect = '<select name="speed_sel" id="speed_sel">'
+ '<option value="auto"> Auto</option>'
+ '<option value="2g5"> 2.5GBit</option>'
+ '<option value="1g"> 1000MBit</option>'
+ '<option value="100m"> 100MBit</option>'
+ '<option value="10m"> 10MBit</option>'
+ '</select>';
const dSelect = '<select name="duplex_sel" id="duplex_sel">'
+ '<option value="any"> Any</option>'
+ '<option value="full"> Full</option>'
+ '<option value="half"> Half</option>'
+ '</select>';
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 = '<button type="button" style="margin: 0 0 0 24px" onclick="applySpeed(' + i + ');">Apply</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);