Revision: 5565
          http://ipcop.svn.sourceforge.net/ipcop/?rev=5565&view=rev
Author:   owes
Date:     2011-03-26 07:00:12 +0000 (Sat, 26 Mar 2011)

Log Message:
-----------
Apply coding style changes.

Modified Paths:
--------------
    ipcop/trunk/src/libs/traffic-lib.pl

Modified: ipcop/trunk/src/libs/traffic-lib.pl
===================================================================
--- ipcop/trunk/src/libs/traffic-lib.pl 2011-03-26 06:50:49 UTC (rev 5564)
+++ ipcop/trunk/src/libs/traffic-lib.pl 2011-03-26 07:00:12 UTC (rev 5565)
@@ -49,9 +49,9 @@
 
 
 @TRAFFIC::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'} );
+    $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'} );
 
 @TRAFFIC::months = ( 0,1,2,3,4,5,6,7,8,9,10,11 );
 
@@ -60,8 +60,7 @@
 my @now = localtime(time);
 $now[5] = $now[5]+1900;
 
-for(my $year = 2001; $year<=($now[5]+2); $year++)
-{
+for (my $year = 2001; $year<=($now[5]+2); $year++) {
     push(@TRAFFIC::years, $year);
 }
 
@@ -93,7 +92,7 @@
 
 sub readSettings
 {
-       &General::readhash($TRAFFIC::settingsfile, \%TRAFFIC::settings);
+    &General::readhash($TRAFFIC::settingsfile, \%TRAFFIC::settings);
 }
 
 sub getDeviceNames
@@ -101,10 +100,8 @@
     my $devices = shift;
     my $interfaces = shift;
 
-    foreach my $name (keys %{$interfaces})
-    {
-        if($interfaces->{$name}{'ID'} ne '')
-        {
+    foreach my $name (keys %{$interfaces}) {
+        if ($interfaces->{$name}{'ID'} ne '') {
             $devices->{$interfaces->{$name}{'ID'}} = $name;
         }
     }
@@ -122,18 +119,18 @@
 {
     my $calc = shift;
 
-       $calc->{'CALC_VOLUME_TOTAL'} = 0;
-       $calc->{'CALC_VOLUME_IN'} = 0;
-       $calc->{'CALC_VOLUME_OUT'} = 0;
-       $calc->{'CALC_WEEK_TOTAL'} = 0;
-       $calc->{'CALC_WEEK_IN'} = 0;
-       $calc->{'CALC_WEEK_OUT'} = 0;
-       $calc->{'CALC_LAST_RUN'} = 0;
-       $calc->{'CALC_PERCENT_TOTAL'} = 0;
-       $calc->{'CALC_PERCENT_IN'} = 0;
-       $calc->{'CALC_PERCENT_OUT'} = 0;
+    $calc->{'CALC_VOLUME_TOTAL'} = 0;
+    $calc->{'CALC_VOLUME_IN'} = 0;
+    $calc->{'CALC_VOLUME_OUT'} = 0;
+    $calc->{'CALC_WEEK_TOTAL'} = 0;
+    $calc->{'CALC_WEEK_IN'} = 0;
+    $calc->{'CALC_WEEK_OUT'} = 0;
+    $calc->{'CALC_LAST_RUN'} = 0;
+    $calc->{'CALC_PERCENT_TOTAL'} = 0;
+    $calc->{'CALC_PERCENT_IN'} = 0;
+    $calc->{'CALC_PERCENT_OUT'} = 0;
 
-       &General::readhash($TRAFFIC::logfile, \%{$calc}) if(-e 
$TRAFFIC::logfile);
+    &General::readhash($TRAFFIC::logfile, \%{$calc}) if(-e $TRAFFIC::logfile);
 }
 
 
@@ -147,14 +144,14 @@
     $calc->{'CALC_WEEK_TOTAL'} = 0;
     $calc->{'CALC_WEEK_IN'} = 0;
     $calc->{'CALC_WEEK_OUT'} = 0;
-       $calc->{'CALC_PERCENT_TOTAL'} = 0;
-       $calc->{'CALC_PERCENT_IN'} = 0;
-       $calc->{'CALC_PERCENT_OUT'} = 0;
+    $calc->{'CALC_PERCENT_TOTAL'} = 0;
+    $calc->{'CALC_PERCENT_IN'} = 0;
+    $calc->{'CALC_PERCENT_OUT'} = 0;
 
-my $endtime   = &getEndtimeNow();
-#print "end: '$endtime'<br />";
+    my $endtime   = &getEndtimeNow();
+    #print "end: '$endtime'<br />";
 
-my $dbh = DBI->connect("dbi:SQLite:dbname=/var/log/traffic/aggregate.db", "", 
"", {RaiseError => 1});
+    my $dbh = DBI->connect("dbi:SQLite:dbname=/var/log/traffic/aggregate.db", 
"", "", {RaiseError => 1});
 eval {
     my $select = "SELECT oob_prefix, SUM(ip_totlen) ";
     $select .= " FROM daily ";
@@ -170,13 +167,12 @@
     # this month
     my $starttime = &getStarttimeMonth($TRAFFIC::settings{'PERIOD_TYPE'});
     $sthSelect->execute($starttime);
-    while($sthSelect->fetch())
-    {
+    while ($sthSelect->fetch()) {
         $calc->{'CALC_VOLUME_TOTAL'} += $bytes;
-        if($prefix =~/_IN/) {
+        if ($prefix =~/_IN/) {
             $calc->{'CALC_VOLUME_IN'} += $bytes;
         }
-        elsif($prefix =~/_OUT/) {
+        elsif ($prefix =~/_OUT/) {
             $calc->{'CALC_VOLUME_OUT'} += $bytes;
         }
     }
@@ -185,7 +181,7 @@
 
     # this week
     # We start on Monday, not on sunday
-    if($now[6] == 0) {
+    if ($now[6] == 0) {
         # it is sunday
         $now[6] = 6;
     }
@@ -204,8 +200,7 @@
 
     $starttime = "$weekStart[5]$startMonth$startDay";
     $sthSelect->execute($starttime);
-    while($sthSelect->fetch())
-    {
+    while ($sthSelect->fetch()) {
         $calc->{'CALC_WEEK_TOTAL'} += $bytes;
         if($prefix =~/_IN/) {
             $calc->{'CALC_WEEK_IN'} += $bytes;
@@ -218,9 +213,9 @@
 
     $sthSelect->finish();
 };
-if ($@) {
-    warn "Transaction aborted because $@";
-}
+    if ($@) {
+        warn "Transaction aborted because $@";
+    }
 
     $calc->{'CALC_VOLUME_TOTAL'} = sprintf("%.2f", 
($calc->{'CALC_VOLUME_TOTAL'}/1048576));
     $calc->{'CALC_VOLUME_IN'} = sprintf("%.2f", 
($calc->{'CALC_VOLUME_IN'}/1048576));
@@ -265,7 +260,7 @@
 
     my $starttime = '';
 
-    if($periodType eq 'rollingWindow') {
+    if ($periodType eq 'rollingWindow') {
         my @rollingStart = localtime( time() - 
(($TRAFFIC::settings{'ROLLING_WINDOW'} - 1) * 86400));
         $rollingStart[5] += 1900;
         my $startMonth = $rollingStart[4] + 1;
@@ -285,9 +280,8 @@
 
         my $startDay = 1;
 
-        if($TRAFFIC::settings{'MONITOR_TRAFFIC_ENABLED'} eq 'on')
-        {
-                $startDay = $TRAFFIC::settings{'STARTDAY'};
+        if ($TRAFFIC::settings{'MONITOR_TRAFFIC_ENABLED'} eq 'on') {
+            $startDay = $TRAFFIC::settings{'STARTDAY'};
         }
 
         # this periode started last month
@@ -318,7 +312,7 @@
     my $displayMode = shift;
     my $devices = shift;
 
-my $dbh = DBI->connect("dbi:SQLite:dbname=/var/log/traffic/aggregate.db", "", 
"", {RaiseError => 1});
+    my $dbh = DBI->connect("dbi:SQLite:dbname=/var/log/traffic/aggregate.db", 
"", "", {RaiseError => 1});
 eval {
     my $select = "SELECT date, oob_prefix, SUM(ip_totlen) ";
     $select .= " FROM daily ";
@@ -327,8 +321,7 @@
 
     my $isFirst = 1;
     # TODO: may some errorhandling in case of no devices
-    foreach my $device (keys %{$devices})
-    {
+    foreach my $device (keys %{$devices}) {
         if($isFirst) {
             $isFirst = 0;
         }
@@ -345,9 +338,9 @@
     ###
     # DEBUG
     ###
-     if ($TRAFFIC::debugFormparams == 1) {
+    if ($TRAFFIC::debugFormparams == 1) {
        print "DEBUG: $select<br />\n";
-   }
+    }
 
     my $sthSelect = $dbh->prepare($select);
     my $date = 0;
@@ -356,8 +349,7 @@
     $sthSelect->bind_columns(\$date, \$prefix, \$bytes);
 
     $sthSelect->execute();
-    while($sthSelect->fetch())
-    {
+    while ($sthSelect->fetch()) {
         $date =~ /(\d\d\d\d)(\d\d)(\d\d)/;
         my $displayDate = "$1-$2-$3";
 
@@ -366,18 +358,15 @@
             $date = "$1$2";
         }
 
-        if(!defined($allDaysBytes->{$date}))
-        {
+        if (!defined($allDaysBytes->{$date})) {
             $allDaysBytes->{$date} = ();
             $allDaysBytes->{$date}{'Day'} = $displayDate;
-
         }
 
         $prefix =~ /^(\w+_\d+)_.*(IN|OUT)/;
         my $rule = $1."_".$2;
 
-        if(!defined($allDaysBytes->{$date}{$rule}))
-        {
+        if (!defined($allDaysBytes->{$date}{$rule})) {
             $allDaysBytes->{$date}{$rule} = 0;
         }
 
@@ -386,56 +375,50 @@
 
     $sthSelect->finish();
 };
-if ($@) {
-    warn "Transaction aborted because $@";
-}
+    if ($@) {
+        warn "Transaction aborted because $@";
+    }
 
-$dbh->disconnect() or warn $dbh->errstr;
-
+    $dbh->disconnect() or warn $dbh->errstr;
 }
 
 
 
 sub traffPercentbar
 {
-       my $percent = $_[0];
-       my $fg = '#a0a0a0';
-       my $bg = '#e2e2e2';
+    my $percent = $_[0];
+    my $fg = '#a0a0a0';
+    my $bg = '#e2e2e2';
 
-       if ($percent =~ m/^(\d+)%$/ )
-       {
-               print <<END;
-                       <table width='100%' border='1' cellspacing='0' 
cellpadding='0' 
style='border-width:1px;border-style:solid;border-color:$fg;width:100%;height:10px;'>
-                       <tr>
+    unless ($percent =~ m/^(\d+)%$/) {
+        return;
+    }
+
+    print <<END;
+<table width='100%' border='1' cellspacing='0' cellpadding='0' 
style='border-width:1px;border-style:solid;border-color:$fg;width:100%;height:10px;'>
+<tr>
 END
 
-               if ($percent eq "100%" || $1 > 100)
-               {
-                       $fg = $TRAFFIC::colorMax;
-                       print "<td width='100%' bgcolor='$fg' 
style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
-               }
-               elsif ($percent eq "0%")
-               {
-                       print "<td width='100%' bgcolor='$bg' 
style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
-               }
-               else
-               {
-                       if($TRAFFIC::settings{'WARN_ENABLED'} eq 'on'
-                               && $1 >= $TRAFFIC::settings{'WARN'})
-                       {
-                               $fg = $TRAFFIC::colorWarn;
-                       }
+    if ($percent eq "100%" || $1 > 100) {
+        $fg = $TRAFFIC::colorMax;
+        print "<td width='100%' bgcolor='$fg' 
style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'>"
+    }
+    elsif ($percent eq "0%") {
+        print "<td width='100%' bgcolor='$bg' 
style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
+    }
+    else {
+        if ($TRAFFIC::settings{'WARN_ENABLED'} eq 'on' && $1 >= 
$TRAFFIC::settings{'WARN'}) {
+            $fg = $TRAFFIC::colorWarn;
+        }
 
-                       print "<td width='$percent' bgcolor='$fg' 
style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'></td><td
 width='" . (100-$1) . "%' bgcolor='$bg' 
style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
-               }
-               print <<END;
-                                       <img src='/images/null.gif' width='1' 
height='1' alt='' />
-                               </td>
-                       </tr>
-                       </table>
+        print "<td width='$percent' bgcolor='$fg' 
style='background-color:$fg;border-style:solid;border-width:1px;border-color:$bg'></td><td
 width='" . (100-$1) . "%' bgcolor='$bg' 
style='background-color:$bg;border-style:solid;border-width:1px;border-color:$bg'>"
+    }
+    print <<END;
+        <img src='/images/null.gif' width='1' height='1' alt='' />
+    </td>
+</tr>
+</table>
 END
-
-       }
 }
 
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Enable your software for Intel(R) Active Management Technology to meet the
growing manageability and security demands of your customers. Businesses
are taking advantage of Intel(R) vPro (TM) technology - will your software 
be a part of the solution? Download the Intel(R) Manageability Checker 
today! http://p.sf.net/sfu/intel-dev2devmar
_______________________________________________
Ipcop-svn mailing list
Ipcop-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ipcop-svn

Reply via email to