X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=html%2Fcgi-bin%2Ftraffic.cgi;h=70e5726c907b6498b85c92bd63f04cea1d341966;hb=eadc8af30a855a89f718353696f6aa167f87462d;hp=22867d76a784f7ffe189fc13c98456b923d87cf4;hpb=b05768be3b86eda86a4e3e6ef043b03a83984eb7;p=people%2Fpmueller%2Fipfire-2.x.git diff --git a/html/cgi-bin/traffic.cgi b/html/cgi-bin/traffic.cgi index 22867d76a7..70e5726c90 100644 --- a/html/cgi-bin/traffic.cgi +++ b/html/cgi-bin/traffic.cgi @@ -1,308 +1,123 @@ #!/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 %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 %cgiparams; my %pppsettings; my %netsettings; &General::readhash("${General::swroot}/ppp/settings", \%pppsettings); &General::readhash("${General::swroot}/ethernet/settings", \%netsettings); -my @wday = ($Lang::tr{'wday1'}, $Lang::tr{'wday2'}, $Lang::tr{'wday3'}, $Lang::tr{'wday4'}, $Lang::tr{'wday5'}, $Lang::tr{'wday6'}, $Lang::tr{'wday7'}); -my ($s, $min, $h, $d, $m,$y) = localtime(time); -$y+=1900; -$m+=1; -$m = $m < 10 ? $m = "0".$m : $m; - -$cgiparams{'MONTH'} = $m; -&Header::getcgihash(\%cgiparams); -$cgiparams{'YEAR'} = $y; &Header::getcgihash(\%cgiparams); &Header::showhttpheaders(); - -my %selectYear; -$selectYear{'YEAR'}{'2007'} = ''; -$selectYear{'YEAR'}{'2008'} = ''; -$selectYear{'YEAR'}{'2009'} = ''; -$selectYear{'YEAR'}{'2010'} = ''; -$selectYear{'YEAR'}{'2011'} = ''; -$selectYear{'YEAR'}{'2012'} = ''; -$selectYear{'YEAR'}{'????'} = ''; -$selectYear{'YEAR'}{$cgiparams{'YEAR'}} = 'selected=\'selected\''; - - -my %selected; - -$selected{'MONTH'}{'01'} = ''; -$selected{'MONTH'}{'02'} = ''; -$selected{'MONTH'}{'03'} = ''; -$selected{'MONTH'}{'04'} = ''; -$selected{'MONTH'}{'05'} = ''; -$selected{'MONTH'}{'06'} = ''; -$selected{'MONTH'}{'07'} = ''; -$selected{'MONTH'}{'08'} = ''; -$selected{'MONTH'}{'09'} = ''; -$selected{'MONTH'}{'10'} = ''; -$selected{'MONTH'}{'11'} = ''; -$selected{'MONTH'}{'12'} = ''; -$selected{'MONTH'}{'??'} = ''; -$selected{'MONTH'}{$cgiparams{'MONTH'}} = 'selected=\'selected\''; - &Header::openpage($Lang::tr{'sstraffic'}, 1, ''); - &Header::openbigbox('100%', 'left'); -&Header::openbox('100%', 'left', $Lang::tr{'settingsc'}); +&Header::openbox('100%', 'center', "$Lang::tr{'traffics'}"); -print < - - -
- $Lang::tr{'selecttraffic'} - - - -
- - -
- -
- - - -END - -&Header::closebox(); +# Display internal network +display_vnstat($netsettings{'GREEN_DEV'}); -&Header::openbox('100%', 'left', $Lang::tr{'traffics'}); - -my $dateWidth = '20%'; -my $netWidth = '34%'; -my $inOutWidth = '17%'; - -# 4 networks -if ($netsettings{'CONFIG_TYPE'} =~ /^(4)$/) { - $dateWidth = '12%'; - $netWidth = '22%'; - $inOutWidth = '11%'; -} -# 3 networks -if ($netsettings{'CONFIG_TYPE'} =~ /^(2|3)$/) { - $dateWidth = '16%'; - $netWidth = '28%'; - $inOutWidth = '14%'; +# Display external network / check if it is PPP or ETH +# and dont display if RED_DEV=GREEN_DEV (green only mode) +if ($netsettings{'RED_TYPE'} ne 'PPPOE') { + if ($netsettings{'RED_DEV'} ne $netsettings{'GREEN_DEV'}) { + display_vnstat($netsettings{'RED_DEV'}); + } +} else { + display_vnstat("ppp0"); } -print < - - - $Lang::tr{'trafficgreen'} -END - +# Check config and display aditional Networks (BLUE and ORANGE) +# if they exist if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) { - print "$Lang::tr{'trafficblue'}"; + display_vnstat($netsettings{'BLUE_DEV'}); } if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) { - print "$Lang::tr{'trafficorange'}"; + display_vnstat($netsettings{'ORANGE_DEV'}); } -if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) { - print "$Lang::tr{'trafficred'}"; - } -print < - - - - - - -END - -if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) -{ - print ""; - print ""; -} +&Header::closebox(); +&Header::closebigbox(); +&Header::closepage(); -if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) -{ - print ""; - print ""; -} -if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) +sub display_vnstat { - print ""; - print ""; -} - print""; - -my $total_blue_in=0; -my $total_blue_out=0; -my $total_green_in=0; -my $total_green_out=0; -my $total_orange_in=0; -my $total_orange_out=0; -my $total_red_in=0; -my $total_red_out=0; -my $lines=0; - -my $displayMode = "daily"; -my $startMonth = $cgiparams{'MONTH'}; -my $endMonth = $cgiparams{'MONTH'}; - -if ($cgiparams{'MONTH'} eq '??') { - $displayMode = "monthly"; - $startMonth = '01'; - $endMonth = '12'; -} - -my $start = "$cgiparams{'YEAR'}$startMonth"."01"; -my $end = "$cgiparams{'YEAR'}$endMonth"."32"; -my %allDaysBytes = (); -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'} =~ /^(3|4)$/) - { - $total_blue_in += $allDaysBytes{$_}{${Traffic::blue_in}}; - $total_blue_out += $allDaysBytes{$_}{${Traffic::blue_out}}; - } - - 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 ""; } - else { - print ""; } - - printf "\n", $allDaysBytes{$_}{'Day'}; - printf "\n", ($allDaysBytes{$_}{${Traffic::green_in}}/1048576); - printf "\n", ($allDaysBytes{$_}{${Traffic::green_out}}/1048576); - - if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) - { - printf "\n", ($allDaysBytes{$_}{${Traffic::blue_in}}/1048576); - printf "\n", ($allDaysBytes{$_}{${Traffic::blue_out}}/1048576); - } - 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++; -} - -$total_green_in=sprintf("%.2f", ($total_green_in/1048576)); -$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_red_in=sprintf("%.2f", ($total_red_in/1048576)); -$total_red_out=sprintf("%.2f", ($total_red_out/1048576)); - -if ($lines % 2) {print ""; } -else {print ""; } - -print <$Lang::tr{'trafficsum'} - - + my $device = $_[0]; + + my $testdata = `/usr/bin/vnstat -i $device`; + + if ( $testdata =~ 'enough') { + print"No data for $device !
"; + } else { + # Falls back to textoutput if there was no % value because vnstati hang in this case + if (!($testdata =~ 'nan%')) { + system("/usr/bin/vnstati -c 5 -s -i $device -o /srv/web/ipfire/html/graphs/vnstat-s-$device.png"); + } + # Hour graph + system("/usr/bin/vnstati -c 5 -h -i $device -o /srv/web/ipfire/html/graphs/vnstat-h-$device.png"); + # Day graph + system("/usr/bin/vnstati -c 5 -d -i $device -o /srv/web/ipfire/html/graphs/vnstat-d-$device.png"); + # Month graph + system("/usr/bin/vnstati -c 5 -m -i $device -o /srv/web/ipfire/html/graphs/vnstat-m-$device.png"); + # Top10 graph + system("/usr/bin/vnstati -c 5 -t -i $device -o /srv/web/ipfire/html/graphs/vnstat-t-$device.png"); + +# Generate HTML-Table with the graphs + print "
$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'}
%s%.3f%.3f%.3f%.3f%.3f%.3f%.3f%.3f
$total_green_in MB$total_green_out MB
"; + if ($testdata =~ 'nan%') { + print ""; + } else { + print""; + } +print < + + + +
";
+		system("/usr/bin/vnstat -i $device");
+		print "
END - -if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/) -{ - print "$total_blue_in MB"; - print "$total_blue_out MB"; +; + } + print"
"; } - -if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) -{ - print "$total_orange_in MB"; - print "$total_orange_out MB"; -} -if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) -{ - print "$total_red_in MB"; - print "$total_red_out MB"; -} -print < - -END - -&Header::closebox(); - -&Header::closebigbox(); - -&Header::closepage();