#!/usr/bin/perl #↑サーバーの設定に合わせてね #等幅でみてちょ(笑 (重要) #デザイン崩れてても文句いわないでね(^_^;) ############################################################## # # # megabbs.cgi ver1.69β1 by chiba # # <書き込み&html更新部分> # # # ############################################################## $cgi="megabbs.cgi"; $ver="1.69-903"; ######クレジット################################################## # <ベース> # # 2ch-Type BBS 2.1 build 2 Home: http://around.tripod.co.jp/ # # Mail: mono@nihen.on.arena.ne.jp # # <謎> # # Aska Board v1.2 Home: http://www.kent-web.com/ # # Mail: webmaster@kent-web.com) # ################################################################## ###########目次########### #(01)目次 #(02)メインルーチン (本筋) #(03)フォームのデコード (&decode) #(04)書き込み処理(スレッド) (®ist) #(05)書き込み処理(レス) (&resregist) #(06)投稿部分&メニューのhtml作成 (&makehtmlhead) #(07)スレッドのhtml作成 (&makehtmlbody) #(08)ロックファイル(symlink関数) (&lock1) #(09)ロックファイル(open関数) (&lock2) #(10)エラー処理 (&error) #(11)リメイク処理 (&remake) #(12)クッキーのセット (&set_cookie) #(13)スレッドのhtmlのリメイク (&remakehtml) #(14)リンク作成 (&makelink) #(15)カウント (&count) #(16)imode (&imode) ################################################## #############☆(02)メインルーチン☆############### ################################################## #config.cgiの読み込み。 open(CONF,"./config.cgi")|| &error("config.cgiが開けません","no"); @conf=; close(CONF); foreach(@conf){tr/\x0D\x0A//d;} ($sitename,$subtitle,$nanashiname,$delmessage,$resusuu,$suresuu,$menusuu,$sureseigen,$hostrec,$wrescheck,$trescheck,$new,$lockkey,$delcheck,$mailing,$mailto,$sendmail,$ng,$ngword,$namecolor,$capcolor,$sagecolor,$titlecolor,$body,$rogo,$table,$table2,$table3,$table4,$table6,$readresbody,$koukoku,$readtitlebody,$itenmessage,$pass,$htmlpath,$htmlzpath,$cgizpath,$kaigyouseigen,$shouryakuseigen,$countzpath,$rogosita,$version,$imode,$ranking,$ipath,$head,$headsuu,$headbody,$headtable,$jst,$meta)=@conf; $|=1; # jcode.plのパス require './jcode.pl'; &decode; #----------------------------------------フォームのデコード if ($mode eq "regist"){®ist;} elsif ($mode eq "res"){&resregist;}#--------------モードがresだったらレスをつける。 elsif($FORM{imode} eq "i"){&iregist;} &makehtmlhead;#-----------------------------------投稿部分とかのHTML作成 &makehtmlbody;#-----------------------------------スレッドの内容のHTML作成 # ロック解除 foreach $lockfiles (@lockfile){ if (-e "$lockfiles") { unlink($lockfiles); } } if($meta eq "はい"){ print "Content-type: text/html;charset=x-sjis\n\n"; print<<"_EOF_"; 自動ページ移動 自動ページ移動中です。
移動しない場合はこの文字列をクリックしてください。
_EOF_ }else{ print "Content-type: text/html;charset=x-sjis\n"; print "Location: $location\n\n"; } exit; ################################################## #############☆(03)フォームのデコード☆########### ################################################## sub decode { if ($ENV{'REQUEST_METHOD'} eq "POST") { if ($ENV{'CONTENT_LENGTH'} > 12000) { &error("投稿量が大きすぎます。","no"); } read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'};$method="get";} @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('H2',$1)/eg; # タグ処理 $value =~ s//>/g; $value =~ s/\"/"/g; $FORM{$name} = $value; } $name = $FORM{'name'}; $email = $FORM{'email'}; $com = $FORM{'com'}; $vires = $FORM{'vires'}; $mode = $FORM{'mode'}; $res = $FORM{'res'}; $board = $FORM{'board'}; $sub = $FORM{'sub'}; ##いろんな嵐対策 if($mode ne "" && $method eq "get"){&error("投稿方法がおかしいです","no");} if($board=~/\W/){&error("板指定方法がオカシイです","no");} unless(-e "./board/$board.txt"){&error("そんな板はありません。(管理人に連絡してください)","no");} open(BOARDMENU,"board.txt"); while(){ chomp; ($logboard,$itenyes)=(split /<>/)[0,3]; if($logboard eq $board){last;} } close(BOARDMENU); if($itenyes eq "yes"){&error("この板はすでに移転済みです","no");} $brsuu=$com=~tr/\n//; if($brsuu > $kaigyouseigen){&error("改行数が多すぎます。","no");} $com=~s/\x0D\x0A/
/g; $com=~s/\x0D/
/g; $com=~s/\x0A/
/g; $com2=$com; $com2=~s/
//g; $com2=~s/ //g; $com2=~tr/ //d; $com2=~tr/\t//d; $name=~tr/\x0D\x0A//d; $email=~tr/\x0D\x0A//d; $sub=~tr/\x0D\x0A//d; if ($com2 eq "" && $mode ne "") { &error("本文が書き込まれていません","no");} if(length $sub >100){ &error("タイトルが長すぎます","no"); } if(length $name >64){ &error("長い名前では投稿できません","no"); } #板の設定ファイルを開く open(BOARD,"./board/$board.txt")|| &error("./board/$board.txtが開けません","no"); ($bbstitle,$setumei,$nanashiname,$bodybo,$oekaki,$sureddosuu,$menusureddosuu,$resusuubo,$sureseigenbo,$hostrec,$trescheck,$wrescheck,$rogobo,$tablebo,$table6bo,$table2bo,$table3bo,$table4bo,$koukokubo,$rogositabo,$newbo,$ibo,$nanashiita,$menuhyouji,$rankingbo,$headbo,$headsuubo,$headtablebo)=split(/<>/,); close(BOARD); $resusuu=$resusuubo || $resusuu; $suresuu=$sureddosuu || $suresuu; $menusuu=$menusureddosuu || $menusuu; $sureseigen=$sureseigenbo || $sureseigen; $body=$bodybo || $body; $table=$tablebo || $table; $table6=$table6bo || $table6; $table2=$table2bo || $table2; $table3=$table3bo || $table3; $table4=$table4bo || $table4; $headtable=$headtablebo || $headtable; $headsuu=$headsuubo || $headsuu; if($nanashiita eq "nanashi"){$name=$nanashiname;} elsif($mode ne "" && $nanashiita eq "kotei" && ($name eq "" || $name=~/^#nanashisan/)){&error("名前いれてください。","no");} elsif($mode ne "" && ($nanashiita eq "cap" && ($name !~/^#/ || $name =~/^#nanashisan/))){&error("キャップ持ちしか発言できません。","no");} #名前変換処理 if ($name eq ""){$name=$nanashiname;} if($mode ne ""){&set_cookie;} if($name=~/^#nanashisan/){ $namei = $name; ($name,$iro) = split(/,/,$namei,2); if ( 7 < length $iro ) {&error("色指定が長すぎます","no");} $name ="\$nanashiname<\/font\>"; } #キャップ処理 elsif ($name=~/^([^#]*)?#([^#]*)#?(.*)?$/){ open(USER,"./cap/$2.cgi")|| &error("キャップ使用方を確認してください.","no"); $name=; close(USER); $name ="\$name \<\/font\>"; $name="$1$name$3"; } $name=~s/fusianasan/<\/b>$ENV{REMOTE_ADDR}/g; $name .= " "; # 一時ファイルを定義 if ($$ eq '') { srand; $tempfile ="1000000000000000 * rand".'.tmp'; }else{$tempfile="$$.temp"} $tmpfile = "$temp" . '.tmp'; $com =~ s/(https?):\/\/([\w\.\?\/&=_~%#\@+,:-]+)/$1:\/\/$2<\/a>/g; if ($email eq "haba" || $email eq "tohaba" ||$FORM{touhaba} eq "on"){$com="$com";$tt=1;} if ($email eq "pre" || $FORM{pre} eq "on"){$com="
$com
";$pre=1;} # 日時の取得 $ENV{'TZ'} = "JST-9"; ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime($jst+time); # 日時のフォーマット $date = sprintf("%04d/%02d/%02d(%s) %02d:%02d", $year+1900,$mon+1,$mday,('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$wday],$hour,$min); $countdate=sprintf("%04d%02d%02d",$year+1900,$mon+1,$mday); # ロックファイル名 @lockfile = ("./lock/$board.lock"); $lognewfile="$htmlpath/$board/${board}_newb.txt"; # ロック処理 if($lockkey eq 'symlink'){&lock1;} elsif($lockkey eq 'open'){&lock2;} if(!(-e "$lognewfile") || -z "$lognewfile" || $FORM{remake} eq "yes"){&remake;} $lognewsuu=0; my($first)=0; open(LOG,$lognewfile) || &error("$lognewfileが開けません","lock"); eval{flock(LOG,1);}; while() { $lognewsuu++; if($first == 0){$first=$_;} $last=$_; } close(LOG); if($first ne $last){&remake;} $location = "$htmlzpath/$board/index.html"; } ################################################## #######☆(04)書き込み処理(スレッド)☆########### ################################################## sub regist { if ($hostrec eq "はい" && open(LOG,"$htmlpath/$board/writehost.dat")){ ($logs,$logdate) = split (/<>/,); close(LOG); if ($ENV{REMOTE_ADDR} eq $logs && $logdate eq $countdate){&error("連続でスレッドを作ることはできません
他の人がスレッドを立てるか、一日たつのを待ってください。","lock");} } if ($sub eq "") {&error("タイトルが記入されていません","lock");} if(length $sub > 60){&error("タイトルが長すぎます","lock"); } $loge=time; while(-e "$htmlpath/$board/txt/${board}_${loge}a.txt"){$loge++;} @ng=split(/,/,$ng); foreach(@ng){ if($com=~/$_/){&error("SPAMうぜぇぇぇ!!!!!!!","lock");} } $com =~ s/>>([0-9]+)\-([0-9]+)/
>>$1\-$2<\/a>/g; $com =~ s/>>([0-9]+)(?![-\d])/>>$1<\/a>/g; $com =~ s/>>([^\d][^<]*)/&makelink($1,$loge)/eg; $writefile="$htmlpath/$board/txt/${board}_${loge}a.txt"; open(OUTR,">$tmpfile") || &error("$tmpfileが開けません","lock"); print OUTR "$loge\n"; print OUTR "$loge<>$sub<>1\n"; my ($count)=0; open(LOGNEW,$lognewfile) || &error("$lognewfileが開けません","lock"); eval{flock(LOGNEW,1);}; while() { if($count < $sureseigen ){ if($count >0 && $count < $lognewsuu-1){print OUTR;} } elsif($count >0 && $count < $lognewsuu-1){push(@sen,$_);$lognewsuu--;} $count++; } close(LOGNEW); print OUTR "$loge\n"; close(OUTR); chmod (0666,$tmpfile); rename ($tmpfile,$lognewfile) || system("mv", $tmpfile, $lognewfile)|| &error("Rename error","lock"); if (-e $tmpfile) { unlink($tmpfile); } $lognewsuu++; if($FORM{mode2} eq "oekaki"){ if($FORM{jouge} eq "ue"){$com="$com
"."";} elsif($FORM{jouge} eq "sita"){$com="
"."$com";} } open(LOCK,$lockfile[0]); eval{flock(LOCK,2);}; open(OUT,">$writefile") || &error("$writefileが開けません","lock"); eval{flock(OUT,2);}; print OUT "$date<>$name<>$sub<>$com<>1<>$email<><>$FORM{mode3}<>\n"; close(OUT); close(LOCK); foreach(@sen){ chomp; ($logg,$suba,$nototal)=split /<>/; $loglog="$htmlpath/$board/txt/${board}_${logg}a.txt"; $loglogb="$htmlpath/$board/txt/${board}_${logg}b.txt"; $ahtml="$htmlpath/$board/html/${board}_${logg}.html"; $log2="$htmlpath/$board/log/${board}_${logg}.txt"; open(LOG,">$log2") || &error("$log2が開けません","lock"); eval{flock(LOG,2);}; open(LOGA,"$loglog")|| &error("$loglogが開けません","lock"); $logloog=; close(LOGA); print LOG "$logloog"; ($logdate,$logtitle,$logpng)=(split(/<>/,$logloog))[0,2,7]; unlink("$htmlpath/$board/png/$logpng.png"); open(LOGB,"$loglogb"); while(){print LOG "$_";} close(LOGB); close(LOG); unlink("$ahtml"); unlink("$loglog"); unlink("$loglogb"); open(LOCK,"$lockfile[0]"); eval{flock(LOCK,2);}; open(LHTM,">>$htmlpath/$board/log/index.html"); print LHTM <<"_EOF_";
$logtitle        $logdate
_EOF_ close(LHTM); close(LOCK); } #最新20件CGIへぶちこむ if($new eq "はい" && $newbo eq "はい"){ $news="$htmlpath/new.txt"; open (TMP,">$tmpfile"); print TMP "$board<>$loge<>$sub<>1<>$cpass<>\n"; open(OLD,"$news"); $count=0; while(){ if($count <= 18){print TMP "$_";$count++;} } close(OLD); close(TMP); rename($tmpfile,$news)|| system("mv", $tmpfile, $news)|| &error("Rename Error","lock"); } #最新20件CGIへぶちこまれた if($imode eq "はい" && $ibo eq "はい"){&imode;} if($ranking eq "はい" && $rankingbo eq "はい"){&count;} if($head eq "はい" && $headbo eq "はい"){&headline;} if($FORM{mode2} eq "i"){$location = "$htmlzpath/$board/i/index.html";} else{$location = "$htmlzpath/$board/index.html";} ###------html作成 $htm="$htmlpath/$board/html/${board}_${loge}.html"; if ($email ne "") {$name = "$name";} if($namecolor){$fontname="  $name";} else{$fontname="  $name";} open(HHH,">$htm"); eval{flock(HHH,2);}; if($delcheck eq "all"){$checkbox="\";} print HHH<<"_EOF_";
1$fontname  $date$checkbox
$com
_EOF_ close(HHH); ####-----html作成ここまで ###########--------メールの転送 if($mailing eq "はい"){ $mail_sub = "$bbstitleにスレッドがたてられました($loge)"; &jcode'convert(*mail_sub,'jis'); &jcode'convert(*name,'jis'); &jcode'convert(*sub,'jis'); &jcode'convert(*com,'jis'); $com =~ s/
/\n/g; $com =~ s/<//g; if (open(MAIL,"| $sendmail $mailto")) { print MAIL "To: $mailto\n"; # メールアドレスがない場合はダミーメールに置き換え if ($email eq "") { $email = "nomail\@xxx.xxx"; } print MAIL "From: $email\n"; print MAIL "Subject: $mail_sub\n"; print MAIL "MIME-Version: 1.0\n"; print MAIL "Content-type: text/plain; charset=ISO-2022-JP\n"; print MAIL "Content-Transfer-Encoding: 7bit\n\n"; print MAIL "--------------------------------------------------------\n"; print MAIL "投稿日 : $date\n"; print MAIL "題名 : $sub\n"; print MAIL "名前 : $name\n"; print MAIL "Email: $email\n"; print MAIL "$com\n\n"; print MAIL "$cgizpath\/readres.cgi\?bo=$board\&vi=$loge\&res=1\n"; print MAIL "--------------------------------------------------------\n"; close(MAIL); } } ################----------メールの転送終わり if($hostrec eq "はい"){ open(HOST,">$htmlpath/$board/writehost.dat"); print HOST "$ENV{REMOTE_ADDR}<>$countdate<>"; close(HOST); chmod 0600,"$htmlpath/$board/writehost.dat"; } } ################################################## ###########☆(05)書き込み処理(レス☆############# ################################################## sub resregist { #嵐対策 $res =~ /^[0-9]+$/ || &error("スレッド指定がおかしいです。","lock"); @ng=split(/,/,$ng); foreach(@ng){ if($com=~/$_/){&error("SPAMうぜぇぇぇ!!!!!!!","lock");} } # >>荒らし対策。 my $linknummax = 10; #番号リンクは10桁まで my $linkkaisu = 20; #リンクの回数制限 my $linkz = 0; my $taihisimasu = $_; $_ = $com; $linkz = s/>>([0-9]{1,$linknummax})\-([0-9]{1,$linknummax})/>>$1\-$2<\/a>/g; $linkz += s/>>([0-9]{1,$linknummax})(?![-\d])/>>$1<\/a>/g; $linkz += s/>>([^\d][^<]*)/&makelink($1,$res)/eg; $com=$_; $_ = $taihisimasu; if ($linkz > $linkkaisu){&error("レスでの>>は、$linkkaisu 回以上使用できません","lock");} #$com =~ s/>>([0-9]+)\-([0-9]+)/>>$1\-$2<\/a>/g; #$com =~ s/>>([0-9]+)(?![-\d])/>>$1<\/a>/g; #$com =~ s/>>([^\d][^<]*)/&makelink($1,$res)/eg; $writefile = "$htmlpath/$board/txt/${board}_${res}b.txt"; $readfile = "$htmlpath/$board/txt/${board}_${res}a.txt"; $resno=0; if (open(IN,"$writefile")){ while(){ $resno++; $old=$_; } close(IN); $oldcom= (split(/<>/, $old))[2]; $com2=$com; $com2=~tr/ //d;$com2=~s/ //g;$oldcom=~tr/ //d;$oldcom=~s/ //g; if ($com2 eq $oldcom && $wrescheck eq "はい") {&error("二重投稿は禁止です。","lock");} } else {$resno=0;} #多重投稿ちぇーーっく if($trescheck eq "はい"){ open(TAJ,"$htmlpath/$board/tajuu.txt"); eval{flock(TAJ,1);}; $oldcom=; close(TAJ); if($oldcom eq $com){&error("多重投稿は禁止です","lock");} open(TAJ,">$htmlpath/$board/tajuu.txt"); eval{flock(TAJ,2);}; print TAJ "$com"; close(TAJ); } open(OUT,"$readfile") || &error("$readfileが開けません。","lock"); $suba=; close(OUT); ($sub,$alldel)=(split(/<>/,$suba))[2,6]; chomp($alldel); if($alldel eq "alldel"){&error("このスレッドは既に移転もしくは削除されています","lock");} $resno=$resno+2; #2001以上は書き込めない my $threadresmax = 2001; if ($resno > $threadresmax){&error("$threadresmax レス以上書き込むことはできません","lock");} if ($FORM{sage} ne 'on' && $email ne 'sage') { open(OUTR,">$tmpfile") ||&error("$tmpfileが開けません。","lock"); print OUTR "$res\n"; print OUTR "$res<>$sub<>$resno\n"; my($count)=0; open(LOGNEW,$lognewfile) || &error("$lognewfileが開けません","lock"); eval{flock(LOGNEW,1);}; while() { if($count > 0 && $count < $lognewsuu-1){ $td=(split(/<>/,$_))[0]; if ($res ne $td){print OUTR;} } $count++; } close(LOGNEW); print OUTR "$res\n"; close(OUTR); chmod (0666,$tmpfile); rename ($tmpfile,$lognewfile) || system("mv", $tmpfile, $lognewfile)|| &error("Rename error","lock"); if (-e $tmpfile) {unlink($tmpfile);} } else{$name = "$name<\/font>";} if($brsuu > $shouryakuseigen){ $shouryaku="yes"; if($pre){$shouryaku.="_pre";} if($tt){$shouryaku.="_tt";} } my $write_secs = (stat($writefile))[9]; open(LOCK,$lockfile[0]); eval{flock(LOCK,2);}; open(OUT,">>$writefile") || &error("$writefileが開けません。","lock"); eval{flock(OUT,2);}; print OUT "$date<>$name<>$com<>$resno<>$email<><>$shouryaku<>\n"; close(OUT); close(LOCK); if ($FORM{sage} eq 'on' || $email eq 'sage') { utime $write_secs,$write_secs,$writefile; } else{ #最新20件CGIへぶちこむ if($new eq "はい" && $newbo eq "はい"){ $news="$htmlpath/new.txt"; open (TMP,">$tmpfile"); print TMP "$board<>$res<>$sub<>$resno<>$cpass<>\n"; open (NEW,"$news"); $count=1; while (){ ($boardnew,$resnew)=split/<>/; if(($board ne $boardnew || $res ne $resnew ) && $count < 20){print TMP;$count++;} } close(NEW); close(TMP); rename ($tmpfile,$news) || system("mv", $tmpfile, $news)|| &error("Rename error","lock"); if (-e $tmpfile) {unlink($tmpfile);} } #最新20件CGIへぶちこまれた } if($imode eq "はい" && $ibo eq "はい"){&imode;} if($ranking eq "はい" && $rankingbo eq "はい"){&count;} if($head eq "はい" && $headbo eq "はい"){&headline;} $location = "$htmlzpath/$board/index.html"; if($FORM{i} eq "on"){ if ($vires eq "on"){$location = "$cgizpath/readres.cgi?bo=$board\&vi=$res&i=on";} else{$location = "$htmlzpath/$board/i/index.html";} } elsif ($vires eq "on"){$location = "$cgizpath/readres.cgi?bo=$board\&vi=$res\&rm=75";} elsif($FORM{new} eq "on" && $FORM{jump} ne "on"){$location = "$cgizpath/new.cgi";} ###----html作成 $htm="$htmlpath/$board/html/${board}_${res}.html"; chomp($suba); ($datea,$namea,$subab,$msga,$noa,$emaila,$delmes) = split(/<>/, $suba); if ($emaila ne "") {$namea = "$namea";} if($namecolor){$fontname="  $namea";} else{$fontname="  $namea";} open(HTM,">$htm"); eval{flock(HTM,2);}; if($delcheck eq "all" && $delmes !~/del/){$checkbox="\";} else{$checkbox="";} print HTM<<"_EOF_";
1$fontname  $datea$checkbox
$msga
_EOF_ $count=1; open(IN,"$writefile"); if($resno < $resusuu){$printing=1;} else{$printing = $resno - $resusuu;} while(){ $count++; if($count > $printing){ chomp; ($dater,$namer,$msg,$nor,$emailr,$delmes,$shouryakuyes) = split /<>/; $printres=$nor; if($delmes eq "toumeidel"){$count--;next;} if($shouryakuyes =~/yes/){ @msg=split(/
/,$msg); $msg=""; for(0..$shouryakuseigen){ $msg.="$msg[$_]
"; } $shouryaku=<<"_EOF_";
省略されました全文を見る _EOF_ if($shouryakuyes=~/pre/){$shouryaku="$shouryaku";} if($shouryakuyes=~/tt/){$shouryaku="$shouryaku";} } else{$shouryaku="";} if ($emailr ne "") {$namer = "$namer";} $fontname=""; if($namecolor){$fontname="  $namer";} else{$fontname="  $namer";} if($delcheck eq "all" && $delmes ne "del"){$checkbox="\";} else{$checkbox="";} print HTM<<"_EOF_";
$printres$fontname  $dater$checkbox
$msg$shouryaku
_EOF_ } } close(IN); close(HTM); ###-----html作成ここまで ###########--------メールの転送 if($mailing eq "はい"){ $mail_sub = "$boardの$subaにレスがつけられました($res)"; &jcode'convert(*mail_sub,'jis'); &jcode'convert(*name,'jis'); &jcode'convert(*com,'jis'); $com =~ s/
/\n/g; $com =~ s/<//g; if (open(MAIL,"| $sendmail $mailto")) { print MAIL "To: $mailto\n"; # メールアドレスがない場合はダミーメールに置き換え if ($email eq "") { $email = "nomail\@xxx.xxx"; } print MAIL "From: $email\n"; print MAIL "Subject: $mail_sub\n"; print MAIL "MIME-Version: 1.0\n"; print MAIL "Content-type: text/plain; charset=ISO-2022-JP\n"; print MAIL "Content-Transfer-Encoding: 7bit\n\n"; print MAIL "--------------------------------------------------------\n"; print MAIL "投稿日 : $date\n"; print MAIL "名前 : $name\n"; print MAIL "Email: $email\n"; print MAIL "$com\n\n"; print MAIL "$cgizpath\/readres.cgi?bo=$board\&vi=$res\&res=$resno\n"; print MAIL "--------------------------------------------------------\n"; close(MAIL); } } ################----------メールの転送終わり } ################################################## ######☆(06)投稿部分&メニューのhtml作成☆######## ################################################## sub makehtmlhead{ open CRYPT,"$htmlpath/$board/crypt.txt"; $boardcry=; close CRYPT; $boardcry=~tr/\n//d; $write_html="$htmlpath/$board/index.html"; $ST=$suresuu+1; $ED=$suresuu+$suresuu; open(HTML,">$write_html"); eval{flock(HTML,2);}; print HTML<<"_EOF_"; $bbstitle $body _EOF_ if ($imode eq "はい" && $ibo eq "はい"){ print HTML<<"_EOF_"; i-mode _EOF_ } print HTML<<"_EOF_"; $rogobo $table
00$bbstitle$subtitle
$setumei
リロード 00
_EOF_ if($oekaki eq "yes"){ print HTML <<"_EOF_";
お絵かきする

_EOF_ } else{ print HTML <<"_EOF_";
pre  等幅
題名:
_EOF_ if($nanashiita ne "nanashi"){ print HTML <<"_EOF_"; 名前:
_EOF_ } print HTML <<"_EOF_";

_EOF_ } $bbstitleb=$bbstitle; $htmlzpathb=$htmlzpath; $bbstitleb =~ s/([^\w ])/'%' . unpack('H2', $1)/eg; $bbstitleb =~ tr/ /+/; $htmlzpathb =~ s/([^\w ])/'%' . unpack('H2', $1)/eg; $htmlzpathb =~ tr/ /+/; print HTML<<"_EOF_"; 板が壊れているときなどはここをクリックしてください _EOF_ if ($ranking eq "はい" && $rankingbo eq "はい"){ print HTML<<"_EOF_";
板別Ranking _EOF_ } else{print HTML "
";} if($new eq "はい" && $newbo eq "はい"){ print HTML<<"_EOF_"; 最新20件 on $sitename(i)  _EOF_ } print HTML<<"_EOF_"; 次のページを見る  過去ログメニュ  リロード
_EOF_ if($menuhyouji eq "はい"){ print HTML<<"_EOF_"; $table6 _EOF_ open(MENU,"./boardmenu.txt"); while(){print HTML;} close(MENU); print HTML<<"_EOF_"; _EOF_ } print HTML<<"_EOF_"; $koukokubo $table2 _EOF_ my($count)=0; open(LOGNEW,$lognewfile) || &error("$lognewfileが開けません","lock"); eval{flock(LOGNEW,1);}; if($lognewsuu-2 > $menusuu){$fileend=$menusuu;} else{$fileend=$lognewsuu-2;} while($logfile=) { if($count > 0 && $count <= $fileend){ $logfile=~tr/\x0D\x0A//d; ($logg,$sub,$nototal)=split(/<>/,$logfile); if ($count < $suresuu){ print HTML<<"_EOF_"; $count-$sub($nototal)/ _EOF_ } elsif ($count == $suresuu){ print HTML<<"_EOF_"; $count-$sub($nototal)
_EOF_ } else{ print HTML<<"_EOF_"; $count-$sub($nototal)/ _EOF_ } } $count++; } print HTML<<"_EOF_";

次のページを見る  過去ログメニュ  リロード  全文検索

_EOF_ } ################################################## #########☆(07)スレッドのhtml作成☆############### ################################################## sub makehtmlbody { seek(LOGNEW,0,0); my($count)=0; if($lognewsuu-2 > $suresuu-1){$fileend=$suresuu;} else{$fileend=$lognewsuu-2;} while(){ if($count > 0 && $count <= $fileend){ tr/\x0D\x0A//d; ($logg,$suba,$nototal)=split /<>/; $article="${board}_${logg}"; $ahtml="$htmlpath/$board/html/${board}_${logg}.html"; unless(-e "$ahtml"){&remakehtml;} $count2=$count-1; $count3=$count+1; $count4=sprintf("%02d",$count); if($delcheck eq "all"){ print HTML<<"_EOF_";
_EOF_ } print HTML<<"_EOF_"; $table3
$count4 $suba 全レス 最新50件 リロード トップ $count4
_EOF_ open(HHM,"$ahtml"); while(){print HTML;} close(HHM); if($delcheck eq "all"){ print HTML<<"_EOF_";
_EOF_ } print HTML<<"_EOF_";
sage  pre  等幅 _EOF_ if($nanashiita ne "nanashi"){ print HTML <<"_EOF_";
名前 _EOF_ } print HTML <<"_EOF_";

 レスを全部見る  最新レス100件  リロード  トップに戻る ($article)

_EOF_ } $count++; } print HTML<<"_EOF_"; $table4 次のページを見る $rogositabo

