#!/usr/bin/perl =head1 NAME Suika Web Server Log viewer =cut use Suika::CGI; use Suika::CGI::Error; use strict; require 'jcode.pl'; if ($main::ENV{PATH_TRANSLATED}) { my $logid = $main::ENV{PATH_TRANSLATED}; $logid = readlink ($logid) if -l $logid; Suika::CGI::Error::http_error ('404') unless -e $logid; open LOG, $logid or Suika::CGI::Error::http_error ('500',''=> $!); my @log = ; close LOG; $logid =~ s#^/usr/local/apache/htdocs##; $logid =~ s#^/home(/[^/]+)/public_html#$1#; print STDOUT < Web server log -- ${logid}

Web server log -- ${logid}

EOH for (sort @log) { my ($vname, $value) = split /\x1f/; my ($item, $sitem) = split /: */, $vname, 2; if ($item eq 'Referer') { if ($sitem =~ m#http://(?:suika\.fam\.cx|suika\.susumu|suika\.ssm|61\.201\.226\.127|192\.168\.0\.4)/search/(?:namazu)\?.*?query=([\x21-\x7e]+?)(?:[&;]|$)#) { my $query = $1; $query =~ tr/+/ /; $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('C', hex($1))/eg; jcode::convert(\$query, 'euc'); $query = _html($query); jcode::convert(\$query, 'jis'); jcode::fw2hw(\$query, 'jis'); $sitem = 'Search for '.$query.''; } elsif ($sitem =~ m#http://www\.google\.(?:com|co\.jp)/search\?([\x00-\xff]+)$#) { my @queries = split /[&;]/, $1; my $ret; for (@queries) { my ($name,$query) = split /=/, $_; if ($name =~ /q/) { $query =~ tr/+/ /; $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('C', hex($1))/eg; jcode::convert(\$query, 'euc'); $query = _html($query); jcode::convert(\$query, 'jis'); jcode::fw2hw(\$query, 'jis'); $ret .= ' '.$query } } $sitem = 'Search (Google) for '.$ret.''; } elsif ($sitem =~ m#http://google\.yahoo\.co\.jp/bin/query\?(?:.*?[&;])?p=([\x21-\x7e]+?)(?:[&;]|$)#) { my $query = $1; $query =~ tr/+/ /; $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('C', hex($1))/eg; jcode::convert(\$query, 'euc'); $query = _html($query); jcode::convert(\$query, 'jis'); jcode::fw2hw(\$query, 'jis'); $sitem = 'Search (Google.Yahoo!j) for '.$query.''; } elsif ($sitem =~ m#http://asearch\.nifty\.com/cgi-bin/Search.cgi\?(?:.*?[&;])?q=([\x21-\x7e]+?)(?:[&;]|$)#) { my $query = $1; $query =~ tr/+/ /; $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('C', hex($1))/eg; jcode::convert(\$query, 'euc'); $query = _html($query); jcode::convert(\$query, 'jis'); jcode::fw2hw(\$query, 'jis'); $sitem = 'Search (@search) for '.$query.''; } elsif ($sitem =~ m#http://(?:suika\.fam\.cx|suika\.susumu|suika\.ssm|61\.201\.226\.127|192\.168\.0\.4)(/[\x21-\x7e]*)#) { $sitem = ''._html($1).''; } else { $sitem =~ tr/\x00-\x20\x7f-\xff//d; $sitem = ''.$sitem.''; } } elsif ($item eq 'User') { $sitem =~ tr/\x00-\x20\x7f-\xff//d; $sitem = jcode::jis(_html(Suika::CGI::User::ID2Name($sitem)). ' ('.$sitem.')' || $sitem); } else { $item = 'UA' if $item eq 'User-Agent'; $sitem = _html($sitem) } print ''."\n"; } print <
'.$item.''.$sitem.''.$value.'
$main::ENV{SERVER_SIGNATURE} EOH } else { Suika::CGI::Error::http_error ('400'); } sub _html ($) { my $s = shift; $s =~ s/&/&/g; $s =~ s//>/g; $s =~ s/"/"/g; $s; } 1; =head1 AUTHOR wakaba =head1 LICENSE Copyright 2001,2002 wakaba . This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. =cut