#!/usr/bin/perl # Google 検索履歴蓄積CGI # For Willcom WX/AH-K300X Series # 2006/03/30 かつ@20041030関連情報(備忘録) http://1030.ragna.info/ # Licensed CreativeCommons http://creativecommons.org/licenses/by-sa/2.5/ ###### 設定項目 #このスクリプトの名前 $script = './index.cgi'; #Google検索結果のログ(基本的には修正不要・自動生成) $logfile = './ggllog.cgi'; #削除時の退避用ログ(基本的には修正不要・自動生成) $escfile = './escdat.cgi'; #運用方式(0=認証なし/1=乱数で区分/2=パスワード認証) $mode = 0; #パスワード(数字6桁) $password = '123456'; ###### 以下は特に修正の必要はありません。 $q = $ENV{'QUERY_STRING'}; if ($q =~ /=/) { @ql = split(/&/,$q); foreach(@ql) { ($n,$v) = split(/=/,$_); $f{$n} = $v; } } else { $f{'q'} = $q; } if ($mode == 2 && $f{'pwd'} ne $password) { &gate; exit; } if ($q) { if ($f{'q'}) { $query = $f{'q'}; $query =~ tr/+/ /; $query =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack('H2', $1)/eg; $query =~ s/%([a-f\d]{2})/pack 'H2',$1/egi; $query = jcode($query)->h2z->sjis; $u_enc = jcode($query)->h2z->utf8; $u_enc =~ s/([^\w ])/'%' . unpack('H2', $1)/eg; $u_enc =~ tr/ /+/; open (RECENT,">>$logfile"); print RECENT time."\t$query\t$u_enc\t$ENV{'REMOTE_ADDR'}\t$f{'uid'}\n"; close RECENT; print "Location: http://www.google.co.jp/search?hl=ja&ie=UTF-8&q=$u_enc\n\n"; } elsif ($f{'d'}) { open (LOG,$logfile); @log = ; close LOG; open (LOG,">$logfile"); open (ESC,">>$escfile"); foreach (@log) { ($ti,$kw,$ut,$ip,$uid) = split(/\t/,$_); if ($f{'d'} != $ti) { print LOG $_; } else { print ESC $_; } } close LOG; close ESC; &disp; } else { &disp; } } else { &disp; } sub gate{ print "Content-type: text/html\n\n"; print <<"_HTML_"; 認証画面
Password:
_HTML_ } sub disp { open (LOG,$logfile); @log=; close LOG; print "Content-type: text/html\n\n"; print <<"_TOP_"; Google検索ログ

Google結果

#) 新規 *) ReloadBookmark


[削] [履歴]
_TOP_ if ($mode == 1) { $form = "User ID:
\n"; } use Jcode; @rlog = reverse(@log); foreach (@rlog) { $_ =~ s/\n//; ($time,$key,$enc,$ip,$uid) = split(/\t/,$_); if ($uid eq $f{'uid'} || $mode != 1) { if (!$flag{$enc}) { $count++; if ($count < 9) { $akey = "accesskey=\"$count\" "; } print "$count) $key
\n"; $flag{$enc} = 1; } else { print "\n"; } if ($count > 30) { last; } } } print <<"_BOTTOM_";
$pwd $form

_BOTTOM_ print '
Script by かつ
'; print "\n"; print "\n"; } exit;