Add web frontend support for dhcp/dhcpd

This commit is contained in:
logicog
2026-03-09 22:11:27 +01:00
parent 4db49b2ee5
commit aa12adc098
2 changed files with 56 additions and 1 deletions
+44 -1
View File
@@ -8,6 +8,20 @@ function checkIp(ip) {
}
async function ipSub() {
if (document.getElementById('dhcp').checked) {
var cmd = "ip dhcp";
try {
const response = await fetch('/cmd', {
method: 'POST',
body: cmd
});
console.log('Completed!', response);
systemInterval = setInterval(fetchIP, 10000);
} catch(err) {
console.error(`Error: ${err}`);
}
return;
}
for (let i=0;i<3;i++) {
if (!checkIp(document.getElementById(ips[i]).value))
return;
@@ -26,7 +40,34 @@ async function ipSub() {
}
}
}
async function dhcpdSub() {
var dhcpd_cmd = "dhcpd off";
if (document.getElementById('dhcpd').checked)
dhcpd_cmd = "dhcpd on";
try {
const response = await fetch('/cmd', {
method: 'POST',
body: dhcpd_cmd
});
console.log('Completed!', response);
} catch(err) {
console.error(`Error: ${err}`);
}
}
function dhcpClicked(e)
{
console.log("dhcpClicked called");
if (e.checked) {
for (let i=0; i<3;i++)
document.getElementById(ips[i]).disabled = true;
document.getElementById('dhcpd').disabled = true;
} else {
console.log("dhcpClicked off");
for (let i=0; i<3;i++)
document.getElementById(ips[i]).disabled = false;
document.getElementById('dhcpd').disabled = false;
}
}
async function sendConfig(c) {
const form = new FormData();
form.append("MAX_FILE_SIZE", "4096");
@@ -98,6 +139,8 @@ function fetchIP() {
document.getElementById("ip").value=s.ip_address;
document.getElementById("netmask").value=s.ip_netmask;
document.getElementById("gw").value=s.ip_gateway;
document.getElementById('dhcp').checked = s.dhcp_client;
document.getElementById('dhcpd').checked = s.dhcp_server;
clearInterval(systemInterval);
// Fetch and populate the config textbox
fetchConfig().then((configText) => {