From ba40ee75f1565d2135c9de1b2e931c16c99eadb5 Mon Sep 17 00:00:00 2001 From: PiBa-NL Date: Mon, 23 May 2016 01:19:08 +0200 Subject: Diagnostics - DNS Lookup, also query for IPv6 addresses --- src/usr/local/www/diag_dns.php | 75 +++++++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 19 deletions(-) diff --git a/src/usr/local/www/diag_dns.php b/src/usr/local/www/diag_dns.php index 18cc1bf..2ed0d07 100755 --- a/src/usr/local/www/diag_dns.php +++ b/src/usr/local/www/diag_dns.php @@ -64,7 +64,6 @@ $pgtitle = array(gettext("Diagnostics"), gettext("DNS Lookup")); require("guiconfig.inc"); $host = trim($_REQUEST['host'], " \t\n\r\0\x0B[];\"'"); -$host_esc = escapeshellarg($host); /* If this section of config.xml has not been populated yet we need to set it up */ @@ -84,19 +83,54 @@ foreach ($a_aliases as $a) { $counter++; } +function resolve_host_addresses($host) { + $recordtypes = array(DNS_A, DNS_AAAA, DNS_CNAME); + $dnsresult = array(); + $resolved = array(); + $errreporting = error_reporting(); + error_reporting($errreporting & ~E_WARNING);// dns_get_record throws a warning if nothing is resolved.. + foreach($recordtypes as $recordtype) { + $tmp = dns_get_record($host, $recordtype); + if (is_array($tmp)) { + $dnsresult = array_merge($dnsresult, $tmp); + } + } + error_reporting($errreporting);// restore original php warning/error settings. + + foreach($dnsresult as $item) { + $newitem = array(); + $newitem['type'] = $item['type']; + switch ($item['type']) { + case 'CNAME': + $newitem['data'] = $item['target']; + $resolved[] = $newitem; + break; + case 'A': + $newitem['data'] = $item['ip']; + $resolved[] = $newitem; + break; + case 'AAAA': + $newitem['data'] = $item['ipv6']; + $resolved[] = $newitem; + break; + + } + } + return $resolved; +} + if (isset($_POST['create_alias']) && (is_hostname($host) || is_ipaddr($host))) { $resolved = gethostbyname($host); $type = "hostname"; if ($resolved) { - $resolved = array(); - exec("/usr/bin/drill {$host_esc} A | /usr/bin/grep {$host_esc} | /usr/bin/grep -v ';' | /usr/bin/awk '{ print $5 }'", $resolved); + $resolved = resolve_host_addresses($host); $isfirst = true; foreach ($resolved as $re) { - if ($re != "") { + if ($re['data'] != "") { if (!$isfirst) { $addresses .= " "; } - $re = rtrim($re); + $re = rtrim($re['data']); if (is_ipaddr($re)) { $sn = is_ipaddrv6($re) ? '/128' : '/32'; } else { @@ -167,8 +201,7 @@ if ($_POST) { $type = "hostname"; $resolved = gethostbyname($host); if ($resolved) { - $resolved = array(); - exec("/usr/bin/drill {$host_esc} A | /usr/bin/grep {$host_esc} | /usr/bin/grep -v ';' | /usr/bin/awk '{ print $5 }'", $resolved); + $resolved = resolve_host_addresses($host); } $hostname = $host; if ($host != $resolved) { @@ -265,18 +298,22 @@ if (!$input_errors && $type) {

-
    - -
  • - -
+ + + + + + + + + + + + + + + +
-- cgit v1.1