#!/usr/bin/perl # RES BOARD v1.0 (2001/06) # Copyright(C) Kent Web 2001 # webmaster@kent-web.com # http://www.kent-web.com/ # バージョン情報 $ver = 'ResBBS v1.0'; #---------------------------------------------------------------# # [ 注意事項 ] # # ・このスクリプトを使用したいかなる損害も作者は一切の責任を # # 負いません。自己の責任の範囲内でご使用ください。 # # ・掲示板下部にある「著作権表示」は、削除・改変を行なうことは # # できません。 # #---------------------------------------------------------------# #============# # 設定項目 # #============# # 文字コードライブラリ取込 require './jcode.pl'; # スクリプトのファイル名 # --> フルパスで指定する場合は http:// から記述 $script = "./resbbs.cgi"; # ログファイルを指定 # --> フルパスで指定する場合は / から記述 $logfile = "./resbbs.log"; # 設定ファイル # → 絶対パスなら / から始まるサーバパスで記述 $setfile = "./resbbs.ini"; # 管理者用マスタパスワード (英数字で8文字以内) $pass = '21010'; # methodの形式 (POST/GET) $method = 'POST'; # タグの許可 (0=no 1=yes) $tagkey = 1; # ホスト名取得方式 # 0 : $ENV{'REMOTE_HOST'}変数で取得 # 1 : gethostbyaddr関数で取得 $gethostbyaddr = 0; # ファイルロック形式 # 0 : no # 1 : yes # → 設定する場合は、ロックファイルを生成するディレクトリ # のパーミッションは原則として「777」に設定する。 $lockkey = 1; # ロックファイル名 $lockfile = "./lock/resbbs.lock"; # 投稿があるとメール通知する (sendmail必須) # 0 : 通知しない # 1 : 通知する $mailing = 0; # sendmailパス(メール通知する時) $sendmail = '/usr/lib/sendmail'; #============# # 設定完了 # #============# # メイン処理 &decode; &set_file; if ($mode eq "howto") { &howto; } elsif ($mode eq "find") { &find; } elsif ($mode eq "usr_del") { &usr_del; } elsif ($mode eq "regist") { ®ist; } elsif ($mode eq "res") { &res_form; } elsif ($mode eq "admin") { &admin; } if ($mode eq 'edit') { &edit; } &html_log; #--------------------# # 設定ファイル認識 # #--------------------# sub set_file { open(IN,"$setfile") || &error("Open Error : $setfile"); $data = ; close(IN); ($title,$t_color,$t_size,$ImgT,$bg,$bc,$tx,$lk,$vl,$al,$face,$b_size,$sub_color,$max,$home,$p_log,$deny,$mailto,$tbl_color,$colors,$autolink,$wait,$topsort) = split(/<>/, $data); # アクセス制限 &get_host; local($flag)=0; @deny = split(/\s+/, $deny); foreach (@deny) { $_ =~ s/\*/\.\*/g; if ($host =~ /$_/i) { $flag=1; last; } } if ($flag) { &error("アクセスを許可されていません"); } @COLORS = split(/\s+/, $colors); # ポイント数 $t_size .= 'pt'; $s_size = ($b_size - 1) . 'pt'; $b_size .= 'pt'; } #--------------# # 記事表示部 # #--------------# sub html_log { # クッキーを取得 &get_cookie; # フォーム長を調整 &get_agent; # ヘッダを出力 &header; # タイトル部 print "
\n"; if ($title_gif eq '') { print "$title\n"; } else { print "\n"; } print <<"EOM";
[トップに戻る] [使い方] [ワード検索] [管理用]
おなまえ
Eメール
題  名  
コメント
URL
削除キー (自分の記事を削除時に使用。英数字で8文字以内)
文字色 EOM # クッキーの色情報がない場合 if ($c_color eq "") { $c_color = $COLORS[0]; } foreach (0 .. $#COLORS) { if ($c_color eq "$COLORS[$_]") { print ""; print "\n"; } else { print ""; print "\n"; } } print "
\n"; print "

