Project

General

Profile

Download (7.11 KB) Statistics
| Branch: | Tag: | Revision:

univnautes / usr / local / www / diag_traceroute.php @ a1b66bec

1
<?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
/*
32
	pfSense_BUILDER_BINARIES:	/usr/sbin/traceroute
33
	pfSense_MODULE:	routing
34
*/
35

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

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

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

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

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

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

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

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

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

    
91
?>
92
<?php if ($input_errors) print_input_errors($input_errors); ?>
93
<form action="diag_traceroute.php" method="post" name="iform" id="iform">
94
<table width="100%" border="0" cellpadding="6" cellspacing="0" summary="diag traceroute">
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
		<?php   $sourceips = get_possible_traffic_source_addresses(true);
118
			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=\"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=\"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=\"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
?>
176
	<script type="text/javascript">
177
	//<![CDATA[
178
	window.onload=function(){
179
		document.getElementById("tracerouteCaptured").wrap='off';
180
	}
181
	//]]>
182
	</script>
183
<?php
184
	echo "<textarea id=\"tracerouteCaptured\" style=\"width:98%\" name=\"code\" rows=\"15\" cols=\"66\" readonly=\"readonly\">";
185
	$useicmp = isset($_REQUEST['useicmp']) ? "-I" : "";
186
	$n = isset($resolve) ? "" : "-n";
187

    
188
	$command = "/usr/sbin/traceroute";
189
	if ($ipproto == "ipv6") {
190
		$command .= "6";
191
		$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ipv6($sourceip);
192
	} else {
193
		$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ip($sourceip);
194
	}
195

    
196
	if ($ifaddr && (is_ipaddr($host) || is_hostname($host)))
197
		$srcip = "-s " . escapeshellarg($ifaddr);
198

    
199
	$cmd = "{$command} {$n} {$srcip} -w 2 {$useicmp} -m " . escapeshellarg($ttl) . " " . escapeshellarg($host);
200

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