From 7274b9bca70e0617b0215d6146b2c99f136e3ccc Mon Sep 17 00:00:00 2001 From: DL6ER Date: Sun, 16 Feb 2020 21:16:06 +0100 Subject: [PATCH] Only use IDN subroutines when the module is available. We have seen reports that at least DietPi is having issues with not matching PHP base and extension versions. Signed-off-by: DL6ER --- scripts/pi-hole/php/add.php | 3 ++- scripts/pi-hole/php/groups.php | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/scripts/pi-hole/php/add.php b/scripts/pi-hole/php/add.php index 1eb6b8d1..147dd355 100644 --- a/scripts/pi-hole/php/add.php +++ b/scripts/pi-hole/php/add.php @@ -22,7 +22,8 @@ $comment = trim($_POST['comment']); // Convert domain name to IDNA ASCII form for international domains // Do this only for exact domains, not for regex filters -if ($list === "white" || $list === "black") { +// Only do it when the php-intl extension is available +if (extension_loaded("intl") && ($list === "white" || $list === "black")) { foreach($domains as &$domain) { $domain = idn_to_ascii($domain); diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index 00f5268c..ad606110 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -352,10 +352,12 @@ if ($_POST['action'] == 'get_groups') { array_push($groups, $gres['group_id']); } $res['groups'] = $groups; - if ($res['type'] === ListType::whitelist || $res['type'] === ListType::blacklist) { + if (extension_loaded("intl") && + ($res['type'] === ListType::whitelist || + $res['type'] === ListType::blacklist) ) { $utf8_domain = idn_to_utf8($res['domain']); // Convert domain name to international form - // if applicable + // if applicable and extension is available if($res['domain'] !== $utf8_domain) { $res['domain'] = $utf8_domain.' ('.$res['domain'].')'; @@ -389,7 +391,11 @@ if ($_POST['action'] == 'get_groups') { if ($type === ListType::whitelist || $type === ListType::blacklist) { // Convert domain name to IDNA ASCII form for international // domains and convert the domain to lower case - $domain = strtolower(idn_to_ascii($domain)); + // Only use IDN routine when php-intl is available + if (extension_loaded("intl")) { + $domain = idn_to_ascii($domain); + } + $domain = strtolower($domain); // Check validity of domain if(filter_var($domain, FILTER_VALIDATE_DOMAIN, FILTER_FLAG_HOSTNAME) === false)