\n"; # ページ区切り処理 $start = $in{'page'} + 1; $end = $in{'page'} + $p_log; # 記事を展開 open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; $i=0; $j=0; $flag=0; while () { ($no,$reno,$date,$name,$mail,$sub, $comment,$url,$host,$pw,$color) = split(/<>/); if ($reno eq "") { $i++; $j++; } if ($i < $start) { next; } if ($i > $end) { next; } if ($mail) { $name = "$name"; } if ($url) { $url = "<HOME>"; } if ($autolink) { &auto_link($comment); } $comment = "
$comment
"; if (!$reno && $flag) { print "

\n"; $flag=1; } if (!$reno) { print "
\n"; $flag=1; } if ($reno) { print "
\n"; } print "\n"; if ($reno) { print ""; } print ""; print "\n"; } else { print "
\n"; } print "

$sub "; if (!$reno) { print "投稿者:$name 投稿日:$date "; } else { print "$name - $date "; } print "No\.$no   $url \n"; if (!$reno) { print "
\n"; print "\n"; print "\n"; print "
\n"; if ($reno) { print "\n"; } print "

$comment"; print "
\n"; } close(IN); print "
\n"; $next_page = $in{'page'} + $p_log; $back_page = $in{'page'} - $p_log; print "
\n"; if ($back_page >= 0) { print "\n"; } if ($next_page < $i) { print "\n"; } print "
\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "記事No\n"; print "削除キー\n"; print "\n"; print "

\n"; # 著作権表示部(削除・改変禁止) print "
\n"; print "- ResBBS -\n"; print "
\n"; print "\n"; exit; } #----------------# # ログ書込処理 # #----------------# sub regist { # 名前とコメントは必須 if ($in{'name'} eq "") { &error("名前が入力されていません"); } if ($in{'comment'} eq "") { &error("コメントが入力されていません"); } # 時間を取得 &get_time; # クッキーを発行 &set_cookie; # ファイルロック if ($lockkey) { &lock; } # ログを開く open(IN,"$logfile") || &error("Open Error : $logfile"); @lines = ; close(IN); # 記事NO処理 $top = shift(@lines); ($no,$ip,$time2) = split(/<>/, $top); $no++; # 連続投稿チェック if ($addr eq "$ip" && $wait > $times - $time2) { &error("連続投稿はもうしばらく時間をおいて下さい"); } # 二重投稿の禁止 local($flag) = 0; foreach (@lines) { ($knum,$kk,$kd,$kname,$kem,$ksub,$kcom) = split(/<>/); if ($in{'name'} eq "$kname" && $in{'comment'} eq "$kcom") { $flag=1; last; } } if ($flag) { &error("二重投稿は禁止です"); } # 削除キーを暗号化 if ($in{'pwd'} ne "") { $ango = &encrypt($in{'pwd'}); } # 親記事の場合 if ($in{'reno'} eq "") { $i=0; $stop=0; foreach (@lines) { ($no2,$reno2) = split(/<>/); $i++; if ($i > $max-1 && $reno2 eq "") { $stop=1; } if (!$stop) { push(@new,$_); } } unshift(@new,"$no<><>$date<>$in{'name'}<>$in{'email'}<>$in{'sub'}<>$in{'comment'}<>$in{'url'}<>$host<>$ango<>$in{'color'}<>\n"); unshift(@new,"$no<>$addr<>$times<>\n"); # 更新 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'}<>\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'}<>\n"); } push(@new,@tmp); # 更新 unshift(@new,"$no<>$addr<>$times<>\n"); open(OUT,">$logfile") || &error("Write Error : $logfile","lock"); 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'}<>\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'}<>\n"); } # 更新 unshift(@new,"$no<>$addr<>$times<>\n"); open(OUT,">$logfile") || &error("Write Error : $logfile","lock"); print OUT @new; close(OUT); } # ロック解除 if ($lockkey) { &unlock; } # メール処理 if ($mailing) { &mail_to; } } #----------------# # 返信フォーム # #----------------# sub res_form { # フォーム長を定義 &get_agent; # クッキーを取得 &get_cookie; # ログを読み込み open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; # ヘッダを出力 &header; # 関連記事出力 print "- 以下は、記事NO. $in{'no'} に関する返信フォームです -
\n"; while () { ($no,$reno,$date,$name,$mail,$sub,$com,$url) = split(/<>/); if ($in{'no'} eq "$no" || $in{'no'} eq "$reno") { if ($in{'no'} eq "$no") { $resub = $sub; } if ($url) { $url = "<HOME>"; } if ($reno) { print '  '; } print "$sub 投稿者:$name 投稿日:$date $url No\.$no
\n"; print "
$com

