diff --git a/list.php b/list.php index 21c8547b..5e4b9751 100644 --- a/list.php +++ b/list.php @@ -37,7 +37,8 @@ function getFullName() { - + + @@ -66,7 +67,7 @@ function getFullName() { -

Regex blocking

+

Regex & Wildcard blocking

diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index da8a19c8..99e7be05 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -126,12 +126,14 @@ window.onload = refresh(false); function add(arg) { var locallistType = listType; var domain = $("#domain"); + var wild = false; if(domain.val().length === 0){ return; } - if(arg === "wild") + if(arg === "wild" || arg === "regex") { - locallistType = "wild"; + locallistType = arg; + wild = true; } var alInfo = $("#alInfo"); @@ -146,8 +148,8 @@ function add(arg) { method: "post", data: {"domain":domain.val().trim(), "list":locallistType, "token":token}, success: function(response) { - if (locallistType !== "wild" && response.indexOf("] Pi-hole blocking is ") === -1 || - locallistType === "wild" && response.length > 1) { + if (!wild && response.indexOf("] Pi-hole blocking is ") === -1 || + wild && response.length > 1) { alFailure.show(); err.html(response); alFailure.delay(4000).fadeOut(2000, function() { @@ -200,6 +202,10 @@ $("#btnAddWildcard").on("click", function() { add("wild"); }); +$("#btnAddRegex").on("click", function() { + add("regex"); +}); + $("#btnRefresh").on("click", function() { refresh(true); }); diff --git a/scripts/pi-hole/php/add.php b/scripts/pi-hole/php/add.php index 723eef11..fe4668cb 100644 --- a/scripts/pi-hole/php/add.php +++ b/scripts/pi-hole/php/add.php @@ -14,6 +14,23 @@ $type = $_POST['list']; // All of the verification for list editing list_verify($type); +function add_regex($regex) +{ + global $regexfile; + if(file_put_contents($regexfile, "\n".$regex, FILE_APPEND) === FALSE) + { + $err = error_get_last()["message"]; + echo "Unable to add regex \"".htmlspecialchars($_POST['domain'])."\" to ${regexfile}
Error message: $err"; + } + else + { + // Send SIGHUP to pihole-FTL using a frontend command + // to force reloading of the regex domains + // This will also wipe the resolver's cache + echo exec("sudo pihole restartdns reload"); + } +} + switch($type) { case "white": if(!isset($_POST["auditlog"])) @@ -34,18 +51,12 @@ switch($type) { } break; case "wild": - if(file_put_contents($regexfile, "\n".$_POST['domain'], FILE_APPEND) === FALSE) - { - $err = error_get_last()["message"]; - echo "Unable to add regex \"".htmlspecialchars($_POST['domain'])."\" to ${regexfile}
Error message: $err"; - } - else - { - // Send SIGHUP to pihole-FTL using a frontend command - // to force reloading of the regex domains - // This will also wipe the resolver's cache - echo exec("sudo pihole restartdns reload"); - } + // Escape "." so it won't be interpreted as the wildcard character + $domain = str_replace(".","\.",$_POST['domain']); + // Add regex filter for legacy wildcard behavior + add_regex("((^)|(\.))".$domain."$"); + case "regex": + add_regex($_POST['domain']); case "audit": echo exec("sudo pihole -a audit ${_POST['domain']}"); break; diff --git a/scripts/pi-hole/php/auth.php b/scripts/pi-hole/php/auth.php index d540db4a..027220c9 100644 --- a/scripts/pi-hole/php/auth.php +++ b/scripts/pi-hole/php/auth.php @@ -139,7 +139,7 @@ function list_verify($type) { // valid domain for regex expressions // Regex filters are validated by FTL // on import and skipped if invalid - if($_POST['list'] !== "wild") + if($_POST['list'] !== "regex") { check_domain(); }