Project

General

Profile

Download (6.57 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 Electric Sheep Fencing, LLC
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
require_once('guiconfig.inc');
63

    
64
$limit = '100';
65
$filter = '';
66

    
67
if (isset($_REQUEST['isAjax'])) {
68
	$netstat = "/usr/bin/netstat -rW";
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 (!isset($_REQUEST['resolve'])) {
78
		$netstat .= " -n";
79
	}
80

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

    
87
	if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
88
		$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
89
	}
90

    
91
	echo htmlspecialchars_decode(shell_exec($netstat));
92

    
93
	exit;
94
}
95

    
96
$pgtitle = array(gettext("Diagnostics"), gettext("Routes"));
97
$shortcut_section = "routing";
98

    
99
include('head.inc');
100

    
101
$form = new Form(false);
102
$form->addGlobal(new Form_Input(
103
	'isAjax',
104
	null,
105
	'hidden',
106
	1
107
));
108
$section = new Form_Section('Routing Table Display Options');
109

    
110
$section->addInput(new Form_Checkbox(
111
	'resolve',
112
	'Resolve names',
113
	'Enable',
114
	$resolve
115
))->setHelp('Enabling name resolution may cause the query to take longer.'.
116
	' It can be stopped at any time by clicking the Stop button in the browser.');
117

    
118
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
119
$section->addInput(new Form_Select(
120
	'limit',
121
	'Rows to display',
122
	$limit,
123
	array_combine($validLimits, $validLimits)
124
));
125

    
126
$section->addInput(new Form_Input(
127
	'filter',
128
	'Filter',
129
	'text',
130
	$host
131
))->setHelp('Use a regular expression to filter IP address or hostnames.');
132

    
133
$form->add($section);
134

    
135
$form->addGlobal(new Form_Button(
136
	'Submit',
137
	'Update',
138
	null,
139
	'fa-refresh'
140
))->addClass('btn-primary');
141

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

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

    
165
	for (var i = 0; i < responseTextArr.length; i++) {
166

    
167
		if (responseTextArr[i] == "") {
168
			continue;
169
		}
170

    
171
		if (i == 0) {
172
			var tmp = '';
173
		} else {
174
			var tmp = '<tr>';
175
		}
176

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

    
191
		if (i == 0) {
192
			thead += tmp;
193
		} else {
194
			tmp += '<td><\/td>'
195
			tbody += tmp;
196
		}
197
	}
198

    
199
	$('#' + section + ' > thead').html(thead);
200
	$('#' + section + ' > tbody').html(tbody);
201
}
202

    
203
function update_all_routes() {
204
	update_routes("IPv4");
205
	update_routes("IPv6");
206
}
207

    
208
events.push(function() {
209
	setInterval('update_all_routes()', 5000);
210
	update_all_routes();
211

    
212
	$(document.forms[0]).on('submit', function(e) {
213
		update_all_routes();
214

    
215
		e.preventDefault();
216
	});
217
});
218
//]]>
219
</script>
220

    
221
<div class="panel panel-default">
222
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv4 Routes")?></h2></div>
223
	<div class="panel panel-body">
224
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv4">
225
		<thead>
226
			<tr>
227
				<th><!-- filled by xhr --></th>
228
			</tr>
229
		</thead>
230
		<tbody>
231
			<tr>
232
				<td><?=gettext("Gathering data, please wait...")?></td>
233
			</tr>
234
		</tbody>
235
		</table>
236
	</div>
237
</div>
238

    
239
<div class="panel panel-default">
240
	<div class="panel-heading"><h2 class="panel-title"><?=gettext("IPv6 Routes")?></h2></div>
241
	<div class="panel panel-body">
242
		<table class="table table-striped table-hover table-condensed sortable-theme-bootstrap" id="IPv6">
243
		<thead>
244
			<tr>
245
				<th><!-- filled by xhr --></th>
246
			</tr>
247
		</thead>
248
		<tbody>
249
			<tr>
250
				<td><?=gettext("Gathering data, please wait...")?></td>
251
			</tr>
252
		</tbody>
253
		</table>
254
	</div>
255
</div>
256

    
257
<?php include("foot.inc");
(25-25/225)