2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
7 # This program is free software: you can redistribute it and/or modify #
8 # it under the terms of the GNU General Public License as published by #
9 # the Free Software Foundation, either version 3 of the License, or #
10 # (at your option) any later version. #
12 # This program is distributed in the hope that it will be useful, #
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15 # GNU General Public License for more details. #
17 # You should have received a copy of the GNU General Public License #
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. #
20 ###############################################################################
22 ###############################################################################
23 # functions copied from general-functions.pl for speed improvement because #
24 # loading and initializing the whole general-functions.pl every second create #
26 ###########################################OA##################################
28 # Returns the output of a shell command
29 sub General__system_output
($) {
34 unless ($pid = open(OUTPUT
, "-|")) {
35 open(STDERR
, ">&STDOUT");
36 exec { ${command
[0]} } @command;
37 die "Could not execute @command: $!";
50 # Function which will return the used interface for the red network zone (red0, ppp0, etc).
51 sub General__get_red_interface
() {
53 open(IFACE
, "/var/ipfire/red/iface") or die "Could not open /var/ipfire/red/iface";
55 my $interface = <IFACE
>;
62 ###############################################################################
64 my $data_last = $ENV{'QUERY_STRING'};
68 my (@fields, $field, $name, $value);
69 @fields = split(/&/, $data_last);
70 foreach $field (@fields) {
71 ($name, $value) = split(/=/, $field);
73 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
74 if ("$name" eq "rxb_last") {
76 } elsif ("$name" eq "txb_last") {
81 my $interface = &General__get_red_interface
();
82 my @data_now = &General__system_output
("ip", "-s", "link", "show", "$interface");
88 if ( $lastline =~ /RX/ ) {
89 @fields = split(/ /, $_);
90 $rxb_now = $fields[4];
91 } elsif ( $lastline =~ /TX/ ) {
92 @fields = split(/ /, $_);
93 $txb_now = $fields[4];
98 my ($rx_kbs, $tx_kbs);
99 my $rxb_diff = $rxb_now - $rxb_last;
100 my $txb_diff = $txb_now - $txb_last;
102 if(( $rxb_diff == $rxb_now ) && ( $txb_diff == $txb_now ))
109 $rx_kbs = $rxb_diff / 1024;
110 $rx_kbs = $rx_kbs / 3.2;
111 $rx_kbs = int($rx_kbs);
112 $tx_kbs = $txb_diff / 1024;
113 $tx_kbs = $tx_kbs / 3.2;
114 $tx_kbs = int($tx_kbs);
117 print "pragma: no-cache\n";
118 print "Content-type: text/xml\n\n";
119 print "<?xml version=\"1.0\"?>\n";
122 <rx_kbs>$tx_kbs kb/s</rx_kbs>
123 <tx_kbs>$rx_kbs kb/s</tx_kbs>