home *** CD-ROM | disk | FTP | other *** search
- #!/usr/local/bin/perl
- # ------------------------------------------------------------------------
- #
- # mkcharts - reads part of the www-servers access log
- # (file SERVER_ROOT/logs/access_log), finds the 20 pages
- # that have been accessed the most, writes the charts to
- # the file charts.$type.html
- #
- mkcharts.cgi
- Author: Brigitte Jellinek
- # Usage: mkcharts.cgi
- # in WWW: HREF = ".../mkcharts.cgi/$type"
- #
- # copyright (c) 1994 Brigitte Jellinek
- # this program is available under the GNU General Public License
- #
- # e-mail bjelli@cosy.sbg.ac.at
- # HREF = "http://www.cosy.sbg.ac.at/people/bjelli.html"
- #
- # Version 4.0
- #
- #
- # ------------------------------------------------------------------------
-
- $SERVER_ROOT = "/home/esel/www/server";
- $LOG_FILE = $SERVER_ROOT . "/logs/access_log";
-
- $type = $ENV{PATH_INFO} || 'nonlocal';
-
- $type =~ s!^/!!;
-
- $charts_file = "charts.$type.html";
-
- # a few arrays for storing the information we find:
- $| = 1;
- $date = `/bin/date`;
-
- %count = (); # no of accesses by host
-
- # for sorting by count
-
- sub bycount # for sorting
- { $count{$a} <=> $count{$b} }
-
- # Main Program.
-
-
- open(FILE, ">$charts_file")
- || &HtmlError("$0", 'bjelli',
- "Couldn't write to file '$charts_file': $!");
-
-
- open (FROM, "$LOG_FILE")
- || &HtmlError("$0", 'bjelli',
- "reading from file '$LOG_FILE': $!");
- $from = <FROM>; close FROM;
- $from =~ s/.*\[(.*)\].*\n/$1/;
-
- open (TO, "tail -1 $LOG_FILE |")
- || &HtmlError("$0", 'bjelli',
- "reading the tail of file '$LOG_FILE': $!");
- $to = <TO>; close TO;
- $to =~ s/.*\[(.*)\].*\n/$1/;
-
- $total_no = `wc -l $LOG_FILE | cut -c1-9 `;
- chop($total_no);
-
- $oldhandle=select(FILE);
- print <<"EOM";
- <HTML> <HEAD>
- <TITLE>Charts Log</title>
- </HEAD>
- <BODY>
- <!--#include virtual="/inc/backlink-cosy.htinc"-->
- <!--#include virtual="/inc/backlink-cosy-www-doku.htinc"-->
- <!--#include virtual="/inc/info.htinc"-->
- <!--#include virtual="/inc/help.htinc"-->
- <HR>
- This Page was cached. You can <A HREF="mkcharts.cgi/$type">
- force an update</A> but that will take some time.
- <HR>
- <H1>Charts <EM>$type</EM> </H1>
-
- <STRONG>$from</STRONG> to <BR>
- <STRONG>$to</STRONG>.
- <P>
- (total no of accesses during that period: $total_no)
- EOM
-
-
-
- open(LOG, "$LOG_FILE");
-
- $count = 0;
-
- FILE:
- while(<LOG>)
- {
- $global_count++;
- if (/^[^\.]* /)
- {
- unless ($type eq 'cosy') { next FILE };
- }
- elsif (/\.sbg\./)
- {
- unless ($type eq 'sbg') { next FILE };
- }
- else
- {
- unless ($type eq 'nonlocal') { next FILE };
- };
-
- chop;
- $count++;
-
- ($host,$id,$user,$date,$request,$status,$bytes) =
- $_ =~ /(\S*) (\S*) (\S*) \[([^\]]*)\] "([^"]*)" (\S*) (\S*)/;
-
- # print STDERR "$host,$id,$user,$date,$request,$status,$bytes\n";
-
- next FILE if $request =~ /^POST/;
-
- ($file) = $request =~ /GET (\S*)/;
-
- # print STDERR "file = $file\n";
-
- if ($file =~ /(.*)\?/) { $file = $1 }; # scipt called with args
- if ($file =~ m!/inc/!) { next FILE }; # don't count includes
- if ($file =~ /\.xbm$/) { next FILE };
- if ($file =~ /\.gif$/) { next FILE };
-
- $count{$file}++;
- };
-
- print " <OL>\n";
- foreach ((reverse sort bycount keys %count)[0..19])
- { print " <LI> $count{$_} <A HREF=\"$_\">$_</A> (<A HREF=\"readlog.cgi?$_\">log</A>)\n";
- };
- print " </OL>\n";
-
- print <<"EndOfFooter";
- (found $count accesses from $type)
- <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: Thu, Feb 10 1994 16:03 MET </ADDRESS>
- </BODY> </HTML>
- EndOfFooter
-
- select ($oldhandle);
- print <<"EOM";
- Content-Type: text/html
-
- <H1> Ready </H1>
- Go back and reload
- EOM
- #
- # That's all folks share and enjoy !
- ###############################################################################
-