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

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

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

#
# the reports code belongs below
function reportFinger ( $logRoot ) {
	$sr = "FINGER-REPORT";
	$begun = ( isset( $GLOBALS["begun"] ) ) ? ( $GLOBALS["begun"] ) : ( date( _dateFmt ) );
	logIt( "Finger Log report for " . date( _dateFmt, $begun ) . ":", $sr );
	memUse( "Finger Reporting started" );
	$allParsed = array();
	if ( $logs = getLogsToarch( $logRoot, -1, "finger" ) ) {
		logIt ( "Total " . count( $logs ) . " Finger logs found in log directory.", $sr );
		pIt ( "Reading Finger 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 Finger log file contents" );
	unset( $totParsed );
	memUse( "Discarded Finger log file contents" );
	logIt ( "Total " . count( $allParsed ) . " Control log lines.", $sr );
	$grep = "/" . implode( "\t", array_fill( 0, 5, "\\\"([\\S\\s^\\\"]*?)\\\"" ) ) . ".*?/";
	pIt ( "Parsing Finger 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"] );
			$all['clientIp'][] = $logItems[3];
			$all['scores']['clientIp'][$keyCount] = $logItems[3];
			$all['host'][] = $logItems[1] . "." . $logItems[2];
			$all['scores']['host'][$keyCount] = $logItems[1] . "." . $logItems[2];
			$all['query'][] = $logItems[5];
			$all['scores']['query'][$keyCount] = $logItems[5];
		} else {
			dot( $dots, "E", NULL, $GLOBALS["dotsPer"] * $GLOBALS["dotsPerEntry"] );
		}
	}
	# This comment left intentionally blank - ...
	# This comment is here to enhance the compression ratio of this zip file which it also specifies for the above comment (does not improve output size of this zip file) :P
	pIt ( " Done." . PHP_EOL, NULL, $GLOBALS["showDots"] );
	unset( $allParsed );
	memUse( "Created Finger entry array" );
	$entsNum = count( $all['clientIp'] );
	$report = "Total " . $entsNum . " Control entries found in logs.";
	logIt ( $report, $sr );
	$titles = array(
		"report" => "Finger Logs",
		"clientIp" => "Client IP Addresses",
		"host" => "Finger Hosts",
		"query" => "Finger Query",
		);
	highScores ( $all['scores'], $titles );
	unset( $all );
	memUse( "Discarded Finger entry array" );
	return $retVal;
}

?>
Return current item: XMail Log Archiver