Project

General

Profile

Download (6.71 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
##|+PRIV
57
##|*IDENT=page-diagnostics-routingtables
58
##|*NAME=Diagnostics: Routing tables
59
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
60
##|*MATCH=diag_routes.php*
61
##|-PRIV
62

    
63
include('guiconfig.inc');
64

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

    
68
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

    
77
	}
78
	if (!isset($_REQUEST['resolve'])) {
79
		$netstat .= " -n";
80
	}
81

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

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

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

    
94
	exit;
95
}
96

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

    
100
include('head.inc');
101

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

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

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

    
143
print $form;
144
?>
145
<script type="text/javascript">
146
//<![CDATA[
147
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

    
157
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

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

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

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

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

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

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

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

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

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

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

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

    
258
<?php include("foot.inc");
(26-26/225)