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

Bugtracker #3543 (added file locking - only option although may not work will all PHP implementations), #3734 plus a bit of tidying up

This commit is contained in:
e107steved
2007-02-10 15:54:47 +00:00
parent b1c6195382
commit 9cf595d9b3
6 changed files with 173 additions and 98 deletions

View File

@@ -11,8 +11,8 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/consolidate.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/log/consolidate.php,v $
| $Revision: 1.8 $ | $Revision: 1.9 $
| $Date: 2007-01-30 21:43:27 $ | $Date: 2007-02-10 15:54:47 $
| $Author: e107steved $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -30,7 +30,8 @@ $ifileprev = "logi_".$yesterday.".php";
$ifile = "logi_".$date.".php"; $ifile = "logi_".$date.".php";
if(file_exists($pathtologs.$pfile)) if(file_exists($pathtologs.$pfile))
{ /* log file is up to date, no consolidation required */ {
/* log file is up to date, no consolidation required */
return; return;
} }
else if(!file_exists($pathtologs.$pfileprev)) else if(!file_exists($pathtologs.$pfileprev))
@@ -220,7 +221,7 @@ createLog();
function createLog($mode="default") function createLog($mode="default")
{ {
global $pathtologs, $statTotal, $statUnique, $pageArray, $pfile, $ifile; global $pathtologs, $statTotal, $statUnique, $pfile, $ifile;
if(!is_writable($pathtologs)) if(!is_writable($pathtologs))
{ {
echo "Log directory is not writable - please CHMOD ".e_PLUGIN."log/logs to 777"; echo "Log directory is not writable - please CHMOD ".e_PLUGIN."log/logs to 777";
@@ -241,19 +242,6 @@ function createLog($mode="default")
$varStart."osInfo = array();\n". $varStart."osInfo = array();\n".
$varStart."pageInfo = array(\n"; $varStart."pageInfo = array(\n";
if($mode == "default")
{
reset($pageArray);
$loop = FALSE;
foreach($pageArray as $key => $info) {
if($loop) {
$data .= ",\n";
}
$data .= $quote.$key.$quote." => array('url' => '".$info['url']."', 'ttl' => 0, 'unq' => 0, 'ttlv' => ".$info['ttlv'].", 'unqv' => ".$info['unqv'].")";
$loop = TRUE;
}
}
$data .= "\n);\n\n?". chr(62); $data .= "\n);\n\n?". chr(62);
if(!touch($pathtologs.$pfile)) { if(!touch($pathtologs.$pfile)) {

View File

@@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/languages/admin/English.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/log/languages/admin/English.php,v $
| $Revision: 1.1.1.1 $ | $Revision: 1.2 $
| $Date: 2006-12-02 04:35:30 $ | $Date: 2007-02-10 15:54:47 $
| $Author: mcfly_e107 $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -45,7 +45,7 @@ define("ADSTAT_L23", "logs from a previous version of e107 have been detected, u
define("ADSTAT_L24", "Go to update script"); define("ADSTAT_L24", "Go to update script");
define("ADSTAT_L25", "Selected stats reset"); define("ADSTAT_L25", "Selected stats reset");
define("ADSTAT_L26", "Remove page entries"); define("ADSTAT_L26", "Remove page entries");
define("ADSTAT_L27", "if your stats have incorrect pages, you can remove them here"); define("ADSTAT_L27", "If your stats have incorrect pages, you can remove them here");
define("ADSTAT_L28", "Open page"); define("ADSTAT_L28", "Open page");
@@ -53,9 +53,8 @@ define("ADSTAT_L29", "Page Name");
define("ADSTAT_L30", "Check to remove"); define("ADSTAT_L30", "Check to remove");
define("ADSTAT_L31", "Remove selected pages"); define("ADSTAT_L31", "Remove selected pages");
define("ADSTAT_L32", "Page Tidy"); define("ADSTAT_L32", "Page Tidy");
//define("ADSTAT_L10", "Referrers");
//define("ADSTAT_L10", "Referrers");
define("ADSTAT_L33", "Configure Statistics Logging");
?> ?>

View File

@@ -10,13 +10,21 @@
| Released under the terms and conditions of the | Released under the terms and conditions of the
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| File locking, modified getip() 18.01.07
|
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/log.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/log/log.php,v $
| $Revision: 1.1.1.1 $ | $Revision: 1.2 $
| $Date: 2006-12-02 04:35:27 $ | $Date: 2007-02-10 15:54:47 $
| $Author: mcfly_e107 $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
// File called with:
// e_PLUGIN_ABS."log/log.php?referer=' + ref + '&color=' + colord + '&eself=' + eself + '&res=' + res + '\">' );\n";
// referer= ref
// color= colord
// eself= eself
// res= res
define("log_INIT", TRUE); define("log_INIT", TRUE);
$colour = strip_tags((isset($_REQUEST['color']) ? $_REQUEST['color'] : '')); $colour = strip_tags((isset($_REQUEST['color']) ? $_REQUEST['color'] : ''));
$res = strip_tags((isset($_REQUEST['res']) ? $_REQUEST['res'] : '')); $res = strip_tags((isset($_REQUEST['res']) ? $_REQUEST['res'] : ''));
@@ -24,7 +32,8 @@ $self = strip_tags((isset($_REQUEST['eself']) ? $_REQUEST['eself'] : ''));
$ref = addslashes(strip_tags((isset($_REQUEST['referer']) ? $_REQUEST['referer'] : ''))); $ref = addslashes(strip_tags((isset($_REQUEST['referer']) ? $_REQUEST['referer'] : '')));
$date = date("z.Y", time()); $date = date("z.Y", time());
if(strstr($ref, "admin")) { if(strstr($ref, "admin"))
{
$ref = FALSE; $ref = FALSE;
} }
@@ -32,15 +41,15 @@ $screenstats = $res."@".$colour;
$agent = $_SERVER['HTTP_USER_AGENT']; $agent = $_SERVER['HTTP_USER_AGENT'];
$ip = getip(); $ip = getip();
$oldref = $ref; // backup for search string being stripped of for referer $oldref = $ref; // backup for search string being stripped off for referer
if($ref && !strstr($ref, $_SERVER['HTTP_HOST'])) { if($ref && !strstr($ref, $_SERVER['HTTP_HOST']))
if(preg_match("#http://(.*?)($|/)#is", $ref, $match)) { {
$ref = $match[0]; if(preg_match("#http://(.*?)($|/)#is", $ref, $match))
} {
$ref = $match[0];
}
} }
$infodata = time().chr(1).$ip.chr(1).$agent.chr(1).$colour.chr(1).$res.chr(1).$self.chr(1).$ref."\n";
$pageDisallow = "cache|file|eself|admin"; $pageDisallow = "cache|file|eself|admin";
$tagRemove = "(\\\)|(\s)|(\')|(\")|(eself)|( )|(\.php)|(\.html)"; $tagRemove = "(\\\)|(\s)|(\')|(\")|(eself)|( )|(\.php)|(\.html)";
$tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|( )"; $tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|( )";
@@ -55,35 +64,56 @@ if(preg_match("/".$pageDisallow."/i", $pageName)) return;
$logPfile = "logs/logp_".$date.".php"; $logPfile = "logs/logp_".$date.".php";
require_once($logPfile);
$flag = FALSE; $p_handle = fopen($logPfile, 'r+');
if(array_key_exists($pageName, $pageInfo)) { if($p_handle && flock( $p_handle, LOCK_EX ) )
$pageInfo[$pageName]['ttl'] ++; {
} else { $log_file_contents = '';
$url = preg_replace("/".$tagRemove2."/si", "", $self); while (!feof($p_handle))
if(preg_match("/".$pageDisallow."/i", $url)) return; { // Assemble a string of data
$pageInfo[$pageName] = array('url' => $url, 'ttl' => 1, 'unq' => 1); $log_file_contents.= fgets($p_handle,1000);
$flag = TRUE; }
$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 />";
}
else
{
echo "Couldn't log data<br /><br /><br /><br />";
exit;
} }
if(!strstr($ipAddresses, $ip)) {
/* unique visit */ $flag = FALSE;
if(!$flag) { if(array_key_exists($pageName, $pageInfo))
$pageInfo[$pageName]['unq'] ++; { // Existing page - just increment stats
} $pageInfo[$pageName]['ttl'] ++;
$siteUnique ++; }
$ipAddresses .= $ip."."; else
require_once("loginfo.php"); { // First access of page
$url = preg_replace("/".$tagRemove2."/si", "", $self);
if(preg_match("/".$pageDisallow."/i", $url)) return;
$pageInfo[$pageName] = array('url' => $url, 'ttl' => 1, 'unq' => 1);
$flag = TRUE;
}
if(!strstr($ipAddresses, $ip))
{ /* unique visit */
if(!$flag)
{
$pageInfo[$pageName]['unq'] ++;
}
$siteUnique ++;
$ipAddresses .= $ip."."; // IP address is stored as hex string
require_once("loginfo.php");
} }
$siteTotal ++; $siteTotal ++;
$info_data = var_export($pageInfo, true); $info_data = var_export($pageInfo, true);
$date_stamp = date("z:Y", time()); //$date_stamp = date("z:Y", time()); // Same as '$date' variable
$data = "<?php $data = "<?php
/* e107 website system: Log file: {$date_stamp} */ /* e107 website system: Log file: {$date} */
\$ipAddresses = '{$ipAddresses}'; \$ipAddresses = '{$ipAddresses}';
\$siteTotal = '{$siteTotal}'; \$siteTotal = '{$siteTotal}';
@@ -93,30 +123,51 @@ $data = "<?php
?>"; ?>";
if ($handle = fopen($logPfile, 'w')) { if ($p_handle)
fwrite($handle, $data); {
ftruncate( $p_handle, 0 );
fseek( $p_handle, 0 );
fwrite($p_handle, $data);
fclose($p_handle);
} }
fclose($handle);
function getip($mode=TRUE) {
if (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = $_SERVER['REMOTE_ADDR']; function getip($mode=TRUE)
if (preg_match("/^([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+)/", getenv('HTTP_X_FORWARDED_FOR'), $ip3)) { {
$ip2 = array('/^0\./', '/^127\.0\.0\.1/', '/^192\.168\..*/', '/^172\.16\..*/', '/^10..*/', '/^224..*/', '/^240..*/'); if (getenv('HTTP_X_FORWARDED_FOR'))
$ip = preg_replace($ip2, $ip, $ip3[1]); {
} $ip = $_SERVER['REMOTE_ADDR'];
} else { if (preg_match("#^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})#", getenv('HTTP_X_FORWARDED_FOR'), $ip3))
$ip = $_SERVER['REMOTE_ADDR']; {
} $ip2 = array('#^0\..*#',
if ($ip == "") { '#^127\..*#', // Local loopbacks
$ip = "x.x.x.x"; '#^192\.168\..*#', // RFC1918 - Private Network
} '#^172\.(?:1[6789]|2\d|3[01])\..*#', // RFC1918 - Private network
if($mode) { '#^10\..*#', // RFC1918 - Private Network
$ipa = explode(".", $ip); '#^169\.254\..*#', // RFC3330 - Link-local, auto-DHCP
return sprintf('%02x%02x%02x%02x', $ipa[0], $ipa[1], $ipa[2], $ipa[3]); '#^2(?:2[456789]|[345][0-9])\..*#' // Single check for Class D and Class E
} else { );
return $ip; $ip = preg_replace($ip2, $ip, $ip3[1]);
} }
}
else
{
$ip = $_SERVER['REMOTE_ADDR'];
}
if ($ip == "")
{
$ip = "x.x.x.x";
}
if($mode)
{
$ipa = explode(".", $ip);
return sprintf('%02x%02x%02x%02x', $ipa[0], $ipa[1], $ipa[2], $ipa[3]);
}
else
{
return $ip;
}
} }
?> ?>

View File

@@ -11,26 +11,48 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/loginfo.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/log/loginfo.php,v $
| $Revision: 1.2 $ | $Revision: 1.3 $
| $Date: 2006-12-19 14:28:51 $ | $Date: 2007-02-10 15:54:47 $
| $Author: e107coders $ | $Author: e107steved $
|
| File locking added
|
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
if (!defined('log_INIT')) { exit; } if (!defined('log_INIT')) { exit; }
$logIfile = "logs/logi_{$date}.php"; $logIfile = "logs/logi_{$date}.php";
require_once($logIfile); $i_handle = fopen($logIfile, 'r+');
if($i_handle && flock( $i_handle, LOCK_EX ) )
{
$log_file_contents = '';
while (!feof($i_handle))
{ // Assemble a string of data
$log_file_contents.= fgets($i_handle,1000);
}
$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 />";
}
else
{
echo "Couldn't log data<br /><br /><br /><br />";
exit;
}
$browser = getBrowser($agent); $browser = getBrowser($agent);
$os = getOs($agent); $os = getOs($agent);
if($screenstats && $screenstats != "@") { if($screenstats && $screenstats != "@")
if(array_key_exists($screenstats, $screenInfo)) { {
$screenInfo[$screenstats] ++; if(array_key_exists($screenstats, $screenInfo))
} else { {
$screenInfo[$screenstats] = 1; $screenInfo[$screenstats] ++;
} }
else
{
$screenInfo[$screenstats] = 1;
}
} }
if(array_key_exists($browser, $browserInfo)) { if(array_key_exists($browser, $browserInfo)) {
@@ -109,13 +131,17 @@ $data .= '$searchInfo = '.var_export($searchInfo, true).";\n\n";
$data .= '$visitInfo = '.var_export($visitInfo, true).";\n\n"; $data .= '$visitInfo = '.var_export($visitInfo, true).";\n\n";
$data .= '?>'; $data .= '?>';
if ($handle = fopen($logIfile, 'w')) {
fwrite($handle, $data); if ($i_handle)
{
ftruncate($i_handle, 0);
fseek( $i_handle, 0 );
fwrite($i_handle, $data);
fclose($i_handle);
} }
fclose($handle);
function getBrowser($agent) { function getBrowser($agent) {
// //
// All "root" browsers must come at the end of the list, unfortunately. // All "root" browsers must come at the end of the list, unfortunately.
// Otherwise, browsers based on them will never be seen. // Otherwise, browsers based on them will never be seen.

View File

@@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/plugin.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/log/plugin.php,v $
| $Revision: 1.1.1.1 $ | $Revision: 1.2 $
| $Date: 2006-12-02 04:35:27 $ | $Date: 2007-02-10 15:54:47 $
| $Author: mcfly_e107 $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
@@ -45,11 +45,22 @@ $eplug_conffile = "admin_config.php";
// Icon image and caption text ------------------------------------------------------------------------------------ // Icon image and caption text ------------------------------------------------------------------------------------
$eplug_icon = $eplug_folder."/images/stats_32.png"; $eplug_icon = $eplug_folder."/images/stats_32.png";
$eplug_icon_small = $eplug_folder."/images/stats_16.png"; $eplug_icon_small = $eplug_folder."/images/stats_16.png";
$eplug_caption = "Configure Statitics Logging"; $eplug_caption = ADSTAT_L33;
// List of preferences ----------------------------------------------------------------------------------------------- // List of preferences -----------------------------------------------------------------------------------------------
$eplug_prefTable = "menu_pref"; $eplug_prefTable = "menu_pref";
$eplug_prefs = array("statActivate" => 0, "statUserclass" => "", "statClass" => 0, "statBrowser" => 1, "statOs" => 1, "statScreen" => 1, "statDomain" => 1, "statRefer" => 1, "statQuery" => 1, "statRecent" => 1); $eplug_prefs = array(
"statActivate" => 0,
"statUserclass" => "",
"statClass" => 0,
"statBrowser" => 1,
"statOs" => 1,
"statScreen" => 1,
"statDomain" => 1,
"statRefer" => 1,
"statQuery" => 1,
"statRecent" => 1
);
// List of table names ----------------------------------------------------------------------------------------------- // List of table names -----------------------------------------------------------------------------------------------
$eplug_table_names = array("logstats"); $eplug_table_names = array("logstats");

View File

@@ -11,9 +11,9 @@
| GNU General Public License (http://gnu.org). | GNU General Public License (http://gnu.org).
| |
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/stats.php,v $ | $Source: /cvs_backup/e107_0.8/e107_plugins/log/stats.php,v $
| $Revision: 1.1.1.1 $ | $Revision: 1.2 $
| $Date: 2006-12-02 04:35:28 $ | $Date: 2007-02-10 15:54:47 $
| $Author: mcfly_e107 $ | $Author: e107steved $
+----------------------------------------------------------------------------+ +----------------------------------------------------------------------------+
*/ */
require_once("../../class2.php"); require_once("../../class2.php");
@@ -133,10 +133,10 @@ $country["arpa"] = "ARPANet";
$country["com"] = "Commercial Users"; $country["com"] = "Commercial Users";
$country["edu"] = "Education"; $country["edu"] = "Education";
$country["gov"] = "Government"; $country["gov"] = "Government";
$country["int"] = "Oganization established by an International Treaty"; $country["int"] = "Organisation established by an International Treaty";
$country["mil"] = "Military"; $country["mil"] = "Military";
$country["net"] = "Network"; $country["net"] = "Network";
$country["org"] = "Organization"; $country["org"] = "Organisation";
$country["ad"] = "Andorra"; $country["ad"] = "Andorra";
$country["ae"] = "United Arab Emirates"; $country["ae"] = "United Arab Emirates";
$country["af"] = "Afghanistan"; $country["af"] = "Afghanistan";