Project

General

Profile

Download (2.81 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 == "") {
69
			$addrdata = $infoarray[0];
70
		} else {
71
			// $hostipformat is "hostname" or "fqdn"
72
			$addrdata = gethostbyaddr($infoarray[0]);
73
			if ($addrdata == $infoarray[0]) {
74
				// gethostbyaddr() gave us back the IP address, so try the static mapping array
75
				if ($iplookup[$infoarray[0]] != "")
76
					$addrdata = $iplookup[$infoarray[0]];
77
			} else {
78
				if ($hostipformat == "hostname") {
79
					// Only pass back the first part of the name, not the FQDN.
80
					$name_array = explode(".", $addrdata);
81
					$addrdata = $name_array[0];
82
				}
83
			}
84
		}
85
        //print host information;
86
        echo $addrdata . ";" . $infoarray[1] . ";" . $infoarray[2] . "|";
87

    
88
        //mark that we collected information
89
        $someinfo = true;
90
    }
91
}
92
unset($bandwidthinfo, $_grb);
93
unset($listedIPs);
94

    
95
//no bandwidth usage found
96
if ($someinfo == false)
97
    echo gettext("no info");
98

    
99
?>
(2-2/246)