#!/usr/bin/perl

###########################################################################
#
# BRICKreporter 
# written by Andreas Fatum, fatum@acelab.net
# (c) 1999
#
###########################################################################

use Socket;

for (my $i = 0; $i <= 32; $i++) 
   {
     $dotMaskBits{join('.',unpack('C4',pack("N",(2**32-(2**(32-$i))))))} = $i;
   }

$startzeit = (times)[0];

$MY_LOGFILE_NAME = "/var/log/brickreporter.log";
$actualversion = "v1.22";
$anzahlacctzeilen = "0";
$dnszaehler = "0";
$dnsmisses = "0";

&parseCommandline();
  
open (MYLOGFILE, ">> $MY_LOGFILE_NAME") or die "Error. Cannot create/append my logfile /var/log/brickreporter.log\n";
$lokalzeit = `date +"%d.%m.%Y %X"`;
chomp $lokalzeit;
printf MYLOGFILE "BRICKreporter is starting the accounting-process at %s\n", $lokalzeit;

&parseConfig();
&parseLogfile();
&checkForHits();

if (($CFG_OUTPUT_FORMAT eq "HTML") || ($CFG_OUTPUT_FORMAT eq "BOTH"))
  {
	$HTML="JEPP";
  }
if (($CFG_OUTPUT_FORMAT eq "TEXT") || ($CFG_OUTPUT_FORMAT eq "BOTH"))
  {
	$TEXT="JEPP";
  }

&ausgabe (%accS);
&ausgabe (%accD);
&ausgabe (%accSI);
&ausgabe (%accDI);

$endzeit = (times)[0];

printf MYLOGFILE "%s accounting records analyzed\n", $anzahlacctzeilen;
printf MYLOGFILE "%s records matched date and filters\n", $matchedacctzeilen;
if ($countDropped > 0) 
{
  printf MYLOGFILE "%s records have been dropped from accounting by your filter.\n", $countDropped;
}
printf MYLOGFILE "All traffic reports generated with\n";
printf MYLOGFILE "output-format %s in %s output-level.\n", $CFG_OUTPUT_FORMAT, $CFG_OUTPUT_LEVEL;
if ($dnszaehler > 0) 
{
printf MYLOGFILE "%s addresses have been looked up, %s could not be resolved\n", $dnszaehler, $dnsmisses;
}
printf MYLOGFILE "BRICKreporter has finished accounting and took %.2f sec. CPU-time.\n", $endzeit - $startzeit;
&endLog;

exit;

sub parseCommandline 
{
if (! $ARGV[0]) 
  { 
     die "No logfile to analyze. Usage: brickreporter [options] logfile\nUse brickreporter -? for help\n"; 
  }

foreach $comlineargs (@ARGV)
  {  
     $argzaehler++;
     if (($comlineargs eq "-?") || ($comlineargs eq "--help"))
       { &showUsage; }
     elsif (($comlineargs eq "-v") || ($comlineargs eq "--version"))
       { print "BRICKreporter is version ", $actualversion, "\n"; exit; }
     elsif (($comlineargs eq "-l") || ($comlineargs eq "--level"))
       {
	 $parameter = splice (@ARGV, $argzaehler, 1); 
         if ((! $parameter) || (!$parameter =~ (/-|--/)))
	   {
	      die "Option -l|--level requires an argument\n"; 
           }
	 elsif ($parameter =~ (/^compact$|^short$|^long$/i))
	   {
	      $CFG_OUTPUT_LEVEL = uc($parameter);
	   }
	 else 
           { 
              die "Allowed arguments for -l|-level are: COMPACT, SHORT or LONG\n";
	   }
       }
     elsif (($comlineargs eq "-f") || ($comlineargs eq "--format"))
       { 
	 $parameter = splice (@ARGV, $argzaehler, 1); 
         if ((! $parameter) || (!$parameter =~ (/-|--/)))
	   {
	      die "Option -f|--format requires an argument\n"; 
           }
	 elsif ($parameter =~ (/^text$|^html$|^both$/i))
	   {
	      $CFG_OUTPUT_FORMAT = uc($parameter);
	   }
	 else 
           { 
              die "Allowed arguments for -f|--format are: TEXT, HTML or BOTH\n";
	   }
        }
     elsif (($comlineargs eq "-d") || ($comlineargs eq "--date"))
       { 
	 $parameter = splice (@ARGV, $argzaehler, 1); 
         if ((! $parameter) || (!$parameter =~ (/-|--/)))
	   {
	      die "Option -d|--date requires an argument\n"; 
           }
	 elsif (($parameter =~ m,^(\d\d\.\d\d\.\d\d\d\d)$,) || ($parameter =~ m,^(\d\d\.\d\d\d\d)$,))
	   {
	      $CFG_DATE = $parameter;
	   }
	 else 
           { 
              die "Allowed arguments for -d|--date are: DD.MM.YYYY or MM.YYYY\n";
	   }
        }
      elsif (($comlineargs eq "-c") || ($comlineargs eq "--config-file"))
       { 
	 $parameter = splice (@ARGV, $argzaehler, 1); 
         if ((! $parameter) || (!$parameter =~ (/-|--/)))
	   {
	      die "Option -c|--config-file requires an argument\n"; 
           }
	 else
	   {
	      $configfile = $parameter;
	   }
       }
     elsif ($comlineargs =~ (/^-|^--/))
	{
	  die "Unknown option: $comlineargs. Use brickreporter -? for usage\n";
	}
     elsif (! $comlineargs)
       {
         die "No logfile to analyze. Usage: brickreporter [options] logfile\nUse brickreporter -? for help\n"; 
       }
     else
       {
	   $logfile = $comlineargs;
       }
  }

if (! $logfile)
  {
         die "No logfile to analyze. Usage: brickreporter [options] logfile\nUse brickreporter -? for help\n"; 
  } 
else
  {
     undef @ARGV;
     $ARGV[0]=$logfile;
  } 

if (! $configfile)
  {
     $configfile="\/etc\/brickreporter.conf";
  }
}

