[ Index ]
 

Code source de e107 0.7.8

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/e107_plugins/log/ -> log.php (source)

   1  <?php
   2  /*
   3  + ----------------------------------------------------------------------------+
   4  |     e107 website system
   5  |
   6  |        Steve Dunstan 2001-2002
   7  |     http://e107.org
   8  |     jalist@e107.org
   9  |
  10  |     Released under the terms and conditions of the
  11  |     GNU General Public License (http://gnu.org).
  12  |
  13  | File locking, modified getip() 18.01.07
  14  |
  15  |     $Source: /cvsroot/e107/e107_0.7/e107_plugins/log/log.php,v $
  16  |     $Revision: 1.25 $
  17  |     $Date: 2007/02/10 15:54:31 $
  18  |     $Author: e107steved $
  19  +----------------------------------------------------------------------------+
  20  */
  21  
  22  // File called with:
  23  // e_PLUGIN_ABS."log/log.php?referer=' + ref + '&color=' + colord + '&eself=' + eself + '&res=' + res + '\">' );\n";
  24  // referer= ref
  25  // color= colord
  26  // eself= eself 
  27  // res= res
  28  define("log_INIT", TRUE);
  29  $colour = strip_tags((isset($_REQUEST['color']) ? $_REQUEST['color'] : ''));
  30  $res = strip_tags((isset($_REQUEST['res']) ? $_REQUEST['res'] : ''));
  31  $self = strip_tags((isset($_REQUEST['eself']) ? $_REQUEST['eself'] : ''));
  32  $ref = addslashes(strip_tags((isset($_REQUEST['referer']) ? $_REQUEST['referer'] : '')));
  33  $date = date("z.Y", time());
  34  
  35  if(strstr($ref, "admin")) 
  36  {
  37      $ref = FALSE;
  38  }
  39  
  40  $screenstats = $res."@".$colour;
  41  $agent = $_SERVER['HTTP_USER_AGENT'];
  42  $ip = getip();
  43  
  44  $oldref = $ref; // backup for search string being stripped off for referer
  45  if($ref && !strstr($ref, $_SERVER['HTTP_HOST'])) 
  46  {
  47    if(preg_match("#http://(.*?)($|/)#is", $ref, $match)) 
  48    {
  49      $ref = $match[0];
  50    }
  51  }
  52  
  53  $pageDisallow = "cache|file|eself|admin";
  54  $tagRemove = "(\\\)|(\s)|(\')|(\")|(eself)|(&nbsp;)|(\.php)|(\.html)";
  55  $tagRemove2 = "(\\\)|(\s)|(\')|(\")|(eself)|(&nbsp;)";
  56  
  57  preg_match("#/(.*?)(\?|$)#si", $self, $match);
  58  $match[1] = isset($match[1]) ? $match[1] : '';
  59  $pageName = substr($match[1], (strrpos($match[1], "/")+1));
  60  $PN = $pageName;
  61  $pageName = preg_replace("/".$tagRemove."/si", "", $pageName);
  62  if($pageName == "") $pageName = "index";
  63  if(preg_match("/".$pageDisallow."/i", $pageName)) return;
  64  
  65  
  66  $logPfile = "logs/logp_".$date.".php";
  67  
  68  $p_handle = fopen($logPfile, 'r+');
  69  if($p_handle && flock( $p_handle, LOCK_EX ) ) 
  70  {
  71    $log_file_contents = '';
  72    while (!feof($p_handle))
  73    {  // Assemble a string of data
  74      $log_file_contents.= fgets($p_handle,1000);
  75    }
  76    $log_file_contents = str_replace(array('<'.'?php','?'.'>'),'',$log_file_contents);
  77    if (eval($log_file_contents) === FALSE) echo "error in log file contents<br /><br /><br /><br />";
  78  }
  79  else
  80  {
  81    echo "Couldn't log data<br /><br /><br /><br />";
  82    exit;
  83  }
  84  
  85  
  86  $flag = FALSE;
  87  if(array_key_exists($pageName, $pageInfo)) 
  88  {  // Existing page - just increment stats
  89    $pageInfo[$pageName]['ttl'] ++;
  90  }
  91  else 
  92  {  // First access of page
  93    $url = preg_replace("/".$tagRemove2."/si", "", $self);
  94    if(preg_match("/".$pageDisallow."/i", $url)) return;
  95    $pageInfo[$pageName] = array('url' => $url, 'ttl' => 1, 'unq' => 1);
  96    $flag = TRUE;
  97  }
  98  
  99  if(!strstr($ipAddresses, $ip)) 
 100  {    /* unique visit */
 101    if(!$flag) 
 102    {
 103      $pageInfo[$pageName]['unq'] ++;
 104    }
 105    $siteUnique ++;
 106    $ipAddresses .= $ip.".";        // IP address is stored as hex string
 107    require_once ("loginfo.php");
 108  }
 109  
 110  $siteTotal ++;
 111  $info_data = var_export($pageInfo, true);
 112  //$date_stamp = date("z:Y", time());            // Same as '$date' variable
 113  
 114  $data = "<?php
 115  
 116  /* e107 website system: Log file: {$date} */
 117  
 118  \$ipAddresses = '{$ipAddresses}';
 119  \$siteTotal = '{$siteTotal}';
 120  \$siteUnique = '{$siteUnique}';
 121  
 122  \$pageInfo = {$info_data};
 123  
 124  ?>";
 125  
 126  if ($p_handle)
 127  {
 128    ftruncate( $p_handle, 0 );
 129    fseek( $p_handle, 0 );
 130    fwrite($p_handle, $data);
 131    fclose($p_handle);
 132  }
 133  
 134  
 135  
 136  function getip($mode=TRUE) 
 137  {
 138    if (getenv('HTTP_X_FORWARDED_FOR')) 
 139    {
 140      $ip = $_SERVER['REMOTE_ADDR'];
 141      if (preg_match("#^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})#", getenv('HTTP_X_FORWARDED_FOR'), $ip3)) 
 142      {  
 143        $ip2 = array('#^0\..*#', 
 144                 '#^127\..*#',                             // Local loopbacks
 145                 '#^192\.168\..*#',                         // RFC1918 - Private Network
 146                 '#^172\.(?:1[6789]|2\d|3[01])\..*#',     // RFC1918 - Private network
 147                 '#^10\..*#',                             // RFC1918 - Private Network
 148                 '#^169\.254\..*#',                         // RFC3330 - Link-local, auto-DHCP 
 149                 '#^2(?:2[456789]|[345][0-9])\..*#'        // Single check for Class D and Class E
 150                 );
 151        $ip = preg_replace($ip2, $ip, $ip3[1]);
 152      }
 153    }
 154    else 
 155    {
 156      $ip = $_SERVER['REMOTE_ADDR'];
 157    }
 158    if ($ip == "") 
 159    {
 160      $ip = "x.x.x.x";
 161    }
 162    if($mode) 
 163    {
 164      $ipa = explode(".", $ip);
 165      return sprintf('%02x%02x%02x%02x', $ipa[0], $ipa[1], $ipa[2], $ipa[3]);
 166    }
 167    else 
 168    {
 169      return $ip;
 170    }
 171  }
 172  
 173  ?>


Généré le : Sun Apr 1 01:23:32 2007 par Balluche grâce à PHPXref 0.7