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
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
11
|
* you may not use this file except in compliance with the License.
|
12
|
* You may obtain a copy of the License at
|
13
|
*
|
14
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15
|
*
|
16
|
* Unless required by applicable law or agreed to in writing, software
|
17
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
18
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
19
|
* See the License for the specific language governing permissions and
|
20
|
* limitations under the License.
|
21
|
*/
|
22
|
|
23
|
##|+PRIV
|
24
|
##|*IDENT=page-diagnostics-routingtables
|
25
|
##|*NAME=Diagnostics: Routing tables
|
26
|
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
|
27
|
##|*MATCH=diag_routes.php*
|
28
|
##|-PRIV
|
29
|
|
30
|
$limit = '100';
|
31
|
$filter = '';
|
32
|
|
33
|
if (isset($_REQUEST['isAjax'])) {
|
34
|
require_once('auth_check.inc');
|
35
|
|
36
|
$netstat = "/usr/bin/netstat -rW";
|
37
|
if (isset($_REQUEST['IPv6'])) {
|
38
|
$netstat .= " -f inet6";
|
39
|
echo "IPv6\n";
|
40
|
} else {
|
41
|
$netstat .= " -f inet";
|
42
|
echo "IPv4\n";
|
43
|
|
44
|
}
|
45
|
if (!isset($_REQUEST['resolve'])) {
|
46
|
$netstat .= " -n";
|
47
|
}
|
48
|
|
49
|
if (!empty($_REQUEST['filter'])) {
|
50
|
$netstat .= " | /usr/bin/sed -e " . escapeshellarg("1,3d; 5,\$ { /" . htmlspecialchars($_REQUEST['filter']) . "/!d; };");
|
51
|
} else {
|
52
|
$netstat .= " | /usr/bin/sed -e '1,3d'";
|
53
|
}
|
54
|
|
55
|
if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
|
56
|
$_REQUEST['limit']++; // Account for the header line
|
57
|
$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
|
58
|
}
|
59
|
|
60
|
echo htmlspecialchars_decode(shell_exec($netstat));
|
61
|
|
62
|
exit;
|
63
|
}
|
64
|
require_once('guiconfig.inc');
|
65
|
|
66
|
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
|
67
|
$shortcut_section = "routing";
|
68
|
|
69
|
include('head.inc');
|
70
|
|
71
|
$form = new Form(false);
|
72
|
$form->addGlobal(new Form_Input(
|
73
|
'isAjax',
|
74
|
null,
|
75
|
'hidden',
|
76
|
1
|
77
|
));
|
78
|
$section = new Form_Section('Routing Table Display Options');
|
79
|
|
80
|
$section->addInput(new Form_Checkbox(
|
81
|
'resolve',
|
82
|
'Resolve names',
|
83
|
'Enable',
|
84
|
$resolve
|
85
|
))->setHelp('Enabling name resolution may cause the query to take longer.'.
|
86
|
' It can be stopped at any time by clicking the Stop button in the browser.');
|
87
|
|
88
|
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
|
89
|
$section->addInput(new Form_Select(
|
90
|
'limit',
|
91
|
'Rows to display',
|
92
|
$limit,
|
93
|
array_combine($validLimits, $validLimits)
|
94
|
));
|
95
|
|
96
|
$section->addInput(new Form_Input(
|
97
|
'filter',
|
98
|
'Filter',
|
99
|
'text',
|
100
|
$host
|
101
|
))->setHelp('Use a regular expression to filter the tables.');
|
102
|
|
103
|
$form->add($section);
|
104
|
|
105
|
$form->addGlobal(new Form_Button(
|
106
|
'Submit',
|
107
|
'Update',
|
108
|
null,
|
109
|
'fa-refresh'
|
110
|
))->addClass('btn-primary');
|
111
|
|
112
|
print $form;
|
113
|
?>
|
114
|
<script type="text/javascript">
|
115
|
//<![CDATA[
|
116
|
function update_routes(section) {
|
117
|
$.ajax(
|
118
|
'/diag_routes.php',
|
119
|
{
|
120
|
type: 'post',
|
121
|
data: $(document.forms[0]).serialize() +'&'+ section +'=true',
|
122
|
success: update_routes_callback,
|
123
|
});
|
124
|
}
|
125
|
|
126
|
function update_routes_callback(html) {
|
127
|
// First line contains section
|
128
|
var responseTextArr = html.split("\n");
|
129
|
var section = responseTextArr.shift();
|
130
|
var tbody = '';
|
131
|
var field = '';
|
132
|
var tr_class = '';
|
133
|
var thead = '<tr>';
|
134
|
|
135
|
for (var i = 0; i < responseTextArr.length; i++) {
|
136
|
|
137
|
if (responseTextArr[i] == "") {
|
138
|
continue;
|
139
|
}
|
140
|
|
141
|
if (i == 0) {
|
142
|
var tmp = '';
|
143
|
} else {
|
144
|
var tmp = '<tr>';
|
145
|
}
|
146
|
|
147
|
var j = 0;
|
148
|
var entry = responseTextArr[i].split(" ");
|
149
|
for (var k = 0; k < entry.length; k++) {
|
150
|
if (entry[k] == "") {
|
151
|
continue;
|
152
|
}
|
153
|
if (i == 0) {
|
154
|
tmp += '<th>' + entry[k] + '<\/th>';
|
155
|
} else {
|
156
|
tmp += '<td>' + entry[k] + '<\/td>';
|
157
|
}
|
158
|
j++;
|
159
|
}
|
160
|
|
161
|
if (i == 0) {
|
162
|
thead += tmp;
|
163
|
} else {
|
164
|
tmp += '<td><\/td>'
|
165
|
tbody += tmp;
|
166
|
}
|
167
|
}
|
168
|
|
169
|
$('#' + section + ' > thead').html(thead);
|
170
|
$('#' + section + ' > tbody').html(tbody);
|
171
|
}
|
172
|
|
173
|
function update_all_routes() {
|
174
|
update_routes("IPv4");
|
175
|
update_routes("IPv6");
|
176
|
}
|
177
|
|
178
|
events.push(function() {
|
179
|
setInterval('update_all_routes()', 5000);
|
180
|
update_all_routes();
|
181
|
|
182
|
$(document.forms[0]).on('submit', function(e) {
|
183
|
update_all_routes();
|
184
|
|
185
|
e.preventDefault();
|
186
|
});
|
187
|
});
|
188
|
//]]>
|
189
|
</script>
|
190
|
|
191
|
<div class="panel panel-default">
|
192
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv4 Routes")?></h2></div>
|
193
|
<div class="panel panel-body">
|
194
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4">
|
195
|
<thead>
|
196
|
<tr>
|
197
|
<th><!-- filled by xhr --></th>
|
198
|
</tr>
|
199
|
</thead>
|
200
|
<tbody>
|
201
|
<tr>
|
202
|
<td><?=gettext("Gathering data, please wait...")?></td>
|
203
|
</tr>
|
204
|
</tbody>
|
205
|
</table>
|
206
|
</div>
|
207
|
</div>
|
208
|
|
209
|
<div class="panel panel-default">
|
210
|
<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv6 Routes")?></h2></div>
|
211
|
<div class="panel panel-body">
|
212
|
<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6">
|
213
|
<thead>
|
214
|
<tr>
|
215
|
<th><!-- filled by xhr --></th>
|
216
|
</tr>
|
217
|
</thead>
|
218
|
<tbody>
|
219
|
<tr>
|
220
|
<td><?=gettext("Gathering data, please wait...")?></td>
|
221
|
</tr>
|
222
|
</tbody>
|
223
|
</table>
|
224
|
</div>
|
225
|
</div>
|
226
|
|
227
|
<?php include("foot.inc");
|