Project

General

Profile

Download (5.56 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 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 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 57a737f1 jim-p
/* Keep above the AJAX code so it gets CSRF protection */
36
require_once('guiconfig.inc');
37
38 72ea2b69 jim-p
if (isset($_POST['isAjax'])) {
39 60ba7c76 PiBa-NL
	require_once('auth_check.inc');
40 179377b0 robjarsen
41 92e8cb11 Renato Botelho
	$netstat = "/usr/bin/netstat -rW";
42 72ea2b69 jim-p
	if (isset($_POST['IPv6'])) {
43 92e8cb11 Renato Botelho
		$netstat .= " -f inet6";
44
		echo "IPv6\n";
45
	} else {
46
		$netstat .= " -f inet";
47
		echo "IPv4\n";
48 45d6ada5 Sjon Hortensius
49 92e8cb11 Renato Botelho
	}
50 72ea2b69 jim-p
	if (!isset($_POST['resolve'])) {
51 92e8cb11 Renato Botelho
		$netstat .= " -n";
52 5f601060 Phil Davis
	}
53 92e8cb11 Renato Botelho
54 72ea2b69 jim-p
	$netstat .= " | /usr/bin/tail -n +5";
55
56 57a737f1 jim-p
	/* Ensure the user-supplied filter is sane */
57
	$filtertext = cleanup_regex_pattern($_POST['filter']);
58
	if (!empty($filtertext)) {
59
		/* Place filter after "--" (bare double-dash) so grep knows not
60
		 * to interpret the filter as command line parameters.
61
		 */
62
		$netstat .= " | /usr/bin/egrep -- " . escapeshellarg($filtertext);
63 5f601060 Phil Davis
	}
64 92e8cb11 Renato Botelho
65 72ea2b69 jim-p
	if (is_numeric($_POST['limit']) && $_POST['limit'] > 0) {
66
		$netstat .= " | /usr/bin/head -n " . escapeshellarg($_POST['limit']);
67 5f601060 Phil Davis
	}
68 92e8cb11 Renato Botelho
69
	echo htmlspecialchars_decode(shell_exec($netstat));
70
71
	exit;
72
}
73
74 a6a6ee00 k-paulius
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
75 b32dd0a6 jim-p
$shortcut_section = "routing";
76 0eacb3b2 Scott Ullrich
77
include('head.inc');
78
79 37676f4e jim-p
$form = new Form(false);
80 45d6ada5 Sjon Hortensius
$form->addGlobal(new Form_Input(
81
	'isAjax',
82
	null,
83
	'hidden',
84
	1
85
));
86 e897f304 Phil Davis
$section = new Form_Section('Routing Table Display Options');
87 45d6ada5 Sjon Hortensius
88
$section->addInput(new Form_Checkbox(
89
	'resolve',
90
	'Resolve names',
91
	'Enable',
92
	$resolve
93 288a2a0f Phil Davis
))->setHelp('Enabling name resolution may cause the query to take longer.'.
94 b6078bed NOYB
	' It can be stopped at any time by clicking the Stop button in the browser.');
95 45d6ada5 Sjon Hortensius
96
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
97
$section->addInput(new Form_Select(
98
	'limit',
99
	'Rows to display',
100
	$limit,
101
	array_combine($validLimits, $validLimits)
102
));
103
104
$section->addInput(new Form_Input(
105
	'filter',
106
	'Filter',
107
	'text',
108 72ea2b69 jim-p
	null
109 57a737f1 jim-p
))->setHelp('Use a regular expression to filter the tables. Invalid or potentially dangerous patterns will be ignored.');
110 45d6ada5 Sjon Hortensius
111
$form->add($section);
112 37676f4e jim-p
113
$form->addGlobal(new Form_Button(
114
	'Submit',
115 faab522f Renato Botelho
	'Update',
116 37676f4e jim-p
	null,
117
	'fa-refresh'
118
))->addClass('btn-primary');
119
120 45d6ada5 Sjon Hortensius
print $form;
121 0eacb3b2 Scott Ullrich
?>
122 8fd9052f Colin Fleming
<script type="text/javascript">
123
//<![CDATA[
124 45d6ada5 Sjon Hortensius
function update_routes(section) {
125
	$.ajax(
126
		'/diag_routes.php',
127
		{
128
			type: 'post',
129
			data: $(document.forms[0]).serialize() +'&'+ section +'=true',
130
			success: update_routes_callback,
131
	});
132
}
133 92e8cb11 Renato Botelho
134 45d6ada5 Sjon Hortensius
function update_routes_callback(html) {
135
	// First line contains section
136
	var responseTextArr = html.split("\n");
137
	var section = responseTextArr.shift();
138
	var tbody = '';
139
	var field = '';
140
	var tr_class = '';
141
142
	for (var i = 0; i < responseTextArr.length; i++) {
143 2f4e37b1 Stephen Beaver
144 947141fd Phil Davis
		if (responseTextArr[i] == "") {
145 45d6ada5 Sjon Hortensius
			continue;
146 947141fd Phil Davis
		}
147 2f4e37b1 Stephen Beaver
148 72ea2b69 jim-p
		var tmp = '<tr>';
149 2f4e37b1 Stephen Beaver
150 45d6ada5 Sjon Hortensius
		var j = 0;
151
		var entry = responseTextArr[i].split(" ");
152
		for (var k = 0; k < entry.length; k++) {
153 947141fd Phil Davis
			if (entry[k] == "") {
154 92e8cb11 Renato Botelho
				continue;
155 947141fd Phil Davis
			}
156 72ea2b69 jim-p
			tmp += '<td>' + entry[k] + '<\/td>';
157 45d6ada5 Sjon Hortensius
			j++;
158 92e8cb11 Renato Botelho
		}
159 45d6ada5 Sjon Hortensius
160 72ea2b69 jim-p
		tmp += '<td><\/td>'
161
		tbody += tmp;
162 92e8cb11 Renato Botelho
	}
163
164 45d6ada5 Sjon Hortensius
	$('#' + section + ' > tbody').html(tbody);
165
}
166 92e8cb11 Renato Botelho
167 45d6ada5 Sjon Hortensius
function update_all_routes() {
168
	update_routes("IPv4");
169
	update_routes("IPv6");
170
}
171 92e8cb11 Renato Botelho
172 947141fd Phil Davis
events.push(function() {
173 72ea2b69 jim-p
	setInterval('update_all_routes()', 15000);
174 45d6ada5 Sjon Hortensius
	update_all_routes();
175 92e8cb11 Renato Botelho
176 947141fd Phil Davis
	$(document.forms[0]).on('submit', function(e) {
177 45d6ada5 Sjon Hortensius
		update_all_routes();
178 92e8cb11 Renato Botelho
179 45d6ada5 Sjon Hortensius
		e.preventDefault();
180
	});
181
});
182 8fd9052f Colin Fleming
//]]>
183 92e8cb11 Renato Botelho
</script>
184
185 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
186 185b4365 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv4 Routes")?></h2></div>
187 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
188 72ea2b69 jim-p
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4" data-sortable>
189 45d6ada5 Sjon Hortensius
		<thead>
190 2f4e37b1 Stephen Beaver
			<tr>
191 72ea2b69 jim-p
				<th><?= gettext('Destination') ?></th>
192
				<th><?= gettext('Gateway') ?></th>
193
				<th><?= gettext('Flags') ?></th>
194
				<th><?= gettext('Uses') ?></th>
195
				<th><?= gettext('MTU') ?></th>
196
				<th><?= gettext('Interface') ?></th>
197
				<th><?= gettext('Expire') ?></th>
198 2f4e37b1 Stephen Beaver
			</tr>
199 45d6ada5 Sjon Hortensius
		</thead>
200
		<tbody>
201
			<tr>
202 72ea2b69 jim-p
				<td colspan="7"><?=gettext("Gathering data, please wait...")?></td>
203 45d6ada5 Sjon Hortensius
			</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 72ea2b69 jim-p
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6" data-sortable>
213 45d6ada5 Sjon Hortensius
		<thead>
214 2f4e37b1 Stephen Beaver
			<tr>
215 72ea2b69 jim-p
				<th><?= gettext('Destination') ?></th>
216
				<th><?= gettext('Gateway') ?></th>
217
				<th><?= gettext('Flags') ?></th>
218
				<th><?= gettext('Uses') ?></th>
219
				<th><?= gettext('MTU') ?></th>
220
				<th><?= gettext('Interface') ?></th>
221
				<th><?= gettext('Expire') ?></th>
222 2f4e37b1 Stephen Beaver
			</tr>
223 45d6ada5 Sjon Hortensius
		</thead>
224
		<tbody>
225
			<tr>
226 72ea2b69 jim-p
				<td colspan="7"><?=gettext("Gathering data, please wait...")?></td>
227 45d6ada5 Sjon Hortensius
			</tr>
228
		</tbody>
229
		</table>
230
	</div>
231
</div>
232 92e8dc9d Colin Fleming
233 c10cb196 Stephen Beaver
<?php include("foot.inc");