Project

General

Profile

Download (4.99 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 b8f91b7c Luiz Souza
 * Copyright (c) 2004-2018 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 288a2a0f Phil Davis
$limit = '100';
31
$filter = '';
32 45d6ada5 Sjon Hortensius
33 92e8cb11 Renato Botelho
if (isset($_REQUEST['isAjax'])) {
34 60ba7c76 PiBa-NL
	require_once('auth_check.inc');
35 139598eb robjarsen
36 92e8cb11 Renato Botelho
	$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 60ba7c76 PiBa-NL
require_once('guiconfig.inc');
65 92e8cb11 Renato Botelho
66 a6a6ee00 k-paulius
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
67 b32dd0a6 jim-p
$shortcut_section = "routing";
68 0eacb3b2 Scott Ullrich
69
include('head.inc');
70
71 37676f4e jim-p
$form = new Form(false);
72 45d6ada5 Sjon Hortensius
$form->addGlobal(new Form_Input(
73
	'isAjax',
74
	null,
75
	'hidden',
76
	1
77
));
78 e897f304 Phil Davis
$section = new Form_Section('Routing Table Display Options');
79 45d6ada5 Sjon Hortensius
80
$section->addInput(new Form_Checkbox(
81
	'resolve',
82
	'Resolve names',
83
	'Enable',
84
	$resolve
85 288a2a0f Phil Davis
))->setHelp('Enabling name resolution may cause the query to take longer.'.
86 b6078bed NOYB
	' It can be stopped at any time by clicking the Stop button in the browser.');
87 45d6ada5 Sjon Hortensius
88
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
89
$section->addInput(new Form_Select(
90
	'limit',
91
	'Rows to display',
92
	$limit,
93
	array_combine($validLimits, $validLimits)
94
));
95
96
$section->addInput(new Form_Input(
97
	'filter',
98
	'Filter',
99
	'text',
100
	$host
101 b86938e7 Stephen Beaver
))->setHelp('Use a regular expression to filter the tables.');
102 45d6ada5 Sjon Hortensius
103
$form->add($section);
104 37676f4e jim-p
105
$form->addGlobal(new Form_Button(
106
	'Submit',
107 faab522f Renato Botelho
	'Update',
108 37676f4e jim-p
	null,
109
	'fa-refresh'
110
))->addClass('btn-primary');
111
112 45d6ada5 Sjon Hortensius
print $form;
113 0eacb3b2 Scott Ullrich
?>
114 8fd9052f Colin Fleming
<script type="text/javascript">
115
//<![CDATA[
116 45d6ada5 Sjon Hortensius
function update_routes(section) {
117
	$.ajax(
118
		'/diag_routes.php',
119
		{
120
			type: 'post',
121
			data: $(document.forms[0]).serialize() +'&'+ section +'=true',
122
			success: update_routes_callback,
123
	});
124
}
125 92e8cb11 Renato Botelho
126 45d6ada5 Sjon Hortensius
function update_routes_callback(html) {
127
	// First line contains section
128
	var responseTextArr = html.split("\n");
129
	var section = responseTextArr.shift();
130
	var tbody = '';
131
	var field = '';
132
	var tr_class = '';
133
	var thead = '<tr>';
134
135
	for (var i = 0; i < responseTextArr.length; i++) {
136 2f4e37b1 Stephen Beaver
137 947141fd Phil Davis
		if (responseTextArr[i] == "") {
138 45d6ada5 Sjon Hortensius
			continue;
139 947141fd Phil Davis
		}
140 2f4e37b1 Stephen Beaver
141 947141fd Phil Davis
		if (i == 0) {
142 2f4e37b1 Stephen Beaver
			var tmp = '';
143 947141fd Phil Davis
		} else {
144 2f4e37b1 Stephen Beaver
			var tmp = '<tr>';
145 947141fd Phil Davis
		}
146 2f4e37b1 Stephen Beaver
147 45d6ada5 Sjon Hortensius
		var j = 0;
148
		var entry = responseTextArr[i].split(" ");
149
		for (var k = 0; k < entry.length; k++) {
150 947141fd Phil Davis
			if (entry[k] == "") {
151 92e8cb11 Renato Botelho
				continue;
152 947141fd Phil Davis
			}
153
			if (i == 0) {
154 45d6ada5 Sjon Hortensius
				tmp += '<th>' + entry[k] + '<\/th>';
155 947141fd Phil Davis
			} else {
156 45d6ada5 Sjon Hortensius
				tmp += '<td>' + entry[k] + '<\/td>';
157 947141fd Phil Davis
			}
158 45d6ada5 Sjon Hortensius
			j++;
159 92e8cb11 Renato Botelho
		}
160 45d6ada5 Sjon Hortensius
161 947141fd Phil Davis
		if (i == 0) {
162 45d6ada5 Sjon Hortensius
			thead += tmp;
163 947141fd Phil Davis
		} else {
164 2f4e37b1 Stephen Beaver
			tmp += '<td><\/td>'
165 45d6ada5 Sjon Hortensius
			tbody += tmp;
166 2f4e37b1 Stephen Beaver
		}
167 92e8cb11 Renato Botelho
	}
168
169 45d6ada5 Sjon Hortensius
	$('#' + section + ' > thead').html(thead);
170
	$('#' + section + ' > tbody').html(tbody);
171
}
172 92e8cb11 Renato Botelho
173 45d6ada5 Sjon Hortensius
function update_all_routes() {
174
	update_routes("IPv4");
175
	update_routes("IPv6");
176
}
177 92e8cb11 Renato Botelho
178 947141fd Phil Davis
events.push(function() {
179 865e0153 Stephen Beaver
	setInterval('update_all_routes()', 5000);
180 45d6ada5 Sjon Hortensius
	update_all_routes();
181 92e8cb11 Renato Botelho
182 947141fd Phil Davis
	$(document.forms[0]).on('submit', function(e) {
183 45d6ada5 Sjon Hortensius
		update_all_routes();
184 92e8cb11 Renato Botelho
185 45d6ada5 Sjon Hortensius
		e.preventDefault();
186
	});
187
});
188 8fd9052f Colin Fleming
//]]>
189 92e8cb11 Renato Botelho
</script>
190
191 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
192 185b4365 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv4 Routes")?></h2></div>
193 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
194 dd7ba16e Stephen Beaver
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4">
195 45d6ada5 Sjon Hortensius
		<thead>
196 2f4e37b1 Stephen Beaver
			<tr>
197
				<th><!-- filled by xhr --></th>
198
			</tr>
199 45d6ada5 Sjon Hortensius
		</thead>
200
		<tbody>
201
			<tr>
202
				<td><?=gettext("Gathering data, please wait...")?></td>
203
			</tr>
204
		</tbody>
205
		</table>
206
	</div>
207 0eacb3b2 Scott Ullrich
</div>
208
209 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
210 185b4365 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv6 Routes")?></h2></div>
211 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
212 dd7ba16e Stephen Beaver
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6">
213 45d6ada5 Sjon Hortensius
		<thead>
214 2f4e37b1 Stephen Beaver
			<tr>
215
				<th><!-- filled by xhr --></th>
216
			</tr>
217 45d6ada5 Sjon Hortensius
		</thead>
218
		<tbody>
219
			<tr>
220
				<td><?=gettext("Gathering data, please wait...")?></td>
221
			</tr>
222
		</tbody>
223
		</table>
224
	</div>
225
</div>
226 92e8dc9d Colin Fleming
227 c10cb196 Stephen Beaver
<?php include("foot.inc");