Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for international domain names #1130

Merged
merged 2 commits into from Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 11 additions & 5 deletions scripts/pi-hole/php/add.php
Expand Up @@ -16,17 +16,23 @@
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();
Expand Down
15 changes: 6 additions & 9 deletions scripts/pi-hole/php/auth.php
Expand Up @@ -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'));
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions scripts/pi-hole/php/get.php
Expand Up @@ -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);
}

Expand Down
10 changes: 9 additions & 1 deletion scripts/pi-hole/php/groups.php
Expand Up @@ -346,6 +346,13 @@ function JSON_error($message = null)
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);
}

Expand All @@ -364,7 +371,8 @@ function JSON_error($message = null)

$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
Expand Down