mirror of
https://github.com/billz/raspap-webgui.git
synced 2025-03-01 10:31:47 +00:00
Create functions from procedural code
This commit is contained in:
@@ -19,7 +19,7 @@ function mask2cidr($mask)
|
||||
*
|
||||
* @param string $cidr
|
||||
* @return string
|
||||
*/
|
||||
*/
|
||||
function cidr2mask($cidr)
|
||||
{
|
||||
$ta = substr ($cidr, strpos ($cidr, '/') + 1) * 1;
|
||||
@@ -29,6 +29,98 @@ function cidr2mask($cidr)
|
||||
return join ('.', $netmask);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a dhcp default config header
|
||||
*
|
||||
* @return array $config
|
||||
*/
|
||||
function defaultHeader()
|
||||
{
|
||||
$config = [ '# RaspAP default configuration' ];
|
||||
$config[] = 'hostname';
|
||||
$config[] = 'clientid';
|
||||
$config[] = 'persistent';
|
||||
$config[] = 'option rapid_commit';
|
||||
$config[] = 'option domain_name_servers, domain_name, domain_search, host_name';
|
||||
$config[] = 'option classless_static_routes';
|
||||
$config[] = 'option ntp_servers';
|
||||
$config[] = 'require dhcp_server_identifier';
|
||||
$config[] = 'slaac private';
|
||||
$config[] = 'nohook lookup-hostname';
|
||||
return $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 $key => $file) {
|
||||
if ($file !== '090_adblock.conf' && !preg_match('/.*_'.$interface.'.conf/', $file)) {
|
||||
removeDnsmasqConfig($interface,$status);
|
||||
}
|
||||
}
|
||||
return $status;
|
||||
}
|
||||
|
||||
/* Functions to write ini files */
|
||||
|
||||
function write_php_ini($array, $file)
|
||||
|
Reference in New Issue
Block a user