]> git.ipfire.org Git - ipfire-2.x.git/blame - html/cgi-bin/speed.cgi
Uploads.cgi entfernt. Die war noch ueber.
[ipfire-2.x.git] / html / cgi-bin / speed.cgi
CommitLineData
16f6c28c
MT
1#!/usr/bin/perl
2#
3# IPFire CGIs
4#
5# This code is distributed under the terms of the GPL
6#
7# (c) The IPFire Team
8#
9
10my $data_last = $ENV{'QUERY_STRING'};
11my $rxb_last = 0;
12my $txb_last = 0;
13
14my (@fields, $field, $name, $value);
15@fields = split(/&/, $data_last);
16foreach $field (@fields) {
17 ($name, $value) = split(/=/, $field);
18 $value =~ tr/+/ /;
19 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
20 if ("$name" eq "rxb_last") {
21 $rxb_last = $value;
22 } elsif ("$name" eq "txb_last") {
23 $txb_last = $value;
24 }
25}
26
27my @data_now = `ip -s link show red0`;
28
29my $lastline;
30my $rxb_now = 0;
31my $txb_now = 0;
32foreach (@data_now) {
33 if ( $lastline =~ /RX/ ) {
34 @fields = split(/ /, $_);
35 $rxb_now = $fields[4];
36 } elsif ( $lastline =~ /TX/ ) {
37 @fields = split(/ /, $_);
38 $txb_now = $fields[4];
39 }
40 $lastline = $_;
41}
42
43my ($rx_kbs, $tx_kbs);
44my $rxb_diff = $rxb_now - $rxb_last;
45my $txb_diff = $txb_now - $txb_last;
46
47if(( $rxb_diff == $rxb_now ) && ( $txb_diff == $txb_now ))
48{
94ec137d
CS
49 $rx_kbs = "0";
50 $tx_kbs = "0";
16f6c28c
MT
51}
52else
53{
54 $rx_kbs = $rxb_diff / 1024;
3ef6c343 55 $rx_kbs = $rx_kbs / 3.2;
16f6c28c
MT
56 $rx_kbs = int($rx_kbs);
57 $tx_kbs = $txb_diff / 1024;
3ef6c343 58 $tx_kbs = $tx_kbs / 3.2;
16f6c28c
MT
59 $tx_kbs = int($tx_kbs);
60}
61
62print "Content-type: text/xml\n\n";
63print "<?xml version=\"1.0\"?>\n";
64print <<END
65<inetinfo>
66 <rx_kbs>$tx_kbs kb/s</rx_kbs>
67 <tx_kbs>$rx_kbs kb/s</tx_kbs>
68 <rxb>$rxb_now</rxb>
69 <txb>$txb_now</txb>
70</inetinfo>
71END
72;