#!/usr/bin/perl # ========================================================================= # # /////CLEVER BBS Ver.4.21 (Shift_JIS)///// # # Copyright (C) 2003-2006 solo.design # All rights reserved # Script written by Junichiro Kondo # web site : http://solodesign.jp/ # mail : support@solodesign.jp # # ========================================================================= # 必要なファイルのパス指定 ------------------------------------------------ require './jcode.pl'; require './cgi-lib.pl'; require './bbsini.cgi'; # 設定終了 ---------------------------------------------------------------- # ------------------------------------------------------------------------- # メイン処理 # ------------------------------------------------------------------------- &decode; &axs_check; if ($mode eq "usr_del") { &usr_del; } elsif ($mode eq "regist") { ®ist; } elsif ($mode eq "res") { &res_form; } elsif ($mode eq "admin") { &admin; } elsif ($mode eq "check") { ✓ } elsif ($mode eq "find") { &find; } &html_log; # ------------------------------------------------------------------------- # アクセス制限 # ------------------------------------------------------------------------- sub axs_check { &get_host; local($flag)=0; foreach (@deny) { if (!$_) { next; } $_ =~ s/\*/\.\*/g; if ($host =~ /$_/i) { $flag=1; last; } } if ($flag) { &error("アクセスを許可されていません"); } } # ------------------------------------------------------------------------- # 画面に表示する前の設定 # ------------------------------------------------------------------------- # HTMLのヘッダー ------------------------------------------------ sub adminheader { print "Content-type: text/html\n\n"; print <<"EOM"; $title EOM } # 記事表示部のヘッダ -------------------------------------------- sub header { if (!$htm_renew) { print "Content-type: text/html; charset=Shift_JIS\n\n"; } open(SKIN, $cleverskin_html); $cleverskin = join('',); close(SKIN); ($head_html,$write_html,$mainhtml,$reshtml,$mafot_html,$fot_html) = split(//, $cleverskin); if ($htm_renew) { print OUT $head_html; } else { print $head_html; } } # 記事表示部の投稿欄 -------------------------------------------- sub write { if (!$htm_renew) { &get_cookie; $write_html =~ s/(name="name")/$1 value="$c_name"/i; $write_html =~ s/(name="email")/$1 value="$c_email"/i; $write_html =~ s/(name="url")/$1 value="http:\/\/$c_url"/i; $write_html =~ s/(name="pwd")/$1 value="$c_pwd"/i; } if ($mode eq "find") { $write_html =~ s/(name="word")/$1 value="$in{'word'}"/i; } if ($in{'cond'} eq 'or') { $write_html =~ s/(value="or")/$1 checked/i; } else { $write_html =~ s/(value="and")/$1 checked/i; } if ($htm_renew) { print OUT $write_html; } else { print $write_html; } } # 記事表示部のメイン -------------------------------------------- sub main { if (!$reno && $flag) { $flag=1; if ($htm_renew) { print OUT $mafot_html; } else { print $mafot_html; } } if (!$reno) { &auto_link($comment); $maintmp = $mainhtml; $maintmp =~ s/no/$no/i; $maintmp =~ s/name/$name/i; $maintmp =~ s/url/$url/i; $maintmp =~ s/sub/$sub/i; $maintmp =~ s/comment/$comment/i; $maintmp =~ s/date/$dat_tmp/i; $maintmp =~ s/mail/$mail/i; $maintmp =~ s/color/$color/i; if (-e "$ImgDir$no$tail") { $maintmp =~ s/img/$img/i; } else { $maintmp =~ s/img//i; } $maintmp =~ s/(a href="resinput")/a href="$script?mode=res&no=$no"/i; $flag=1; if ($htm_renew) { print OUT $maintmp; } else { print $maintmp; } } if ($reno) { &auto_link($comment); $restmp = $reshtml; $restmp =~ s/resno/$no/i; $restmp =~ s/resname/$name/i; $restmp =~ s/resurl/$url/i; $restmp =~ s/ressub/$sub/i; $restmp =~ s/rescomment/$comment/i; $restmp =~ s/resdate/$dat_tmp/i; $restmp =~ s/resmail/$mail/i; $restmp =~ s/rescolor/$color/i; if (-e "$ImgDir$no$tail") { $restmp =~ s/resimg/$img/i; } else { $restmp =~ s/resimg//i; } if ($htm_renew) { print OUT $restmp; } else { print $restmp; } } } # 記事表示部のフッタ -------------------------------------------- sub footer { $fottmp = $fot_html; $next = $page + $p_log; $back = $page - $p_log; $p_flag=0; if ($page_icon) { $page_back = ""; $page_next = ""; } else { $page_back = $back_text; $page_next = $next_text; } if ($mode eq "find") { if ($in{'word'} ne "") { if ($count >= 1) { $fottmp =~ s/footmsg/「$in{'word'}」を検索した結果ヒット数は$count件ありました。/i; } else { $fottmp =~ s/footmsg/「$in{'word'}」を検索した結果マッチする書き込みはありませんでした。/i; } if ($back_line >= 0) { $fottmp =~ s/back/$page_back<\/a>/i; } else { $fottmp =~ s/back//i; } if ($page_end ne "$end_data") { $fottmp =~ s/next/$page_next<\/a>/i; } else { $fottmp =~ s/next//i; } } else { $fottmp =~ s/footmsg/検索キーワードを入力してください。/i; $fottmp =~ s/back//i; $fottmp =~ s/next//i; } } else { $fottmp =~ s/footmsg//i; if ($back >= 0) { $p_flag=1; $fottmp =~ s/back/$page_back<\/a>/i; } else { $fottmp =~ s/back//i; } if ($next < $i) { $p_flag=1; $fottmp =~ s/next/$page_next<\/a>/i; } else { $fottmp =~ s/next//i; } } if ($htm_renew) { print OUT $fottmp; } else { print $fottmp; } } # レス記事部のヘッダ -------------------------------------------- sub resheader { print "Content-type: text/html; charset=Shift_JIS\n\n"; open(RES, $resskin_html); $resskin = join('',); close(RES); ($reshead_html,$reswrite_html,$resmainhtml,$resreshtml,$resmafot_html,$resfot_html) = split(//, $resskin); print $reshead_html; } # レス記事部の投稿欄 ------------------------------------------- sub reswrite { &get_cookie; if ($res_clip) { $reswrite_html =~ s/(method="POST")/$1 enctype="multipart\/form-data"/i; } else { $reswrite_html =~ s/(method="POST")/$1/i; } $reswrite_html =~ s/(name="name")/$1 value="$c_name"/i; $reswrite_html =~ s/(name="email")/$1 value="$c_email"/i; $reswrite_html =~ s/(name="url")/$1 value="http:\/\/$c_url"/i; $reswrite_html =~ s/(name="pwd")/$1 value="$c_pwd"/i; $reswrite_html =~ s/(name="reno")/$1 value="$in{'no'}"/i; print $reswrite_html; } # レス記事部のメイン -------------------------------------------- sub resmain { if ($in{'no'} eq "$no" || $in{'no'} eq "$reno") { $dat_tmp = $dateline; ($d_year,$d_mon,$d_day,$d_weekstr,$d_hour,$d_min,$d_sec) = split(/&/,$date); $dat_tmp =~ s/year/$d_year/i; $dat_tmp =~ s/month/$d_mon/i; $dat_tmp =~ s/day/$d_day/i; $dat_tmp =~ s/week/$d_weekstr/i; $dat_tmp =~ s/hour/$d_hour/i; $dat_tmp =~ s/minute/$d_min/i; $dat_tmp =~ s/second/$d_sec/i; if (!$reno) { &auto_link($comment); $resmaintmp = $resmainhtml; $resmaintmp =~ s/no/$no/i; $resmaintmp =~ s/name/$name/i; $resmaintmp =~ s/url/$url/i; $resmaintmp =~ s/sub/$sub/i; $resmaintmp =~ s/comment/$comment/i; $resmaintmp =~ s/date/$dat_tmp/i; $resmaintmp =~ s/mail/$mail/i; $resmaintmp =~ s/color/$color/i; if (-e "$ImgDir$no$tail") { $resmaintmp =~ s/img/$img/i; } else { $resmaintmp =~ s/img//i; } print $resmaintmp; } if ($reno) { &auto_link($comment); $resrestmp = $resreshtml; $resrestmp =~ s/resno/$no/i; $resrestmp =~ s/resname/$name/i; $resrestmp =~ s/resurl/$url/i; $resrestmp =~ s/ressub/$sub/i; $resrestmp =~ s/rescomment/$comment/i; $resrestmp =~ s/resdate/$dat_tmp/i; $resrestmp =~ s/resmail/$mail/i; $resrestmp =~ s/rescolor/$color/i; if (-e "$ImgDir$no$tail") { $resrestmp =~ s/resimg/$img/i; } else { $resrestmp =~ s/resimg//i; } print $resrestmp; if ($reno && !$flag) { $flag=1; } } } } # レス記事部のフッタ -------------------------------------------- sub resfooter { print $resfot_html; } # 検索記事表示部のメイン ---------------------------------------- sub findmain { &auto_link($comment); $findmaintmp = $mainhtml; $findmaintmp =~ s/no/$findno/i; $findmaintmp =~ s/name/$name/i; $findmaintmp =~ s/url/$url/i; $findmaintmp =~ s/sub/$sub/i; $findmaintmp =~ s/comment/$comment/i; $findmaintmp =~ s/date/$dat_tmp/i; $findmaintmp =~ s/mail/$mail/i; $findmaintmp =~ s/color/$color/i; if (-e "$ImgDir$no$tail") { $findmaintmp =~ s/img/$img/i; } else { $findmaintmp =~ s/img//i; } $findmaintmp =~ s/(a href="resinput")/a href="$script?mode=res&no=$resno"/i; print $findmaintmp; print $mafot_html; } # ------------------------------------------------------------------------- # HTML更新処理 # ------------------------------------------------------------------------- sub html_renew { if ($htmfile ne "") { open(OUT,">$htmfile") || &error("Write Error: $htmfile"); $htm_renew = 1; &header; &write; $start = $page + 1; $end = $page + $p_log; open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; $i=0; $flag=0; while () { ($no,$reno,$date,$name,$mail,$sub,$comment, $url,$host,$pw,$color,$tail,$w,$h,$chk) = split(/<>/); if ($reno eq "") { $i++; } if ($i < $start) { next; } if ($i > $end) { next; } $dat_tmp = $dateline; ($d_year,$d_mon,$d_day,$d_weekstr,$d_hour,$d_min,$d_sec) = split(/&/,$date); $dat_tmp =~ s/year/$d_year/i; $dat_tmp =~ s/month/$d_mon/i; $dat_tmp =~ s/day/$d_day/i; $dat_tmp =~ s/week/$d_weekstr/i; $dat_tmp =~ s/hour/$d_hour/i; $dat_tmp =~ s/minute/$d_min/i; $dat_tmp =~ s/second/$d_sec/i; if ($mail_icon && $mail) { $mail = ""; } elsif (!$mail_icon && $mail) { if ($name_link) { $name = "$name"; } else { $mail = "$mail_text"; } } if ($home_img) { $link_img = ""; } if ($home_icon && $url) { $url = ""; } elsif (!$home_icon && $url) { $url = "$home_text"; } &imgview; &main; } close(IN); print OUT $mafot_html; &footer; close(OUT); $htm_renew = 0; } } # ------------------------------------------------------------------------- # 記事表示部 # ------------------------------------------------------------------------- sub html_log { &header; &write; $start = $page + 1; $end = $page + $p_log; open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; $i=0; $flag=0; while () { ($no,$reno,$date,$name,$mail,$sub,$comment, $url,$host,$pw,$color,$tail,$w,$h,$chk) = split(/<>/); if ($reno eq "") { $i++; } if ($i < $start) { next; } if ($i > $end) { next; } $dat_tmp = $dateline; ($d_year,$d_mon,$d_day,$d_weekstr,$d_hour,$d_min,$d_sec) = split(/&/,$date); $dat_tmp =~ s/year/$d_year/i; $dat_tmp =~ s/month/$d_mon/i; $dat_tmp =~ s/day/$d_day/i; $dat_tmp =~ s/week/$d_weekstr/i; $dat_tmp =~ s/hour/$d_hour/i; $dat_tmp =~ s/minute/$d_min/i; $dat_tmp =~ s/second/$d_sec/i; if ($mail_icon && $mail) { $mail = ""; } elsif (!$mail_icon && $mail) { if ($name_link) { $name = "$name"; } else { $mail = "$mail_text"; } } if ($home_img) { $link_img = ""; } if ($home_icon && $url) { $url = ""; } elsif (!$home_icon && $url) { $url = "$home_text"; } &imgview; &main; } close(IN); print $mafot_html; &footer; } # ------------------------------------------------------------------------- # 返信フォーム # ------------------------------------------------------------------------- sub res_form { open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; &resheader; &reswrite; $flag=0; while () { ($no,$reno,$date,$name,$mail,$sub,$comment, $url,$host,$pw,$color,$tail,$w,$h,$chk) = split(/<>/); if ($mail_icon && $mail) { $mail = ""; } elsif (!$mail_icon && $mail) { if ($name_link) { $name = "$name"; } else { $mail = "$mail_text"; } } if ($home_icon && $url) { $url = ""; } elsif (!$home_icon && $url) { $url = "$home_text"; } &imgview &resmain } close(IN); print $resmafot_html; &resfooter; exit; } # ------------------------------------------------------------------------- # エラー処理 # ------------------------------------------------------------------------- sub error { &unlock if ($lockflag); &adminheader; print <<"EOM";

