Ein Paar Dateien fuer die GPLv3 angepasst.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / speed.cgi
1 #!/usr/bin/perl
2 ###############################################################################
3 # #
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007 Michael Tremer & Christian Schmidt #
6 # #
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. #
11 # #
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. #
16 # #
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/>. #
19 # #
20 ###############################################################################
21
22 my $data_last = $ENV{'QUERY_STRING'};
23 my $rxb_last = 0;
24 my $txb_last = 0;
25
26 my (@fields, $field, $name, $value);
27 @fields = split(/&/, $data_last);
28 foreach $field (@fields) {
29 ($name, $value) = split(/=/, $field);
30 $value =~ tr/+/ /;
31 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
32 if ("$name" eq "rxb_last") {
33 $rxb_last = $value;
34 } elsif ("$name" eq "txb_last") {
35 $txb_last = $value;
36 }
37 }
38
39 my @data_now = `ip -s link show red0`;
40
41 my $lastline;
42 my $rxb_now = 0;
43 my $txb_now = 0;
44 foreach (@data_now) {
45 if ( $lastline =~ /RX/ ) {
46 @fields = split(/ /, $_);
47 $rxb_now = $fields[4];
48 } elsif ( $lastline =~ /TX/ ) {
49 @fields = split(/ /, $_);
50 $txb_now = $fields[4];
51 }
52 $lastline = $_;
53 }
54
55 my ($rx_kbs, $tx_kbs);
56 my $rxb_diff = $rxb_now - $rxb_last;
57 my $txb_diff = $txb_now - $txb_last;
58
59 if(( $rxb_diff == $rxb_now ) && ( $txb_diff == $txb_now ))
60 {
61 $rx_kbs = "0";
62 $tx_kbs = "0";
63 }
64 else
65 {
66 $rx_kbs = $rxb_diff / 1024;
67 $rx_kbs = $rx_kbs / 3.2;
68 $rx_kbs = int($rx_kbs);
69 $tx_kbs = $txb_diff / 1024;
70 $tx_kbs = $tx_kbs / 3.2;
71 $tx_kbs = int($tx_kbs);
72 }
73
74 print "Content-type: text/xml\n\n";
75 print "<?xml version=\"1.0\"?>\n";
76 print <<END
77 <inetinfo>
78 <rx_kbs>$tx_kbs kb/s</rx_kbs>
79 <tx_kbs>$rx_kbs kb/s</tx_kbs>
80 <rxb>$rxb_now</rxb>
81 <txb>$txb_now</txb>
82 </inetinfo>
83 END
84 ;