Project

General

Profile

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

    
3
/* $Id$ */
4
/*
5
	diag_routes.php
6
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
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 the
18
	documentation and/or other materials provided with the distribution.
19

    
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30

    
31
*/
32

    
33
/*
34
	pfSense_BUILDER_BINARIES:	/usr/bin/netstat
35
	pfSense_MODULE:	routing
36
*/
37
##|+PRIV
38
##|*IDENT=page-diagnostics-routingtables
39
##|*NAME=Diagnostics: Routing tables page
40
##|*DESCR=Allow access to the 'Diagnostics: Routing tables' page.
41
##|*MATCH=diag_routes.php*
42
##|-PRIV
43

    
44
include('guiconfig.inc');
45

    
46
$limit='100';
47
$filter='';
48

    
49
if (isset($_REQUEST['isAjax'])) {
50
	$netstat = "/usr/bin/netstat -rW";
51
	if (isset($_REQUEST['IPv6'])) {
52
		$netstat .= " -f inet6";
53
		echo "IPv6\n";
54
	} else {
55
		$netstat .= " -f inet";
56
		echo "IPv4\n";
57

    
58
	}
59
	if (!isset($_REQUEST['resolve']))
60
		$netstat .= " -n";
61

    
62
	if (!empty($_REQUEST['filter']))
63
		$netstat .= " | /usr/bin/sed -e '1,3d; 5,\$ { /" . escapeshellarg(htmlspecialchars($_REQUEST['filter'])) . "/!d; };'";
64
	else
65
		$netstat .= " | /usr/bin/sed -e '1,3d'";
66

    
67
	if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0)
68
		$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
69

    
70
	echo htmlspecialchars_decode(shell_exec($netstat));
71

    
72
	exit;
73
}
74

    
75
$pgtitle = array(gettext("Diagnostics"),gettext("Routing tables"));
76
$shortcut_section = "routing";
77

    
78
include('head.inc');
79

    
80
require('classes/Form.class.php');
81

    
82
$form = new Form(new Form_Button(
83
	'update',
84
	'Update'
85
));
86
$form->addGlobal(new Form_Input(
87
	'isAjax',
88
	null,
89
	'hidden',
90
	1
91
));
92
$section = new Form_Section('Traceroute');
93

    
94
$section->addInput(new Form_Checkbox(
95
	'resolve',
96
	'Resolve names',
97
	'Enable',
98
	$resolve
99
))->setHelp('Enabling name resolution may cause the query should take longer.'.
100
	' You can stop it at any time by clicking the Stop button in your browser.');
101

    
102
$validLimits = array('10', '50', '100', '200', '500', '1000', 'all');
103
$section->addInput(new Form_Select(
104
	'limit',
105
	'Rows to display',
106
	$limit,
107
	array_combine($validLimits, $validLimits)
108
));
109

    
110
$section->addInput(new Form_Input(
111
	'filter',
112
	'Filter',
113
	'text',
114
	$host
115
))->setHelp('Use a regular expression to filter IP address or hostnames');
116

    
117
$form->add($section);
118
print $form;
119
?>
120
<script>
121
function update_routes(section) {
122
	$.ajax(
123
		'/diag_routes.php',
124
		{
125
			type: 'post',
126
			data: $(document.forms[0]).serialize() +'&'+ section +'=true',
127
			success: update_routes_callback,
128
	});
129
}
130

    
131
function update_routes_callback(html) {
132
	// First line contains section
133
	var responseTextArr = html.split("\n");
134
	var section = responseTextArr.shift();
135
	var tbody = '';
136
	var field = '';
137
	var tr_class = '';
138
	var thead = '<tr>';
139

    
140
	for (var i = 0; i < responseTextArr.length; i++) {
141
		if (responseTextArr[i] == "")
142
			continue;
143
		var tmp = '<tr>';
144
		var j = 0;
145
		var entry = responseTextArr[i].split(" ");
146
		for (var k = 0; k < entry.length; k++) {
147
			if (entry[k] == "")
148
				continue;
149
			if (i == 0)
150
				tmp += '<th>' + entry[k] + '<\/th>';
151
			else
152
				tmp += '<td>' + entry[k] + '<\/td>';
153
			j++;
154
		}
155

    
156
		tmp += '<td><\/td>';
157

    
158
		if (i == 0)
159
			thead += tmp;
160
		else
161
			tbody += tmp;
162
	}
163

    
164
	$('#' + section + ' > thead').html(thead);
165
	$('#' + section + ' > tbody').html(tbody);
166
}
167

    
168
function update_all_routes() {
169
	update_routes("IPv4");
170
	update_routes("IPv6");
171
}
172

    
173
events.push(function(){
174
	setInterval('update_all_routes()', 5000);
175
	update_all_routes();
176

    
177
	$(document.forms[0]).on('submit', function(e){
178
		update_all_routes();
179

    
180
		e.preventDefault();
181
	});
182
});
183
</script>
184

    
185
<div class="panel panel-default">
186
	<div class="panel-heading">IPv4 Routes</div>
187
	<div class="panel panel-body">
188
		<table class="table table-striped table-compact" id="IPv4">
189
		<thead>
190
			<!-- filled by xhr -->
191
		</thead>
192
		<tbody>
193
			<tr>
194
				<td><?=gettext("Gathering data, please wait...")?></td>
195
			</tr>
196
		</tbody>
197
		</table>
198
	</div>
199
</div>
200

    
201
<div class="panel panel-default">
202
	<div class="panel-heading">IPv6 Routes</div>
203
	<div class="panel panel-body">
204
		<table class="table table-striped table-compact" id="IPv6">
205
		<thead>
206
			<!-- filled by xhr -->
207
		</thead>
208
		<tbody>
209
			<tr>
210
				<td><?=gettext("Gathering data, please wait...")?></td>
211
			</tr>
212
		</tbody>
213
		</table>
214
	</div>
215
</div>
216

    
217
<?php include("foot.inc");
(34-34/241)