summaryrefslogtreecommitdiffstats
path: root/src/usr/local/www/diag_dns.php
diff options
context:
space:
mode:
authorChris Buechler <cmb@pfsense.org>2016-06-29 23:30:12 -0500
committerChris Buechler <cmb@pfsense.org>2016-06-29 23:30:12 -0500
commitf48034878df5acd2d6e744105db99153b0dc19a8 (patch)
tree062aa567fa65affac054e4998d01290f27904702 /src/usr/local/www/diag_dns.php
parent9a8b5401c4ca4ead4542fd9b7184d8ed6a040f30 (diff)
parentba40ee75f1565d2135c9de1b2e931c16c99eadb5 (diff)
downloadpfsense-f48034878df5acd2d6e744105db99153b0dc19a8.zip
pfsense-f48034878df5acd2d6e744105db99153b0dc19a8.tar.gz
Merge pull request #3028 from PiBa-NL/2.3_dnsV6
Diffstat (limited to 'src/usr/local/www/diag_dns.php')
-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