Project

General

Profile

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

    
57
$_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);
58

    
59
$someinfo = false;
60
for ($x=2; $x<12; $x++){
61

    
62
    $bandwidthinfo = $listedIPs[$x];
63

    
64
   // echo $bandwidthinfo;
65
    $emptyinfocounter = 1;
66
    if ($bandwidthinfo != "") {
67
        $infoarray = explode (":",$bandwidthinfo);
68
		if ($hostipformat == "hostname") {
69
			$addrdata = gethostbyaddr($infoarray[0]);
70
			if ($addrdata == $infoarray[0]) {
71
				// gethostbyaddr() gave us back the IP address, so try the static mapping array
72
				if ($iplookup[$infoarray[0]] != "")
73
					$addrdata = $iplookup[$infoarray[0]];
74
			} else {
75
				// gethostbyaddr() gave an answer. Just pass back the name up to the first "."
76
				$name_array = explode(".", $addrdata);
77
				$addrdata = $name_array[0];
78
			}
79
		} else {
80
			$addrdata = $infoarray[0];
81
		}
82
        //print host information;
83
        echo $addrdata . ";" . $infoarray[1] . ";" . $infoarray[2] . "|";
84

    
85
        //mark that we collected information
86
        $someinfo = true;
87
    }
88
}
89
unset($bandwidthinfo, $_grb);
90
unset($listedIPs);
91

    
92
//no bandwidth usage found
93
if ($someinfo == false)
94
    echo gettext("no info");
95

    
96
?>
(2-2/246)