#!/usr/local/bin/perl ############################################################################## # shiromuku(bu2)BBS version 2.72 # Created 04/22/2002 # Copyright 2002 Shiromuku # Available at http://www.t-okada.com/cgi/ ############################################################################### # COPYRIGHT NOTICE (著作権の告示) # Copyright 2002 Shiromuku All Rights Reserved. # This script can be used and modified free of charge as long as you don't change this header or any of the parts that give me credit for writing this. (このスクリプトは無償で使用または改変できます。ただしこの著作権の告知と上記のコメント、及びCGIにより生成されるHTML表示下部にある著作権表示部は変えないで下さい。) # By using this script you agree to indemnify me from any liability that might arise from its use. In simple English, if this script somehow makes your computer run amuck and kill the pope, it's not my fault.(このスクリプトを使用することにより、使用者はその使用によって起こる可能性のあるいかなる事柄に対する責務についても、私Shiromukuに免責の保証を与えることに同意したものとします。) # Redistributing and selling the code for this program without prior written consent is expressly forbidden.(前もって書面での承諾を得ることなくこのプログラムのコードを再配布したり売ったりすることは 明確に禁じられています。) ####################### require './jcode.pl'; require './sbu2_bbs_lib.cgi'; ####################### use strict; my $gl = &get_globals("sbu2_bbs_gl.cgi"); $gl->{version} = "version 2.72"; my ($form, $filename); my $config = &open_config ($gl); if ($ENV{'CONTENT_LENGTH'} || $ENV{'QUERY_STRING'}) {$form = &parse_data($gl,$config);} my %HoD = (); @HoD{"gl", "config", "form"} = ($gl, $config, $form); if ($config->{use_view_pass}) { my%boardname = split(/\,/,$HoD{gl}{boardname}); my$cookie = &get_cookie (\%boardname); #print "Content-type: text/html\n\n"; #print "cookie/$cookie->{view_password}\n"; if ($HoD{form}{view_password}) { &check_view_pass (\%HoD,"view_pass"); } else { if ($cookie->{view_password}) { $HoD{form}{view_password} = $cookie->{view_password}; &check_view_pass (\%HoD,"view_pass"); } else {&return_login(\%HoD); exit (0) ;} } } if ($ENV{'REQUEST_METHOD'} eq "POST") { if ($form->{action} eq "admin_enter") {&return_admin_enter(\%HoD);} elsif ($form->{action} eq "show_icon") {&show_icon(\%HoD);} elsif ($form->{action} eq "reply") {&return_reply(\%HoD);} elsif ($form->{action} eq "search_all") {&search_all(\%HoD);} elsif ($form->{action} eq "showlast") {&return_html(\%HoD);} elsif ($form->{action} eq "user") {&user(\%HoD);} elsif ($form->{action} eq "user_a") {&user(\%HoD);} exit (0) ; } else { if ($form->{action} eq "show_icon") {&show_icon(\%HoD); exit (0);} $filename = "$gl->{basedir}/$gl->{passfile}"; if (-e $filename) {&return_html(\%HoD);} else { &head("管理用ページ", \%HoD); print "

IDとパスワードの設定をする

\n"; print "
まず最初にIDとパスワードの設定をして下さい
\n"; print "
{cgi_a}\">\n"; print "\n"; print "
\n"; print "\n"; print "\n"; print "
ユーザID
(半角英数字で8文字以内にして下さい。)
パスワード
(半角英数字で8文字以内にして下さい。)
パスワード
(確認のためもう一度)
\n"; print "
\n"; print "
\n"; print "\n"; } } exit (0) ; ############################ sub parse_data { my ($gl,$config) = @_; my ($buffer, @pairs, $pair, $name, %form, $value); if ($ENV{'REQUEST_METHOD'} eq "POST") { if ($config->{check_referer} == 1) {&check_referer($gl,$config);} read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else {$buffer = $ENV{'QUERY_STRING'};} @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/\|\|\|//g; $value =~ s//>/ig; $value =~ s/"/"/g; $value =~ s/\r\n/
/g; $value =~ s/\r/
/g; $value =~ s/\n/
/g; jcode::convert(\$value,$gl->{mycode}); if ($gl->{mycode} eq 'sjis') {jcode::h2z_sjis(\$value); } if ($gl->{mycode} eq 'euc') {jcode::h2z_euc(\$value); } $form{$name} = $value; } return \%form; } ############################ #書き込みと最新記事表示用のメインページ sub return_html{ my$HoD = shift; my($c_num, $page_maxs, $p, $ps, @pp_data, $p_flag, $t_flag, %last); if ($HoD->{config}{show_counter}) {$c_num = &counter ($HoD);} if (!$HoD->{form}{txtnumber}) {$HoD->{form}{txtnumber} = "log";} if (!$HoD->{form}{action}) {$HoD->{form}{action} = "showlast";} if ($HoD->{form}{txtnumber} ne "log") { $HoD->{config}{c1_image} = "Log$HoD->{form}{txtnumber}"; $HoD->{config}{c2_title} = "

