home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / PERLPAD3.ZIP / PERLPAD3.CAB / readlog.ppm < prev    next >
Encoding:
Text File  |  1999-02-06  |  5.1 KB  |  87 lines

  1. Readlog
  2. Author Brigitte Jellinek
  3. $local_server = "www.cosy.sbg.ac.at";$www_server_dir = "/home/esel/www/server";
  4. $www_documents_dir = "/home/esel/www/www_home";$| = 1;$date = `/bin/date`;
  5. # a few arrays for storing the information we find:
  6. @last = ();     # last access by host@count = ();    # no of accesses by host
  7. %index = ();    # index: host (as found in log), value: index of above arrays
  8. # for sorting by date
  9. %no_of_month = ( Jan, 1, Feb, 2, Mar, 3, Apr, 4, May, 5, Jun, 6,
  10.                      Jul, 7, Aug, 8, Sep, 9, Oct,10, Nov,11, Dec,12 );
  11. sub bydate     # for sorting
  12.    {   ($amonth, $ano) = split(/ /, $last[$index{$a}]);   
  13.        ($bmonth, $bno) = split(/ /, $last[$index{$b}]);
  14.        if ( $amonth eq $bmonth )        {  $ano <=> $bno }       else  
  15.        { $no_of_month{$amonth} <=> $no_of_month{$bmonth} };   }
  16. # two little subroutins for formating output - really not importantsub pr
  17.    {  $caller = $_[0];      $i = $index{ $caller };
  18.       print "$caller called ";
  19.       if    ($count[$i]==1) { print "once, on $last[$i]\n"; }
  20.       elsif ($count[$i]==2) { print "twice, last on $last[$i]\n"; }
  21.       else  {print "$count[$i] times, last on $last[$i]\n"};    };sub prli
  22.    {  local($heading,$pattern) = @_;
  23.       @l = grep(/$pattern/, sort bydate keys %index);      if ($#l >= 0) 
  24.        { print "<H1>$heading</H1>";         print "    <UL>\n";
  25.          foreach (@l)          { print "    <LI>";        &pr( $_ ); 
  26.             delete $index{$_};          };        print "    </UL>\n";      };
  27.     }# Main Program.
  28. if ($ARGV[0] eq '')    # no argument (filename to search): introduction.
  29.     { print <<'EndOfExplanation';Content-type: text/html<HTML> <HEAD>
  30.     <TITLE>Read Log</title>    <ISINDEX></HEAD> <BODY>
  31.      <INC SRV "/inc/backlink-cosy.htinc">
  32.      <INC SRV "/inc/backlink-cosy-www-doku.htinc">
  33.      <INC SRV "/inc/info.htinc">     <INC SRV "/inc/help.htinc">     <HR> 
  34.       <H1>Read Log</H1>
  35.       This is a tool for reading the httpd access log of documents.
  36.       Enter the name of the document whos log you want to see.<P> 
  37.       This only works if the document is on our local Server
  38.       The <A HREF="/www-doku/scripts/logstat/readlog"> source code</A> 
  39.       of this script is available. <P>       share and enjoy !<P>
  40. EndOfExplanation    }else    {print <<"EOM";Content-type: text/html<HTML> <HEAD>
  41.     <TITLE>Read Log</title></HEAD> <BODY>
  42.      <INC SRV "/inc/backlink-cosy.htinc">
  43.      <INC SRV "/inc/backlink-cosy-www-doku.htinc">
  44.      <INC SRV "/inc/info.htinc">     <INC SRV "/inc/help.htinc">     <HR> EOM
  45.       $filename = $ARGV[0];     # that's what we're looking for
  46.       $filename =~ s/\\//g;  # unescape characters
  47.       $filename =~ s/%(..)/pack('c',hex($1))/eg;  # unescape characters
  48.       print "    <H1>Read Log for File '$filename'</H1>\n";      
  49. #     $filename =~ s!\^! !g;      open(LOG, 
  50.           "fgrep '$filename' ${www_server_dir}/logs/access_log |");
  51. #     $filename =~ s!^ !!;
  52.       $global_count = 0;   # whole no of accesset to $filename      while(<LOG>)
  53.             {            chop;
  54.             ($caller,$weekday,$month,$day_of_month,
  55.                   $time_of_day,$year,$get,$file) = split;
  56.             if ($file =~ /(.*)\?/) { $file = $1 };        if ($file eq $filename)
  57.          { $global_count++;    
  58.                 $caller .= ".cosy.sbg.ac.at"  unless $caller =~ /\./;        
  59.             if( defined $index{$caller} )  #caller already in array
  60.                   { $i = $index{$caller};
  61.             $last[$i] = $month . " " . $day_of_month;            $count[$i]++;
  62.                   }                else                  { 
  63.             push( @last, $month . " " . $day_of_month );            push( @count, 1 );
  64.             $i = $#count;                    $index{ $caller } = $i;              };
  65.           };        };      chop $files_found; 
  66.       print "    found $global_count references to this file\n";
  67.       print "<H1>local</H1>";      foreach (grep(/cosy.sbg.ac.at/, keys %index),
  68.           grep(/dwst..\.edvz.sbg.ac.at/, keys %index),
  69.           grep(/.coma.sbg.ac.at/, keys %index))
  70.             { if    ( /(.*)\.cosy/     ) {$name = $1}
  71.           elsif ( /(dwst..\.edvz)/ ) {$name = $1}
  72.           elsif ( /(.*\.coma)/     ) {$name = $1}
  73.           else                       {$name = $_};          print "$name, ";
  74.           delete $index{$_};        };      print " all called.\n";
  75.       &prli("Salzburg", '\.sbg\.ac\.at$');      &prli("Austria", '\.at$');
  76.       &prli("Germany", '\.de$');      print "<H1>Earth</H1>";
  77.       print "    <UL>\n";      foreach (sort bydate keys %index)
  78.             { $i = $index{ $_ };          print "    <LI>";          &pr($_);        };
  79.       print "    </UL>\n";    }print <<"EndOfFooter";    <HR>
  80.     <ADDRESS>Script written by 
  81.     <A HREF=${dq}http://www.cosy.sbg.ac.at/people/bjelli.html$dq>
  82.     Brigitte Jellinek</A> (bjelli@cosy.sbg.ac.at)</ADDRESS>
  83.     <ADDRESS>This page created: $date
  84.     <ADDRESS>Script last modified: Sat, Nov 13 1993    16:19 MET </ADDRESS>
  85. </BODY> </HTML>EndOfFooter#
  86. # That's all folks                                            share and enjoy !
  87. ###############################################################################