mirror of
https://github.com/logicog/RTLPlayground.git
synced 2026-08-30 14:52:51 +08:00
Add web frontend support for dhcp/dhcpd
This commit is contained in:
+44
-1
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user