From 4e12212f1373131bf54fea661835502b4474c3b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 28 Aug 2022 19:19:05 +0200 Subject: [PATCH 1/3] Revert empty domain dot replacement MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- scripts/pi-hole/js/db_queries.js | 5 ----- scripts/pi-hole/js/index.js | 8 +++----- scripts/pi-hole/js/queries.js | 5 ----- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js index a550f6d30..9fa169592 100644 --- a/scripts/pi-hole/js/db_queries.js +++ b/scripts/pi-hole/js/db_queries.js @@ -377,12 +377,7 @@ $(function () { $("td:eq(5)", row).append(" (" + (1000 * data[7]).toFixed(1) + "ms)"); } - // Substitute domain by "." if empty var domain = data[2]; - if (domain.length === 0) { - domain = "."; - } - $("td:eq(2)", row).text(domain); }, dom: diff --git a/scripts/pi-hole/js/index.js b/scripts/pi-hole/js/index.js index b92aa47da..e2adc112b 100644 --- a/scripts/pi-hole/js/index.js +++ b/scripts/pi-hole/js/index.js @@ -703,7 +703,7 @@ function updateTopLists() { $("#ad-frequency td").parent().remove(); var domaintable = $("#domain-frequency").find("tbody:last"); var adtable = $("#ad-frequency").find("tbody:last"); - var url, domain, percentage, urlText; + var url, domain, percentage; for (domain in data.top_queries) { if (Object.prototype.hasOwnProperty.call(data.top_queries, domain)) { // Sanitize domain @@ -713,8 +713,7 @@ function updateTopLists() { } domain = utils.escapeHtml(domain); - urlText = domain === "" ? "." : domain; - url = '' + urlText + ""; + url = '' + domain + ""; percentage = (data.top_queries[domain] / data.dns_queries_today) * 100; domaintable.append( " " + @@ -740,8 +739,7 @@ function updateTopLists() { } domain = utils.escapeHtml(domain); - urlText = domain === "" ? "." : domain; - url = '' + urlText + ""; + url = '' + domain + ""; percentage = (data.top_ads[domain] / data.ads_blocked_today) * 100; adtable.append( " " + diff --git a/scripts/pi-hole/js/queries.js b/scripts/pi-hole/js/queries.js index 18f09d729..19d883268 100644 --- a/scripts/pi-hole/js/queries.js +++ b/scripts/pi-hole/js/queries.js @@ -262,12 +262,7 @@ $(function () { $("td:eq(4)", row).addClass("text-underline pointer"); } - // Substitute domain by "." if empty var domain = data[2]; - if (domain.length === 0) { - domain = "."; - } - if (isCNAME) { var CNAMEDomain = data[8]; // Add domain in CNAME chain causing the query to have been blocked From 21521498b5614fbd1da6323e8a5f7e1b53b2241f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 28 Aug 2022 20:15:36 +0200 Subject: [PATCH 2/3] Keep conversion for long-term data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian König --- scripts/pi-hole/js/db_queries.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/scripts/pi-hole/js/db_queries.js b/scripts/pi-hole/js/db_queries.js index 9fa169592..6fe714dd5 100644 --- a/scripts/pi-hole/js/db_queries.js +++ b/scripts/pi-hole/js/db_queries.js @@ -377,7 +377,15 @@ $(function () { $("td:eq(5)", row).append(" (" + (1000 * data[7]).toFixed(1) + "ms)"); } + // Substitute domain by "." if empty + // This was introduced by https://github.com/pi-hole/AdminLTE/pull/1244 but is considered obsolete since + // https://github.com/pi-hole/FTL/pull/1413. However, we keep the conversion here to keep user's + // statistic accurat when they import older data with empty domain fields var domain = data[2]; + if (domain.length === 0) { + domain = "."; + } + $("td:eq(2)", row).text(domain); }, dom: From f4c264be86ccb55ca75dad42ec914e5ca22713e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20K=C3=B6nig?= Date: Sun, 28 Aug 2022 21:56:36 +0200 Subject: [PATCH 3/3] Add special handling for the root zone on domain validation and IDNA conversion 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/func.php | 5 +++++ scripts/pi-hole/php/groups.php | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/scripts/pi-hole/php/func.php b/scripts/pi-hole/php/func.php index bb59611a9..76a19cd8b 100644 --- a/scripts/pi-hole/php/func.php +++ b/scripts/pi-hole/php/func.php @@ -12,6 +12,11 @@ ini_set('pcre.recursion_limit', 1500); function validDomain($domain_name, &$message = null) { + // special handling of the root zone `.` + if ($domain_name == '.') { + return true; + } + if (!preg_match('/^((-|_)*[a-z\\d]((-|_)*[a-z\\d])*(-|_)*)(\\.(-|_)*([a-z\\d]((-|_)*[a-z\\d])*))*$/i', $domain_name)) { if ($message !== null) { $message = 'it contains invalid characters'; diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 7dc02cd94..8ba2552d6 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -510,11 +510,14 @@ function verify_ID_array($arr) $res['groups'] = $groups; if ($res['type'] === ListType::whitelist || $res['type'] === ListType::blacklist) { // Convert domain name to international form - $utf8_domain = convertIDNAToUnicode($res['domain']); + // Skip this for the root zone `.` + if ($res['domain'] != '.') { + $utf8_domain = convertIDNAToUnicode($res['domain']); - // if domain and international form are different, show both - if ($res['domain'] !== $utf8_domain) { - $res['domain'] = $utf8_domain.' ('.$res['domain'].')'; + // if domain and international form are different, show both + if ($res['domain'] !== $utf8_domain) { + $res['domain'] = $utf8_domain.' ('.$res['domain'].')'; + } } } // Prevent domain and comment fields from returning any arbitrary javascript code which could be executed on the browser. @@ -595,8 +598,10 @@ function verify_ID_array($arr) $input = $domain; // Convert domain name to IDNA ASCII form for international domains - $domain = convertUnicodeToIDNA($domain); - + // Skip this for the root zone `.` + if ($domain != '.') { + $domain = convertUnicodeToIDNA($domain); + } 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);