Project

General

Profile

Download (4.96 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-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
require_once('guiconfig.inc');
31

    
32
$limit = '100';
33
$filter = '';
34

    
35
if (isset($_REQUEST['isAjax'])) {
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

    
65
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
66
$shortcut_section = "routing";
67

    
68
include('head.inc');
69

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

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

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

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

    
102
$form->add($section);
103

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

    
111
print $form;
112
?>
113
<script type="text/javascript">
114
//<![CDATA[
115
function update_routes(section) {
116
	$.ajax(
117
		'/diag_routes.php',
118
		{
119
			type: 'post',
120
			data: $(document.forms[0]).serialize() +'&'+ section +'=true',
121
			success: update_routes_callback,
122
	});
123
}
124

    
125
function update_routes_callback(html) {
126
	// First line contains section
127
	var responseTextArr = html.split("\n");
128
	var section = responseTextArr.shift();
129
	var tbody = '';
130
	var field = '';
131
	var tr_class = '';
132
	var thead = '<tr>';
133

    
134
	for (var i = 0; i < responseTextArr.length; i++) {
135

    
136
		if (responseTextArr[i] == "") {
137
			continue;
138
		}
139

    
140
		if (i == 0) {
141
			var tmp = '';
142
		} else {
143
			var tmp = '<tr>';
144
		}
145

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

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

    
168
	$('#' + section + ' > thead').html(thead);
169
	$('#' + section + ' > tbody').html(tbody);
170
}
171

    
172
function update_all_routes() {
173
	update_routes("IPv4");
174
	update_routes("IPv6");
175
}
176

    
177
events.push(function() {
178
	setInterval('update_all_routes()', 5000);
179
	update_all_routes();
180

    
181
	$(document.forms[0]).on('submit', function(e) {
182
		update_all_routes();
183

    
184
		e.preventDefault();
185
	});
186
});
187
//]]>
188
</script>
189

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

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

    
226
<?php include("foot.inc");
(24-24/225)