Location: PHPKode > projects > XMail Log Archiver > xmlogarch.d/reports.d/filters.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 = "Mail Filters";

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

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

#
# the reports code belongs below
function reportFilters ( $logRoot ) {
	global $xmailServer;
	$sr = "FILTERS-REPORT";
	$begun = ( isset( $GLOBALS["begun"] ) ) ? ( $GLOBALS["begun"] ) : ( date( _dateFmt ) );
	logIt( "Filters Log report for " . date( _dateFmt, $begun ) . ":", $sr );
	memUse( "Filters Reporting started" );
	$allFilters = array();
	if ( $filtersLogs = getLogsToarch( $logRoot, -1, "filters" ) ) {
		logIt ( "Total " . count( $filtersLogs ) . " Filters logs found in log directory.", $sr );
		pIt ( "Reading filter log file lines... ", NULL, $GLOBALS["showDots"] );
		$dots = 0;
		foreach ( $filtersLogs as $logName ) {
			$dots++;
			if ( $totFilters[$logName] = slurpLog( slashDir( $logRoot ) . $logName ) ) {
				dot( $dots );
				$allFilters = array_merge( $allFilters, explode( "\n", $totFilters[$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"] );
	}
	memUse( "Concatinated filter log file contents" );
	unset( $totFilters );
	memUse( "Discarded filter log file contents" );
	logIt ( "Total " . count( $allFilters ) . " Filters log lines.", $sr );
	$grep = "/" . implode( "\t", array_fill( 0, 10, "\\\"([\\S\\s^\\\"]*?)\\\"" ) ) . ".*?/";
	pIt ( "Parsing filter log entries... ", NULL, $GLOBALS["showDots"] );
	$dots = 0;
	$keyCount = 0;
	foreach ( $allFilters as $logLine ) {
		$dots++;
		if ( preg_match( $grep, $logLine, $logItems ) ) {
		$keyCount++;
			dot( $dots, NULL, NULL, $GLOBALS["dotsPer"] * $GLOBALS["dotsPerEntry"] );
			if ( $logItems[9] > 0 ) { // not a zero (no action) result
				$all['sender'][] = $logItems[1];
				$all['scores']['sender'][$keyCount] = $logItems[1]; //recipient ( local user )
				$all['recipient'][] = $logItems[2];
				$all['scores']['recipient'][$keyCount] = $logItems[2]; //recipient ( local user )
				$all['remoteIp'][] = $logItems[4];
				$all['scores']['remoteIp'][$keyCount] = $logItems[4]; //recipient ( local user )
				$all['type'][] = $logItems[6];
				$all['scores']['type'][$keyCount] = $logItems[6]; //recipient ( local user )
			}
			$all['info'][] = $logItems[7];
		} else {
			dot( $dots, "E", NULL, $GLOBALS["dotsPer"] * $GLOBALS["dotsPerEntry"] );
		}
	}
	pIt ( " Done." . PHP_EOL, NULL, $GLOBALS["showDots"] );
	unset( $allFilters );
	memUse( "Created filters entry array" );
	$entsNum = count( $all['info'] );
	$report = "Total " . $entsNum . " filter entries found in logs.";
	$retVal = $entsNum;
	logIt ( $report, $sr );
	$titles = array(
		"report" => "Filters",
		"recipient" => "Recipientss (Rcpt-To)",
		"remoteIp" => "Remote IP Addresses",
		"sender" => "Senders (From)",
		"type" => "Filter Types",
		);
	highScores ( $all['scores'], $titles );
	unset( $all );
	memUse( "Discarded Filters entry array" );
	return $retVal;
}
?>
Return current item: XMail Log Archiver