mirror of
https://github.com/billz/raspap-webgui.git
synced 2023-10-10 13:37:24 +02:00
Handle dhcp for eth0, udpdate dhcpcd + dnsmasq.conf
This commit is contained in:
parent
0049518769
commit
6d14cbaee5
@ -81,15 +81,46 @@ function DisplayDHCPConfig()
|
||||
|
||||
$config .= "log-facility=/tmp/dnsmasq.log".PHP_EOL;
|
||||
$config .= "conf-dir=/etc/dnsmasq.d".PHP_EOL;
|
||||
|
||||
file_put_contents("/tmp/dnsmasqdata", $config);
|
||||
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_CONFIG, $return);
|
||||
|
||||
// handle DHCP for eth0 option
|
||||
if ($_POST['dhcp-eth0'] == "1" && $_POST['interface'] == "eth0") {
|
||||
$dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG);
|
||||
if (!preg_match('/inteface eth0/', $dhcp_cnf)) {
|
||||
// set dhcp values from ini, fallback to default if undefined
|
||||
$eth0_cfg = parse_ini_file(RASPI_CONFIG_NETWORKING.'/eth0.ini', false, INI_SCANNER_RAW);
|
||||
$ip_address = ($eth0_cfg['ip_address'] == '') ? '172.16.10.1/24' : $eth0_cfg['ip_address'];
|
||||
$domain_name_server = ($eth0_cfg['domain_name_server'] =='') ? '1.1.1.1 8.8.8.8' : $eth0_cfg['domain_name_server'];
|
||||
|
||||
// append eth0 config to dhcpcd.conf
|
||||
$cfg = $dhcp_conf;
|
||||
$cfg[] = '# RaspAP '.$_POST['interface'].' configuration';
|
||||
$cfg[] = 'interface '.$_POST['interface'];
|
||||
$cfg[] = 'static ip_address='.$ip_address;
|
||||
$cfg[] = 'static domain_name_server='.$domain_name_server;
|
||||
$cfg[] = PHP_EOL;
|
||||
$cfg = join(PHP_EOL, $cfg);
|
||||
$dhcp_cfg .= $cfg;
|
||||
file_put_contents("/tmp/dhcpddata", $dhcp_cfg);
|
||||
system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $return);
|
||||
$status->addMessage('DHCP configuration for eth0 added.', 'success');
|
||||
}
|
||||
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_ETH0, $return);
|
||||
$status->addMessage('Dnsmasq configuration for eth0 added.', 'success');
|
||||
} elseif (!isset($_POST['dhcp-eth0']) && file_exists(RASPI_DNSMASQ_ETH0)) {
|
||||
// todo: remove dhcpcd eth0 conf
|
||||
system('sudo rm '.RASPI_DNSMASQ_ETH0, $return);
|
||||
$status->addMessage('Dnsmasq configuration for eth0 removed.', 'success');
|
||||
} else {
|
||||
system('sudo cp /tmp/dnsmasqdata '.RASPI_DNSMASQ_CONFIG, $return);
|
||||
}
|
||||
|
||||
} else {
|
||||
$status->addMessage($errors, 'danger');
|
||||
}
|
||||
|
||||
if ($return == 0) {
|
||||
$status->addMessage('Dnsmasq configuration updated successfully', 'success');
|
||||
$status->addMessage('Dnsmasq configuration updated successfully.', 'success');
|
||||
} else {
|
||||
$status->addMessage('Dnsmasq configuration failed to be updated.', 'danger');
|
||||
}
|
||||
@ -176,7 +207,9 @@ function DisplayDHCPConfig()
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (file_exists(RASPI_DNSMASQ_ETH0)) {
|
||||
$dhcp_eth0 = 1;
|
||||
}
|
||||
exec("ip -o link show | awk -F': ' '{print $2}'", $interfaces);
|
||||
exec('cat ' . RASPI_DNSMASQ_LEASES, $leases);
|
||||
|
||||
@ -198,7 +231,8 @@ function DisplayDHCPConfig()
|
||||
"conf",
|
||||
"dhcpHost",
|
||||
"interfaces",
|
||||
"leases"
|
||||
"leases",
|
||||
"dhcp_eth0"
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user