Project

General

Profile

Download (5.39 KB) Statistics
| Branch: | Tag: | Revision:
1 737ed7d1 jim-p
<?php
2
/*
3
	diag_dns.php
4
5
	Copyright (C) 2009 Jim Pingle (jpingle@gmail.com)
6
	All rights reserved.
7
8
	Redistribution and use in source and binary forms, with or without
9
	modification, are permitted provided that the following conditions are met:
10
11
	1. Redistributions of source code must retain the above copyright notice,
12
	this list of conditions and the following disclaimer.
13
14
	2. Redistributions in binary form must reproduce the above copyright
15
	notice, this list of conditions and the following disclaimer in the
16
	documentation and/or other materials provided with the distribution.
17
18
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
19
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
21
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
22
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27
	POSSIBILITY OF SUCH DAMAGE.
28
*/
29
30 13d193c2 Scott Ullrich
/*
31
	pfSense_MODULE:	dns
32
*/
33
34 6593dae6 jim-p
$pgtitle = array("Diagnostics","DNS Lookup");
35 737ed7d1 jim-p
require("guiconfig.inc");
36
37
/* Cheap hack to support both $_GET and $_POST */
38
if ($_GET['host'])
39
	$_POST = $_GET;
40
41
if ($_POST) {
42
	unset($input_errors);
43
44
	$reqdfields = explode(" ", "host");
45
	$reqdfieldsn = explode(",", "Host");
46
47
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, &$input_errors);
48
	$host = trim($_POST['host']);
49 b97c5ed6 sullrich
	$host_esc = escapeshellarg(trim($_POST['host']));
50
	
51 c1aa682e Chris Buechler
	if (!is_hostname($host) && !is_ipaddr($host)) 
52 737ed7d1 jim-p
		$input_errors[] = "Host must be a valid hostname or IP address.";
53 86ab47ff sullrich
54
	// Test resolution speed of each DNS server.
55
	if ((is_hostname($host) || is_ipaddr($host))) {
56
		$dns_speeds = array();
57
		list($pconfig['dns1'],$pconfig['dns2'],$pconfig['dns3'],$pconfig['dns4']) = $config['system']['dnsserver'];
58
		for ($dnscounter=1; $dnscounter<5; $dnscounter++) {
59
			$dns_server = $pconfig['dns' . $dnscounter];
60 b97c5ed6 sullrich
			$query_time = `dig {$host_esc} @{$dns_server} | grep Query | cut -d':' -f2`;
61 77f87165 sullrich
			if($query_time == "")
62
				$query_time = "No response";
63 86ab47ff sullrich
			$new_qt = array();
64
			$new_qt['dns_server'] = $dns_server;
65 77f87165 sullrich
			$new_qt['query_time'] = $query_time;			
66 86ab47ff sullrich
			$dns_speeds[] = $new_qt;
67
			unset($new_qt);
68
		}
69 737ed7d1 jim-p
	}
70
71
	$type = "unknown";
72
	$resolved = "";
73 2312b0eb jim-p
	$ipaddr = "";
74
	$hostname = "";
75 737ed7d1 jim-p
	if (!$input_errors) {
76
		if (is_ipaddr($host)) {
77
			$type = "ip";
78
			$resolved = gethostbyaddr($host);
79 2312b0eb jim-p
			$ipaddr = $host;
80
			if ($host != $resolved)
81
				$hostname = $resolved;
82 737ed7d1 jim-p
		} elseif (is_hostname($host)) {
83
			$type = "hostname";
84
			$resolved = gethostbyname($host);
85 2312b0eb jim-p
			$hostname = $host;
86
			if ($host != $resolved)
87
				$ipaddr = $resolved;
88 737ed7d1 jim-p
		}
89
90
		if ($host == $resolved) {
91
			$resolved = "No record found";
92
		}
93
	}
94
}
95
96
include("head.inc"); ?>
97
<body link="#000000" vlink="#000000" alink="#000000">
98
<? include("fbegin.inc"); ?>
99
<table width="100%" border="0" cellpadding="0" cellspacing="0">
100
        <tr>
