Project

General

Profile

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