Location: PHPKode > projects > XMail Log Archiver > xmlogarch.d/reports.d/pop3.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 = "POP3 Logs";

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

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

#
# the reports code belongs below
function reportPop3 ( $logRoot ) {
	$retVal = FALSE;
	$sr = "POP3-REPORT";
	$begun = ( isset( $GLOBALS["begun"] ) ) ? ( $GLOBALS["begun"] ) : ( date( _dateFmt ) );
	logIt( "POP3 Filter Log report for " . date( _dateFmt, $begun ) . ":", $sr );
	memUse( "POP3 Reporting started" );
	$allPop3 = array();
	if ( $pop3Logs = getLogsToarch( $logRoot, -1, "pop3" ) ) {
		logIt ( "Total " . count( $pop3Logs ) . " POP3 logs found in log directory.", $sr );
		pIt ( "Reading POP3 log file lines... ", NULL, $GLOBALS["showDots"] );
		$dots = 0;
		foreach ( $pop3Logs as $logName ) {
			$dots++;
			if ( $totPop3[$logName] = slurpLog( slashDir( $logRoot ) . $logName ) ) {
				dot( $dots );
				$allPop3 = array_merge( $allPop3, explode( "\n", $totPop3[$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 POP3 log file contents" );
	unset( $totPop3 );
	memUse( "Discarded POP3 log file contents" );
	logIt ( "Total " . count( $allPop3 ) . " POP3 log lines.", $sr );
	$grep = "/" . implode( "\t", array_fill( 0, 6, "\\\"([\\S\\s^\\\"]*?)\\\"" ) ) . ".*?/";
	pIt ( "Parsing POP3 log entries... ", NULL, $GLOBALS["showDots"] );
	$dots = 0;
	$keyCount = 0;
	foreach ( $allPop3 as $logLine ) {
		$dots++;
		if ( preg_match( $grep, $logLine, $logItems ) ) {
			$keyCount++;
			dot( $dots, NULL, NULL, $GLOBALS["dotsPer"] * $GLOBALS["dotsPerEntry"] );
			$all['fqdn'][] = $logItems[1];
			$all['domain'][] = $logItems[2];
			$all['scores']['domain'][$keyCount] = $logItems[2];
			$all['ip'][] = $logItems[3];
			$all['scores']['ip'][$keyCount] = $logItems[3];
			$all['user'][] = $logItems[5];
			$all['scores']['user'][$keyCount] = $logItems[5];
		} else {
			dot( $dots, "E", NULL, $GLOBALS["dotsPer"] * $GLOBALS["dotsPerEntry"] );
		}
	}
	pIt ( " Done." . PHP_EOL, NULL, $GLOBALS["showDots"] );
	unset( $allPop3 );
	memUse( "Created POP3 entry array" );
	$entsNum = count( $all['fqdn'] );
	$report = "Total " . $entsNum . " POP3 entries found in logs.";
	logIt ( $report, $sr );
	$titles = array(
		"report" => "POP3",
		"domain" => "User's Login Domain",
		"ip" => "IP Address Users Checked From",
		"user" => "POP3 Users",
		);
	highScores ( $all['scores'], $titles );
	unset( $all );
	memUse( "Discarded POP3 entry array" );
	$retVal = TRUE;
	return $retVal;
}

?>
Return current item: XMail Log Archiver