1
|
<?php
|
2
|
/*
|
3
|
* diag_routes.php
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
7
|
* Copyright (c) 2006 Fernando Lamos
|
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
|
18
|
* the documentation and/or other materials provided with the
|
19
|
* distribution.
|
20
|
*
|
21
|
* 3. All advertising materials mentioning features or use of this software
|
22
|
* must display the following acknowledgment:
|
23
|
* "This product includes software developed by the pfSense Project
|
24
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
25
|
*
|
26
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
27
|
* endorse or promote products derived from this software without
|
28
|
* prior written permission. For written permission, please contact
|
29
|
* coreteam@pfsense.org.
|
30
|
*
|
31
|
* 5. Products derived from this software may not be called "pfSense"
|
32
|
* nor may "pfSense" appear in their names without prior written
|
33
|
* permission of the Electric Sheep Fencing, LLC.
|
34
|
*
|
35
|
* 6. Redistributions of any form whatsoever must retain the following
|
36
|
* acknowledgment:
|
37
|
*
|
38
|
* "This product includes software developed by the pfSense Project
|
39
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
40
|
*
|
41
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
42
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
43
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
44
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
45
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
46
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
47
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
48
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
49
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
50
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
51
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
52
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
53
|
*/
|
54
|
|
55
|
##|+PRIV
|
56
|
##|*IDENT=page-diagnostics-routingtables
|
57
|
##|*NAME=Diagnostics: Routing tables
|
58
|
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
|
59
|
##|*MATCH=diag_routes.php*
|
60
|
##|-PRIV
|
61
|
|
62
|
require_once('guiconfig.inc');
|
63
|
|
64
|
$limit = '100';
|
65
|
$filter = '';
|
66
|
|
67
|
if (isset($_REQUEST['isAjax'])) {
|
68
|
$netstat = "/usr/bin/netstat -rnW";
|
69
|
if (isset($_REQUEST['IPv6'])) {
|
70
|
$netstat .= " -f inet6";
|
71
|
echo "IPv6\n";
|
72
|
} else {
|
73
|
$netstat .= " -f inet";
|
74
|
echo "IPv4\n";
|
75
|
}
|
76
|
|
77
|
if (!empty($_REQUEST['filter'])) {
|
78
|
$netstat .= " | /usr/bin/sed -e " . escapeshellarg("1,3d; 5,\$ { /" . htmlspecialchars($_REQUEST['filter']) . "/!d; };");
|
79
|
} else {
|
80
|
$netstat .= " | /usr/bin/sed -e '1,3d'";
|
81
|
}
|
82
|
|
83
|
if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
|
84
|
$_REQUEST['limit']++; // Account for the header line
|
85
|
$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
|
86
|
}
|
87
|
|
88
|
if (isset($_REQUEST['resolve'])) {
|
89
|
$netstat_output_array = explode("\n", shell_exec($netstat));
|
90
|
$output_text = "";
|
91
|
foreach ($netstat_output_array as $netstat_line) {
|
92
|
$netstat_columns_array = explode(" ", $netstat_line);
|
93
|
$output_line = "";
|
94
|
foreach ($netstat_columns_array as $netstat_column) {
|
95
|
// An address can be like:
|
96
|
// address%dev/CIDR ff01::%em0/32
|
97
|
// address%dev fe80::a00:1234:5678:9abc%em0
|
98
|
// address/CIDR 2001:470:12:abcd::/64 192.168.1.0/24
|
99
|
// or just an address 2001:470:12:abcd:1:2:3:4 192.168.1.1
|
100
|
// Separate the bit before and after any slash.
|
101
|
$slash_parts = explode("/", $netstat_column);
|
102
|
// Then separate the bit before and after any percent sign.
|
103
|
$percent_parts = explode("%", $slash_parts[0]);
|
104
|
if (is_ipaddr($percent_parts[0])) {
|
105
|
// Try and reverse resolve the first part, which looks like an IP Address
|
106
|
$output_line .= gethostbyaddr($percent_parts[0]);
|
107
|
if (strlen($percent_parts[1]) > 0) {
|
108
|
// Put back the percent bit.
|
109
|
$output_line .= "%" . $percent_parts[1];
|
110
|
}
|
111
|
if (strlen($slash_parts[1]) > 0) {
|
112
|
// Put back the slash bit.
|
113
|
$output_line .= "/" . $slash_parts[1];
|
114
|
}
|
115
|
} else {
|
116
|
$output_line .= $netstat_column;
|
117
|
}
|
118
|
$output_line .= " ";
|
119
|
}
|
120
|
$output_text .= trim($output_line) . "\n";
|
121
|
}
|
122
|
} else {
|
123
|
$output_text = shell_exec($netstat);
|
124
|
}
|
125
|
|
126
|
echo htmlspecialchars_decode($output_text);
|
127
|
exit;
|
128
|
}
|
129
|
|
130
|
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
|
131
|
$shortcut_section = "routing";
|
132
|
|
133
|
include('head.inc');
|
134
|
|
135
|
$form = new Form(false);
|
136
|
$form->addGlobal(new Form_Input(
|
137
|
'isAjax',
|
138
|
null,
|
139
|
'hidden',
|
140
|
1
|
141
|
));
|
142
|
$section = new Form_Section('Routing Table Display Options');
|
143
|
|
144
|
$section->addInput(new Form_Checkbox(
|
145
|
'resolve',
|
146
|
'Resolve names',
|
147
|
'Enable',
|
148
|
$resolve
|
149
|
))->setHelp('Enabling name resolution may cause the query to take longer.'.
|
150
|
' It can be stopped at any time by clicking the Stop button in the browser.');
|
151
|
|
152
|
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
|
153
|
$section->addInput(new Form_Select(
|
154
|
'limit',
|
155
|
'Rows to display',
|
156
|
$limit,
|
157
|
array_combine($validLimits, $validLimits)
|
158
|
));
|
159
|
|
160
|
$section->addInput(new Form_Input(
|
161
|
'filter',
|
162
|
'Filter',
|
163
|
'text',
|
164
|
$host
|
165
|
))->setHelp('Use a regular expression to filter the tables.');
|
166
|
|
167
|
$form->add($section);
|
168
|
|
169
|
$form->addGlobal(new Form_Button(
|
170
|
'Submit',
|
171
|
'Update',
|
172
|
null,
|
173
|
'fa-refresh'
|
174
|
))->addClass('btn-primary');
|
175
|
|
176
|
print $form;
|
177
|
?>
|
178
|
<script type="text/javascript">
|
179
|
//<![CDATA[
|
180
|
function update_routes(section) {
|
181
|
$.ajax(
|
182
|
'/diag_routes.php',
|
183
|
{
|
184
|
type: 'post',
|
185
|
data: $(document.forms[0]).serialize() +'&'+ section +'=true',
|
186
|
success: update_routes_callback,
|
187
|
});
|
188
|
}
|
189
|
|
190
|
function update_routes_callback(html) {
|
191
|
// First line contains section
|
192
|
var responseTextArr = html.split("\n");
|
193
|
var section = responseTextArr.shift();
|
194
|
var tbody = '';
|
195
|
var field = '';
|
196
|
var tr_class = '';
|
197
|
var thead = '<tr>';
|
198
|
|
199
|
for (var i = 0; i < responseTextArr.length; i++) {
|
200
|
|
201
|
if (responseTextArr[i] == "") {
|
202
|
continue;
|
203
|
}
|
204
|
|
205
|
if (i == 0) {
|
206
|
var tmp = '';
|
207
|
} else {
|
208
|
var tmp = '<tr>';
|
209
|
}
|
210
|
|
211
|
var j = 0;
|
212
|
var entry = responseTextArr[i].split(" ");
|
213
|
for (var k = 0; k < entry.length; k++) {
|
214
|
if (entry[k] == "") {
|
215
|
continue;
|
216
|
}
|
217
|
if (i == 0) {
|
218
|
tmp += '<th>' + entry[k] + '<\/th>';
|
219
|
} else {
|
220
|
tmp += '<td>' + entry[k] + '<\/td>';
|
221
|
}
|
222
|
j++;
|
223
|
}
|
224
|
|
225
|
if (i == 0) {
|
226
|
thead += tmp;
|
227
|
} else {
|
228
|
tmp += '<td><\/td>'
|
229
|
tbody += tmp;
|
230
|
}
|
231
|
}
|
232
|
|
233
|
$('#' + section + ' > thead').html(thead);
|
234
|
$('#' + section + ' > tbody').html(tbody);
|
235
|
}
|
236
|
|
237
|
function update_all_routes() {
|
238
|
update_routes("IPv4");
|
239
|
update_routes("IPv6");
|
240
|
}
|
241
|
|
242
|
events.push(function() {
|
243
|
setInterval('update_all_routes()', 5000);
|
244
|
update_all_routes();
|
245
|
|
246
|
$(document.forms[0]).on('submit', function(e) {
|
247
|
update_all_routes();
|
248
|
|
249
|
e.preventDefault();
|
250
|
});
|
251
|
});
|
252
|
//]]>
|
253
|
</script>
|
254
|
|
255
|
<div class="panel panel-default">
|
256
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv4 Routes")?></h2></div>
|
257
|
<div class="panel panel-body">
|
258
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4">
|
259
|
<thead>
|
260
|
<tr>
|
261
|
<th><!-- filled by xhr --></th>
|
262
|
</tr>
|
263
|
</thead>
|
264
|
<tbody>
|
265
|
<tr>
|
266
|
<td><?=gettext("Gathering data, please wait...")?></td>
|
267
|
</tr>
|
268
|
</tbody>
|
269
|
</table>
|
270
|
</div>
|
271
|
</div>
|
272
|
|
273
|
<div class="panel panel-default">
|
274
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv6 Routes")?></h2></div>
|
275
|
<div class="panel panel-body">
|
276
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6">
|
277
|
<thead>
|
278
|
<tr>
|
279
|
<th><!-- filled by xhr --></th>
|
280
|
</tr>
|
281
|
</thead>
|
282
|
<tbody>
|
283
|
<tr>
|
284
|
<td><?=gettext("Gathering data, please wait...")?></td>
|
285
|
</tr>
|
286
|
</tbody>
|
287
|
</table>
|
288
|
</div>
|
289
|
</div>
|
290
|
|
291
|
<?php include("foot.inc");
|