Revision 643bc7b0
Added by Jim Pingle over 12 years ago
usr/local/www/diag_traceroute.php | ||
---|---|---|
28 | 28 |
POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
*/ |
30 | 30 |
|
31 |
/*
|
|
31 |
/* |
|
32 | 32 |
pfSense_BUILDER_BINARIES: /usr/sbin/traceroute |
33 | 33 |
pfSense_MODULE: routing |
34 | 34 |
*/ |
... | ... | |
42 | 42 |
|
43 | 43 |
require("guiconfig.inc"); |
44 | 44 |
|
45 |
$allowautocomplete = true; |
|
45 | 46 |
$pgtitle = array(gettext("Diagnostics"),gettext("Traceroute")); |
46 | 47 |
include("head.inc"); |
47 | 48 |
|
... | ... | |
65 | 66 |
if (($_REQUEST['ttl'] < 1) || ($_REQUEST['ttl'] > MAX_TTL)) { |
66 | 67 |
$input_errors[] = sprintf(gettext("Maximum number of hops must be between 1 and %s"), MAX_TTL); |
67 | 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."); |
|
68 | 75 |
|
69 | 76 |
if (!$input_errors) { |
70 |
$gateway = $_REQUEST['gateway'];
|
|
77 |
$sourceip = $_REQUEST['sourceip'];
|
|
71 | 78 |
$do_traceroute = true; |
72 |
$host = $_REQUEST['host']; |
|
73 | 79 |
$ttl = $_REQUEST['ttl']; |
74 | 80 |
$resolve = $_REQUEST['resolve']; |
75 | 81 |
} |
... | ... | |
84 | 90 |
|
85 | 91 |
?> |
86 | 92 |
<?php if ($input_errors) print_input_errors($input_errors); ?> |
87 |
<form action="diag_traceroute.php" method="post" name="iform" id="iform"> |
|
88 |
<table width="100%" border="0" cellpadding="6" cellspacing="0"> |
|
89 |
<tr> |
|
90 |
<td colspan="2" valign="top" class="listtopic"><?=gettext("Traceroute");?></td> |
|
91 |
</tr> |
|
92 |
<tr> |
|
93 |
<td width="22%" valign="top" class="vncellreq"><?=gettext("Host");?></td> |
|
94 |
<td width="78%" class="vtable"> |
|
95 |
<?=$mandfldhtml;?><input name="host" type="text" class="formfld" id="host" size="20" value="<?=htmlspecialchars($host);?>"></td> |
|
96 |
</tr> |
|
97 |
<tr> |
|
98 |
<td width="22%" valign="top" class="vncellreq"><?=gettext("Gateway"); ?></td> |
|
99 |
<td width="78%" class="vtable"> |
|
100 |
<select name="gateway" class="formfld"> |
|
101 |
<option value="default" <?php echo ($interface == "default" ? "selected" : "") ?>>Default</option> |
|
102 |
<?php $gateways = return_gateways_array(); |
|
103 |
foreach ($gateways as $gwname => $gwitem): ?> |
|
104 |
<option value="<?=$gwitem['interface'];?>" <?php if (!link_interface_to_bridge($gwitem['friendlyiface']) && $gwitem['interface'] == $gateway) echo "selected"; ?>> |
|
105 |
<?=htmlspecialchars($gwname);?> |
|
106 |
</option> |
|
107 |
<?php endforeach; ?> |
|
108 |
</select> |
|
109 |
</td> |
|
110 |
</tr> |
|
111 |
<tr> |
|
112 |
<td width="22%" valign="top" class="vncellreq"><?=gettext("Maximum number of hops");?></td> |
|
113 |
<td width="78%" class="vtable"> |
|
114 |
<select name="ttl" class="formfld" id="ttl"> |
|
115 |
<?php for ($i = 1; $i <= MAX_TTL; $i++): ?> |
|
116 |
<option value="<?=$i;?>" <?php if ($i == $ttl) echo "selected"; ?>><?=$i;?></option> |
|
117 |
<?php endfor; ?> |
|
118 |
</select> |
|
119 |
</td> |
|
120 |
</tr> |
|
121 |
<tr> |
|
122 |
<td width="22%" valign="top" class="vncellreq"><?=gettext("Reverse Address Lookup");?></td> |
|
123 |
<td width="78%" class="vtable"> |
|
124 |
<input name="resolve" type="checkbox"<?php echo (!isset($resolve) ? "" : " CHECKED"); ?>> |
|
125 |
</td> |
|
126 |
</tr> |
|
127 |
<tr> |
|
128 |
<td width="22%" valign="top" class="vncellreq"><?=gettext("Use ICMP");?></td> |
|
129 |
<td width="78%" class="vtable"> |
|
130 |
<input name="useicmp" type="checkbox"<?php if($_REQUEST['useicmp']) echo " CHECKED"; ?>> |
|
131 |
</td> |
|
132 |
</tr> |
|
133 |
<tr> |
|
134 |
<td width="22%" valign="top"> </td> |
|
135 |
<td width="78%"> |
|
136 |
<input name="Submit" type="submit" class="formbtn" value="<?=gettext("Traceroute");?>"> |
|
137 |
</td> |
|
138 |
</tr> |
|
139 |
<tr> |
|
140 |
<td valign="top" colspan="2"> |
|
141 |
<p><span class="vexpl"><span class="red"><b><?=gettext("Note: ");?></b></span><?=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.");?></span><p> |
|
142 |
<?php if ($do_traceroute) { |
|
143 |
echo "<font face='terminal' size='2'>"; |
|
144 |
echo("<br><strong>" . gettext("Traceroute output:") . "</strong><br>"); |
|
145 |
echo('<pre>'); |
|
146 |
ob_end_flush(); |
|
147 |
$useicmp = isset($_REQUEST['useicmp']) ? "-I" : ""; |
|
148 |
$srcint = ($gateway != "default") ? "-i " . escapeshellarg(get_real_interface($gateway)) : ""; |
|
149 |
$n = isset($resolve) ? "" : "-n"; |
|
150 |
system("/usr/sbin/traceroute $n $srcint $useicmp -w 2 -m " . escapeshellarg($ttl) . " " . escapeshellarg($host)); |
|
151 |
system("/usr/sbin/traceroute6 $n $srcint $useicmp -w 2 -m " . escapeshellarg($ttl) . " " . escapeshellarg($host)); |
|
152 |
echo('</pre>'); |
|
153 |
} |
|
154 |
?> |
|
155 |
</td> |
|
156 |
</tr> |
|
157 |
</table> |
|
93 |
<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 |
<?php $sourceips = get_possible_traffic_source_addresses(); |
|
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"; ?>><?=$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"> </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 |
$cmd = "{$command} {$n} {$srcip} -w 2 -m " . escapeshellarg($ttl) . " " . escapeshellarg($host); |
|
191 |
|
|
192 |
//echo "Traceroute command: {$cmd}\n"; |
|
193 |
system($cmd); |
|
194 |
echo "</pre>\n"; |
|
195 |
} ?> |
|
196 |
</td> |
|
197 |
</tr> |
|
198 |
</table> |
|
158 | 199 |
</form> |
159 | 200 |
<?php include("fend.inc"); ?> |
Also available in: Unified diff
Fix up traceroute page to allow it to use all possible source addresses, add selection for IPv4/IPv6, allow autocomplete, clean up HTML/whitespace, correct output formatting.