Project

General

Profile

Download (7.97 KB) Statistics
| Branch: | Tag: | Revision:
1 0eacb3b2 Scott Ullrich
<?php
2
/*
3 aaec5634 Renato Botelho
 * diag_routes.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6 2a2396a6 Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7 aaec5634 Renato Botelho
 * Copyright (c) 2006 Fernando Lamos
8
 * All rights reserved.
9
 *
10
 * Redistribution and use in source and binary forms, with or without
11
 * modification, are permitted provided that the following conditions are met:
12
 *
13
 * 1. Redistributions of source code must retain the above copyright notice,
14
 *    this list of conditions and the following disclaimer.
15
 *
16
 * 2. Redistributions in binary form must reproduce the above copyright
17
 *    notice, this list of conditions and the following disclaimer in
18
 *    the documentation and/or other materials provided with the
19
 *    distribution.
20
 *
21
 * 3. All advertising materials mentioning features or use of this software
22
 *    must display the following acknowledgment:
23
 *    "This product includes software developed by the pfSense Project
24
 *    for use in the pfSense® software distribution. (http://www.pfsense.org/).
25
 *
26
 * 4. The names "pfSense" and "pfSense Project" must not be used to
27
 *    endorse or promote products derived from this software without
28
 *    prior written permission. For written permission, please contact
29
 *    coreteam@pfsense.org.
30
 *
31
 * 5. Products derived from this software may not be called "pfSense"
32
 *    nor may "pfSense" appear in their names without prior written
33
 *    permission of the Electric Sheep Fencing, LLC.
34
 *
35
 * 6. Redistributions of any form whatsoever must retain the following
36
 *    acknowledgment:
37
 *
38
 * "This product includes software developed by the pfSense Project
39
 * for use in the pfSense software distribution (http://www.pfsense.org/).
40
 *
41
 * THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
42
 * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
43
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
44
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
45
 * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
46
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
47
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
48
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
49
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
50
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
51
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
52
 * OF THE POSSIBILITY OF SUCH DAMAGE.
53 fd9ebcd5 Stephen Beaver
 */
54 aaec5634 Renato Botelho
55 6b07c15a Matthew Grooms
##|+PRIV
56
##|*IDENT=page-diagnostics-routingtables
57 5230f468 jim-p
##|*NAME=Diagnostics: Routing tables
58 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
59
##|*MATCH=diag_routes.php*
60
##|-PRIV
61
62 288a2a0f Phil Davis
$limit = '100';
63
$filter = '';
64 45d6ada5 Sjon Hortensius
65 92e8cb11 Renato Botelho
if (isset($_REQUEST['isAjax'])) {
66 afe8afac PiBa-NL
	require_once('auth_check.inc');
67
	
68 ed893ee5 Phil Davis
	$netstat = "/usr/bin/netstat -rnW";
69 92e8cb11 Renato Botelho
	if (isset($_REQUEST['IPv6'])) {
70
		$netstat .= " -f inet6";
71
		echo "IPv6\n";
72
	} else {
73
		$netstat .= " -f inet";
74
		echo "IPv4\n";
75 5f601060 Phil Davis
	}
76 92e8cb11 Renato Botelho
77 5f601060 Phil Davis
	if (!empty($_REQUEST['filter'])) {
78 b1952073 jim-p
		$netstat .= " | /usr/bin/sed -e " . escapeshellarg("1,3d; 5,\$ { /" . htmlspecialchars($_REQUEST['filter']) . "/!d; };");
79 5f601060 Phil Davis
	} else {
80 92e8cb11 Renato Botelho
		$netstat .= " | /usr/bin/sed -e '1,3d'";
81 5f601060 Phil Davis
	}
82 92e8cb11 Renato Botelho
83 5f601060 Phil Davis
	if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
84 089d1e3f Stephen Beaver
		$_REQUEST['limit']++;  // Account for the header line
85 92e8cb11 Renato Botelho
		$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
86 5f601060 Phil Davis
	}
