From 4633f800abe7c6cbf67a9cdedf07afe42b04b570 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 20 Jan 2017 16:22:19 +0100 Subject: [PATCH] Import of whitelist / blacklist / wildcard list added --- scripts/pi-hole/php/takeout.php | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/php/takeout.php b/scripts/pi-hole/php/takeout.php index 256f5c44..aaeb6b90 100644 --- a/scripts/pi-hole/php/takeout.php +++ b/scripts/pi-hole/php/takeout.php @@ -1,4 +1,5 @@ "; return; } + $contents = ""; while (!feof($fp)) { - $contents .= fread($fp, 2); + $contents .= fread($fp, 4096); } fclose($fp); - return $contents; + $domains = array_filter(explode("\n",$contents)); + check_domains($domains); + return $domains; } function add_to_zip($path,$name) @@ -22,6 +26,16 @@ function add_to_zip($path,$name) $zip->addFile($path.$name,$name); } +function check_domains($domains) +{ + foreach($domains as $domain) + { + if(!is_valid_domain_name($domain)){ + log_and_die(htmlspecialchars($domain).' is not a valid domain'); + } + } +} + function getWildcardListContent() { if(file_exists("/etc/dnsmasq.d/03-pihole-wildcard.conf")) { @@ -71,8 +85,14 @@ if($_POST["action"] == "in") $zip = new ZipArchive(); $x = $zip->open($source); if ($x === true) { - echo process_zip("blacklist.txt"); - echo process_zip("whitelist.txt"); + $blacklist = process_zip("blacklist.txt"); + echo exec("sudo pihole -b -q ".implode(" ", $blacklist)); + + $whitelist = process_zip("whitelist.txt"); + echo exec("sudo pihole -w -q ".implode(" ", $whitelist)); + + $wildlist = process_zip("wildcardblocking.txt"); + echo exec("sudo pihole -wild -q ".implode(" ", $wildlist)); $zip->close(); } else