1 |
0eacb3b2
|
Scott Ullrich
|
<?php
|
2 |
|
|
|
3 |
|
|
/* $Id$ */
|
4 |
|
|
/*
|
5 |
|
|
diag_routes.php
|
6 |
|
|
*/
|
7 |
fd9ebcd5
|
Stephen Beaver
|
/* ====================================================================
|
8 |
|
|
* Copyright (c) 2004-2015 Electric Sheep Fencing, LLC. All rights reserved.
|
9 |
|
|
* Copyright (c) 2006 Fernando Lamos
|
10 |
|
|
*
|
11 |
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
12 |
|
|
* are permitted provided that the following conditions are met:
|
13 |
|
|
*
|
14 |
|
|
* 1. Redistributions of source code must retain the above copyright notice,
|
15 |
|
|
* this list of conditions and the following disclaimer.
|
16 |
|
|
*
|
17 |
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
18 |
|
|
* notice, this list of conditions and the following disclaimer in
|
19 |
|
|
* the documentation and/or other materials provided with the
|
20 |
|
|
* distribution.
|
21 |
|
|
*
|
22 |
|
|
* 3. All advertising materials mentioning features or use of this software
|
23 |
|
|
* must display the following acknowledgment:
|
24 |
|
|
* "This product includes software developed by the pfSense Project
|
25 |
|
|
* for use in the pfSense software distribution. (http://www.pfsense.org/).
|
26 |
|
|
*
|
27 |
|
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
28 |
|
|
* endorse or promote products derived from this software without
|
29 |
|
|
* prior written permission. For written permission, please contact
|
30 |
|
|
* coreteam@pfsense.org.
|
31 |
|
|
*
|
32 |
|
|
* 5. Products derived from this software may not be called "pfSense"
|
33 |
|
|
* nor may "pfSense" appear in their names without prior written
|
34 |
|
|
* permission of the Electric Sheep Fencing, LLC.
|
35 |
|
|
*
|
36 |
|
|
* 6. Redistributions of any form whatsoever must retain the following
|
37 |
|
|
* acknowledgment:
|
38 |
|
|
*
|
39 |
|
|
* "This product includes software developed by the pfSense Project
|
40 |
|
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
41 |
|
|
*
|
42 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
43 |
|
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
44 |
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
45 |
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
46 |
|
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
47 |
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
48 |
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
49 |
|
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
50 |
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
51 |
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
52 |
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
53 |
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
54 |
|
|
*
|
55 |
|
|
* ====================================================================
|
56 |
|
|
*
|
57 |
|
|
*/
|
58 |
13d193c2
|
Scott Ullrich
|
/*
|
59 |
45d6ada5
|
Sjon Hortensius
|
pfSense_BUILDER_BINARIES: /usr/bin/netstat
|
60 |
13d193c2
|
Scott Ullrich
|
pfSense_MODULE: routing
|
61 |
|
|
*/
|
62 |
6b07c15a
|
Matthew Grooms
|
##|+PRIV
|
63 |
|
|
##|*IDENT=page-diagnostics-routingtables
|
64 |
|
|
##|*NAME=Diagnostics: Routing tables page
|
65 |
|
|
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
|
66 |
|
|
##|*MATCH=diag_routes.php*
|
67 |
|
|
##|-PRIV
|
68 |
|
|
|
69 |
0eacb3b2
|
Scott Ullrich
|
include('guiconfig.inc');
|
70 |
|
|
|
71 |
288a2a0f
|
Phil Davis
|
$limit = '100';
|
72 |
|
|
$filter = '';
|
73 |
45d6ada5
|
Sjon Hortensius
|
|
74 |
92e8cb11
|
Renato Botelho
|
if (isset($_REQUEST['isAjax'])) {
|
75 |
|
|
$netstat = "/usr/bin/netstat -rW";
|
76 |
|
|
if (isset($_REQUEST['IPv6'])) {
|
77 |
|
|
$netstat .= " -f inet6";
|
78 |
|
|
echo "IPv6\n";
|
79 |
|
|
} else {
|
80 |
|
|
$netstat .= " -f inet";
|
81 |
|
|
echo "IPv4\n";
|
82 |
45d6ada5
|
Sjon Hortensius
|
|
83 |
92e8cb11
|
Renato Botelho
|
}
|
84 |
5f601060
|
Phil Davis
|
if (!isset($_REQUEST['resolve'])) {
|
85 |
92e8cb11
|
Renato Botelho
|
$netstat .= " -n";
|
86 |
5f601060
|
Phil Davis
|
}
|
87 |
92e8cb11
|
Renato Botelho
|
|
88 |
5f601060
|
Phil Davis
|
if (!empty($_REQUEST['filter'])) {
|
89 |
92e8cb11
|
Renato Botelho
|
$netstat .= " | /usr/bin/sed -e '1,3d; 5,\$ { /" . escapeshellarg(htmlspecialchars($_REQUEST['filter'])) . "/!d; };'";
|
90 |
5f601060
|
Phil Davis
|
} else {
|
91 |
92e8cb11
|
Renato Botelho
|
$netstat .= " | /usr/bin/sed -e '1,3d'";
|
92 |
5f601060
|
Phil Davis
|
}
|
93 |
92e8cb11
|
Renato Botelho
|
|
94 |
5f601060
|
Phil Davis
|
if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
|
95 |
92e8cb11
|
Renato Botelho
|
$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
|
96 |
5f601060
|
Phil Davis
|
}
|
97 |
92e8cb11
|
Renato Botelho
|
|
98 |
|
|
echo htmlspecialchars_decode(shell_exec($netstat));
|
99 |
|
|
|
100 |
|
|
exit;
|
101 |
|
|
}
|
102 |
|
|
|
103 |
699737d9
|
Phil Davis
|
$pgtitle = array(gettext("Diagnostics"), gettext("Routing tables"));
|
104 |
b32dd0a6
|
jim-p
|
$shortcut_section = "routing";
|
105 |
0eacb3b2
|
Scott Ullrich
|
|
106 |
|
|
include('head.inc');
|
107 |
|
|
|
108 |
ad2879b8
|
PiBa-NL
|
require_once('classes/Form.class.php');
|
109 |
45d6ada5
|
Sjon Hortensius
|
|
110 |
38e06c66
|
Sjon Hortensius
|
$form = new Form('Update');
|
111 |
45d6ada5
|
Sjon Hortensius
|
$form->addGlobal(new Form_Input(
|
112 |
|
|
'isAjax',
|
113 |
|
|
null,
|
114 |
|
|
'hidden',
|
115 |
|
|
1
|
116 |
|
|
));
|
117 |
|
|
$section = new Form_Section('Traceroute');
|
118 |
|
|
|
119 |
|
|
$section->addInput(new Form_Checkbox(
|
120 |
|
|
'resolve',
|
121 |
|
|
'Resolve names',
|
122 |
|
|
'Enable',
|
123 |
|
|
$resolve
|
124 |
288a2a0f
|
Phil Davis
|
))->setHelp('Enabling name resolution may cause the query to take longer.'.
|
125 |
45d6ada5
|
Sjon Hortensius
|
' You can stop it at any time by clicking the Stop button in your browser.');
|
126 |
|
|
|
127 |
|
|
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
|
128 |
|
|
$section->addInput(new Form_Select(
|
129 |
|
|
'limit',
|
130 |
|
|
'Rows to display',
|
131 |
|
|
$limit,
|
132 |
|
|
array_combine($validLimits, $validLimits)
|
133 |
|
|
));
|
134 |
|
|
|
135 |
|
|
$section->addInput(new Form_Input(
|
136 |
|
|
'filter',
|
137 |
|
|
'Filter',
|
138 |
|
|
'text',
|
139 |
|
|
$host
|
140 |
|
|
))->setHelp('Use a regular expression to filter IP address or hostnames');
|
141 |
|
|
|
142 |
|
|
$form->add($section);
|
143 |
|
|
print $form;
|
144 |
0eacb3b2
|
Scott Ullrich
|
?>
|
145 |
45d6ada5
|
Sjon Hortensius
|
<script>
|
146 |
|
|
function update_routes(section) {
|
147 |
|
|
$.ajax(
|
148 |
|
|
'/diag_routes.php',
|
149 |
|
|
{
|
150 |
|
|
type: 'post',
|
151 |
|
|
data: $(document.forms[0]).serialize() +'&'+ section +'=true',
|
152 |
|
|
success: update_routes_callback,
|
153 |
|
|
});
|
154 |
|
|
}
|
155 |
92e8cb11
|
Renato Botelho
|
|
156 |
45d6ada5
|
Sjon Hortensius
|
function update_routes_callback(html) {
|
157 |
|
|
// First line contains section
|
158 |
|
|
var responseTextArr = html.split("\n");
|
159 |
|
|
var section = responseTextArr.shift();
|
160 |
|
|
var tbody = '';
|
161 |
|
|
var field = '';
|
162 |
|
|
var tr_class = '';
|
163 |
|
|
var thead = '<tr>';
|
164 |
|
|
|
165 |
|
|
for (var i = 0; i < responseTextArr.length; i++) {
|
166 |
|
|
if (responseTextArr[i] == "")
|
167 |
|
|
continue;
|
168 |
|
|
var tmp = '<tr>';
|
169 |
|
|
var j = 0;
|
170 |
|
|
var entry = responseTextArr[i].split(" ");
|
171 |
|
|
for (var k = 0; k < entry.length; k++) {
|
172 |
|
|
if (entry[k] == "")
|
173 |
92e8cb11
|
Renato Botelho
|
continue;
|
174 |
|
|
if (i == 0)
|
175 |
45d6ada5
|
Sjon Hortensius
|
tmp += '<th>' + entry[k] + '<\/th>';
|
176 |
92e8cb11
|
Renato Botelho
|
else
|
177 |
45d6ada5
|
Sjon Hortensius
|
tmp += '<td>' + entry[k] + '<\/td>';
|
178 |
|
|
j++;
|
179 |
92e8cb11
|
Renato Botelho
|
}
|
180 |
45d6ada5
|
Sjon Hortensius
|
|
181 |
|
|
tmp += '<td><\/td>';
|
182 |
|
|
|
183 |
|
|
if (i == 0)
|
184 |
|
|
thead += tmp;
|
185 |
|
|
else
|
186 |
|
|
tbody += tmp;
|
187 |
92e8cb11
|
Renato Botelho
|
}
|
188 |
|
|
|
189 |
45d6ada5
|
Sjon Hortensius
|
$('#' + section + ' > thead').html(thead);
|
190 |
|
|
$('#' + section + ' > tbody').html(tbody);
|
191 |
|
|
}
|
192 |
92e8cb11
|
Renato Botelho
|
|
193 |
45d6ada5
|
Sjon Hortensius
|
function update_all_routes() {
|
194 |
|
|
update_routes("IPv4");
|
195 |
|
|
update_routes("IPv6");
|
196 |
|
|
}
|
197 |
92e8cb11
|
Renato Botelho
|
|
198 |
45d6ada5
|
Sjon Hortensius
|
events.push(function(){
|
199 |
|
|
setInterval('update_all_routes()', 5000);
|
200 |
|
|
update_all_routes();
|
201 |
92e8cb11
|
Renato Botelho
|
|
202 |
45d6ada5
|
Sjon Hortensius
|
$(document.forms[0]).on('submit', function(e){
|
203 |
|
|
update_all_routes();
|
204 |
92e8cb11
|
Renato Botelho
|
|
205 |
45d6ada5
|
Sjon Hortensius
|
e.preventDefault();
|
206 |
|
|
});
|
207 |
|
|
});
|
208 |
92e8cb11
|
Renato Botelho
|
</script>
|
209 |
|
|
|
210 |
45d6ada5
|
Sjon Hortensius
|
<div class="panel panel-default">
|
211 |
f17594c7
|
Sjon Hortensius
|
<div class="panel-heading"><h2 class="panel-title">IPv4 Routes</h2></div>
|
212 |
45d6ada5
|
Sjon Hortensius
|
<div class="panel panel-body">
|
213 |
|
|
<table class="table table-striped table-compact" id="IPv4">
|
214 |
|
|
<thead>
|
215 |
|
|
<!-- filled by xhr -->
|
216 |
|
|
</thead>
|
217 |
|
|
<tbody>
|
218 |
|
|
<tr>
|
219 |
|
|
<td><?=gettext("Gathering data, please wait...")?></td>
|
220 |
|
|
</tr>
|
221 |
|
|
</tbody>
|
222 |
|
|
</table>
|
223 |
|
|
</div>
|
224 |
0eacb3b2
|
Scott Ullrich
|
</div>
|
225 |
|
|
|
226 |
45d6ada5
|
Sjon Hortensius
|
<div class="panel panel-default">
|
227 |
f17594c7
|
Sjon Hortensius
|
<div class="panel-heading"><h2 class="panel-title">IPv6 Routes</h2></div>
|
228 |
45d6ada5
|
Sjon Hortensius
|
<div class="panel panel-body">
|
229 |
|
|
<table class="table table-striped table-compact" id="IPv6">
|
230 |
|
|
<thead>
|
231 |
|
|
<!-- filled by xhr -->
|
232 |
|
|
</thead>
|
233 |
|
|
<tbody>
|
234 |
|
|
<tr>
|
235 |
|
|
<td><?=gettext("Gathering data, please wait...")?></td>
|
236 |
|
|
</tr>
|
237 |
|
|
</tbody>
|
238 |
|
|
</table>
|
239 |
|
|
</div>
|
240 |
|
|
</div>
|
241 |
92e8dc9d
|
Colin Fleming
|
|
242 |
45d6ada5
|
Sjon Hortensius
|
<?php include("foot.inc");
|