Project

General

Profile

« Previous | Next » 

Revision 893fb622

Added by Michele Di Maria over 12 years ago

Adds "Sort by direction" in the Traffic Graph page

Added the option to sort IPs by direction in the Traffic Graph page, and
improved the detection of the local network to monitor (before the
results could not be realistic because of too many "local IPs" were
monitored.

View differences:

usr/local/www/bandwidth_by_ip.php
22 22
$real_interface = convert_friendly_interface_to_real_interface_name($interface);
23 23
$intip = find_interface_ip($real_interface);
24 24
$intip = explode (".", $intip);
25

  
26
//use class A subnet to make sure we capture all traffic on specified interface
27
$intsubnet = $intip[0] . ".0.0.0/8";
28

  
29
exec("/usr/local/bin/rate -i {$real_interface} -nlq 1 -Aba 20 -c {$intsubnet} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1,  $2,  $4,  $6,  $8 }'", $listedIPs);
30

  
25
//get interface netmask
26
$netmask = find_interface_subnet($real_interface);
27
//get the sort method
28
$sort = $_GET['sort'];
29
if ($sort == "out") 
30
	{$sort_method = "-T";}
31
else
32
	{$sort_method = "-R";}
33
//use the same class of the specified interface
34
if ($netmask >= 24) {
35
	$intsubnet = $intip[0] . "." . $intip[1] . "." . $intip[2] . ".0/24";
36
}
37
elseif ($netmask >=16){
38
	$intsubnet = $intip[0] . "." . $intip[1] . ".0.0/16";
39
}
40
else {
41
	$intsubnet = $intip[0] . ".0.0.0/8";
42
}
43
exec("/usr/local/bin/rate -i {$real_interface} -nlq 1 -Aba 20 {$sort_method} -c {$intsubnet} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1,  $2,  $4,  $6,  $8 }'", $listedIPs);
31 44
unset($bandwidthinfo);
32 45
unset($receivebytesarray);
33 46
unset($transmitbytesarray);
usr/local/www/status_graph.php
81 81
} else {
82 82
	$curif = "wan";
83 83
}
84
if ($_GET['sort']) {
85
	$cursort = $_GET['sort'];
86
} else {
87
	$cursort = "";
88
}
84 89

  
85 90
$pgtitle = array(gettext("Status"),gettext("Traffic Graph"));
86 91

  
......
94 99

  
95 100
function updateBandwidth(){
96 101
    var hostinterface = "<?php echo htmlspecialchars($curif); ?>";
97
    bandwidthAjax(hostinterface);
102
	var sorting = "<?php echo htmlspecialchars($cursort); ?>";
103
    bandwidthAjax(hostinterface, sorting);
98 104
}
99 105

  
100
function bandwidthAjax(hostinterface) {
101
	uri = "bandwidth_by_ip.php?if=" + hostinterface;
106
function bandwidthAjax(hostinterface, sorting) {
107
	uri = "bandwidth_by_ip.php?if=" + hostinterface + "&sort=" + sorting;
102 108
	var opt = {
103 109
	    // Use GET
104 110
	    type: 'get',
......
184 190
}
185 191
?>
186 192
</select>
193
, Sort by: 
194
<select name="sort" class="formselect" style="z-index: -10;" onchange="document.form1.submit()">
195
	<option value="">Bandwidth In</option>
196
	<option value="out"<?php if ($cursort == "out") echo " selected";?>>Bandwidth Out</option>
197
</select>
187 198
</form>
188 199
<p><form method="post" action="status_graph.php">
189 200
</form>

Also available in: Unified diff