Project

General

Profile

Download (6.71 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 6b07c15a Matthew Grooms
##|+PRIV
57
##|*IDENT=page-diagnostics-routingtables
58 5230f468 jim-p
##|*NAME=Diagnostics: Routing tables
59 6b07c15a Matthew Grooms
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
60
##|*MATCH=diag_routes.php*
61
##|-PRIV
62
63 0eacb3b2 Scott Ullrich
include('guiconfig.inc');
64
65 288a2a0f Phil Davis
$limit = '100';
66
$filter = '';
67 45d6ada5 Sjon Hortensius
68 92e8cb11 Renato Botelho
if (isset($_REQUEST['isAjax'])) {
69
	$netstat = "/usr/bin/netstat -rW";
70
	if (isset($_REQUEST['IPv6'])) {
71
		$netstat .= " -f inet6";
72
		echo "IPv6\n";
73
	} else {
74
		$netstat .= " -f inet";
75
		echo "IPv4\n";
76 45d6ada5 Sjon Hortensius
77 92e8cb11 Renato Botelho
	}
78 5f601060 Phil Davis
	if (!isset($_REQUEST['resolve'])) {
79 92e8cb11 Renato Botelho
		$netstat .= " -n";
80 5f601060 Phil Davis
	}
81 92e8cb11 Renato Botelho
82 5f601060 Phil Davis
	if (!empty($_REQUEST['filter'])) {
83 92e8cb11 Renato Botelho
		$netstat .= " | /usr/bin/sed -e '1,3d; 5,\$ { /" . escapeshellarg(htmlspecialchars($_REQUEST['filter'])) . "/!d; };'";
84 5f601060 Phil Davis
	} else {
85 92e8cb11 Renato Botelho
		$netstat .= " | /usr/bin/sed -e '1,3d'";
86 5f601060 Phil Davis
	}
87 92e8cb11 Renato Botelho
88 5f601060 Phil Davis
	if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
89 92e8cb11 Renato Botelho
		$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
90 5f601060 Phil Davis
	}
91 92e8cb11 Renato Botelho
92
	echo htmlspecialchars_decode(shell_exec($netstat));
93
94
	exit;
95
}
96
97 a6a6ee00 k-paulius
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
98 b32dd0a6 jim-p
$shortcut_section = "routing";
99 0eacb3b2 Scott Ullrich
100
include('head.inc');
101
102 37676f4e jim-p
$form = new Form(false);
103 45d6ada5 Sjon Hortensius
$form->addGlobal(new Form_Input(
104
	'isAjax',
105
	null,
106
	'hidden',
107
	1
108
));
109 e897f304 Phil Davis
$section = new Form_Section('Routing Table Display Options');
110 45d6ada5 Sjon Hortensius
111
$section->addInput(new Form_Checkbox(
112
	'resolve',
113
	'Resolve names',
114
	'Enable',
115
	$resolve
116 288a2a0f Phil Davis
))->setHelp('Enabling name resolution may cause the query to take longer.'.
117 45d6ada5 Sjon Hortensius
	' You can stop it at any time by clicking the Stop button in your browser.');
