]>
git.ipfire.org Git - people/teissler/ipfire-2.x.git/blob - html/cgi-bin/speed.cgi
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 my $data_last = $ENV{'QUERY_STRING'};
26 my (@fields, $field, $name, $value);
27 @fields = split(/&/, $data_last);
28 foreach $field (@fields) {
29 ($name, $value) = split(/=/, $field);
31 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
32 if ("$name" eq "rxb_last") {
34 } elsif ("$name" eq "txb_last") {
40 my $interface = `cat /var/ipfire/red/iface`;
41 my @data_now = `ip -s link show $interface`;
47 if ( $lastline =~ /RX/ ) {
48 @fields = split(/ /, $_);
49 $rxb_now = $fields[4];
50 } elsif ( $lastline =~ /TX/ ) {
51 @fields = split(/ /, $_);
52 $txb_now = $fields[4];
57 my ($rx_kbs, $tx_kbs);
58 my $rxb_diff = $rxb_now - $rxb_last;
59 my $txb_diff = $txb_now - $txb_last;
61 if(( $rxb_diff == $rxb_now ) && ( $txb_diff == $txb_now ))
68 $rx_kbs = $rxb_diff / 1024;
69 $rx_kbs = $rx_kbs / 3.2;
70 $rx_kbs = int($rx_kbs);
71 $tx_kbs = $txb_diff / 1024;
72 $tx_kbs = $tx_kbs / 3.2;
73 $tx_kbs = int($tx_kbs);
76 print "pragma: no-cache\n";
77 print "Content-type: text/xml\n\n";
78 print "<?xml version=\"1.0\"?>\n";
81 <rx_kbs>$tx_kbs kb/s</rx_kbs>
82 <tx_kbs>$rx_kbs kb/s</tx_kbs>