1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-02 20:57:26 +02:00

Bugtracker #4925 - monthly stats were being double counted

Also some notice removal
This commit is contained in:
e107steved
2010-03-13 22:14:30 +00:00
parent eeee1e20cd
commit c03a06be82
2 changed files with 264 additions and 249 deletions

View File

@@ -1,241 +1,257 @@
<?php <?php
/* /*
* e107 website system * e107 website system
* *
* Copyright (C) 2008-2009 e107 Inc (e107.org) * Copyright (C) 2008-2009 e107 Inc (e107.org)
* Released under the terms and conditions of the * Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt) * GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
* *
* Administration Area - User classes * Administration Area - User classes
* *
* $Source: /cvs_backup/e107_0.8/e107_plugins/log/log.php,v $ * $Source: /cvsroot/e107/e107_0.8/e107_plugins/log/log.php,v $
* $Revision$ * $Revision$
* $Date$ * $Date$
* $Author$ * $Author$
* *
*/ */
/* File to log page accesses - called with /* File to log page accesses - called with
e_PLUGIN_ABS."log/log.php?base64encode(referer=' + ref + '&color=' + colord + '&eself=' + eself + '&res=' + res + '\">' );)"; e_PLUGIN_ABS."log/log.php?base64encode(referer=' + ref + '&color=' + colord + '&eself=' + eself + '&res=' + res + '\">' );)";
referer= ref referer= ref
color= colord color= colord
eself= eself eself= eself
res= res res= res
err_direct - optional error flag err_direct - optional error flag
err_referer - referrer if came via error page err_referer - referrer if came via error page
qry = 1 to log query part as well
// Normally the file is 'silent' - if any errors occur, not sure where they'll appear - (file type now text/html instead of text/css)
*/ // Normally the file is 'silent' - if any errors occur, not sure where they'll appear - (file type now text/html instead of text/css)
define('log_INIT', TRUE); */
define('log_INIT', TRUE);
$logVals = urldecode(base64_decode($_SERVER['QUERY_STRING']));
parse_str($logVals, $vals); // Array of page names which should have individual query values recorded.
// The top level array index is the page name.
echo "\n"; // This is harmless data which seems to avoid intermittent problems. // If the top level value is an array, it must be an array of query string beginnings to match.
$pageUnique = array('page' => 1, 'content' => array('content'));
//$logfp = fopen('logs/rcvstring.txt', 'a+'); fwrite($logfp, $logVals."\n"); fclose($logfp);
//$logfp = fopen('logs/rcvstring.txt', 'a+'); fwrite($logfp, print_r($vals, TRUE)."\n"); fclose($logfp);
$logVals = urldecode(base64_decode($_SERVER['QUERY_STRING']));
$colour = strip_tags((isset($vals['colour']) ? $vals['colour'] : '')); parse_str($logVals, $vals);
$res = strip_tags((isset($vals['res']) ? $vals['res'] : ''));
$self = strip_tags((isset($vals['eself']) ? $vals['eself'] : ''));
$ref = addslashes(strip_tags((isset($vals['referer']) ? $vals['referer'] : ''))); header('Cache-Control: no-cache, must-revalidate'); // See if this discourages browser caching
$date = date("z.Y", time()); header('Expires: Sat, 26 Jul 1997 05:00:00 GMT'); // Date in the past
$logPfile = "logs/logp_".$date.".php";
//$logfp = fopen('logs/rcvstring.txt', 'a+'); fwrite($logfp, $logVals."\n"); fclose($logfp);
//$logString = "Colour: {$colour} Res: {$res} Self: {$self} Referrer: {$ref} ErrCode: {$vals['err_direct']}\n"; //$logfp = fopen('logs/rcvstring.txt', 'a+'); fwrite($logfp, print_r($vals, TRUE)."\n"); fclose($logfp);
//$logfp = fopen('logs/rcvstring.txt', 'a+'); fwrite($logfp, $logString); fclose($logfp);
$colour = strip_tags((isset($vals['colour']) ? $vals['colour'] : ''));
$res = strip_tags((isset($vals['res']) ? $vals['res'] : ''));
// vet resolution and colour depth some more - avoid dud values $self = strip_tags((isset($vals['eself']) ? $vals['eself'] : ''));
if ($res && preg_match("#.*?((\d+)\w+?(\d+))#", $res, $match)) $ref = addslashes(strip_tags((isset($vals['referer']) ? $vals['referer'] : '')));
{ $logQry = isset($vals['qry']) && $vals['qry'];
$res = $match[2].'x'.$match[3];
} $date = date('z.Y', time());
else $logPfile = 'logs/logp_'.$date.'.php';
{
$res = '??'; // Can't decode resolution //$logString = "Colour: {$colour} Res: {$res} Self: {$self} Referrer: {$ref} ErrCode: {$vals['err_direct']}\n";
} //$logfp = fopen('logs/rcvstring.txt', 'a+'); fwrite($logfp, $logString); fclose($logfp);
if ($colour && preg_match("#.*?(\d+)#",$colour,$match))
{ // vet resolution and colour depth some more - avoid dud values
$colour = intval($match[1]); if ($res && preg_match("#.*?((\d+)\w+?(\d+))#", $res, $match))
} {
else $res = $match[2].'x'.$match[3];
{ }
$colour='??'; else
} {
$res = '??'; // Can't decode resolution
}
if ($err_code = strip_tags((isset($vals['err_direct']) ? $vals['err_direct'] : '')))
{ if ($colour && preg_match("#.*?(\d+)#",$colour,$match))
$ref = addslashes(strip_tags(isset($vals['err_referer']) ? $vals['err_referer'] : '')); {
// Uncomment the next two lines to create a separate CSV format log of invalid accesses - error code, entered URL, referrer $colour = intval($match[1]);
// $log_string = $err_code.",".$self.",".$ref; }
// $logfp = fopen("logs/errpages.csv", 'a+'); fwrite($logfp, $log_string."\n\r"); fclose($logfp); else
$err_code .= ':'; {
} $colour='??';
}
if(strstr($ref, 'admin'))
{
$ref = FALSE; if ($err_code = strip_tags((isset($vals['err_direct']) ? $vals['err_direct'] : '')))
} {
$ref = addslashes(strip_tags(isset($vals['err_referer']) ? $vals['err_referer'] : ''));
$screenstats = $res.'@'.$colour; // Uncomment the next two lines to create a separate CSV format log of invalid accesses - error code, entered URL, referrer
$agent = $_SERVER['HTTP_USER_AGENT']; // $log_string = $err_code.",".$self.",".$ref;
$ip = getip(); // $logfp = fopen("logs/errpages.csv", 'a+'); fwrite($logfp, $log_string."\n\r"); fclose($logfp);
$err_code .= ':';
$oldref = $ref; // backup for search string being stripped off for referer }
if($ref && !strstr($ref, $_SERVER['HTTP_HOST']))
{ if(strstr($ref, 'admin'))
if(preg_match("#http://(.*?)($|/)#is", $ref, $match)) {
{ $ref = FALSE;
$ref = $match[0]; }
}
} $screenstats = $res.'@'.$colour;
$agent = $_SERVER['HTTP_USER_AGENT'];
$pageDisallow = "cache|file|eself|admin"; $ip = getip();
$tagRemove = "(\\\)|(\s)|(\')|(\")|(eself)|(&nbsp;)|(\.php)|(\.html)";
$tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|(&nbsp;)"; $oldref = $ref; // backup for search string being stripped off for referer
if($ref && !strstr($ref, $_SERVER['HTTP_HOST']))
preg_match("#/(.*?)(\?|$)#si", $self, $match); {
$match[1] = isset($match[1]) ? $match[1] : ''; if(preg_match("#http://(.*?)($|/)#is", $ref, $match))
$pageName = substr($match[1], (strrpos($match[1], "/")+1)); {
$PN = $pageName; $ref = $match[0];
$pageName = preg_replace("/".$tagRemove."/si", "", $pageName); }
if($pageName == "") $pageName = "index"; }
$pageName = $err_code.$pageName; // Add the error code at the beginning, so its treated uniquely $pageDisallow = "cache|file|eself|admin";
$tagRemove = "(\\\)|(\s)|(\')|(\")|(eself)|(&nbsp;)|(\.php)|(\.html)";
if(preg_match("/".$pageDisallow."/i", $pageName)) return; $tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|(&nbsp;)";
preg_match("#/(.*?)(\?|$)(.*)#si", $self, $match);
$p_handle = fopen($logPfile, 'r+'); $match[1] = isset($match[1]) ? $match[1] : '';
if($p_handle && flock( $p_handle, LOCK_EX ) ) $pageName = substr($match[1], (strrpos($match[1], "/")+1));
{ $PN = $pageName;
$log_file_contents = ''; $pageName = preg_replace("/".$tagRemove."/si", "", $pageName);
while (!feof($p_handle)) if($pageName == "") $pageName = "index";
{ // Assemble a string of data
$log_file_contents.= fgets($p_handle,1000); if(preg_match("/".$pageDisallow."/i", $pageName)) return;
}
$log_file_contents = str_replace(array('<'.'?php','?'.'>'),'',$log_file_contents);
if (eval($log_file_contents) === FALSE) echo "error in log file contents<br /><br /><br /><br />"; if ($logQry)
} {
else $pageName .= '+'.$match[3]; // All queries match
{ }
echo "Couldn't log data<br /><br /><br /><br />"; $pageName = $err_code.$pageName; // Add the error code at the beginning, so its treated uniquely
exit; //$logfp = fopen('logs/rcvstring.txt', 'a+'); fwrite($logfp, $pageName."\n"); fclose($logfp);
}
$p_handle = fopen($logPfile, 'r+');
if($p_handle && flock( $p_handle, LOCK_EX ) )
$flag = FALSE; {
if(array_key_exists($pageName, $pageInfo)) $log_file_contents = '';
{ // Existing page - just increment stats while (!feof($p_handle))
$pageInfo[$pageName]['ttl'] ++; { // Assemble a string of data
} $log_file_contents.= fgets($p_handle,1000);
else }
{ // First access of page $log_file_contents = str_replace(array('<'.'?php','?'.'>'),'',$log_file_contents);
$url = preg_replace("/".$tagRemove2."/si", "", $self); if (eval($log_file_contents) === FALSE) echo "error in log file contents<br /><br /><br /><br />";
if(preg_match("/".$pageDisallow."/i", $url)) return; }
$pageInfo[$pageName] = array('url' => $url, 'ttl' => 1, 'unq' => 1); else
$flag = TRUE; {
} echo "Couldn't log data<br /><br /><br /><br />";
exit;
if(!strstr($ipAddresses, $ip)) }
{ /* unique visit */
if(!$flag)
{ $flag = FALSE;
$pageInfo[$pageName]['unq'] ++; if(array_key_exists($pageName, $pageInfo))
} { // Existing page - just increment stats
$siteUnique ++; $pageInfo[$pageName]['ttl'] ++;
$ipAddresses .= $ip."."; // IP address is stored as hex string }
require_once("loginfo.php"); else
} { // First access of page
$url = preg_replace("/".$tagRemove2."/si", "", $self);
if(preg_match("/".$pageDisallow."/i", $url)) return;
$siteTotal ++; $pageInfo[$pageName] = array('url' => $url, 'ttl' => 1, 'unq' => 1);
$info_data = var_export($pageInfo, true); $flag = TRUE;
//$date_stamp = date("z:Y", time()); // Same as '$date' variable }
$data = "<?php if(!strstr($ipAddresses, $ip))
{ /* unique visit */
/* e107 website system: Log file: {$date} */ if(!$flag)
{
\$ipAddresses = '{$ipAddresses}'; $pageInfo[$pageName]['unq'] ++;
\$siteTotal = '{$siteTotal}'; }
\$siteUnique = '{$siteUnique}'; $siteUnique ++;
$ipAddresses .= $ip."."; // IP address is stored as hex string
\$pageInfo = {$info_data}; require_once("loginfo.php");
}
?>";
if ($p_handle) $siteTotal ++;
{ $info_data = var_export($pageInfo, true);
ftruncate( $p_handle, 0 ); //$date_stamp = date("z:Y", time()); // Same as '$date' variable
fseek( $p_handle, 0 );
fwrite($p_handle, $data); $data = "<?php
fclose($p_handle);
} /* e107 website system: Log file: {$date} */
\$ipAddresses = '{$ipAddresses}';
// Get current IP address - return as a hex-encoded string \$siteTotal = '{$siteTotal}';
function getip() \$siteUnique = '{$siteUnique}';
{
$ip = $_SERVER['REMOTE_ADDR']; \$pageInfo = {$info_data};
if (getenv('HTTP_X_FORWARDED_FOR'))
{ ?>";
if (preg_match("#^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})#", getenv('HTTP_X_FORWARDED_FOR'), $ip3))
{ if ($p_handle)
$ip2 = array('#^0\..*#', {
'#^127\..*#', // Local loopbacks ftruncate( $p_handle, 0 );
'#^192\.168\..*#', // RFC1918 - Private Network fseek( $p_handle, 0 );
'#^172\.(?:1[6789]|2\d|3[01])\..*#', // RFC1918 - Private network fwrite($p_handle, $data);
'#^10\..*#', // RFC1918 - Private Network fclose($p_handle);
'#^169\.254\..*#', // RFC3330 - Link-local, auto-DHCP }
'#^2(?:2[456789]|[345][0-9])\..*#' // Single check for Class D and Class E
);
$ip = preg_replace($ip2, $ip, $ip3[1]); // Get current IP address - return as a hex-encoded string
} function getip()
} {
if ($ip == "") $ip = $_SERVER['REMOTE_ADDR'];
{ if (getenv('HTTP_X_FORWARDED_FOR'))
$ip = "x.x.x.x"; {
} if (preg_match("#^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})#", getenv('HTTP_X_FORWARDED_FOR'), $ip3))
if (strpos($ip, ':') === FALSE) {
{ // Its an IPV4 address - return it as 32-character packed hex string $ip2 = array('#^0\..*#',
$ipa = explode(".", $ip); '#^127\..*#', // Local loopbacks
return str_repeat('0000',5).'ffff'.sprintf('%02x%02x%02x%02x', $ipa[0], $ipa[1], $ipa[2], $ipa[3]); '#^192\.168\..*#', // RFC1918 - Private Network
} '#^172\.(?:1[6789]|2\d|3[01])\..*#', // RFC1918 - Private network
else '#^10\..*#', // RFC1918 - Private Network
{ // Its IPV6 '#^169\.254\..*#', // RFC3330 - Link-local, auto-DHCP
if (strpos($ip,'.') !== FALSE) '#^2(?:2[456789]|[345][0-9])\..*#' // Single check for Class D and Class E
{ // IPV4 'tail' to deal with );
$temp = strrpos($ip,':') +1; $ip = preg_replace($ip2, $ip, $ip3[1]);
$ipa = explode('.',substr($ip,$temp)); }
$ip = substr($ip,0, $temp).sprintf('%02x%02x:%02x%02x', $ipa[0], $ipa[1], $ipa[2], $ipa[3]); }
} if ($ip == "")
// Now 'normalise' the address {
$temp = explode(':',$ip); $ip = "x.x.x.x";
$s = 8 - count($temp); // One element will of course be the blank }
foreach ($temp as $f) if (strpos($ip, ':') === FALSE)
{ { // Its an IPV4 address - return it as 32-character packed hex string
if ($f == '') $ipa = explode(".", $ip);
{ return str_repeat('0000',5).'ffff'.sprintf('%02x%02x%02x%02x', $ipa[0], $ipa[1], $ipa[2], $ipa[3]);
$ret .= '0000'; // Always put in one set of zeros for the blank }
if ($s > 0) else
{ { // Its IPV6
$ret .= str_repeat('0000',$s); if (strpos($ip,'.') !== FALSE)
$s = 0; { // IPV4 'tail' to deal with
} $temp = strrpos($ip,':') +1;
} $ipa = explode('.',substr($ip,$temp));
else $ip = substr($ip,0, $temp).sprintf('%02x%02x:%02x%02x', $ipa[0], $ipa[1], $ipa[2], $ipa[3]);
{ }
$ret .= sprintf('%04x',hexdec($f)); // Now 'normalise' the address
} $temp = explode(':',$ip);
} $s = 8 - count($temp); // One element will of course be the blank
return $ret; foreach ($temp as $f)
} {
} if ($f == '')
{
$ret .= '0000'; // Always put in one set of zeros for the blank
if ($s > 0)
{
$ret .= str_repeat('0000',$s);
$s = 0;
}
}
else
{
$ret .= sprintf('%04x',hexdec($f));
}
}
return $ret;
}
}
?> ?>

View File

@@ -17,28 +17,27 @@
//define('CSV_DEBUG', TRUE); //define('CSV_DEBUG', TRUE);
require_once("../../class2.php"); require_once('../../class2.php');
if (!getperms("P")) if (!getperms('P'))
{ {
header("location:../index.php"); header('Location: '.e_BASE.'index.php');
exit; exit;
} }
if (e_QUERY) if (e_QUERY)
{ {
$sl_qs = explode(".", e_QUERY); $sl_qs = explode('.', e_QUERY);
} }
$action = varset($sl_qs[0],'config'); $action = varset($sl_qs[0],'config');
$params = varset($sl_qs[1],''); $params = varset($sl_qs[1],'');
if (($action != 'export') || $params) if (($action != 'export') || $params)
{ {
header("location:../index.php"); header('Location: '.e_BASE.'index.php');
exit; exit;
} }
define("LOGPATH", e_PLUGIN."log/"); include_lan(e_PLUGIN.'log/languages/'.e_LANGUAGE.'_admin_log.php'); // LANs may be needed for error messages
include_lan(LOGPATH."languages/admin/".e_LANGUAGE.".php"); // LANs may be needed for error messages
// List of the non-page-based info which is gathered - historically only 'all-time' stats, now we support monthly as well. (Here, only keys are used for validation) // List of the non-page-based info which is gathered - historically only 'all-time' stats, now we support monthly as well. (Here, only keys are used for validation)