]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blobdiff - html/cgi-bin/traffics.cgi
Net-Traffic aktualisiert
[people/pmueller/ipfire-2.x.git] / html / cgi-bin / traffics.cgi
index 92e73140781683a7abb79d37679acacf80c9f8d3..26e4a134b6bfdb2a0c1403462bd60bca55718a3c 100644 (file)
@@ -6,6 +6,12 @@
 #
 # (c) The SmoothWall Team
 #
+# $Id: traffics.cgi,v 1.12 2006/11/15 21:14:02 dotzball Exp $
+#
+# traffics.cgi, v1.1.0 2003/10/18
+#              supports now:
+#                      * IPCop v1.3.0
+#                      * choosing year
 
 use strict;
 
@@ -16,94 +22,89 @@ 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 %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 <<END;
 <table width='100%' align='center'>
 <tr>
-       <td width='95%' class='base' align='center'>
+       <td width='90%' class='base' align='center'>
                <form method='post' action='/cgi-bin/traffics.cgi'>
                $Lang::tr{'trafficfrom'}
                <select name='STARTDAY'>
 END
 
-foreach (@days) 
+foreach my $day (@days)
 {
        print "\t<option ";
-       if ($_ == $cgiparams{'STARTDAY'}) {
+       if ($day == $cgiparams{'STARTDAY'}) {
                print 'selected=\'selected\' '; }
-       print "value='$_'>$_</option>\n";
+       print "value='$day'>$day</option>\n";
 }
 print <<END;
        </select>
        <select name='STARTMONTH'>
 END
 
-foreach (@months)
+foreach my $month (@NETTRAFF::months)
 {
        print "\t<option ";
-       if ($_ == $cgiparams{'STARTMONTH'}) {
+       if ($month == $cgiparams{'STARTMONTH'}) {
                print 'selected=\'selected\' '; }
-       print "value='$_'>$longmonths[$_]</option>\n";
+       print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
 }
 
 print <<END;
@@ -111,11 +112,11 @@ print <<END;
        <select name='STARTYEAR'>
 END
 
-for (my $index=0; $index<=$#years; $index++) {
+foreach my $year (@NETTRAFF::years) {
        print "\t<option ";
-       if ($years[$index] == $cgiparams{'STARTYEAR'}) {
+       if ($year == $cgiparams{'STARTYEAR'}) {
                print 'selected=\'selected\' '; }
-       print "value='$years[$index]'>$years[$index]</option>\n";
+       print "value='$year'>$year</option>\n";
 }
 
 print <<END;
@@ -124,13 +125,13 @@ print <<END;
        <select name='STOPDAY'>
 END
 
-foreach (@days) 
+foreach my $day (@days)
 {
        print "\t<option ";
-       if ($_ == $cgiparams{'STOPDAY'}) 
+       if ($day == $cgiparams{'STOPDAY'})
                {
                print 'selected=\'selected\' '; }
-       print "value='$_'>$_</option>\n";
+       print "value='$day'>$day</option>\n";
 }
 
 print <<END;
@@ -138,12 +139,12 @@ print <<END;
        <select name='STOPMONTH'>
 END
 
-foreach (@months)
+foreach my $month (@NETTRAFF::months)
 {
        print "\t<option ";
-       if ($_ == $cgiparams{'STOPMONTH'}) {
+       if ($month == $cgiparams{'STOPMONTH'}) {
                print 'selected=\'selected\' '; }
-       print "value='$_'>$longmonths[$_]</option>\n";
+       print "value='$month'>$NETTRAFF::longmonths[$month]</option>\n";
 }
 
 print <<END;
@@ -151,31 +152,31 @@ print <<END;
        <select name='STOPYEAR'>
 END
 
-for (my $index = 0; $index <=$#years; $index++) {
+foreach my $year (@NETTRAFF::years) {
        print "\t<option ";
-       if ($years[$index] == $cgiparams{'STOPYEAR'}) {
+       if ($year == $cgiparams{'STOPYEAR'}) {
                print 'selected=\'selected\' '; }
-       print "value='$years[$index]'>$years[$index]</option>\n";
+       print "value='$year'>$year</option>\n";
 }
 
 
 print <<END;
                        </select>
                        <input type='submit' name='ACTION' value='$Lang::tr{'update'}' />
-               </form> 
-       </td>        
+               </form>
+       </td>
        <td width='5%' align='center'>
                <form method='post' action='/cgi-bin/traffic.cgi'>
                <input type='submit' name='ACTION' value=' > ' />
                </form>
-       </td>   
+       </td>
        </tr>
        </table>
 END
 
 &Header::closebox();
 
-&Header::openbox('100%', 'left', $Lang::tr{'traffics'});
+&Header::openbox('100%', 'left', "$Lang::tr{'traffics'}");
 
 my $dateWidth = '20%';
 my $netWidth = '34%';
@@ -209,38 +210,37 @@ if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/) {
        print "<td width='$netWidth' align='center' class='boldbase' ><b>$Lang::tr{'trafficorange'}</b></td>";
 }
 
-if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/) {
-       print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>";
-       }
-
+if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
+{
+print "<td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>";
+}
 print <<END;
-               <td width='$netWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficred'}</b></td>
        </tr>
        </table>
        <table width='100%'>
        <tr>
                <td width='$dateWidth' align='center' class='boldbase'><b>$Lang::tr{'trafficdate'}</b></td>
-               <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficin'}</b></font></td>
-               <td width='$inOutWidth' align='center' class='boldbase'><font color='#16A61D'><b>$Lang::tr{'trafficout'}</b></font></td>
+               <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><b>$Lang::tr{'trafficin'}</b></font></td>
+               <td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourgreen'><b>$Lang::tr{'trafficout'}</b></font></td>
 END
 
 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
-{  
+{
        print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficin'}</b></font></td>";
        print "<td width='$inOutWidth' align='center' class='boldbase'><font color='${Header::colourblue}'><b>$Lang::tr{'trafficout'}</b></font></td>";
-} 
+}
 
 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
-{  
-       print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficin'}</b></font></td>";
-       print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#FF9933'><b>$Lang::tr{'trafficout'}</b></font></td>";
-} 
+{
+       print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><b>$Lang::tr{'trafficin'}</b></font></td>";
+       print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourorange'><b>$Lang::tr{'trafficout'}</b></font></td>";
+}
 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
-{      
-       print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficin'}</b></font></td>";
-       print "<td width='$inOutWidth' align='center' class='boldbase'><font color='#CE1B31'><b>$Lang::tr{'trafficout'}</b></font></td>";
+{
+print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficin'}</b></font></td>";
+print "<td width='$inOutWidth' align='center' class='boldbase'><font color='$Header::colourred'><b>$Lang::tr{'trafficout'}</b></font></td>";
 }
-       print"</tr>";
+print "</tr>";
 
 my $total_blue_in=0;
 my $total_blue_out=0;
@@ -279,49 +279,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'} =~ /^(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 "<tr bgcolor='$color{'color20'}'>"; }
        else {
                print "<tr bgcolor='$color{'color22'}'>"; }
-                               
+
        printf "<td align='center' nowrap='nowrap'>%s</td>\n", $allDaysBytes{$_}{'Day'};
        printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_in}}/1048576);
        printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::green_out}}/1048576);
