X-Git-Url: http://git.ipfire.org/?p=people%2Fteissler%2Fipfire-2.x.git;a=blobdiff_plain;f=html%2Fcgi-bin%2Ftraffics.cgi;h=af9115089fe64abf92e9e8aa65a8857f4c4d9c29;hp=00c7ebe6c12f28d585e417c8bf45bc1834d46a7c;hb=70df830214c97a68fcb7e89ae0d7df58c35590be;hpb=15f635cc82b61ae06ce8476acdb7adee34df92ee diff --git a/html/cgi-bin/traffics.cgi b/html/cgi-bin/traffics.cgi index 00c7ebe6c..af9115089 100644 --- a/html/cgi-bin/traffics.cgi +++ b/html/cgi-bin/traffics.cgi @@ -1,104 +1,116 @@ #!/usr/bin/perl -# -# SmoothWall CGIs -# -# This code is distributed under the terms of the GPL -# -# (c) The SmoothWall Team -# +############################################################################### +# # +# IPFire.org - A linux based firewall # +# Copyright (C) 2007 Michael Tremer & Christian Schmidt # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see . # +# # +############################################################################### use strict; # enable only the following on debugging purpose -use warnings; -use CGI::Carp 'fatalsToBrowser'; +#use warnings; +#use CGI::Carp 'fatalsToBrowser'; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/lang.pl"; require "${General::swroot}/header.pl"; -require '/var/ipfire/net-traffic/net-traffic-lib.pl'; +require "${General::swroot}/net-traffic/net-traffic-admin.pl"; +require "${General::swroot}/net-traffic/net-traffic-lib.pl"; -my %cgiparams; +my %color = (); +my %mainsettings = (); +&General::readhash("${General::swroot}/main/settings", \%mainsettings); +&General::readhash("/srv/web/ipfire/html/themes/".$mainsettings{'THEME'}."/include/colors.txt", \%color); + +my %cgiparams; my %netsettings; &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); -my @years=("2007","2008","2009","2010","2011","2012","2013","2014","2015"); - -my @longmonths = ( $Lang::tr{'january'}, $Lang::tr{'february'}, $Lang::tr{'march'}, - $Lang::tr{'april'}, $Lang::tr{'may'}, $Lang::tr{'june'}, $Lang::tr{'july'}, $Lang::tr{'august'}, - $Lang::tr{'september'}, $Lang::tr{'october'}, $Lang::tr{'november'}, - $Lang::tr{'december'} ); - -my @months = ( 0,1,2,3,4,5,6,7,8,9,10,11 ); my @days = ( 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 ); -my @now = localtime(time); +my @now = localtime(time); $now[5] = $now[5]+1900; -$cgiparams{'STARTDAY'} = 10; -$cgiparams{'STOPDAY'} = 11; -$cgiparams{'STARTYEAR'} = $now[5]; -$cgiparams{'STOPYEAR'} = $now[5]; +$cgiparams{'STARTDAY'} = 10; +$cgiparams{'STOPDAY'} = 11; +$cgiparams{'STARTYEAR'} = $now[5]; +$cgiparams{'STOPYEAR'} = $now[5]; + +if($NETTRAFF::settings{'MONTHLY_VOLUME_ON'} eq 'on') +{ + $cgiparams{'STARTDAY'} = $NETTRAFF::settings{'STARTDAY'}; + $cgiparams{'STOPDAY'} = $NETTRAFF::settings{'STARTDAY'}; +} # this periode started last month -if ($now[3] < 10) { +if ($now[3] < $cgiparams{'STARTDAY'}) { $cgiparams{'STARTMONTH'} = $now[4]-1; $cgiparams{'STOPMONTH'} = $now[4]; # when current month is january we start in last year december - if ($now[4] == 0) { + if ($cgiparams{'STOPMONTH'} == 0) { $cgiparams{'STARTYEAR'} = $now[5]-1; - $cgiparams{'STARTMONTH'} = 11; + $cgiparams{'STARTMONTH'} = 11; } } else { $cgiparams{'STARTMONTH'} = $now[4]; $cgiparams{'STOPMONTH'} = $now[4]+1; - # when we are december, this periode ends next year january - if ($now[4] == 11) { - $cgiparams{'STOPYEAR'} = $now[5]+1; + # when we are in december, this periode ends next year january + if ($cgiparams{'STARTMONTH'} == 11) { + $cgiparams{'STOPYEAR'} = $now[5]+1; $cgiparams{'STOPMONTH'} = 0; } } - -&Header::getcgihash(\%cgiparams); +&Header::getcgihash(\%cgiparams); &Header::showhttpheaders(); - &Header::openpage($Lang::tr{'sstraffic'}, 1, ''); - &Header::openbigbox('100%', 'left'); - -&Header::openbox('100%', 'left', $Lang::tr{'settings'}); +&Header::openbox('100%', 'left', ""); print < - +
$Lang::tr{'trafficfrom'} END -foreach (@months) +foreach my $month (@NETTRAFF::months) { print "\t\n"; + print "value='$month'>$NETTRAFF::longmonths[$month]\n"; } print < END -for (my $index=0; $index<=$#years; $index++) { +foreach my $year (@NETTRAFF::years) { print "\t\n"; + print "value='$year'>$year\n"; } print < END -foreach (@days) +foreach my $day (@days) { print "\t\n"; + print "value='$day'>$day\n"; } print < END -foreach (@months) +foreach my $month (@NETTRAFF::months) { print "\t\n"; + print "value='$month'>$NETTRAFF::longmonths[$month]\n"; } print < END -for (my $index = 0; $index <=$#years; $index++) { +foreach my $year (@NETTRAFF::years) { print "\t\n"; + print "value='$year'>$year\n"; } print < - - + +
- + END &Header::closebox(); -&Header::openbox('100%', 'left', $Lang::tr{'traffics'}); +&Header::openbox('100%', 'left', "$Lang::tr{'traffics'}"); my $dateWidth = '20%'; my $netWidth = '34%'; my $inOutWidth = '17%'; # 4 networks -if ($netsettings{'CONFIG_TYPE'} =~ /^(5|7)$/) { +if ($netsettings{'CONFIG_TYPE'} =~ /^(4)$/) { $dateWidth = '12%'; $netWidth = '22%'; $inOutWidth = '11%'; } # 3 networks -if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|4|6)$/) { +if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3)$/) { $dateWidth = '16%'; $netWidth = '28%'; $inOutWidth = '14%'; @@ -196,41 +208,45 @@ print <$Lang::tr{'trafficgreen'} END -if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) { +if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) { print "$Lang::tr{'trafficblue'}"; } -if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) { +if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) { print "$Lang::tr{'trafficorange'}"; } +if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) +{ +print "$Lang::tr{'trafficred'}"; +} print <$Lang::tr{'trafficred'} - - + + END -if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) -{ +if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) +{ print ""; print ""; -} +} -if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) -{ - print ""; - print ""; -} -print <$Lang::tr{'trafficin'} - - -END +if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) +{ + print ""; + print ""; +} +if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) +{ +print ""; +print ""; +} +print ""; my $total_blue_in=0; my $total_blue_out=0; @@ -269,45 +285,49 @@ my @allDays = &Traffic::calcTraffic(\%allDaysBytes,$start,$end, $displayMode); foreach (@allDays) { $total_green_in += $allDaysBytes{$_}{${Traffic::green_in}}; $total_green_out += $allDaysBytes{$_}{${Traffic::green_out}}; - - if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) + + if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) { $total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}}; $total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}}; } - - if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) + + if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) { $total_orange_in += $allDaysBytes{$_}{${Traffic::orange_in}}; $total_orange_out += $allDaysBytes{$_}{${Traffic::orange_out}}; } - + + if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) + { $total_red_in += $allDaysBytes{$_}{${Traffic::red_in}}; $total_red_out += $allDaysBytes{$_}{${Traffic::red_out}}; - + } + if ($lines % 2) { - print ""; } + print ""; } else { - print ""; } - + print ""; } + printf "\n", $allDaysBytes{$_}{'Day'}; printf "\n", ($allDaysBytes{$_}{${Traffic::green_in}}/1048576); printf "\n", ($allDaysBytes{$_}{${Traffic::green_out}}/1048576); - - if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) - { + + if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) + { printf "\n", ($allDaysBytes{$_}{${Traffic::blue_in}}/1048576); printf "\n", ($allDaysBytes{$_}{${Traffic::blue_out}}/1048576); - } - if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) - { + } + if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) + { printf "\n", ($allDaysBytes{$_}{${Traffic::orange_in}}/1048576); printf "\n", ($allDaysBytes{$_}{${Traffic::orange_out}}/1048576); - } - + } + if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) + { printf "\n", ($allDaysBytes{$_}{${Traffic::red_in}}/1048576); printf "\n", ($allDaysBytes{$_}{${Traffic::red_out}}/1048576); - + } $lines++; } @@ -316,40 +336,38 @@ $total_green_out=sprintf("%.2f", ($total_green_out/1048576)); $total_blue_in=sprintf("%.2f", ($total_blue_in/1048576)); $total_blue_out=sprintf("%.2f", ($total_blue_out/1048576)); $total_orange_in=sprintf("%.2f", ($total_orange_in/1048576)); -$total_orange_out=sprintf("%.2f", ($total_orange_out/1048576)); +$total_orange_out=sprintf("%.2f", ($total_orange_out/1048576)); $total_red_in=sprintf("%.2f", ($total_red_in/1048576)); $total_red_out=sprintf("%.2f", ($total_red_out/1048576)); - -if ($lines % 2) {print ""; } -else {print ""; } - + +if ($lines % 2) {print ""; } +else {print ""; } + print <$Lang::tr{'trafficsum'} END - -if ($netsettings{'CONFIG_TYPE'} =~ /^(4|5|6|7)$/) -{ + +if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) +{ print ""; print ""; } -if ($netsettings{'CONFIG_TYPE'} =~ /^(1|3|5|7)$/) -{ +if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) +{ print ""; print ""; } - -print <$total_red_in MB - - -
$Lang::tr{'trafficdate'}$Lang::tr{'trafficin'}$Lang::tr{'trafficout'}$Lang::tr{'trafficin'}$Lang::tr{'trafficout'}$Lang::tr{'trafficin'}$Lang::tr{'trafficout'}$Lang::tr{'trafficin'}$Lang::tr{'trafficout'}$Lang::tr{'trafficout'}
$Lang::tr{'trafficin'}$Lang::tr{'trafficout'}$Lang::tr{'trafficin'}$Lang::tr{'trafficout'}
%s%.3f%.3f%.3f%.3f%.3f%.3f%.3f%.3f
$total_green_in MB $total_green_out MB$total_blue_in MB$total_blue_out MB$total_orange_in MB$total_orange_out MB$total_red_out MB
-END -&Header::closebox(); +if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) +{ +print "$total_red_in MB"; +print "$total_red_out MB"; +} +print ""; +&Header::closebox(); &Header::closebigbox(); - &Header::closepage();