home *** CD-ROM | disk | FTP | other *** search
- Readlog
- Author Brigitte Jellinek
- $local_server = "www.cosy.sbg.ac.at";$www_server_dir = "/home/esel/www/server";
- $www_documents_dir = "/home/esel/www/www_home";$| = 1;$date = `/bin/date`;
- # a few arrays for storing the information we find:
- @last = (); # last access by host@count = (); # no of accesses by host
- %index = (); # index: host (as found in log), value: index of above arrays
- # for sorting by date
- %no_of_month = ( Jan, 1, Feb, 2, Mar, 3, Apr, 4, May, 5, Jun, 6,
- Jul, 7, Aug, 8, Sep, 9, Oct,10, Nov,11, Dec,12 );
- sub bydate # for sorting
- { ($amonth, $ano) = split(/ /, $last[$index{$a}]);
- ($bmonth, $bno) = split(/ /, $last[$index{$b}]);
- if ( $amonth eq $bmonth ) { $ano <=> $bno } else
- { $no_of_month{$amonth} <=> $no_of_month{$bmonth} }; }
- # two little subroutins for formating output - really not importantsub pr
- { $caller = $_[0]; $i = $index{ $caller };
- print "$caller called ";
- if ($count[$i]==1) { print "once, on $last[$i]\n"; }
- elsif ($count[$i]==2) { print "twice, last on $last[$i]\n"; }
- else {print "$count[$i] times, last on $last[$i]\n"}; };sub prli
- { local($heading,$pattern) = @_;
- @l = grep(/$pattern/, sort bydate keys %index); if ($#l >= 0)
- { print "<H1>$heading</H1>"; print " <UL>\n";
- foreach (@l) { print " <LI>"; &pr( $_ );
- delete $index{$_}; }; print " </UL>\n"; };
- }# Main Program.
- if ($ARGV[0] eq '') # no argument (filename to search): introduction.
- { print <<'EndOfExplanation';Content-type: text/html<HTML> <HEAD>
- <TITLE>Read Log</title> <ISINDEX></HEAD> <BODY>
- <INC SRV "/inc/backlink-cosy.htinc">
- <INC SRV "/inc/backlink-cosy-www-doku.htinc">
- <INC SRV "/inc/info.htinc"> <INC SRV "/inc/help.htinc"> <HR>
- <H1>Read Log</H1>
- This is a tool for reading the httpd access log of documents.
- Enter the name of the document whos log you want to see.<P>
- This only works if the document is on our local Server
- The <A HREF="/www-doku/scripts/logstat/readlog"> source code</A>
- of this script is available. <P> share and enjoy !<P>
- EndOfExplanation }else {print <<"EOM";Content-type: text/html<HTML> <HEAD>
- <TITLE>Read Log</title></HEAD> <BODY>
- <INC SRV "/inc/backlink-cosy.htinc">
- <INC SRV "/inc/backlink-cosy-www-doku.htinc">
- <INC SRV "/inc/info.htinc"> <INC SRV "/inc/help.htinc"> <HR> EOM
- $filename = $ARGV[0]; # that's what we're looking for
- $filename =~ s/\\//g; # unescape characters
- $filename =~ s/%(..)/pack('c',hex($1))/eg; # unescape characters
- print " <H1>Read Log for File '$filename'</H1>\n";
- # $filename =~ s!\^! !g; open(LOG,
- "fgrep '$filename' ${www_server_dir}/logs/access_log |");
- # $filename =~ s!^ !!;
- $global_count = 0; # whole no of accesset to $filename while(<LOG>)
- { chop;
- ($caller,$weekday,$month,$day_of_month,
- $time_of_day,$year,$get,$file) = split;
- if ($file =~ /(.*)\?/) { $file = $1 }; if ($file eq $filename)
- { $global_count++;
- $caller .= ".cosy.sbg.ac.at" unless $caller =~ /\./;
- if( defined $index{$caller} ) #caller already in array
- { $i = $index{$caller};
- $last[$i] = $month . " " . $day_of_month; $count[$i]++;
- } else {
- push( @last, $month . " " . $day_of_month ); push( @count, 1 );
- $i = $#count; $index{ $caller } = $i; };
- }; }; chop $files_found;
- print " found $global_count references to this file\n";
- print "<H1>local</H1>"; foreach (grep(/cosy.sbg.ac.at/, keys %index),
- grep(/dwst..\.edvz.sbg.ac.at/, keys %index),
- grep(/.coma.sbg.ac.at/, keys %index))
- { if ( /(.*)\.cosy/ ) {$name = $1}
- elsif ( /(dwst..\.edvz)/ ) {$name = $1}
- elsif ( /(.*\.coma)/ ) {$name = $1}
- else {$name = $_}; print "$name, ";
- delete $index{$_}; }; print " all called.\n";
- &prli("Salzburg", '\.sbg\.ac\.at$'); &prli("Austria", '\.at$');
- &prli("Germany", '\.de$'); print "<H1>Earth</H1>";
- print " <UL>\n"; foreach (sort bydate keys %index)
- { $i = $index{ $_ }; print " <LI>"; &pr($_); };
- print " </UL>\n"; }print <<"EndOfFooter"; <HR>
- <ADDRESS>Script written by
- <A HREF=${dq}http://www.cosy.sbg.ac.at/people/bjelli.html$dq>
- Brigitte Jellinek</A> (bjelli@cosy.sbg.ac.at)</ADDRESS>
- <ADDRESS>This page created: $date
- <ADDRESS>Script last modified: Sat, Nov 13 1993 16:19 MET </ADDRESS>
- </BODY> </HTML>EndOfFooter#
- # That's all folks share and enjoy !
- ###############################################################################