#!/usr/local/bin/perl # ↑あなたが加入しているプロバイダの「perl」言語が使用できる # パスを指定します。一般的に「#!/usr/local/bin/perl」で大丈夫 #*************************************************************************************** # △Resboard Var 1.0▽ # ○Yuppies CGI # http://http://www.geocities.co.jp/Milano/1567/ # ○フリープログラム # 使用条件:[Yuppies]へのリンクは消さないで下さい。 # ○質問、コメントはYumiまで。 # Yuppi(Yumi Tanaka) # YUPPI@chat.club.or.jp # # ※パスワードの変更を行ってください。 #*************************************************************************************** #日本語コード変換モジュール #-------------変更1------------- #require 'jcode.pl'; if (-f "jcode.pl") { $jflag = true; require "jcode.pl"; $code = ord(substr("漢", 0, 1)); if ($code == 0xb4) { $ccode = "euc"; $hcode = "x-euc-jp"; } elsif ($code == 0x1b) { $ccode = "jis"; $hcode = "iso-2022-jp"; } else { $ccode = "sjis"; $hcode = "x-sjis"; } } #*************************************************************************************** # ▼ここから▼ 初期設定を行います #*************************************************************************************** #掲示板を設置するURLを設定 #コメント送信後、リロードしますので必ず指定 $reload = 'http://***/***/cgi-bin/resboard1.cgi'; #「Home」で戻るURLを設定 $homeadd = ''; #管理者のメールアドレスを指定 $mailto = ''; #掲示板のタイトル $bbstitle = 'ResBBS'; #ヘッダー $head = <<"_HEAD_"; $bbstitle _HEAD_ #タイトルのカラー $color_btl = '#555555'; #掲示板のTOPに表記される部分 $top = <<"_TOP_";
$bbstitle
掲示板サンプルです。 _TOP_ #掲示板の最後に表記される部分 $under = <<"_UNDER_";

$mailto _UNDER_ #Bodyタグ設定 $body = "