$_[0]


ブラウザのBackでお戻り下さい

EOM exit; } # ------------------------------------------------------------------------- # 管理モード # ------------------------------------------------------------------------- sub admin { if ($in{'pass'} eq "") { &adminheader; print <<"EOM";
For Webmaster only!

パスワードを入力して下さい。

  


EOM exit; } if ($in{'pass'} ne $pass) { &error("パスワードが違います"); } &adminheader; print <<"EOM";

For Webmaster
ここは管理者用のページです。
管理者以外のアクセスを禁止します。


管理用ページを終了し、表\示用ページに戻る。

EOM if ($in{'chk'}) { @CHK = split(/\0/, $in{'chk'}); if ($lockkey) { &lock; } @new=(); open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; while () { ($no,$reno,$d,$n,$m,$s,$com,$u,$ho,$p,$c,$t,$w,$h,$chk) = split(/<>/); foreach $xx (@CHK) { if ($no eq $xx) { $_ = "$no<>$reno<>$d<>$n<>$m<>$s<>$com<>$u<>$ho<>$p<>$c<>$t<>$w<>$h<>1<>\n"; last; } } push(@new,$_); } close(IN); unshift(@new,$top); open(OUT,">$logfile") || &error("Write Error : $logfile"); print OUT @new; close(OUT); if ($lockkey) { &unlock; } &html_renew; } if ($in{'del'}) { @DEL = split(/\0/, $in{'del'}); if ($lockkey) { &lock; } @new=(); open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; while () { $flag=0; ($no,$reno,$d,$n,$m,$s,$com,$u,$ho,$p,$c,$tail,$w,$h,$chk) = split(/<>/); foreach $del (@DEL) { if ($no eq $del || $reno eq $del) { if (-e "$ImgDir$no$tail") { unlink("$ImgDir$no$tail"); } $flag=1; last; } } if ($flag == 0) { push(@new,$_); } } close(IN); unshift(@new,$top); open(OUT,">$logfile") || &error("Write Error : $logfile"); print OUT @new; close(OUT); if ($lockkey) { &unlock; } &html_renew; } if ($in{'reno'}) { &get_time; open(IN,"$logfile") || &error("Open Error : $logfile"); @lines = ; close(IN); $top = shift(@lines); ($no,$ip,$time2) = split(/<>/, $top); $no++; if ($in{'pwd'} ne "") { $ango = &encrypt($in{'pwd'}); } if ($in{'upfile'}) { &UpFile; } $match=0; @new=(); foreach (@lines) { ($no2,$reno2) = split(/<>/); if ($match == 0 && $in{'reno'} eq "$no2") { $match=1; } elsif ($match == 1 && $in{'reno'} ne "$reno2") { $match=2; push(@new,"$no<>$in{'reno'}<>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$tail<>$W<>$H<>0<>\n"); } push(@new,$_); } if ($match == 1) { push(@new,"$no<>$in{'reno'}<>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$tail<>$W<>$H<>0<>\n"); } unshift(@new,"$no<>$addr<>$times<>\n"); open(OUT,">$logfile") || &error("Write Error : $logfile"); print OUT @new; close(OUT); &html_renew; } # 管理を表示 ---------------------------------------------------- if ($page eq "") {$page = 0; } print "
\n"; print "
  • 記事を削除する場合は番号左側のチェックボックスにチェックを入れ「送信する」を押して下さい。\n"; print "
  • 画像許可を行なう場合は「画像許可」のチェックボックスにチェックを入れ「送信する」を押して下さい。\n"; print "
  • レスをする場合は⇒RES左のラジオボタンを選択しレスフォームにメッセージを入力して「送信する」を押してください。
