#!/usr/local/bin/perl # 掲示板表示CGI # morries用 # # Parameters # bbfile : bulletin board file path & name # limit : 1ページに表示する項目数 # page : 表示させるページ(0~) %buff = ( 'Path_img',"/bb/", 'Path_html',"/bb/", 'Path_cgi',"/bin/bb/", 'lockFile',"./.lockm", 'bbfile',"./bbm3.dat", 'bbfilepath' ,undef, 'limit',10, 'page',0 ); if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $str, $ENV{'CONTENT_LENGTH'}); } else { $str = $ENV{'QUERY_STRING'}; } @querys = split(/&/,$str); foreach (@querys) { ($name,$value) = split(/=/,$_); $value =~ tr/+/ /; $value =~ s/%([a-fA-f0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $value =~ tr/,/;/; $buff{$name} = $value; } if($buff{"limit"} < 1){ $buff{"limit"} = 10; } # Lock file!!! $has_symlink = (eval('symlink("","");'), $@ eq ''); if($has_symlink){ while(!symlink('.', $buff{'lockFile'})) { if($i++ > 10) { # time-out error print "Content-Type: text/html\n\n"; print "\n"; print "

\n"; print 'サーバでタイムアウトが発生しました。'; print "\n"; exit(0); } sleep(1); } } else{ while(-e $buff{'lockFile'}) { if($i++ > 10) { # time-out error print "Content-Type: text/html\n\n"; print "\n"; print "

\n"; print 'サーバでタイムアウトが発生しました。'; print "\n"; exit(0); } sleep(1); } # lock open(LOCKON,"> $buff{'lockFile'}"); print LOCKON "Lock on\n"; close(LOCKON); } # Count bb data open(IN,"<$buff{'bbfile'}"); $recMax = 0; while(){ $recMax++; } close(IN); # Max page count $pageMax = int($recMax / $buff{'limit'}); if($recMax % $buff{'limit'}){ $pageMax++; } # 表示するページ番号 $dspPage = $buff{'page'}; if($dspPage >= $pageMax){ $dspPage = $pageMax; } $offsetRow = $dspPage * $buff{'limit'}; print "Content-type: text/html\n\n"; print "MORRIE'S BORD\n"; print "\n"; print "\n"; print "\n"; if($dspPage > 0){ $prev = $dspPage - 1; print "\n"; } if($dspPage < ($pageMax - 1)){ $next = $dspPage + 1; print "\n"; } print "
\n"; print "前ページ\n"; print "\n"; print "次ページ\n"; print "
\n"; $itemNo = 0; $printstart = 0; $offset = 0; $getCount = 0; open(IN,"<$buff{'bbfile'}"); print "\n"; while(){ if($offset >= $offsetRow){ @db = split(/,/,$_); chomp($db[9]); # OLD -> $db[0]:date $db[1]:title $db[2]:name $db[3]:email $db[4]:body $db[5]:link # $db[0]:date(yy) $db[1]:date(mn) $db[2]:date(day) $db[3]:date(hh) $db[4]:date(mm) # $db[5]:title $db[6]:name $db[7]:email $db[8]:body $db[9]:link print "\n"; print "\n"; if($db[7] ne ""){ print "\n"; } else{ print "\n"; } print "\n"; print "\n"; print "\n"; print "\n"; $getCount++; if($getCount >= $buff{'limit'}){ last; } } else{ $offset++; } } print "

$db[5]
\n"; print "

投稿者$db[6]$db[6]投稿日時$db[0]年$db[1]月$db[2]日 $db[3]時$db[4]分
$db[8]\n"; if($db[9] ne ""){ if($db[9] =~ /^http:\/\//){ print "
$db[9]\n"; } else{ print "
$db[9]\n"; } } print "


\n"; print "
\n"; print "
\n"; print "\n"; close(IN); # unlock unlink($buff{'lockFile'});