Project

General

Profile

Download (6.63 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/*
3
	diag_routes.php
4
*/
5
/* ====================================================================
6
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved.
7
 *  Copyright (c)  2006 Fernando Lamos
8
 *
9
 *  Redistribution and use in source and binary forms, with or without modification,
10
 *  are permitted provided that the following conditions are met:
11
 *
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
 *      distribution.
19
 *
20
 *  3. All advertising materials mentioning features or use of this software
21
 *      must display the following acknowledgment:
22
 *      "This product includes software developed by the pfSense Project
23
 *       for use in the pfSense software distribution. (http://www.pfsense.org/).
24
 *
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
 *
40
 *  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
/*
57
	pfSense_BUILDER_BINARIES:	/usr/bin/netstat
58
	pfSense_MODULE:	routing
59
*/
60
##|+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
include('guiconfig.inc');
68

    
69
$limit = '100';
70
$filter = '';
71

    
72
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

    
81
	}
82
	if (!isset($_REQUEST['resolve'])) {
83
		$netstat .= " -n";
84
	}
85

    
86
	if (!empty($_REQUEST['filter'])) {
87
		$netstat .= " | /usr/bin/sed -e '1,3d; 5,\$ { /" . escapeshellarg(htmlspecialchars($_REQUEST['filter'])) . "/!d; };'";
88
	} else {
89
		$netstat .= " | /usr/bin/sed -e '1,3d'";
90
	}
91

    
92
	if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
93
		$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
94
	}
95

    
96
	echo htmlspecialchars_decode(shell_exec($netstat));
97

    
98
	exit;
99
}
100

    
101
$pgtitle = array(gettext("Diagnostics"), gettext("Routing tables"));
102
$shortcut_section = "routing";
103

    
104
include('head.inc');
105

    
106
require_once('classes/Form.class.php');
107

    
108
$form = new Form('Update');
109
$form->addGlobal(new Form_Input(
110
	'isAjax',
111
	null,
112
	'hidden',
113
	1
114
));
115
$section = new Form_Section('Routing Table Display Options');
116

    
117
$section->addInput(new Form_Checkbox(
118
	'resolve',
119
	'Resolve names',
120
	'Enable',
121
	$resolve
122
))->setHelp('Enabling name resolution may cause the query to take longer.'.
123
	' 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
?>
143
<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

    
154
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

    
165
		if (responseTextArr[i] == "")
166
			continue;
167

    
168
		if (i == 0)
169
			var tmp = '';
170
		else
171
			var tmp = '<tr>';
172

    
173
		var j = 0;
174
		var entry = responseTextArr[i].split(" ");
175
		for (var k = 0; k < entry.length; k++) {
176
			if (entry[k] == "")
177
				continue;
178
			if (i == 0)
179
				tmp += '<th>' + entry[k] + '<\/th>';
180
			else
181
				tmp += '<td>' + entry[k] + '<\/td>';
182
			j++;
183
		}
184

    
185
		if (i == 0)
186
			thead += tmp;
187
		else {
188
			tmp += '<td><\/td>'
189
			tbody += tmp;
190
		}
191
	}
192

    
193
	$('#' + section + ' > thead').html(thead);
194
	$('#' + section + ' > tbody').html(tbody);
195
}
196

    
197
function update_all_routes() {
198
	update_routes("IPv4");
199
	update_routes("IPv6");
200
}
201

    
202
events.push(function(){
203
	setInterval('update_all_routes()', 5000);
204
	update_all_routes();
205

    
206
	$(document.forms[0]).on('submit', function(e){
207
		update_all_routes();
208

    
209
		e.preventDefault();
210
	});
211
});
212
</script>
213

    
214
<div class="panel panel-default">
215
	<div class="panel-heading"><h2 class="panel-title">IPv4 Routes</h2></div>
216
	<div class="panel panel-body">
217
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4">
218
		<thead>
219
			<tr>
220
				<th><!-- filled by xhr --></th>
221
			</tr>
222
		</thead>
223
		<tbody>
224
			<tr>
225
				<td><?=gettext("Gathering data, please wait...")?></td>
226
			</tr>
227
		</tbody>
228
		</table>
229
	</div>
230
</div>
231

    
232
<div class="panel panel-default">
233
	<div class="panel-heading"><h2 class="panel-title">IPv6 Routes</h2></div>
234
	<div class="panel panel-body">
235
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6">
236
		<thead>
237
			<tr>
238
				<th><!-- filled by xhr --></th>
239
			</tr>
240
		</thead>
241
		<tbody>
242
			<tr>
243
				<td><?=gettext("Gathering data, please wait...")?></td>
244
			</tr>
245
		</tbody>
246
		</table>
247
	</div>
248
</div>
249

    
250
<?php include("foot.inc");
(34-34/234)