mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-12-27 07:31:09 +01:00
Consolidate functions in their respective dhcpcd + dnsmasq classes
This commit is contained in:
@@ -64,77 +64,6 @@ function cidr2mask($cidr)
|
||||
return $netmask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a dhcp configuration block for the specified interface
|
||||
*
|
||||
* @param string $iface
|
||||
* @param object $status
|
||||
* @return boolean $result
|
||||
*/
|
||||
function removeDHCPConfig($iface,$status)
|
||||
{
|
||||
$dhcp_cfg = file_get_contents(RASPI_DHCPCD_CONFIG);
|
||||
$dhcp_cfg = preg_replace('/^#\sRaspAP\s'.$iface.'\s.*?(?=\s*^\s*$)([\s]+)/ms', '', $dhcp_cfg, 1);
|
||||
file_put_contents("/tmp/dhcpddata", $dhcp_cfg);
|
||||
system('sudo cp /tmp/dhcpddata '.RASPI_DHCPCD_CONFIG, $result);
|
||||
if ($result == 0) {
|
||||
$status->addMessage('DHCP configuration for '.$iface.' removed.', 'success');
|
||||
} else {
|
||||
$status->addMessage('Failed to remove DHCP configuration for '.$iface.'.', 'danger');
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a dhcp configuration block for the specified interface
|
||||
*
|
||||
* @param string $dhcp_cfg
|
||||
* @param string $iface
|
||||
* @return string $dhcp_cfg
|
||||
*/
|
||||
function removeDHCPIface($dhcp_cfg,$iface)
|
||||
{
|
||||
$dhcp_cfg = preg_replace('/^#\sRaspAP\s'.$iface.'\s.*?(?=\s*^\s*$)([\s]+)/ms', '', $dhcp_cfg, 1);
|
||||
return $dhcp_cfg;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a dnsmasq configuration block for the specified interface
|
||||
*
|
||||
* @param string $iface
|
||||
* @param object $status
|
||||
* @return boolean $result
|
||||
*/
|
||||
function removeDnsmasqConfig($iface,$status)
|
||||
{
|
||||
system('sudo rm '.RASPI_DNSMASQ_PREFIX.$iface.'.conf', $result);
|
||||
if ($result == 0) {
|
||||
$status->addMessage('Dnsmasq configuration for '.$iface.' removed.', 'success');
|
||||
} else {
|
||||
$status->addMessage('Failed to remove dnsmasq configuration for '.$iface.'.', 'danger');
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scans dnsmasq configuration dir for the specified interface
|
||||
* Non-matching configs are removed, optional adblock.conf is protected
|
||||
*
|
||||
* @param string $dir_conf
|
||||
* @param string $interface
|
||||
* @param object $status
|
||||
*/
|
||||
function scanConfigDir($dir_conf,$interface,$status)
|
||||
{
|
||||
$syscnf = preg_grep('~\.(conf)$~', scandir($dir_conf));
|
||||
foreach ($syscnf as $cnf) {
|
||||
if ($cnf !== '090_adblock.conf' && !preg_match('/.*_'.$interface.'.conf/', $cnf)) {
|
||||
system('sudo rm /etc/dnsmasq.d/'.$cnf, $result);
|
||||
}
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a default (fallback) value for the selected service, interface & setting
|
||||
* from /etc/raspap/networking/defaults.json
|
||||
|
||||
Reference in New Issue
Block a user