\n"; } } close(IN); # タイトル名 if ($resub !~ /^Re\:/) { $resub = "Re\: $resub"; } print <<"EOM";
おなまえ
Eメール
タイトル
メッセージ
URL
削除キー (自分の記事を削除時に使用。英数字で8文字以内)
文字色 EOM # クッキーの色情報がない場合 if ($c_color eq "") { $c_color = $COLORS[0]; } foreach (0 .. $#COLORS) { if ($c_color eq "$COLORS[$_]") { print ""; print "\n"; } else { print ""; print "\n"; } } print "
\n"; print "
\n"; print "\n"; exit; } #----------------# # デコード処理 # #----------------# sub decode { if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/, $buffer); foreach (@pairs) { ($name,$value) = split(/=/, $_); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # 文字コードをシフトJIS変換 &jcode'convert(*value,'sjis'); # タグ処理 if ($tagkey) { $value =~ s/<>/<>/g; } else { $value =~ s/&/&/g; $value =~ s//>/g; } # 改行等処理 if ($name eq "comment") { $value =~ s/\r\n/
/g; $value =~ s/\r/
/g; $value =~ s/\n/
/g; } else { $value =~ s/\r//g; $value =~ s/\n//g; } # 一括削除用 if ($name eq 'del') { push(@DEL,$value); } $in{$name} = $value; } $mode = $in{'mode'}; $in{'url'} =~ s/^http\:\/\///; if ($in{'sub'} eq "") { $in{'sub'} = "無題"; } } #----------------------------# # 掲示板の使い方メッセージ # #----------------------------# sub howto { if ($tagkey == 0) { $tag_msg = "投稿内容には、タグは一切使用できません。\n"; } else { $tag_msg = "コメント欄には、タグ使用をすることができます。\n"; } &header; print <<"EOM"; [掲示板にもどる]
掲示板の利用上の注意

  1. この掲示板はクッキー対応です。1度記事を投稿いただくと、おなまえ、Eメール、URL、削除キーの情報は2回目以降は自動入力されます。(ただし利用者のブラウザがクッキー対応の場合)

  2. $tag_msg

  3. 記事を投稿する上での必須入力項目は「おなまえ」「メッセージ」です。Eメール、URL、題名、削除キーは任意です。

  4. 記事には、半角カナは一切使用しないで下さい。文字化けの原因となります。

  5. 記事の投稿時に「削除キー」にパスワード(英数字で8文字以内)を入れておくと、その記事は次回削除キーによって削除することができます。

  6. 記事の保持件数は最大 $max件です。それを超えると古い順に自動削除されます。

  7. 既存の記事に「返信」をすることができます。各記事の上部にある「返信」ボタンを押すと返信用フォームが現れます。

  8. 過去の投稿記事から「キーワード」によって簡易検索ができます。トップメニューの「ワード検索」のリンクをクリックすると検索モードとなります。

  9. 管理者が著しく不利益と判断する記事や他人を誹謗中傷する記事は予\告なく削除することがあります。
EOM exit; } #------------------# # ワード検索処理 # #------------------# sub find { &header; print <<"EOM"; [掲示板にもどる]
ワード検索

  • 検索したいキーワードを入力し、検索領域を選択して「検索ボタン」を押してください。
  • キーワードは「半角スペース」で区切って複数指定することができます。

