#! /usr/local/bin/perl ############################################ #BooGuestBook v1.04 / this program is free.# #(C) BooBooClub 2000-2006 # ############################################ #set data $max = '100'; $vmax = '20'; $cgi = './bgb.cgi'; $dat = './bgbdata.dat'; $admin = './bgbad.cgi'; $bgbtitle = 'BooGuestBook'; $head = ''; $linkname = ''; $write = ''; $linkurl = './linkurl'; $back = 'bgcolor="#ffffff" background="./bgb_b.gif"'; $linkc= 'text="#555555" link="#0000ff" vlink="880088"'; $nomail = '#888888'; $fonts = '2'; $autolink = 'on'; $margin = '100'; $blink = ''; $nlink = ''; #read lib require 'jcode.pl'; #file_lock &lock; $ENV{'TZ'}='JST-9'; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $year = ($year + 1900); $mon++; if ($sec < 10) { $sec = "0$sec";} if ($min < 10) { $min = "0$min";} if ($hour < 10){ $hour = "0$hour";} if ($mon < 10) { $mon = "0$mon";} if ($mday < 10){ $mday = "0$mday";} $time = "$year/$mon/$mday $hour:$min:$sec"; #read 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/\cM\n//g; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/\,//g; $value =~ s//>/ig; $value =~ s/\r\n|[\r\n]/
/ig; #prevent chr error &jcode'convert(*value,'sjis'); $FORM{$name} = $value; } #branch if($FORM{'submit'}){ ✓ &write; &html; } elsif($FORM{'write'}){ &whtml; } else{ &html; } sub check{ if($FORM{'name'} eq "" || $FORM{'txt'} eq ""){ &error; } } sub write{ open(DAT,"$dat"); @bgbdats = ; close(DAT); $last = $bgbdats[0]; @last = split(/,/,$last); chomp $last; if($last[4] ne ""){ $count = $last[4] + 1; } else{ $count = "1"; } if($autolink eq 'on'){ $FORM{'txt'} =~ s/(http:[\w\.\/\~\+\-\?%=&^]+)/$1<\/a>/g; $FORM{'txt'} =~ s/([\w\.\-]+@[\w\.\-]+)/$1<\/a>/g; } elsif($autolink eq 'onw'){ $FORM{'txt'} =~ s/(http:[\w\.\/\~\+\-\?%=&^]+)/$1<\/a>/g; $FORM{'txt'} =~ s/([\w\.\-]+@[\w\.\-]+)/$1<\/a>/g; } $wrt = "$time\,$FORM{'name'}\,$FORM{'mail'}\,$FORM{'txt'}\,$count\n"; unshift(@bgbdats,$wrt); $hml = @bgbdats; if($hml > $max){ $max--; @ndat = @bgbdats[0..$max]; } else{ @ndat = @bgbdats; } #write new dat open(DAT,">$dat"); print DAT @ndat; close(DAT); } sub html{ #get dat open(DAT,"$dat"); @bgbdats = ; close(DAT); #html print "Content-type: text/html\n\n"; print "$bgbtitle\n"; print "\n"; if($margin != 0){ print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; } print "
\n"; print "$head\n"; print "

\n"; print "$write\n"; print " $linkname\n"; print "
\n"; &view; print "\n"; print "
\n"; print "Produced by BooBooClub
\n"; print "[管理ページ]
\n"; print "
\n"; print "
\n"; if($margin != 0){ print "
\n"; } print "\n"; unlink("$lockfile"); exit 0; } sub whtml{ #html print "Content-type: text/html\n\n"; print "$bgbtitle\n"; print "\n"; if($margin != 0){ print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; } print "
\n"; print "$head\n"; print "

\n"; print " $linkname\n"; print "
\n"; &form; print "\n"; print "
\n"; print "Produced by BooBooClub
\n"; print "
\n"; print "
\n"; if($margin != 0){ print "
\n"; } print "\n"; unlink("$lockfile"); exit 0; } sub view{ if(!$FORM{'p'}){ $FORM{'p'} = ''; } if($FORM{'back'}){ $FORM{'p'} = $FORM{'b'}; } elsif($FORM{'next'}){ $FORM{'p'} = $FORM{'n'}; } $listcount = @target; @list = ("$FORM{'p'}","$vmax","","","",@bgbdats); @list = &list(@list); @bgbdats = splice(@list,5); if($list[2] eq '-'){ $noback = 1; } if($list[3] eq '-'){ $nonext = 1; } print "
\n"; print "
\n\n"; foreach $bgbdat(@bgbdats){ chomp $bgbdat; ($time,$name,$mail,$txt,$count) = split(/,/,$bgbdat); $time = substr($time,0,16); if($mail ne ""){ print "$name "; } else{ print "$name "; } print "($time) -$count-
"; print "
"; print "$txt\n\n"; print "
\n"; } if($nonext != 1){ print "$blink\n"; } if($noback != 1){ print "$nlink\n"; } print "
\n"; print "
\n"; } sub list{ local(@info[0..4],@list) = @_; local $long = @list; if($long < $info[0] * $info[1]){ $info[0] = int($long / $info[1]); } local $back = $info[0] - 1; local $next = $info[0] + 1; if($info[0] eq '' || $info[0] == 0){ $info[0] = 0; $back = '-'; } local $begin = $info[0] * $info[1]; local $end = ($info[0] + 1) * $info[1] - 1; if($long <= $end + 1){ $end = $long - 1; $next = '-'; } @list = @list[$begin..$end]; ("$begin-$end","$info[1]","$back","$next","",(@list)); } sub form{ print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "名前 :\n"; print "\n"; print "   E-mail:\n"; print "\n"; print "
\n"; print "
\n"; print "メッセージ:
\n"; print "\n"; print "
\n"; print ""; print " \n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; print "
\n"; } sub error{ print "Content-type: text/html\n\n"; print "$bgbtitle\n"; print "\n"; if($margin != 0){ print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; } print "

記帳エラー



\n"; print "お名前とメッセージをお書きください。
\n"; print "ブラウザのバックボタンで戻ってください。
\n"; print "
\n"; if($margin != 0){ print "
\n"; } print "\n"; unlink("$lockfile"); exit 0; } sub lock{ $lockfile = './lock/lockfile'; $retry = 1; until(symlink("$dat", "$lockfile")){ if(++$retry >= 30){ unlink("$lockfile"); exit 0; } sleep(1); } }