\n"; print "
\n"; print "\n"; print "\n"; #print "\n"; $start = $page + 1; $end = $page + 5; open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; $i=0; $flag=0; while () { $img_flag=0; ($no,$reno,$date,$name,$mail,$sub,$comment, $url,$host,$pw,$color,$tail,$w,$h,$chk) = split(/<>/); if ($reno eq "") { $i++; } if ($i < $start) { next; } if ($i > $end) { next; } $dat_tmp = 'year/month/day hour:minute'; ($d_year,$d_mon,$d_day,$d_weekstr,$d_hour,$d_min,$d_sec) = split(/&/,$date); $dat_tmp =~ s/year/$d_year/i; $dat_tmp =~ s/month/$d_mon/i; $dat_tmp =~ s/day/$d_day/i; $dat_tmp =~ s/week/$d_weekstr/i; $dat_tmp =~ s/hour/$d_hour/i; $dat_tmp =~ s/minute/$d_min/i; $dat_tmp =~ s/second/$d_sec/i; $date =$dat_tmp; if ($mail) { $name="$name"; } if ($url) { $url = "Website"; } else { $url = '-'; } &auto_link($comment); if (-e "$ImgDir$no$tail") { if ($tail eq ".gif" || $tail eq ".jpg" || $tail eq ".png") { $img_flag = 1; $File = "画像"; } else { $File = "File"; } $size = -s "$ImgDir$no$tail"; $all += $size; $clip = "[$File $size bytes]"; } else { $clip = ""; $size = 0; } if ($reno eq "") { print <<"EOM";
 