sub showUsage
{
	print "\n";
	print "BRICKreporter analyzes the ip-accounting-messages in a Brick syslog-file and\n";
	print "generates various traffic reports. See brickreporter.conf and brickreporter(1)\n";
	print "\n";
	print "Usage: brickreporter [options] LOGFILE\n";
	print "\n";
	print "Options:\n";
	print "  -c, --config-file=CONFIG       use config-file CONFIG\n";
	print "  -l, --level=long|short|compact set output-level\n";
	print "  -f, --format=text|html|both    set output-format\n";
	print "  -d, --date=DD.MM.YYYY|MM.YYYY  set date to analyze\n";
	print "  -v, --version                  print version number, then exit\n";
	print "  -?, --help                     print this help, then exit\n";
	print "\n";
	print "LOGFILE is the name of the syslog-file you want to be analyzed\n";
	print "\n";
	print "Example:\n";
	print "brickreporter -c my.conf -l short -f html /var/log/bricklog-0199\n";
	print "\n";
	print "Report bugs to <brickreporter-bugs\@acelab.net>\n";
	print "\n";
	print "(c)1999 acelab\n";
	print "\n";
	exit;
}

sub parseConfig
{
  open (CFGFILE, "< $configfile") or $noconfigfile="1";

  if ($noconfigfile) 
    {
      print MYLOGFILE "Warning: Can't open config-file $configfile, using defaults...\n";
      if (! $CFG_OUTPUT_FORMAT) { $CFG_OUTPUT_FORMAT = "TEXT"; }
      if (! $CFG_OUTPUT_LEVEL) { $CFG_OUTPUT_LEVEL = "COMPACT"; }
      $CFG_OUTPUT_TEXT_FILENAME = "./brickreporter.txt";
      $CFG_OUTPUT_HTML_FILENAME = "./brickreporter.html";
      $CFG_RESOLVE_SRC_IP = "NO";
      $CFG_RESOLVE_DEST_IP = "NO";
    }
  else
    {
      while (<CFGFILE>)
        {
	  chomp;		
	  s/#.*//;		
	  s/^\s+//;		
	  s/\s+$//;		
	  next unless length;	
	  my ($variablen, $werte) = split (/\s*=\s*/, $_, 2);
	  $config{$variablen} = $werte;
        }

       $CFG_NETS_ACC = ($config{"NETS_TO_ACCOUNT"});
       $CFG_NETS_DROP = ($config{"NETS_TO_DROP"});
       if ($CFG_NETS_DROP)
	 {
	    @netsToDrop = split (/\s*,\s*/,$CFG_NETS_DROP);
	 }
       else
	 {
	    $nothingToDrop=1;
	 }

       if ($CFG_NETS_ACC)
	 {
	    @netsToAccount = split (/\s*,\s*/,$CFG_NETS_ACC);
	 }
       else
         {
	    print MYLOGFILE "No NETS_TO_ACCOUNT specified so there is no work to do.\n";
	    &endLog;
	    die "Sorry, but without any NETS_TO_ACCOUNT there is no work to do.\n";
	 }

      if (! $CFG_DATE)
      {
       $CFG_D_D = ($config{"ACC_DATE_DAY"});
       if ($CFG_D_D)
	 {
            if ($CFG_D_D < 10)
	      { 
		$CFG_D_D = "0" . $CFG_D_D; 
	      }
	    $CFG_D_D .= ".";
         }
       
       $CFG_D_M = ($config{"ACC_DATE_MONTH"});
       if ($CFG_D_M)
	 {
	     if ($CFG_D_M < 10)
               { 	
		  $CFG_D_M = "0" . $CFG_D_M; 
	       }
	     $CFG_D_M .= ".";
	 }

       $CFG_D_Y = ($config{"ACC_DATE_YEAR"});
       $CFG_DATE=$CFG_D_D . $CFG_D_M . $CFG_D_Y;
      }

       $CFG_BRICK_NAME = ($config{"BRICK_NAME"});
       if ($CFG_BRICK_NAME eq undef)
	 {
	    print MYLOGFILE "Warning: No BRICK_NAME defined. I will use any accounting information found in the logfile.\n";
	    print MYLOGFILE "         This might probably mix up your statistics. You have been warned\n";
	 }

     if (! $CFG_OUTPUT_FORMAT)
      {
       $CFG_OUTPUT_FORMAT = uc($config{"OUTPUT_FORMAT"}); 
       if ($CFG_OUTPUT_FORMAT)
         {
            if (($CFG_OUTPUT_FORMAT ne "TEXT") && ($CFG_OUTPUT_FORMAT ne "HTML") && ($CFG_OUTPUT_FORMAT ne "BOTH")) 
              { 
                print MYLOGFILE "Warning: Illegal option for OUTPUT_FORMAT. Defaulting to TEXT\n";
	        $CFG_OUTPUT_FORMAT = "TEXT";
	      }
         }
       else
	 {
            print MYLOGFILE "Warning: No OUTPUT_FORMAT defined. Defaulting to TEXT\n";
	    $CFG_OUTPUT_FORMAT = "TEXT";
	 }
       }
      
       if (! $CFG_OUTPUT_LEVEL)
	{ 
       	   $CFG_OUTPUT_LEVEL = uc($config{"OUTPUT_LEVEL"}); 
           if ($CFG_OUTPUT_LEVEL)
             {
                if (($CFG_OUTPUT_LEVEL ne "SHORT") && ($CFG_OUTPUT_LEVEL ne "LONG") && ($CFG_OUTPUT_LEVEL ne "COMPACT")) 
                  { 
                    print MYLOGFILE "Warning: Illegal option for OUTPUT_LEVEL. Defaulting to COMPACT\n";
	            $CFG_OUTPUT_LEVEL = "COMPACT";
	          }
             }
           else
	     {
                print MYLOGFILE "Warning: No OUTPUT_LEVEL defined. Defaulting to COMPACT\n";
	        $CFG_OUTPUT_LEVEL = "COMPACT";
	     }
        }

	$CFG_PROZENT = $config{"SERVICES_WATERMARK"};
	if ($CFG_PROZENT eq undef)
	  {
       	     print MYLOGFILE "Warning: SERVICES_WATERMARK not set. Defaulting to 0.5\n"; 
             $CFG_PROZENT = "0.5";
	  }
	if (($CFG_PROZENT<0) || ($CFG_PROZENT>100))
	  {
       	     print MYLOGFILE "Warning: Illegal value for SERVICES_WATERMARK defined. Setting it to 0.5\n"; 
             $CFG_PROZENT = "0.5";
	  }

       $CFG_OUTPUT_TEXT_FILENAME = $config{"OUTPUT_TEXT_FILENAME"};
       if ((($CFG_OUTPUT_FORMAT eq "TEXT") || ($CFG_OUTPUT_FORMAT eq "BOTH")) && ($CFG_OUTPUT_TEXT_FILENAME eq undef))
         {
	    if ($CFG_DATE eq undef)
              {
       	         print MYLOGFILE "No OUTPUT_TEXT_FILENAME defined. Defaulting to ./brickreporter.txt\n"; 
	         $CFG_OUTPUT_TEXT_FILENAME = "./brickreporter.txt";
	      }
 	    else
	      {
       	         print MYLOGFILE "No OUTPUT_TEXT_FILENAME defined. Defaulting to ./brickreporter-", $CFG_DATE, ".txt\n"; 
	         $DummyNameText = "./brickreporter-" . $CFG_DATE . ".txt";
	         $CFG_OUTPUT_TEXT_FILENAME = $DummyNameText;
              }
         }

       $CFG_OUTPUT_HTML_FILENAME = $config{"OUTPUT_HTML_FILENAME"};
       if ((($CFG_OUTPUT_FORMAT eq "HTML") || ($CFG_OUTPUT_FORMAT eq "BOTH")) && ($CFG_OUTPUT_HTML_FILENAME eq undef))
	{         
	    if ($CFG_DATE eq undef)
              {
       	    	 print MYLOGFILE "No OUTPUT_HTML_FILENAME defined. Defaulting to ./brickreporter.html\n"; 
	    	 $CFG_OUTPUT_HTML_FILENAME = "./brickreporter.html";
	      }
 	    else
	      {
       	         print MYLOGFILE "No OUTPUT_HTML_FILENAME defined. Defaulting to ./brickreporter-", $CFG_DATE, ".html\n"; 
	         $DummyNameHtml = "./brickreporter-" . $CFG_DATE . ".html";
	         $CFG_OUTPUT_HTML_FILENAME = $DummyNameHtml;
              }
         }

       $CFG_RESOLVE_SRC_IP = uc($config{"RESOLVE_SRC_IP"});
       if ($CFG_RESOLVE_SRC_IP)
         {
           if (($CFG_RESOLVE_SRC_IP ne "YES") && ($CFG_RESOLVE_SRC_IP ne "NO")) 
             { 
                print MYLOGFILE "Warning: Illegal option for RESOLVE_SRC_IP. Defaulting to NO\n";
	        $CFG_RESOLVE_SRC_IP = "NO";
	     }
         }
       else
	 {
                print MYLOGFILE "Warning: No RESOLVE_SRC_IP defined. Defaulting to NO\n";
	        $CFG_RESOLVE_SRC_IP = "NO";
	 }

       $CFG_RESOLVE_DEST_IP = uc($config{"RESOLVE_DEST_IP"});
       if ($CFG_RESOLVE_DEST_IP)
         {
           if (($CFG_RESOLVE_DEST_IP ne "YES") && ($CFG_RESOLVE_DEST_IP ne "NO")) 
             { 
               print MYLOGFILE "Warning: Illegal option for RESOLVE_DEST_IP. Defaulting to NO\n";
	       $CFG_RESOLVE_DEST_IP = "NO";
	     }
         }
       else
	 {
                print MYLOGFILE "Warning: No RESOLVE_DEST_IP defined. Defaulting to NO\n";
	        $CFG_RESOLVE_DEST_IP = "NO";
	 }
    }
}