Log$HoD->{form}{txtnumber}

"; $HoD->{config}{c2_introduction} = ""; } &head_html(\*STDOUT,$HoD); print "
{config}{align_b}\">{config}{t_width_b}\" BORDER=0 CELLPADDING=0>
\n"; print "$HoD->{config}{c2_title}\n"; print "$HoD->{config}{c2_introduction}\n"; if ($HoD->{form}{txtnumber} eq "log") { &add_form_html ("main", $HoD); print "

\n"; } open(LOG,"<$HoD->{gl}{basedir}/$HoD->{gl}{yourname}_$HoD->{form}{txtnumber}\.cgi"); if (!$HoD->{form}{next_page}) { $page_maxs = $HoD->{config}{n_page_max}; $p = 0; $HoD->{form}{next_page} = 0; $ps = 0;} else { $page_maxs = $HoD->{form}{next_page} + $HoD->{config}{n_page_max}; $p = 0; $ps = $HoD->{form}{next_page};} while () { chomp; @pp_data = split(/\|\|\|/,$_); if($pp_data[0] eq "petadmin") { if ($p >= $page_maxs) { $p_flag = 1; #last; } if (($p < $page_maxs) && ($p >= $HoD->{form}{next_page})) { if ($t_flag == 1) { print "
\n"; print "
\n"; if ($HoD->{config}{img_line_url} && ($HoD->{config}{img_line_url} ne 'http://')) { print "
{config}{img_line_url}\">
\n"; } if (!$HoD->{config}{img_line_url} && !$HoD->{config}{border_color} && !$HoD->{config}{table_color}) { print "
{config}{text_color}\">\n"; } print "
\n"; } print "
\n"; &table_html ($HoD); &subj_date_name_hp_html ("main", \@pp_data, $HoD); $t_flag = 1; $ps++; } $p++; } elsif (($pp_data[0] eq "reply") && ($p <= $page_maxs) && ($p > $HoD->{form}{next_page})) { if ($HoD->{config}{border_color}) { if (!$HoD->{config}{td_color}) { print "
{config}{border_color}\">\n"; } } else { if (!$HoD->{config}{td_color}) { print "
{config}{text_color}\">\n"; } } &subj_date_name_hp_html ("reply", \@pp_data, $HoD); $t_flag = 1; } } close(LOG); if ($t_flag == 1) { print "


\n"; } $last{ps} = $ps; $last{p1} = $p; $last{page_maxs} = $page_maxs; $last{p_flag} = $p_flag; $HoD->{last} = {%last}; &last_html ($HoD); if ($HoD->{config}{use_oldlog}) { my $txtnum = &get_number ($HoD->{gl}{txtnumfile}, '1', $HoD); if (-e "$HoD->{gl}{basedir}/$HoD->{gl}{yourname}_$txtnum\.cgi") { &last_html1($txtnum, $HoD); } } if (($HoD->{form}{action} ne "selectadmin") && ($HoD->{form}{action} ne "reply") && ($HoD->{form}{action} ne "search_all")) { &form_html ($HoD); } print "
\n"; &search_html ($HoD); print "
\n"; print "$HoD->{config}{c2_back}\n"; print "
\n"; if (($HoD->{form}{txtnumber} eq "log") && $HoD->{config}{show_counter}) { print "
{config}{title_color}\" SIZE=2>$c_num
\n"; } &foot_html1 (\*STDOUT, $HoD); } ############################ #修正・削除画面 sub user { my $HoD = shift; my(@u_data, $test_pass, $flag); if ($HoD->{form}{mynum} eq "") {&error("番号を入力して下さい。\n", $HoD->{config});} if ($HoD->{form}{action} eq "user_a") {&check_pass ($HoD);} if ($HoD->{form}{action} eq "user") { if ($HoD->{form}{pass} eq "") {&error("パスワードを入力して下さい。\n", $HoD->{config});} $test_pass = &crypt ($HoD->{form}{pass}, 'aa', $HoD); } open(LOG,"<$HoD->{gl}{basedir}/$HoD->{gl}{yourname}_$HoD->{form}{txtnumber}\.cgi") || &error("ファイルがオープンできません。\n", $HoD->{config}); while () { next if /^\d+$/; chomp; @u_data = split(/\|\|\|/,$_); if ($HoD->{form}{mynum} == $u_data[2]) { if ((($HoD->{form}{action} eq "user") && ($u_data[11] eq $test_pass) && ($HoD->{form}{pass} ne '')) || ($HoD->{form}{action} eq "user_a")) { $HoD->{config}{c1_image} = "記事[$HoD->{form}{mynum}]の修正・削除"; &head_html(\*STDOUT,$HoD); print "

記事[$HoD->{form}{mynum}]の修正・削除

\n"; if ($HoD->{form}{action} eq "user_a") { print "
投稿者情報 $u_data[13]

\n"; } if ($u_data[12]) { print "
\n"; print "
\n"; &img_html($u_data[12],$HoD); print "\n"; print "

\n"; } $u_data[9] =~ s/
/\n/g; if ($HoD->{config}{use_html} != 1) { $u_data[9] =~ s/(.*?)<\/B>/<B>$1<\/B>/ig; $u_data[9] =~ s/(.*?)<\/FONT>/<FONT $1>$2<\/FONT>/ig; $u_data[9] =~ s/]+)>(.*?)<\/a>/<a href=$1>$2<\/a>/ig; $u_data[9] =~ s/<([^>]|\n)*>//g; } print "
{gl}{cgi_r}\">\n"; if ($HoD->{form}{action} eq "user") { print "\n"; print "{form}{pass}\">\n"; } print "{form}{txtnumber}\">\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; &table_html ($HoD); &add_html ($HoD, \@u_data); print "\n"; print "

