Project

General

Profile

Download (4.96 KB) Statistics
| Branch: | Tag: | Revision:
1 0eacb3b2 Scott Ullrich
<?php
2
/*
3 c5d81585 Renato Botelho
 * diag_routes.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 c5d81585 Renato Botelho
 * Copyright (c) 2006 Fernando Lamos
8
 * All rights reserved.
9
 *
10 b12ea3fb Renato Botelho
 * 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 c5d81585 Renato Botelho
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 c5d81585 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * 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 fd9ebcd5 Stephen Beaver
 */
22 c5d81585 Renato Botelho
23 6b07c15a Matthew Grooms
##|+PRIV
24
##|*IDENT=page-diagnostics-routingtables
25 5230f468 jim-p
##|*NAME=Diagnostics: Routing tables
26 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
27
##|*MATCH=diag_routes.php*
28
##|-PRIV
29
30 86573bb9 Phil Davis
require_once('guiconfig.inc');
31 0eacb3b2 Scott Ullrich
32 288a2a0f Phil Davis
$limit = '100';
33
$filter = '';
34 45d6ada5 Sjon Hortensius
35 92e8cb11 Renato Botelho
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 45d6ada5 Sjon Hortensius
44 92e8cb11 Renato Botelho
	}
45 5f601060 Phil Davis
	if (!isset($_REQUEST['resolve'])) {
46 92e8cb11 Renato Botelho
		$netstat .= " -n";
47 5f601060 Phil Davis
	}
48 92e8cb11 Renato Botelho
49 5f601060 Phil Davis
	if (!empty($_REQUEST['filter'])) {
50 a3013ca6 jim-p
		$netstat .= " | /usr/bin/sed -e " . escapeshellarg("1,3d; 5,\$ { /" . htmlspecialchars($_REQUEST['filter']) . "/!d; };");
51 5f601060 Phil Davis
	} else {
52 92e8cb11 Renato Botelho
		$netstat .= " | /usr/bin/sed -e '1,3d'";
53 5f601060 Phil Davis
	}
54 92e8cb11 Renato Botelho
55 5f601060 Phil Davis
	if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
56 d526fc2d Stephen Beaver
		$_REQUEST['limit']++;  // Account for the header line
57 92e8cb11 Renato Botelho
		$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
58 5f601060 Phil Davis
	}
59 92e8cb11 Renato Botelho
60
	echo htmlspecialchars_decode(shell_exec($netstat));
61
62
	exit;
63
}
64
65 a6a6ee00 k-paulius
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
66 b32dd0a6 jim-p
$shortcut_section = "routing";
67 0eacb3b2 Scott Ullrich
68
include('head.inc');
69
70 37676f4e jim-p
$form = new Form(false);
71 45d6ada5 Sjon Hortensius
$form->addGlobal(new Form_Input(
72
	'isAjax',
73
	null,
74
	'hidden',
75
	1
76
));
77 e897f304 Phil Davis
$section = new Form_Section('Routing Table Display Options');
78 45d6ada5 Sjon Hortensius
79
$section->addInput(new Form_Checkbox(
80
	'resolve',
81
	'Resolve names',
82
	'Enable',
83
	$resolve
84 288a2a0f Phil Davis
))->setHelp('Enabling name resolution may cause the query to take longer.'.
85 b6078bed NOYB
	' It can be stopped at any time by clicking the Stop button in the browser.');
86 45d6ada5 Sjon Hortensius
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 b86938e7 Stephen Beaver
))->setHelp('Use a regular expression to filter the tables.');
101 45d6ada5 Sjon Hortensius
102
$form->add($section);
103 37676f4e jim-p
104
$form->addGlobal(new Form_Button(
105
	'Submit',
106 faab522f Renato Botelho
	'Update',
107 37676f4e jim-p
	null,
108
	'fa-refresh'
109
))->addClass('btn-primary');
110
111 45d6ada5 Sjon Hortensius
print $form;
112 0eacb3b2 Scott Ullrich
?>
113 8fd9052f Colin Fleming
<script type="text/javascript">
114
//<![CDATA[
115 45d6ada5 Sjon Hortensius
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 92e8cb11 Renato Botelho
125 45d6ada5 Sjon Hortensius
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 2f4e37b1 Stephen Beaver
136 947141fd Phil Davis
		if (responseTextArr[i] == "") {
137 45d6ada5 Sjon Hortensius
			continue;
138 947141fd Phil Davis
		}
