Project

General

Profile

Download (7.1 KB) Statistics
| Branch: | Tag: | Revision:
1 0eacb3b2 Scott Ullrich
<?php
2
3
/* $Id$ */
4
/*
5
	diag_routes.php
6 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7 0eacb3b2 Scott Ullrich
	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 13d193c2 Scott Ullrich
/*
34 5f601060 Phil Davis
	pfSense_BUILDER_BINARIES:	/usr/bin/netstat
35 13d193c2 Scott Ullrich
	pfSense_MODULE:	routing
36
*/
37 6b07c15a Matthew Grooms
##|+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 0eacb3b2 Scott Ullrich
include('guiconfig.inc');
45
46 92e8cb11 Renato Botelho
if (isset($_REQUEST['isAjax'])) {
47
	$netstat = "/usr/bin/netstat -rW";
48
	if (isset($_REQUEST['IPv6'])) {
49
		$netstat .= " -f inet6";
50
		echo "IPv6\n";
51
	} else {
52
		$netstat .= " -f inet";
53
		echo "IPv4\n";
54
	}
55 5f601060 Phil Davis
	if (!isset($_REQUEST['resolve'])) {
56 92e8cb11 Renato Botelho
		$netstat .= " -n";
57 5f601060 Phil Davis
	}
58 92e8cb11 Renato Botelho
59 5f601060 Phil Davis
	if (!empty($_REQUEST['filter'])) {
60 92e8cb11 Renato Botelho
		$netstat .= " | /usr/bin/sed -e '1,3d; 5,\$ { /" . escapeshellarg(htmlspecialchars($_REQUEST['filter'])) . "/!d; };'";
61 5f601060 Phil Davis
	} else {
62 92e8cb11 Renato Botelho
		$netstat .= " | /usr/bin/sed -e '1,3d'";
63 5f601060 Phil Davis
	}
64 92e8cb11 Renato Botelho
65 5f601060 Phil Davis
	if (is_numeric($_REQUEST['limit']) && $_REQUEST['limit'] > 0) {
66 92e8cb11 Renato Botelho
		$netstat .= " | /usr/bin/head -n {$_REQUEST['limit']}";
67 5f601060 Phil Davis
	}
68 92e8cb11 Renato Botelho
69
	echo htmlspecialchars_decode(shell_exec($netstat));
70
71
	exit;
72
}
73
74 699737d9 Phil Davis
$pgtitle = array(gettext("Diagnostics"), gettext("Routing tables"));
75 b32dd0a6 jim-p
$shortcut_section = "routing";
76 0eacb3b2 Scott Ullrich
77
include('head.inc');
78
79
?>
80 f6510207 xbipin
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
81 92e8cb11 Renato Botelho
82 92e8dc9d Colin Fleming
<?php include("fbegin.inc"); ?>
83
84 92e8cb11 Renato Botelho
<script type="text/javascript">
85
//<![CDATA[
86
87
	function update_routes(section) {
88
		var url = "diag_routes.php";
89
		var limit = jQuery('#limit option:selected').text();
90
		var filter = jQuery('#filter').val();
91
		var params = "isAjax=true&limit=" + limit + "&filter=" + filter;
92 5f601060 Phil Davis
		if (jQuery('#resolve').is(':checked')) {
93 92e8cb11 Renato Botelho
			params += "&resolve=true";
94 5f601060 Phil Davis
		}
95
		if (section == "IPv6") {
96 92e8cb11 Renato Botelho
			params += "&IPv6=true";
97 5f601060 Phil Davis
		}
98 92e8cb11 Renato Botelho
		var myAjax = new Ajax.Request(
99
			url,
100
			{
101
				method: 'post',
102
				parameters: params,
103
				onComplete: update_routes_callback
104
			});
105
	}
106
107
	function update_routes_callback(transport) {
108
		// First line contains section
109
		var responseTextArr = transport.responseText.split("\n");
110
		var section = responseTextArr.shift();
111
		var tbody = '';
112
		var field = '';
113
		var elements = 8;
114
		var tr_class = '';
115
116 92e8dc9d Colin Fleming
		var thead = '<tr><td class="listtopic" colspan="' + elements + '"><strong>' + section + '<\/strong><\/td><\/tr>' + "\n";
117 92e8cb11 Renato Botelho
		for (var i = 0; i < responseTextArr.length; i++) {
118 5f601060 Phil Davis
			if (responseTextArr[i] == "") {
119 92e8cb11 Renato Botelho
				continue;
120 5f601060 Phil Davis
			}
121 92e8cb11 Renato Botelho
			var tmp = '';
122
			if (i == 0) {
123
				tr_class = 'listhdrr';
124
				tmp += '<tr class="sortableHeaderRowIdentifier">' + "\n";
125
			} else {
126
				tr_class = 'listlr';
127
				tmp += '<tr>' + "\n";
128
			}
129
			var j = 0;
130
			var entry = responseTextArr[i].split(" ");
131
			for (var k = 0; k < entry.length; k++) {
132 5f601060 Phil Davis
				if (entry[k] == "") {
133 92e8cb11 Renato Botelho
					continue;
134 5f601060 Phil Davis
				}
135
				if (i == 0 && j == (elements - 1)) {
136 92e8cb11 Renato Botelho
					tr_class = 'listhdr';
137 5f601060 Phil Davis
				}
138 92e8dc9d Colin Fleming
				tmp += '<td class="' + tr_class + '">' + entry[k] + '<\/td>' + "\n";
139 5f601060 Phil Davis
				if (i > 0) {
140 92e8cb11 Renato Botelho
					tr_class = 'listr';
141 5f601060 Phil Davis
				}
142 92e8cb11 Renato Botelho
				j++;
143
			}
144
			// The 'Expire' field might be blank
145 5f601060 Phil Davis
			if (j == (elements - 1)) {
146 92e8dc9d Colin Fleming
				tmp += '<td class="listr">&nbsp;<\/td>' + "\n";
147 5f601060 Phil Davis
			}
148 92e8dc9d Colin Fleming
			tmp += '<\/tr>' + "\n";
149 5f601060 Phil Davis
			if (i == 0) {
150 92e8cb11 Renato Botelho
				thead += tmp;
151 5f601060 Phil Davis
			} else {
152 92e8cb11 Renato Botelho
				tbody += tmp;
153 5f601060 Phil Davis
			}
154 92e8cb11 Renato Botelho
		}
155
		jQuery('#' + section + ' > thead').html(thead);
156
		jQuery('#' + section + ' > tbody').html(tbody);
157
	}
