mirror of
https://github.com/e107inc/e107.git
synced 2025-08-05 14:17:49 +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:
@@ -11,8 +11,8 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/consolidate.php,v $
|
||||
| $Revision: 1.8 $
|
||||
| $Date: 2007-01-30 21:43:27 $
|
||||
| $Revision: 1.9 $
|
||||
| $Date: 2007-02-10 15:54:47 $
|
||||
| $Author: e107steved $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
@@ -30,7 +30,8 @@ $ifileprev = "logi_".$yesterday.".php";
|
||||
$ifile = "logi_".$date.".php";
|
||||
|
||||
if(file_exists($pathtologs.$pfile))
|
||||
{ /* log file is up to date, no consolidation required */
|
||||
{
|
||||
/* log file is up to date, no consolidation required */
|
||||
return;
|
||||
}
|
||||
else if(!file_exists($pathtologs.$pfileprev))
|
||||
@@ -220,7 +221,7 @@ createLog();
|
||||
|
||||
function createLog($mode="default")
|
||||
{
|
||||
global $pathtologs, $statTotal, $statUnique, $pageArray, $pfile, $ifile;
|
||||
global $pathtologs, $statTotal, $statUnique, $pfile, $ifile;
|
||||
if(!is_writable($pathtologs))
|
||||
{
|
||||
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."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);
|
||||
|
||||
if(!touch($pathtologs.$pfile)) {
|
||||
|
@@ -11,9 +11,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/languages/admin/English.php,v $
|
||||
| $Revision: 1.1.1.1 $
|
||||
| $Date: 2006-12-02 04:35:30 $
|
||||
| $Author: mcfly_e107 $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2007-02-10 15:54:47 $
|
||||
| $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_L25", "Selected stats reset");
|
||||
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");
|
||||
|
||||
|
||||
@@ -53,9 +53,8 @@ define("ADSTAT_L29", "Page Name");
|
||||
define("ADSTAT_L30", "Check to remove");
|
||||
define("ADSTAT_L31", "Remove selected pages");
|
||||
define("ADSTAT_L32", "Page Tidy");
|
||||
//define("ADSTAT_L10", "Referrers");
|
||||
//define("ADSTAT_L10", "Referrers");
|
||||
|
||||
define("ADSTAT_L33", "Configure Statistics Logging");
|
||||
|
||||
|
||||
?>
|
@@ -10,13 +10,21 @@
|
||||
| Released under the terms and conditions of the
|
||||
| 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 $
|
||||
| $Revision: 1.1.1.1 $
|
||||
| $Date: 2006-12-02 04:35:27 $
|
||||
| $Author: mcfly_e107 $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2007-02-10 15:54:47 $
|
||||
| $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);
|
||||
$colour = strip_tags((isset($_REQUEST['color']) ? $_REQUEST['color'] : ''));
|
||||
$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'] : '')));
|
||||
$date = date("z.Y", time());
|
||||
|
||||
if(strstr($ref, "admin")) {
|
||||
if(strstr($ref, "admin"))
|
||||
{
|
||||
$ref = FALSE;
|
||||
}
|
||||
|
||||
@@ -32,15 +41,15 @@ $screenstats = $res."@".$colour;
|
||||
$agent = $_SERVER['HTTP_USER_AGENT'];
|
||||
$ip = getip();
|
||||
|
||||
$oldref = $ref; // backup for search string being stripped of for referer
|
||||
if($ref && !strstr($ref, $_SERVER['HTTP_HOST'])) {
|
||||
if(preg_match("#http://(.*?)($|/)#is", $ref, $match)) {
|
||||
$ref = $match[0];
|
||||
}
|
||||
$oldref = $ref; // backup for search string being stripped off for referer
|
||||
if($ref && !strstr($ref, $_SERVER['HTTP_HOST']))
|
||||
{
|
||||
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";
|
||||
$tagRemove = "(\\\)|(\s)|(\')|(\")|(eself)|( )|(\.php)|(\.html)";
|
||||
$tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|( )";
|
||||
@@ -55,35 +64,56 @@ if(preg_match("/".$pageDisallow."/i", $pageName)) return;
|
||||
|
||||
|
||||
$logPfile = "logs/logp_".$date.".php";
|
||||
require_once($logPfile);
|
||||
|
||||
$flag = FALSE;
|
||||
if(array_key_exists($pageName, $pageInfo)) {
|
||||
$pageInfo[$pageName]['ttl'] ++;
|
||||
} else {
|
||||
$url = preg_replace("/".$tagRemove2."/si", "", $self);
|
||||
if(preg_match("/".$pageDisallow."/i", $url)) return;
|
||||
$pageInfo[$pageName] = array('url' => $url, 'ttl' => 1, 'unq' => 1);
|
||||
$flag = TRUE;
|
||||
$p_handle = fopen($logPfile, 'r+');
|
||||
if($p_handle && flock( $p_handle, LOCK_EX ) )
|
||||
{
|
||||
$log_file_contents = '';
|
||||
while (!feof($p_handle))
|
||||
{ // Assemble a string of data
|
||||
$log_file_contents.= fgets($p_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;
|
||||
}
|
||||
|
||||
if(!strstr($ipAddresses, $ip)) {
|
||||
/* unique visit */
|
||||
if(!$flag) {
|
||||
$pageInfo[$pageName]['unq'] ++;
|
||||
}
|
||||
$siteUnique ++;
|
||||
$ipAddresses .= $ip.".";
|
||||
require_once("loginfo.php");
|
||||
|
||||
$flag = FALSE;
|
||||
if(array_key_exists($pageName, $pageInfo))
|
||||
{ // Existing page - just increment stats
|
||||
$pageInfo[$pageName]['ttl'] ++;
|
||||
}
|
||||
else
|
||||
{ // 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 ++;
|
||||
$info_data = var_export($pageInfo, true);
|
||||
$date_stamp = date("z:Y", time());
|
||||
//$date_stamp = date("z:Y", time()); // Same as '$date' variable
|
||||
|
||||
$data = "<?php
|
||||
|
||||
/* e107 website system: Log file: {$date_stamp} */
|
||||
/* e107 website system: Log file: {$date} */
|
||||
|
||||
\$ipAddresses = '{$ipAddresses}';
|
||||
\$siteTotal = '{$siteTotal}';
|
||||
@@ -93,30 +123,51 @@ $data = "<?php
|
||||
|
||||
?>";
|
||||
|
||||
if ($handle = fopen($logPfile, 'w')) {
|
||||
fwrite($handle, $data);
|
||||
if ($p_handle)
|
||||
{
|
||||
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'];
|
||||
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..*/');
|
||||
$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;
|
||||
|
||||
|
||||
function getip($mode=TRUE)
|
||||
{
|
||||
if (getenv('HTTP_X_FORWARDED_FOR'))
|
||||
{
|
||||
$ip = $_SERVER['REMOTE_ADDR'];
|
||||
if (preg_match("#^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})#", getenv('HTTP_X_FORWARDED_FOR'), $ip3))
|
||||
{
|
||||
$ip2 = array('#^0\..*#',
|
||||
'#^127\..*#', // Local loopbacks
|
||||
'#^192\.168\..*#', // RFC1918 - Private Network
|
||||
'#^172\.(?:1[6789]|2\d|3[01])\..*#', // RFC1918 - Private network
|
||||
'#^10\..*#', // RFC1918 - Private Network
|
||||
'#^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]);
|
||||
}
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@@ -11,26 +11,48 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/loginfo.php,v $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2006-12-19 14:28:51 $
|
||||
| $Author: e107coders $
|
||||
| $Revision: 1.3 $
|
||||
| $Date: 2007-02-10 15:54:47 $
|
||||
| $Author: e107steved $
|
||||
|
|
||||
| File locking added
|
||||
|
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
if (!defined('log_INIT')) { exit; }
|
||||
|
||||
$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);
|
||||
$os = getOs($agent);
|
||||
|
||||
if($screenstats && $screenstats != "@") {
|
||||
if(array_key_exists($screenstats, $screenInfo)) {
|
||||
$screenInfo[$screenstats] ++;
|
||||
} else {
|
||||
$screenInfo[$screenstats] = 1;
|
||||
}
|
||||
if($screenstats && $screenstats != "@")
|
||||
{
|
||||
if(array_key_exists($screenstats, $screenInfo))
|
||||
{
|
||||
$screenInfo[$screenstats] ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
$screenInfo[$screenstats] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
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 .= '?>';
|
||||
|
||||
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) {
|
||||
|
||||
//
|
||||
// All "root" browsers must come at the end of the list, unfortunately.
|
||||
// Otherwise, browsers based on them will never be seen.
|
||||
|
@@ -11,9 +11,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/plugin.php,v $
|
||||
| $Revision: 1.1.1.1 $
|
||||
| $Date: 2006-12-02 04:35:27 $
|
||||
| $Author: mcfly_e107 $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2007-02-10 15:54:47 $
|
||||
| $Author: e107steved $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
|
||||
@@ -45,11 +45,22 @@ $eplug_conffile = "admin_config.php";
|
||||
// Icon image and caption text ------------------------------------------------------------------------------------
|
||||
$eplug_icon = $eplug_folder."/images/stats_32.png";
|
||||
$eplug_icon_small = $eplug_folder."/images/stats_16.png";
|
||||
$eplug_caption = "Configure Statitics Logging";
|
||||
$eplug_caption = ADSTAT_L33;
|
||||
|
||||
// List of preferences -----------------------------------------------------------------------------------------------
|
||||
$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 -----------------------------------------------------------------------------------------------
|
||||
$eplug_table_names = array("logstats");
|
||||
|
@@ -11,9 +11,9 @@
|
||||
| GNU General Public License (http://gnu.org).
|
||||
|
|
||||
| $Source: /cvs_backup/e107_0.8/e107_plugins/log/stats.php,v $
|
||||
| $Revision: 1.1.1.1 $
|
||||
| $Date: 2006-12-02 04:35:28 $
|
||||
| $Author: mcfly_e107 $
|
||||
| $Revision: 1.2 $
|
||||
| $Date: 2007-02-10 15:54:47 $
|
||||
| $Author: e107steved $
|
||||
+----------------------------------------------------------------------------+
|
||||
*/
|
||||
require_once("../../class2.php");
|
||||
@@ -133,10 +133,10 @@ $country["arpa"] = "ARPANet";
|
||||
$country["com"] = "Commercial Users";
|
||||
$country["edu"] = "Education";
|
||||
$country["gov"] = "Government";
|
||||
$country["int"] = "Oganization established by an International Treaty";
|
||||
$country["int"] = "Organisation established by an International Treaty";
|
||||
$country["mil"] = "Military";
|
||||
$country["net"] = "Network";
|
||||
$country["org"] = "Organization";
|
||||
$country["org"] = "Organisation";
|
||||
$country["ad"] = "Andorra";
|
||||
$country["ae"] = "United Arab Emirates";
|
||||
$country["af"] = "Afghanistan";
|
||||
|
Reference in New Issue
Block a user