2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2021 IPFire Twan <info@ipfire.org> #
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 # Function which will return the used interface for the red network zone (red0, ppp0, etc).
29 sub General__get_red_interface
() {
31 open(IFACE
, "/var/ipfire/red/iface") or die "Could not open /var/ipfire/red/iface";
33 my $interface = <IFACE
>;
40 ###############################################################################
42 my $data_last = $ENV{'QUERY_STRING'};
46 my (@fields, $field, $name, $value);
47 @fields = split(/&/, $data_last);
48 foreach $field (@fields) {
49 ($name, $value) = split(/=/, $field);
51 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
52 if ("$name" eq "rxb_last") {
54 } elsif ("$name" eq "txb_last") {
59 my $interface = &General__get_red_interface
();
61 open(RX
, "/sys/class/net/$interface/statistics/rx_bytes") or die "Could not open /sys/class/net/$interface/statistics/rx_bytes";
66 open(TX
, "/sys/class/net/$interface/statistics/tx_bytes") or die "Could not open /sys/class/net/$interface/statistics/tx_bytes";
71 my ($rx_kbs, $tx_kbs);
72 my $rxb_diff = $rxb_now - $rxb_last;
73 my $txb_diff = $txb_now - $txb_last;
75 if(( $rxb_diff == $rxb_now ) && ( $txb_diff == $txb_now ))
82 $rx_kbs = $rxb_diff / 1024;
83 $rx_kbs = $rx_kbs / 3.2;
84 $rx_kbs = int($rx_kbs);
85 $tx_kbs = $txb_diff / 1024;
86 $tx_kbs = $tx_kbs / 3.2;
87 $tx_kbs = int($tx_kbs);
90 print "pragma: no-cache\n";
91 print "Content-type: text/xml\n\n";
92 print "<?xml version=\"1.0\"?>\n";
95 <rx_kbs>$tx_kbs kb/s</rx_kbs>
96 <tx_kbs>$rx_kbs kb/s</tx_kbs>