From b2cc349abfd163468bdb3f5e015675fb6e25e39f Mon Sep 17 00:00:00 2001 From: DL6ER Date: Fri, 14 Feb 2020 17:24:01 +0100 Subject: [PATCH] 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)