-               
+
        if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
-       {  
+       {
                printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_in}}/1048576);
                printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::blue_out}}/1048576);
-       } 
+       }
        if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
-       {   
+       {
                printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_in}}/1048576);
                printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::orange_out}}/1048576);
-       } 
-       if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
+       }
+  if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
   {
        printf "<td align='center' nowrap='nowrap'>%.3f</td>\n", ($allDaysBytes{$_}{${Traffic::red_in}}/1048576);
        printf "<td align='center' nowrap='nowrap'>%.3f</td></tr>\n", ($allDaysBytes{$_}{${Traffic::red_out}}/1048576);
-  }            
+  }
        $lines++;
 }
 
@@ -330,42 +330,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 "<tr bgcolor='$color{'color20'}'>"; }
+
+if ($lines % 2) {print "<tr bgcolor='$color{'color22'}'>"; }
 else {print "<tr bgcolor='$color{'color22'}'>"; }
-  
+
 print <<END;
        <td align='center' class='boldbase' height='20' nowrap='nowrap'><b>$Lang::tr{'trafficsum'}</b></td>
        <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_in MB</b></td>
        <td align='center' class='boldbase' nowrap='nowrap'><b>$total_green_out MB</b></td>
 END
-  
+
 if ($netsettings{'CONFIG_TYPE'} =~ /^(3|4)$/)
-{    
+{
        print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_in MB</b></td>";
        print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_blue_out MB</b></td>";
 }
 
 if ($netsettings{'CONFIG_TYPE'} =~ /^(2|4)$/)
-{    
+{
        print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_in MB</b></td>";
        print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_orange_out MB</b></td>";
 }
+
 if ($netsettings{'CONFIG_TYPE'} =~ /^(1|2|3|4)$/)
 {
-       print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>";
-       print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>";   
-}  
-print <<END;
-       </tr>
-       </table>
-END
+print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_in MB</b></td>";
+print "<td align='center' class='boldbase' nowrap='nowrap'><b>$total_red_out MB</b></td>";
+}
+print "</tr></table>";
 
 &Header::closebox();
-
 &Header::closebigbox();
-
 &Header::closepage();