1 |
93e1b16c
|
Scott Ullrich
|
<?php
|
2 |
|
|
/*
|
3 |
|
|
diag_traceroute.php
|
4 |
|
|
part of m0n0wall (http://m0n0.ch/wall)
|
5 |
|
|
|
6 |
ce77a9c4
|
Phil Davis
|
Copyright (C) 2013-2015 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 |
77af9793
|
sbeaver
|
pfSense_MODULE: routing
|
35 |
13d193c2
|
Scott Ullrich
|
*/
|
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 |
444381d1
|
sbeaver
|
|
50 |
93e1b16c
|
Scott Ullrich
|
define('MAX_TTL', 64);
|
51 |
|
|
define('DEFAULT_TTL', 18);
|
52 |
|
|
|
53 |
77af9793
|
sbeaver
|
$pconfig['ttl'] = DEFAULT_TTL;
|
54 |
|
|
$pconfig['ipproto'] = 'IPv4';
|
55 |
|
|
$pconfig['sourceip'] = 'Any';
|
56 |
|
|
|
57 |
|
|
function create_sourceaddresslist() {
|
58 |
|
|
$list = array('any' => 'Any');
|
59 |
|
|
|
60 |
|
|
$sourceips = get_possible_traffic_source_addresses(true);
|
61 |
|
|
|
62 |
cd7d902d
|
sbeaver
|
foreach ($sourceips as $sipvalue => $sipname)
|
63 |
77af9793
|
sbeaver
|
$list[$sipname[value]] = $sipname[name];
|
64 |
|
|
|
65 |
|
|
return($list);
|
66 |
|
|
}
|
67 |
|
|
|
68 |
b8cc74ed
|
sullrich
|
if ($_POST || $_REQUEST['host']) {
|
69 |
93e1b16c
|
Scott Ullrich
|
unset($input_errors);
|
70 |
|
|
unset($do_traceroute);
|
71 |
|
|
|
72 |
|
|
/* input validation */
|
73 |
|
|
$reqdfields = explode(" ", "host ttl");
|
74 |
6132751b
|
Rafael Lucas
|
$reqdfieldsn = array(gettext("Host"),gettext("ttl"));
|
75 |
1e9b4611
|
Renato Botelho
|
do_input_validation($_REQUEST, $reqdfields, $reqdfieldsn, $input_errors);
|
76 |
444381d1
|
sbeaver
|
|
77 |
b8cc74ed
|
sullrich
|
if (($_REQUEST['ttl'] < 1) || ($_REQUEST['ttl'] > MAX_TTL)) {
|
78 |
ea6be4a7
|
Erik Fonnesbeck
|
$input_errors[] = sprintf(gettext("Maximum number of hops must be between 1 and %s"), MAX_TTL);
|
79 |
93e1b16c
|
Scott Ullrich
|
}
|
80 |
643bc7b0
|
jim-p
|
$host = trim($_REQUEST['host']);
|
81 |
|
|
$ipproto = $_REQUEST['ipproto'];
|
82 |
|
|
if (($ipproto == "ipv4") && is_ipaddrv6($host))
|
83 |
|
|
$input_errors[] = gettext("When using IPv4, the target host must be an IPv4 address or hostname.");
|
84 |
|
|
if (($ipproto == "ipv6") && is_ipaddrv4($host))
|
85 |
|
|
$input_errors[] = gettext("When using IPv6, the target host must be an IPv6 address or hostname.");
|
86 |
93e1b16c
|
Scott Ullrich
|
|
87 |
77af9793
|
sbeaver
|
if (!$input_errors)
|
88 |
444381d1
|
sbeaver
|
$host = $_REQUEST['host'];
|
89 |
|
|
|
90 |
77af9793
|
sbeaver
|
$sourceip = $_REQUEST['sourceip'];
|
91 |
|
|
$do_traceroute = true;
|
92 |
|
|
$ttl = $_REQUEST['ttl'];
|
93 |
|
|
$resolve = $_REQUEST['resolve'];
|
94 |
|
|
$useicmp = $_REQUEST['useicmp'];
|
95 |
|
|
|
96 |
|
|
} else {
|
97 |
|
|
$resolve = false;
|
98 |
444381d1
|
sbeaver
|
$useicmp = false;
|
99 |
77af9793
|
sbeaver
|
}
|
100 |
99e991fd
|
Warren Baker
|
|
101 |
93e1b16c
|
Scott Ullrich
|
if (!isset($do_traceroute)) {
|
102 |
|
|
$do_traceroute = false;
|
103 |
|
|
$host = '';
|
104 |
|
|
$ttl = DEFAULT_TTL;
|
105 |
|
|
}
|
106 |
99e991fd
|
Warren Baker
|
|
107 |
77af9793
|
sbeaver
|
if ($input_errors)
|
108 |
|
|
print_input_errors($input_errors);
|
109 |
444381d1
|
sbeaver
|
|
110 |
77af9793
|
sbeaver
|
require('classes/Form.class.php');
|
111 |
|
|
|
112 |
38e06c66
|
Sjon Hortensius
|
$form = new Form('Traceroute');
|
113 |
77af9793
|
sbeaver
|
|
114 |
|
|
$section = new Form_Section('Traceroute');
|
115 |
|
|
|
116 |
|
|
$section->addInput(new Form_Input(
|
117 |
|
|
'host',
|
118 |
|
|
'Hostname',
|
119 |
|
|
'text',
|
120 |
|
|
$host,
|
121 |
|
|
['placeholder' => 'Hostname to trace.']
|
122 |
|
|
));
|
123 |
|
|
|
124 |
|
|
$section->addInput(new Form_Select(
|
125 |
|
|
'ipproto',
|
126 |
|
|
'IP Protocol',
|
127 |
|
|
$pconfig['protocol'],
|
128 |
|
|
array('ipv4' => 'IPv4', 'ipv6' => 'IPv6')
|
129 |
|
|
))->setHelp('Select the protocol to use');
|
130 |
|
|
|
131 |
|
|
$section->addInput(new Form_Select(
|
132 |
|
|
'sourceip',
|
133 |
|
|
'Source Address',
|
134 |
|
|
$pconfig['source'],
|
135 |
|
|
create_sourceaddresslist()
|
136 |
|
|
))->setHelp('Select source address for the trace');
|
137 |
|
|
|
138 |
|
|
$section->addInput(new Form_Select(
|
139 |
|
|
'ttl',
|
140 |
|
|
'Maximum nuber of hops',
|
141 |
|
|
$ttl,
|
142 |
cd7d902d
|
sbeaver
|
array_combine(range(1, MAX_TTL), range(1, MAX_TTL))
|
143 |
77af9793
|
sbeaver
|
))->setHelp('Select the maximum number of network hops to trace');
|
144 |
|
|
|
145 |
|
|
$section->addInput(new Form_Checkbox(
|
146 |
|
|
'resolve',
|
147 |
|
|
'Reverse Address Lookup',
|
148 |
|
|
'',
|
149 |
|
|
$resolve
|
150 |
|
|
))->setHelp('When checked, traceroute will attempt to perform a PTR lookup to locate hostnames for hops along the path. Will slow down the process as it has to wait for DNS replies.');
|
151 |
|
|
|
152 |
|
|
$section->addInput(new Form_Checkbox(
|
153 |
|
|
'useicmp',
|
154 |
|
|
gettext("Use ICMP"),
|
155 |
|
|
'',
|
156 |
|
|
$useicmp
|
157 |
|
|
))->setHelp('By default, traceroute uses UDP but that may be blocked by some routers. Check this box to use ICMP instead, which may succeed. ');
|
158 |
|
|
|
159 |
|
|
$form->add($section);
|
160 |
|
|
print $form;
|
161 |
|
|
|
162 |
|
|
/* Show the traceroute results */
|
163 |
|
|
if (!$input_errors && $do_traceroute) {
|
164 |
|
|
|
165 |
643bc7b0
|
jim-p
|
$useicmp = isset($_REQUEST['useicmp']) ? "-I" : "";
|
166 |
|
|
$n = isset($resolve) ? "" : "-n";
|
167 |
|
|
|
168 |
|
|
$command = "/usr/sbin/traceroute";
|
169 |
|
|
if ($ipproto == "ipv6") {
|
170 |
|
|
$command .= "6";
|
171 |
|
|
$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ipv6($sourceip);
|
172 |
|
|
} else {
|
173 |
|
|
$ifaddr = is_ipaddr($sourceip) ? $sourceip : get_interface_ip($sourceip);
|
174 |
|
|
}
|
175 |
|
|
|
176 |
|
|
if ($ifaddr && (is_ipaddr($host) || is_hostname($host)))
|
177 |
|
|
$srcip = "-s " . escapeshellarg($ifaddr);
|
178 |
|
|
|
179 |
f09c5600
|
jim-p
|
$cmd = "{$command} {$n} {$srcip} -w 2 {$useicmp} -m " . escapeshellarg($ttl) . " " . escapeshellarg($host);
|
180 |
444381d1
|
sbeaver
|
?>
|
181 |
|
|
<div class="panel panel-default">
|
182 |
|
|
<div class="panel-heading">Results</div>
|
183 |
|
|
<div class="panel-body">
|
184 |
|
|
<?php
|
185 |
|
|
if ($result = shell_exec($cmd))
|
186 |
|
|
print(nl2br($result));
|
187 |
|
|
else
|
188 |
|
|
print('Error: ' . $host . ' ' . gettext("could not be traced/resolved"));
|
189 |
|
|
?>
|
190 |
|
|
</div>
|
191 |
|
|
</div>
|
192 |
|
|
<?php
|
193 |
77af9793
|
sbeaver
|
}
|
194 |
|
|
|
195 |
|
|
include("foot.inc");
|
196 |
|
|
?>
|