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