diff --git a/scripts/pi-hole/php/add.php b/scripts/pi-hole/php/add.php index d6059a51..94da8863 100644 --- a/scripts/pi-hole/php/add.php +++ b/scripts/pi-hole/php/add.php @@ -16,17 +16,23 @@ if (empty($api)) { list_verify($list); } +// Split individual domains into array +$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); +} + // Only check domains we add to the exact lists. // Regex are validated by FTL during import $check_lists = ["white","black","audit"]; if(in_array($list, $check_lists)) { - check_domain(); + check_domain($domains); } -// Split individual domains into array -$domains = preg_split('/\s+/', trim($_POST['domain'])); -$comment = trim($_POST['comment']); - require_once("func.php"); require_once("database.php"); $GRAVITYDB = getGravityDBFilename(); diff --git a/scripts/pi-hole/php/auth.php b/scripts/pi-hole/php/auth.php index 56f84520..7398cbdf 100644 --- a/scripts/pi-hole/php/auth.php +++ b/scripts/pi-hole/php/auth.php @@ -113,15 +113,12 @@ function check_csrf($token) { } } -function check_domain() { - if(isset($_POST['domain'])){ - $domains = preg_split('/\s+/', $_POST['domain']); - foreach($domains as $domain) - { - $validDomain = is_valid_domain_name($domain); - if(!$validDomain){ - log_and_die(htmlspecialchars($domain. ' is not a valid domain')); - } +function check_domain(&$domains) { + foreach($domains as &$domain) + { + $validDomain = is_valid_domain_name($domain); + if(!$validDomain){ + log_and_die(htmlspecialchars($domain. ' is not a valid domain')); } } } diff --git a/scripts/pi-hole/php/get.php b/scripts/pi-hole/php/get.php index f47f2c84..5a230bdb 100644 --- a/scripts/pi-hole/php/get.php +++ b/scripts/pi-hole/php/get.php @@ -30,6 +30,13 @@ 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'].')'; + } array_push($entries, $res); } diff --git a/scripts/pi-hole/php/groups.php b/scripts/pi-hole/php/groups.php index ff6f7aa5..fcea7e22 100644 --- a/scripts/pi-hole/php/groups.php +++ b/scripts/pi-hole/php/groups.php @@ -346,6 +346,13 @@ 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'].')'; + } array_push($data, $res); } @@ -364,7 +371,8 @@ if ($_POST['action'] == 'get_groups') { $type = intval($_POST['type']); - $domain = $_POST['domain']; + // Convert domain name to IDNA ASCII form for international domains + $domain = idn_to_ascii($_POST['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