キーワード
検索条件 AND OR
EOM # ワード検索の実行と結果表示 if ($in{'word'} ne ""){ # 入力内容を整理 $in{'word'} =~ s/ / /g; @pairs = split(/\s+/, $in{'word'}); # ファイルを読み込み open(DB,"$logfile") || &error("Open Error : $logfile"); @lines = ; close(DB); # 検索処理 foreach (1 .. $#lines) { $flag = 0; foreach $pair (@pairs){ if (index($lines[$_],$pair) >= 0) { $flag = 1; if ($in{'cond'} eq 'or') { last; } } else { if ($in{'cond'} eq 'and') { $flag=0; last; } } } if ($flag) { push(@new,$lines[$_]); } } # 検索終了 $count = @new; print "検索結果:$count件\n"; print "

    \n"; foreach (@new) { ($no,$reno,$date,$name,$email,$sub,$com,$url) = split(/<>/); if ($email) { $name = "$name"; } if ($url) { $url = "<HOME>"; } if ($reno) { $no = "$renoへのレス"; } # 結果を表示 print "
  1. [$no] $sub 投稿者:$name 投稿日:$date $url
    \n"; print "
    $com
    \n"; } print "
    \n
\n"; } print "\n"; exit; } #---------------------------------# # ブラウザを判断:フォーム幅調整 # #---------------------------------# sub get_agent { # ブラウザ名を取得 $agent = $ENV{'HTTP_USER_AGENT'}; if ($agent =~ /MSIE 3/i) { $nam_wid = 30; $sub_wid = 40; $com_wid = 65; $url_wid = 48; $nam_wid2 = 20; } elsif ($agent =~ /MSIE 4/i || $agent =~ /MSIE 5/i) { $nam_wid = 30; $sub_wid = 40; $com_wid = 60; $url_wid = 70; $nam_wid2 = 20; } else { $nam_wid = 20; $sub_wid = 25; $com_wid = 56; $url_wid = 50; $nam_wid2 = 10; } } #------------------# # クッキーの発行 # #------------------# sub set_cookie { # クッキーは60日間有効 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: ResBBS=$cook; expires=$gmt\n"; } #------------------# # クッキーを取得 # #------------------# sub get_cookie { @pairs = split(/;/, $ENV{'HTTP_COOKIE'}); foreach (@pairs) { local($key,$val) = split(/=/); $key =~ s/\s//g; $GET{$key} = $val; } @pairs = split(/,/, $GET{'ResBBS'}); foreach (@pairs) { local($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 error { if ($lockkey) { &unlock; } &header if (!$head_flag); print "

ERROR !

\n"; print "

$_[0]\n"; print "


\n"; print "\n"; exit; } #--------------# # 管理モード # #--------------# sub admin { if ($in{'pass'} ne "" && $in{'pass'} ne "$pass") { &error("パスワードが違います"); } &header; print "[掲示板に戻る]\n"; print "
\n"; print "管理モード\n"; print "
\n"; if ($in{'pass'} eq "") { print "

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

\n"; print "
\n"; print "\n"; print "\n"; print ""; print "
\n"; } else { # 削除処理 if ($DEL[0]) { # ロック処理 if ($lockkey) { &lock; } # 削除情報をマッチングし更新 @new=(); open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; while () { $flag=0; ($no,$reno,$date) = split(/<>/); foreach $del (@DEL) { if ($no eq "$del" || $reno eq "$del") { $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; } } # 管理を表示 if ($in{'page'} eq "") { $in{'page'} = 0; } print "

\n"; print "
  • 削除する記事のチェックボックスにチェックを入れ、削除ボタンを押して下さい。\n"; print "
  • 親記事を削除するとレス記事も一括して削除されます。
\n"; print "
\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print ""; print "\n"; print "

