]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/speed.cgi
speed.cgi: Add requirement for general-functions.pl.
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / speed.cgi
CommitLineData
16f6c28c 1#!/usr/bin/perl
70df8302
MT
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###############################################################################
16f6c28c 21
5e99660d
SS
22require '/var/ipfire/general-functions.pl';
23
16f6c28c
MT
24my $data_last = $ENV{'QUERY_STRING'};
25my $rxb_last = 0;
26my $txb_last = 0;
27
28my (@fields, $field, $name, $value);
29@fields = split(/&/, $data_last);
30foreach $field (@fields) {
31 ($name, $value) = split(/=/, $field);
32 $value =~ tr/+/ /;
33 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
34 if ("$name" eq "rxb_last") {
35 $rxb_last = $value;
36 } elsif ("$name" eq "txb_last") {
37 $txb_last = $value;
38 }
39}
40
1e7c0108
SS
41my $interface = &General::get_red_interface();
42my @data_now = &General::system_output("ip", "-s", "link", "show", "$interface");
16f6c28c
MT
43
44my $lastline;
45my $rxb_now = 0;
46my $txb_now = 0;
47foreach (@data_now) {
48 if ( $lastline =~ /RX/ ) {
49 @fields = split(/ /, $_);
50 $rxb_now = $fields[4];
51 } elsif ( $lastline =~ /TX/ ) {
52 @fields = split(/ /, $_);
53 $txb_now = $fields[4];
54 }
55 $lastline = $_;
56}
57
58my ($rx_kbs, $tx_kbs);
59my $rxb_diff = $rxb_now - $rxb_last;
60my $txb_diff = $txb_now - $txb_last;
61
62if(( $rxb_diff == $rxb_now ) && ( $txb_diff == $txb_now ))
63{
94ec137d
CS
64 $rx_kbs = "0";
65 $tx_kbs = "0";
16f6c28c
MT
66}
67else
68{
69 $rx_kbs = $rxb_diff / 1024;
3ef6c343 70 $rx_kbs = $rx_kbs / 3.2;
16f6c28c
MT
71 $rx_kbs = int($rx_kbs);
72 $tx_kbs = $txb_diff / 1024;
3ef6c343 73 $tx_kbs = $tx_kbs / 3.2;
16f6c28c
MT
74 $tx_kbs = int($tx_kbs);
75}
76
f63935b1 77print "pragma: no-cache\n";
16f6c28c
MT
78print "Content-type: text/xml\n\n";
79print "<?xml version=\"1.0\"?>\n";
80print <<END
81<inetinfo>
82 <rx_kbs>$tx_kbs kb/s</rx_kbs>
83 <tx_kbs>$rx_kbs kb/s</tx_kbs>
84 <rxb>$rxb_now</rxb>
85 <txb>$txb_now</txb>
86</inetinfo>
87END
88;