Project

General

Profile

Download (6.62 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
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
$form = new Form('Update');
107
$form->addGlobal(new Form_Input(
108
	'isAjax',
109
	null,
110
	'hidden',
111
	1
112
));
113
$section = new Form_Section('Routing Table Display Options');
114

    
115
$section->addInput(new Form_Checkbox(
116
	'resolve',
117
	'Resolve names',
118
	'Enable',
119
	$resolve
120
))->setHelp('Enabling name resolution may cause the query to take longer.'.
121
	' You can stop it at any time by clicking the Stop button in your browser.');
122

    
123
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
124
$section->addInput(new Form_Select(
125
	'limit',
126
	'Rows to display',
127
	$limit,
128
	array_combine($validLimits, $validLimits)
129
));
130

    
131
$section->addInput(new Form_Input(
132
	'filter',
133
	'Filter',
134
	'text',
135
	$host
136
))->setHelp('Use a regular expression to filter IP address or hostnames');
137

    
138
$form->add($section);
139
print $form;
140
?>
141
<script type="text/javascript">
142
//<![CDATA[
143
function update_routes(section) {
144
	$.ajax(
145
		'/diag_routes.php',
146
		{
147
			type: 'post',
148
			data: $(document.forms[0]).serialize() +'&'+ section +'=true',
149
			success: update_routes_callback,
150
	});
151
}
152

    
153
function update_routes_callback(html) {
154
	// First line contains section
155
	var responseTextArr = html.split("\n");
156
	var section = responseTextArr.shift();
157
	var tbody = '';
158
	var field = '';
159
	var tr_class = '';
160
	var thead = '<tr>';
161

    
162
	for (var i = 0; i < responseTextArr.length; i++) {
163

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

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

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

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

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

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

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

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

    
208
		e.preventDefault();
209
	});
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");
(33-33/228)