\n"; print ""; print "\n"; # ページ区切り処理 $start = $in{'page'} + 1; $end = $in{'page'} + $p_log; open(IN,"$logfile") || &error("Open Error : $logfile"); $top = ; $i=0; $j=0; while () { ($no,$reno,$date,$name,$mail, $sub,$com,$url,$host,$pw) = split(/<>/); if ($reno eq "") { $i++; $j++; } if ($i < $start) { next; } if ($i > $end) { next; } if ($mail) { $name="$name"; } ($date,$dmy) = split(/\(/, $date); if ($url) { $url = "<Home>"; } else { $url = '-'; } $com =~ s/
//ig; $com =~ s//>/g; if (length($com) > 40) { $com = substr($com,0,38); $com .= ".."; } if ($reno eq "") { print "
\n"; } # 削除チェックボックス print ""; print ""; print ""; print ""; print "\n"; } close(IN); print "\n"; print "
削除記事NO投稿日タイトル投稿者URLコメントホスト名

$no$date$sub$name$url$com$host

\n"; } $next_page = $in{'page'} + $p_log; $back_page = $in{'page'} - $p_log; print "

\n"; if ($back_page >= 0) { print "\n"; } if ($next_page < $i) { print "\n"; } print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "

\n"; print "\n"; exit; } #--------------------# # 設定ファイル編集 # #--------------------# sub edit { if ($in{'pass'} ne "$pass") { &error("パスワードが違います"); } # 実行 if ($in{'action'} eq "edit") { if ($in{'ImgT'} eq "http://") { $in{'ImgT'} = ""; } if ($in{'bg'} eq "http://") { $in{'bg'} = ""; } if ($in{'mailto'} ne "") { if ($in{'mailto'} =~ /\,/) { &error("メールアドレスに「コンマ」が含まれています"); } if ($in{'mailto'} !~ /.+\@.+\..+/) { &error("メールアドレスの入力が不正です"); } } $in{'deny'} =~ s/ / /g; foreach (1 .. 8) { $key_col = 'color' . $_; $in{$key_col} =~ s/\s//g; if ($in{$key_col} eq "") { &error("文字選択色\($_\)の指定がありません"); } } open(OUT,">$setfile") || &error("Write Error : $setfile"); print OUT "$in{'title'}<>$in{'t_color'}<>$in{'t_size'}<>$in{'ImgT'}<>$in{'bg'}<>$in{'bc'}<>$in{'tx'}<>$in{'lk'}<>$in{'vl'}<>$in{'al'}<>$in{'face'}<>$in{'b_size'}<>$in{'sub_color'}<>$in{'max'}<>$in{'home'}<>$in{'p_log'}<>$in{'deny'}<>$in{'mailto'}<>$in{'tbl_color'}<>$in{'color1'} $in{'color2'} $in{'color3'} $in{'color4'} $in{'color5'} $in{'color6'} $in{'color7'} $in{'color8'}<>$in{'topsort'}<>$in{'wait'}<>$in{'autolink'}<>"; close(OUT); # 完了メッセージ &header; print "

修正は正常に完了しました

\n"; print "
\n"; print "
\n"; print "
\n\n"; exit; } $t_size =~s /pt$//g; $b_size2 = $b_size; $b_size2 =~s /pt$//g; if ($ImgT eq "") { $ImgT = "http://"; } if ($bg eq "") { $bg = "http://"; } &header; print <<"EOM"; [掲示板に戻る]
設定ファイル編集

- 変更する部分のみ修正してください -

\n"; print "\n"; print "\n"; $i=0; foreach (0 .. 7) { $i++; $key_col = 'color' . $i; print "\n"; print "\n"; } print <<"EOM"; EOM if ($mailing) { print "\n"; print "\n"; print "\n"; } print "

タイトル名
タイトル色
タイトルサイズ ポイント
タイトル画像 (任意)

壁紙 (任意)
背景色
文字色
リンク色1  (未訪問)
リンク色2  (訪問済)
リンク色3  (訪問中)

文字サイズ ポイント
文字タイプ
記事題名色
記事下地色
最大記事数
ページ記事数
戻り先

自動ソ\ート(レスが付くと関連記事をトップに移動)
待機秒数秒(同一ホストからの連続投稿を制御)
自動リンク(コメント欄のURLを自動でリンクする機能\)
文字選択色($i)\n"; print "

