]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - html/cgi-bin/speed.cgi
suricata: Change midstream policy to "pass-flow"
[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 #
a8dd6e98 5# Copyright (C) 2007-2021 IPFire Twan <info@ipfire.org> #
70df8302
MT
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
110d4c81
AF
22###############################################################################
23# functions copied from general-functions.pl for speed improvement because #
24# loading and initializing the whole general-functions.pl every second create #
25# high system load #
26###########################################OA##################################
27#
110d4c81
AF
28# Function which will return the used interface for the red network zone (red0, ppp0, etc).
29sub General__get_red_interface() {
30
31 open(IFACE, "/var/ipfire/red/iface") or die "Could not open /var/ipfire/red/iface";
32
33 my $interface = <IFACE>;
34 close(IFACE);
35 chomp $interface;
36
37 return $interface;
38}
39#
40###############################################################################
5e99660d 41
16f6c28c
MT
42my $data_last = $ENV{'QUERY_STRING'};
43my $rxb_last = 0;
44my $txb_last = 0;
45
66c36198 46my (@fields, $field, $name, $value);
16f6c28c
MT
47@fields = split(/&/, $data_last);
48foreach $field (@fields) {
49 ($name, $value) = split(/=/, $field);
50 $value =~ tr/+/ /;
51 $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
52 if ("$name" eq "rxb_last") {
53 $rxb_last = $value;
54 } elsif ("$name" eq "txb_last") {
55 $txb_last = $value;
56 }
57}
58
110d4c81 59my $interface = &General__get_red_interface();
16f6c28c 60
a8dd6e98
AF
61open(RX, "/sys/class/net/$interface/statistics/rx_bytes") or die "Could not open /sys/class/net/$interface/statistics/rx_bytes";
62my $rxb_now = <RX>;
63close(RX);
64chomp $rxb_now;
65
66open(TX, "/sys/class/net/$interface/statistics/tx_bytes") or die "Could not open /sys/class/net/$interface/statistics/tx_bytes";
67my $txb_now = <TX>;
68close(TX);
69chomp $txb_now;
16f6c28c
MT
70
71my ($rx_kbs, $tx_kbs);
72my $rxb_diff = $rxb_now - $rxb_last;
73my $txb_diff = $txb_now - $txb_last;
74
75if(( $rxb_diff == $rxb_now ) && ( $txb_diff == $txb_now ))
76{
94ec137d
CS
77 $rx_kbs = "0";
78 $tx_kbs = "0";
16f6c28c
MT
79}
80else
81{
82 $rx_kbs = $rxb_diff / 1024;
3ef6c343 83 $rx_kbs = $rx_kbs / 3.2;
16f6c28c
MT
84 $rx_kbs = int($rx_kbs);
85 $tx_kbs = $txb_diff / 1024;
3ef6c343 86 $tx_kbs = $tx_kbs / 3.2;
16f6c28c
MT
87 $tx_kbs = int($tx_kbs);
88}
89
f63935b1 90print "pragma: no-cache\n";
16f6c28c
MT
91print "Content-type: text/xml\n\n";
92print "<?xml version=\"1.0\"?>\n";
93print <<END
94<inetinfo>
95 <rx_kbs>$tx_kbs kb/s</rx_kbs>
96 <tx_kbs>$rx_kbs kb/s</tx_kbs>
97 <rxb>$rxb_now</rxb>
98 <txb>$txb_now</txb>
99</inetinfo>
100END
101;