Project

General

Profile

Download (7.1 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
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
	if (!isset($_REQUEST['resolve'])) {
56
		$netstat .= " -n";
57
	}
58

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

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

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

    
71
	exit;
72
}
73

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

    
77
include('head.inc');
78

    
79
?>
80
<body link="#0000CC" vlink="#0000CC" alink="#0000CC">
81

    
82
<?php include("fbegin.inc"); ?>
83

    
84
<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
		if (jQuery('#resolve').is(':checked')) {
93
			params += "&resolve=true";
94
		}
95
		if (section == "IPv6") {
96
			params += "&IPv6=true";
97
		}
98
		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
		var thead = '<tr><td class="listtopic" colspan="' + elements + '"><strong>' + section + '<\/strong><\/td><\/tr>' + "\n";
117
		for (var i = 0; i < responseTextArr.length; i++) {
118
			if (responseTextArr[i] == "") {
119
				continue;
120
			}
121
			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
				if (entry[k] == "") {
133
					continue;
134
				}
135
				if (i == 0 && j == (elements - 1)) {
136
					tr_class = 'listhdr';
137
				}
138
				tmp += '<td class="' + tr_class + '">' + entry[k] + '<\/td>' + "\n";
139
				if (i > 0) {
140
					tr_class = 'listr';
141
				}
142
				j++;
143
			}
144
			// The 'Expire' field might be blank
145
			if (j == (elements - 1)) {
146
				tmp += '<td class="listr">&nbsp;<\/td>' + "\n";
147
			}
148
			tmp += '<\/tr>' + "\n";
149
			if (i == 0) {
150
				thead += tmp;
151
			} else {
152
				tbody += tmp;
153
			}
154
		}
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
	jQuery(document).ready(function() {setTimeout('update_all_routes()', 5000);});
171

    
172
//]]>
173
</script>
174

    
175
<div id="mainarea">
176
<form action="diag_routes.php" method="post">
177
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="6" summary="diag routes">
178
	<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
<?php
192
	foreach (array("10", "50", "100", "200", "500", "1000", gettext("all")) as $item) {
193
		echo "<option value=\"{$item}\" " . ($item == "100" ? "selected=\"selected\"" : "") . ">{$item}</option>\n";
194
	}
195
?>
196
			</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
</table>
221
</form>
222

    
223
<table class="tabcont sortable" width="100%" cellspacing="0" cellpadding="6" border="0" id="IPv4" summary="ipv4 routes">
224
	<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
<table class="tabcont sortable" width="100%" cellspacing="0" cellpadding="6" border="0" id="IPv6" summary="ipv6 routes">
232
	<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
</table>
239

    
240
</div>
241

    
242
<?php
243
include('fend.inc');
244
?>
245

    
246
</body>
247
</html>
(45-45/256)