From 9f0e5fa67e7e78ae2665e7c0fbbe585c22c1b81d Mon Sep 17 00:00:00 2001 From: yubiuser Date: Tue, 12 Oct 2021 20:50:37 +0200 Subject: [PATCH] Use getCustomDNSEntries in deleteAllCustomDNSEntries Signed-off-by: yubiuser --- scripts/pi-hole/php/func.php | 40 +++++++++++------------------------- 1 file changed, 12 insertions(+), 28 deletions(-) diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php index 9dca2046..139d97a5 100644 --- a/scripts/pi-hole/php/func.php +++ b/scripts/pi-hole/php/func.php @@ -277,37 +277,21 @@ function deleteCustomDNSEntry() function deleteAllCustomDNSEntries() { - if (isset($customDNSFile)) - { - $handle = fopen($customDNSFile, "r"); - if ($handle) - { - try - { - while (($line = fgets($handle)) !== false) { - $line = str_replace("\r","", $line); - $line = str_replace("\n","", $line); - $explodedLine = explode (" ", $line); + try + { + $existingEntries = getCustomDNSEntries(); - if (count($explodedLine) != 2) - continue; + foreach ($existingEntries as $entry) { + pihole_execute("-a removecustomdns ".$entry->ip." ".$entry->domain); + } - $ip = $explodedLine[0]; - $domain = $explodedLine[1]; + } + catch (\Exception $ex) + { + return returnError($ex->getMessage()); + } - pihole_execute("-a removecustomdns ".$ip." ".$domain); - } - } - catch (\Exception $ex) - { - return returnError($ex->getMessage()); - } - - fclose($handle); - } - } - - return returnSuccess(); + return returnSuccess(); } // CNAME