\n"; if ($HoD->{form}{action} eq "user_a") { &id_html1($HoD); print "\n"; print "\n"; } print "
\n"; print "
\n"; print "

\n"; print "
{gl}{cgi_a}\">\n"; print "\n"; print "\n"; print "\n"; print "{form}{txtnumber}\">\n"; print "\n"; if ($HoD->{form}{action} eq "user") { print "\n"; print "{form}{pass}\">\n"; } if ($HoD->{form}{action} eq "user_a") { &id_html1($HoD); print "\n"; print "\n"; } print "
\n"; print "
\n"; &foot_html (\*STDOUT, $HoD); $flag = 1; last; } else { &error("ID・パスワードに間違いがあります。\n", $HoD->{config}); } } else { $flag = 0; } } close(LOG); if ($flag == 0) { &error("正しい番号を入力して下さい。\n", $HoD->{config}); } } ############################ #返信書き込み用ページ sub return_reply{ my $HoD = shift; my (@r_data, @r_datax, $res_num); $HoD->{config}{c1_t_comment} ="Reply to the Message [$HoD->{form}{mynum}]"; $HoD->{config}{c1_image} = "Reply to the Message [$HoD->{form}{mynum}]"; $HoD->{config}{c2_title} = "

Reply to the Message [$HoD->{form}{mynum}]



"; &head_html(\*STDOUT,$HoD); print "
{config}{align_b}\">{config}{t_width_b}\" BORDER=0 CELLPADDING=0>
\n"; print "$HoD->{config}{c2_title}\n"; open(LOG,"<$HoD->{gl}{basedir}/$HoD->{gl}{yourname}_$HoD->{form}{txtnumber}\.cgi") || &error("ファイルがオープンできません。\n",$HoD->{config}); while () { chomp; @r_data = split(/\|\|\|/,$_); if (($r_data[0] eq "petadmin") && ($r_data[2] == $HoD->{form}{mynum})) { @r_datax = @r_data; print "
\n"; &table_html ($HoD); &subj_date_name_hp_html ("main", \@r_data, $HoD); } elsif (($r_data[0] eq "reply") && ($r_data[1] == $HoD->{form}{mynum})) { if ($HoD->{config}{border_color}) { print "
{config}{border_color}\">\n"; } else { print "
{config}{text_color}\">\n"; } &subj_date_name_hp_html ("reply", \@r_data, $HoD); } } close(LOG); print "


