]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - html/cgi-bin/speed.cgi
suricata: Change midstream policy to "pass-flow"
[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 require '/var/ipfire/general-functions.pl';
23
24 my $data_last = $ENV{'QUERY_STRING'};
25 my $rxb_last = 0;
26 my $txb_last = 0;
27
28 my (@fields, $field, $name, $value);
29 @fields = split(/&/, $data_last);
30 foreach $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
41 my $interface = &General::get_red_interface();
42 my @data_now = &General::system_output("ip", "-s", "link", "show", "$interface");
43
44 my $lastline;
45 my $rxb_now = 0;
46 my $txb_now = 0;
47 foreach (@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
58 my ($rx_kbs, $tx_kbs);
59 my $rxb_diff = $rxb_now - $rxb_last;
60 my $txb_diff = $txb_now - $txb_last;
61
62 if(( $rxb_diff == $rxb_now ) && ( $txb_diff == $txb_now ))
63 {
64 $rx_kbs = "0";
65 $tx_kbs = "0";
66 }
67 else
68 {
69 $rx_kbs = $rxb_diff / 1024;
70 $rx_kbs = $rx_kbs / 3.2;
71 $rx_kbs = int($rx_kbs);
72 $tx_kbs = $txb_diff / 1024;
73 $tx_kbs = $tx_kbs / 3.2;
74 $tx_kbs = int($tx_kbs);
75 }
76
77 print "pragma: no-cache\n";
78 print "Content-type: text/xml\n\n";
79 print "<?xml version=\"1.0\"?>\n";
80 print <<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>
87 END
88 ;