Project

General

Profile

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