Project

General

Profile

Download (6.45 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2

    
3
/* $Id$ */
4
/*
5
	diag_routes.php
6
*/
7
/* ====================================================================
8
 *  Copyright (c)  2004-2015  Electric Sheep Fencing, LLC. All rights reserved. 
9
 *  Copyright (c)  2006 Fernando Lamos
10
 *
11
 *  Redistribution and use in source and binary forms, with or without modification, 
12
 *  are permitted provided that the following conditions are met: 
13
 *
14
 *  1. Redistributions of source code must retain the above copyright notice,
15
 *      this list of conditions and the following disclaimer.
16
 *
17
 *  2. Redistributions in binary form must reproduce the above copyright
18
 *      notice, this list of conditions and the following disclaimer in
19
 *      the documentation and/or other materials provided with the
20
 *      distribution. 
21
 *
22
 *  3. All advertising materials mentioning features or use of this software 
23
 *      must display the following acknowledgment:
24
 *      "This product includes software developed by the pfSense Project
25
 *       for use in the pfSense software distribution. (http://www.pfsense.org/). 
26
 *
27
 *  4. The names "pfSense" and "pfSense Project" must not be used to
28
 *       endorse or promote products derived from this software without
29
 *       prior written permission. For written permission, please contact
30
 *       coreteam@pfsense.org.
31
 *
32
 *  5. Products derived from this software may not be called "pfSense"
33
 *      nor may "pfSense" appear in their names without prior written
34
 *      permission of the Electric Sheep Fencing, LLC.
35
 *
36
 *  6. Redistributions of any form whatsoever must retain the following
37
 *      acknowledgment:
38
 *
39
 *  "This product includes software developed by the pfSense Project
40
 *  for use in the pfSense software distribution (http://www.pfsense.org/).
41
  *
42
 *  THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
43
 *  EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
44
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
45
 *  PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
46
 *  ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
47
 *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
48
 *  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
49
 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
50
 *  HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
51
 *  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
52
 *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
53
 *  OF THE POSSIBILITY OF SUCH DAMAGE.
54
 *
55
 *  ====================================================================
56
 *
57
 */
58
/*
59
	pfSense_BUILDER_BINARIES:	/usr/bin/netstat
60
	pfSense_MODULE:	routing
61
*/
62
##|+PRIV
63
##|*IDENT=page-diagnostics-routingtables
64
##|*NAME=Diagnostics: Routing tables page
65
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
66
##|*MATCH=diag_routes.php*
67
##|-PRIV
68

    
69
include('guiconfig.inc');
70

    
71
$limit = '100';
72
$filter = '';
73

    
74
if (isset($_REQUEST['isAjax'])) {
75
	$netstat = "/usr/bin/netstat -rW";
76
	if (isset($_REQUEST['IPv6'])) {
77
		$netstat .= " -f inet6";
78
		echo "IPv6\n";
79
	} else {
80
		$netstat .= " -f inet";
81
		echo "IPv4\n";
82

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

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

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

    
98
	echo htmlspecialchars_decode(shell_exec($netstat));
99

    
100
	exit;
101
}
102

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

    
106
include('head.inc');
107

    
108
require_once('classes/Form.class.php');
109

    
110
$form = new Form('Update');
111
$form->addGlobal(new Form_Input(
112
	'isAjax',
113
	null,
114
	'hidden',
115
	1
116
));
117
$section = new Form_Section('Traceroute');
118

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

    
127
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
128
$section->addInput(new Form_Select(
129
	'limit',
130
	'Rows to display',
131
	$limit,
132
	array_combine($validLimits, $validLimits)
133
));
134

    
135
$section->addInput(new Form_Input(
136
	'filter',
137
	'Filter',
138
	'text',
139
	$host
140
))->setHelp('Use a regular expression to filter IP address or hostnames');
141

    
142
$form->add($section);
143
print $form;
144
?>
145
<script>
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
		if (responseTextArr[i] == "")
167
			continue;
168
		var tmp = '<tr>';
169
		var j = 0;
170
		var entry = responseTextArr[i].split(" ");
171
		for (var k = 0; k < entry.length; k++) {
172
			if (entry[k] == "")
173
				continue;
174
			if (i == 0)
175
				tmp += '<th>' + entry[k] + '<\/th>';
176
			else
177
				tmp += '<td>' + entry[k] + '<\/td>';
178
			j++;
179
		}
180

    
181
		tmp += '<td><\/td>';
182

    
183
		if (i == 0)
184
			thead += tmp;
185
		else
186
			tbody += tmp;
187
	}
188

    
189
	$('#' + section + ' > thead').html(thead);
190
	$('#' + section + ' > tbody').html(tbody);
191
}
192

    
193
function update_all_routes() {
194
	update_routes("IPv4");
195
	update_routes("IPv6");
196
}
197

    
198
events.push(function(){
199
	setInterval('update_all_routes()', 5000);
200
	update_all_routes();
201

    
202
	$(document.forms[0]).on('submit', function(e){
203
		update_all_routes();
204

    
205
		e.preventDefault();
206
	});
207
});
208
</script>
209

    
210
<div class="panel panel-default">
211
	<div class="panel-heading"><h2 class="panel-title">IPv4 Routes</h2></div>
212
	<div class="panel panel-body">
213
		<table class="table table-striped table-compact" id="IPv4">
214
		<thead>
215
			<!-- filled by xhr -->
216
		</thead>
217
		<tbody>
218
			<tr>
219
				<td><?=gettext("Gathering data, please wait...")?></td>
220
			</tr>
221
		</tbody>
222
		</table>
223
	</div>
224
</div>
225

    
226
<div class="panel panel-default">
227
	<div class="panel-heading"><h2 class="panel-title">IPv6 Routes</h2></div>
228
	<div class="panel panel-body">
229
		<table class="table table-striped table-compact" id="IPv6">
230
		<thead>
231
			<!-- filled by xhr -->
232
		</thead>
233
		<tbody>
234
			<tr>
235
				<td><?=gettext("Gathering data, please wait...")?></td>
236
			</tr>
237
		</tbody>
238
		</table>
239
	</div>
240
</div>
241

    
242
<?php include("foot.inc");
(35-35/235)