1
|
<?php
|
2
|
|
3
|
/* $Id$ */
|
4
|
/*
|
5
|
diag_routes.php
|
6
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
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 the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
|
31
|
*/
|
32
|
|
33
|
/*
|
34
|
pfSense_BUILDER_BINARIES: /usr/bin/netstat
|
35
|
pfSense_MODULE: routing
|
36
|
*/
|
37
|
##|+PRIV
|
38
|
##|*IDENT=page-diagnostics-routingtables
|
39
|
##|*NAME=Diagnostics: Routing tables page
|
40
|
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
|
41
|
##|*MATCH=diag_routes.php*
|
42
|
##|-PRIV
|
43
|
|
44
|
include('guiconfig.inc');
|
45
|
|
46
|
$limit='100';
|
47
|
$filter='';
|
48
|
|
49
|
if (isset($_REQUEST['isAjax'])) {
|
50
|
$netstat = "/usr/bin/netstat -rW";
|
51
|
if (isset($_REQUEST['IPv6'])) {
|
52
|
$netstat .= " -f inet6";
|
53
|
echo "IPv6\n";
|
54
|
} else {
|
55
|
$netstat .= " -f inet";
|
56
|
echo "IPv4\n";
|
57
|
|
58
|
}
|
59
|
if (!isset($_REQUEST['resolve']))
|
60
|
$netstat .= " -n";
|
61
|
|
62
|
if (!empty($_REQUEST['filter']))
|
63
|
$netstat .= " | /usr/bin/sed -e '1,3d; 5,\$ { /" . escapeshellarg(htmlspecialchars($_REQUEST['filter'])) . "/!d; };'";
|
64
|
else
|
65
|
$netstat .= " | /usr/bin/sed -e '1,3d'";
|
66
|
|
67
|
if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0)
|
68
|
$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
|
69
|
|
70
|
echo htmlspecialchars_decode(shell_exec($netstat));
|
71
|
|
72
|
exit;
|
73
|
}
|
74
|
|
75
|
$pgtitle = array(gettext("Diagnostics"),gettext("Routing tables"));
|
76
|
$shortcut_section = "routing";
|
77
|
|
78
|
include('head.inc');
|
79
|
|
80
|
require('classes/Form.class.php');
|
81
|
|
82
|
$form = new Form('Update');
|
83
|
$form->addGlobal(new Form_Input(
|
84
|
'isAjax',
|
85
|
null,
|
86
|
'hidden',
|
87
|
1
|
88
|
));
|
89
|
$section = new Form_Section('Traceroute');
|
90
|
|
91
|
$section->addInput(new Form_Checkbox(
|
92
|
'resolve',
|
93
|
'Resolve names',
|
94
|
'Enable',
|
95
|
$resolve
|
96
|
))->setHelp('Enabling name resolution may cause the query should take longer.'.
|
97
|
' You can stop it at any time by clicking the Stop button in your browser.');
|
98
|
|
99
|
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
|
100
|
$section->addInput(new Form_Select(
|
101
|
'limit',
|
102
|
'Rows to display',
|
103
|
$limit,
|
104
|
array_combine($validLimits, $validLimits)
|
105
|
));
|
106
|
|
107
|
$section->addInput(new Form_Input(
|
108
|
'filter',
|
109
|
'Filter',
|
110
|
'text',
|
111
|
$host
|
112
|
))->setHelp('Use a regular expression to filter IP address or hostnames');
|
113
|
|
114
|
$form->add($section);
|
115
|
print $form;
|
116
|
?>
|
117
|
<script>
|
118
|
function update_routes(section) {
|
119
|
$.ajax(
|
120
|
'/diag_routes.php',
|
121
|
{
|
122
|
type: 'post',
|
123
|
data: $(document.forms[0]).serialize() +'&'+ section +'=true',
|
124
|
success: update_routes_callback,
|
125
|
});
|
126
|
}
|
127
|
|
128
|
function update_routes_callback(html) {
|
129
|
// First line contains section
|
130
|
var responseTextArr = html.split("\n");
|
131
|
var section = responseTextArr.shift();
|
132
|
var tbody = '';
|
133
|
var field = '';
|
134
|
var tr_class = '';
|
135
|
var thead = '<tr>';
|
136
|
|
137
|
for (var i = 0; i < responseTextArr.length; i++) {
|
138
|
if (responseTextArr[i] == "")
|
139
|
continue;
|
140
|
var tmp = '<tr>';
|
141
|
var j = 0;
|
142
|
var entry = responseTextArr[i].split(" ");
|
143
|
for (var k = 0; k < entry.length; k++) {
|
144
|
if (entry[k] == "")
|
145
|
continue;
|
146
|
if (i == 0)
|
147
|
tmp += '<th>' + entry[k] + '<\/th>';
|
148
|
else
|
149
|
tmp += '<td>' + entry[k] + '<\/td>';
|
150
|
j++;
|
151
|
}
|
152
|
|
153
|
tmp += '<td><\/td>';
|
154
|
|
155
|
if (i == 0)
|
156
|
thead += tmp;
|
157
|
else
|
158
|
tbody += tmp;
|
159
|
}
|
160
|
|
161
|
$('#' + section + ' > thead').html(thead);
|
162
|
$('#' + section + ' > tbody').html(tbody);
|
163
|
}
|
164
|
|
165
|
function update_all_routes() {
|
166
|
update_routes("IPv4");
|
167
|
update_routes("IPv6");
|
168
|
}
|
169
|
|
170
|
events.push(function(){
|
171
|
setInterval('update_all_routes()', 5000);
|
172
|
update_all_routes();
|
173
|
|
174
|
$(document.forms[0]).on('submit', function(e){
|
175
|
update_all_routes();
|
176
|
|
177
|
e.preventDefault();
|
178
|
});
|
179
|
});
|
180
|
</script>
|
181
|
|
182
|
<div class="panel panel-default">
|
183
|
<div class="panel-heading">IPv4 Routes</div>
|
184
|
<div class="panel panel-body">
|
185
|
<table class="table table-striped table-compact" id="IPv4">
|
186
|
<thead>
|
187
|
<!-- filled by xhr -->
|
188
|
</thead>
|
189
|
<tbody>
|
190
|
<tr>
|
191
|
<td><?=gettext("Gathering data, please wait...")?></td>
|
192
|
</tr>
|
193
|
</tbody>
|
194
|
</table>
|
195
|
</div>
|
196
|
</div>
|
197
|
|
198
|
<div class="panel panel-default">
|
199
|
<div class="panel-heading">IPv6 Routes</div>
|
200
|
<div class="panel panel-body">
|
201
|
<table class="table table-striped table-compact" id="IPv6">
|
202
|
<thead>
|
203
|
<!-- filled by xhr -->
|
204
|
</thead>
|
205
|
<tbody>
|
206
|
<tr>
|
207
|
<td><?=gettext("Gathering data, please wait...")?></td>
|
208
|
</tr>
|
209
|
</tbody>
|
210
|
</table>
|
211
|
</div>
|
212
|
</div>
|
213
|
|
214
|
<?php include("foot.inc");
|