Project

General

Profile

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