Project

General

Profile

« Previous | Next » 

Revision 92e8cb11

Added by Renato Botelho almost 12 years ago

Improvements on Diagnostics -> Routes

  • Add filter expression
  • Add limit number of rows option (default 100)
  • Run one netstat for each section
  • Load netstat result using ajax after page is loaded

View differences:

usr/local/www/diag_routes.php
42 42

  
43 43
include('guiconfig.inc');
44 44

  
45
if (isset($_REQUEST['isAjax'])) {
46
	$netstat = "/usr/bin/netstat -rW";
47
	if (isset($_REQUEST['IPv6'])) {
48
		$netstat .= " -f inet6";
49
		echo "IPv6\n";
50
	} else {
51
		$netstat .= " -f inet";
52
		echo "IPv4\n";
53
	}
54
	$netstat .= (isset($_REQUEST['IPv6']) ? " -f inet6" : " -f inet");
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

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

  
......
49 75

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

  
79
<script type="text/javascript">
80
//<![CDATA[
81

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

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

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

  
146
//]]>
147
</script>
148

  
52 149
<?php include("fbegin.inc"); ?>
53 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

  
54 164
<div id="mainarea">
55 165
<form action="diag_routes.php" method="post">
56 166
<table class="tabcont" width="100%" border="0" cellspacing="0" cellpadding="6">
......
58 168
<tr>
59 169
<td class="vncellreq" width="22%"><?=gettext("Name resolution");?></td>
60 170
<td class="vtable" width="78%">
61
<input type="checkbox" class="formfld" name="resolve" value="yes" <?php if ($_POST['resolve'] == 'yes') echo 'checked'; ?>><?=gettext("Enable");?></input>
171
<input type="checkbox" class="formfld" id="resolve" name="resolve" value="yes" <?php if ($_POST['resolve'] == 'yes') echo 'checked'; ?>><?=gettext("Enable");?></input>
62 172
<br />
63 173
<span class="expl"><?=gettext("Enable this to attempt to resolve names when displaying the tables.");?></span>
64 174
</td>
65 175
</tr>
66 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" : "") . ">{$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

  
67 201
<tr>
68 202
<td class="vncellreq" width="22%">&nbsp;</td>
69 203
<td class="vtable" width="78%">
70
<input type="submit" class="formbtn" name="submit" value="<?=gettext("Show"); ?>" />
204
<input type="button" class="formbtn" name="update" onclick="update_all_routes();" value="<?=gettext("Update"); ?>" />
71 205
<br />
72 206
<br />
73 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>
......
77 211
</table>
78 212
</form>
79 213

  
80
<?php
81

  
82
	$netstat = ($_POST['resolve'] == 'yes' ? 'netstat -rW' : 'netstat -nrW');
83
	list($dummy, $internet, $internet6) = explode("\n\n", shell_exec($netstat));
84

  
85
	foreach (array(&$internet, &$internet6) as $tabindex => $table) {
86
		$elements = ($tabindex == 0 ? 8 : 8);
87
		$name = ($tabindex == 0 ? 'IPv4' : 'IPv6');
88
?>
89
<table class="tabcont sortable" width="100%" cellspacing="0" cellpadding="6" border="0">
90
<thead>
91
<tr><td class="listtopic" colspan="<?=$elements?>"><strong><?=$name;?></strong></font></td></tr>
92
<?php
93
		foreach (explode("\n", $table) as $i => $line) {
94
			if ($i == 0) continue;
95
			if ($line == "") continue;
96

  
97
			if ($i == 1)
98
				$class = 'listhdrr';
99
			else
100
				$class = 'listlr';
101

  
102
			if ($i == 1)
103
				print("<tr class=\"sortableHeaderRowIdentifier\">\n");
104
			else
105
				print("<tr>\n");
106
				
107
			$j = 0;
108
			foreach (explode(' ', $line) as $entry) {
109
				if ($entry == '') continue;
110
				if ($i == 1 && $j == $elements - 1)
111
					$class = 'listhdr';
112
				print("<td class=\"$class\">$entry</td>\n");
113
				if ($i > 1)
114
					$class = 'listr';
115
				$j++;
116
			}
117
			// The 'Expire' field might be blank
118
			if ($j == $elements - 1)
119
				print('<td class="listr">&nbsp;</td>' . "\n");
120
			print("</tr>\n");
121
			if ($i == 1)
122
				print("</thead>\n");
123
		}
124
		print("</table>\n");
125
	} 
126

  
127
?>
214
<table class="tabcont sortable" width="100%" cellspacing="0" cellpadding="6" border="0" id="IPv4">
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">
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>
128 229
</table>
129 230

  
130 231
</div>

Also available in: Unified diff