[ Index ]
 

Code source de phpMyVisites 2.3

Accédez au Source d'autres logiciels libres

Classes | Fonctions | Variables | Constantes | Tables

title

Body

[fermer]

/plugins/clickheat/libs/scripts/ -> parseClickLogs.pl (source)

   1  #!/usr/bin/perl -w

   2  ###

   3  ## ClickHeat : Apache log parser

   4  ## 

   5  ## Developpement effectue pour/developed for WAT (www.wat.tv)

   6  ## WAT - Partagez votre univers (vid�os, musique, photos) entre amis

   7  ## WAT - Share your videos, music and photos with your friends

   8  ## Si vous appreciez ce script, utilisez le site WAT !

   9  ## If you like this script, use WAT !

  10  ##

  11  ## Plus d'informations : http://www.labsmedia.fr/clickheat/performance.html

  12  ## More information: http://www.labsmedia.com/clickheat/performance.html

  13  ##

  14  ## @author Vincent Audino pour WAT - www.wat.tv

  15  ## @since 03/28/2007

  16  ## @update 31/07/2007 - Yvan Taviaud : correction du paramètre «p=» qui devient «g=»

  17  ###

  18  
  19  
  20  use Date::Manip;
  21  use strict;
  22  
  23  my $date;
  24  my $page;
  25  my $x;
  26  my $y;
  27  my $w;
  28  my $c;
  29  my $browser;
  30  my $random;
  31  my $referer;
  32  my %fdcache;
  33  my $maxcached = 10;
  34  my $currentfd;
  35  
  36  
  37  if ($#ARGV < 1)
  38  {
  39      die "usage: ./parseClickLogs.pl apache_logs_file dest_path [domain_ignored]\n";
  40  }
  41  
  42  my $srcFile = $ARGV[0];
  43  my $destPath = $ARGV[1] . '/';
  44  my $ignored = defined($ARGV[2]) ? $ARGV[2] : '';
  45  
  46  mkdir($destPath) if (!-d $destPath);
  47  
  48  open(LOGFILE, $srcFile) or die("Impossible d'ouvrir le fichier ".$srcFile);
  49  
  50  while(<LOGFILE>)
  51  {
  52      if (/.*clickheat.*/ 
  53      && ($ignored eq "" || !/.*http:\/\/.*$ignored.*/) )
  54      {
  55      if (s/.*\[(.*)\].*g=(.*)&x=([0-9]*)&y=([0-9]*)&w=([0-9]*)&b=(.*)&c=([0-9])&random=(.*) HTTP.* \"(http:\/\/.*)\" \".*\" .*/$1, $2, $3, $4, $5, $6, $7, $8, $9/)
  56      {
  57          $date = ParseDate($1); $page = $2; $x = $3; $y = $4; $w = $5; $browser = $6; $c = $7; $random  = $8; $referer = $9;
  58          $page = 'none' if ($page eq '');
  59  
  60          $date =~ s#^(....)(..)(..)(..):(..):(..)#$1-$2-$3#;
  61          
  62          my $writeDir = $destPath.$page;
  63          my $writeFile = $writeDir.'/'.$date.'.log';
  64          mkdir($writeDir) if (!-d $destPath.$page);
  65  
  66  
  67          if (defined($fdcache{$writeFile}))
  68          {
  69          $currentfd = $fdcache{$writeFile};
  70          }
  71          else
  72          {
  73          open(my $fd, ">>".$writeFile) or die ("Erreur d'ouverture de " . $writeFile);
  74          chmod 0606, $writeFile;
  75          
  76          if (keys(%fdcache) == $maxcached)
  77          {
  78              # cache plein

  79              # on vire le dernier

  80              my @fdcache = %fdcache;
  81              close pop @fdcache;
  82              pop @fdcache;
  83              %fdcache = @fdcache;
  84          }
  85          
  86          $fdcache{$writeFile} = $fd;
  87          
  88          $currentfd = $fdcache{$writeFile};
  89          }
  90          print $currentfd $x.'|'.$y.'|'.$w.'|'.$browser.'|'.$c."\n";
  91  
  92  
  93          #

  94              # REFERRER

  95          #

  96          if ($referer ne '')
  97          {
  98          $writeFile = $writeDir . '/url.txt';
  99          
 100          if (!-f $writeFile)
 101          {
 102              open(my $fd,">".$writeFile) or die ("Erreur d'ouverture de " . $writeFile) ;            
 103              chmod 0606, $writeFile;
 104              print $fd $referer.'>0>0>0';
 105              close $fd;
 106          }
 107          }
 108       }
 109      }
 110  }
 111  
 112  while( my ($k, $v) = each %fdcache )
 113  {
 114      close $v;
 115  }
 116  
 117  close LOGFILE;
 118  


Généré le : Mon Nov 26 14:10:01 2007 par Balluche grâce à PHPXref 0.7
  Clicky Web Analytics