Project

General

Profile

Download (5.08 KB) Statistics
| Branch: | Tag: | Revision:
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-2020 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
if (isset($_REQUEST['isAjax'])) {
36
	require_once('auth_check.inc');
37

    
38
	$netstat = "/usr/bin/netstat -rW";
39
	if (isset($_REQUEST['IPv6'])) {
40
		$netstat .= " -f inet6";
41
		echo "IPv6\n";
42
	} else {
43
		$netstat .= " -f inet";
44
		echo "IPv4\n";
45

    
46
	}
47
	if (!isset($_REQUEST['resolve'])) {
48
		$netstat .= " -n";
49
	}
50

    
51
	if (!empty($_REQUEST['filter'])) {
52
		$netstat .= " | /usr/bin/sed -e " . escapeshellarg("1,3d; 5,\$ { /" . htmlspecialchars($_REQUEST['filter']) . "/!d; };");
53
	} else {
54
		$netstat .= " | /usr/bin/sed -e '1,3d'";
55
	}
56

    
57
	if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
58
		$_REQUEST['limit']++;  // Account for the header line
59
		$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
60
	}
61

    
62
	echo htmlspecialchars_decode(shell_exec($netstat));
63

    
64
	exit;
65
}
66
require_once('guiconfig.inc');
67

    
68
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
69
$shortcut_section = "routing";
70

    
71
include('head.inc');
72

    
73
$form = new Form(false);
74
$form->addGlobal(new Form_Input(
75
	'isAjax',
76
	null,
77
	'hidden',
78
	1
79
));
80
$section = new Form_Section('Routing Table Display Options');
81

    
82
$section->addInput(new Form_Checkbox(
83
	'resolve',
84
	'Resolve names',
85
	'Enable',
86
	$resolve
87
))->setHelp('Enabling name resolution may cause the query to take longer.'.
88
	' It can be stopped at any time by clicking the Stop button in the browser.');
89

    
90
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
91
$section->addInput(new Form_Select(
92
	'limit',
93
	'Rows to display',
94
	$limit,
95
	array_combine($validLimits, $validLimits)
96
));
97

    
98
$section->addInput(new Form_Input(
99
	'filter',
100
	'Filter',
101
	'text',
102
	$host
103
))->setHelp('Use a regular expression to filter the tables.');
104

    
105
$form->add($section);
106

    
107
$form->addGlobal(new Form_Button(
108
	'Submit',
109
	'Update',
110
	null,
111
	'fa-refresh'
112
))->addClass('btn-primary');
113

    
114
print $form;
115
?>
116
<script type="text/javascript">
117
//<![CDATA[
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

    
139
		if (responseTextArr[i] == "") {
140
			continue;
141
		}
142

    
143
		if (i == 0) {
144
			var tmp = '';
145
		} else {
146
			var tmp = '<tr>';
147
		}
148

    
149
		var j = 0;
150
		var entry = responseTextArr[i].split(" ");
151
		for (var k = 0; k < entry.length; k++) {
152
			if (entry[k] == "") {
153
				continue;
154
			}
155
			if (i == 0) {
156
				tmp += '<th>' + entry[k] + '<\/th>';
157
			} else {
158
				tmp += '<td>' + entry[k] + '<\/td>';
159
			}
160
			j++;
161
		}
162

    
163
		if (i == 0) {
164
			thead += tmp;
165
		} else {
166
			tmp += '<td><\/td>'
167
			tbody += tmp;
168
		}
169
	}
170

    
171
	$('#' + section + ' > thead').html(thead);
172
	$('#' + section + ' > tbody').html(tbody);
173
}
174

    
175
function update_all_routes() {
176
	update_routes("IPv4");
177
	update_routes("IPv6");
178
}
179

    
180
events.push(function() {
181
	setInterval('update_all_routes()', 5000);
182
	update_all_routes();
183

    
184
	$(document.forms[0]).on('submit', function(e) {
185
		update_all_routes();
186

    
187
		e.preventDefault();
188
	});
189
});
190
//]]>
191
</script>
192

    
193
<div class="panel panel-default">
194
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv4 Routes")?></h2></div>
195
	<div class="panel panel-body">
196
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4">
197
		<thead>
198
			<tr>
199
				<th><!-- filled by xhr --></th>
200
			</tr>
201
		</thead>
202
		<tbody>
203
			<tr>
204
				<td><?=gettext("Gathering data, please wait...")?></td>
205
			</tr>
206
		</tbody>
207
		</table>
208
	</div>
209
</div>
210

    
211
<div class="panel panel-default">
212
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv6 Routes")?></h2></div>
213
	<div class="panel panel-body">
214
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6">
215
		<thead>
216
			<tr>
217
				<th><!-- filled by xhr --></th>
218
			</tr>
219
		</thead>
220
		<tbody>
221
			<tr>
222
				<td><?=gettext("Gathering data, please wait...")?></td>
223
			</tr>
224
		</tbody>
225
		</table>
226
	</div>
227
</div>
228

    
229
<?php include("foot.inc");
(28-28/227)