Project

General

Profile

Download (7.97 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
 * diag_routes.php
4
 *
5
 * part of pfSense (https://www.pfsense.org)
6
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
7
 * 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
 */
54

    
55
##|+PRIV
56
##|*IDENT=page-diagnostics-routingtables
57
##|*NAME=Diagnostics: Routing tables
58
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
59
##|*MATCH=diag_routes.php*
60
##|-PRIV
61

    
62
$limit = '100';
63
$filter = '';
64

    
65
if (isset($_REQUEST['isAjax'])) {
66
	require_once('auth_check.inc');
67
	
68
	$netstat = "/usr/bin/netstat -rnW";
69
	if (isset($_REQUEST['IPv6'])) {
70
		$netstat .= " -f inet6";
71
		echo "IPv6\n";
72
	} else {
73
		$netstat .= " -f inet";
74
		echo "IPv4\n";
75
	}
76

    
77
	if (!empty($_REQUEST['filter'])) {
78
		$netstat .= " | /usr/bin/sed -e " . escapeshellarg("1,3d; 5,\$ { /" . htmlspecialchars($_REQUEST['filter']) . "/!d; };");
79
	} else {
80
		$netstat .= " | /usr/bin/sed -e '1,3d'";
81
	}
82

    
83
	if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
84
		$_REQUEST['limit']++;  // Account for the header line
85
		$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
86
	}
87

    
88
	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

    
126
	echo htmlspecialchars_decode($output_text);
127
	exit;
128
}
129
require_once('guiconfig.inc');
130

    
131
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
132
$shortcut_section = "routing";
133

    
134
include('head.inc');
135

    
136
$form = new Form(false);
137
$form->addGlobal(new Form_Input(
138
	'isAjax',
139
	null,
140
	'hidden',
141
	1
142
));
143
$section = new Form_Section('Routing Table Display Options');
144

    
145
$section->addInput(new Form_Checkbox(
146
	'resolve',
147
	'Resolve names',
148
	'Enable',
149
	$resolve
150
))->setHelp('Enabling name resolution may cause the query to take longer.'.
151
	' It can be stopped at any time by clicking the Stop button in the browser.');
152

    
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
))->setHelp('Use a regular expression to filter the tables.');
167

    
168
$form->add($section);
169

    
170
$form->addGlobal(new Form_Button(
171
	'Submit',
172
	'Update',
173
	null,
174
	'fa-refresh'
175
))->addClass('btn-primary');
176

    
177
print $form;
178
?>
179
<script type="text/javascript">
180
//<![CDATA[
181
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

    
191
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

    
202
		if (responseTextArr[i] == "") {
203
			continue;
204
		}
205

    
206
		if (i == 0) {
207
			var tmp = '';
208
		} else {
209
			var tmp = '<tr>';
210
		}
211

    
212
		var j = 0;
213
		var entry = responseTextArr[i].split(" ");
214
		for (var k = 0; k < entry.length; k++) {
215
			if (entry[k] == "") {
216
				continue;
217
			}
218
			if (i == 0) {
219
				tmp += '<th>' + entry[k] + '<\/th>';
220
			} else {
221
				tmp += '<td>' + entry[k] + '<\/td>';
222
			}
223
			j++;
224
		}
225

    
226
		if (i == 0) {
227
			thead += tmp;
228
		} else {
229
			tmp += '<td><\/td>'
230
			tbody += tmp;
231
		}
232
	}
233

    
234
	$('#' + section + ' > thead').html(thead);
235
	$('#' + section + ' > tbody').html(tbody);
236
}
237

    
238
function update_all_routes() {
239
	update_routes("IPv4");
240
	update_routes("IPv6");
241
}
242

    
243
events.push(function() {
244
	setInterval('update_all_routes()', 5000);
245
	update_all_routes();
246

    
247
	$(document.forms[0]).on('submit', function(e) {
248
		update_all_routes();
249

    
250
		e.preventDefault();
251
	});
252
});
253
//]]>
254
</script>
255

    
256
<div class="panel panel-default">
257
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv4 Routes")?></h2></div>
258
	<div class="panel panel-body">
259
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4">
260
		<thead>
261
			<tr>
262
				<th><!-- filled by xhr --></th>
263
			</tr>
264
		</thead>
265
		<tbody>
266
			<tr>
267
				<td><?=gettext("Gathering data, please wait...")?></td>
268
			</tr>
269
		</tbody>
270
		</table>
271
	</div>
272
</div>
273

    
274
<div class="panel panel-default">
275
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv6 Routes")?></h2></div>
276
	<div class="panel panel-body">
277
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6">
278
		<thead>
279
			<tr>
280
				<th><!-- filled by xhr --></th>
281
			</tr>
282
		</thead>
283
		<tbody>
284
			<tr>
285
				<td><?=gettext("Gathering data, please wait...")?></td>
286
			</tr>
287
		</tbody>
288
		</table>
289
	</div>
290
</div>
291

    
292
<?php include("foot.inc");
(28-28/230)