158
159
//]]>
160
</script>
161
162
<script type="text/javascript">
163
//<![CDATA[
164
165
	function update_all_routes() {
166
		update_routes("IPv4");
167
		update_routes("IPv6");
168
	}
169
170 5f601060 Phil Davis
	jQuery(document).ready(function() {setTimeout('update_all_routes()', 5000);});
171 92e8cb11 Renato Botelho
172
//]]>
173
</script>
174
175 0eacb3b2 Scott Ullrich
<div id="mainarea">
176
<form action="diag_routes.php" method="post">
177 92e8dc9d Colin Fleming
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="6" summary="diag routes">
178 5f601060 Phil Davis
	<tr>
179
		<td class="vncellreq" width="22%"><?=gettext("Name resolution");?></td>
180
		<td class="vtable" width="78%">
181
			<input type="checkbox" class="formfld" id="resolve" name="resolve" value="yes" <?php if ($_POST['resolve'] == 'yes') echo "checked=\"checked\""; ?> /><?=gettext("Enable");?>
182
			<br />
183
			<span class="expl"><?=gettext("Enable this to attempt to resolve names when displaying the tables.");?></span>
184
		</td>
185
	</tr>
186
187
	<tr>
188
		<td class="vncellreq" width="22%"><?=gettext("Number of rows");?></td>
189
		<td class="vtable" width="78%">
190
			<select id="limit" name="limit">
191 92e8cb11 Renato Botelho
<?php
192
	foreach (array("10", "50", "100", "200", "500", "1000", gettext("all")) as $item) {
193 92e8dc9d Colin Fleming
		echo "<option value=\"{$item}\" " . ($item == "100" ? "selected=\"selected\"" : "") . ">{$item}</option>\n";
194 92e8cb11 Renato Botelho
	}
195
?>
196 5f601060 Phil Davis
			</select>
197
			<br />
198
			<span class="expl"><?=gettext("Select how many rows to display.");?></span>
199
		</td>
200
	</tr>
201
202
	<tr>
203
		<td class="vncellreq" width="22%"><?=gettext("Filter expression");?></td>
204
		<td class="vtable" width="78%">
205
			<input type="text" class="formfld search" name="filter" id="filter" />
206
			<br />
207
			<span class="expl"><?=gettext("Use a regular expression to filter IP address or hostnames.");?></span>
208
		</td>
209
	</tr>
210
211
	<tr>
212
		<td class="vncellreq" width="22%">&nbsp;</td>
213
		<td class="vtable" width="78%">
214
			<input type="button" class="formbtn" name="update" onclick="update_all_routes();" value="<?=gettext("Update"); ?>" />
215
			<br />
216
			<br />
217
			<span class="vexpl"><span class="red"><strong><?=gettext("Note:")?></strong></span> <?=gettext("By enabling name resolution, the query should take a bit longer. You can stop it at any time by clicking the Stop button in your browser.");?></span>
218
		</td>
219
	</tr>
220 0eacb3b2 Scott Ullrich
</table>
221
</form>
222
223 92e8dc9d Colin Fleming
<table class="tabcont sortable" width="100%" cellspacing="0" cellpadding="6" border="0" id="IPv4" summary="ipv4 routes">
224 92e8cb11 Renato Botelho
	<thead>
225
		<tr><td class="listtopic"><strong>IPv4</strong></td></tr>
226
	</thead>
227
	<tbody>
228
		<tr><td class="listhdrr"><?=gettext("Gathering data, please wait...");?></td></tr>
229
	</tbody>
230
</table>
231 92e8dc9d Colin Fleming
<table class="tabcont sortable" width="100%" cellspacing="0" cellpadding="6" border="0" id="IPv6" summary="ipv6 routes">
232 92e8cb11 Renato Botelho
	<thead>
233
		<tr><td class="listtopic"><strong>IPv6</strong></td></tr>
234
	</thead>
235
	<tbody>
236
		<tr><td class="listhdrr"><?=gettext("Gathering data, please wait...");?></td></tr>
237
	</tbody>
238 0eacb3b2 Scott Ullrich
</table>
239
240
</div>
241
242
<?php
243
include('fend.inc');
244
?>
245 92e8dc9d Colin Fleming
246
</body>
247
</html>