アクセス制限
・アクセス拒否するホスト名を記述
・半角スペースで区切って複数指定可
・ワイルドカード (*) 使用可

メール通知先"; print "(任意)

\n"; print "\n"; print "
\n"; print "\n"; exit; } #------------------# # ユーザ記事削除 # #------------------# 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,$dt,$name,$mail,$sub,$com,$url,$host,$pw) = split(/<>/); if ($flag == 0 && $in{'no'} eq "$no") { $PW = $pw; if ($reno eq "") { $flag=2; } else { $flag=1; } } elsif ($flag == 2 && $in{'no'} eq "$reno") { next; } else { push(@new,$_); } } if ($flag == 0) { &error("該当記事が見当たりません"); } if ($PW eq '') { &error("該当記事には削除キーが設定されていません"); } # 削除キーを照合 $match = &decrypt("$in{'pwd'}","$PW"); if ($match ne 'yes') { &error("削除キーが違います"); } # 更新 unshift(@new,$top); open(OUT,">$logfile") || &error("Write Error : $logfile"); print OUT @new; close(OUT); # ロック解除 if ($lockkey) { &unlock; } } #--------------# # 時間を取得 # #--------------# sub get_time { $ENV{'TZ'} = "JST-9"; $times = time; ($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", $year+1900,$mon+1,$mday,$week[$wday],$hour,$min); } #--------------# # ロック処理 # #--------------# sub lock { if (-e $lockfile) { # 3分以上古いロックは削除する ($mtime) = (stat($lockfile))[9]; if ($mtime < time - 180) { &unlock; } } local($retry) = 5; while (!mkdir($lockfile, 0755)) { if (--$retry <= 0) { &error('Lock is busy'); } sleep(1); } } #--------------# # ロック解除 # #--------------# sub unlock { rmdir($lockfile); } #--------------# # メール送信 # #--------------# sub mail_to { $mailto =~ s/\s/\,/g; unless (-e $sendmail) { &error("sendmailのパスが不正です"); } $MailSub = "[$title : $no] $in{'sub'}"; $m_com = $in{'comment'}; $m_com =~ s/
/\n/g; $m_com =~ s/<//g; $m_com =~ s/&/&/g; if ($in{'url'}) { $m_url = "http://$in{'url'}"; } $MailBody = <<"EOM"; $titleに以下の投稿がありました。 投稿日時:$date ホスト名:$host ブラウザ:$ENV{'HTTP_USER_AGENT'} おなまえ:$in{'name'} Eメール:$in{'email'} タイトル:$in{'sub'} URL :$m_url コメント: $m_com EOM # JISコード変換 &jcode'convert(*MailSub,'jis'); &jcode'convert(*MailBody,'jis'); # メールアドレスがない場合はダミーメールに置き換え if ($in{'email'} eq "") { $email = 'nomail@xxx.xxx'; } else { $email = $in{'email'}; } # sendmail送信 if (!open(MAIL,"| $sendmail -t")) { &error("メール送信に失敗しました"); } 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 "--------------------------------------------------------\n"; print MAIL "$MailBody\n"; print MAIL "--------------------------------------------------------\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; } #------------------# # HTMLのヘッダー # #------------------# sub header { $head_flag=1; print "Content-type: text/html\n\n"; print <<"EOM"; $title EOM } #-----------------# # 自動URLリンク # #-----------------# sub auto_link { $_[0] =~ s/([^=^\"]|^)(http\:[\w\.\~\-\/\?\&\+\=\:\@\%\;\#\%]+)/$1$2<\/a>/g; } #----------------# # ホスト名取得 # #----------------# sub get_host { $host = $ENV{'REMOTE_HOST'}; $addr = $ENV{'REMOTE_ADDR'}; if ($get_remotehost) { if ($host eq "" || $host eq "$addr") { $host = gethostbyaddr(pack("C4", split(/\./, $addr)), 2); } } if ($host eq "") { $host = $addr; } }