Project

General

Profile

Download (6.73 KB) Statistics
| Branch: | Tag: | Revision:
1 93e1b16c Scott Ullrich
<?php
2
/*
3
	diag_traceroute.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5
6
	Copyright (C) 2005 Paul Taylor (paultaylor@winndixie.com) and Manuel Kasper <mk@neon1.net>.
7
	All rights reserved.
8
9
	Redistribution and use in source and binary forms, with or without
10
	modification, are permitted provided that the following conditions are met:
11
12
	1. Redistributions of source code must retain the above copyright notice,
13
	this list of conditions and the following disclaimer.
14
15
	2. Redistributions in binary form must reproduce the above copyright
16
	notice, this list of conditions and the following disclaimer in the
17
	documentation and/or other materials provided with the distribution.
18
19
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
20
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
21
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28
	POSSIBILITY OF SUCH DAMAGE.
29
*/
30
31 643bc7b0 jim-p
/*
32 13d193c2 Scott Ullrich
	pfSense_BUILDER_BINARIES:	/usr/sbin/traceroute
33
	pfSense_MODULE:	routing
34
*/
35
36 6b07c15a Matthew Grooms
##|+PRIV
37
##|*IDENT=page-diagnostics-traceroute
38
##|*NAME=Diagnostics: Traceroute page
39
##|*DESCR=Allow access to the 'Diagnostics: Traceroute' page.
40
##|*MATCH=diag_traceroute.php*
41
##|-PRIV
42
43 b8a66425 Scott Ullrich
require("guiconfig.inc");
44 13d193c2 Scott Ullrich
45 643bc7b0 jim-p
$allowautocomplete = true;
46 6132751b Rafael Lucas
$pgtitle = array(gettext("Diagnostics"),gettext("Traceroute"));
47 b8a66425 Scott Ullrich
include("head.inc");
48 13d193c2 Scott Ullrich
49 b8a66425 Scott Ullrich
?>
50
<body link="#000000" vlink="#000000" alink="#000000">
51 a3381369 Colin Fleming
<?php include("fbegin.inc"); ?>
52 43fdebc5 Scott Ullrich
<?php
53
54 93e1b16c Scott Ullrich
define('MAX_TTL', 64);
55
define('DEFAULT_TTL', 18);
56
57 b8cc74ed sullrich
if ($_POST || $_REQUEST['host']) {
58 93e1b16c Scott Ullrich
	unset($input_errors);
59
	unset($do_traceroute);
60
61
	/* input validation */
62
	$reqdfields = explode(" ", "host ttl");
63 6132751b Rafael Lucas
	$reqdfieldsn = array(gettext("Host"),gettext("ttl"));
64 b8cc74ed sullrich
	do_input_validation($_REQUEST, $reqdfields, $reqdfieldsn, &$input_errors);
65 93e1b16c Scott Ullrich
66 b8cc74ed sullrich
	if (($_REQUEST['ttl'] < 1) || ($_REQUEST['ttl'] > MAX_TTL)) {
67 ea6be4a7 Erik Fonnesbeck
		$input_errors[] = sprintf(gettext("Maximum number of hops must be between 1 and %s"), MAX_TTL);
68 93e1b16c Scott Ullrich
	}
69 643bc7b0 jim-p
	$host = trim($_REQUEST['host']);
70
	$ipproto = $_REQUEST['ipproto'];
71
	if (($ipproto == "ipv4") && is_ipaddrv6($host))
72
		$input_errors[] = gettext("When using IPv4, the target host must be an IPv4 address or hostname.");
73
	if (($ipproto == "ipv6") && is_ipaddrv4($host))
74
		$input_errors[] = gettext("When using IPv6, the target host must be an IPv6 address or hostname.");
75 93e1b16c Scott Ullrich
76
	if (!$input_errors) {
77 643bc7b0 jim-p
		$sourceip = $_REQUEST['sourceip'];
78 93e1b16c Scott Ullrich
		$do_traceroute = true;
79 b8cc74ed sullrich
		$ttl = $_REQUEST['ttl'];
80 99e991fd Warren Baker
		$resolve = $_REQUEST['resolve'];
81 93e1b16c Scott Ullrich
	}
82 99e991fd Warren Baker
} else
83
	$resolve = true;
84
85 93e1b16c Scott Ullrich
if (!isset($do_traceroute)) {
86
	$do_traceroute = false;
87
	$host = '';
88
	$ttl = DEFAULT_TTL;
89
}
90 99e991fd Warren Baker
91 93e1b16c Scott Ullrich
?>
92
<?php if ($input_errors) print_input_errors($input_errors); ?>
93 643bc7b0 jim-p
<form action="diag_traceroute.php" method="post" name="iform" id="iform">
94
<table width="100%" border="0" cellpadding="6" cellspacing="0">
95
<tr>
96
	<td colspan="2" valign="top" class="listtopic"><?=gettext("Traceroute");?></td>