$no EOM if ($ImageCheck) { if ($img_flag == 1 && $chk == 1) { print "OK 画像許可 "; } elsif ($img_flag == 1 && $chk != 1) { print " 画像許可 "; } } print <<"EOM"; ⇒RES
$date [$host]
$name [$url] $clip

$sub
$comment

EOM } else { print <<"EOM";
 
$no EOM if ($ImageCheck) { if ($img_flag == 1 && $chk == 1) { print "OK 画像許可 "; } elsif ($img_flag == 1 && $chk != 1) { print " 画像許可 "; } } print <<"EOM";
$date [$host]
$name [$url] $clip

$sub
$comment

EOM } } close(IN); &get_cookie; print <<"EOM";
 
  レスフォーム
  お名前
  タイトル
  コメント
  URL
  E-Mail
  添付File
 

EOM print "\n"; $all = int ($all / 1024); print "【添付データ総数 : $all KB】
\n"; $next = $page + 5; $p_flag=0; if ($next < $i) { $p_flag=1; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; } print "
\n"; print "\n"; exit; } # ------------------------------------------------------------------------- # 検索処理 # ------------------------------------------------------------------------- sub find { &header; &write; # 検索の実行と結果表示 ------------------------------------------ if ($in{'word'} ne "") { $in{'word'} =~ s/ / /g; @pairs = split(/\s+/, $in{'word'}); # ファイルを読み込み -------------------------------------------- @new=(); open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; while () { $flag=0; foreach $pair (@pairs) { if (index($_,$pair) >= 0) { $flag=1; if ($in{'cond'} eq 'or') { last; } } else { if ($in{'cond'} eq 'and') { $flag=0; last; } } } if ($flag) { push(@new,$_); } } close(IN); # 検索終了 ------------------------------------------------------ $count = @new; if ($page eq '') { $page = 0; } $end_data = @new - 1; $page_end = $page + $p_log - 1; if ($page_end >= $end_data) { $page_end = $end_data; } $next_line = $page_end + 1; $back_line = $page - $p_log; $enwd = &url_enc($in{'word'}); foreach ($page .. $page_end) { ($no,$reno,$date,$name,$mail,$sub,$comment, $url,$host,$pw,$color,$tail,$w,$h,$chk) = split(/<>/, $new[$_]); $dat_tmp = $dateline; ($d_year,$d_mon,$d_day,$d_weekstr,$d_hour,$d_min,$d_sec) = split(/&/,$date); $dat_tmp =~ s/year/$d_year/i; $dat_tmp =~ s/month/$d_mon/i; $dat_tmp =~ s/day/$d_day/i; $dat_tmp =~ s/week/$d_weekstr/i; $dat_tmp =~ s/hour/$d_hour/i; $dat_tmp =~ s/minute/$d_min/i; $dat_tmp =~ s/second/$d_sec/i; if ($mail_icon && $mail) { $mail = ""; } elsif (!$mail_icon && $mail) { if ($name_link) { $name = "$name"; } else { $mail = "$mail_text"; } } if ($home_img) { $link_img = ""; } if ($home_icon && $url) { $url = ""; } elsif (!$home_icon && $url) { $url = "$home_text"; } if ($reno) { $findno = "Re:$reno"; $resno = "$reno"; } else { $findno = "$no"; $resno = "$no"; } &imgview; &findmain; } } &footer; exit; } # ------------------------------------------------------------------------- # ログ書込処理 # ------------------------------------------------------------------------- sub regist { &form_check; &get_time; &set_cookie; if ($lockkey) { &lock; } open(IN,"$logfile") || &error("Open Error : $logfile"); @lines = ; close(IN); $top = shift(@lines); ($no,$ip,$time2) = split(/<>/, $top); $no++; if ($addr eq $ip && $wait > $times - $time2) { &error("連続投稿はもうしばらく時間をおいて下さい"); } if ($in{'pwd'} ne "") { $ango = &encrypt($in{'pwd'}); } if ($in{'upfile'}) { &UpFile; } if ($in{'reno'} eq "") { $i=0; $stop=0; foreach (@lines) { ($no2,$reno2,$d,$n,$m,$s,$com, $u,$ho,$p,$c,$tail2,$w,$h,$chk) = split(/<>/); $i++; if ($i > $max-1 && $reno2 eq "") { $stop=1; } if (!$stop) { push(@new,$_); } else { if ($pastkey) { push(@data,$_); } if (-e "$ImgDir$no2$tail2") { unlink("$ImgDir$no2$tail2"); } } } unshift(@new,"$no<><>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$tail<>$W<>$H<>0<>\n"); unshift(@new,"$no<>$addr<>$times<>\n"); if ($data[0]) { &pastlog; } open(OUT,">$logfile") || &error("Write Error : $logfile"); print OUT @new; close(OUT); } elsif ($in{'reno'} && $topsort) { $match=0; @new=(); @tmp=(); foreach (@lines) { ($no2,$reno2) = split(/<>/); if ($in{'reno'} eq "$no2") { $match=1; push(@new,$_); } elsif ($in{'reno'} eq "$reno2") { push(@new,$_); } elsif ($match == 1 && $in{'reno'} ne "$reno2") { $match=2; push(@new,"$no<>$in{'reno'}<>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$tail<>$W<>$H<>0<>\n"); push(@tmp,$_); } else { push(@tmp,$_); } } if ($match == 1) { push(@new,"$no<>$in{'reno'}<>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$tail<>$W<>$H<>0<>\n"); } push(@new,@tmp); unshift(@new,"$no<>$addr<>$times<>\n"); open(OUT,">$logfile") || &error("Write Error : $logfile"); print OUT @new; close(OUT); } else { $match=0; @new=(); foreach (@lines) { ($no2,$reno2) = split(/<>/); if ($match == 0 && $in{'reno'} eq "$no2") { $match=1; } elsif ($match == 1 && $in{'reno'} ne "$reno2") { $match=2; push(@new,"$no<>$in{'reno'}<>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$tail<>$W<>$H<>0<>\n"); } push(@new,$_); } if ($match == 1) { push(@new,"$no<>$in{'reno'}<>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>$tail<>$W<>$H<>0<>\n"); } unshift(@new,"$no<>$addr<>$times<>\n"); open(OUT,">$logfile") || &error("Write Error : $logfile"); print OUT @new; close(OUT); } if ($lockkey) { &unlock; } if ($mailing == 1 && $in{'email'} ne "$mailto") { &mail_to; } elsif ($mailing == 2) { &mail_to; } elsif ($mailing == 3) { &mail_to; } &html_renew; } # ------------------------------------------------------------------------- # 画像アップロード # ------------------------------------------------------------------------- sub UpFile { $macbin=0; foreach (@in) { if ($_ =~ /(.*)Content-type:(.*)/i) { $tail=$2; } if ($_ =~ /(.*)filename=(.*)/i) { $fname=$2; } if ($_ =~ /application\/x-macbinary/i) { $macbin=1; } } $tail =~ s/\r//g; $tail =~ s/\n//g; $fname =~ tr/\"\x0D\x0A//d; $flag=0; if ($tail =~ /image\/gif/i && $gif) { $tail=".gif"; $flag=1; } if ($tail =~ /image\/jpeg/i && $jpeg) { $tail=".jpg"; $flag=1; } if ($tail =~ /image\/x-png/i && $png) { $tail=".png"; $flag=1; } if ($tail =~ /text\/plain/i && $text) { $tail=".txt"; $flag=1; } if ($tail =~ /lha/i && $lha) { $tail=".lzh"; $flag=1; } if ($tail =~ /zip/i && $zip) { $tail=".zip"; $flag=1; } if ($tail =~ /pdf/i && $pdf) { $tail=".pdf"; $flag=1; } if ($tail =~ /audio\/.*mid/i && $midi) { $tail=".mid"; $flag=1; } if ($tail =~ /msword/i && $word) { $tail=".doc"; $flag=1; } if ($tail =~ /ms-excel/i && $excel) { $tail=".xls"; $flag=1; } if ($tail =~ /ms-powerpoint/i && $ppt) { $tail=".ppt"; $flag=1; } if ($tail =~ /audio\/.*realaudio/i && $ram) { $tail=".ram"; $flag=1; } if ($tail =~ /application\/.*realmedia/i && $rm) { $tail=".rm"; $flag=1; } if ($tail =~ /video\/.*mpeg/i && $mpeg) { $tail=".mpg"; $flag=1; } if ($tail =~ /audio\/.*mpeg/i && $mp3) { $tail=".mp3"; $flag=1; } if (!$flag) { if ($fname =~ /\.gif$/i && $gif) { $tail=".gif"; $flag=1; } if (($fname =~ /\.jpe?g$/i && $jpeg)) { $tail=".jpg"; $flag=1; } if ($fname =~ /\.png$/i && $png) { $tail=".png"; $flag=1; } if ($fname =~ /\.lzh$/i && $lha) { $tail=".lzh"; $flag=1; } if ($fname =~ /\.txt$/i && $text) { $tail=".txt"; $flag=1; } if ($fname =~ /\.zip$/i && $zip) { $tail=".zip"; $flag=1; } if ($fname =~ /\.pdf$/i && $pdf) { $tail=".pdf"; $flag=1; } if ($fname =~ /\.mid$/i && $midi) { $tail=".mid"; $flag=1; } if ($fname =~ /\.doc$/i && $word) { $tail=".doc"; $flag=1; } if ($fname =~ /\.xls$/i && $excel) { $tail=".xls"; $flag=1; } if ($fname =~ /\.ppt$/i && $ppt) { $tail=".ppt"; $flag=1; } if ($fname =~ /\.ram$/i && $ram) { $tail=".ram"; $flag=1; } if ($fname =~ /\.rm$/i && $rm) { $tail=".rm"; $flag=1; } if ($fname =~ /\.mpe?g$/i && $mpeg) { $tail=".mpg"; $flag=1; } if ($fname =~ /\.mp3$/i && $mp3) { $tail=".mp3"; $flag=1; } } # アップロード失敗処理 ------------------------------------------ if (!$flag && !$clip_error) { return; } elsif (!$flag && $clip_error) { &error("アップロードできないファイル形式です","lock"); } $upfile = $in{'upfile'}; # マックバイナリ対策 -------------------------------------------- if ($macbin) { $length = substr($upfile,83,4); $length = unpack("%N",$length); $upfile = substr($upfile,128,$length); } # 添付データを書き込み ------------------------------------------ $ImgFile = "$ImgDir$no$tail"; open(OUT,"> $ImgFile") || &error("画像のアップロードに失敗しました","lock"); binmode(OUT); binmode(STDOUT); print OUT $upfile; close(OUT); chmod (0666,$ImgFile); # 画像サイズ取得 ------------------------------------------------ if ($tail eq ".jpg") { ($W, $H) = &JpegSize($ImgFile); } elsif ($tail eq ".gif") { ($W, $H) = &GifSize($ImgFile); } elsif ($tail eq ".png") { ($W, $H) = &PngSize($ImgFile); } } # ------------------------------------------------------------------------- # デコード処理 # ------------------------------------------------------------------------- sub decode { &ReadParse; while (($key,$val) = each %in) { if ($key ne "upfile") { &jcode'convert(*val, "sjis", "", "z"); if ($tagkey) { $val =~ s/<>/<>/g; } else { $val =~ s//>/g; } if ($key eq "comment") { $val =~ s/\r\n/
/g; $val =~ s/\r/
/g; $val =~ s/\n/
/g; } else { $val =~ s/\r//g; $val =~ s/\n//g; } } $in{$key} = $val; } $mode = $in{'mode'}; $page = $in{'page'}; $in{'url'} =~ s/^http\:\/\///; if ($in{'sub'} eq "") { $in{'sub'} = "Untitled"; } } # ------------------------------------------------------------------------- # クッキーの発行 # ------------------------------------------------------------------------- sub set_cookie { local($sec,$min,$hour,$mday,$mon,$year,$wday) = gmtime(time+60*24*60*60); @month=('Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'); $gmt = sprintf("%s, %02d-%s-%04d %02d:%02d:%02d GMT", $week[$wday],$mday,$month[$mon],$year+1900,$hour,$min,$sec); $cook="name<>$in{'name'}\,email<>$in{'email'}\,url<>$in{'url'}\,pwd<>$in{'pwd'}\,color<>$in{'color'}"; print "Set-Cookie: CLEVER=$cook; expires=$gmt\n"; } # ------------------------------------------------------------------------- # クッキーを取得 # ------------------------------------------------------------------------- sub get_cookie { local($key, $val, @pairs); @pairs = split(/;/, $ENV{'HTTP_COOKIE'}); foreach (@pairs) { ($key,$val) = split(/=/); $key =~ s/\s//g; $GET{$key} = $val; } @pairs = split(/,/, $GET{'CLEVER'}); foreach (@pairs) { ($key,$val) = split(/<>/); $COOK{$key} = $val; } $c_name = $COOK{'name'}; $c_email = $COOK{'email'}; $c_url = $COOK{'url'}; $c_pwd = $COOK{'pwd'}; $c_color = $COOK{'color'}; if ($in{'name'}) { $c_name = $in{'name'}; } if ($in{'email'}) { $c_email = $in{'email'}; } if ($in{'url'}) { $c_url = $in{'url'}; } if ($in{'pwd'}) { $c_pwd = $in{'pwd'}; } if ($in{'color'}) { $c_color = $in{'color'}; } } # ------------------------------------------------------------------------- # ユーザ記事削除 # ------------------------------------------------------------------------- sub usr_del { if ($in{'no'} eq '' || $in{'pwd'} eq '') { &error("記事Noまたは削除キーが入力モレです"); } if ($lockkey) { &lock; } open(IN,"$logfile") || &error("Open Error : $logfile"); @lines = ; close(IN); $top = shift(@lines); $flag=0; foreach (@lines) { ($no,$reno,$date,$name,$mail,$sub,$com, $url,$host,$pw,$color,$tail,$w,$h,$chk) = split(/<>/); if ($flag == 0 && $in{'no'} eq "$no") { if ($pw eq '') { &error("該当記事には削除キーが設定されていません"); } $match = &decrypt("$in{'pwd'}","$pw"); if ($match ne 'yes') { &error("削除キーが違います"); } if (-e "$ImgDir$no$tail") { unlink("$ImgDir$no$tail"); } if ($reno eq "") { $flag=2; } else { $flag=1; } } elsif ($flag == 2 && $in{'no'} eq "$reno") { if (-e "$ImgDir$no$tail") { unlink("$ImgDir$no$tail"); } next; } else { push(@new,$_); } } if ($flag == 0) { &error("該当記事が見当たりません"); } unshift(@new,$top); open(OUT,">$logfile") || &error("Write Error : $logfile"); print OUT @new; close(OUT); if ($lockkey) { &unlock; } &html_renew; } # ------------------------------------------------------------------------- # フォーム入力チェック # ------------------------------------------------------------------------- sub form_check { local($ref_url); if ($base_url) { $ref_url = $ENV{'HTTP_REFERER'}; $ref_url =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; if ($ref_url !~ /$base_url/i) { &error("不正なアクセスです"); } } if ($in_name) { if ($in{'name'} eq "") { &error("名前が入力されていません"); } } if ($in_email) { if ($in{'email'} eq "") { &error("E-Mailが入力されていません"); } } if ($in{'email'} ne "") { if ($in{'email'} !~ /[\w\.\-]+\@[\w\.\-]+\.[a-zA-Z]{2,4}/) { &error("E-Mailの入力内容が不正です"); } } if ($in_url) { if ($in{'url'} eq "") { &error("URLが入力されていません"); } } if ($in_comment) { if ($in{'comment'} eq "") { &error("コメントが入力されていません"); } if ($in{'comment'} !~ /[\x80-\xff]/) { &error("コメントの入力内容が不正です"); } } if ($in_img) { if ($in{'upfile'} eq "") { &error("画像ファイルが指定されていません"); } } } # ------------------------------------------------------------------------- # 時間を取得 # ------------------------------------------------------------------------- sub get_time { $ENV{'TZ'} = "JST-9"; $times = time; $date = localtime($times); ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime($times); @week = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat'); $date = sprintf("%04d&%02d&%02d&%s&%02d&%02d&%02d", $year+1900,$mon+1,$mday,$week[$wday],$hour,$min,$sec); } # ------------------------------------------------------------------------- # ロック処理 # ------------------------------------------------------------------------- sub lock { if (-e $lockfile) { local($mtime) = (stat($lockfile))[9]; if ($mtime < time - 60) { &unlock; } } local($retry) = 5; if ($lockkey == 1) { while (!symlink(".", $lockfile)) { if (--$retry <= 0) { &error('LOCK is BUSY'); } sleep(1); } } elsif ($lockkey == 2) { while (!mkdir($lockfile, 0755)) { if (--$retry <= 0) { &error('LOCK is BUSY'); } sleep(1); } } $lockflag=1; } # ------------------------------------------------------------------------- # ロック解除 # ------------------------------------------------------------------------- sub unlock { if ($lockkey == 1) { unlink($lockfile); } elsif ($lockkey == 2) { rmdir($lockfile); } $lockflag=0; } # ------------------------------------------------------------------------- # メール送信 # ------------------------------------------------------------------------- sub mail_to { $MailSub = "[$title : $no]"; if ($in{'email'} eq "") { $email = 'nomail@xxx.xxx'; } else { $email = $in{'email'}; } $com = $in{'comment'}; $com =~ s/
/\n/g; $com =~ s/<//g; $com =~ s/"/\"/g; if ($User_Info) { $MailBody = <<"EOM"; $mailcom [$title] Title : $in{'sub'} Sender : $in{'name'}さん $com [User_Info] Mail Address : $in{'email'} Web site : http://$in{'url'} HTTP-User-Agent : $ENV{'HTTP_USER_AGENT'} Remote-host : $host Remote-Addr : $ENV{'REMOTE_ADDR'} $mailsign EOM } else{ $MailBody = $mailcom; } &jcode'convert(*MailSub,'jis'); &jcode'convert(*MailBody,'jis'); if (!open(MAIL,"| $sendmail -t")) { &error("メール送信に失敗しました"); } if ($mailing == 3) { print MAIL "To: $email\n"; print MAIL "Bcc: $mailto\n"; }else{ print MAIL "To: $mailto\n"; } print MAIL "From: $email\n"; print MAIL "Subject: $MailSub\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"; print MAIL "X-Mailer: $ver\n\n"; print MAIL "$MailBody\n"; close(MAIL); } # ------------------------------------------------------------------------- # パスワード暗号処理 # ------------------------------------------------------------------------- sub encrypt { local($inpw) = $_[0]; local(@SALT, $salt, $encrypt); @SALT = ('a'..'z', 'A'..'Z', '0'..'9', '.', '/'); srand; $salt = $SALT[int(rand(@SALT))] . $SALT[int(rand(@SALT))]; $encrypt = crypt($inpw, $salt) || crypt ($inpw, '$1$' . $salt); return $encrypt; } # ------------------------------------------------------------------------- # パスワード照合処理 # ------------------------------------------------------------------------- sub decrypt { local($inpw, $logpw) = @_; local($salt, $key, $check); $salt = $logpw =~ /^\$1\$(.*)\$/ && $1 || substr($logpw, 0, 2); $check = "no"; if (crypt($inpw, $salt) eq "$logpw" || crypt($inpw, '$1$' . $salt) eq "$logpw") { $check = "yes"; } return $check; } # ------------------------------------------------------------------------- # 自動URLリンク # ------------------------------------------------------------------------- sub auto_link { if ($autolink ne '') { $_[0] =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1$autolink<\/a>/g; } else { $_[0] =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1$2<\/a>/g; } } # ------------------------------------------------------------------------- # ホスト名取得 # ------------------------------------------------------------------------- sub get_host { $host = $ENV{'REMOTE_HOST'}; $addr = $ENV{'REMOTE_ADDR'}; if ($host eq "" || $host eq $addr) { $host = gethostbyaddr(pack("C4", split(/\./, $addr)), 2) || $addr; } } # ------------------------------------------------------------------------- # チェックモード # ------------------------------------------------------------------------- sub check { &adminheader; print <<"EOM";

Check Mode
チェックモードの表\示。


チェックモードを終了し、表\示用ページに戻る。

EOM print "
    \n"; if (-e $logfile) { print "
  • ログファイルのパス:OK\n"; } else { print "
  • ログファイルのパス:NG → $logfile\n"; } if (-r $logfile && -w $logfile) { print "
  • ログファイルのパーミッション:OK\n"; } else { print "
  • ログファイルのパーミッション:NG\n"; } print "
  • ロック形式:"; if ($lockkey == 0) { print "ロック設定なし\n"; } else { if ($lockkey == 1) { print "symlink\n"; } else { print "mkdir\n"; } ($lockdir) = $lockfile =~ /(.*)[\\\/].*$/; print "
  • ロックディレクトリ:$lockdir\n"; if (-d $lockdir) { print "
  • ロックディレクトリのパス:OK → $lockdir\n"; } else { print "
  • ロックディレクトリのパス:NG → $lockdir\n"; } if (-r $lockdir && -w $lockdir && -x $lockdir) { print "
  • ロックディレクトリのパーミッション:OK → $lockdir\n"; } else { print "
  • ロックディレクトリのパーミッション:NG → $lockdir\n"; } } print "
  • 画像ディレクトリ:$ImgDir\n"; if (-d $ImgDir) { print "
  • 画像ディレクトリのパス:OK\n"; } else { print "
  • 画像ディレクトリ:NG → $ImgDir\n"; } if (-r $ImgDir && -w $ImgDir && -x $ImgDir) { print "
  • 画像ディレクトリのパーミッション:OK\n"; } else { print "
  • 画像ディレクトリのパーミッション:NG → $ImgDir\n"; } print "
\n
\n"; exit; } # ------------------------------------------------------------------------- # 画像表示 # ------------------------------------------------------------------------- sub imgview { if (-e "$ImgDir$no$tail") { if ($tail eq ".gif" || $tail eq ".jpg" || $tail eq ".png") { # 画像表示縮小 -------------------------------------------------- if ($w > $MaxW || $h > $MaxH) { $w2 = $MaxW / $w; $h2 = $MaxH / $h; if ($w2 < $h2) { $key = $w2; } else { $key = $h2; } $w3 = int ($w * $key) || 1; $h3 = int ($h * $key) || 1; } else { $w3 = $w; $h3 = $h; } if ($ImageCheck && $chk != 1) { $img = ""; } elsif ($w && $h && $home_img==0) { $img = ""; } elsif ($w && $h && $home_img==1) { $img = "$link_img"; } elsif ($w && $h && $home_img==2) { $w4 = $w+20; $h4 = $h+25; $img = ""; } elsif ($home_img==0) { $img = ""; } elsif ($home_img==1) { $img = "$link_img"; } elsif ($home_img==2) { $img = ""; } else { $img = ""; } } else { $img = "Download:$no$tail $no$tail"; } } } # ------------------------------------------------------------------------- # JPEGサイズ認識 # ------------------------------------------------------------------------- sub JpegSize { local($jpeg) = @_; local($t, $m, $c, $l, $W, $H); open(JPEG, "$jpeg") || return (0,0); binmode JPEG; read(JPEG, $t, 2); while (1) { read(JPEG, $t, 4); ($m, $c, $l) = unpack("a a n", $t); if ($m ne "\xFF") { $W = $H = 0; last; } elsif ((ord($c) >= 0xC0) && (ord($c) <= 0xC3)) { read(JPEG, $t, 5); ($H, $W) = unpack("xnn", $t); last; } else { read(JPEG, $t, ($l - 2)); } } close(JPEG); return ($W, $H); } # ------------------------------------------------------------------------- # GIFサイズ認識 # ------------------------------------------------------------------------- sub GifSize { local($gif) = @_; local($data); open(GIF,"$gif") || return (0,0); binmode(GIF); sysread(GIF,$data,10); close(GIF); if ($data =~ /^GIF/) { $data = substr($data,-4); } $W = unpack("v",substr($data,0,2)); $H = unpack("v",substr($data,2,2)); return ($W, $H); } # ------------------------------------------------------------------------- # PNGサイズ認識 WWWis (http://www.bloodyeck.com/wwwis/) より引用 # ------------------------------------------------------------------------- sub PngSize { local($PNG) = @_; local($head, $a, $b, $c, $d, $e, $f, $g, $h); open(PNG,"$PNG") || return (0,0); binmode(PNG); if (defined(PNG) && read(PNG, $head, 8) == 8 && $head eq "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" && read(PNG, $head, 4) == 4 && read(PNG, $head, 4) == 4 && $head eq "IHDR" && read(PNG, $head, 8) == 8) { ($a,$b,$c,$d,$e,$f,$g,$h) = unpack("C"x8, $head); } else { return (0,0); } close(PNG); return ($a<<24|$b<<16|$c<<8|$d, $e<<24|$f<<16|$g<<8|$h); } # ------------------------------------------------------------------------- # URLエンコード # ------------------------------------------------------------------------- sub url_enc { local($_) = @_; s/(\W)/'%' . unpack('H2', $1)/eg; s/\s/+/g; $_; }