#!/usr/bin/perl ############################################################################## # This is under GNU GPL licences # # Copyright (C) 2001 Ismail YENIGUL(yenigul@itu.edu.tr,yenigul@rt.net.tr) # ismail@enderunix.org # 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 2 of the License, or # (at your option) any later version, and provided that the above # copyright and permission notice is included with all distributed # copies of this or derived software. # # 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, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA # # http://www.enderunix.org/isoqlog # # this version has modifications by R Hutchinson, hutch@midwales.com # mostly cleanup of html ############################################################################## $c = scalar(@ARGV); if($c<1) { print "\n\n Usage : perl isoqlog.pl isoqlog.conf \n\n"; exit; } require $ARGV[0]; require $langfile; if($logformat eq "splogger" ) { $logformat = "syslog"; } #$Debug = 1; # 0 for no output $my = @mydomains; $mydomains[$my] = "General"; $maxdomainin = $maxincoming; $maxdomainout = $maxoutgoing; $maxdomaintotal = $maxtotal; $maxdomainbyte = $maxbyte; $maxdomain_userin = $maxincoming; $maxdomain_userout = $maxoutgoing; $maxdomain_usertotal = $maxtotal; $maxdomain_userbyte = $maxbyte; $maxuserin = $maxincoming; $maxuserout = $maxoutgoing; $maxusertotal = $maxtotal; $maxuserbyte = $maxbyte; $from = "from"; $no_mailbox = "_no_mailbox_here_by_that_name"; $not_find_hostname = "find_any_host_by_that_name"; $failed_smtp_connection = "I_wasn't_able_to_establish_an_SMTP_connection"; $RELAY = "invalid RELAY client"; $CNAME_lookup = "CNAME_lookup_failed_temporarily"; $unable_Maildir = "Unable_to_open_./Maildir:_is_a_directory"; $Unable_to_chdir_to_maildir = "Unable_to_chdir_to_maildir"; $RELAYcounter = 0; #Relaying Error Counter $no_mailbox_counter = 0; #no mailbox error counter $no_hostname = 0; #No hostname Error counter $failed_smtp_counter = 0; #Failed to SMTP counter $CNAME_lookup_counter = 0; $unable_Maildir_counter = 0; $Unable_to_chdir_to_maildir_counter = 0; ###############DO NOT CHANGE FOLLOWINT VALUES ######################### $start = "starting delivery"; #variable to determine outgoing in syslog #################VARIABLES IS END HERE!################################# #It is time to start :)) #I am using OpenFile Function to open files #$logfile="/var/log/syslog"; @tosba = @mydomains; @kefal = @mydomains; # Getting Date From Syslog print "OK I am starting ! \n\n" if($Debug); print "Your Logformat $logformat \n" if($Debug); if($logformat eq "syslog") { GetDateFromSyslog(); GetInfoFromSyslog(); } else { GetDateFromMultilog(); GetInfoFromMultilog(); } print "Creating Directories\n" if($Debug); # Create Folder Mkdir ("$isoqlogdir"); #Mkdir ("$isoqlogdir/General"); #Mkdir ("$isoqlogdir/General/$ThisYear"); foreach (@mydomains){ $Domaindir = "$isoqlogdir/$_"; Mkdir("$Domaindir"); Mkdir("$Domaindir/$ThisYear"); } # Create Folder ends print "Creating Directories done\n\n" if($Debug); # From To and Bytes #DOMAINS PART IS PROCESSING print " Working on all domains for getting (incoming mail , outgoing mail ,total mail , mail byte ) values \n" if($Debug); foreach $key ( sort keys %AllDomains) { if(defined($AllDomains{$key}->[0]) ) { $FromDomains{$key} = $AllDomains{$key}->[0]; } if(defined($AllDomains{$key}->[1]) ) { $ToDomains{$key} = $AllDomains{$key}->[1]; } if(defined($AllDomains{$key}->[2]) ) { $ByteDomains{$key} = $AllDomains{$key}->[2]; } if(defined($AllDomains{$key}->[0]) || defined($AllDomains{$key}->[1])) { $FromAndToDomains{$key} = $AllDomains{$key}->[0] + $AllDomains{$key}->[1]; } #uf end } #foreach is end #Sorting Domains to get TOP scores $TotalIncoming = 0; $TotalOutgoing = 0; $TotalBytes = 0; foreach $key (sort keys %AllDomains) { $TotalIncoming += $AllDomains{$key}->[0]; $TotalOutgoing += $AllDomains{$key}->[1]; $TotalBytes += $AllDomains{$key}->[2]; } $TotalMails = $TotalIncoming + $TotalOutgoing; print " Sorting domains according to (incoming mail , outgoing mail , total mail and mail byte) values \n" if($Debug); ## we create totals file now i will fetch it # above i define Total valuse so i do not write anything to domains file ... @SortedFromDomains = sort { $FromDomains{$b} <=> $FromDomains{$a} } keys %FromDomains; @SortedFromAndToDomains = sort { $FromAndToDomains{$b} <=> $FromAndToDomains{$a} } keys %FromAndToDomains; @SortedToDomains = sort { $ToDomains{$b} <=> $ToDomains{$a} } keys %ToDomains; @SortedByteDomains = sort { $ByteDomains{$b} <=> $ByteDomains{$a} } keys %ByteDomains; print "All Domains Sorted \n" if($Debug); $FromDomainsNumber = @SortedFromDomains; $ToDomainsNumber = @SortedToDomains; $ByteDomainsNumber = @SortedByteDomains; $FromAndToDomainsNumber = @SortedFromAndToDomains; #we are checking maxvalues in files #if it is less then max values that user defined . i am replacing user defined values with in files if($FromAndToDomainsNumber < $maxdomaintotal ){ $maxdomaintotal = $FromAndToDomainsNumber; } if($ToDomainsNumber < $maxdomainin ){ $maxdomainin = $ToDomainsNumber; } if($FromDomainsNumber < $maxdomainout ){ $maxdomainout = $FromDomainsNumber; } if($ByteDomainsNumber < $maxdomainbyte ){ $maxdomainbyte = $ByteDomainsNumber; } #ALL USERS VALUES print " Working on all user emails for getting (incoming , outgoing,byte) values \n" if($Debug); foreach $key ( sort keys %AllUsers) { if(defined($AllUsers{$key}->[0])) { $FromUsers{$key} = $AllUsers{$key}->[0]; } if(defined($AllUsers{$key}->[1])) { $ToUsers{$key} = $AllUsers{$key}->[1]; } if(defined($AllUsers{$key}->[2]) ) { $ByteUsers{$key} = $AllUsers{$key}->[2]; } $FromAndToUsers{$key} = $AllUsers{$key}->[0] + $AllUsers{$key}->[1]; } #foreach is end print " Sorting all users according to (incoming mail , outgoing mail m total and byte) values \n" if($Debug); @SortedFromUsers = sort { $FromUsers{$b} <=> $FromUsers{$a} } keys %FromUsers; @SortedToUsers = sort { $ToUsers{$b} <=> $ToUsers{$a} } keys %ToUsers; @SortedByteUsers = sort { $ByteUsers{$b} <=> $ByteUsers{$a} } keys %ByteUsers; @SortedFromAndToUsers = sort { $FromAndToUsers{$b} <=> $FromAndToUsers{$a} } keys %FromAndToUsers; print "All Users Sorted \n" if($Debug); $FromUsersNumber = @SortedFromUsers; $ToUsersNumber = @SortedToUsers; $ByteUsersNumber = @SortedByteUsers; $FromAndToUsersNumber = @SortedFromAndToUsers; if($FromAndToUsersNumber < $maxusertotal){ $maxdomain_usertotal = $FromAndToUsersNumber; } if($ToUsersNumber < $maxuserin){ $maxdomain_userin = $ToUsersNumber; } if($FromUsersNumber < $maxuserout){ $maxdomain_userout = $FromUsersNumber; } if($ByteUsersNumber < $maxuserbyte){ $maxdomain_userbyte=$ByteUserssNumber; } # we will determining Totalincoming mail ,OutGoing Number and Bytes; ####################Total's end########################3 #it is time to creat MonthFile foreach(@mydomains){ $ThisMonthFile = "$isoqlogdir/$_/$ThisYear/$ThisMonth"; $DomainName = $_; $AllMonthFile = "$isoqlogdir/$_/AllMonths"; MonthFile("$ThisMonthFile","$DomainName"); AllMonthsFile("$AllMonthFile","$DomainName"); } ## we will find $mydomains users incoming outgoing mail and mail bytes foreach $domainname (@tosba){ foreach $key (sort keys %AllUsers) { $userdomain = $AllUsers{$key}->[3]; if($domainname eq $userdomain or $domainname eq "General") { $FromMyDomainUsers{$key} = $AllUsers{$key}->[0]; $FromAndToMyDomainUsers{$key} = $AllUsers{$key}->[0] + $AllUsers{$key}->[1]; $ToMyDomainUsers{$key} = $AllUsers{$key}->[1]; $ByteMyDomainUsers{$key} = $AllUsers{$key}->[2]; } #if end } #for each #key .... end # we will sort users according to incoming putgoing total mail number and bytes @SortedFromAndToMyDomainUsers = sort { $FromAndToMyDomainUsers{$b} <=> $FromAndToMyDomainUsers{$a} } keys %FromAndToUsers; @SortedFromMyDomainUsers = sort { $FromMyDomainUsers{$b} <=> $FromMyDomainUsers{$a} } keys %FromMyDomainUsers; @SortedToMyDomainUsers = sort { $ToMyDomainUsers{$b} <=> $ToMyDomainUsers{$a} } keys %ToMyDomainUsers; @SortedByteMyDomainUsers = sort { $ByteMyDomainUsers{$b} <=> $ByteMyDomainUsers{$a} } keys %ByteMyDomainUsers; $SortedFromAndToMyDomainUsersNumber = @SortedFromAndToMyDomainUsers; $SortedFromUsersNumber = @SortedFromMyDomainUsers; $SortedToUsersNumber = @SortedToMyDomainUsers; $SortedByteUsersNumber = @SortedByteMyDomainUsers; # we are setting our max user values if the values in log file is smaller than user defined max values if($SortedFromAndToMyDomainUsersNumber < $maxusertotal){ $maxusertotal = $SortedFromAndToMyDomainUsersNumber; } if($SortedFromUsersNumber < $maxuserin){ $maxuserin = $SortedFromUsersNumber; } if($SortedToUsersNumber < $maxuserout){ $maxuserout = $SortedToUsersNumber; } if($SortedByteUsersNumber < $maxuserbyte){ $maxuserbyte = $SortedByteUsersNumber; } #$maxuserbyte=MaxorMin("$SortedByteUsersNumber","$maxuserbyte"); #########write to file ################# print "Writing $isoqlogdir/$domainname/FromUsers\n" if($Debug); OpenFile ("FromUsers",">","$isoqlogdir/$domainname/FromUsers"); for ($i=0;$i<$maxuserout; $i++) { if(defined($FromMyDomainUsers{$SortedFromMyDomainUsers[$i]})) { print FromUsers "$SortedFromMyDomainUsers[$i]:$FromMyDomainUsers{$SortedFromMyDomainUsers[$i]}\n"; } #if defined end } #for end close(FromUsers); print "Writing $isoqlogdir/$domainname/ToUsers\n" if($Debug); OpenFile("ToUsers",">","$isoqlogdir/$domainname/ToUsers"); for ($i=0;$i<$maxuserin; $i++) { if(defined($ToMyDomainUsers{$SortedToMyDomainUsers[$i]})) { print ToUsers "$SortedToMyDomainUsers[$i]:$ToMyDomainUsers{$SortedToMyDomainUsers[$i]}\n"; } #if defined end } #for end close(ToUsers); print "Writing file $isoqlogdir/$domainname/TotalUsers\n" if($Debug); OpenFile ("TotalUsers",">","$isoqlogdir/$domainname/TotalUsers"); for ($i=0;$i<$maxusertotal; $i++) { if(defined($FromMyDomainUsers{$SortedFromMyDomainUsers[$i]}) || defined($ToMyDomainUsers{$SortedToMyDomainUsers[$i]}) ) { print TotalUsers "$SortedFromAndToMyDomainUsers[$i]:$ToMyDomainUsers{$SortedFromAndToMyDomainUsers[$i]}:$FromMyDomainUsers{$SortedFromAndToMyDomainUsers[$i]}\n"; } # if end } # for end here close(TotalUsers); print "Writing file $isoqlogdir/$domainname/ByteUsers\n" if($Debug); OpenFile ("ByteUsers",">","$isoqlogdir/$domainname/ByteUsers"); for ($i=0;$i<$maxuserbyte; $i++) { if (defined($ByteMyDomainUsers{$SortedByteMyDomainUsers[$i]})) { print ByteUsers "$SortedByteMyDomainUsers[$i]:$ByteMyDomainUsers{$SortedByteMyDomainUsers[$i]}\n"; } } #for end close(ByteUsers); undef %FromAndToMyDomainUsers; undef %FromMyDomainUsers; undef %ToMyDomainUsers; undef %ByteMyDomainUsers; $maxuserin = $maxincoming; $maxuserout = $maxoutgoing; $maxusertotal = $maxtotal; $maxuserbyte = $maxbyte; } #foreach $domainname (@mydomains) end print "All domains done\n\n" if($Debug); print "Starting html\n" if($Debug); ########PROCESSING ON HTML OUTPUT &output_isolog_homepage(); ### we are writing domains index.html foreach $domains (@tosba){ &output_domains_indexhtml(); # foreach $domains (@kefal) { &output_daily_indexhtml(); &output_dailys_indexhtml(); # } } #big html foreach is end print "html done\n" if($Debug); print "All Done\n\n" if($Debug); exit; ########################################################## #FUNCTIONS ########################################################## #------------------------------------------------------------------# sub CommonErrors { #------------------------------------------------------------------# #print "in sub CommonErrors\n" if($Debug); $_=$_[0]; if(/$RELAY/) { #relaying denied error $RELAYcounter++; $there_are_errors++; } if(/$no_mailbox/) { #no mailbox error $no_mailbox_counter++; $there_are_errors++; } if(/$not_find_hostname/) { #not find hostname $no_hostname++; $there_are_errors++; } if(/$failed_smtp_connection/) { #failed smtp connection error $failed_smtp_counter++; $there_are_errors++; } if(/$CNAME_lookup/) { #error MX record $CNAME_lookup_counter++; $there_are_errors++; } if(/$unable_Maildir/) { #error MX record $unable_Maildir_counter++; $there_are_errors++; } if(/$Unable_to_chdir_to_maildir/) { $Unable_to_chdir_to_maildir_counter++; $there_are_errors++; } } # CommonErrors Function is end Here #------------------------------------------------------------------# sub ToDomainsAndUsers { #------------------------------------------------------------------# #print "in sub ToDomainsAndUsers\n" if($Debug); $username = $_[0]; $userdomain = $_[1]; $testuserdomain = $userdomain."-"; # i am determinig to vpopmaol user fornat if(($username cmp $testuserdomain) ==1) { #if you are using vpopmail virtual domains username format is domain-username, so we are removing domain @getdomain=split(/-/,$username); if(($getdomain[0] cmp $userdomain) == 0) { $_ = $username; $realuser = s/$testuserdomain//; $username = $_; $email = $username."\@".$userdomain; } #if getdomain cmp $... end else { $email = $username."\@".$userdomain; } #else end } else { $email = $username."\@".$userdomain; } # it is time to add domain and user value to hash array #$AllDomains{'$userdomain'}->[0] = From Mail Number #$AllDomains{'$userdomain'}->[1] =To Mail number #$AllDomains{'$userdomain'}->[2] = Bytes if (exists($AllDomains{$userdomain})) { if(defined($AllDomains{$userdomain}->[1])) { $AllDomains{$userdomain}->[1]++; } else { # first one $AllDomains{$userdomain}->[1] = 1; } # else end } #if exists end else { $AllDomains{$userdomain}->[1] = 1; } # Users TO #$AllUsers{'$email'}->[0] =From Mail number #$AllUsers{'$email'}->[1] = To Mail Number #$AllUsers{'$email'}->[2] = Bytes #$AllUsers{'$email'}->[3] = User's Domain if (exists($AllUsers{$email})) { if(defined($AllUsers{$email}->[1])) { $AllUsers{$email}->[1]++; } else { # first one $AllUsers{$email}->[1]=1; } # else end # adding to userdomain to AllUsers Hash if(!defined($AllUsers{$email}->[3])) { $AllUsers{$email}->[3]=$userdomain; } } #if exists end # if this user is not in hash else { $AllUsers{$email}->[1]=1; } } #ToDomainsAndUsers is end here #------------------------------------------------------------------# sub GetDateFromSyslog { #------------------------------------------------------------------# print "in sub GetDateFromSyslog\n" if($Debug); # we are getting date from syslog generated by sploggoer # I write this function because syslog is a bit stupid ! # if day is less then 10 it puts two space between month and day # Feb 4 .... #if day is >= 10 it puts one space such as # Feb 14 .... print "Getting date\n" if($Debug); OpenFile("GETDATE","<","$logfile"); $line = ; chomp($line); @date1 = split (/ /,$line); close(GETDATE); $ThisMonth = $date1[0]; $l = length($date1[1]); if($l == 0 ) { $ThisDay = $date1[2]; } else { $ThisDay = $date1[1]; } @testmonths = ("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"); $monthtest = 0; foreach (@testmonths) { if($_ eq $ThisMonth){ $monthtest = 1; } } if($monthtest == 0){ print "There is Problem with Month Name, \n Please check the Maillog file\n"; exit; } else { print "OK Month Name is correct\n"; } ($sec,$minute,$hour,$day,$month,$ThisYear)=localtime(time); $ThisYear += 1900; if($month == 0 && $ThisMonth eq "Oct") { $ThisYear = $ThisYear -1; } } # GetDateFromSyslog function is end here #------------------------------------------------------------------# sub OpenFile { # FILE OPEN FUNCTION #------------------------------------------------------------------# my $FileDescription = $_[0]; my $FileMode = $_[1]; my $FileName = $_[2]; open ($FileDescription,"$FileMode $FileName") or die ("$FileName could not be opened"); #opening to qmail LOGFILE } #------------------------------------------------------------------# sub FromDomainsUsersAndBytes { #------------------------------------------------------------------# #print "in sub FromDomainsUsersAndBytes\n" if($Debug); $Byte = $_[0]; $email = $_[1]; #print "First $Byte\n"; #print "First EMAIL $email\n"; $_ = $email; # we are removing < > from $result = s///; $email = $_; #print "SECOUNd EMAIL $email\n"; @domainanduser = split(/@/,$email); $userdomain = $domainanduser[1]; #print "SECOUNT DOMAIN $userdomain\n"; # it is time to add domain and user value to hash array #$AllDomains{'$userdomain'}->[0] = From Mail Number #$AllDomains{'$userdomain'}->[1] =To Mail number #$AllDomains{'$userdomain'}->[2] = Bytes if (exists($AllDomains{$userdomain})) { if(defined($AllDomains{$userdomain}->[0])) { $AllDomains{$userdomain}->[0]++; # it is defined,increment from domain counter $AllDomains{$userdomain}->[2]+=$Byte; # domain bytes # print "FROM BYTESSSS $Byte $AllDomains{$userdomain}->[2] \n"; } else { # first one $AllDomains{$userdomain}->[0]=1; $AllDomains{$userdomain}->[2]=$Byte; # print "FROM BYTESSSS 2 $Byte \n $AllDomains{$userdomain}->[2] \n"; } # else end } #if exists end else { $AllDomains{$userdomain}->[0]=1; $AllDomains{$userdomain}->[2]=$Byte; # print "FROM BYTESSSS 3 $Byte $AllDomains{$userdomain}->[2] \n"; } # we added from and bytes # Users TO #$AllUsers{'$email'}->[0] =From Mail number #$AllUsers{'$email'}->[1] = To Mail Number #$AllUsers{'$email'}->[2] = Bytes #$AllUsers{'$email'}->[3] = User's Domain if (exists($AllUsers{$email})) { if(defined($AllUsers{$email}->[0])) { $AllUsers{$email}->[0]++; $AllUsers{$email}->[2]+=$Byte; } else { # first one $AllUsers{$email}->[0]=1; $AllUsers{$email}->[2]=$Byte; } # else end if(!defined($AllUsers{$email}->[3])) { $AllUsers{$email}->[3]=$userdomain; } } #if exists end # if this user is not in hash else { $AllUsers{$email}->[0]=1; $AllUsers{$email}->[2]=$Byte; } # adding to userdomain to AllUsers Hash } #FromDomainsUsersAndBytes is end here #------------------------------------------------------------------# sub GetDateFromMultilog { #------------------------------------------------------------------# print "in sub GetDateFromMultilog\n" if($Debug); print "\tReading $logfile\n" if($Debug); OpenFile("GETDATEMULTILOG","<","$logfile"); $line=; chomp($line); @date= split (/ /,$line); close(GETDATEMULTILOG); @yearmonthday=split(/-/,$date[0]); $ThisYear=$yearmonthday[0]; $ThisDay=$yearmonthday[2]; %months= ( '01','Jan', '02','Feb', '03','Mar', '04','Apr', '05','May', '06','Jun', '07','Jul', '08','Aug', '09','Sep', '10','Oct', '11','Dec', '12','Nov',); $ThisMonth=$months{$yearmonthday[1]}; } #we are creating from and to domains lists to sort them #------------------------------------------------------------------# sub Mkdir { #------------------------------------------------------------------# $Directory=$_[0]; if(! -e $Directory){ print "$Directory does not exist, creating." if($Debug); mkdir("$Directory",755); } } #---------------- MonthFile -------------------------------------------- #------------------------------------------------------------------# sub MonthFile { #------------------------------------------------------------------# print "in sub MonthFile\n" if($Debug); my $monthfile=$_[0]; my $domain=$_[1]; if(! $FromDomains{$domain}){ $FromDomains{$domain} = 0;} if(! $ToDomains{$domain}){ $ToDomains{$domain} = 0;} if(! $ByteDomains{$domain}){ $ByteDomains{$domain} = 0;} $DomainTotal = $FromDomains{$domain} + $ToDomains{$domain}; if(! -e "$monthfile") { print "Writing $monthfile\n" if($Debug); OpenFile("THISMONTHFILE",">","$monthfile"); #print THISMONTHFILE "#Day:In:Out:Byte:Total:Allin:Allout:AllBytes:AllTotal\n"; $DomainTotal = $FromDomains{$domain} + $ToDomains{$domain}; if($domain eq "General" ) { print THISMONTHFILE "$ThisDay:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails\n"; } else { print THISMONTHFILE "$ThisDay:$FromDomains{$domain}:$ToDomains{$domain}:$ByteDomains{$domain}:$DomainTotal:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails\n"; } #print THISMONTHFILE "$ThisDay:$FromDomains{$domain}:$ToDomains{$domain}:$ByteDomains{$domain}:$DomainTotal\n"; close(THISMONTHFILE); } else { #if $thismonth file exist; Edit it #we are looking for the same day in a month , # if we find that they are sane we are replacing with newest one; # because maybe you can run this script two or more times in one day print "Editing $monthfile\n" if($Debug); OpenFile("THISMONTH","<","$monthfile"); OpenFile("THISMONTHNEW",">","$monthfile.tmp"); while($line=) { chomp($line); $_=$line; if(/^#/) { next; #if beginning of line is # ignore this line } @FileInfo=split(/:/,$line); $Fileday=$FileInfo[0]; if ($Fileday eq $ThisDay) { if($domain eq "General" ) { print THISMONTHNEW "$ThisDay:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails\n"; } else { print THISMONTHNEW "$ThisDay:$FromDomains{$domain}:$ToDomains{$domain}:$ByteDomains{$domain}:$DomainTotal:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails\n"; $DayExist=1; } # else end } #if $Fileday ... end else { # if day is not match Just add it print THISMONTHNEW "$line\n"; } } #while end close (THISMONTH); close (THISMONTHNEW); if($DayExist!=1) { print "Writing $monthfile.tmp\n" if($Debug); OpenFile("DAY_ADD",">>","$monthfile.tmp"); #print DAY_ADD "$ThisDay:$FromDomains{$domain}:$ToDomains{$domain}:$ByteDomains{$domain}:$DomainTotal\n"; if($domain eq "General" ) { print DAY_ADD "$ThisDay:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails\n"; } else { print DAY_ADD "$ThisDay:$FromDomains{$domain}:$ToDomains{$domain}:$ByteDomains{$domain}:$DomainTotal:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails\n"; } close (DAY_ADD); } # we are moving .tmp to original system("/bin/mv $monthfile.tmp $monthfile"); } #else -e exit; } # --------sub MonthFile ends---------------------------------- #------------------------------------------------------------------# sub AllMonthsFile { #------------------------------------------------------------------# print "in sub AllMonthsFile\n" if($Debug); my $allmonths=$_[0]; my $domain=$_[1]; my $thismonth="$isoqlogdir/$domain/$ThisYear/$ThisMonth"; my $averagecounter=0; my $DomainTotal=$FromDomains{$domain}+$ToDomains{$domain}; if (! -e "$allmonths"){ print "Writing $allmonths\n" if($Debug); OpenFile("ALLMONTHS",">","$allmonths"); #print ALLMONTHS "$ThisMonth:$ThisYear:$FromDomains{$domain}:$ToDomains{$domain}:$ByteDomains{$domain}:$DomainTotal:$FromDomains{$domain}:$ToDomains{$domain}:$ByteDomains{$domain}:$DomainTotal\n"; if($domain eq "General" ) { print ALLMONTHS "$ThisMonth:$ThisYear:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails\n"; } else { print ALLMONTHS "$ThisMonth:$ThisYear:$FromDomains{$domain}:$ToDomains{$domain}:$ByteDomains{$domain}:$DomainTotal:$FromDomains{$domain}:$ToDomains{$domain}:$ByteDomains{$domain}:$DomainTotal:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails\n"; } close (ALLMONTHS); } # if (! -e "$allmonths") end #if months file exist we are updating file info else { #big else! #to create daily average we are opening to thismonth file $avr_from = 0; $avr_to = 0; $avr_byte = 0; $avr_all = 0; $all_mydomainfrom = 0; $all_mydomainto = 0; $all_mydomainbyte = 0; $all_mydomain_all = 0; if($domain ne "General" ) { $allin = 0; $allout = 0; $allbyte = 0; $allall = 0; } print "Reading $thismonth\n" if($Debug); OpenFile("FOR_AVERAGE","<","$thismonth"); while($thismonthfile=) { chomp($thismonthfile); $_=$thismonthfile; if(/^#/){ next; } else { $averagecounter++; @data=split(/:/,$_); $all_mydomainfrom += $data[1]; $all_mydomainto += $data[2]; $all_mydomainbyte += $data[3]; $all_mydomain_all += $data[4]; if($domain ne "General" ) { $allin += $data[5]; $allout += $data[6]; $allbyte += $data[7]; $allall += $data[8]; } #if ne General end } #else end; } #while ended $avr_from = int ($all_mydomainfrom/$averagecounter); #incoming average; $avr_to = int ($all_mydomainto/$averagecounter); #outgoing average $avr_byte = int ($all_mydomainbyte/$averagecounter); #outgoing average $avr_all = int ($all_mydomain_all/$averagecounter);#all average print "Editing $allmonths\n" if($Debug); OpenFile("MONTHSFILE","<","$allmonths"); OpenFile("MONTHFILE_TMP",">","$allmonths.tmp"); while($_=) { chomp($_); if(/^#/) { next; } @allmonthsfile = split(/:/,$_); $filemonth = $allmonthsfile[0]; $fileyear = $allmonthsfile[1]; if ( ($filemonth eq $ThisMonth ) && ($fileyear eq $ThisYear )) { $monthexist = 1; #print MONTHFILE_TMP "$ThisMonth:$ThisYear:$avr_from:$avr_to:$avr_byte:$avr_all:$all_mydomainfrom:$all_mydomainto:$all_mydomainbyte:$all_mydomain_all\n"; # print MONTHFILE_TMP "$ThisMonth:$ThisYear:$avr_from:$avr_to:$avr_byte:$avr_all:$all_mydomainfrom:$all_mydomainto:$all_mydomainbyte:$all_mydomain_all:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails\n"; if($domain eq "General" ) { print MONTHFILE_TMP "$ThisMonth:$ThisYear:$avr_from:$avr_to:$avr_byte:$avr_all:$all_mydomainfrom:$all_mydomainto:$all_mydomainbyte:$all_mydomain_all\n"; $monthexist=1; } else { print MONTHFILE_TMP "$ThisMonth:$ThisYear:$avr_from:$avr_to:$avr_byte:$avr_all:$all_mydomainfrom:$all_mydomainto:$all_mydomainbyte:$all_mydomain_all:$allin:$allout:$allbyte:$allall\n"; $monthexist=1; } #else end } #if $filemonth and $fileyear are not our $ThisMonth and $ThisYear print it without replacing else { print MONTHFILE_TMP "$_\n"; } } #while end close (MONTHSFILE); close (MONTHFILE_TMP); if( $monthexist != 1 ) { print "Appending $allmonths.tmp\n" if($Debug); OpenFile ("APPEND",">>","$allmonths.tmp"); #print APPEND "$ThisMonth:$ThisYear:$avr_from:$avr_to:$avr_byte:$avr_all:$all_mydomainfrom:$all_mydomainto:$all_mydomainbyte:$all_mydomain_all\n"; # print APPEND "$ThisMonth:$ThisYear:$avr_from:$avr_to:$avr_byte:$avr_all:$all_mydomainfrom:$all_mydomainto:$all_mydomainbyte:$all_mydomain_all:$TotalIncoming:$TotalOutgoing:$TotalBytes:$TotalMails\n"; if($domain eq "General" ) { print APPEND "$ThisMonth:$ThisYear:$avr_from:$avr_to:$avr_byte:$avr_all:$all_mydomainfrom:$all_mydomainto:$all_mydomainbyte:$all_mydomain_all\n"; } else { print APPEND "$ThisMonth:$ThisYear:$avr_from:$avr_to:$avr_byte:$avr_all:$all_mydomainfrom:$all_mydomainto:$all_mydomainbyte:$all_mydomain_all:$allin:$allout:$allbyte:$allall\n"; } close (APPEND); } system("/bin/mv $allmonths.tmp $allmonths"); } #big else end }#function end hre ###HTML FUNCTIONS ########################## #------------------------------------------------------------------# sub IndexPart1 { #------------------------------------------------------------------# my $Filedesc=$_[0]; print $Filedesc qq| $L_Incoming $L_Outgoing $L_Bytes $L_Total |; } #------------------------------------------------------------------# sub EnderUnixTeam { #------------------------------------------------------------------# my $o = qq|
IsoQlog version $version   EnderUNiX Software Development Team
|; return($o); } #------------------------------------------------------------------# sub PrintGeneral { #------------------------------------------------------------------# PrintFilePart1 ("$DAILYS","Incoming","$L_Domain"); for ($i=0; $i< $maxdomainin ; $i++ ){ if($SortedFromDomains[$i]){ $mailnumber = $i+1; print $DAILYS qq| $mailnumber $SortedFromDomains[$i] $FromDomains{$SortedFromDomains[$i]} |; } } #for is end print $DAILYS &endbox; PrintFilePart1 ("$DAILYS","Outgoing","$L_Domain"); for ( $i= 0; $i<$maxdomainout ; $i++ ){ if($SortedToDomains[$i]){ $mailnumber = $i+1; print $DAILYS qq| $mailnumber $SortedToDomains[$i] $ToDomains{$SortedToDomains[$i]} |; } } #for is end print $DAILYS &endbox; PrintFilePart1 ("$DAILYS","Total","$L_Domain"); for ($i=0;$i<$maxdomaintotal;$i++ ){ if (!defined($FromDomains{$SortedFromAndToDomains[$i]} ) ) { $FromDomains{$SortedFromAndToDomains[$i]} = 0; } if (! $FromAndToDomains{$SortedFromAndToDomains[$i]}) { $FromAndToDomains{$SortedFromAndToDomains[$i]} = 0; } if (! $FromDomains{$SortedFromAndToDomains[$i]}) { $FromDomains{$SortedFromAndToDomains[$i]} = 0; } if (! $ToDomains{$SortedFromAndToDomains[$i]}) { $ToDomains{$SortedFromAndToDomains[$i]} = 0; } $mailnumber = $i+1; print $DAILYS qq| $mailnumber $SortedFromAndToDomains[$i] $FromDomains{$SortedFromAndToDomains[$i]} $ToDomains{$SortedFromAndToDomains[$i]} $FromAndToDomains{$SortedFromAndToDomains[$i]} |; } #for is end print $DAILYS &endbox; #Procesing on Byte Support PrintFilePart1 ("$DAILYS","Byte","$L_Domain"); for ($i=0;$i<$maxdomainbyte;$i++ ){ #$ByteDomains{$SortedByteDomains[$i]} = int ( $ByteDomains{$SortedByteDomains[$i]}/1048576 ); if($ByteDomains{$SortedByteDomains[$i]} < 1024){ $d = int ( $ByteDomains{$SortedByteDomains[$i]} ); $MBorKBByteDomains = "B"; } elsif($ByteDomains{$SortedByteDomains[$i]} < 1048576){ $d = int ( $ByteDomains{$SortedByteDomains[$i]}/1024 ); $MBorKBByteDomains = "KB"; } else{ $d = int ( $ByteDomains{$SortedByteDomains[$i]}/1048576 ); $MBorKBByteDomains = "MB"; } $mailnumber=$i+1; print $DAILYS qq| $mailnumber $SortedByteDomains[$i] $d $MBorKBByteDomains |; } #for is end print $DAILYS &endbox; PrintFilePart1 ("$DAILYS","Incoming","$L_Email"); for ($i=0; $i<$maxdomain_userin ; $i++ ){ $mailnumber=$i+1; print $DAILYS qq| $mailnumber $SortedFromUsers[$i] $FromUsers{$SortedFromUsers[$i]} |; } #for is end print $DAILYS &endbox; PrintFilePart1 ("$DAILYS","Outgoing","$L_Email"); for ($i=0;$i<$maxdomain_userout;$i++ ){ $mailnumber = $i+1; print $DAILYS qq| $mailnumber $SortedToUsers[$i] $ToUsers{$SortedToUsers[$i]} |; } #for is end print $DAILYS &endbox; PrintFilePart1 ("$DAILYS","Total","$L_Email"); for ($i = 0; $i < $maxdomain_usertotal; $i++ ){ $mailnumber=$i+1; if ($FromUsers{$SortedFromAndToUsers[$i]} == "") { #if it it undefined set it zero $FromUsers{$SortedFromAndToUsers[$i]} = 0; } if ($ToUsers{$SortedFromAndToUsers[$i]} == "") { #if it it undefined set it zero $ToUsers{$SortedFromAndToUsers[$i]} = 0; } print $DAILYS qq| $mailnumber $SortedFromAndToUsers[$i] $FromUsers{$SortedFromAndToUsers[$i]} $ToUsers{$SortedFromAndToUsers[$i]} $FromAndToUsers{$SortedFromAndToUsers[$i]} |; } #for is end print $DAILYS &endbox; #Procesing on Byte Support PrintFilePart1 ("$DAILYS","Byte","$L_Email"); for ($i=0;$i<$maxdomainbyte;$i++ ){ $mailnumber=$i+1; if($ByteUsers{$SortedByteUsers[$i]} < 1048576){ $u = int ($ByteUsers{$SortedByteUsers[$i]}/1024 ); $MBorKBu = "KB"; } else{ $u = int ($ByteUsers{$SortedByteUsers[$i]}/1048576 ); $MBorKBu = "MB"; } print $DAILYS qq| $mailnumber $SortedByteUsers[$i] $u $MBorKBu |; } #for is end print $DAILYS &endbox; } #------------------------------------------------------------------# sub PrintFilePart1 { #------------------------------------------------------------------# my $FileDesc = $_[0]; my $InOutTotalByte = $_[1]; my $EmailorDomain = $_[2]; if($InOutTotalByte eq "Byte") { print $FileDesc &startbox("$ThisDay $ThisMonth $L_Top $L_Bytes","600","11"); } elsif($InOutTotalByte eq "Incoming"){ print $FileDesc &startbox("$ThisDay $ThisMonth $L_Top $L_Incoming","600","11"); } elsif($InOutTotalByte eq "Outgoing"){ print $FileDesc &startbox("$ThisDay $ThisMonth $L_Top $L_Outgoing","600","11"); } elsif($InOutTotalByte eq "Total"){ print $FileDesc &startbox("$ThisDay $ThisMonth $L_Top $L_Total","600","11"); } print $FileDesc qq| # $EmailorDomain |; if($InOutTotalByte eq "Byte") { print $FileDesc qq| $L_Bytes |; } elsif($InOutTotalByte eq "Total") { print $FileDesc qq| $L_Outgoing $L_Incoming $L_Total |; } else { print $FileDesc qq| $L_Mail |; } print $FileDesc qq||; } #Print File PARt 1 end ######################################################### #------------------------------------------------------------------# sub PrintFilePart2 { #------------------------------------------------------------------# my $FileDesc=$_[0]; my $Filename =$_[1]; my $InOutTotalByte=$_[2]; #for ($i=0; $i<$maxoutgoing ;$i++) { print "Reading $Filename\n" if($Debug); OpenFile ("GETUSERINFO","<","$Filename"); #$countme=$i+1; $mailnumber=0; while ($LineValue=) { chomp($LineValue); @Values=split(/:/,$LineValue); my $Value1 = $Values[0]; my $Value2 = $Values[1]; if($InOutTotalByte eq "Total") { if($Value2 == "") { $Value2 = 0; } $Value3=$Values[2]; if($Value3 == "") { $Value3 = 0; } $Totals= $Value2 + $Value3; #print "VAlue2=$Value2 , value3=$Value3\n"; } if($InOutTotalByte eq "Byte") { if($Value2 < 1048576){ $Value2 = int ($Value2/1024); $MBorKBValue2 = "KB"; } else{ $Value2 = int ($Value2/1048576); $MBorKBValue2 = "MB"; } } $mailnumber++; print $FileDesc qq| $mailnumber $Value1 |; if($InOutTotalByte eq "Byte") { print $FileDesc qq| $Value2 $MBorKBValue2 |; } else { print $FileDesc qq| $Value2 |; } if($InOutTotalByte eq "Total" ) { #print "Total basildi $Filename \n"; print $FileDesc qq| $Value3 $Totals |; } print $FileDesc "\n"; } #while is end print $FileDesc &endbox; close(GETUSERINFO); } #------------------------------------------------------------------# sub makehtmlheader{ #------------------------------------------------------------------# my $t1 = shift(@_); my $t2 = shift(@_); my $t3 = shift(@_); my $o = qq| $t1
From the $mycompany Support Team