87 92e8cb11 Renato Botelho
88 ed893ee5 Phil Davis
	if (isset($_REQUEST['resolve'])) {
89
		$netstat_output_array = explode("\n", shell_exec($netstat));
90
		$output_text = "";
91
		foreach ($netstat_output_array as $netstat_line) {
92
			$netstat_columns_array = explode(" ", $netstat_line);
93
			$output_line = "";
94
			foreach ($netstat_columns_array as $netstat_column) {
95
				// An address can be like:
96
				// address%dev/CIDR     ff01::%em0/32
97
				// address%dev          fe80::a00:1234:5678:9abc%em0
98
				// address/CIDR         2001:470:12:abcd::/64       192.168.1.0/24
99
				// or just an address   2001:470:12:abcd:1:2:3:4    192.168.1.1
100
				// Separate the bit before and after any slash.
101
				$slash_parts = explode("/", $netstat_column);
102
				// Then separate the bit before and after any percent sign.
103
				$percent_parts = explode("%", $slash_parts[0]);
104
				if (is_ipaddr($percent_parts[0])) {
105
					// Try and reverse resolve the first part, which looks like an IP Address
106
					$output_line .= gethostbyaddr($percent_parts[0]);
107
					if (strlen($percent_parts[1]) > 0) {
108
						// Put back the percent bit.
109
						$output_line .= "%" . $percent_parts[1];
110
					}
111
					if (strlen($slash_parts[1]) > 0) {
112
						// Put back the slash bit.
113
						$output_line .= "/" . $slash_parts[1];
114
					}
115
				} else {
116
					$output_line .= $netstat_column;
117
				}
118
				$output_line .= " ";
119
			}
120
			$output_text .= trim($output_line) . "\n";
121
		}
122
	} else {
123
		$output_text = shell_exec($netstat);
124
	}
125 92e8cb11 Renato Botelho
126 ed893ee5 Phil Davis
	echo htmlspecialchars_decode($output_text);
127 92e8cb11 Renato Botelho
	exit;
128
}
129 afe8afac PiBa-NL
require_once('guiconfig.inc');
130 92e8cb11 Renato Botelho
131 a6a6ee00 k-paulius
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
132 b32dd0a6 jim-p
$shortcut_section = "routing";
133 0eacb3b2 Scott Ullrich
134
include('head.inc');
135
136 37676f4e jim-p
$form = new Form(false);
137 45d6ada5 Sjon Hortensius
$form->addGlobal(new Form_Input(
138
	'isAjax',
139
	null,
140
	'hidden',
141
	1
142
));
143 e897f304 Phil Davis
$section = new Form_Section('Routing Table Display Options');
144 45d6ada5 Sjon Hortensius
145
$section->addInput(new Form_Checkbox(
146
	'resolve',
147
	'Resolve names',
148
	'Enable',
149
	$resolve
150 288a2a0f Phil Davis
))->setHelp('Enabling name resolution may cause the query to take longer.'.
151 ce871619 Stephen Beaver
	' It can be stopped at any time by clicking the Stop button in the browser.');
