☆1行掲示板☆
#!/usr/local/bin/perl
#
# 蓄々一行掲示板 v2 rev 1.3
#
# このファイルは主となるスクリプトです。
# 設定は conf.cgi で行います。
# バージョンアップ時に差し替えが可能です。
#
# 使い方
# HTMLに記述するタグの文法
# [an error occurred while processing this directive]
# 記述例
# [an error occurred while processing this directive]
# 掲示板に直接リンクする場合
# BBS
# 書き込みの管理
# 掲示板下部のadminリンクを開いて下さい。
#
# 蓄積多趣味人(作者のサイト)
# http://www.akiyan.com/
#
# とほほのSSI入門
# http://tohoho.wakusei.ne.jp/wwwssi.htm
#
# 更新履歴
# 2003/01/08 rev1.3 conf.cgiの管理ページのスタイルシート設定項目を無効にし、管理ページで表がウィンドウからはみ出て表示される問題を修正。
# 2002/12/26 rev1.2.1 管理ページに書き込みフォームを追加、自動リンクのtarget属性設定を追加。
# 2002/12/23 rev1.2 日付が1ヶ月遅れて表示される問題を修正。
# 2002/12/19 rev1.1 公開。
#
require 'conf.cgi';
require 'jcode.pl';
&get_query_string();
$conf{'maxlog'}--;
$admin_style = <<"EOM";
h1,h2 {
font-size:100%;
font-weight:bold;
margin:0;
}
body {
font-size:82%;
padding:1%;
}
thead {
font-weight:bold;
}
tbody {
font-weight:normal;
}
td {
border-width:0 0 1px 0;
border-style:dotted;
border-color:#888;
margin:0;
word-break:break-all;
}
EOM
$MODE = $FORM{'mode'};
$ACTION = $FORM{'action'};
$LOG_FILENAME = './log.cgi';
@LOG_FORMAT = ('status', 'number' ,'name' ,'text' ,'time' , 'host', 'referer');
$LOG_CUTSTR = '<>';
if ($MODE eq '') {
$conf{'charset'} = 'sjis';
&put(&login());
exit;
}
&loadlog();
if ($MODE eq 'write') {
&write();
print "location: $conf{'return_url'}\n\n";
exit;
}
if ($MODE eq 'logviewx') {
$conf{'charset'} = 'sjis';
$conf{'viewline'} = $conf{'viewline_logview'};
&put(&latest());
exit;
}
if ($MODE eq 'latest') {
&put(&latest());
exit;
}
if ($MODE eq 'admin') {
$conf{'charset'} = 'sjis';
if ($FORM{'password'} eq $conf{'password'}) {
&put(&admin());
} else {
&put(&login(' パスワードが違います。 ')); } exit; } exit; ### # ログをハッシュの配列に格納 / ログ保存最大件数チェック尻切 sub loadlog { local($num, $row, $log_src, $array, $key, $value, $num_active); @LOG = (); @LOG_ALL = (); @log_src = file($LOG_FILENAME); if ($#log_src > $conf{'maxlog'}) { open(OUT, "+< $LOG_FILENAME"); eval { flock(OUT, 2); }; eval { truncate(OUT, 0); }; eval { seek(OUT, 0, 0); }; for($num = 1; $num <= $#log_src; $num++) { print(OUT $log_src[$num]); } close(OUT); @log_src = file($LOG_FILENAME); } @log_src = reverse(@log_src); $num_active = 0; for ($num = 0; $num <= $#log_src; $num++) { my $data; $row = $log_src[$num]; @array = split(/$LOG_CUTSTR/, $row); @data = &format_hash(*LOG_FORMAT, *array); ($data{'sec'} ,$data{'min'} ,$data{'hour'} ,$data{'mday'} ,$data{'mon'} ,$data{'YEAR'} ,$data{'wday'} ,$data{'yday'} ,$data{'isdst'}) = localtime($data{'time'}); $data{'YEAR'} += ($data{'YEAR'} < 1900) ? 1900 : 0; $data{'year'} = substr($data{'YEAR'}, 2); $data{'mon'} = &enforce_figure($data{'mon'} + 1, 2); $data{'mday'} = &enforce_figure($data{'mday'}, 2); $data{'hour'} = &enforce_figure($data{'hour'}, 2); $data{'min'} = &enforce_figure($data{'min'}, 2); $data{'sec'} = &enforce_figure($data{'sec'}, 2); while ( ($key, $value) = each %data) { $LOG_ALL[$num]{$key} = $value; } if ($data{'status'} == 0) { while ( ($key, $value) = each %data) { $LOG[$num_active]{$key} = $value; } $num_active++; } } } sub put { local($html) = @_; if ($conf{'charset'} ne "" && $conf{'charset'} ne "sjis") { &jcode'convert(*html, $conf{'charset'}); } print $html; } sub latest { local($num, $hash_grob, $html, $contents, $option, $start, $body); $hash_grob = ''; $contents{'navi'} = ''; $contents{'message_list'} = ''; $html = &content_type('text/html'); my $view_count = 0; $start = ( $FORM{'start'} > 0 ) ? $FORM{'start'} : 0; for ($num = $start; $num <= $#LOG; $num++) { if ($conf{'autolink'}) { $LOG[$num]{'text'} = &auto_link($LOG[$num]{'text'}, $conf{'urlreplace'}, $conf{'target'}); } $hash_grob = $LOG[$num]; $contents{'message_list'} .= &replace_hash($hash_grob, $conf{'html_message'}); $view_count++; if ($view_count == $conf{'viewline'}) { if ($num < $#LOG && $MODE eq 'logview') { $option{'start'} = $FORM{'start'} + $conf{'viewline_logview'}; $contents{'navi'} = $conf{'html_navi'}; $contents{'navi'} = &replace_hash(*conf, $contents{'navi'}); $contents{'navi'} = &replace_hash(*option, $contents{'navi'}); } $num = $#LOG; } } if ($MODE eq 'logview') { $body{'body'} = $conf{'html_body'}; $body{'body'} = &replace_hash(*conf , $body{'body'}); $body{'body'} = &replace_hash(*contents, $body{'body'}); $html .= $conf{'html_logview'}; $html = &replace_hash(*body, $html); $html = &replace_hash(*conf, $html); } else { $html .= $conf{'html_body'}; $html = &replace_hash(*conf, $html); $html = &replace_hash(*contents, $html); } return($html); } sub write { local(@data, $wdata, $first, $row); $wdata = ''; $first = 1; $data{'number'} = &select_max(*LOG_ALL, 'number') + 1; $data{'name'} = &real_html($FORM{'name'}); $data{'text'} = &real_html($FORM{'text'}); $data{'time'} = &gettime($conf{'timediff'}); $data{'status'} = 0; $data{'host'} = ($ENV{'REMOTE_HOST'} ne '') ? $ENV{'REMOTE_HOST'} : $ENV{'REMOTE_ADDR'}; $data{'referer'} = $ENV{'HTTP_REFERER'}; if ($data{'name'} eq "") { &error('名前が入力されていません。'); exit; } if ($data{'text'} eq "") { &error('メッセージが入力されていません。'); exit; } if ($data{'text'} =~ /http/){ &error('This message seems spam.'); exit; } if ($data{'text'} =~ /\!/){ &error('This message seems spam.'); exit; } if (!($data{'host'} =~ /jp/)){ &error('This message seems spam.'); } if (length($data{'name'} . $data{'text'}) > $conf{'maxlength'}) { &error('入力可能な最大の長さは、名前とメッセージで' . $conf{'maxlength'} . 'バイトまでです。'); exit; } if ((time() - (stat($LOG_FILENAME))[9]) <= $conf{'stoptime'}) { &error($conf{'stoptime'} . '秒以内の連続書き込みは禁止されています。'); exit; } foreach $row (@LOG_FORMAT) { $wdata .= ($first != 1) ? $LOG_CUTSTR : ''; $wdata .= $data{$row}; $first = 0; } open(OUT, ">> $LOG_FILENAME"); eval { flock(OUT, 2); }; print(OUT "$wdata\n"); close(OUT); } sub login { local($message) = @_; if ($conf{'password'} eq '') { $message .= '【警告】パスワードが設定されていません。conf.cgiを編集してパスワードを設定してください。(そのままボタンを押せばログインは出来ます) '; } $html = &content_type('text/html'); $html .= &html_header($conf{'title'}.' 管理ログイン',$admin_style); $html .= <<"EOM";$conf{'title'} 管理ログイン |