summaryrefslogtreecommitdiffstats
path: root/src/usr
diff options
context:
space:
mode:
authorPiBa-NL <pba_2k3@yahoo.com>2016-05-23 01:19:08 +0200
committerPiBa-NL <pba_2k3@yahoo.com>2016-06-29 22:03:44 +0200
commitba40ee75f1565d2135c9de1b2e931c16c99eadb5 (patch)
tree13b85950c9a10417c5776ed3d7a118871bb18394 /src/usr
parenta3013ca688ce6e8b506fa2a5c6251f77778e39bc (diff)
downloadpfsense-ba40ee75f1565d2135c9de1b2e931c16c99eadb5.zip
pfsense-ba40ee75f1565d2135c9de1b2e931c16c99eadb5.tar.gz
Diagnostics - DNS Lookup, also query for IPv6 addresses
Diffstat (limited to 'src/usr')
-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 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) {
<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