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 |
5177b583
|
Phil Davis
|
|
28 |
f0a3b883
|
Scott Ullrich
|
$intip = find_interface_ip($real_interface);
|
29 |
1fea5ad9
|
Renato Botelho
|
//get interface subnet
|
30 |
893fb622
|
Michele Di Maria
|
$netmask = find_interface_subnet($real_interface);
|
31 |
b1b930dd
|
Ermal
|
$intsubnet = gen_subnet($intip, $netmask) . "/$netmask";
|
32 |
5177b583
|
Phil Davis
|
|
33 |
737aef33
|
Phil Davis
|
// see if they want local, remote or all IPs returned
|
34 |
5177b583
|
Phil Davis
|
$filter = $_GET['filter'];
|
35 |
|
|
|
36 |
737aef33
|
Phil Davis
|
if ($filter == "")
|
37 |
|
|
$filter = "local";
|
38 |
|
|
|
39 |
5177b583
|
Phil Davis
|
if ($filter == "local") {
|
40 |
|
|
$ratesubnet = "-c " . $intsubnet;
|
41 |
|
|
} else {
|
42 |
|
|
// Tell the rate utility to consider the whole internet (0.0.0.0/0)
|
43 |
|
|
// and to consider local "l" traffic - i.e. traffic within the whole internet
|
44 |
|
|
// then we can filter the resulting output as we wish below.
|
45 |
|
|
$ratesubnet = "-lc 0.0.0.0/0";
|
46 |
|
|
}
|
47 |
|
|
|
48 |
893fb622
|
Michele Di Maria
|
//get the sort method
|
49 |
|
|
$sort = $_GET['sort'];
|
50 |
|
|
if ($sort == "out")
|
51 |
|
|
{$sort_method = "-T";}
|
52 |
|
|
else
|
53 |
|
|
{$sort_method = "-R";}
|
54 |
1fea5ad9
|
Renato Botelho
|
|
55 |
c16f7c5c
|
Phil Davis
|
// get the desired format for displaying the host name or IP
|
56 |
|
|
$hostipformat = $_GET['hostipformat'];
|
57 |
|
|
$iplookup = array();
|
58 |
|
|
// If hostname display is requested and the DNS forwarder does not already have DHCP static names registered,
|
59 |
|
|
// then load the DHCP static mappings into an array keyed by IP address.
|
60 |
37d4cbf3
|
Warren Baker
|
if (($hostipformat != "") && ((!isset($config['dnsmasq']['enable']) || !isset($config['dnsmasq']['regdhcpstatic']))
|
61 |
|
|
|| (!isset($config['unbound']['enable']) || !isset($config['unbound']['regdhcpstatic'])))) {
|
62 |
c16f7c5c
|
Phil Davis
|
if (is_array($config['dhcpd'])) {
|
63 |
|
|
foreach ($config['dhcpd'] as $ifdata) {
|
64 |
|
|
if (is_array($ifdata['staticmap'])) {
|
65 |
|
|
foreach ($ifdata['staticmap'] as $hostent) {
|
66 |
|
|
if (($hostent['ipaddr'] != "") && ($hostent['hostname'] != "")) {
|
67 |
|
|
$iplookup[$hostent['ipaddr']] = $hostent['hostname'];
|
68 |
|
|
}
|
69 |
|
|
}
|
70 |
|
|
}
|
71 |
|
|
}
|
72 |
|
|
}
|
73 |
|
|
}
|
74 |
|
|
|
75 |
5177b583
|
Phil Davis
|
$_grb = exec("/usr/local/bin/rate -i {$real_interface} -nlq 1 -Aba 20 {$sort_method} {$ratesubnet} | tr \"|\" \" \" | awk '{ printf \"%s:%s:%s:%s:%s\\n\", $1, $2, $4, $6, $8 }'", $listedIPs);
|
76 |
f0a3b883
|
Scott Ullrich
|
|
77 |
|
|
$someinfo = false;
|
78 |
|
|
for ($x=2; $x<12; $x++){
|
79 |
|
|
|
80 |
|
|
$bandwidthinfo = $listedIPs[$x];
|
81 |
|
|
|
82 |
|
|
// echo $bandwidthinfo;
|
83 |
|
|
$emptyinfocounter = 1;
|
84 |
|
|
if ($bandwidthinfo != "") {
|
85 |
6745e860
|
Ermal Lu?i
|
$infoarray = explode (":",$bandwidthinfo);
|
86 |
737aef33
|
Phil Davis
|
if (($filter == "all") ||
|
87 |
5177b583
|
Phil Davis
|
(($filter == "local") && (ip_in_subnet($infoarray[0], $intsubnet))) ||
|
88 |
|
|
(($filter == "remote") && (!ip_in_subnet($infoarray[0], $intsubnet)))) {
|
89 |
a02ce260
|
Phil Davis
|
if ($hostipformat == "") {
|
90 |
|
|
$addrdata = $infoarray[0];
|
91 |
c16f7c5c
|
Phil Davis
|
} else {
|
92 |
a02ce260
|
Phil Davis
|
// $hostipformat is "hostname" or "fqdn"
|
93 |
|
|
$addrdata = gethostbyaddr($infoarray[0]);
|
94 |
|
|
if ($addrdata == $infoarray[0]) {
|
95 |
|
|
// gethostbyaddr() gave us back the IP address, so try the static mapping array
|
96 |
|
|
if ($iplookup[$infoarray[0]] != "")
|
97 |
|
|
$addrdata = $iplookup[$infoarray[0]];
|
98 |
|
|
} else {
|
99 |
|
|
if ($hostipformat == "hostname") {
|
100 |
|
|
// Only pass back the first part of the name, not the FQDN.
|
101 |
|
|
$name_array = explode(".", $addrdata);
|
102 |
|
|
$addrdata = $name_array[0];
|
103 |
|
|
}
|
104 |
232d38ab
|
Phil Davis
|
}
|
105 |
c16f7c5c
|
Phil Davis
|
}
|
106 |
a02ce260
|
Phil Davis
|
//print host information;
|
107 |
|
|
echo $addrdata . ";" . $infoarray[1] . ";" . $infoarray[2] . "|";
|
108 |
f0a3b883
|
Scott Ullrich
|
|
109 |
a02ce260
|
Phil Davis
|
//mark that we collected information
|
110 |
|
|
$someinfo = true;
|
111 |
|
|
}
|
112 |
5177b583
|
Phil Davis
|
}
|
113 |
f0a3b883
|
Scott Ullrich
|
}
|
114 |
ae88de13
|
Ermal
|
unset($bandwidthinfo, $_grb);
|
115 |
|
|
unset($listedIPs);
|
116 |
f0a3b883
|
Scott Ullrich
|
|
117 |
|
|
//no bandwidth usage found
|
118 |
|
|
if ($someinfo == false)
|
119 |
a1129192
|
Carlos Eduardo Ramos
|
echo gettext("no info");
|
120 |
f0a3b883
|
Scott Ullrich
|
|
121 |
|
|
?>
|