Project

General

Profile

Download (7.17 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_traceroute.php
4
	part of m0n0wall (http://m0n0.ch/wall)
5

    
6
        Copyright (C) 2013-2014 Electric Sheep Fencing, LP
7
	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
/*
33
	pfSense_BUILDER_BINARIES:	/usr/sbin/traceroute
34
	pfSense_MODULE:	routing
35
*/
36

    
37
##|+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
require("guiconfig.inc");
45

    
46
$allowautocomplete = true;
47
$pgtitle = array(gettext("Diagnostics"),gettext("Traceroute"));
48
include("head.inc");
49

    
50
?>
51
<body link="#000000" vlink="#000000" alink="#000000">
52
<?php include("fbegin.inc"); ?>
53
<?php
54

    
55
define('MAX_TTL', 64);
56
define('DEFAULT_TTL', 18);
57

    
58
if ($_POST || $_REQUEST['host']) {
59
	unset($input_errors);
60
	unset($do_traceroute);
61

    
62
	/* input validation */
63
	$reqdfields = explode(" ", "host ttl");
64
	$reqdfieldsn = array(gettext("Host"),gettext("ttl"));
65
	do_input_validation($_REQUEST, $reqdfields, $reqdfieldsn, $input_errors);
66

    
67
	if (($_REQUEST['ttl'] < 1) || ($_REQUEST['ttl'] > MAX_TTL)) {
68
		$input_errors[] = sprintf(gettext("Maximum number of hops must be between 1 and %s"), MAX_TTL);
69
	}
70
	$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

    
77
	if (!$input_errors) {
78
		$sourceip = $_REQUEST['sourceip'];
79
		$do_traceroute = true;
80
		$ttl = $_REQUEST['ttl'];
81
		$resolve = $_REQUEST['resolve'];
82
	}
83
} else
84
	$resolve = true;
85

    
86
if (!isset($do_traceroute)) {
87
	$do_traceroute = false;
88
	$host = '';
89
	$ttl = DEFAULT_TTL;
90
}
91

    
92
?>
93
<?php if ($input_errors) print_input_errors($input_errors); ?>
94
<form action="diag_traceroute.php" method="post" name="iform" id="iform">
95
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="diag traceroute">
96
<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
		<?=$mandfldhtml;?><input name="host" type="text" class="formfld" id="host" size="20" value="<?=htmlspecialchars($host);?>" /></td>
103
</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
			<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
		</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
		<?php   $sourceips = get_possible_traffic_source_addresses(true);
119
			foreach ($sourceips as $sip):
120
				$selected = "";
121
				if (!link_interface_to_bridge($sip['value']) && ($sip['value'] == $sourceip))
122
					$selected = "selected=\"selected\"";
123
		?>
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
				<option value="<?=$i;?>" <?php if ($i == $ttl) echo "selected=\"selected\""; ?>><?=$i;?></option>
137
			<?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
		<input name="resolve" type="checkbox"<?php echo (!isset($resolve) ? "" : " checked=\"checked\""); ?> />
145
	</td>
146
</tr>
147
<tr>
148
	<td width="22%" valign="top" class="vncellreq"><?=gettext("Use ICMP");?></td>
149
	<td width="78%" class="vtable">
150
		<input name="useicmp" type="checkbox"<?php if($_REQUEST['useicmp']) echo " checked=\"checked\""; ?> />
151
	</td>
152
</tr>
153
<tr>
154
	<td width="22%" valign="top">&nbsp;</td>
155
	<td width="78%">
156
		<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Traceroute");?>" />
157
	</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
		<br /><br />
165
		<?=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
	echo "<font face=\"terminal\" size=\"2\">\n";
174
	echo "<strong>" . gettext("Traceroute output:") . "</strong><br />\n";
175
	ob_end_flush();
176
?>
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
	$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
	$cmd = "{$command} {$n} {$srcip} -w 2 {$useicmp} -m " . escapeshellarg($ttl) . " " . escapeshellarg($host);
201

    
202
	//echo "Traceroute command: {$cmd}\n";
203
	system($cmd);
204
	echo "</textarea>&nbsp;</font>";
205
} ?>
206
	</td>
207
</tr>
208
</table>
209
</form>
210
<?php include("fend.inc"); ?>
211
</body>
212
</html>
(53-53/256)