\n"; print "
\n"; &add_form_html("reply", $HoD, \@r_datax); print "

\n"; print "
\n"; &foot_html (\*STDOUT, $HoD); } ############################ #全記事検索処理 sub search_all { my $HoD = shift; my ($filename, $i, @match, $page_maxs, $p, $ps, $lines, @s_data, $cat_data, $cat_name_j,$lastnumx,$pp,$s_num, $p_flag, %last); my $searchword = $HoD->{form}{searchword}; my $next_page = $HoD->{form}{next_page}; my $yourname = $HoD->{gl}{yourname}; if ($searchword eq '') {&error("キーワードを記入して下さい。\n", $HoD->{config});} $searchword =~ s/ / /g; my @searchword = split(' ', $searchword); $HoD->{config}{c1_image} = "Search"; $HoD->{config}{c2_title} = "

Search

"; $HoD->{config}{c2_introduction} = ""; &head_html(\*STDOUT,$HoD); print "
{config}{align_b}\">{config}{t_width_b}\" BORDER=0 CELLPADDING=0>
\n"; print "$HoD->{config}{c2_title}\n"; print "$HoD->{config}{c2_introduction}\n"; print "
【$searchword】の検索結果です\n"; open (LFILE,">$HoD->{gl}{basedir}/$HoD->{gl}{lockfile}") or &error("ファイルがオープンできません。\n", $HoD->{config}); eval("flock(LFILE, 2)"); opendir (DIR, "$HoD->{gl}{basedir}"); foreach $filename ( readdir (DIR) ) { if ($filename =~ /^$yourname\_(\w+)\.cgi$/o) { $lastnumx = $1; open(FILE,"<$HoD->{gl}{basedir}/$filename") or &error("ファイルがオープンできません。\n", $HoD->{config}); while () { next if /^\d+$/; $pp = 0; foreach $i (@searchword) { if (index($_,$i) >= 0) { $pp++; if ($HoD->{form}{s} eq 'or') { last; } } else { $pp = 0; if ($HoD->{form}{s} eq 'and') { last; } } } $_ .= $lastnumx; push (@match, $_) if ($pp > 0); } $s_num = @match; close(FILE); } } closedir (DIR); eval("flock(LFILE, 8)"); close(LFILE); if ($s_num) { print "--- 該当記事: $s_num

\n"; if (!$HoD->{form}{next_page}) { $page_maxs = $HoD->{config}{n_page_max}; $p = 0; $HoD->{form}{next_page} = 0; $ps = 0;} else { $page_maxs = $HoD->{form}{next_page} + $HoD->{config}{n_page_max}; $p = 0; $ps = $HoD->{form}{next_page};} foreach $lines (@match) { my @line = split(/\n/,$lines); chomp $line[0]; @s_data = split(/\|\|\|/,$line[0]); $HoD->{form}{txtnumber} = $line[1]; if ($p >= $page_maxs) { $p_flag = 1; last; } if (($p < $page_maxs) && ($p >= $HoD->{form}{next_page})) { &table_html ($HoD); &subj_date_name_hp_html ("main", \@s_data, $HoD); &back_html ($HoD); print "