152 45d6ada5 Sjon Hortensius
153
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
154
$section->addInput(new Form_Select(
155
	'limit',
156
	'Rows to display',
157
	$limit,
158
	array_combine($validLimits, $validLimits)
159
));
160
161
$section->addInput(new Form_Input(
162
	'filter',
163
	'Filter',
164
	'text',
165
	$host
166 5e40e7af Stephen Beaver
))->setHelp('Use a regular expression to filter the tables.');
167 45d6ada5 Sjon Hortensius
168
$form->add($section);
169 37676f4e jim-p
170
$form->addGlobal(new Form_Button(
171
	'Submit',
172 faab522f Renato Botelho
	'Update',
173 37676f4e jim-p
	null,
174
	'fa-refresh'
175
))->addClass('btn-primary');
176
177 45d6ada5 Sjon Hortensius
print $form;
178 0eacb3b2 Scott Ullrich
?>
179 8fd9052f Colin Fleming
<script type="text/javascript">
180
//<![CDATA[
181 45d6ada5 Sjon Hortensius
function update_routes(section) {
182
	$.ajax(
183
		'/diag_routes.php',
184
		{
185
			type: 'post',
186
			data: $(document.forms[0]).serialize() +'&'+ section +'=true',
187
			success: update_routes_callback,
188
	});
189
}
190 92e8cb11 Renato Botelho
191 45d6ada5 Sjon Hortensius
function update_routes_callback(html) {
192
	// First line contains section
193
	var responseTextArr = html.split("\n");
194
	var section = responseTextArr.shift();
195
	var tbody = '';
196
	var field = '';
197
	var tr_class = '';
198
	var thead = '<tr>';
199
200
	for (var i = 0; i < responseTextArr.length; i++) {
201 2f4e37b1 Stephen Beaver
202 947141fd Phil Davis
		if (responseTextArr[i] == "") {
203 45d6ada5 Sjon Hortensius
			continue;
204 947141fd Phil Davis
		}
205 2f4e37b1 Stephen Beaver
206 947141fd Phil Davis
		if (i == 0) {
207 2f4e37b1 Stephen Beaver
			var tmp = '';
208 947141fd Phil Davis
		} else {
209 2f4e37b1 Stephen Beaver
			var tmp = '<tr>';
210 947141fd Phil Davis
		}
211 2f4e37b1 Stephen Beaver
212 45d6ada5 Sjon Hortensius
		var j = 0;
213
		var entry = responseTextArr[i].split(" ");
214
		for (var k = 0; k < entry.length; k++) {
215 947141fd Phil Davis
			if (entry[k] == "") {
216 92e8cb11 Renato Botelho
				continue;
217 947141fd Phil Davis
			}
218
			if (i == 0) {
219 45d6ada5 Sjon Hortensius
				tmp += '<th>' + entry[k] + '<\/th>';
220 947141fd Phil Davis
			} else {
221 45d6ada5 Sjon Hortensius
				tmp += '<td>' + entry[k] + '<\/td>';
222 947141fd Phil Davis
			}
223 45d6ada5 Sjon Hortensius
			j++;
224 92e8cb11 Renato Botelho
		}
225 45d6ada5 Sjon Hortensius
226 947141fd Phil Davis
		if (i == 0) {
227 45d6ada5 Sjon Hortensius
			thead += tmp;
228 947141fd Phil Davis
		} else {
229 2f4e37b1 Stephen Beaver
			tmp += '<td><\/td>'
230 45d6ada5 Sjon Hortensius
			tbody += tmp;
231 2f4e37b1 Stephen Beaver
		}
232 92e8cb11 Renato Botelho
	}
233
234 45d6ada5 Sjon Hortensius
	$('#' + section + ' > thead').html(thead);
235
	$('#' + section + ' > tbody').html(tbody);
236
}
237 92e8cb11 Renato Botelho
238 45d6ada5 Sjon Hortensius
function update_all_routes() {
239
	update_routes("IPv4");
240
	update_routes("IPv6");
241
}
242 92e8cb11 Renato Botelho
243 947141fd Phil Davis
events.push(function() {
244 865e0153 Stephen Beaver
	setInterval('update_all_routes()', 5000);
245 45d6ada5 Sjon Hortensius
	update_all_routes();
246 92e8cb11 Renato Botelho
247 947141fd Phil Davis
	$(document.forms[0]).on('submit', function(e) {
248 45d6ada5 Sjon Hortensius
		update_all_routes();
249 92e8cb11 Renato Botelho
250 45d6ada5 Sjon Hortensius
		e.preventDefault();
251
	});
252
});
253 8fd9052f Colin Fleming
//]]>
254 92e8cb11 Renato Botelho
</script>
255
256 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
257 185b4365 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv4 Routes")?></h2></div>
258 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
259 dd7ba16e Stephen Beaver
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4">
260 45d6ada5 Sjon Hortensius
		<thead>
261 2f4e37b1 Stephen Beaver
			<tr>
262
				<th><!-- filled by xhr --></th>
263
			</tr>
264 45d6ada5 Sjon Hortensius
		</thead>
265
		<tbody>
266
			<tr>
267
				<td><?=gettext("Gathering data, please wait...")?></td>
268
			</tr>
269
		</tbody>
270
		</table>
271
	</div>
272 0eacb3b2 Scott Ullrich
</div>
273
274 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
275 185b4365 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv6 Routes")?></h2></div>
276 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
277 dd7ba16e Stephen Beaver
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6">
278 45d6ada5 Sjon Hortensius
		<thead>
279 2f4e37b1 Stephen Beaver
			<tr>
280
				<th><!-- filled by xhr --></th>
281
			</tr>
282 45d6ada5 Sjon Hortensius
		</thead>
283
		<tbody>
284
			<tr>
285
				<td><?=gettext("Gathering data, please wait...")?></td>
286
			</tr>
287
		</tbody>
288
		</table>
289
	</div>
290
</div>
291 92e8dc9d Colin Fleming
292 c10cb196 Stephen Beaver
<?php include("foot.inc");