97
</tr>
98
<tr>
99
	<td width="22%" valign="top" class="vncellreq"><?=gettext("Host");?></td>
100
	<td width="78%" class="vtable">
101
		<?=$mandfldhtml;?><input name="host" type="text" class="formfld" id="host" size="20" value="<?=htmlspecialchars($host);?>"></td>
102
</tr>
103
<tr>
104
	<td width="22%" valign="top" class="vncellreq"><?=gettext("IP Protocol"); ?></td>
105
	<td width="78%" class="vtable">
106
		<select name="ipproto" class="formselect">
107
			<option value="ipv4" <?php if ($ipproto == "ipv4") echo 'selected="selected"' ?>>IPv4</option>
108
			<option value="ipv6" <?php if ($ipproto == "ipv6") echo 'selected="selected"' ?>>IPv6</option>
109
		</select>
110
	</td>
111
</tr>
112
<tr>
113
	<td width="22%" valign="top" class="vncell"><?=gettext("Source Address"); ?></td>
114
	<td width="78%" class="vtable">
115
		<select name="sourceip" class="formselect">
116
			<option value="">Any</option>
117 81448ffa jim-p
		<?php   $sourceips = get_possible_traffic_source_addresses(true);
118 643bc7b0 jim-p
			foreach ($sourceips as $sip):
119
				$selected = "";
120
				if (!link_interface_to_bridge($sip['value']) && ($sip['value'] == $sourceip))
121
					$selected = 'selected="selected"';
122
		?>
123
			<option value="<?=$sip['value'];?>" <?=$selected;?>>
124
				<?=htmlspecialchars($sip['name']);?>
125
			</option>
126
			<?php endforeach; ?>
127
		</select>
128
	</td>
129
</tr>
130
<tr>
131
	<td width="22%" valign="top" class="vncellreq"><?=gettext("Maximum number of hops");?></td>
132
	<td width="78%" class="vtable">
133
		<select name="ttl" class="formfld" id="ttl">
134
			<?php for ($i = 1; $i <= MAX_TTL; $i++): ?>
135
				<option value="<?=$i;?>" <?php if ($i == $ttl) echo "selected"; ?>><?=$i;?></option>
136
			<?php endfor; ?>
137
		</select>
138
	</td>
139
</tr>
140
<tr>
141
	<td width="22%" valign="top" class="vncellreq"><?=gettext("Reverse Address Lookup");?></td>
142
	<td width="78%" class="vtable">
143
		<input name="resolve" type="checkbox"<?php echo (!isset($resolve) ? "" : " CHECKED"); ?>>
144
	</td>
145
</tr>
146
<tr>
147
	<td width="22%" valign="top" class="vncellreq"><?=gettext("Use ICMP");?></td>
148
	<td width="78%" class="vtable">
149
		<input name="useicmp" type="checkbox"<?php if($_REQUEST['useicmp']) echo " CHECKED"; ?>>
150
	</td>
151
</tr>
152
<tr>
153
	<td width="22%" valign="top">&nbsp;</td>
154
	<td width="78%">
155
		<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Traceroute");?>">
156
	</td>
157
</tr>
158
<tr>
159
	<td valign="top" colspan="2">
160
	<span class="vexpl">
161
		<span class="red"><b><?=gettext("Note: ");?></b></span>
162
		<?=gettext("Traceroute may take a while to complete. You may hit the Stop button on your browser at any time to see the progress of failed traceroutes.");?>
163
		<br/><br/>
164
		<?=gettext("Using a source interface/IP address that does not match selected type (IPv4, IPv6) will result in an error or empty output.");?>
165
	</span>
166
	</td>
167
</tr>
168
<tr>
169
	<td valign="top" colspan="2">
170
<?php
171
if ($do_traceroute) {
172
	echo "<font face='terminal' size='2'>\n";
173
	echo "<strong>" . gettext("Traceroute output:") . "</strong><br />\n";
174
	ob_end_flush();
175
	echo "<pre>\n";
176
	$useicmp = isset($_REQUEST['useicmp']) ? "-I" : "";
177
	$n = isset($resolve) ? "" : "-n";
178
179
	$command = "/usr/sbin/traceroute";
180
	if ($ipproto == "ipv6") {
181
		$command .= "6";
182
		$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ipv6($sourceip);
183
	} else {
184
		$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ip($sourceip);
185
	}
186
187
	if ($ifaddr && (is_ipaddr($host) || is_hostname($host)))
188
		$srcip = "-s " . escapeshellarg($ifaddr);
189
190 f09c5600 jim-p
	$cmd = "{$command} {$n} {$srcip} -w 2 {$useicmp} -m " . escapeshellarg($ttl) . " " . escapeshellarg($host);
191 643bc7b0 jim-p
192
	//echo "Traceroute command: {$cmd}\n";
193
	system($cmd);
194
	echo "</pre>\n";
195
} ?>
196
	</td>
197
</tr>
198
</table>
199 93e1b16c Scott Ullrich
</form>
200
<?php include("fend.inc"); ?>