From a75e8fc1d31ab920b01a5efae69694c07d3e94b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Thu, 26 May 2022 23:34:52 +0200 Subject: [PATCH 1/2] Also check wildcard domains for validity before adding MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- scripts/pi-hole/php/groups.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 157fc50b..4fdcdc88 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -640,15 +640,9 @@ if ($_POST['action'] == 'get_groups') { } } - if(isset($_POST['type']) && strlen($_POST['type']) === 2 && $_POST['type'][1] === 'W') + if( ! ($_POST['type'] == '2' || $_POST['type'] == '3')) { - // Apply wildcard-style formatting - $domain = "(\\.|^)".str_replace(".","\\.",$domain)."$"; - } - - if($type === ListType::whitelist || $type === ListType::blacklist) - { - // If adding to the exact lists, we convert the domain lower case and check whether it is valid + // If not adding a RegEx, we convert the domain lower case and check whether it is valid $domain = strtolower($domain); $msg = ""; if(!validDomain($domain, $msg)) @@ -664,6 +658,12 @@ if ($_POST['action'] == 'get_groups') { } } + if(isset($_POST['type']) && strlen($_POST['type']) === 2 && $_POST['type'][1] === 'W') + { + // Apply wildcard-style formatting + $domain = "(\\.|^)".str_replace(".","\\.",$domain)."$"; + } + // First try to delete any occurrences of this domain if we're in // replace mode. Only do this when the domain to be replaced is in // the default group! Otherwise, we would shuffle group settings and @@ -996,7 +996,7 @@ if ($_POST['action'] == 'get_groups') { if (!$stmt->execute()) { if ($db->lastErrorCode() == 19) { - // ErrorCode 19 is "Constraint violation", here the unique constraint of `address` + // ErrorCode 19 is "Constraint violation", here the unique constraint of `address` // is violated (https://www.sqlite.org/rescode.html#constraint). // If the list is already in database, add to ignored list, but don't throw error $ignored++; From ff350449c025730711a203634a913ca6be097aef Mon Sep 17 00:00:00 2001 From: yubiuser Date: Sun, 12 Jun 2022 13:24:53 +0200 Subject: [PATCH 2/2] Use simpler logic Co-authored-by: Adam Warner Signed-off-by: yubiuser --- scripts/pi-hole/php/groups.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 4fdcdc88..da95aabb 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -640,7 +640,7 @@ if ($_POST['action'] == 'get_groups') { } } - if( ! ($_POST['type'] == '2' || $_POST['type'] == '3')) + if( $_POST['type'] != '2' && $_POST['type'] != '3') { // If not adding a RegEx, we convert the domain lower case and check whether it is valid $domain = strtolower($domain);