Project

General

Profile

Download (3.04 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* 
3
 * To change this template, choose Tools | Templates
4
 * and open the template in the editor.
5
 *
6
 */
7

    
8
/*
9
	pfSense_BUILDER_BINARIES:	/usr/local/bin/rate
10
	pfSense_MODULE:	trafficgraph
11
*/
12

    
13
require_once('guiconfig.inc');
14
require_once('interfaces.inc');
15
require_once('pfsense-utils.inc');
16
require_once('util.inc');
17

    
18
$listedIPs = "";
19

    
20
//get interface IP and break up into an array
21
$interface = $_GET['if'];
22
$real_interface = get_real_interface($interface);
23
if (!does_interface_exist($real_interface)) {
24
	echo gettext("Wrong Interface");
25
	return;
26
}
27
$intip = find_interface_ip($real_interface);
28
//get interface subnet
29
$netmask = find_interface_subnet($real_interface);
30
$intsubnet = gen_subnet($intip, $netmask) . "/$netmask";
31
//get the sort method
32
$sort = $_GET['sort'];
33
if ($sort == "out") 
34
	{$sort_method = "-T";}
35
else
36
	{$sort_method = "-R";}
37

    
38
$filter = $_GET['filter'];
39

    
40
// get the desired format for displaying the host name or IP
41
$hostipformat = $_GET['hostipformat'];
42
$iplookup = array();
43
// If hostname display is requested and the DNS forwarder does not already have DHCP static names registered,
44
// then load the DHCP static mappings into an array keyed by IP address.
45
if (($hostipformat != "") && (!isset($config['dnsmasq']['enable']) || !isset($config['dnsmasq']['regdhcpstatic']))) {
46
	if (is_array($config['dhcpd'])) {
47
		foreach ($config['dhcpd'] as $ifdata) {
48
			if (is_array($ifdata['staticmap'])) {
49
				foreach ($ifdata['staticmap'] as $hostent) {
50
					if (($hostent['ipaddr'] != "") && ($hostent['hostname'] != "")) {
51
						$iplookup[$hostent['ipaddr']] = $hostent['hostname'];
52
					}
53
				}
54
			}
55
		}
56
	}
57
}
58

    
59
$_grb = 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);
60

    
61
$someinfo = false;
62
for ($x=2; $x<12; $x++){
63

    
64
    $bandwidthinfo = $listedIPs[$x];
65

    
66
   // echo $bandwidthinfo;
67
    $emptyinfocounter = 1;
68
    if ($bandwidthinfo != "") {
69
        $infoarray = explode (":",$bandwidthinfo);
70
		if (($filter == "") ||
71
			(($filter == "local") && (ip_in_subnet($infoarray[0], $intsubnet))) ||
72
			(($filter == "remote") && (!ip_in_subnet($infoarray[0], $intsubnet)))) {
73
			if ($hostipformat == "") {
74
				$addrdata = $infoarray[0];
75
			} else {
76
				// $hostipformat is "hostname" or "fqdn"
77
				$addrdata = gethostbyaddr($infoarray[0]);
78
				if ($addrdata == $infoarray[0]) {
79
					// gethostbyaddr() gave us back the IP address, so try the static mapping array
80
					if ($iplookup[$infoarray[0]] != "")
81
						$addrdata = $iplookup[$infoarray[0]];
82
				} else {
83
					if ($hostipformat == "hostname") {
84
						// Only pass back the first part of the name, not the FQDN.
85
						$name_array = explode(".", $addrdata);
86
						$addrdata = $name_array[0];
87
					}
88
				}
89
			}
90
			//print host information;
91
			echo $addrdata . ";" . $infoarray[1] . ";" . $infoarray[2] . "|";
92

    
93
			//mark that we collected information
94
			$someinfo = true;
95
		}
96
    }
97
}
98
unset($bandwidthinfo, $_grb);
99
unset($listedIPs);
100

    
101
//no bandwidth usage found
102
if ($someinfo == false)
103
    echo gettext("no info");
104

    
105
?>
(2-2/246)