$cgi ver.$ver
(c)megabbs
(original) _EOF_ if($oekaki eq "yes"){ print HTML <<"_EOF_";
お絵かきしぃ掲示板PaintBBS
Client Program しぃちゃん
Server Program 藍珠
_EOF_ } print HTML<<"_EOF_";

_EOF_ close(HTML); } ################################################## #####☆(08)ロックファイル(symlink関数)☆######## ################################################## sub lock1 { foreach $lockfiles (@lockfile){ local($retry) = 10; while (!symlink(".",$lockfiles)) { if (--$retry <= 0) { &error("LOCK is BUSY","lock"); } sleep(1); } } } ################################################## #####☆(09)ロックファイル(open関数)☆########### ################################################## sub lock2 { foreach $lockfiles (@lockfile){ local($flag) = 0; foreach (1 .. 10) { if (-e $lockfiles) { sleep(1); } else { open(LOCK,">$lockfiles") || &error("Write Error : $lockfiles","lock"); close(LOCK); $flag = 1; last; } } if ($flag == 0) { &error("LOCK is BUSY","lock"); } } } ################################################## ###############☆(10)エラー処理☆################# ################################################## sub error { if ($_[1] eq "lock"){foreach $lockfiles (@lockfile){if( -e $lockfiles){ unlink($lockfiles); }}} if (-e $tmpfile) { unlink($tmpfile); } if ($HEAD eq "") { print "Content-type: text/html;charset=x-sjis\n\n";} print <<"_EOF_";
エラー
$_[0]
$FORM{com}
_EOF_ exit; } ################################################## #############☆(11)リメイク処理☆################# ################################################## sub remake{ opendir(DIR,"$htmlpath/$board/txt"); #↓ここで作るハッシュは、「時間 . キー」をキーにして、中にはキーがセットしてあるにょ。 foreach $files (grep!/^..?$/,readdir DIR){ $files=~tr/\x0D\x0A//d; $files=~/^${board}_(.*)(a|b)\.txt$/; if($2 eq 'a'){ if (! -e "$htmlpath/$board/txt/${board}_${1}b.txt"){ my($mtime) = (stat("$htmlpath/$board/txt/$files"))[10]; $time{"$mtime"."$files"}="$files"; } } elsif($2 eq 'b'){ my($mtime) = (stat("$htmlpath/$board/txt/$files"))[10]; $time{"$mtime"."$files"}="$files"; } } closedir (DIR); #さっき作ったハッシュのキーだけを取り出して配列を作ってるにょ @mtime = keys(%time); #で、その配列をソート関数使ってソートするにょ @sorting = sort {$b <=> $a} @mtime; $lognewsuu=2; open(TMP,">$tmpfile"); print TMP "00001\n"; foreach $key (@sorting){ my($files)=$time{$key}; $files=~/^${board}_(.*)(?:a|b)\.txt$/; my($logapath)="$htmlpath/$board/txt/${board}_${1}a.txt"; my($logbpath)="$htmlpath/$board/txt/${board}_${1}b.txt"; open(LOG,"$logapath"); my($title)=(split(/<>/,))[2]; close(LOG); open(LOG,"$logbpath"); my($count)=0; while(read LOG, $_, 1024) { $count += tr/\n//; } close(LOG); $count++; if($files=~/^${board}_(.*)(?:a|b)\.txt$/){ print TMP "$1<>$title<>$count\n"; $lognewsuu++; } } print TMP "00001\n"; close (TMP); rename($tmpfile,$lognewfile); } ################################################## ##########☆(12)クッキーのセット☆################ ################################################## sub set_cookie { local($xx, $cname, $cvalue); for $xx (split(/; */, $ENV{'HTTP_COOKIE'})) { ($cname, $cvalue) = split(/=/, $xx); $COOKIE{$cname} = $cvalue; } $ENV{'TZ'} = "GMT"; # 国際標準時を取得 ($secg,$ming,$hourg,$mdayg,$mong,$yearg,$wdayg,$ydayg,$isdstg)=localtime($jst+time+2592000);#30日間保存 $ENV{'TZ'} = "Japan"; $date_gmt =sprintf("%s, %02d-%s-%4d %02d:%02d:%02d GMT",('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday')[$wdayg],$mdayg,('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec')[$mong],$yearg+1900,$hourg,$ming,$secg); print "Set-Cookie: NAME=$name; expires=$date_gmt; path=/\n"; print "Set-Cookie: EMAIL=$email; expires=$date_gmt; path=/\n"; } ################################################## ##########☆(14)スレッドのhtmlのリメイク☆######## ################################################## sub remakehtml{ $ahtml="$htmlpath/$board/html/${board}_${logg}.html"; $a1stfile="$htmlpath/$board/txt/${board}_${logg}a.txt"; $b1stfile="$htmlpath/$board/txt/${board}_${logg}b.txt"; $article="${board}_${logg}"; open(LOG,$a1stfile); ($date,$name,$sub,$msg,$no,$email,$delmes) = split(/<>/,); close(LOG); $email=~tr/\x0D\x0A//d; if ($email ne "") {$name = "$name";} if($namecolor){$fontname="  $name";} else{$fontname="  $name";} open(HTM,">$ahtml"); eval{flock(HTM,2);}; if($delcheck eq "all" && $delmes!~/del/){$checkbox="\";} else{$checkbox="";} print HTM<<"_EOF_";
1$fontname  $date$checkbox
$msg
_EOF_ my($resukazu)=0; open(LOG,$b1stfile); while(read LOG, $_, 1024) { $resukazu += tr/\n//; } seek(LOG,0,0); my($count)=0; if(($resukazu-1) < $resusuu){$printing=0;} else{$printing = $resukazu - $resusuu;} while(){ $count++; if($count > $printing){ tr/\x0D\x0A//d; ($dater,$namer,$msg,$nor,$emailr,$delmes,$shouryakuyes) = split /<>/; $printres=$nor; if($delmes eq "toumeidel"){$count--;next;} $printres=$count+1; $shouryaku=""; if($shouryakuyes=~/yes/){ @msg=split(/
/,$msg); $msg=""; for(0..$shouryakuseigen){ $msg.="$msg[$_]
"; } $shouryaku=<<"_EOF_";
省略されました全文を見る _EOF_ if($shouryakuyes=~/pre/){$shouryaku="$shouryaku";} if($shouryakuyes=~/tt/){$shouryaku="$shouryaku";} } if ($emailr ne "") {$namer = "$namer";} if($namecolor){$fontname="  $namer";} else{$fontname="  $namer";} if($delcheck eq "all" && $delmes ne "del"){$checkbox="\";} else{$checkbox="";} print HTM<<"_EOF_";
$printres$fontname  $dater$checkbox
$msg$shouryaku
_EOF_ }} close(LOG); close(HTM); } ################################################## ################☆(15)リンク作成☆################ ################################################## sub makelink( $$ ){ my($targetName,$targetvi) = @_; my $handlemax = 40 ; #20文字を超えるハンドルはリンクからカット $oldname=$targetName; $targetName =~ s/([^\w ])/'%' . unpack('H2', $1)/eg; $targetName =~ tr/ /+/; if (length($targetName) > $handlemax){ return ">>$oldname" }; return ">>$oldname\x20<\/a>"; } ################################################## ################☆(16)カウント☆################## ################################################## sub count{ open LOCK,">./lock/count.lock"; eval{flock(LOCK,2);}; foreach my $countlog ("all","$countdate"){ my $countok=0; open COUNT,"./count/res$countlog.txt"; while(){ ($countsuu,$boardcount)=(split /<>/)[0,1]; if($boardcount eq $board){$countok=1;last;} } if(!$countok){$countsuu=0;} else{$countok=0;} $countsuu++; seek COUNT,0,0; open TMP,">count$tmpfile"; while(){ chomp; my ($countsuun,$boardcount,$boardnamecount,$htmlzpathbo)=split /<>/; if($boardcount ne $board){ if($countsuu >= $countsuun){ print TMP "$countsuu<>$board<>$bbstitle<>$htmlzpath<>\n$countsuun<>$boardcount<>$boardnamecount<>$htmlzpathbo<>\n"; $countok="1"; last; } else{print TMP "$_\n";} } } if($countok){ while(){ my $boardcount=(split /<>/)[1]; if($boardcount ne $board){print TMP;} } } else{print TMP "$countsuu<>$board<>$bbstitle<>$htmlzpath<>\n";} close COUNT; close TMP; rename "count$tmpfile" => "./count/res$countlog.txt"; } close LOCK; } ################################################## ##################☆(17)i-mode☆################## ################################################## sub imode{ if(! -e "$htmlpath/$board/i/."){mkdir "$htmlpath/$board/i",0777;} open(LOGNEW,"$htmlpath/$board/${board}_newb.txt"); $nonolog=; open(TMP,">$tmpfile"); print TMP <<"_EOF_"; $bbstitle $bbstitle@i
戻る
新規スレ

