From 8f19d759f28e52e2eeb0826b822e7b877171434f Mon Sep 17 00:00:00 2001 From: billz Date: Sun, 20 Jul 2025 06:36:43 -0700 Subject: [PATCH] Consolidate functions in their respective dhcpcd + dnsmasq classes --- includes/functions.php | 71 ------------------------------------------ 1 file changed, 71 deletions(-) diff --git a/includes/functions.php b/includes/functions.php index 9541e307..8b388cf4 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -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