$t2

$t3
|; return($o); } #------------------------------------------------------------------# sub display_time{ #------------------------------------------------------------------# my ($sec,$minutes,$hour,$day ,$month ,$year) = localtime(time); $month = $month+1; my $year = $year+1900; my $o = qq| $L_Generated $day/$month/$year $hour:$minutes:$sec

|; return($o); } #------------------------------------------------------------------# sub makemenu{ #------------------------------------------------------------------# # develop into menu my ($m, $m1, $m2); my $o = qq|
|; foreach $m(@_){ ($m1,$m2)=split(":",$m,2); $o .= qq| |; } $o .= qq|
$L_Main_Page$m2

|; return($o); } #------------------------------------------------------------------# sub GetInfoFromSyslog{ #call openfile function to open a file with various purpose print "in sub GetInfoFromSyslog\n" if($Debug); print "\tReading $logfile\n" if($Debug); OpenFile ("MAILLOGFILE","<","$logfile"); while(){ chomp($_); CommonErrors ("$_"); $_=lc($_); #make the line lowercase if(/$start/) { @ToLineArray= split(/ /,$_); if($ThisDay< 10) { @UserandDomain=split(/@/,$ToLineArray[14]); ToDomainsAndUsers("$UserandDomain[0]","$UserandDomain[1]"); } else { @UserandDomain=split(/@/,$ToLineArray[13]); ToDomainsAndUsers("$UserandDomain[0]","$UserandDomain[1]"); } } #if /$start/ end # we start to collect from mail addresses if(/$from/ && /bytes/ && /info msg/) { @FromLineArray= split(/ /,$_); if($ThisDay< 10) { FromDomainsUsersAndBytes ("$FromLineArray[11]","$FromLineArray[13]"); } else { FromDomainsUsersAndBytes ("$FromLineArray[10]","$FromLineArray[12]"); } } # if (/$msginfo && /from ) and here } # while end } #------------------------------------------------------------------# sub GetInfoFromMultilog{ #call openfile function to open a file with various purpose print "in sub GetInfoFromMultilog\n" if($Debug); print "\tReading $logfile\n" if($Debug); OpenFile ("MAILLOGFILE","<","$logfile"); while(){ chomp($_); CommonErrors ("$_"); $_=lc($_); #make the line lowercase if(/$start/) { @ToLineArray= split(/ /,$_); @UserandDomain=split(/@/,$ToLineArray[9]); ToDomainsAndUsers("$UserandDomain[0]","$UserandDomain[1]"); } #if /$start/ end # we start to collect from mail addresses if(/$from/ && /bytes/ && /info msg/) { @FromLineArray= split(/ /,$_); FromDomainsUsersAndBytes ("$FromLineArray[6]","$FromLineArray[8]"); } # if (/$msginfo && /from ) and here }# while end } #------------------------------------------------------------------# sub output_isolog_homepage{ print "Writing $isoqlogdir/index.html\n" if($Debug); OpenFile ("ALLINDEX",">","$isoqlogdir/index.html"); print ALLINDEX &makehtmlheader("$L_Qmail_stat Generated by IsoQlog","$mycompany Support Team", "$L_Qmail_stat"); # $Plsclk has no value..... #print ALLINDEX qq| #
$Plsclk