118
119
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
120
$section->addInput(new Form_Select(
121
	'limit',
122
	'Rows to display',
123
	$limit,
124
	array_combine($validLimits, $validLimits)
125
));
126
127
$section->addInput(new Form_Input(
128
	'filter',
129
	'Filter',
130
	'text',
131
	$host
132
))->setHelp('Use a regular expression to filter IP address or hostnames');
133
134
$form->add($section);
135 37676f4e jim-p
136
$form->addGlobal(new Form_Button(
137
	'Submit',
138
	'Update',
139
	null,
140
	'fa-refresh'
141
))->addClass('btn-primary');
142
143 45d6ada5 Sjon Hortensius
print $form;
144 0eacb3b2 Scott Ullrich
?>
145 8fd9052f Colin Fleming
<script type="text/javascript">
146
//<![CDATA[
147 45d6ada5 Sjon Hortensius
function update_routes(section) {
148
	$.ajax(
149
		'/diag_routes.php',
150
		{
151
			type: 'post',
152
			data: $(document.forms[0]).serialize() +'&'+ section +'=true',
153
			success: update_routes_callback,
154
	});
155
}
156 92e8cb11 Renato Botelho
157 45d6ada5 Sjon Hortensius
function update_routes_callback(html) {
158
	// First line contains section
159
	var responseTextArr = html.split("\n");
160
	var section = responseTextArr.shift();
161
	var tbody = '';
162
	var field = '';
163
	var tr_class = '';
164
	var thead = '<tr>';
165
166
	for (var i = 0; i < responseTextArr.length; i++) {
167 2f4e37b1 Stephen Beaver
168 947141fd Phil Davis
		if (responseTextArr[i] == "") {
169 45d6ada5 Sjon Hortensius
			continue;
170 947141fd Phil Davis
		}
171 2f4e37b1 Stephen Beaver
172 947141fd Phil Davis
		if (i == 0) {
173 2f4e37b1 Stephen Beaver
			var tmp = '';
174 947141fd Phil Davis
		} else {
175 2f4e37b1 Stephen Beaver
			var tmp = '<tr>';
176 947141fd Phil Davis
		}
177 2f4e37b1 Stephen Beaver
178 45d6ada5 Sjon Hortensius
		var j = 0;
179
		var entry = responseTextArr[i].split(" ");
180
		for (var k = 0; k < entry.length; k++) {
181 947141fd Phil Davis
			if (entry[k] == "") {
182 92e8cb11 Renato Botelho
				continue;
183 947141fd Phil Davis
			}
184
			if (i == 0) {
185 45d6ada5 Sjon Hortensius
				tmp += '<th>' + entry[k] + '<\/th>';
186 947141fd Phil Davis
			} else {
187 45d6ada5 Sjon Hortensius
				tmp += '<td>' + entry[k] + '<\/td>';
188 947141fd Phil Davis
			}
189 45d6ada5 Sjon Hortensius
			j++;
190 92e8cb11 Renato Botelho
		}
191 45d6ada5 Sjon Hortensius
192 947141fd Phil Davis
		if (i == 0) {
193 45d6ada5 Sjon Hortensius
			thead += tmp;
194 947141fd Phil Davis
		} else {
195 2f4e37b1 Stephen Beaver
			tmp += '<td><\/td>'
196 45d6ada5 Sjon Hortensius
			tbody += tmp;
197 2f4e37b1 Stephen Beaver
		}
198 92e8cb11 Renato Botelho
	}
199
200 45d6ada5 Sjon Hortensius
	$('#' + section + ' > thead').html(thead);
201
	$('#' + section + ' > tbody').html(tbody);
202
}
203 92e8cb11 Renato Botelho
204 45d6ada5 Sjon Hortensius
function update_all_routes() {
205
	update_routes("IPv4");
206
	update_routes("IPv6");
207
}
208 92e8cb11 Renato Botelho
209 947141fd Phil Davis
events.push(function() {
210 865e0153 Stephen Beaver
	setInterval('update_all_routes()', 5000);
211 45d6ada5 Sjon Hortensius
	update_all_routes();
212 92e8cb11 Renato Botelho
213 947141fd Phil Davis
	$(document.forms[0]).on('submit', function(e) {
214 45d6ada5 Sjon Hortensius
		update_all_routes();
215 92e8cb11 Renato Botelho
216 45d6ada5 Sjon Hortensius
		e.preventDefault();
217
	});
218
});
219 8fd9052f Colin Fleming
//]]>
220 92e8cb11 Renato Botelho
</script>
221
222 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
223 185b4365 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv4 Routes")?></h2></div>
224 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
225 dd7ba16e Stephen Beaver
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4">
226 45d6ada5 Sjon Hortensius
		<thead>
227 2f4e37b1 Stephen Beaver
			<tr>
228
				<th><!-- filled by xhr --></th>
229
			</tr>
230 45d6ada5 Sjon Hortensius
		</thead>
231
		<tbody>
232
			<tr>
233
				<td><?=gettext("Gathering data, please wait...")?></td>
234
			</tr>
235
		</tbody>
236
		</table>
237
	</div>
238 0eacb3b2 Scott Ullrich
</div>
239
240 45d6ada5 Sjon Hortensius
<div class="panel panel-default">
241 185b4365 Phil Davis
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv6 Routes")?></h2></div>
242 45d6ada5 Sjon Hortensius
	<div class="panel panel-body">
243 dd7ba16e Stephen Beaver
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6">
244 45d6ada5 Sjon Hortensius
		<thead>
245 2f4e37b1 Stephen Beaver
			<tr>
246
				<th><!-- filled by xhr --></th>
247
			</tr>
248 45d6ada5 Sjon Hortensius
		</thead>
249
		<tbody>
250
			<tr>
251
				<td><?=gettext("Gathering data, please wait...")?></td>
252
			</tr>
253
		</tbody>
254
		</table>
255
	</div>
256
</div>
257 92e8dc9d Colin Fleming
258 c10cb196 Stephen Beaver
<?php include("foot.inc");