"; #記事部分のテーブルの枠サイズ(0で枠無し) $t_size = 2; #記事上部(書き込み者表示部分)バック&テキストカラー $color_nb = '#555555'; $color_nn = '#ffffff';#訪問者name色 $color_nd = '#eeeeee';#日付の表示色 $color_tl = '#555555';#タイトル色 #記事バック&テキストカラー $color_cb = '#dddddd'; $color_ct = '#333333'; #レス書き込み者nameカラー $color_rn = '#555555'; #レス部分バック&テキストカラー $color_rb = '#efefef'; $color_rt = '#777777'; #管理者削除モードのパスワード $password = 'abc777'; #ファイル最大記憶数(極端に多くするとパフォーマンスが低下します) $max = 50; #1ページ表示数(新規投稿記事) $pagevew = 10; #レス記入のテキスト部分の行数指定 → 0〜(0だとテキストボックス、1〜でテキストエリア) $resrow = 1; #*************************************************************************************** # ▲ここまで▲ #*************************************************************************************** $file = 'resboard1.txt'; $CookieName = 'resboard1'; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time); $date_now = sprintf("%02d/%02d/%02d %02d:%02d", $year, $mon + 1, $mday, $hour, $min); if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $formdata, $ENV{'CONTENT_LENGTH'}); } else { $formdata = $ENV{'QUERY_STRING'}; } $ENV{'TZ'} = "GMT"; #クッキーの有効期限:30日 ($c_sec,$c_min,$c_hour,$c_mday,$c_mon,$c_year,$c_wday,$c_yday,$c_isdst) = localtime(time + 30 * 86400); @pairs = split(/&/,$formdata); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s//>/g; $value =~ s/\n//g; $value =~ s/\,//g; &jcode'convert(*value,'sjis'); $FORM{$name} = $value; } if (!open(NOTE,"$file")) { &error(bad_file); } @DATA = ; close(NOTE); foreach $line (@DATA) { ($date,$code,$ress,$name,$email,$homepage,$title,$comment,$key) = split(/\,/,$line); if ($ress < 1) { push(@NEW,$line); } } if ($FORM{'action'} eq "regist") { ®ist; } elsif ($FORM{'action'} eq 'delete') { &delete; } elsif ($FORM{'action'} eq 's_delete') { &s_delete; } elsif ($FORM{'action'} eq 'delmode' && $FORM{'password'} eq $password) { &delmode; } elsif ($FORM{'action'} eq 'new') { &new_html; } else { &html; } #*************************************************************************************** sub cookie_read { $cookies = $ENV{'HTTP_COOKIE'}; @pairs = split(/;/,$cookies); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ s/ //g; $DUMMY{$name} = $value; } @pairs = split(/,/,$DUMMY{$CookieName}); foreach $pair (@pairs) { ($name, $value) = split(/\!/, $pair); $COOKIE{$name} = $value; } } #*** ▼ HTML(記事表示部分) ▼ ********************************************************** sub html { @DATA = reverse(@DATA); &cookie_read; print "Content-type: text/html\n\n"; print "\n"; print "$head\n"; print "$top\n"; print "$body\n"; if ($FORM{'pline'} eq '') { $pline = 0; } else { $pline = $FORM{'pline'}; } $end_data = @NEW - 1; $page_end = $pline + ($pagevew - 1); if ($page_end >= $end_data) { $page_end = $end_data; } print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; $next_line = $page_end + 1; if ($page_end ne $end_data) { #次ページのためのフォームを生成 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"; print "\n"; print "
\n"; foreach ($pline .. $page_end) { ($date,$code,$ress,$name,$email,$homepage,$title,$comment,$key) = split(/\,/,$NEW[$_]); $comment =~ s/\r/
/g; 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"; print "\n"; print "$name\n"; print "  \n"; print "\n"; if( $email ne "" ){ print "  \n"; print "[Email]\n"; } if( $homepage ne ""){ print " \n"; $dammy = $homepage; print "\n"; print "[HomePage]\n"; } print "\n"; print "  $date\n"; print "
\n"; print "\n"; print "  $title\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; print "
\n"; print "\n"; print "$comment\n"; &res; print "
\n"; print "\n"; print "\n"; print "\n"; print "Name:\n"; print "\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; if($resrow == 0){print "\n";} else{print "\n";} print "
\n"; } print "$under\n"; print "
\n"; print "△Yuppies CGI▽\n";#この部分は消さないで print "\n"; exit; }#html #+++ ▽ レス表示部分 ▽ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub res{ $x = 1; foreach $ressline (@DATA) { ($da,$co,$re,$na,$em,$h,$tl,$com,$s_pas) = split(/\,/,$ressline); $com =~ s/\r/
/g; if ($code eq $re) { print "\n"; print "
\n"; print "$x \n"; print "\n"; print "$na\n"; print " $da\n"; print "
\n"; print "\n"; print "$com\n"; print "
\n"; print "
\n"; $x++; } } } #*** ▼ 新規記事記入画面 ▼ ************************************************************ sub new_html { &cookie_read; print "Content-type: text/html\n\n"; print "\n"; print "$head\n"; print "$body\n"; print "
\n"; print "\n"; print "\n"; print "$bbstitle\n"; print "\n"; print "

\n"; print "サンプルです。\n"; print "
\n"; print "タグは使えません。\n"; &form; print "
\n"; print "\n"; exit; }#new_html #+++ ▽ 書き込みフォーム ▽ ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ sub form{ print "
\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n";} else{ print "\n";} print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
Name\n"; print "
E-Mail\n"; print "
HomePage\n"; if($COOKIE{'hp'} eq ""){ print "
Title
コメント\n"; print "
\n"; print "削除キー\n"; print "\n"; print "      \n"; print "\n"; print "
\n"; print "
\n"; print "\n"; print "\n"; }#form #=== × 記事書き込み × ================================================================ sub regist { if ($FORM{'name'} eq "") { &error(bad_name); } if ($FORM{'type'} ne "res") { if ($FORM{'key'} eq "") { &error(bad_pass2); }} if ($FORM{'comment'} eq "") { &error(bad_comment); } if ($c_year < 10) { $c_year = "0$c_year"; } if ($c_sec < 10) { $c_sec = "0$c_sec"; } if ($c_min < 10) { $c_min = "0$c_min"; } if ($c_hour < 10) { $c_hour = "0$c_hour"; } if ($c_mday < 10) { $c_mday = "0$c_mday"; } $y0="Sunday"; $y1="Monday"; $y2="Tuesday"; $y3="Wednesday"; $y4="Thursday"; $y5="Friday"; $y6="Saturday"; $youbi = ($y0,$y1,$y2,$y3,$y4,$y5,$y6) [$c_wday]; $m0="Jan"; $m1="Feb"; $m2="Mar"; $m3="Apr"; $m4="May"; $m5="Jun"; $m6="Jul"; $m7="Aug"; $m8="Sep"; $m9="Oct"; $m10="Nov"; $m11="Dec"; $month = ($m0,$m1,$m2,$m3,$m4,$m5,$m6,$m7,$m8,$m9,$m10,$m11) [$c_mon]; $date_gmt = "$youbi, $c_mday\-$month\-$c_year $c_hour:$c_min:$c_sec GMT"; $cook="na\!$FORM{'name'}\,em\!$FORM{'email'}\,hp\!$FORM{'hp'}\,key\!$FORM{'key'}"; #クッキーに書き込み print "Set-Cookie: $CookieName=$cook; expires=$date_gmt\n"; $i = 1; foreach $line (@DATA) { $i++; if ($i < $max) { push(@new_data,$line); } } $count = @DATA; if ($count < 1) { $new_code = 1; } else { ($date,$code,$ress,$name,$email,$homepage,$title,$comment,$key) = split(/\,/,$DATA[0]); $new_code = $code + 1; } $value = "$date_now\,$new_code,$FORM{'ress'}\,$FORM{'name'}\,$FORM{'email'}\,$FORM{'hp'}\,$FORM{'title'}\,$FORM{'comment'}\,$FORM{'key'}\n"; unshift(@new_data,$value); if (!open(NOTE,">$file")) { &error(bad_file); } print NOTE @new_data; close(NOTE); print "Location: $reload" . '?' . "\n\n"; }#regist #=== ▽ 記事の削除:メンテナンス画面 ▽ ================================================ sub delmode { $count = @DATA; if ($count < 1) { &html; } print "Content-type: text/html\n\n"; print "\n"; print "$head\n"; print "$body\n"; print "
\n"; print "\n"; print "\n"; print "削除コード:\n"; print "
\n"; print "スペースで区切っていくつでも同時に削除することができます。\n"; print "
\n"; print "
\n"; print "\n"; foreach $line (@DATA) { ($date,$code,$ress,$name,$email,$homepage,$title,$comment,$key) = split(/\,/,$line); $comment =~ s/
//g; print "[$code]\n"; print "$name\n"; print "$date
\n"; print "$comment\n"; print "
\n"; } print "
\n"; print "
\n"; print "\n"; print "\n"; print "削除コード:\n"; print "
\n"; print "スペースで区切っていくつでも同時に削除することができます。\n"; print "
\n"; exit; } #=== × 記事の削除:メンテから × ====================================================== sub delete { if ($FORM{'del'} eq "all"){ @new_data = ""; } else{ @CODE = split(/ /,$FORM{'delcode'}); $keycount = @CODE; if ($keycount eq 0) { &html; } if (!open(NOTE,"$file")) { &error(bad_file); } @DATA = ; close(NOTE); foreach $line (@DATA) { ($date,$code,$ress,$name,$email,$homepage,$title,$comment,$key) = split(/\,/,$line); $match = "false"; foreach $delcode (@CODE) { if ($code eq $delcode) { $match = "true"; } } if ($match eq "false") { push (@new_data,$line); } }} if (!open(NOTE,">$file")) { &error(bad_file); } print NOTE @new_data; close(NOTE); print "Location: $reload" . '?' . "\n\n"; } #=== × 記事の削除:削除キーから × ==================================================== sub s_delete { if (!open(NOTE,"$file")) { &error(bad_file); } @DATA = ; close(NOTE); foreach $line (@DATA) { ($date,$code,$ress,$name,$email,$homepage,$title,$comment,$s_pass) = split(/\,/,$line); if ($code != $FORM{'delcode'}) {push (@new_data,$line);} if ($code == $FORM{'delcode'}) { if ($FORM{'d_ps'} == $password) {} elsif ($FORM{'d_ps'} == $s_pass) {} elsif ($FORM{'d_ps'} != $s_pass) { &error(bad_pass);} } } if (!open(NOTE,">$file")) { &error(bad_file); } print NOTE @new_data; close(NOTE); print "$FORM{'d_ps'}\n"; print "Location: $reload" . '?' . "\n\n"; } #=== ▽ エラー処理 ▽ ================================================================== sub error { $error = $_[0]; if ($error eq "bad_file") { $msg = 'ファイルのオープン、入出力に失敗しました'; } elsif ($error eq "bad_name") { $msg = '名前を入れてね。'; } elsif ($error eq "bad_comment") { $msg = 'コメントを入れてね。'; } elsif ($error eq "bad_nomatch") { $msg = 'コードが登録されていません。'; } elsif ($error eq "bad_pass") { $msg = '削除キーが一致しません'; } elsif ($error eq "bad_pass2") { $msg = '削除キーを入れてね。記事の削除に使います'; } else { $msg = '原因不明のエラーで処理を継続できません'; } print "Content-type: text/html\n\n"; print "$head\n"; print "$body\n"; print "



\n"; print "

ERROR
\n"; print "「戻る」ボタンで戻ってください\n"; print "

$msg
\n"; print "\n"; exit; }