From 7c9f09db0e49a5cb8ed0c095903c0e615b66cd83 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 15 Jul 2018 12:56:40 +0200 Subject: [PATCH] Directly write imported regex file to disk instead of useing bash callbacks Signed-off-by: DL6ER --- scripts/pi-hole/php/func.php | 4 ++-- scripts/pi-hole/php/teleporter.php | 8 +++++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php index edd0cbcb..fb9cda82 100644 --- a/scripts/pi-hole/php/func.php +++ b/scripts/pi-hole/php/func.php @@ -45,10 +45,10 @@ if(!function_exists('hash_equals')) { } } -function add_regex($regex) +function add_regex($regex, $mode=FILE_APPEND, $append="\n") { global $regexfile; - if(file_put_contents($regexfile, "\n".$regex, FILE_APPEND) === FALSE) + if(file_put_contents($regexfile, $append.$regex, $mode) === FALSE) { $err = error_get_last()["message"]; echo "Unable to add regex \"".htmlspecialchars($regex)."\" to ${regexfile}
Error message: $err"; diff --git a/scripts/pi-hole/php/teleporter.php b/scripts/pi-hole/php/teleporter.php index 380eb613..dbdb637d 100644 --- a/scripts/pi-hole/php/teleporter.php +++ b/scripts/pi-hole/php/teleporter.php @@ -113,6 +113,7 @@ if(isset($_POST["action"])) exec("sudo pihole -b -q -nr ".implode(" ", $blacklist)); $importedsomething = true; } + if(isset($_POST["whitelist"]) && $file->getFilename() === "whitelist.txt") { $whitelist = process_file(file_get_contents($file)); @@ -124,10 +125,11 @@ if(isset($_POST["action"])) if(isset($_POST["regexlist"]) && $file->getFilename() === "regex.list") { - $regexlist = process_file(file_get_contents($file),false); + $regexraw = file_get_contents($file); + $regexlist = process_file($regexraw,false); echo "Processing regex.list (".count($regexlist)." entries)
\n"; - exec("sudo pihole --regex -nr --nuke"); - exec("sudo pihole --regex -q -nr ".implode(" ", $regexlist)); + // NULL = overwrite (or create) the regex filter file + add_regex($regexraw, NULL,""); $importedsomething = true; }