139 2f4e37b1 Stephen Beaver
140 947141fd Phil Davis
		if (i == 0) {
141 2f4e37b1 Stephen Beaver
			var tmp = '';
142 947141fd Phil Davis
		} else {
143 2f4e37b1 Stephen Beaver
			var tmp = '<tr>';
144 947141fd Phil Davis
		}
145 2f4e37b1 Stephen Beaver
146 45d6ada5 Sjon Hortensius
		var j = 0;
147
		var entry = responseTextArr[i].split(" ");
148
		for (var k = 0; k < entry.length; k++) {
149 947141fd Phil Davis
			if (entry[k] == "") {
150 92e8cb11 Renato Botelho
				continue;
151 947141fd Phil Davis
			}
152
			if (i == 0) {
153 45d6ada5 Sjon Hortensius
				tmp += '<th>' + entry[k] + '<\/th>';
154 947141fd Phil Davis
			} else {
155 45d6ada5 Sjon Hortensius
				tmp += '<td>' + entry[k] + '<\/td>';
156 947141fd Phil Davis
			}
157 45d6ada5 Sjon Hortensius
			j++;
158 92e8cb11 Renato Botelho
		}
159 45d6ada5 Sjon Hortensius
160 947141fd Phil Davis
		if (i == 0) {
161 45d6ada5 Sjon Hortensius
			thead += tmp;
162 947141fd Phil Davis
		} else {
163 2f4e37b1 Stephen Beaver
			tmp += '<td><\/td>'
164 45d6ada5 Sjon Hortensius
			tbody += tmp;
165 2f4e37b1 Stephen Beaver
		}
166 92e8cb11 Renato Botelho
	}
167
168 45d6ada5 Sjon Hortensius
	$('#' + section + ' > thead').html(thead);
169
	$('#' + section + ' > tbody').html(tbody);
170
}
171 92e8cb11 Renato Botelho
172 45d6ada5 Sjon Hortensius
function update_all_routes() {
173
	update_routes("IPv4");
174
	update_routes("IPv6");
175
}
176 92e8cb11 Renato Botelho
177 947141fd Phil Davis
events.push(function() {
178 865e0153 Stephen Beaver
	setInterval('update_all_routes()', 5000);
179 45d6ada5 Sjon Hortensius
	update_all_routes();
180 92e8cb11 Renato Botelho
181 947141fd Phil Davis
	$(document.forms[0]).on('submit', function(e) {
182 45d6ada5 Sjon Hortensius
		update_all_routes();
183 92e8cb11 Renato Botelho
184 45d6ada5 Sjon Hortensius
		e.preventDefault();
185
	});
186
});
187 8fd9052f Colin Fleming
//]]>
188 92e8cb11 Renato Botelho
</script>
189
190 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
191 185b4365 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv4 Routes")?></h2></div>
192 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
193 dd7ba16e Stephen Beaver
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4">
194 45d6ada5 Sjon Hortensius
		<thead>
195 2f4e37b1 Stephen Beaver
			<tr>
196
				<th><!-- filled by xhr --></th>
197
			</tr>
198 45d6ada5 Sjon Hortensius
		</thead>
199
		<tbody>
200
			<tr>
201
				<td><?=gettext("Gathering data, please wait...")?></td>
202
			</tr>
203
		</tbody>
204
		</table>
205
	</div>
206 0eacb3b2 Scott Ullrich
</div>
207
208 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
209 185b4365 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv6 Routes")?></h2></div>
210 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
211 dd7ba16e Stephen Beaver
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6">
212 45d6ada5 Sjon Hortensius
		<thead>
213 2f4e37b1 Stephen Beaver
			<tr>
214
				<th><!-- filled by xhr --></th>
215
			</tr>
216 45d6ada5 Sjon Hortensius
		</thead>
217
		<tbody>
218
			<tr>
219
				<td><?=gettext("Gathering data, please wait...")?></td>
220
			</tr>
221
		</tbody>
222
		</table>
223
	</div>
224
</div>
225 92e8dc9d Colin Fleming
226 c10cb196 Stephen Beaver
<?php include("foot.inc");