From b2cc349abfd163468bdb3f5e015675fb6e25e39f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 14 Feb 2020 17:24:01 +0100 Subject: [PATCH 1/9] Only try to convert exact domains using the IDN library. Signed-off-by: DL6ER --- scripts/pi-hole/js/list.js | 6 ++++++ scripts/pi-hole/php/add.php | 9 ++++++--- scripts/pi-hole/php/get.php | 14 ++++++++------ scripts/pi-hole/php/groups.php | 22 ++++++++++++---------- 4 files changed, 32 insertions(+), 19 deletions(-) diff --git a/scripts/pi-hole/js/list.js b/scripts/pi-hole/js/list.js index 8a369c34..4f01c563 100644 --- a/scripts/pi-hole/js/list.js +++ b/scripts/pi-hole/js/list.js @@ -123,6 +123,12 @@ function sub(index, entry, arg) { list = "#list-regex"; heading = "#h3-regex"; locallistType = arg; + } else { + // Extract possible IDN part + // This extracts "xn--allestrungen-9ib.de" from, + // e.g. "allestörungen.de (xn--allestrungen-9ib.de)" + var raw_domain = entry.split("("); + entry = raw_domain[raw_domain.length - 1].split(")")[0]; } var alInfo = $("#alInfo"); diff --git a/scripts/pi-hole/php/add.php b/scripts/pi-hole/php/add.php index 94da8863..621e613f 100644 --- a/scripts/pi-hole/php/add.php +++ b/scripts/pi-hole/php/add.php @@ -21,9 +21,12 @@ $domains = preg_split('/\s+/', trim($_POST['domain'])); $comment = trim($_POST['comment']); // Convert domain name to IDNA ASCII form for international domains -foreach($domains as &$domain) -{ - $domain = idn_to_ascii($domain); +// Do this only for exact domains, not for regex filters +if ($list === "white" || $list === "black") { + foreach($domains as &$domain) + { + $domain = idn_to_ascii($domain); + } } // Only check domains we add to the exact lists. diff --git a/scripts/pi-hole/php/get.php b/scripts/pi-hole/php/get.php index 5a230bdb..09c238f9 100644 --- a/scripts/pi-hole/php/get.php +++ b/scripts/pi-hole/php/get.php @@ -30,12 +30,14 @@ function getTableContent($type) { while($results !== false && $res = $results->fetchArray(SQLITE3_ASSOC)) { - $utf8_domain = idn_to_utf8($res['domain']); - // Convert domain name to international form - // if applicable - if($res['domain'] !== $utf8_domain) - { - $res['domain'] = $utf8_domain.' ('.$res['domain'].')'; + if ($res['type'] === ListType::whitelist || $res['type'] === ListType::blacklist) { + $utf8_domain = idn_to_utf8($res['domain']); + // Convert domain name to international form + // if applicable + if($res['domain'] !== $utf8_domain) + { + $res['domain'] = $utf8_domain.' ('.$res['domain'].')'; + } } array_push($entries, $res); } diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 2482c6f6..6ccdbf1f 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -346,12 +346,14 @@ if ($_POST['action'] == 'get_groups') { array_push($groups, $gres['group_id']); } $res['groups'] = $groups; - $utf8_domain = idn_to_utf8($res['domain']); - // Convert domain name to international form - // if applicable - if($res['domain'] !== $utf8_domain) - { - $res['domain'] = $utf8_domain.' ('.$res['domain'].')'; + if ($res['type'] === ListType::whitelist || $res['type'] === ListType::blacklist) { + $utf8_domain = idn_to_utf8($res['domain']); + // Convert domain name to international form + // if applicable + if($res['domain'] !== $utf8_domain) + { + $res['domain'] = $utf8_domain.' ('.$res['domain'].')'; + } } array_push($data, $res); } @@ -371,10 +373,10 @@ if ($_POST['action'] == 'get_groups') { $type = intval($_POST['type']); - // Convert domain name to IDNA ASCII form for international domains - $domain = idn_to_ascii($_POST['domain']); - if($type === ListType::whitelist || $type === ListType::blacklist) - { + if ($type === ListType::whitelist || $type === ListType::blacklist) { + // Convert domain name to IDNA ASCII form for international domains + $domain = idn_to_ascii($_POST['domain']); + // If adding to the exact lists, we convert the domain lower case and check whether it is valid $domain = strtolower($domain); if(filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false) From 623cecc64cfba15f2095d4007ee43eb517d099d1 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 14 Feb 2020 17:41:03 +0100 Subject: [PATCH 2/9] Also show regex link when this is CNAME regex blocked. Signed-off-by: DL6ER --- scripts/pi-hole/js/queries.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 58c64cd2..6e659ea9 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -250,6 +250,18 @@ $(document).ready(function() { blocked = true; colorClass = "text-red"; fieldtext = "Blocked (regex blacklist, CNAME)"; + + if (data.length > 9 && data[9] > -1) { + fieldtext = + "" + + fieldtext + + ' '; + } + buttontext = ''; isCNAME = true; From 1d7889d7549e40ae0f61d9f3cbd7793caa64cbf8 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 14 Feb 2020 17:50:51 +0100 Subject: [PATCH 3/9] Add hover title to regex link icon. Signed-off-by: DL6ER --- scripts/pi-hole/js/queries.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 6e659ea9..483927a7 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -207,7 +207,7 @@ $(document).ready(function() { colorClass + ">" + fieldtext + - ' '; + ' '; } buttontext = @@ -259,7 +259,7 @@ $(document).ready(function() { colorClass + ">" + fieldtext + - ' '; + ' '; } buttontext = From facb5b07a941ebeb36cccb563965dda9241eb0d8 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 14 Feb 2020 17:54:34 +0100 Subject: [PATCH 4/9] Regex IDs start from 1 by default. 0 means the query has been imported from the database. It makes no sense to show a link when we don't know which regex was responsible for blocking (this is not stored in the database). Signed-off-by: DL6ER --- scripts/pi-hole/js/queries.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 483927a7..d68aa29c 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -199,7 +199,7 @@ $(document).ready(function() { colorClass = "text-red"; fieldtext = "Blocked (regex blacklist)"; - if (data.length > 9 && data[9] > -1) { + if (data.length > 9 && data[9] > 0) { fieldtext = "(regex blacklist, CNAME)"; - if (data.length > 9 && data[9] > -1) { + if (data.length > 9 && data[9] > 0) { fieldtext = "(regex blacklist)"; if (data.length > 9 && data[9] > 0) { - fieldtext = - "" + - fieldtext + - ' '; + regexLink = true; } buttontext = @@ -252,14 +246,7 @@ $(document).ready(function() { fieldtext = "Blocked (regex blacklist, CNAME)"; if (data.length > 9 && data[9] > 0) { - fieldtext = - "" + - fieldtext + - ' '; + regexLink = true; } buttontext = @@ -285,6 +272,25 @@ $(document).ready(function() { $("td:eq(4)", row).html(fieldtext); $("td:eq(6)", row).html(buttontext); + if (regexLink) { + $("td:eq(4)", row).hover( + function() { + this.title = "Click to show matching regex filter"; + this.style.color = "#72afd2"; + }, + function() { + this.style.color = ""; + } + ); + $("td:eq(4)", row).click(function() { + var new_tab = window.open("groups-domains.php?domainid=" + data[9], "_blank"); + if (new_tab) { + new_tab.focus(); + } + }); + $("td:eq(4)", row).css("cursor", "pointer"); + } + // Add domain in CNAME chain causing the query to have been blocked var domain = data[2]; var CNAME_domain = data[8]; From 268a6d9144959dd2402217f96f8a7637a83273be Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 15 Feb 2020 07:35:37 +0100 Subject: [PATCH 6/9] Extract domain in addition request for all domain types, not just the exact ones. Signed-off-by: DL6ER --- scripts/pi-hole/php/groups.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 6ccdbf1f..aa6e3f83 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -372,13 +372,14 @@ if ($_POST['action'] == 'get_groups') { } $type = intval($_POST['type']); + $domain = $_POST['domain']; if ($type === ListType::whitelist || $type === ListType::blacklist) { - // Convert domain name to IDNA ASCII form for international domains - $domain = idn_to_ascii($_POST['domain']); + // Convert domain name to IDNA ASCII form for international + // domains and convert the domain to lower case + $domain = strtolower(idn_to_ascii($domain)); - // If adding to the exact lists, we convert the domain lower case and check whether it is valid - $domain = strtolower($domain); + // Check validity of domain if(filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false) { throw new Exception('Domain ' . htmlentities(utf8_encode($domain)) . 'is not a valid domain.'); From ccb9cb45b2bdbce558de739925b53b72be590f86 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 15 Feb 2020 09:26:55 +0100 Subject: [PATCH 7/9] Add info that users should run pihole -g (can also be doen on the web interface) after modifying their adlists. Signed-off-by: DL6ER --- gravity.php | 2 +- groups-adlists.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/gravity.php b/gravity.php index d86be424..b73cf514 100644 --- a/gravity.php +++ b/gravity.php @@ -15,7 +15,7 @@ From 09c7ba99fa393d04ffd59915c7aea7e7946076f0 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 15 Feb 2020 12:25:07 +0100 Subject: [PATCH 8/9] Underline clickable regex links on Query Log page. Signed-off-by: DL6ER --- scripts/pi-hole/js/queries.js | 3 ++- style/pi-hole.css | 10 +++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 95f847da..ca999435 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -288,7 +288,8 @@ $(document).ready(function() { new_tab.focus(); } }); - $("td:eq(4)", row).css("cursor", "pointer"); + $("td:eq(4)", row).addClass("underline"); + $("td:eq(4)", row).addClass("pointer"); } // Add domain in CNAME chain causing the query to have been blocked diff --git a/style/pi-hole.css b/style/pi-hole.css index eb986c22..b17a4a17 100644 --- a/style/pi-hole.css +++ b/style/pi-hole.css @@ -242,4 +242,12 @@ td.highlight { background-color: yellow; -} \ No newline at end of file +} + +.underline { + text-decoration: underline; +} + +.pointer { + cursor: pointer; +} From 8d6e2a07fb1adea557fe560ff24108ad92da4e48 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sat, 15 Feb 2020 18:16:56 +0100 Subject: [PATCH 9/9] Reverse logic on Query Log to ensure only permitted queries can be added to the blacklist. Signed-off-by: DL6ER --- scripts/pi-hole/js/queries.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 58c64cd2..db157011 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -478,10 +478,10 @@ $(document).ready(function() { $("#all-queries tbody").on("click", "button", function() { var data = tableApi.row($(this).parents("tr")).data(); - if (data[4] === "1" || data[4] === "4" || data[4] === "5") { - add(data[2], "white"); - } else { + if (data[4] === "2" || data[4] === "3") { add(data[2], "black"); + } else { + add(data[2], "white"); } });