101
                <td>
102
<?php if ($input_errors) print_input_errors($input_errors); ?>
103
	<form action="diag_dns.php" method="post" name="iform" id="iform">
104
	  <table width="100%" border="0" cellpadding="6" cellspacing="0">
105 4c7e2f4e sullrich
		<tr>
106
			<td colspan="2" valign="top" class="listtopic">Resolve DNS hostname or IP</td>
107
		</tr>
108 737ed7d1 jim-p
        <tr>
109
		  <td width="22%" valign="top" class="vncellreq">Hostname or IP</td>
110
		  <td width="78%" class="vtable">
111
            <?=$mandfldhtml;?><input name="host" type="text" class="formfld" id="host" size="20" value="<?=htmlspecialchars($host);?>">
112
			<? if ($resolved && $type) { ?>
113 9080cb52 sullrich
			=  <font size="+1"><?php echo $resolved; ?><font size="-1>">
114 737ed7d1 jim-p
			<?	} ?>
115
		  </td>
116
		</tr>
117 37d98ce7 sullrich
<?php		if($_POST): ?>
118 86ab47ff sullrich
		<tr>
119 b02b3399 sullrich
		  <td width="22%" valign="top" class="vncell">Resolution time per server</td>
120 86ab47ff sullrich
		  <td width="78%" class="vtable">
121 87fa30ba sullrich
				<table width="170" border="1" cellpadding="2" style="border-width: 1px 1px 1px 1px; border-collapse: collapse;">
122 86ab47ff sullrich
					<tr>
123
						<td>
124
							<b>Server</b>
125
						</td>
126
						<td>
127
							<b>Query time</b>
128
						</td>
129
					</tr>
130
<?php
131
					if(is_array($dns_speeds)) 
132
						foreach($dns_speeds as $qt):
133
?>
134
					<tr>
135
						<td>
136
							<?=$qt['dns_server']?>
137
						</td>
138
						<td>
139
							<?=$qt['query_time']?>
140
						</td>
141
					</tr>
142
<?php
143
					endforeach;
144
?>
145
				</table>
146
		  </td>
147
		</tr>
148 37d98ce7 sullrich
		<?php endif; ?>
149 2312b0eb jim-p
		<?php if (!$input_errors && $ipaddr) { ?>
150
		<tr>
151 9080cb52 sullrich
			<td width="22%" valign="top"  class="vncell">More Information:</td>
152 2312b0eb jim-p
			<td width="78%" class="vtable">
153 b8cc74ed sullrich
				<a target="_new" href ="/diag_ping.php?host=<?=$host?>&interface=wan&count=3">Ping</a> <br/>
154
				<a target="_new" href ="/diag_traceroute.php?host=<?=$host?>&ttl=18">Traceroute</a>
155
				<p/>
156
				NOTE: The following links are to external services, so their reliability cannot be guaranteed.<br/><br/>
157 c51684d7 sullrich
				<a target="_new" href="http://private.dnsstuff.com/tools/whois.ch?ip=<?php echo $ipaddr; ?>">IP WHOIS @ DNS Stuff</a><br />
158
				<a target="_new" href="http://private.dnsstuff.com/tools/ipall.ch?ip=<?php echo $ipaddr; ?>">IP Info @ DNS Stuff</a>
159 2312b0eb jim-p
			</td>
160
		</tr>
161
		<?php } ?>
162 737ed7d1 jim-p
		<tr>
163
		  <td width="22%" valign="top">&nbsp;</td>
164
		  <td width="78%">
165 b97c5ed6 sullrich
			<br/>&nbsp;
166 737ed7d1 jim-p
            <input name="Submit" type="submit" class="formbtn" value="DNS Lookup">
167
		</td>
168
		</tr>
169
	</table>
170
</form>
171
</td></tr></table>
172
<?php include("fend.inc"); ?>