\n"; $ps++; } $p++; } $last{ps} = $ps; $last{page_maxs} = $page_maxs; $last{p_flag} = $p_flag; $HoD->{last} = {%last}; &last_html ($HoD); } else { print "
該当する記事はありませんでした。
\n"; } &search_html ($HoD); print "
\n"; &foot_html (\*STDOUT, $HoD); } ############################ #ページ移動 sub last_html { my $HoD = shift; my ($page, $i, $k); my $next_pages = $HoD->{last}{ps}; my $prev_page = $HoD->{form}{next_page} - $HoD->{config}{n_page_max}; print "
\n"; if (($prev_page >= 0) && ($HoD->{last}{page_maxs} != $HoD->{config}{n_page_max})) { print "{gl}{cgi}\">\n"; print "{form}{cat}\">\n"; print "{form}{action}\">\n"; print "{form}{txtnumber}\">\n"; print "{form}{t_type}\">\n"; print "{form}{searchword}\">\n"; print "{form}{searchword_a}\">\n"; print "{form}{searchword_b}\">\n"; print "{form}{s}\">\n"; print "\n"; print "\n"; } if ($HoD->{last}{p_flag} == 1) { print "{gl}{cgi}\">\n"; print "{form}{cat}\">\n"; print "{form}{action}\">\n"; print "{form}{txtnumber}\">\n"; print "{form}{t_type}\">\n"; print "{form}{searchword}\">\n"; print "{form}{searchword_a}\">\n"; print "{form}{searchword_b}\">\n"; print "{form}{s}\">\n"; print "\n"; print "\n"; } print "
\n"; if ($HoD->{form}{txtnumber} && $HoD->{last}{p1}) { if ($HoD->{form}{txtnumber} eq "log") {print "現行ログ/\n";} else {print "Log$HoD->{form}{txtnumber}/\n";} if ($HoD->{last}{p1}) { $page = int($HoD->{last}{p1}/$HoD->{config}{n_page_max}); if ((($HoD->{last}{p1} % $HoD->{config}{n_page_max}) > 0) || ($HoD->{config}{n_page_max} == 0)) {++$page;} $i = 1; $k = 0; while ($i <= $page) { if ($HoD->{form}{next_page} == $k) { print "[$i]\n"; } else { print "{gl}{cgi}?action=showlast&cat=$HoD->{form}{cat}&txtnumber=$HoD->{form}{txtnumber}&next_page=$k&t_type=$HoD->{form}{t_type}\" style=\"text-decoration:none\">[$i]\n"; } ++$i; $k += $HoD->{config}{n_page_max}; } } print "\n"; } print "
\n"; } ############################ #過去の記事を見る部分のHTML sub last_html1 { my($txtnum, $HoD) = @_; print "
\n"; print "{gl}{cgi}\" TARGET=_self>\n"; print "{form}{cat}\">\n"; print "{form}{action}\">\n"; print "{form}{t_type}\">\n"; print "\n"; print "
\n"; print "
\n"; #print "
\n"; } ############################ #アイコンの表示 sub show_icon { my $HoD = shift; $HoD->{config}{c1_image} = "Icon"; $HoD->{config}{c2_title} = "

Icon

"; $HoD->{config}{c2_bkgd_img} = ""; &head_html(\*STDOUT,$HoD); print "

Icon

\n"; &show_files($HoD); print "

ブラウザを閉じて戻って下さい。
\n"; print "\n"; } ############################ #フォーム部分のHTML sub add_form_html { my ($h_type, $HoD, $data) = @_; my$marktopl = $data->[0]; ++$marktopl; my$cookie; my%boardname = split(/\,/,$HoD->{gl}{boardname}); if ($HoD->{config}{usepasscookie} == 1) {$cookie = &get_cookie (\%boardname);} print "
\n"; &table_html ($HoD); print "
$HoD->{config}{c1_t_comment}
\n"; print "\n"; print "
{gl}{cgi_r}\">\n"; print "\n"; if ($h_type eq "main") { print "\n"; } if ($h_type eq "reply") { print "\n"; print "[2]\">\n"; } &add_html ($HoD, $data); if ($HoD->{config}{use_add_pass}) { print "\n"; print "投稿用PASS{add_password}\">\n"; } print "
\n"; print "
\n"; } ############################ #修正・削除フォーム sub form_html { my $HoD = shift; my$cookie; my%boardname = split(/\,/,$HoD->{gl}{boardname}); if ($HoD->{config}{usepasscookie} == 1) {$cookie = &get_cookie (\%boardname);} print "
{gl}{cgi}\">\n"; print "
\n"; print "\n"; print "{form}{txtnumber}\">\n"; print "\n"; print "{gl}{cgi}\">\n"; print "\n"; print "{form}{txtnumber}\">\n"; print "\n"; print "
No.\n"; print "PASS{pass}\">\n"; print "
No.\n"; print "USER{username}\" size=10>\n"; print "PASS{password}\" size=10>\n"; print "
\n"; } ############################ #counter sub counter { my $HoD = shift; my $c_num = &get_number ($HoD->{gl}{c_numfile}, '1', $HoD); unless ($HoD->{form}{action} =~ /^showlast/) { &increment_num ($HoD->{gl}{c_numfile},$c_num, $HoD); } if (length $c_num < $HoD->{config}{n_figure1}) { $c_num = &make_figure ($c_num,length $c_num,$HoD->{config}{n_figure1}); } return $c_num; } ############################ #桁数調整 sub make_figure { my ($num, $length, $figure) = @_; my $keta = $figure - $length; my $i = 0; while ($i < $keta) { $num = "0$num"; $i++; } return $num; }