summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPiBa-NL <pba_2k3@yahoo.com>2016-05-23 01:19:08 +0200
committerChris Buechler <cmb@pfsense.org>2016-06-29 23:30:33 -0500
commit0b316bd18100d6bf864ecdfecd79968f0d11c562 (patch)
tree494043169701cf0a247295e3025f95dbf16d356c
parenta5297e819cb15a1e8e47d8b4cef848d509e86681 (diff)
downloadpfsense-0b316bd18100d6bf864ecdfecd79968f0d11c562.zip
pfsense-0b316bd18100d6bf864ecdfecd79968f0d11c562.tar.gz
Diagnostics - DNS Lookup, also query for IPv6 addresses
-rwxr-xr-xsrc/usr/local/www/diag_dns.php75
1 files changed, 56 insertions, 19 deletions
diff --git a/src/usr/local/www/diag_dns.php b/src/usr/local/www/diag_dns.php
index 2df22c8..2fcdad2 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_once("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) {
<div class="panel panel-default">
<div class="panel-heading"><h2 class="panel-title"><?=gettext('Results')?></h2></div>
<div class="panel-body">
- <ul class="list-group">
-<?php
- foreach ((array)$resolved as $hostitem) {
-?>
- <li class="list-group-item"><?=$hostitem?></li>
-<?php
- if ($hostitem != "") {
- $found++;
- }
- }
-?>
- </ul>
+
+ <table class="table">
+ <thead>
+ <tr>
+ <th><?=gettext('Result')?></th>
+ <th><?=gettext('Record type')?></th>
+ </tr>
+ </thead>
+ <tbody>
+<?php foreach ((array)$resolved as $hostitem):?>
+ <tr>
+ <td><?=$hostitem['data']?></td><td><?=$hostitem['type']?></td>
+ </tr>
+<?php endforeach; ?>
+ </tbody>
+ </table>
</div>
</div>
<?php endif; ?>
OpenPOWER on IntegriCloud