Project

General

Profile

Download (5.39 KB) Statistics
| Branch: | Tag: | Revision:
1
<?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
/*
31
	pfSense_MODULE:	dns
32
*/
33

    
34
$pgtitle = array("Diagnostics","DNS Lookup");
35
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
	$host_esc = escapeshellarg(trim($_POST['host']));
50
	
51
	if (!is_hostname($host) && !is_ipaddr($host)) 
52
		$input_errors[] = "Host must be a valid hostname or IP address.";
53

    
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
			$query_time = `dig {$host_esc} @{$dns_server} | grep Query | cut -d':' -f2`;
61
			if($query_time == "")
62
				$query_time = "No response";
63
			$new_qt = array();
64
			$new_qt['dns_server'] = $dns_server;
65
			$new_qt['query_time'] = $query_time;			
66
			$dns_speeds[] = $new_qt;
67
			unset($new_qt);
68
		}
69
	}
70

    
71
	$type = "unknown";
72
	$resolved = "";
73
	$ipaddr = "";
74
	$hostname = "";
75
	if (!$input_errors) {
76
		if (is_ipaddr($host)) {
77
			$type = "ip";
78
			$resolved = gethostbyaddr($host);
79
			$ipaddr = $host;
80
			if ($host != $resolved)
81
				$hostname = $resolved;
82
		} elseif (is_hostname($host)) {
83
			$type = "hostname";
84
			$resolved = gethostbyname($host);
85
			$hostname = $host;
86
			if ($host != $resolved)
87
				$ipaddr = $resolved;
88
		}
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
		<tr>
106
			<td colspan="2" valign="top" class="listtopic">Resolve DNS hostname or IP</td>
107
		</tr>
108
        <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
			=  <font size="+1"><?php echo $resolved; ?><font size="-1>">
114
			<?	} ?>
115
		  </td>
116
		</tr>
117
<?php		if($_POST): ?>
118
		<tr>
119
		  <td width="22%" valign="top" class="vncell">Resolution time per server</td>
120
		  <td width="78%" class="vtable">
121
				<table width="170" border="1" cellpadding="2" style="border-width: 1px 1px 1px 1px; border-collapse: collapse;">
122
					<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
		<?php endif; ?>
149
		<?php if (!$input_errors && $ipaddr) { ?>
150
		<tr>
151
			<td width="22%" valign="top"  class="vncell">More Information:</td>
152
			<td width="78%" class="vtable">
153
				<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
				<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
			</td>
160
		</tr>
161
		<?php } ?>
162
		<tr>
163
		  <td width="22%" valign="top">&nbsp;</td>
164
		  <td width="78%">
165
			<br/>&nbsp;
166
            <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"); ?>
(9-9/221)