Project

General

Profile

Download (3 KB) Statistics
| Branch: | Tag: | Revision:
1 f0a3b883 Scott Ullrich
<?php
2
/* 
3
 * To change this template, choose Tools | Templates
4
 * and open the template in the editor.
5
 *
6
 */
7
8 13d193c2 Scott Ullrich
/*
9
	pfSense_BUILDER_BINARIES:	/usr/local/bin/rate
10
	pfSense_MODULE:	trafficgraph
11
*/
12
13 f0a3b883 Scott Ullrich
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 b1b930dd Ermal
$real_interface = get_real_interface($interface);
23
if (!does_interface_exist($real_interface)) {
24
	echo gettext("Wrong Interface");
25
	return;
26
}
27 f0a3b883 Scott Ullrich
$intip = find_interface_ip($real_interface);
28 1fea5ad9 Renato Botelho
//get interface subnet
29 893fb622 Michele Di Maria
$netmask = find_interface_subnet($real_interface);
30 b1b930dd Ermal
$intsubnet = gen_subnet($intip, $netmask) . "/$netmask";
31 893fb622 Michele Di Maria
//get the sort method
32
$sort = $_GET['sort'];
33
if ($sort == "out") 
34
	{$sort_method = "-T";}
35
else
36
	{$sort_method = "-R";}
37 1fea5ad9 Renato Botelho
38 a02ce260 Phil Davis
$filter = $_GET['filter'];
39
40 c16f7c5c Phil Davis
// 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 2dbd8924 Phil Davis
if (($hostipformat != "") && (!isset($config['dnsmasq']['regdhcpstatic']))) {
46 c16f7c5c Phil Davis
	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 ae88de13 Ermal
$_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 f0a3b883 Scott Ullrich
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 6745e860 Ermal Lu?i
        $infoarray = explode (":",$bandwidthinfo);
70 a02ce260 Phil Davis
		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 c16f7c5c Phil Davis
			} else {
76 a02ce260 Phil Davis
				// $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 232d38ab Phil Davis
				}
89 c16f7c5c Phil Davis
			}
90 a02ce260 Phil Davis
			//print host information;
91
			echo $addrdata . ";" . $infoarray[1] . ";" . $infoarray[2] . "|";
92 f0a3b883 Scott Ullrich
93 a02ce260 Phil Davis
			//mark that we collected information
94
			$someinfo = true;
95
		}
96 f0a3b883 Scott Ullrich
    }
97
}
98 ae88de13 Ermal
unset($bandwidthinfo, $_grb);
99
unset($listedIPs);
100 f0a3b883 Scott Ullrich
101
//no bandwidth usage found
102
if ($someinfo == false)
103 a1129192 Carlos Eduardo Ramos
    echo gettext("no info");
104 f0a3b883 Scott Ullrich
105
?>