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

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

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

#
# the reports code belongs below
function reportCtrl ( $logRoot ) {
	$sr = "CONTROL-REPORT";
	$begun = ( isset( $GLOBALS["begun"] ) ) ? ( $GLOBALS["begun"] ) : ( date( _dateFmt ) );
	logIt( "Control Log report for " . date( _dateFmt, $begun ) . ":", $sr );
	memUse( "Control Reporting started" );
	$allParsed = array();
	if ( $logs = getLogsToarch( $logRoot, -1, "ctrl" ) ) {
		logIt ( "Total " . count( $logs ) . " Control logs found in log directory.", $sr );
		pIt ( "Reading Control log file lines... ", NULL, $GLOBALS["showDots"] );
		$dots = 0;
		foreach ( $logs as $logName ) {
			$dots++;
			if ( $totParsed[$logName] = slurpLog( slashDir( $logRoot ) . $logName ) ) {
				dot( $dots );
				$allParsed = array_merge( $allParsed, explode( "\n", $totParsed[$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 Control log file contents" );
	unset( $totParsed );
	memUse( "Discarded Control log file contents" );
	logIt ( "Total " . count( $allParsed ) . " Control log lines.", $sr );
	$grep = "/" . implode( "\t", array_fill( 0, 5, "\\\"([\\S\\s^\\\"]*?)\\\"" ) ) . ".*?/";
	pIt ( "Parsing Control log entries... ", NULL, $GLOBALS["showDots"] );
	$dots = 0;
	$keyCount = 0;
	foreach ( $allParsed as $logLine ) {
		$dots++;
		if ( preg_match( $grep, $logLine, $logItems ) ) {
			$keyCount++;
			dot( $dots, NULL, NULL, $GLOBALS["dotsPer"] * $GLOBALS["dotsPerEntry"] );
			if ( $logItems[5] == "REQ" ) {
				$all['ip'][] = $logItems[1];
				$all['scores']['ip'][$keyCount] = $logItems[1];
				$all['user'][] = $logItems[2];
				$all['scores']['user'][$keyCount] = $logItems[2];
			} else {
				$all[$logItems[5]][] = $logItems[2];
				$all['scores'][$logItems[5]][$keyCount] = $logItems[2];
			}
		} else {
			dot( $dots, "E", NULL, $GLOBALS["dotsPer"] * $GLOBALS["dotsPerEntry"] );
		}
	}
	pIt ( " Done." . PHP_EOL, NULL, $GLOBALS["showDots"] );
	unset( $allParsed );
	memUse( "Created Control entry array" );
	$entsNum = count( $all['ip'] );
	$report = "Total " . $entsNum . " Control entries found in logs.";
	logIt ( $report, $sr );
	$titles = array(
		"report" => "Control",
		"AUTH" => "Authenticated Requests",
		"FAIL" => "Failed Requests",
		"ip" => "Requesting IP Addresses",
		"user" => "Requesting Users",
		);
	highScores ( $all['scores'], $titles );
	unset( $all );
	memUse( "Discarded Control entry array" );
	return $retVal;
}

?>
Return current item: XMail Log Archiver