sub parseLogfile
{
  
ZEILELESEN:
  while (<>) 
   {
    if (/ACCT: INET:/)
    {
     if (/${CFG_BRICK_NAME}/)
      {
	$anzahlacctzeilen+=1;
    	$zeile=$_;
    	chomp $zeile;
    	@felder = split(/ +/, $zeile);
	if ($CFG_DATE)
	  {
	     if (! ($felder[6] =~ /${CFG_DATE}/))
	       {
                  next ZEILELESEN; 
	       }
          }

        ($src_ip, $src_port, $src_if)=split(/:|\//, $felder[10]);
        ($dest_ip, $dest_port, $dest_if)=split(/:|\//,$felder[12]);
        $connectionsumme=$felder[14] + $felder[16];

	if (! $nothingToDrop) 
	  {
           $aktSrc=unpack("N", pack("C4", split(/\./, $src_ip)));
           $aktDest=unpack("N", pack("C4", split(/\./, $dest_ip)));
           foreach $filter (@netsToDrop)
            {
              if ($filter =~ m,^(\d+\.\d+\.\d+\.\d+)/(\d+)$,) 
                {
                   $netz = $1;
                   $bits = $2;
                }
             elsif ($filter =~ m,^(\d+\.\d+\.\d+\.\d+):(\d+\.\d+\.\d+\.\d+)$,) 
                {
                   $netz = $1;
                   $bits = $dotMaskBits{$2}; 
                }
	     else
                { 
	      		print MYLOGFILE "Error: Incorrect syntax/value for NETS_TO_DROP. Exiting.\n";
	      		&endLog;
                        die "Error: Incorrect syntax/value for NETS_TO_DROP. Exiting.\n";
		}
             $intNetz = unpack("N", pack("C4", split(/\./, $netz)));
             $intNetz &= (2**32-(2**(32-$bits)));
             if ((($aktSrc>=$intNetz) && ($aktSrc<($intNetz+2**(32-$bits))))
              || (($aktDest>=$intNetz) && ($aktDest<($intNetz+2**(32-$bits)))))
               {
		   $countDropped++;
		   next ZEILELESEN;
	       }
             }	
           }	
        $mindestensEiner="Stimmt";    
        $matchedacctzeilen++;	      

	if ($src_if eq "0") { $src_if = "0 (BRICK)"; }
	if ($dest_if eq "0") { $dest_if = "0 (BRICK)"; }
	if ($src_port eq "20") { $dest_port = "21"; }
	if ($dest_port eq "20") { $dest_port = "21"; }
	if ($src_port eq "119") { $dest_port = "119"; }

        $eintrag={
		SRCIP=>$src_ip,
		SRCIF=>$src_if,
		DESTIP=>$dest_ip,
		DESTIF=>$dest_if,
		DIENST=>$dest_port,
		BYTES=>$connectionsumme
              };
     $aktSrc=unpack("N", pack("C4", split(/\./, $eintrag->{SRCIP})));
     $aktDest=unpack("N", pack("C4", split(/\./, $eintrag->{DESTIP})));
     foreach $filter (@netsToAccount)
       {
         if ($filter =~ m,^(\d+\.\d+\.\d+\.\d+)/(\d+)$,) 
           {
             $netz = $1;
             $bits = $2;
           }
         elsif ($filter =~ m,^(\d+\.\d+\.\d+\.\d+):(\d+\.\d+\.\d+\.\d+)$,) 
           {
             $netz = $1;
             $bits = $dotMaskBits{$2}; 
           }
	 else
	   {
		print "FehlerFilter: ->", $filter, "<-\n"; 
		print "Netz: ", $netz, "\n"; 
		print "Bits: ", $bits, "\n"; 
	      print MYLOGFILE "Error: Incorrect syntax/value for NETS_TO_ACCOUNT. Exiting.\n";
	      &endLog;
	      die "Error: Incorrect syntax/value for NETS_TO_ACCOUNT. Exiting.\n";
	   }
	      
         $intNetz = unpack("N", pack("C4", split(/\./, $netz)));
         $intNetz &= (2**32-(2**(32-$bits)));
         if (($aktSrc >= $intNetz) && ($aktSrc < ($intNetz+2**(32-$bits))))
         {
	  %accS->{$eintrag->{SRCIP}}->{$eintrag->{DESTIP}} +=$eintrag->{BYTES}; 
	  %accS->{$eintrag->{SRCIP}}->{"SUMME"} += $eintrag->{BYTES};
	  %accS->{"SUMME"}->{"GESAMT"} += $eintrag->{BYTES};
	  %accS->{"SUMME"}->{$eintrag->{DIENST}} += $eintrag->{BYTES};
	  %accD->{$eintrag->{DESTIP}}->{$eintrag->{SRCIP}} +=$eintrag->{BYTES}; 
	  %accD->{$eintrag->{DESTIP}}->{"SUMME"} += $eintrag->{BYTES};
	  %accD->{"SUMME"}->{"GESAMT"} += $eintrag->{BYTES};
	  %accD->{"SUMME"}->{$eintrag->{DIENST}} += $eintrag->{BYTES};
	  %accSI->{$eintrag->{SRCIF}}->{$eintrag->{DESTIF}}+=$eintrag->{BYTES}; 
	  %accSI->{$eintrag->{SRCIF}}->{"SUMME"} += $eintrag->{BYTES};
	  %accSI->{"SUMME"}->{"GESAMT"} += $eintrag->{BYTES};
	  %accSI->{"SUMME"}->{$eintrag->{DIENST}} += $eintrag->{BYTES};
	  %accDI->{$eintrag->{DESTIF}}->{$eintrag->{SRCIF}}+=$eintrag->{BYTES}; 
	  %accDI->{$eintrag->{DESTIF}}->{"SUMME"} += $eintrag->{BYTES};
	  %accDI->{"SUMME"}->{"GESAMT"} += $eintrag->{BYTES};
	  %accDI->{"SUMME"}->{$eintrag->{DIENST}} += $eintrag->{BYTES};
         }
        elsif (($aktDest >= $intNetz) && ($aktDest < ($intNetz+2**(32-$bits))))
         {
	  %accS->{$eintrag->{DESTIP}}->{$eintrag->{SRCIP}} +=$eintrag->{BYTES}; 
	  %accS->{$eintrag->{DESTIP}}->{"SUMME"} += $eintrag->{BYTES};
	  %accS->{"SUMME"}->{"GESAMT"} += $eintrag->{BYTES};
	  %accS->{"SUMME"}->{$eintrag->{DIENST}} += $eintrag->{BYTES};
	  %accD->{$eintrag->{SRCIP}}->{$eintrag->{DESTIP}} +=$eintrag->{BYTES}; 
	  %accD->{$eintrag->{SRCIP}}->{"SUMME"} += $eintrag->{BYTES};
	  %accD->{"SUMME"}->{"GESAMT"} += $eintrag->{BYTES};
	  %accD->{"SUMME"}->{$eintrag->{DIENST}} += $eintrag->{BYTES};
	  %accSI->{$eintrag->{DESTIF}}->{$eintrag->{SRCIF}}+=$eintrag->{BYTES}; 
	  %accSI->{$eintrag->{DESTIF}}->{"SUMME"} += $eintrag->{BYTES};
	  %accSI->{"SUMME"}->{"GESAMT"} += $eintrag->{BYTES};
	  %accSI->{"SUMME"}->{$eintrag->{DIENST}} += $eintrag->{BYTES};
	  %accDI->{$eintrag->{SRCIF}}->{$eintrag->{DESTIF}}+=$eintrag->{BYTES}; 
	  %accDI->{$eintrag->{SRCIF}}->{"SUMME"} += $eintrag->{BYTES};
	  %accDI->{"SUMME"}->{"GESAMT"} += $eintrag->{BYTES};
	  %accDI->{"SUMME"}->{$eintrag->{DIENST}} += $eintrag->{BYTES};
         }
       }
     }
   }
 }
}

sub checkForHits
{
  if ($mindestensEiner eq undef)
    {
	print MYLOGFILE "Sorry but your logfile does not contain any accounting information. Exiting.\n";
	&endLog;
	die "Sorry, but the logfile doesn't contain any accounting information\n";
    }
}

sub ausgabe 
{
  undef $sonstiges;
  undef %srcBytesListe;
  undef %mytraf;
  undef %mytopten;
  %mytraf = @_;
  $thisIsRun += 1;
  $strich = "==========================================================================================";
  $bre="<DIV ALIGN=\"RIGHT\">";
  $ere="</DIV>";

       if ($thisIsRun eq "1")
         {
	   if ($TEXT)
           {
       	    if (! open (TXTOUTFILE, "> $CFG_OUTPUT_TEXT_FILENAME"))
              {
		print MYLOGFILE "Could not open txt-output file for writing. Not enough rights? Exiting.\n";
		&endLog;
              	die "Couldn't open text-output-file for writing. Not enough rights? Exiting...\n";
	      }
            }
  
            if ($HTML)
            {
	      if (! open (HTMOUTFILE, "> $CFG_OUTPUT_HTML_FILENAME"))
               {
		print MYLOGFILE "Could not open html-output file for writing. Not enough rights? Exiting.\n";
		&endLog;
		die "Couldn't open html-output-file for writing. Not enough rights? Exiting...\n";
	       }
  	      print HTMOUTFILE "<HTML>\n";
	      print HTMOUTFILE "<HEAD>\n";
	      print HTMOUTFILE "<meta name=\"Author\" content=\"acelab (c) 1999\">\n";
	      print HTMOUTFILE "<meta name=\"GENERATOR\" content=\"BRICKreporter by acelab\">\n";
	      print HTMOUTFILE "<TITLE>BRICKreporter IP-Accounting</TITLE>\n";
	      print HTMOUTFILE "</HEAD>\n";
  	      print HTMOUTFILE"<BODY>\n";
  	      print HTMOUTFILE"<a href=\"http://www.acelab.net/brickreporter\"><img src=\"http://www.acelab.net/brickreporter/br-logo.jpg\" align=\"left\" border=\"0\"></a><br>\n";
             }
      		
            if ($CFG_BRICK_NAME eq undef)
              { 
		 if ($CFG_DATE)
		   { 
                     if ($TEXT)
                       {
		        $fueller = $CFG_DATE . " created " . $lokalzeit;
		        $breite = length($fueller);
       	         	print TXTOUTFILE "\n BRICKreporter traffic analysis for $CFG_DATE created $lokalzeit\n";  
       	         	printf TXTOUTFILE " ===================================%${breite}s\n", substr($strich,1,$breite);  
                       }
		     if ($HTML)
		       {
			 print HTMOUTFILE "<H3><center>BRICKreporter traffic analysis for $CFG_DATE created $lokalzeit</center></H3>\n<br><br>\n";
	       	         print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; 
       	                 print HTMOUTFILE "<TABLE>\n";  
		       }
		   }
		 else
		   {
		     if ($TEXT)
		       {
		        $fueller = " created " . $lokalzeit;
		        $breite = length($fueller);
       	         	print TXTOUTFILE "\n BRICKreporter traffic analysis created $lokalzeit\n";  
       	         	printf TXTOUTFILE " ==============================%${breite}s\n", substr($strich,1,$breite);  
		       }
		     if ($HTML)
		       {
			 print HTMOUTFILE "<H3><center>BRICKreporter traffic analysis created $lokalzeit</center></H3>\n<br><br>\n";
	       	         print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; 
       	                 print HTMOUTFILE "<TABLE>\n";  
		       }
		   }
	      }
            else
	      {
		 if ($CFG_DATE)
		   {
		      if ($TEXT)
			{
		          $breite = (length($CFG_DATE) + length($CFG_BRICK_NAME) + length(" created ") + length($lokalzeit));
       	                  print TXTOUTFILE "\n BRICKreporter traffic analysis for system $CFG_BRICK_NAME for $CFG_DATE created $lokalzeit\n";  
       	                  printf TXTOUTFILE " ===============================================%${breite}s\n", substr($strich,1,$breite); 
			}
		      if ($HTML)
			{
       	                  print HTMOUTFILE "<H3><center>BRICKreporter traffic analysis for system $CFG_BRICK_NAME for $CFG_DATE created $lokalzeit</center></H3>\n<br><br>\n";  
	       	          print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; 
       	                  print HTMOUTFILE "<TABLE>\n";  
			}
		   }
		 else
		   {
		     if ($TEXT)
		       {
			 $breite = length($CFG_BRICK_NAME) + length(" created ") + length($lokalzeit);
       	                 print TXTOUTFILE "\n BRICKreporter traffic analysis for system $CFG_BRICK_NAME created $lokalzeit\n";  
       	                 printf TXTOUTFILE " ==========================================%${breite}s\n", substr($strich,1,$breite);  
                         print TXTOUTFILE "\n\n";
		       }
		     if ($HTML)
		       {
       	                 print HTMOUTFILE "<H3><center>BRICKreporter traffic analysis for system $CFG_BRICK_NAME created $lokalzeit</center></H3>\n<br><br>\n";  
	       	         print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; 
       	                 print HTMOUTFILE "<TABLE>\n";  
		       }
		   }
	      }
	  } 

	if (($thisIsRun eq "1") && ($CFG_OUTPUT_LEVEL eq "LONG"))
	 {
	   if ($TEXT)
	    {
              print TXTOUTFILE " Traffic by source to destination address (detailed):\n";
              print TXTOUTFILE " ====================================================\n";
	    }
	   if ($HTML)
	    {
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Traffic by source to destination address (detailed):</b></center></TD></TR>\n";
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"></TD></TR>\n";
	    }
          }
	if (($thisIsRun eq "2") && ($CFG_OUTPUT_LEVEL eq "LONG"))
 	  {
	   if ($TEXT)
	    {
               print TXTOUTFILE "\n\n###########################################################################\n\n\n";
               print TXTOUTFILE " Traffic by destination to source address (detailed):\n";
               print TXTOUTFILE " ====================================================\n";
	    }
	   if ($HTML)
	    {
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; 
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Traffic by destination to source address (detailed):</b></center></TD></TR>\n";
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"></TD></TR>\n";
	    }
          }
	if (($thisIsRun eq "3") && ($CFG_OUTPUT_LEVEL eq "LONG"))
 	  {
	   if ($TEXT)
	    {
               print TXTOUTFILE "\n\n###########################################################################\n\n\n";
               print TXTOUTFILE " Traffic by source to destination interface (detailed):\n";
               print TXTOUTFILE " ======================================================\n";
	    }
	   if ($HTML)
	    { 
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; 
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Traffic by source to destination interface (detailed):</b></center></TD></TR>\n";
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"></TD></TR>\n";
	    }
          }
	if (($thisIsRun eq "4") && ($CFG_OUTPUT_LEVEL eq "LONG"))
 	  {
	   if ($TEXT)
	    {
               print TXTOUTFILE "\n\n###########################################################################\n\n\n";
               print TXTOUTFILE " Traffic by destination to source interface (detailed):\n";
               print TXTOUTFILE " ======================================================\n";
	    }
	   if ($HTML)
	    {
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; 
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Traffic by destination to source interface (detailed):</b></center></TD></TR>\n";
	      print HTMOUTFILE "<TR><TD COLSPAN=\"4\"></TD></TR>\n";
	    }
          }
       foreach $tmp (sort keys %mytraf)
        {
          if ($tmp ne "SUMME")
            {
	      if ($CFG_OUTPUT_LEVEL ne "COMPACT")
              { 
	       if ((($CFG_RESOLVE_SRC_IP eq "YES") && ($thisIsRun eq "1")) || 
                      (($CFG_RESOLVE_DEST_IP eq "YES") && ($thisIsRun eq "2")))
                 {
		   if ($src_name = gethostbyaddr(inet_aton($tmp), 2)) 
                     {
		         $dnszaehler++; 
		     }
		   else {
                 	   $src_name = $tmp;
			   $dnsmisses++;
			}
                 }
	       else
		{
		   $src_name = $tmp;  
		}
              }
	       $mysubtotal=$mytraf{$tmp}->{"SUMME"}; 
               $mytopten{$mysubtotal} .= $tmp . ",";
	       if ($CFG_OUTPUT_LEVEL eq "LONG")
		{
	       	   $formzahl = reverse $mytraf{$tmp}->{"SUMME"};
	       	   $formzahl =~ s/(\d\d\d)(?=\d)/$1./g;
	       	   $formnorm = reverse $formzahl;
		   if ($TEXT) {
	       	   printf TXTOUTFILE "\n%30s  -->      Subtotal : %15s Bytes\n", substr($src_name,0,29), $formnorm; }
		   if ($HTML) {
	       	   print HTMOUTFILE "<TR><TD></TD><TD></TD><TD></TD></TR>\n";
		   printf HTMOUTFILE "<TR><TD>$bre %s $ere</TD><TD>$bre Subtotal : $ere</TD><TD>$bre %s Bytes $ere</TD></TR>\n", $src_name, $formnorm; }
		}
	
               foreach $tmptmp (sort keys %{$mytraf{$tmp}})
                 {
		    if (($tmptmp ne "SUMME") && ($CFG_OUTPUT_LEVEL eq "LONG"))
		      {
	                 if ((($CFG_RESOLVE_DEST_IP eq "YES") && ($thisIsRun eq "1")) || 
                                (($CFG_RESOLVE_SRC_IP eq "YES") && ($thisIsRun eq "2")))
               	           {
		             if ($dest_name = gethostbyaddr(inet_aton($tmptmp), 2)) 
				{
		                   $dnszaehler++; 
				}
		             else {
                 	             $dest_name = $tmptmp;
			             $dnsmisses++;
			          }
               	           }
                         else
                           {
		   	      $dest_name = $tmptmp;  
                           }
			 $formzahl = reverse $mytraf{$tmp}->{$tmptmp};
			 $formzahl =~ s/(\d\d\d)(?=\d)/$1./g;
			 $formnorm = reverse $formzahl;
			 if ($TEXT) {
                         printf TXTOUTFILE "                   %30s : %15s Bytes\n", substr($dest_name,0,29), $formnorm; }
			 if ($HTML) {
                         printf HTMOUTFILE "<TR><TD></TD><TD>$bre %s : $ere</TD><TD>$bre %s Bytes $ere</TD></TR>\n", $dest_name, $formnorm; }
		      }
		    else 
		     {
			$srcBytesListe{$tmp} = $mytraf{$tmp}->{$tmptmp};
		     }
                 }
	    }
	  else 
	    {
	       if ($CFG_OUTPUT_LEVEL eq "LONG")
		 {
	           $formzahl = reverse $mytraf{"SUMME"}->{"GESAMT"};
	       	   $formzahl =~ s/(\d\d\d)(?=\d)/$1./g;
	           $formnorm = reverse $formzahl;
		   if ($TEXT) {
                   printf TXTOUTFILE "\n                                       GRANDTOTAL : %15s Bytes\n", $formnorm;
	           print TXTOUTFILE "\n---------------------------------------------------------------------------\n\n"; }
		   if ($HTML) {
	       	   print HTMOUTFILE "<TR><TD></TD><TD></TD><TD></TD></TR>\n";
                   printf HTMOUTFILE "<TR><TD></TD><TD>$bre<b>GRANDTOTAL :</b>$ere</TD><TD>$bre<b>%15s Bytes</b>$ere</TD></TR>\n", $formnorm; 
	       	   print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; }
	         }
	       
	       if (($thisIsRun eq "1") && ($CFG_OUTPUT_LEVEL ne "COMPACT"))
                 {
		   if ($TEXT) {
	       	     print TXTOUTFILE " Traffic by source address (cumulated):\n";
	             print TXTOUTFILE " ======================================\n\n"; }
		   if ($HTML) {
	             print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Traffic by source address (cumulated):</b></center></TD></TR>\n";
	             print HTMOUTFILE "<TR><TD COLSPAN=\"4\"></TD></TR>\n"; }
                 }

	       if (($thisIsRun eq "2") && ($CFG_OUTPUT_LEVEL ne "COMPACT"))
                 {
	            if ($CFG_OUTPUT_LEVEL eq "SHORT")
                      {
			if ($TEXT) {
                          print TXTOUTFILE "\n---------------------------------------------------------------------------\n\n"; }
			if ($HTML) {
	                  print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><hr></TD></TR>\n"; }
		      }
		    if ($TEXT) {
	       	       print TXTOUTFILE " Traffic by destination address (cumulated):\n";
	               print TXTOUTFILE " ===========================================\n\n"; }
		   if ($HTML) {
	             print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Traffic by destination address (cumulated):</b></center></TD></TR>\n";
	             print HTMOUTFILE "<TR><TD COLSPAN=\"4\"></TD></TR>\n"; }
                 }

	       if (($thisIsRun eq "3") && ($CFG_OUTPUT_LEVEL ne "COMPACT"))
                 {
	            if ($CFG_OUTPUT_LEVEL eq "SHORT")
                      {
			if ($TEXT) {
                          print TXTOUTFILE "\n---------------------------------------------------------------------------\n\n"; }
			if ($HTML) {
	                  print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><hr></TD></TR>\n"; }
		      }
		    if ($TEXT) {
	       	      print TXTOUTFILE " Traffic by source interface (cumulated):\n";
	              print TXTOUTFILE " ========================================\n\n"; }
		   if ($HTML) {
	             print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Traffic by source interface (cumulated):</b></center></TD></TR>\n";
	             print HTMOUTFILE "<TR><TD COLSPAN=\"4\"></TD></TR>\n"; }
                 }

	       if (($thisIsRun eq "4") && ($CFG_OUTPUT_LEVEL ne "COMPACT"))
                 {
	            if ($CFG_OUTPUT_LEVEL eq "SHORT")
                      {
			if ($TEXT) {
                          print TXTOUTFILE "\n---------------------------------------------------------------------------\n\n"; }
			if ($HTML) {
	                  print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><hr></TD></TR>\n"; }
		      }
		    if ($TEXT) {
	       	      print TXTOUTFILE " Traffic by destination interface (cumulated):\n";
	              print TXTOUTFILE " =============================================\n\n"; }
		   if ($HTML) {
	             print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Traffic by destination interface (cumulated):</b></center></TD></TR>\n";
	             print HTMOUTFILE "<TR><TD COLSPAN=\"4\"></TD></TR>\n"; }
                 }

	       foreach $listenelement (sort keys %srcBytesListe)
		 {
	           $formzahl = reverse $srcBytesListe{$listenelement};
	           $formzahl =~ s/(\d\d\d)(?=\d)/$1./g;
	           $formnorm = reverse $formzahl;
		   $protz = 100 / $mytraf{"SUMME"}->{"GESAMT"} * $srcBytesListe{$listenelement};
		  if ($CFG_OUTPUT_LEVEL ne "COMPACT")
                  {
	           if ((($CFG_RESOLVE_SRC_IP eq "YES") && ($thisIsRun eq "1")) || 
                          (($CFG_RESOLVE_DEST_IP eq "YES") && ($thisIsRun eq "2")))
                     {
       		        if ($traffName = gethostbyaddr(inet_aton($listenelement), 2)) 
			  {
				$dnszaehler++;
			  }
			else
			  {
              		      $traffName = $listenelement;
			      $dnsmisses++;
			  }
               	     }
                    else
                     {
		         $traffName = $listenelement;  
		     }
		   if ($TEXT) {
		     printf TXTOUTFILE "%30s : %15s Bytes (%6.2f\%)\n", substr($traffName,0,29), $formnorm, $protz; }
		   if ($HTML) { 
                     printf HTMOUTFILE "<TR><TD>$bre %s : $ere</TD><TD>$bre %s Bytes $ere</TD><TD>$bre (%6.2f\%) $ere</TD></TR>\n", $traffName, $formnorm, $protz; }
		   }
		 }
	       $formzahl = reverse $mytraf{"SUMME"}->{"GESAMT"};
	       $formzahl =~ s/(\d\d\d)(?=\d)/$1./g;
	       $formnorm = reverse $formzahl;
	       if ($CFG_OUTPUT_LEVEL ne "COMPACT")
	       {
	        if ($TEXT) 
                 {
	         printf TXTOUTFILE "                    GRANDTOTAL : %15s Bytes (100.00\%)\n", $formnorm;
	         print TXTOUTFILE "\n---------------------------------------------------------------------------\n\n";
		 }
	       if ($HTML) 
                 {
                  printf HTMOUTFILE "<TR><TD>$bre <b>GRANDTOTAL :</b> $ere</TD><TD>$bre <b> %s Bytes </b> $ere</TD><TD>$bre<b>(100.00\%)</b>$ere</TD></TR>\n", $formnorm; 
	       	  print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; 
	         }
	       }

	      if ($thisIsRun eq "1")
               {
		 if ($TEXT) {
	            print TXTOUTFILE " Traffic by service:\n";
	            print TXTOUTFILE " ===================\n\n";
                   }
		 if ($HTML) {
	       	   print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Traffic by service:</b></center></TD></TR>\n"; 
                  }
               foreach $tmptmp (sort keys %{$mytraf{$tmp}})
                 {
		    $bgs = $mytraf{"SUMME"}->{"GESAMT"};
		    if ($tmptmp ne "GESAMT")
		      {
			$formzahl = reverse $mytraf{$tmp}->{$tmptmp};
	                $formzahl =~ s/(\d\d\d)(?=\d)/$1./g;
			$formnorm = reverse $formzahl;
			$prozent = 100 / $bgs * $mytraf{$tmp}->{$tmptmp};
			if ($prozent >= $CFG_PROZENT)
			  {
				$afservice = getservbyport($tmptmp, "tcp") or
				$afservice = getservbyport($tmptmp, "udp") or
				$afservice = $tmptmp; 
				if ($TEXT) {
				printf TXTOUTFILE "%10s : %15s Bytes (%6.2f\%)\n", uc($afservice), $formnorm, $prozent; }
				if ($HTML) {
				printf HTMOUTFILE "<TR><TD>$bre %s : $ere</TD><TD>$bre %s Bytes $ere</TD><TD>$bre (%6.2f\%) $ere</TD></TR>\n", uc($afservice), $formnorm, $prozent; }
			  }
			else
			  {
				$sonstiges += $mytraf{$tmp}->{$tmptmp};
			  }
		      }
		    else 
		     {
			$formzahl = reverse $sonstiges;
	                $formzahl =~ s/(\d\d\d)(?=\d)/$1./g;
			$formnorm = reverse $formzahl;
			if ($TEXT) {
			  if ($sonstiges > 0) {
			  printf TXTOUTFILE "      MISC : %15s Bytes (%6.2f\%)\n", $formnorm, 100/$bgs*$sonstiges; }
			  print TXTOUTFILE  " ----------------------------------------\n";
			}
			if (($HTML) && ($sonstiges > 0)) {
			    printf HTMOUTFILE "<TR><TD>$bre MISC : $ere</TD><TD>$bre %s Bytes $ere</TD><TD>$bre (%6.2f\%) $ere</TD></TR>\n", $formnorm, 100/$bgs*$sonstiges; } 
			$formzahl = reverse $bgs;
	                $formzahl =~ s/(\d\d\d)(?=\d)/$1./g;
			$formnorm = reverse $formzahl;
			if ($TEXT) {
			  printf TXTOUTFILE "     TOTAL : %15s Bytes (100.00\%)\n", $formnorm; }
			if ($HTML) {
			  printf HTMOUTFILE "<TR><TD>$bre <b> TOTAL : </b> $ere</TD><TD>$bre <b> %s Bytes </b> $ere</TD><TD>$bre <b> (100.00\%) </b> $ere</TD></TR>\n", $formnorm; 
	       	          print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; }
		     }
		 } 
	       } 
	    }
        }

       if (($thisIsRun eq "1") || ($thisIsRun eq "2") || 
		($thisIsRun eq "3") || ($thisIsRun eq "4"))
         {
	    if ($TEXT) 
	      {
	        print TXTOUTFILE "\n---------------------------------------------------------------------------\n\n";
		if ($thisIsRun eq "1") {
	        print TXTOUTFILE " Top-Ten traffic by source address:\n"; 
	        print TXTOUTFILE " ==================================\n\n"; }
		if ($thisIsRun eq "2") {
	        print TXTOUTFILE " Top-Ten traffic by destination address:\n"; 
	        print TXTOUTFILE " =======================================\n\n"; }
		if ($thisIsRun eq "3") {
	        print TXTOUTFILE " Top-Ten traffic by source interface:\n"; 
	        print TXTOUTFILE " ====================================\n\n"; }
		if ($thisIsRun eq "4") {
	        print TXTOUTFILE " Top-Ten traffic by destination interface:\n"; 
	        print TXTOUTFILE " =========================================\n\n"; }
	      }
	    if ($HTML)
	      {
	       	print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; 
		if ($thisIsRun eq "1") {
	        print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Top-Ten traffic by source address:</b></center></TD></TR>\n"; }
		if ($thisIsRun eq "2") {
	        print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Top-Ten traffic by destination address:</b></center></TD></TR>\n"; }
		if ($thisIsRun eq "3") {
	        print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Top-Ten traffic by source interface:</b></center></TD></TR>\n"; }
		if ($thisIsRun eq "4") {
	        print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><center><b>Top-Ten traffic by destination interface:</b></center></TD></TR>\n"; }
	      }
		undef $zaehler;
		undef @multidest;
		$traffGesamt = $mytraf{"SUMME"}->{"GESAMT"};
                foreach $topten (sort { $b <=> $a } keys %mytopten)
  		  {	
     		    if ($zaehler++ > 9) { last; };
		    $topzahl = reverse ($topten);
	            $topzahl =~ s/(\d\d\d)(?=\d)/$1./g;
		    $topnorm = reverse $topzahl;
	 	    @multidest = split (/,+/,$mytopten{$topten});

	            if ((($CFG_RESOLVE_SRC_IP eq "YES") && ($thisIsRun eq "1")) || 
                          (($CFG_RESOLVE_DEST_IP eq "YES") && ($thisIsRun eq "2")))
                     {
       		        if ($traffName = gethostbyaddr(inet_aton($multidest[0]), 2))
			  {
				$dnszaehler++;
			  }
			else
			  {
				$dnsmisses++;
              		        $traffName = $multidest[0];
			  }
               	     }
                    else
                     {
		         $traffName = $multidest[0];  
		     }
		     $protz = 100 / $traffGesamt * $topten;

		    if ($TEXT) {
     		      printf TXTOUTFILE "%2s.: %30s : %15s Bytes (%6.2f\%)\n", $zaehler, $traffName, $topnorm, $protz; }
		    if ($HTML) {
		      printf HTMOUTFILE "<TR><TD>$bre %s.: $ere</TD><TD>$bre %s $ere</TD><TD>$bre %s Bytes $ere</TD><TD>$bre (%6.2f\%) $ere</TD></TR>\n", $zaehler, $traffName, $topnorm, $protz; }
		    if (scalar(@multidest) > 1)
		      {
		        for ($mf = 1; $mf <= (scalar(@multidest)-2); $mf++)
		           {
	                      if ((($CFG_RESOLVE_SRC_IP eq "YES") && ($thisIsRun eq "1")) || 
                                    (($CFG_RESOLVE_DEST_IP eq "YES") && ($thisIsRun eq "2")))
                                {
       		                  if ($traffName = gethostbyaddr(inet_aton($multidest[$mf]), 2))
				    {
					$dnszaehler++;
				    }
				  else
				    {
              		           	$traffName = $multidest[$mf];
					$dnsmisses++;
				    }
               	                }
                              else
                                {
		                   $traffName = $multidest[$mf];  
			        }
			   if ($TEXT) {
			     printf TXTOUTFILE "     %30s : %15s Bytes (%6.2f\%)\n", $traffName, $topnorm, $protz; }
			     if ($HTML) {
		               printf HTMOUTFILE "<TR><TD></TD><TD>$bre %s $ere</TD><TD>$bre %s Bytes (%6.2f\%) $ere</TD></TR>\n", $traffName, $topnorm, $protz; }
			   }
		      }
	 	  }
		if ($HTML) {
	       	print HTMOUTFILE "<TR><TD COLSPAN=\"4\"><HR></TD></TR>\n"; }
         }

       if ($thisIsRun eq "4")
         {
	    if ($TEXT)
	      {
		 print TXTOUTFILE "\n\n-------------------------------------------\n";
		 print TXTOUTFILE "End of the BRICKreporter accounting reports\n\n";
                 close (TXTOUTFILE);
	      }
            if ($HTML)
              {
		  print HTMOUTFILE "<TR><TD COLSPAN=\"3\"></TD></TR>\n";
		  print HTMOUTFILE "<TR><TD COLSPAN=\"3\">End of the BRICKreporter accounting reports</TD></TR>\n";
  	          print HTMOUTFILE "</TABLE>\n";
  	          print HTMOUTFILE "</BODY>\n</HTML>\n";
	          close (HTMOUTFILE);
	      }
	 }
}

sub endLog
{
  $lokalzeit = `date +"%d.%m.%Y %X"`;
  chomp $lokalzeit;
  printf MYLOGFILE "BRICKreporter has ended the accounting-process at %s\n", $lokalzeit;
  print MYLOGFILE "-------------------------------------------------------------------------------\n";
  close (MYLOGFILE);
}

#--------------------------
#
# End of BRICKreporter
#
#--------------------------

