#!/usr/bin/perl -w use Socket; # Socketモジュールを使う require './jcodeLE.pl'; require './getres.cgi'; $| = 1; $targethost = 'snog.squares.net'; $targetdir = 'vote2'; $targetcgi = 'vote.cgi'; $referer = "http://$targethost/$targetdir/"; $cgipath = 'http://www.jks.is.tsukuba.ac.jp/~akaho/board'; #このCGIがある所 $thiscgi = 'getlog.cgi'; $topfile = 'getlog.htm'; $logdir = 'log'; $bodys = '
'; #標準表示設定 $metacode = ''; #文字コード指定 $sleepsec = 10; $seritime = 3; #連続実行制限(分) $temporary = 'tmp.htm'; &execcheck; &ginit; &decode; if($room =~ /http:\/\/$targethost\/$targetdir\/htm\/(\d+)\.html/){ $room = $1; } if($proxyname ne ''){ ($proxy,$proxyport) = split(/:/, $proxyname); $proxyport = 8080 if($proxyport == 0); $host = $proxy; $port = $proxyport; }else{ $host = $targethost; $port = 80; } #箱リストの取得 if($getlist eq "on"){ $arg_string = "lm=1000"; $targetpath = "$targetdir/list.cgi?$arg_string"; &make_connection($host,$port); &get_html; &write_lines("$logdir/list.htm",@htmllines); #list.htmにリストを取る &html;exit; } #箱番号が指定されていなければ入力画面へ if($room == 0){ &print_interface; exit; } print "Content-type: text/html\n\n"; print <<"_HTML_";$room 箱取得の要求を受け取りました。 しばらくした後トップページへお戻り下さい。
トップページ $cgipath/$topfile(3分後自動ジャンプ)
_HTML_ #箱取得要求 #$arg_string = "room=$room"; #$targetpath = "$targetdir/$targetcgi?$arg_string"; #とりあえず$targetpathの設定で2ヶ所、'htm'を挟んだ $targetpath = "$targetdir/htm/$room.html"; &make_connection($host,$port); &err("箱の取得に失敗しました。") if(&get_html($targethost,$targetpath,$referer,'')); @htmllines=grep(!/CONTENT=\"no\-cache\">/,@htmllines); #no-cacheのMETAタグ行を消す &get_votes; &err("項目の取得に失敗しました。") if(@votes == 0); &write_lines("$logdir/b${room}t.htm",@htmllines); #箱のトップページを書き出す $logfile = "$logdir/box${room}.txt"; open(DB,">$logfile");close(DB); $htmlfile = "$logdir/b${room}c.htm"; foreach $vt (@votes){ #各項目のコメントを取得 $targetpath = "$targetdir/htm/$details{$vt}"; &make_connection($host,$port); &get_html($targethost,$targetpath,$referer,''); &get_comments; &err("コメントの取得に失敗しました。") if(@comments == 0); &print_comments($logfile,$vt); # sleep($sleepsec); } &write_html($logfile,$htmlfile); &html;exit; ################################################## #取得した箱HTMLから項目へのリンク @details,@votesを抽出 sub get_votes { my($vote,$ln,$i,$v); @votes = (); %details = (); $ln = @htmllines-1; $v = 0; foreach $i (0 .. $ln){ if($htmllines[$i] =~ /ログは更新(取得)順に並んでいます。
_HTML_ print DB "注意事項
コメントの順は上から下が定着したようなので従来の下から上はやめました。
自分でCGIを実行している方は、getlog.txt
の「reverse」行をコメントアウトすると上から下、しなければ下から上になります。
_HTML_ #箱リストの取得 print <<"_HTML_";
箱リストを更新する
_HTML_ print ""; }#print_interface END ################################################## #引数のデコード sub decode { my($pair,$name,$value,@pairs,@lines); if ($ENV{'REQUEST_METHOD'} eq "POST"){ read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); }else{ $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/,$buffer); foreach $pair (@pairs){ ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; &jcode'convert(*value,'sjis'); $value =~ s/:#//g; $value =~ s/\t/ /g; $value =~ s/|//g; $value =~ s/</g;$value =~ s/>/>/g; $value =~ s/"/"/g; $value =~ s/\r//g;$value =~ s/\n//g; $FORM{$name} = $value if($name && $value); } $room = $FORM{'room'}; $proxyname = $FORM{'proxy'}; $getlist = $FORM{'getlist'}; $targetcgi = $FORM{'cgi'} if ($FORM{'cgi'} ne ''); }#decode END ################################################## #連続実行制限 sub execcheck{ my(@files,$file,$filedata); opendir(DIR,"$logdir"); @files = grep(/\w+\.htm/, readdir(DIR)); closedir(DIR); foreach $file (@files){ if($file ne $temporary){ $filedata = -M "./$logdir/$file"; if(int($filedata*24*60) < $seritime){ &err("CGIの連続実行制限にかかりました(詳細は注意事項を参照して下さい)。"); } } } } ################################################## sub err{ my($error); $error = $_[0]; print "Content-type: text/html\n\n"; print <<"_HTML_";$error