#|; print ALLINDEX qq|


    |; foreach (@tosba) { print ALLINDEX "
  • $_\n
  • "; } print ALLINDEX "



"; print ALLINDEX &EnderUnixTeam; #print EnderUnix banner close(ALLINDEX); } #------------------------------------------------------------------# sub output_domains_indexhtml{ print "in sub output_domains_indexhtml\n" if($Debug); $indexhtml = "$isoqlogdir/$domains/index.html"; print "Writing $indexhtml \n" if($Debug); OpenFile ("INDEXHTML",">","$indexhtml") ; print INDEXHTML &makehtmlheader("$domains $L_Qmail_stat","$domains","$L_Monthly"); print INDEXHTML &display_time; print INDEXHTML &makemenu(); print INDEXHTML &startbox("$domains $L_Monthly $L_Qmail_stat","650","14"); print INDEXHTML qq| $L_Month $L_Daily_Average |; if($display_totals_in_domains){ if ($domains ne "General" ) { print INDEXHTML qq| $domains |; } } print INDEXHTML qq| $L_Total |; IndexPart1("INDEXHTML"); IndexPart1("INDEXHTML"); if($display_totals_in_domains){ if($domains ne "General" ){ IndexPart1("INDEXHTML"); } } print INDEXHTML qq||; $mydomain_all_in = 0; $mydomain_all_out = 0; $mydomain_all_all = 0; $mydomain_all_byte = 0; $allin = 0; $allout = 0; $allbyte = 0; $allall = 0; print "Reading $isoqlogdir/$domains/AllMonths\n" if($Debug); OpenFile ("GETMONTHS","<","$isoqlogdir/$domains/AllMonths"); while ($lines=){ chomp($lines); $_=$lines; if (/^#/) { next; } else { @filevalues=split(/:/,$lines); if( $filevalues[4] < 1048576) { $megabyte=int ($filevalues[4]/1024); $MBorKBMG="KB"; } else { $megabyte=int ($filevalues[4]/1048576); $MBorKBMG="MB"; } if( $filevalues[8] < 1048576) { $filevalues8=int($filevalues[8]/1024); $MBorKB8="KB"; } else { $filevalues8=int ($filevalues[8]/1048576); $MBorKB8="MB"; } if( $filevalues[12] < 1048576) { $filevalues12=int ($filevalues[12]/1024); $MBorKB12="KB"; } else { $filevalues12=int ($filevalues[12]/1048576); $MBorKB12="MB"; } for ($i=2;$i<14 ;$i++) { if ($filevalues[$i]==""){ $filevalues[$i]=0; } } $indexhtml_link = "$filevalues[1]/$filevalues[0]$filevalues[1].html"; print INDEXHTML qq| $filevalues[0] $filevalues[1] $filevalues[2] $filevalues[3] $megabyte $MBorKBMG $filevalues[5] $filevalues[6] $filevalues[7] $filevalues8 $MBorKB8 $filevalues[9] |; if($display_totals_in_domains){ if ($domains ne "General" ) { print INDEXHTML qq| $filevalues[10] $filevalues[11] $filevalues12 $MBorKB12 $filevalues[13] |; } } print INDEXHTML "\n"; $mydomain_all_in += $filevalues[6]; $mydomain_all_out += $filevalues[7]; $mydomain_all_byte += $filevalues[8]; $mydomain_all_all += $filevalues[9]; if($display_totals_in_domains){ if ($domains ne "General" ) { $allin += $filevalues[10]; $allout += $filevalues[11]; $allbyte += $filevalues[12]; $allall += $filevalues[13]; }#ne General is end } } } if($mydomain_all_byte < 1048576) { $mydombyte=int($mydomain_all_byte/1024); $MBorKBMyDom="KB"; } else { $mydombyte=int($mydomain_all_byte/1048576); $MBorKBMyDom="MB"; } if($allbyte < 1048576) { $allbyte=int($allbyte/1024); $MBorKBAll="KB"; } else { $allbyte=int($allbyte/1048576); $MBorKBAll="MB"; } print INDEXHTML qq| $L_Total $mydomain_all_in $mydomain_all_out $mydombyte $MBorKBMyDom $mydomain_all_all |; if($display_totals_in_domains){ if ($domains ne "General" ) { print INDEXHTML qq| $allin $allout $allbyte $MBorKBAll $allall |; } } print INDEXHTML qq||; print INDEXHTML &endbox; print INDEXHTML "
"; print INDEXHTML &makemenu(); print INDEXHTML &EnderUnixTeam; close(INDEXHTML); print "leaving sub output_domains_indexhtml\n\n" if($Debug); } #- end INDEXHTML --------------------------------------------------# #------------------------------------------------------------------# sub output_daily_indexhtml{ print "in sub output_daily_indexhtml\n" if($Debug); my (@X_allall_total,@X_all_months,@X_all_bytes); $todayhtmlfile="$isoqlogdir/$domains/$ThisYear/$ThisMonth$ThisYear.html"; print "Writing $todayhtmlfile\n" if($Debug); OpenFile ("DAILY",">","$todayhtmlfile"); print DAILY &makehtmlheader("$domains $L_Qmail_stat","$L_Daily $L_Stats","$domains"); print DAILY &display_time; #print DAILY &makemenu("$indexhtml_link:$indexhtml_link"); print DAILY &makemenu(); print DAILY &startbox("$domains $L_Qmail_stat","600","11"); print DAILY qq| $ThisMonth - $ThisYear $L_Day $domains |; if($display_totals_in_domains){ if ($domains ne "General") { print DAILY qq| $L_Total |; } } print DAILY "\n"; IndexPart1("DAILY"); if($display_totals_in_domains){ if ($domains ne "General") { IndexPart1("DAILY"); } } print DAILY qq||; print "Reading $isoqlogdir/$domains/$ThisYear/$ThisMonth\n" if($Debug); OpenFile ("CURRENT_MONTH" ,"<","$isoqlogdir/$domains/$ThisYear/$ThisMonth") ; $monthly_mydomainin_total = 0; $monthly_mydomainout_total = 0; $monthly_mydomainbyte_total = 0; $monthly_mydomainall_total = 0; $m_allin_total = 0; #monthly all incoming total $m_allout_total = 0; #monthly all out total $m_allbyte_total = 0; #monthly all byte total $m_allall_total = 0; #monthly all total total while($_=) { chomp($_); if(/^#/) { next; } else { @alldaysvalues = split(/:/,$_); push(@X_all_months , $alldaysvalues[0]); push(@X_all_bytes , $alldaysvalues[3]); push(@X_allall_total , $alldaysvalues[4]); $monthly_mydomainin_total += $alldaysvalues[1]; $monthly_mydomainout_total += $alldaysvalues[2]; $monthly_mydomainbyte_total += $alldaysvalues[3]; $monthly_mydomainall_total += $alldaysvalues[4]; if ($domains ne "General") { #if($display_totals_in_domains){ $m_allin_total += $alldaysvalues[5]; $m_allout_total += $alldaysvalues[6]; $m_allbyte_total += $alldaysvalues[7]; $m_allall_total += $alldaysvalues[8]; if($alldaysvalues[7] < 1024){ $alldaysvaluesbyte7 = int ($alldaysvalues[7]); $MBorKBAllDaysbyte7 = " B"; } elsif($alldaysvalues[7] < 1048576){ $alldaysvaluesbyte7 = int ($alldaysvalues[7]/1024); $MBorKBAllDaysbyte7 = "KB"; } else{ $alldaysvaluesbyte7 = int ($alldaysvalues[7]/1048576); $MBorKBAllDaysbyte7 = "MB"; } if($alldaysvalues[3] < 1) { $alldaysvaluesbyte = 0; $MBorKBAllDays = ""; } elsif($alldaysvalues[3] < 1024) { $alldaysvaluesbyte = int ( $alldaysvalues[3]); $MBorKBAllDays = " B"; } elsif($alldaysvalues[3] < 1048576) { $alldaysvaluesbyte = int ( $alldaysvalues[3]/1024); $MBorKBAllDays = "KB"; } else { $alldaysvaluesbyte = int ( $alldaysvalues[3]/1048576); $MBorKBAllDays = "MB"; } #} } #if ne General is end else { if($alldaysvalues[3] < 1024) { $gen = int ($alldaysvalues[3]); $MBorKBgen = " B"; } elsif($alldaysvalues[3] < 1048576) { $gen = int ($alldaysvalues[3]/1024); $MBorKBgen = "KB"; } else{ $gen = int ($alldaysvalues[3]/1048576); $MBorKBgen = "MB"; } } print DAILY qq| $alldaysvalues[0] $alldaysvalues[1] $alldaysvalues[2] |; if ($domains ne "General" ) { #if($display_totals_in_domains){ print DAILY qq| $alldaysvaluesbyte $MBorKBAllDays |; #} } else { print DAILY qq| $gen $MBorKBgen |; } print DAILY qq| $alldaysvalues[4] |; if ($domains ne "General") { if($display_totals_in_domains){ print DAILY qq| $alldaysvalues[5] $alldaysvalues[6] $alldaysvaluesbyte7 $MBorKBAllDaysbyte7 $alldaysvalues[8] |; } } #if $domains ne General is end here else{ # } } } if( $monthly_mydomainbyte_total < 1024) { $tosbik = int($monthly_mydomainbyte_total); $MBorKBTosbik = " B"; } elsif( $monthly_mydomainbyte_total < 1048576) { $tosbik = int($monthly_mydomainbyte_total/1024); $MBorKBTosbik = "KB"; } else { $tosbik = int($monthly_mydomainbyte_total/1048576); $MBorKBTosbik = "MB"; } print DAILY qq| \n $L_Total $monthly_mydomainin_total $monthly_mydomainout_total $tosbik $MBorKBTosbik $monthly_mydomainall_total |; if ($domains ne "General") { if($display_totals_in_domains){ if($m_allbyte_total < 1024) { $iso = int($m_allbyte_total); $MBorKBiso = " B"; } elsif($m_allbyte_total < 1048576) { $iso = int($m_allbyte_total/1024); $MBorKBiso = "KB"; } else { $iso = int($m_allbyte_total/1048576); $MBorKBiso = "MB"; } print DAILY qq| $m_allin_total $m_allout_total $iso $MBorKBiso $m_allall_total |; } } print DAILY qq||; print DAILY &endbox; # CHART print DAILY &startbox("$domains $L_Daily $L_Chart","600",""); $mag = 2; $rh = 100*$mag; print DAILY qq| |; for($ct = 0; $ct <= $#X_allall_total; $ct++){ #$xp = int((($x/100)*$m_allall_total)/10); #$xp = int(($x/$m_allall_total)*100); if ($domains ne "General") { if($X_allall_total[$ct] and $monthly_mydomainall_total){ $xmp = int(($X_allall_total[$ct]/$monthly_mydomainall_total)*100); } else{ $xmp = 0; } if($X_all_bytes[$ct] and $monthly_mydomainbyte_total){ $xbp = int(($X_all_bytes[$ct]/$monthly_mydomainbyte_total)*100); } else{ $xbp = 0; } } else{ if($X_allall_total[$ct] and $monthly_mydomainall_total){ $xmp = int(($X_allall_total[$ct]/$monthly_mydomainall_total)*100); } else{ $xmp = 0; } if($X_all_bytes[$ct] and $monthly_mydomainbyte_total){ $xbp = int(($X_all_bytes[$ct]/$monthly_mydomainbyte_total)*100); } else{ $xbp = 0; } } $mh = $xmp*$mag; $bh = $xbp*$mag; print DAILY qq| |; } # $x
$xp
# $x $xp %
#$m_allall_total
print DAILY qq| |; foreach $x(@X_all_months){ print DAILY qq| |; } print DAILY qq|
|; #print DAILY "$X_allall_total[$ct]
$xmp
$X_all_bytes[$ct]
$xbp
" if($Debug); print DAILY qq| $xmp% ($X_allall_total[$ct])$xbp% ($X_all_bytes[$ct])
$x
$L_Alt_PEmails $L_PEmails     $L_Alt_PBytes $L_PBytes |; print DAILY &endbox; print DAILY "
"; #if ($domains ne "General") { # #debug # for($ct = 0; $ct <= $#X_allall_total; $ct++){ # print DAILY "$X_allall_total[$ct]
$xmp
$X_all_bytes[$ct]
$xbp
"; # #print DAILY "Total of emails:$monthly_mydomainall_total
"; # #print DAILY "Total of bytes:$m_allbyte_total
"; # $mymail += $X_allall_total[$ct]; # $mybyte += $X_all_bytes[$ct]; # } # print DAILY "Total of emails:$monthly_mydomainall_total ($mymail)
"; # print DAILY "Total of bytes:($mybyte) ($monthly_mydomainbyte_total)
"; #} #else{ # #debug # for($ct = 0; $ct <= $#X_allall_total; $ct++){ # print DAILY "$X_allall_total[$ct]
$xmp

$X_all_bytes[$ct]
$xbp
"; # $mymail += $X_allall_total[$ct]; # $mybyte += $X_all_bytes[$ct]; # } # print DAILY "Total of emails:$monthly_mydomainall_total ($mymail)
"; # print DAILY " Total of bytes:$monthly_mydomainbyte_total ($mybyte)
"; # # #} print DAILY &makemenu; print DAILY &EnderUnixTeam; close(DAILY); print "leaving sub output_daily_indexhtml\n\n" if($Debug); } #------------------------------------------------------------------# sub output_dailys_indexhtml{ print "in sub output_dailys_indexhtml\n" if($Debug); $TopS[0]="TODAYTOPS" ; $thisfile = "$isoqlogdir/$domains/$ThisYear/$ThisDay-$ThisMonth$ThisYear.html"; print "Writing $thisfile\n" if($Debug); OpenFile ("TODAYTOPS",">","$thisfile"); $DAILYS=$TopS[0]; print $DAILYS &makehtmlheader("$domains $L_Qmail_stat","$domains $L_Stats","for $ThisDay $ThisMonth $ThisYear"); print $DAILYS &display_time; print $DAILYS &makemenu(); if( $domains eq "General" ) { PrintGeneral(); }#if $domains eq General End else { PrintFilePart1 ($DAILYS,"Incoming",$L_Email); PrintFilePart2 ($DAILYS,"$isoqlogdir/$domains/FromUsers","Incoming"); PrintFilePart1 ($DAILYS,"Outgoing",$L_Email); PrintFilePart2 ($DAILYS,"$isoqlogdir/$domains/ToUsers","Outgoing"); PrintFilePart1 ($DAILYS,"Total",$L_Email); PrintFilePart2 ($DAILYS,"$isoqlogdir/$domains/TotalUsers","Total"); PrintFilePart1 ($DAILYS,"Byte",$L_Email); PrintFilePart2 ($DAILYS,"$isoqlogdir/$domains/ByteUsers","Byte"); } if($display_errors==1) { if($there_are_errors){ print $DAILYS &startbox("$ThisDay $ThisMonth $L_Common_errors","600","3"); print $DAILYS qq| $no_mailbox $no_mailbox_counter $RELAY $RELAYcounter Not_$not_find_hostname $no_hostname $failed_smtp_connection $failed_smtp_counter $CNAME_lookup $CNAME_lookup_counter $unable_Maildir $unable_Maildir_counter $Unable_to_chdir_to_maildir $Unable_to_chdir_to_maildir_counter |; print $DAILYS &endbox; } else{ print $DAILYS qq|
$L_NoErrors



|; } } #error display is end here if($display_description){ # Print Description print $DAILYS &startbox("$L_Description","600","3"); print $DAILYS qq| $L_Incoming $L_Mail: $L_IncomingMailDesc  $L_Outgoing $L_Mail: $L_OutgoingMailDesc  $L_Total $L_Mail $L_TotalMailDesc  $L_Bytes: $L_ByteMailDesc  |; print $DAILYS &endbox; } print $DAILYS &makemenu(); print $DAILYS &EnderUnixTeam; close($DAILYS); print "leaving sub output_dailys_indexhtml\n\n" if($Debug); } #------------------------------------------------------------------# sub startbox{ my $l = shift(@_); my $s = shift(@_); my $c = shift(@_); if(! $s){ $s = "600";} if(! $c){ $c = ""; } else{ $c = "colspan='$c'"; } my $o = qq| |; return($o); } #------------------------------------------------------------------# sub endbox{ my $o = qq|
$l


|; } #------------------------------------------------------------------# #print DAILY "

#


# #
# IsoQlog version 1.5 stable #Ismail YENIGUL #
\n"; #print DAILY "\n"; ## eof ##