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