/[suikacvs]/webroot/admin/web/bin/log-view.cgi
Suika

Diff of /webroot/admin/web/bin/log-view.cgi

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by wakaba, Sun Feb 17 08:59:05 2002 UTC revision 1.2 by wakaba, Sun Feb 17 09:20:36 2002 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl
2    
3  =head1 NAME  =head1 NAME
4    
5  Suika Web Server Log viewer  Suika Web Server Log viewer
6    
7  =cut  =cut
8    
9  use Suika::CGI::Error;  use Suika::CGI::Error;
10  use strict;  use strict;
11  require 'jcode.pl';  require 'jcode.pl';
12    
13  if ($main::ENV{PATH_TRANSLATED}) {  if ($main::ENV{PATH_TRANSLATED}) {
14    my $logid = $main::ENV{PATH_TRANSLATED};    my $logid = $main::ENV{PATH_TRANSLATED};
15    Suika::CGI::Error::die ('404') unless -e $logid;    Suika::CGI::Error::die ('404') unless -e $logid;
16        
17    open LOG, $logid or Suika::CGI::Error::die ('500',=> $!) unless -e $logid;    open LOG, $logid or Suika::CGI::Error::die ('500',''=> $!) unless -e $logid;
18      my @log = <LOG>;      my @log = <LOG>;
19    close LOG;    close LOG;
20        
21    $logid =~ s#^/usr/local/apache/htdocs##;    $logid =~ s#^/usr/local/apache/htdocs##;
22    $logid =~ s#^/home(/[^/]+)/public_html#$1#;    $logid =~ s#^/home(/[^/]+)/public_html#$1#;
23        
24    print STDOUT <<EOH;    print STDOUT <<EOH;
25  Content-Type: text/html; charset=iso-8859-1  Content-Type: text/html; charset=iso-8859-1
26  Content-Language: en  Content-Language: en
27    
28  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN">
29  <html lang="en">  <html lang="en">
30  <head>  <head>
31  <title lang="en">Web server log -- ${logid}</title>  <title lang="en">Web server log -- ${logid}</title>
32  <link rel="stylesheet" href="/admin/web/bin/log-view-style">  <link rel="stylesheet" href="/admin/web/bin/log-view-style">
33  <link rev="mail" href="mailto:webmaster\@suika.fam.cx">  <link rev="mail" href="mailto:webmaster\@suika.fam.cx">
34  <link rel="copyright" href="/c/pd" title="Public Domain.">  <link rel="copyright" href="/c/pd" title="Public Domain.">
35  </head>  </head>
36  <body>  <body>
37    
38  <h1>Web server log -- ${logid}</h1>  <h1>Web server log -- ${logid}</h1>
39    
40  <table><tbody>  <table><tbody>
41  EOH  EOH
42        
43    for (sort @log) {    for (sort @log) {
44      my ($vname, $value) = split /\x1f/;      my ($vname, $value) = split /\x1f/;
45      my ($item, $sitem) = split /: */, $vname, 2;      my ($item, $sitem) = split /: */, $vname, 2;
46      if ($item eq 'Referer') {      if ($item eq 'Referer') {
47        if ($sitem =~ m#http://(?:suika\.fam\.cx|suika\.susumu|suika\.ssm|61\.201\.226\.127|192\.168\.0\.4)/search/(?:namazu)\?.*?query=([\x21-\x7e]+?)(?:[&;]|$)#) {        if ($sitem =~ m#http://(?:suika\.fam\.cx|suika\.susumu|suika\.ssm|61\.201\.226\.127|192\.168\.0\.4)/search/(?:namazu)\?.*?query=([\x21-\x7e]+?)(?:[&;]|$)#) {
48          my $query = $1; $query =~ tr/+/ /;          my $query = $1; $query =~ tr/+/ /;
49          $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;          $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;
50          jcode::convert(\$query, 'euc');  $query = _html($query);          jcode::convert(\$query, 'euc');  $query = _html($query);
51          jcode::convert(\$query, 'jis');          jcode::convert(\$query, 'jis');
52          jcode::fw2hw(\$query, 'jis');          jcode::fw2hw(\$query, 'jis');
53          $sitem = 'Search for '.$query.'<!-- '.$sitem.' -->';          $sitem = 'Search for '.$query.'<!-- '.$sitem.' -->';
54        } elsif ($sitem =~ m#http://www\.google\.(?:com|co\.jp)/search\?([\x00-\xff]+)$#) {        } elsif ($sitem =~ m#http://www\.google\.(?:com|co\.jp)/search\?([\x00-\xff]+)$#) {
55          my @queries = split /[&;]/, $1;          my @queries = split /[&;]/, $1;
56          my $ret;          my $ret;
57          for (@queries) {          for (@queries) {
58            my ($name,$query) = split /=/, $_;            my ($name,$query) = split /=/, $_;
59            if ($name =~ /q/) {            if ($name =~ /q/) {
60              $query =~ tr/+/ /;              $query =~ tr/+/ /;
61              $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;              $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;
62              jcode::convert(\$query, 'euc');  $query = _html($query);              jcode::convert(\$query, 'euc');  $query = _html($query);
63              jcode::convert(\$query, 'jis');  jcode::fw2hw(\$query, 'jis');              jcode::convert(\$query, 'jis');  jcode::fw2hw(\$query, 'jis');
64              $ret .= ' '.$query              $ret .= ' '.$query
65            }            }
66          }          }
67          $sitem = 'Search (Google) for '.$ret.'<!-- '.$sitem.' -->';          $sitem = 'Search (Google) for '.$ret.'<!-- '.$sitem.' -->';
68        } elsif ($sitem =~ m#http://google\.yahoo\.co\.jp/bin/query\?(?:.*?[&;])?p=([\x21-\x7e]+?)(?:[&;]|$)#) {        } elsif ($sitem =~ m#http://google\.yahoo\.co\.jp/bin/query\?(?:.*?[&;])?p=([\x21-\x7e]+?)(?:[&;]|$)#) {
69          my $query = $1; $query =~ tr/+/ /;          my $query = $1; $query =~ tr/+/ /;
70          $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;          $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;
71          jcode::convert(\$query, 'euc');  $query = _html($query);          jcode::convert(\$query, 'euc');  $query = _html($query);
72          jcode::convert(\$query, 'jis');  jcode::fw2hw(\$query, 'jis');          jcode::convert(\$query, 'jis');  jcode::fw2hw(\$query, 'jis');
73          $sitem = 'Search (Google.Yahoo!j) for '.$query.'<!-- '.$sitem.' -->';          $sitem = 'Search (Google.Yahoo!j) for '.$query.'<!-- '.$sitem.' -->';
74        } elsif ($sitem =~ m#http://asearch\.nifty\.com/cgi-bin/Search.cgi\?(?:.*?[&;])?q=([\x21-\x7e]+?)(?:[&;]|$)#) {        } elsif ($sitem =~ m#http://asearch\.nifty\.com/cgi-bin/Search.cgi\?(?:.*?[&;])?q=([\x21-\x7e]+?)(?:[&;]|$)#) {
75          my $query = $1; $query =~ tr/+/ /;          my $query = $1; $query =~ tr/+/ /;
76          $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;          $query =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack(C, hex($1))/eg;
77          jcode::convert(\$query, 'euc');  $query = _html($query);          jcode::convert(\$query, 'euc');  $query = _html($query);
78          jcode::convert(\$query, 'jis');  jcode::fw2hw(\$query, 'jis');          jcode::convert(\$query, 'jis');  jcode::fw2hw(\$query, 'jis');
79          $sitem = 'Search (@search) for '.$query.'<!-- '.$sitem.' -->';          $sitem = 'Search (@search) for '.$query.'<!-- '.$sitem.' -->';
80        } elsif ($sitem =~ m#http://(?:suika\.fam\.cx|suika\.susumu|suika\.ssm|61\.201\.226\.127|192\.168\.0\.4)(/[\x21-\x7e]*)#) {        } elsif ($sitem =~ m#http://(?:suika\.fam\.cx|suika\.susumu|suika\.ssm|61\.201\.226\.127|192\.168\.0\.4)(/[\x21-\x7e]*)#) {
81          $sitem = '<a href="'._html($1).'">'._html($1).'</a>';          $sitem = '<a href="'._html($1).'">'._html($1).'</a>';
82        } else {        } else {
83          $sitem =~ tr/\x00-\x20\x7f-\xff//d;          $sitem =~ tr/\x00-\x20\x7f-\xff//d;
84          $sitem = '<a href="'.$sitem.'">'.$sitem.'</a>';          $sitem = '<a href="'.$sitem.'">'.$sitem.'</a>';
85        }        }
86      } elsif ($item eq 'User') {      } elsif ($item eq 'User') {
87        $sitem =~ tr/\x00-\x20\x7f-\xff//d;        $sitem =~ tr/\x00-\x20\x7f-\xff//d;
88        $sitem = jcode::jis(_html(Suika::CGI::User::ID2Name($sitem)).        $sitem = jcode::jis(_html(Suika::CGI::User::ID2Name($sitem)).
89                 ' ('.$sitem.')' || $sitem);                 ' ('.$sitem.')' || $sitem);
90      } else {      } else {
91        $item = 'UA' if $item eq 'User-Agent';        $item = 'UA' if $item eq 'User-Agent';
92        $sitem = _html($sitem)        $sitem = _html($sitem)
93      }      }
94      print '<tr><th>'.$item.'</th><td>'.$sitem.'</td><td class="count">'.$value.'</td></tr>'."\n";      print '<tr><th>'.$item.'</th><td>'.$sitem.'</td><td class="count">'.$value.'</td></tr>'."\n";
95    }    }
96        
97    print <<EOH;    print <<EOH;
98  </tbody></table>  </tbody></table>
99    
100  <address>  <address>
101  $main::ENV{SERVER_SIGNATURE}  $main::ENV{SERVER_SIGNATURE}
102  </address>  </address>
103  </body></html>  </body></html>
104  EOH  EOH
105    
106  } else {  } else {
107    Suika::CGI::Error::die ('400');    Suika::CGI::Error::die ('400');
108  }  }
109    
110  sub _html ($) {  sub _html ($) {
111    my $s = shift;    my $s = shift;
112    $s =~ s/&/&amp;/g;    $s =~ s/&/&amp;/g;
113    $s =~ s/</&lt;/g;    $s =~ s/</&lt;/g;
114    $s =~ s/>/&gt;/g;    $s =~ s/>/&gt;/g;
115    $s =~ s/"/&quot;/g;    $s =~ s/"/&quot;/g;
116    $s;    $s;
117  }  }
118    
119  1;  1;
120    
121  =head1 AUTHOR  =head1 AUTHOR
122    
123  wakaba <w@suika.fam.cx>  wakaba <w@suika.fam.cx>
124    
125  =head1 LICENSE  =head1 LICENSE
126    
127  Copyright 2001,2002 wakaba <w@suika.fam.cx>.  Copyright 2001,2002 wakaba <w@suika.fam.cx>.
128    
129      This program is free software; you can redistribute it and/or modify      This program is free software; you can redistribute it and/or modify
130      it under the terms of the GNU General Public License as published by      it under the terms of the GNU General Public License as published by
131      the Free Software Foundation; either version 2 of the License, or      the Free Software Foundation; either version 2 of the License, or
132      (at your option) any later version.      (at your option) any later version.
133    
134      This program is distributed in the hope that it will be useful,      This program is distributed in the hope that it will be useful,
135      but WITHOUT ANY WARRANTY; without even the implied warranty of      but WITHOUT ANY WARRANTY; without even the implied warranty of
136      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
137      GNU General Public License for more details.      GNU General Public License for more details.
138    
139      You should have received a copy of the GNU General Public License      You should have received a copy of the GNU General Public License
140      along with this program; see the file COPYING.  If not, write to      along with this program; see the file COPYING.  If not, write to
141      the Free Software Foundation, Inc., 59 Temple Place - Suite 330,      the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
142      Boston, MA 02111-1307, USA.      Boston, MA 02111-1307, USA.
143    
144  =cut  =cut

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24