Project

General

Profile

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

    
3
/* $Id$ */
4
/*
5
	diag_routes.php
6
        Copyright (C) 2013-2014 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
	if (!empty($_REQUEST['filter']))
59
		$netstat .= " | /usr/bin/sed -e '1,3d; 5,\$ { /" . escapeshellarg(htmlspecialchars($_REQUEST['filter'])) . "/!d; };'";
60
	else
61
		$netstat .= " | /usr/bin/sed -e '1,3d'";
62

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

    
66
	echo htmlspecialchars_decode(shell_exec($netstat));
67

    
68
	exit;
69
}
70

    
71
$pgtitle = array(gettext("Diagnostics"),gettext("Routing tables"));
72
$shortcut_section = "routing";
73

    
74
include('head.inc');
75

    
76
?>
77
<body link="#000000" vlink="#000000" alink="#000000">
78

    
79
<?php include("fbegin.inc"); ?>
80

    
81
<script type="text/javascript">
82
//<![CDATA[
83

    
84
	function update_routes(section) {
85
		var url = "diag_routes.php";
86
		var limit = jQuery('#limit option:selected').text();
87
		var filter = jQuery('#filter').val();
88
		var params = "isAjax=true&limit=" + limit + "&filter=" + filter;
89
		if (jQuery('#resolve').is(':checked'))
90
			params += "&resolve=true";
91
		if (section == "IPv6")
92
			params += "&IPv6=true";
93
		var myAjax = new Ajax.Request(
94
			url,
95
			{
96
				method: 'post',
97
				parameters: params,
98
				onComplete: update_routes_callback
99
			});
100
	}
101

    
102
	function update_routes_callback(transport) {
103
		// First line contains section
104
		var responseTextArr = transport.responseText.split("\n");
105
		var section = responseTextArr.shift();
106
		var tbody = '';
107
		var field = '';
108
		var elements = 8;
109
		var tr_class = '';
110

    
111
		var thead = '<tr><td class="listtopic" colspan="' + elements + '"><strong>' + section + '<\/strong><\/td><\/tr>' + "\n";
112
		for (var i = 0; i < responseTextArr.length; i++) {
113
			if (responseTextArr[i] == "")
114
				continue;
115
			var tmp = '';
116
			if (i == 0) {
117
				tr_class = 'listhdrr';
118
				tmp += '<tr class="sortableHeaderRowIdentifier">' + "\n";
119
			} else {
120
				tr_class = 'listlr';
121
				tmp += '<tr>' + "\n";
122
			}
123
			var j = 0;
124
			var entry = responseTextArr[i].split(" ");
125
			for (var k = 0; k < entry.length; k++) {
126
				if (entry[k] == "")
127
					continue;
128
				if (i == 0 && j == (elements - 1))
129
					tr_class = 'listhdr';
130
				tmp += '<td class="' + tr_class + '">' + entry[k] + '<\/td>' + "\n";
131
				if (i > 0)
132
					tr_class = 'listr';
133
				j++;
134
			}
135
			// The 'Expire' field might be blank
136
			if (j == (elements - 1))
137
				tmp += '<td class="listr">&nbsp;<\/td>' + "\n";
138
			tmp += '<\/tr>' + "\n";
139
			if (i == 0)
140
				thead += tmp;
141
			else
142
				tbody += tmp;
143
		}
144
		jQuery('#' + section + ' > thead').html(thead);
145
		jQuery('#' + section + ' > tbody').html(tbody);
146
	}
147

    
148
//]]>
149
</script>
150

    
151
<script type="text/javascript">
152
//<![CDATA[
153

    
154
	function update_all_routes() {
155
		update_routes("IPv4");
156
		update_routes("IPv6");
157
	}
158

    
159
	jQuery(document).ready(function(){setTimeout('update_all_routes()', 5000);});
160

    
161
//]]>
162
</script>
163

    
164
<div id="mainarea">
165
<form action="diag_routes.php" method="post">
166
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="6" summary="diag routes">
167

    
168
<tr>
169
<td class="vncellreq" width="22%"><?=gettext("Name resolution");?></td>
170
<td class="vtable" width="78%">
171
<input type="checkbox" class="formfld" id="resolve" name="resolve" value="yes" <?php if ($_POST['resolve'] == 'yes') echo "checked=\"checked\""; ?> /><?=gettext("Enable");?>
172
<br />
173
<span class="expl"><?=gettext("Enable this to attempt to resolve names when displaying the tables.");?></span>
174
</td>
175
</tr>
176

    
177
<tr>
178
<td class="vncellreq" width="22%"><?=gettext("Number of rows");?></td>
179
<td class="vtable" width="78%">
180
<select id="limit" name="limit">
181
<?php
182
	foreach (array("10", "50", "100", "200", "500", "1000", gettext("all")) as $item) {
183
		echo "<option value=\"{$item}\" " . ($item == "100" ? "selected=\"selected\"" : "") . ">{$item}</option>\n";
184
	}
185
?>
186
</select>
187
<br />
188
<span class="expl"><?=gettext("Select how many rows to display.");?></span>
189
</td>
190
</tr>
191

    
192
<tr>
193
<td class="vncellreq" width="22%"><?=gettext("Filter expression");?></td>
194
<td class="vtable" width="78%">
195
<input type="text" class="formfld search" name="filter" id="filter" />
196
<br />
197
<span class="expl"><?=gettext("Use a regular expression to filter IP address or hostnames.");?></span>
198
</td>
199
</tr>
200

    
201
<tr>
202
<td class="vncellreq" width="22%">&nbsp;</td>
203
<td class="vtable" width="78%">
204
<input type="button" class="formbtn" name="update" onclick="update_all_routes();" value="<?=gettext("Update"); ?>" />
205
<br />
206
<br />
207
<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>
208
</td>
209
</tr>
210

    
211
</table>
212
</form>
213

    
214
<table class="tabcont sortable" width="100%" cellspacing="0" cellpadding="6" border="0" id="IPv4" summary="ipv4 routes">
215
	<thead>
216
		<tr><td class="listtopic"><strong>IPv4</strong></td></tr>
217
	</thead>
218
	<tbody>
219
		<tr><td class="listhdrr"><?=gettext("Gathering data, please wait...");?></td></tr>
220
	</tbody>
221
</table>
222
<table class="tabcont sortable" width="100%" cellspacing="0" cellpadding="6" border="0" id="IPv6" summary="ipv6 routes">
223
	<thead>
224
		<tr><td class="listtopic"><strong>IPv6</strong></td></tr>
225
	</thead>
226
	<tbody>
227
		<tr><td class="listhdrr"><?=gettext("Gathering data, please wait...");?></td></tr>
228
	</tbody>
229
</table>
230

    
231
</div>
232

    
233
<?php
234
include('fend.inc');
235
?>
236

    
237
</body>
238
</html>
(45-45/256)