_EOF_ $count=0; while(){ $count++; if($count < 50 && $lognewsuu-1 > $count){ chomp; ($isureno,$isuresub,$iressuu)=split /<>/; print TMP "$isuresub($iressuu)
"; } else{last;} } close(LOGNEW); print TMP <<"_EOF_";
戻る _EOF_ close(TMP); rename($tmpfile,"$htmlpath/$board/i/index.html"); } ################################################## ##############☆(18)i-modeスレ☆################## ################################################## sub iregist{ open CRYPT,"$htmlpath/$board/crypt.txt"; $boardcry=; close CRYPT; $boardcry=~tr/\n//d; print <<"_EOF_"; Content-type: text/html $bbstitleにスレッドを立てる $bbstitleにスレッドを立てる
題名
_EOF_ if($nanashiita ne "nanashi"){ print <<"_EOF_"; 名前メール:
_EOF_ } print <<"_EOF_";
_EOF_ # ロック解除 foreach $lockfiles (@lockfile){ if (-e "$lockfiles") { unlink($lockfiles); } } exit; } ################################################## ##############☆(18)ヘッドライン作成☆############ ################################################## sub headline{ #板独自html my ($count)=0; my($mylognew)=$lognewsuu-2; open HEAD , ">$board/head.html"; print HEAD <<"_EOF_"; $headtable  $bbstitle[$mylognew][Last update $date]  _EOF_ open LOG , "$htmlpath/$board/${board}_newb.txt"; while(){ if(/<>/ && $count < $headsuu){ $count++; tr/\n//d; my ($logvi,$logtitle,$logres)=split/<>/; print HEAD "$count-$logtitle($logres)/"; } } close LOG; print HEAD <<"_EOF_"; _EOF_ close HEAD; open TMP, ">$tmpfile"; open SUB, "head.txt"; print TMP "$board<>$bbstitle<>\n"; while (){tr/\n//d;my ($logboard,$logtitle)=split/<>/;if($logboard ne $board){print TMP "$_\n"} } close SUB; close TMP; rename ("$tmpfile","head.txt"); #板独自html終了 #全体 open ALL,">$htmlpath/head.html"; print ALL <<"_EOF_"; ヘッドライン $headbody
_EOF_ open LOG,"head.txt"; while(){ my ($logboard,$logtitle)=split/<>/; print ALL "$logtitle/" } print ALL "

"; seek LOG,0,0; while(){ my ($logboard,$logtitle)=split/<>/; if(open HEAD,"$logboard/head.html"){ while (){print ALL;} close HEAD; print ALL "
"; } } close LOG; print ALL <<"_EOF_"; _EOF_ close ALL; } ######################################################### ####################------終了-------#################### ######################################################### exit;