Location: PHPKode > projects > XMail Log Archiver > xmlogarch.d/reports.d/bouncer.php
<?php
/*
	 License
    XMail Log Archiver
	 http://xmlogarch.sourceforge.net
    Copyright (C) 2006 Bryn Mosher

    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License Version 2 as
	 published by the Free Software Foundation.

    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 contact , write to 
	 hide@address.com
	 - or -
	 Free Software Foundation, Inc.
	 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#
# (ie myreport.php  is named myreport )
# name of php file  without the '.php' extension
$modTitle = "Bouncer Filter";

#
# this is used to detect loaded modules
# key must be the same as name
#val is array of required modules
$reqRepMod['bouncer'] = array();

#
# this is the function to perform the report
# must be called ($modulenName)Do() and recieves no parameters
function bouncerDo () {
	global $logRoot;
	reportBouncer( $logRoot );
}

#
# the reports code belongs below
function reportBouncer ( $logRoot ) {
	global $xmailServer;
	$retVal = FALSE;
	$sr = "BOUNCER-FILTER-REPORT";
	$begun = ( isset( $GLOBALS["begun"] ) ) ? ( $GLOBALS["begun"] ) : ( date( _dateFmt ) );
	logIt( "Bouncer Filter Log report for " . date( _dateFmt, $begun ) . ":", $sr );
	memUse( "Bouncer Filter Reporting started" );
	$allBouncer = array();
	$catBounceer = "";
	if ( $bouncerLogs = getLogsToarch( $logRoot, -1, "bouncer" ) ) {
		logIt ( "Total " . count( $bouncerLogs ) . " Bouncer logs found in log directory.", $sr );
		pIt ( "Reading Bouncer log file lines... ", NULL, $GLOBALS["showDots"] );
		$dots = 0;
		foreach ( $bouncerLogs as $logName ) {
			$dots++;
			if ( $totBouncer[$logName] = slurpLog( slashDir( $logRoot ) . $logName ) ) {
				dot( $dots );
				$allBouncer = array_merge( $allBouncer, explode( "\n", $totBouncer[$logName] ) ); # line break just in case
			} else {
//				logIt( "Could not read log '" . slashDir( $logRoot ) . $logName . "'.", $sr );
				dot( $dots, "E" );
			}
		}
		pIt ( " Done." . PHP_EOL, NULL, $GLOBALS["showDots"] );
		$retVal = TRUE;
	}
	memUse( "Concatinated Bouncer log file contents" );
	unset( $totBouncer );
	memUse( "Discarded Bouncer log file contents" );
	logIt ( "Total " . count( $allBouncer ) . " Bouncer log lines.", $sr );
	$grep = "/" . implode( "\t", array_fill( 0, 9, "\\\"([\\S\\s^\\\"]*?)\\\"" ) ) . ".*?/";
	pIt ( "Parsing Bouncer log entries... ", NULL, $GLOBALS["showDots"] );
	$dots = 0;
	$keyCount = 0;
	foreach ( $allBouncer as $logLine ) {
		$dots++;
		if ( preg_match( $grep, $logLine, $logItems ) ) {
			$keyCount++;
			dot( $dots, NULL, NULL, $GLOBALS["dotsPer"] * $GLOBALS["dotsPerEntry"] );
			$all['procDate'][] = $logItems[1];
			$all['smtpTo'][] = $logItems[2];
			$all['scores']['smtpTo'][$keyCount] = $logItems[2];
			$all['cDomain'][] = $logItems[3];
			$all['scores']['cDomain'][$keyCount] = $logItems[3];
			$all['senderIp'][] = $logItems[4];
			$all['scores']['senderIp'][$keyCount] = $logItems[4];
			$all['smtpFrom'][] = $logItems[5];
			$all['scores']['smtpFrom'][$keyCount] = $logItems[5];
			$all['messageDate'][] = $logItems[6];
			$all['reason'][] = $logItems[9];
			$all['scores']['reason'][$keyCount] = $logItems[9];
		} else {
			dot( $dots, "E", NULL, $GLOBALS["dotsPer"] * $GLOBALS["dotsPerEntry"] );
		}
	}
	pIt ( " Done." . PHP_EOL, NULL, $GLOBALS["showDots"] );
	unset( $allBouncer );
	memUse( "Created Bouncer entry array" );
	$entsNum = count( $all['procDate'] );
	$report = "Total " . $entsNum . " Bouncer entries found in logs.";
	logIt ( $report, $sr );
	$titles = array(
		"report" => "Bouncer",
		"reason" => "Bounced Reasons",
		"senderIp" => "Bouncer Connecting IP Addresses",
		"smtpTo" => "Bouncer Recepients",
		"smtpFrom" => "Bouncer Senders",
		);
	highScores ( $all['scores'], $titles );
	unset( $all );
	memUse( "Discarded Bouncer entry array" );
	return $retVal;
}

?>
Return current item: XMail Log Archiver