#!/usr/local/bin/perl
#Web Diary Professional (2004/05/01)
$ver = '2.27';
#
#Copyright(C) Knight 2002-2004
#Mail ... knight@big.or.jp
#Home ... http://www.big.or.jp/~knight/
#――――― 設定項目 ――――――――――――――――――――――――
#管理者用パスワード
$admin_pwd = 'pass';
#初期設定ファイル
require './diary.ini';
#――――― 設定項目終了 ――――――――――――――――――――――
### メイン処理
&mobile();
&decode();
if ($in{'mode'} eq 'res' && $res_mode == 1) {
&res();
} elsif ($in{'mode'} eq 'icon' && $icon_mode == 1) {
&icon();
} elsif ($in{'mode'} eq 'img' && $img_show_way == 2) {
&img();
} elsif ($in{'mode'} eq 'loglist') {
&loglist();
} elsif ($in{'mode'} eq 'view') {
&view();
} elsif ($in{'mode'} eq 'search') {
&search();
} elsif ($in{'mode'} eq 'userdel' && $res_mode == 1) {
&userdel();
} elsif ($in{'mode'} eq 'past' && $make_past == 1) {
&past();
} elsif ($in{'mode'} eq 'admin') {
&admin();
} elsif ($in{'mode'} eq 'regist' && $res_mode == 1) {
®ist();
}
if ($frame_mode == 1) {
&frame();
} else {
&html();
}
### HTML出力
sub html {
if ($mini_counter != 0) {
if ($ENV{'REQUEST_METHOD'} ne 'POST' && $ENV{'QUERY_STRING'} eq '') {
&count_up();
}
open(COUNT, "$count_log") || &error("カウントログファイルを読み出せません");
$data = ;
close(COUNT);
($sum, $c_today, $c_yesterday, $key) = split(/\t/, $data);
}
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
&header();
print <<"_HTML_";
▲戻る /
タイトル一覧 /
ログ検索 /
_HTML_
if ($res_mode == 1) {
print qq|
記事編集 / \n|;
}
if ($make_past == 1) {
print qq|
過去ログ / \n|;
}
print <<"_HTML_";
投稿者用
_HTML_
if ($mini_counter == 1) {
$counter = sprintf("%0${count_figure}d", $sum);
print qq|Access $counter\n|;
}
print <<"_HTML_";
_HTML_
if ($show_title == 1) {
print <<"_HTML_";
_HTML_
if ($title_img ne '') {
print qq|

\n|;
} else {
print qq|
$title
\n|;
}
print <<"_HTML_";
$top_message
_HTML_
} else {
print '
';
}
print <<"_HTML_";
|
_HTML_
if ($layout == 0) {
if ($show_calendar == 1) {
&calendar(@logs);
}
if ($record_size != 0) {
&record(@logs);
}
print <<"_HTML_";
|
_HTML_
if ($show_index == 0 || $in{'date'} ne '' || $in{'year'} ne '' || $in{'month'} ne '' || $in{'no'} ne '') {
&showlog(&extract(@logs));
} else {
&index_mesg();
}
} elsif ($layout == 1) {
if ($show_calendar == 1) {
&calendar(@logs);
}
if ($record_size != 0) {
&record(@logs);
}
if ($show_index == 0 || $in{'date'} ne '' || $in{'year'} ne '' || $in{'month'} ne '' || $in{'no'} ne '') {
&showlog(&extract(@logs));
} else {
&index_mesg();
}
} else {
if ($show_index == 0 || $in{'date'} ne '' || $in{'year'} ne '' || $in{'month'} ne '' || $in{'no'} ne '') {
&showlog(&extract(@logs));
} else {
&index_mesg();
}
print <<"_HTML_";
|
_HTML_
if ($show_calendar == 1) {
&calendar(@logs);
}
if ($record_size != 0) {
&record(@logs);
}
}
print <<"_HTML_";
|
_HTML_
&footer();
}
### フレーム
sub frame {
if ($in{'mode'} eq 'frame_calendar' || $in{'exec'} eq 'move') {
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
&header();
print <<"_HTML_";
▲戻る /
タイトル一覧 /
ログ検索 /
_HTML_
if ($res_mode == 1) {
print qq|
記事編集 / \n|;
}
if ($make_past == 1) {
print qq|
過去ログ / \n|;
}
print <<"_HTML_";
_HTML_
if ($show_calendar == 1) {
&calendar(@logs);
}
if ($record_size != 0) {
&record(@logs);
}
print qq|\n|;
&footer();
} elsif ($in{'mode'} eq 'frame_log' || $in{'date'} ne '' || $in{'year'} ne '' || $in{'no'} ne '') {
if ($mini_counter != 0) {
open(COUNT, "$count_log") || &error("カウントログファイルを読み出せません");
$data = ;
close(COUNT);
($sum, $c_today, $c_yesterday, $key) = split(/\t/, $data);
}
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
&header();
print qq|\n|;
if ($mini_counter == 1) {
$counter = sprintf("%0${count_figure}d", $sum);
print qq|Access $counter\n|;
}
print qq|
\n|;
print qq|\n|;
if ($show_title == 1) {
if ($title_img ne '') {
print qq|

\n|;
} else {
print qq|
$title
\n|;
}
print <<"_HTML_";
$top_message
_HTML_
} else {
print '
';
}
if ($show_index == 0 || $in{'date'} ne '' || $in{'year'} ne '' || $in{'month'} ne '' || $in{'no'} ne '') {
&showlog(&extract(@logs));
} else {
&index_mesg();
}
print '
';
&footer();
} else {
if ($mini_counter != 0 && $ENV{'REQUEST_METHOD'} ne 'POST' && $ENV{'QUERY_STRING'} eq '') {
&count_up();
}
print <<"_HTML_";
Content-Type: text/html
$title
_HTML_
}
exit();
}
### インデックス
sub index_mesg {
print <<"_HTML_";
| $title |
| |
$index_message
_HTML_
if ($index_record_size != 0) {
print " ■ 最近の$index_record_size件 ";
$i = 0;
foreach (@logs) {
($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/);
if ($reno != 0) {
next;
}
$i++;
if ($i > $index_record_size) {
last;
}
($sec, $min, $hour, $day, $mon, $year, $week) = localtime(time());
$today = sprintf("%04d%02d%02d", $year + 1900, $mon + 1, $day);
if ($new_date != 0 && $today - $date < $new_date) {
$new = $new_mark;
} else {
$new = '';
}
if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) {
$date = "$1/$2/$3";
}
print qq|$date … $subj $new \n|;
}
}
print <<"_HTML_";
|
|
|
_HTML_
}
### カレンダー
sub calendar {
local(@logs) = @_;
if ($frame_mode == 1) {
$target = ' target="log"';
}
%date = ();
foreach (@logs) {
($date, $icon) = (split(/\t/))[2, 9];
if ($icon eq '') {
$icon = '-';
}
$date{"$date"} .= "$icon<>";
}
($d, $m, $y) = (localtime(time()))[3, 4, 5];
$y = sprintf("%04d", $y + 1900);
$m = sprintf("%01d", $m + 1);
$d = sprintf("%01d", $d);
if ($in{'date'} ne '') {
if ($in{'date'} =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) {
$year = sprintf("%04d", $1);
$month = sprintf("%01d", $2);
}
if ($y == $year && $m == $month) {
$today = $d;
}
} elsif ($in{'year'} eq '') {
$year = $y;
$month = $m;
$today = $d;
} else {
if ($in{'year'} == $y && $in{'month'} == $m) {
$today = $d;
}
$year = $in{'year'};
$month = $in{'month'};
}
$head = qq|$year年 $month月|;
$prev_month = $month - 1;
$prev_year = $year;
if ($prev_month < 1) {
$prev_month = 12;
$prev_year--;
}
$prev = qq|<<|;
$next_month = $month + 1;
$next_year = $year;
if ($next_month > 12) {
$next_month = 1;
$next_year++;
}
$next = qq|>>|;
print <<"_HTML_";
| $prev $head $next |
_HTML_
foreach (0 .. 6) {
$week = $week[$_];
print qq|| \n|;
if ($_ == 0) {
print qq|$week\n|;
} elsif ($_ == 6) {
print qq|$week\n|;
} else {
print qq|$week\n|;
}
print qq| | \n|;
}
print '
';
$wkey = &getweek('1', $year, $month);
$lastday = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[$month - 1] + ($month == 2 && (($year % 4 == 0 && $year % 100 != 0) || $year % 400 == 0));
$i = 0;
$day = 1;
$flag = 0;
$week_num = 0;
$spend = 0;
foreach (1 .. 42) {
if ($wkey == $i) {
$flag = 1;
}
if ($lastday < $day) {
$flag = 0;
}
if ($i == 0) {
print '';
}
if ($flag == 0) {
print qq|| - | \n|;
} else {
$month = sprintf("%02d", $month);
$code = sprintf("%02d", $day);
if ($day == $today) {
print qq||;
} else {
print qq| | |;
}
if ($i == 0) {
$color = $sun_color;
} elsif ($i == 6) {
$color = $sat_color;
} else {
$color = $day_color;
}
if ($spend == 1) {
$spend = 0;
$color = $sun_color;
} else {
foreach $spend_day (@spend_day) {
if ("$month$code" eq "$spend_day") {
if ($i == 0) {
$spend = 1;
}
$color = $sun_color;
last;
}
}
while (($m, $n) = each(%spend_day)) {
if ($i == 1 && "$month" eq "$m" && "$week_num" eq "$n") {
$color = $sun_color;
last;
}
}
}
if ($written_mark eq '' && $date{"$year$month$code"} ne '') {
print qq||;
}
print qq|$day\n|;
if ($written_mark eq '' && $date{"$year$month$code"} ne '') {
print qq||;
}
if ($written_mark ne '' && $date{"$year$month$code"} ne '') {
$j = 1;
foreach $diary_info (split(/<>/, $date{"$year$month$code"})) {
if ($icon_display != 0) {
if ($diary_info eq '-') {
$written_icon = $written_mark
} else {
$written_icon = qq| |;
}
} else {
$written_icon = $written_mark;
}
if ($j != 1) {
$diary_no = "#$j";
} else {
$diary_no = '';
}
print qq| $written_icon\n|;
if ($written_mark_multi == 1) {
$j++;
} else {
last;
}
}
}
print qq| | |;
}
$i++;
if ($i == 1 && $flag == 1) {
$week_num++;
}
if ($i == 7) {
print '
';
$i = 0;
}
if ($flag == 1) {
$day++;
}
}
print <<"_HTML_";
_HTML_
$prev = qq|<< 前の月\n|;
$next = qq|次の月 >>\n|;
print qq|$prev / $next
\n|;
print <<"_HTML_";
_HTML_
}
### 更新履歴表示
sub record {
local(@logs) = @_;
if ($frame_mode == 1) {
$target = ' target="log"';
}
if ($res_mode == 1) {
$parent = 0;
foreach (@logs) {
if ((split(/\t/, $_))[1] == 0) {
$parent++;
}
}
} else {
$parent = $#logs + 1;
}
if ($in{'record'} > 0) {
$n = $in{'record'} - 1;
$prev = qq|↑新しい投稿 / |;
} else {
$prev = '';
}
if (int(($parent - 1) / $record_size) > $in{'record'}) {
$n = $in{'record'} + 1;
$next = qq|↓以前の投稿|;
} else {
$next = '';
}
print <<"_HTML_";
| ■ 更新履歴 |
_HTML_
$start = $in{'record'} * $record_size;
$end = $start + $record_size;
$i = 0;
foreach (@logs) {
($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/);
if ($reno != 0) {
next;
}
$i++;
if ($i <= $start) {
next;
}
if ($i > $end) {
last;
}
($sec, $min, $hour, $day, $mon, $year, $week) = localtime(time());
$today = sprintf("%04d%02d%02d", $year + 1900, $mon + 1, $day);
if ($new_date != 0 && $today - $date < $new_date) {
$new = $new_mark;
} else {
$new = '';
}
if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) {
$date = "$1/$2/$3";
}
print qq|$date $new $subj
\n|;
}
print <<"_HTML_";
$prev$next
|
_HTML_
}
### 投稿記事表示
sub showlog {
local(@logs) = @_;
if ($frame_mode == 1) {
$target = ' target="_parent"';
$mode = 'mode=frame_log&';
}
if ($res_mode == 1) {
$parent = 0;
foreach (@logs) {
if ((split(/\t/, $_))[1] == 0) {
$parent++;
}
}
} else {
$parent = $#logs + 1;
}
if ($in{'mode'} ne 'past' && $in{'date'} eq '' && $in{'year'} eq '' && $in{'month'} eq '' && $in{'no'} eq '') {
$start = $in{'page'} * $default_show;
$end = $start + $default_show;
} else {
$start = 0;
$end = $#logs + 1;
}
if ($in{'page'} > 0) {
$n = $in{'page'} - 1;
$prev = qq|↑新しい投稿 / |;
} else {
$prev = '';
}
if (int(($parent - 1) / $default_show) > $in{'page'}) {
$n = $in{'page'} + 1;
$next = qq|↓以前の投稿|;
} else {
$next = '';
}
$i = 0;
$flag = 0;
foreach (@logs) {
($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/);
if ($in{'mode'} eq 'search' || $reno == 0) {
$i++;
}
if ($i <= $start) {
next;
}
if ($i > $end) {
last;
}
if ($date ne '') {
if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) {
($sec, $min, $hour, $day, $mon, $year, $week) = localtime(time());
$today = sprintf("%04d%02d%02d", $year + 1900, $mon + 1, $day);
if ($in{'preview'} ne 'on' && $new_date != 0 && $today - $date < $new_date) {
$new = $new_mark;
} else {
$new = '';
}
$year = sprintf("%04d", $1);
$month = sprintf("%02d", $2);
$day = sprintf("%02d", $3);
$week = $week[&getweek($day, $year, $month)];
$date = qq|$year年$month月$day日($week)|;
} else {
($sec, $min, $hour, $day, $mon, $year, $week) = localtime($date);
$date = sprintf("%04d年%02d月%02d日(%s)%02d:%02d", $year + 1900, $mon + 1, $day, $week[$week], $hour, $min);
}
}
if ($mail ne '') {
$mail = qq|/ Eメール|;
}
if ($url ne '') {
$url = qq|/ URL|;
}
if ($auto_link == 1) {
$text = &auto_link($text);
}
if ($color_mode == 1) {
if ($color eq '') {
$color = $color[0];
}
$text = qq|$text|;
}
if ($upload_mode == 1 && $file ne '' && -e "$upfile_dir$file") {
$file =~ /[^\/\\]*\.([^.\/\\]*)$/;
$ext = ".$1";
$file_info = '';
$file_byte = &comma((stat("$upfile_dir$file"))[7]);
if ($ext eq '.gif' || $ext eq '.jpeg' || $ext eq '.jpg' || $ext eq '.jpe' || $ext eq '.png') {
open(IMG, "$upfile_dir$file");
binmode(IMG);
if ($ext eq '.gif') {
($img_width, $img_height) = &gifsize(*IMG);
} elsif ($ext eq '.jpeg' || $ext eq '.jpg' || $ext eq '.jpe') {
($img_width, $img_height) = &jpegsize(*IMG);
} elsif ($ext eq '.png') {
($img_width, $img_height) = &pngsize(*IMG);
}
if ($img_show_way == 2) {
$org_img_width = $img_width;
$org_img_height = $img_height;
}
if ($img_width > $img_max_width) {
$img_height = int($img_height / ($img_width / $img_max_width));
$img_width = $img_max_width;
}
if ($text_align == 0) {
$align_left = '';
} else {
$align_left = ' align="left"';
}
if ($img_align == 0) {
$file_info = qq|
|;
} elsif ($img_align == 1) {
$file_info = qq||;
} else {
$file_info = qq|
|;
}
if ($img_align == 1 || $text_align == 0) {
$text_top_br = '
';
}
if ($img_show_way == 0) {
$text = qq|$file_info$text_top_br$text\n|;
} elsif ($img_show_way == 1) {
$text = qq|$file_info$text_top_br$text\n|;
} elsif ($img_show_way == 2) {
$text = qq|$file_info$text_top_br$text\n|;
} else {
$text = qq|$file_info$text_top_br$text\n|;
}
} else {
$text = qq|$file($file_byte byte)
$text\n|;
}
}
if ($icon_mode == 1 && $icon_display != 1 && $icon ne '') {
$icon = qq|
|;
} else {
$icon = ' ';
}
chop($host);
if ($in{'preview'} ne 'on') {
$partition = '
';
}
if ($res_mode == 1 && $logs[0] + 0 != 0 && ($in{'mode'} eq '' || $in{'mode'} eq 'frame_log')) {
$res = qq|[ 返信する ]|;
}
if (($in{'mode'} eq 'search' && $in{'no'} eq '' && $flag == 1) || ($flag == 1 && $reno == 0)) {
print <<"_HTML_";
_HTML_
}
if (($in{'mode'} eq 'search' && $in{'no'} eq '') || $reno == 0) {
$flag = 1;
if ($in{'date'} ne '') {
print qq|\n|;
}
print <<"_HTML_";
_HTML_
}
if (($in{'mode'} eq 'search' && $in{'no'} eq '') || $reno == 0) {
if ($res_mode == 1 && $in{'mode'} eq 'search' && $in{'no'} eq '') {
if ($reno == 0) {
$show = $no;
} else {
$show = $reno;
}
$all_show_info = qq|[関連記事を表\示]|;
} else {
$all_show_info = '';
}
print <<"_HTML_";
| ■ $subj $new |
$date |
$all_show_info $res
|
_HTML_
} else {
print <<"_HTML_";
$partition□ $name $mail $url / $date $new
|
_HTML_
}
}
print <<"_HTML_";
_HTML_
if ($in{'mode'} ne 'search' && $in{'mode'} ne 'past' && $in{'date'} eq '' && $in{'year'} eq '' && $in{'month'} eq '' && $in{'no'} eq '') {
print <<"_HTML_";
$prev$next
_HTML_
}
return;
}
### 表示ログ抽出
sub extract {
local(@logs) = @_;
$i = 0;
@show = ();
foreach (@logs) {
($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/);
if ($in{'date'} ne '') {
if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) {
$year = $1;
$month = $2;
$day = $3;
if($in{'date'} =~ /^(\d\d\d\d)(\d\d)(\d\d)$/ && $year == $1 && $month == $2 && $day == $3) {
push(@show, $_);
$show_no = $no;
}
} elsif ($show_no ne '' && $show_no == $reno) {
push(@show, $_);
}
} elsif ($in{'year'} ne '' || $in{'month'} ne '') {
if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/ && $in{'year'} == $1 && $in{'month'} == $2) {
push(@show, $_);
$show_no = $no;
} elsif ($show_no ne '' && $show_no == $reno) {
push(@show, $_);
}
} elsif ($in{'no'} ne '') {
if ($in{'no'} == $no || $in{'no'} == $reno) {
push(@show, $_);
}
} else {
push(@show, $_);
}
}
@logs = ();
if ($show[0] ne '') {
@logs = @show;
} else {
$logs[0] = "0\t0\t\t\t\t\tNo Data\t該当する投稿はありません。\t\t\t\t\t";
}
return @logs;
}
### 投稿フォーム表示
sub form {
if ($in{'mode'} eq 'res') {
%cookie = &get_cookie($cookie_id);
if ($cookie{'url'} eq '') {
$cookie{'url'} = 'http://';
}
if ($cookie{'color'} eq '') {
$cookie{'color'} = $color[0];
}
$subj = 'Re:' . (split(/\t/, $logs[0]))[6];
$text = '';
$mode = 'regist';
$submit = '返信する';
} else {
%cookie = &get_cookie($cookie_id);
$in{'no'} = $reno;
$cookie{'name'} = $name;
$cookie{'mail'} = $mail;
$cookie{'url'} = $url;
$text =~ s/
/\n/g;
$cookie{'color'} = $color;
$cookie{'pwd'} = $in{'user_pwd'};
$mode = 'userdel';
$submit = '修正する';
}
print <<"_HTML_";
_HTML_
return;
}
### 返信フォーム表示
sub res {
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
@res = ();
foreach (@logs) {
($no, $reno) = split(/\t/);
if ($in{'no'} == $no || $in{'no'} == $reno) {
push(@res, $_);
}
}
@logs = @res;
&header();
print <<"_HTML_";
返信フォーム
_HTML_
&showlog(@logs);
&form();
&footer();
}
### 投稿画像表示
sub img {
print <<"_HTML_";
Content-Type: text/html
IMAGE WINDOW
_HTML_
exit;
}
### アイコン一覧
sub icon {
&header();
print <<"_HTML_";
アイコン一覧
■ 選択できるアイコンは以下のとおりです。
_HTML_
@new = ();
foreach (@icon) {
if ($_ ne '') {
push(@new, $_);
}
}
@icon = @new;
$icon_no = ($#icon + 1) / 2;
foreach (1 .. $icon_no) {
if (($_ % 5) == 1) {
print "\n";
}
$icon_file = shift(@icon);
$icon_name = shift(@icon);
print qq|
$icon_name | \n|;
if (($_ % 5) == 0) {
print "
\n";
}
if ($_ == $icon_no) {
foreach (1 .. (5 - ($_ % 5))) {
print qq|- | \n|;
}
print "\n";
}
}
print <<"_HTML_";
_HTML_
&footer();
}
### タイトル一覧
sub loglist {
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
$parent = 0;
foreach (@logs) {
if ((split(/\t/))[1] == 0) {
$parent++;
}
}
&header();
print <<"_HTML_";
タイトル一覧
_HTML_
if ($icon_display != 0) {
print qq|
\n|;
}
$start = $in{'page'} * $list_size;
$end = $start + $list_size;
$i = 0;
foreach (@logs) {
($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/);
if ($reno == 0) {
$i++;
}
if ($reno != 0 || $i <= $start) {
next;
}
if ($i > $end) {
last;
}
if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) {
($sec, $min, $hour, $day, $mon, $year, $week) = localtime(time());
$today = sprintf("%04d%02d%02d", $year + 1900, $mon + 1, $day);
if ($new_date != 0 && $today - $date < $new_date) {
$new = $new_mark;
} else {
$new = '';
}
$year = sprintf("%04d", $1);
$month = sprintf("%02d", $2);
$day = sprintf("%02d", $3);
$week = $week[&getweek($day, $year, $month)];
$date = qq|$year年$month月$day日($week)|;
}
if ($icon_display != 0) {
print qq||;
if ($icon ne '') {
print qq| |;
}
print qq| | |;
}
print qq|$date $subj $new \n|;
if ($icon_display != 0) {
print qq| |
|;
}
}
if ($icon_display != 0) {
print qq|
\n|;
}
print '';
print qq|ページ移動 /|;
foreach (0 .. int(($parent - 1) / $list_size)) {
$page_info = $_ + 1;
if ($in{'page'} == $_) {
print qq| [$page_info]|;
} else {
print qq| [
$page_info]|;
}
}
print qq|
\n|;
&footer();
}
### 個別表示
sub view {
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
&header();
@show = ();
$i = 1;
$pno = 0;
foreach (@logs) {
($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/);
if ($in{'no'} == $i || ($reno != 0 && $reno == $pno)) {
push(@show, $_);
if ($in{'no'} == $i) {
$pno = $no;
}
}
if ($reno == 0) {
$i++;
}
}
if ($in{'mode'} eq '') {
$view = qq|以前の投稿を表\示|;
} else {
$prev_view = '↓前の投稿';
$next_view = '次の投稿↑';
$view = '/';
if ($in{'no'} != $i - 1) {
$prev_no = $in{'no'} + 1;
$prev_view = qq|$prev_view\n|;
}
if ($in{'no'} != 1) {
$next_no = $in{'no'} - 1;
$next_view = qq|$next_view\n|;
}
}
print <<"_HTML_";
個別表\示
_HTML_
&showlog(@show);
print qq|$prev_view $view $next_view
\n|;
&footer();
}
### ログ検索
sub search {
&header();
print <<"_HTML_";
ログ検索
■ 検索したいキーワードを入力し、検索ボタンを押してください。
■ キーワードは半角スペースで区切って複数指定することができます。
_HTML_
if ($in{'word'} ne '' || $in{'no'} ne '') {
if ($make_past == 0 || $in{'obje'} ne 'past') {
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@search = ;
close(FILE);
}
if ($make_past == 1 && $in{'obje'} ne 'now') {
opendir(DIR, "$past_dir") || &error("過去ログディレクトリを読み出せません");
@dir = readdir(DIR);
closedir(DIR);
@dir = sort {$b <=> $a} (@dir);
@past = ();
foreach (@dir) {
if ($_ =~ /^\d+(\.\w+)$/ && $1 eq $past_ext) {
open(FILE, "$past_dir$_") || &error("過去ログファイルを読み出せません");
@file = ;
close(FILE);
push(@past, @file);
}
}
if ($in{'obje'} eq 'all') {
push(@search, @past);
} elsif($in{'obje'} eq 'past') {
@search = @past;
}
}
if ($in{'word'} ne '') {
$in{'word'} =~ s/ / /g;
@pairs = split(/\s+/, $in{'word'});
@logs = ();
foreach (@search) {
$string = $_;
$flag = 0;
foreach $pair (@pairs) {
if ($in{'string'} eq 'dis') {
$string =~ tr/A-Z/a-z/;
$pair =~ tr/A-Z/a-z/;
}
if (index($string, $pair) >= 0) {
$flag = 1;
if ($in{'cond'} eq 'or') { last; }
} else {
if ($in{'cond'} eq 'and') { $flag = 0; last; }
}
}
if ($flag != 0) { push(@logs, $_); }
}
print qq|ページ移動 /|;
foreach (0 .. int($#logs / $page_size)) {
$page_info = $_ + 1;
if ($in{'page'} == $_) {
print qq| [$page_info]|;
} else {
$inword = $in{'word'};
$inword =~ s/(\W)/'%' . unpack('H2',$1)/ge;
print qq| [
$page_info]|;
}
}
print qq|
\n|;
} elsif ($in{'no'} ne '') {
@logs = ();
foreach (@search) {
($no, $reno) = split(/\t/);
if (($reno == 0 && $in{'no'} == $no) || ($reno != 0 && $in{'no'} == $reno)) {
push(@logs, $_);
}
}
print qq|
\n|;
}
$default_show = $page_size;
&showlog(@logs);
}
print '
';
&footer();
}
### ユーザー記事削除
sub userdel {
if ($in{'prev'} ne '') { $in{'page'}--; }
if ($in{'next'} ne '') { $in{'page'}++; }
if ($in{'delete'} ne '') {
if ($ENV{'REQUEST_METHOD'} ne 'POST') {
&error("不正なアクセスです");
}
if ($ENV{'HTTP_REFERER'} ne '' && $base_url ne '' && $ENV{'HTTP_REFERER'} !~ /^$base_url/i) {
&error("不正なアクセスです");
}
if ($in{'user_pwd'} eq '') {
&error("削除キーを入力してください");
}
if ($in{'del'} eq '') {
&error("削除したい記事を選択してください");
}
&lock($lock_file);
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
@new = ();
$flag = 0;
$del_list = '';
foreach (@logs) {
($no, $reno, $pwd) = (split(/\t/))[0, 1, 11];
if ($flag == 0 && $in{'del'} == $no) {
&decrypt($in{'user_pwd'}, $pwd);
$flag = 1;
} elsif ($flag == 1 && $in{'del'} == $reno) {
$flag = 1;
} else {
$flag = 0;
}
if ($flag == 0) {
push(@new, $_);
} else {
$del_list .= " [$no]";
}
}
$work_mesg = "$del_list番の記事を削除しました";
open(FILE, ">$log_file") || &error("ログファイルに書き込めません");
print FILE @new;
close(FILE);
if ($js_mode != 0) {
&output_jsfile(@new);
}
&unlock($lock_file);
}
if ($edit_mode == 1 && $in{'modify'} ne '') {
if ($ENV{'REQUEST_METHOD'} ne 'POST') {
&error("不正なアクセスです");
}
if ($ENV{'HTTP_REFERER'} ne '' && $base_url ne '' && $ENV{'HTTP_REFERER'} !~ /^$base_url/i) {
&error("不正なアクセスです");
}
if ($in{'user_pwd'} eq '') {
&error("削除キーを入力してください");
}
if ($in{'modi'} eq '') {
&error("修正したい記事を選択してください");
}
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
$flag = 0;
foreach (@logs) {
chop($_);
($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/);
if ($in{'modi'} == $no) {
&decrypt($in{'user_pwd'}, $pwd);
$flag = 1;
last;
}
}
if ($flag != 1) {
&error("該当する記事が見つかりません");
}
&header();
print <<"_HTML_";
$page_info
■ 記事を修正して、修正ボタンを押してください。
_HTML_
&form();
&footer();
}
if ($edit_mode == 1 && $in{'no'} ne '') {
®ist_check();
&lock($lock_file);
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
if ($in{'subj'} eq '') {
$in{'subj'} = '無題';
}
if ($in{'url'} eq 'http://') {
$in{'url'} = '';
}
if ($in{'pwd'} ne '') {
$in{'pwd'} = &encrypt($in{'pwd'});
}
$line = "$in{'no'}\t$in{'reno'}\t$in{'date'}\t$in{'name'}\t$in{'mail'}\t$in{'url'}\t$in{'subj'}\t$in{'text'}\t$in{'color'}\t$in{'icon'}\t$in{'file'}\t$in{'pwd'}\t$host\n";
@new = ();
foreach (@logs) {
if ($in{'no'} == ($_ + 0)) {
push(@new, $line);
} else {
push(@new, $_);
}
}
$work_mesg = "[$in{'no'}] 番の記事を修正しました";
open(FILE, ">$log_file") || &error("ログファイルに書き込めません");
print FILE @new;
close(FILE);
if ($js_mode != 0) {
&output_jsfile(@new);
}
&unlock($lock_file);
}
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
$parent = 0;
foreach (@logs) {
if ((split(/\t/))[1] == 0) {
$parent++;
}
}
&header();
print <<"_HTML_";
記事編集
■ 削除キーを入力して削除したい記事にチェックを入れ、削除ボタンを押してください。
_HTML_
if ($edit_mode == 1) {
print qq|■ 削除キーを入力して修正したい記事にチェックを入れ、修正ボタンを押してください。
\n|;
}
print <<"_HTML_";
■ 投稿時に削除キーを設定していなければ記事を削除することはできません。
_HTML_
&footer();
}
### 過去ログ表示
sub past {
opendir(DIR, "$past_dir") || &error("過去ログディレクトリを読み出せません");
@dir = readdir(DIR);
closedir(DIR);
@dir = sort {$a <=> $b} (@dir);
$past_byte = 0;
foreach (@dir) {
if ($_ =~ /^\d+(\.\w+)$/ && $1 eq $past_ext) {
$past_byte += (stat("$past_dir$_"))[7];
}
}
&header();
print <<"_HTML_";
過去ログ
■ 表\示したい過去ログを選択し、表\示ボタンを押してください。
■ ログ検索によって過去ログを検索することができます。
_HTML_
if ($in{'view'} ne '' && $in{'view'} =~ /^\d+\.\w+$/ && -e "$past_dir$in{'view'}") {
open(FILE, "$past_dir$in{'view'}") || &error("過去ログファイルを読み出せません");
@logs = ;
close(FILE);
if ($past_show == 1) {
if ($in{'no'} ne '') {
@show = ();
foreach (@logs) {
($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/);
if ($in{'no'} == $no) {
push(@show, $_);
last;
}
}
print '
';
&showlog(@show);
} else {
print '
';
if ($icon_display != 0) {
print qq|
\n|;
}
foreach (@logs) {
($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/);
if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) {
($sec, $min, $hour, $day, $mon, $year, $week) = localtime(time());
$year = sprintf("%04d", $1);
$month = sprintf("%02d", $2);
$day = sprintf("%02d", $3);
$week = $week[&getweek($day, $year, $month)];
$date = qq|$year年$month月$day日($week)|;
}
if ($icon_display != 0) {
print qq||;
if ($icon ne '') {
print qq| |;
}
print qq| | |;
}
print qq|$date $subj \n|;
if ($icon_display != 0) {
print qq| |
|;
}
}
if ($icon_display != 0) {
print qq|
\n|;
}
print '';
}
} else {
print '
';
&showlog(@logs);
}
}
print '
';
&footer();
}
### 管理者用
sub admin {
if ($in{'admin_pwd'} eq '') {
&header();
print <<"_HTML_";
管理者パスワードを入力してください
_HTML_
&footer();
} else {
if ($ENV{'REQUEST_METHOD'} ne 'POST') {
&error("不正なアクセスです");
}
if ($ENV{'HTTP_REFERER'} ne '' && $base_url ne '' && $ENV{'HTTP_REFERER'} !~ /^$base_url/i) {
&error("不正なアクセスです");
}
if ($in{'admin_pwd'} ne $admin_pwd) {
&error("パスワードが違います");
}
if ($in{'prev'} ne '') { $in{'page'}--; }
if ($in{'next'} ne '') { $in{'page'}++; }
if ($make_past == 1 && ($in{'create_log'} ne '' || $in{'read_log'} ne '')) {
&lock($lock_file);
opendir(DIR, "$past_dir") || &error("過去ログディレクトリを読み出せません");
@dir = readdir(DIR);
closedir(DIR);
@dir = sort {$a <=> $b} (@dir);
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
if ($in{'create_log'} ne '') {
$dir[$#dir] =~ /([^\/\\]*)\.([^.\/\\]*)$/;
$past_file = ($1 + 1) . $past_ext;
@past = ();
(*logs, *past) = &move_log(*logs, *past, $past_size);
open(FILE, ">$past_dir$past_file") || &error("過去ログファイルを作成できません");
print FILE @past;
close(FILE);
chmod(0666, "$past_dir$past_file");
$work_mesg = "スレッド$past_size件を過去ログに移動しました";
}
if ($in{'read_log'} ne '') {
$past_file = $dir[$#dir];
open(FILE, "$past_dir$past_file") || &error("過去ログファイルを読み出せません");
@past = ;
close(FILE);
(*logs, *past) = &move_log(*logs, *past, 're');
unlink("$past_dir$past_file");
$work_mesg = "スレッド$past_size件を過去ログから読み戻しました";
}
open(FILE, ">$log_file") || &error("ログファイルに書き込めません");
print FILE @logs;
close(FILE);
if ($js_mode != 0) {
&output_jsfile(@logs);
}
&unlock($lock_file);
}
if ($in{'delete'} ne '') {
if ($delete[0] eq '') {
&error("削除したい投稿を選択してください");
}
&lock($lock_file);
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
@new = ();
$del_list = '';
foreach (@logs) {
($no, $reno, $file) = (split(/\t/))[0, 1, 10];
$flag = 0;
foreach $del (@delete) {
if ($no == $del || $reno == $del) { $flag = 1; last; }
}
if ($flag == 0) {
push(@new, $_);
} else {
$del_list .= " [$no]";
if (-e "$upfile_dir$file") {
unlink("$upfile_dir$file");
}
}
}
$work_mesg = "$del_list番の投稿を削除しました";
open(FILE, ">$log_file") || &error("ログファイルに書き込めません");
print FILE @new;
close(FILE);
if ($js_mode != 0) {
&output_jsfile(@new);
}
&unlock($lock_file);
}
if ($in{'download'} ne '') {
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
print "Content-type: text/download\n\n";
print @logs;
exit;
}
if ($in{'form'} ne '' || $in{'modify'} ne '') {
if ($in{'form'} ne '') {
%cookie = &get_cookie($admin_cookie_id);
if ($cookie{'color'} eq '') {
$cookie{'color'} = $color[0];
}
$page_info = '予定を書く';
$form_info = '書き込む';
$input_mode = 'regist';
($sec, $min, $hour, $day, $mon, $year, $week) = localtime(time());
$this_year = sprintf("%04d", $year + 1900);
$this_month = sprintf("%02d", $mon + 1);
$this_day = sprintf("%02d", $day);
} else {
if ($in{'modi'} eq '') {
&error("修正したい投稿を選択してください");
}
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
$flag = 0;
foreach (@logs) {
chop($_);
($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/);
if ($in{'modi'} == $no) { $flag = 1; last; }
}
if ($flag != 1) {
&error("該当する日記が見つかりません");
}
$page_info = '予定を修正する';
$form_info = '修正する';
$input_mode = 'modi';
if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) {
$this_year = sprintf("%04d", $1);
$this_month = sprintf("%02d", $2);
$this_day = sprintf("%02d", $3);
} else {
($sec, $min, $hour, $day, $mon, $year, $week) = localtime(time());
$this_year = sprintf("%04d", $year + 1900);
}
$text =~ s/
/\n/g;
$cookie{'color'} = $color;
$cookie{'icon'} = $icon;
$file =~ /([^\/\\]*)\.([^.\/\\]*)$/;
$ext = $2;
$ext =~ tr/A-Z/a-z/;
}
&header();
print <<"_HTML_";
$page_info
_HTML_
if ($upload_mode == 1 && $in{'mode'} eq 'admin' && $in{'form'} ne '') {
$insert_data = qq| onSubmit="return insertData()"|;
}
if ($file ne '') {
print <<"_HTML_";
■ ファイルの項目を入力しなければ、以前の内容が引き続いて使用されます。
_HTML_
}
print <<"_HTML_";
_HTML_
&footer();
}
if ($in{'regist'} ne '' || $in{'modi'} ne '') {
$in{'subj'} = &create_line($in{'subj'});
$in{'text'} = &create_text($in{'text'});
$in{'text'} =~ s/&/&/g;
$in{'text'} =~ s/<//g;
$in{'text'} =~ s/"/"/g;
if ($in{'date'} eq '') {
$in{'date'} = "$in{'year'}$in{'month'}$in{'day'}";
}
if ($in{'date'} !~ /^\d\d\d\d\d\d\d\d$/) {
&error("日付が不正です");
}
if ($in{'subj'} eq '') {
&error("題名が入力されていません");
}
if ($in{'text'} eq '') {
&error("本文が入力されていません");
}
if ($in{'preview'} eq 'on') {
&preview();
}
$cookie{'color'} = $in{'color'};
$cookie{'icon'} = $in{'icon'};
$cookie{'preview'} = $in{'c_preview'};
&set_cookie(*cookie, $admin_cookie_id, $hold_days);
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
if ($in{'regist'} ne '') {
$host = $ENV{'REMOTE_HOST'};
$addr = $ENV{'REMOTE_ADDR'};
if ($host eq "" || $host eq $addr) {
if ($gethostbyaddr == 1) {
$host = gethostbyaddr(pack("C4", split(/\./, $addr)), 2) || $addr;
}
}
$no = 0;
$parent = 0;
$subj = '';
$text = '';
foreach (@logs) {
if ($_ + 0 > $no) {
($no, $date, $subj, $text) = (split(/\t/))[0, 2, 6, 7];
}
if ((split(/\t/))[1] == 0) {
$parent++;
}
}
$no++;
if ($in{'subj'} eq $subj && $in{'text'} eq $text) {
&error("すでに書き込まれています");
}
if ($in{'file'} ne '') {
$in{'file'} = &upfile($in{'file'}, $in{'filename'}, $no);
} elsif ($in{'ext'} ne '' && -e "$upfile_dir$temporary_file") {
$in{'file'} = "$no.$in{'ext'}";
rename("$upfile_dir$temporary_file", "$upfile_dir$in{'file'}");
}
$line = "$no\t0\t$in{'date'}\t\t\t\t$in{'subj'}\t$in{'text'}\t$in{'color'}\t$in{'icon'}\t$in{'file'}\t\t$host\n";
if ($make_past == 0) {
foreach (0 .. ($parent - $max_log)) {
($no, $reno) = split(/\t/, $logs[$#logs]);
if ($reno == 0) {
($file) = (split(/\t/, pop(@logs)))[10];
if (-e "$upfile_dir$file") {
unlink("$upfile_dir$file");
}
} else {
while ((split(/\t/, $logs[$#logs]))[1] != 0) {
($file) = (split(/\t/, pop(@logs)))[10];
if (-e "$upfile_dir$file") {
unlink("$upfile_dir$file");
}
}
($file) = (split(/\t/, pop(@logs)))[10];
if (-e "$upfile_dir$file") {
unlink("$upfile_dir$file");
}
}
}
}
@new = ();
$flag = 0;
foreach (@logs) {
($no, $reno, $date) = split(/\t/);
if ($flag == 0 && $reno == 0 && $in{'date'} + 0 >= $date) {
$flag = 1;
push(@new, $line);
}
push(@new, $_);
}
if ($flag == 0) {
push(@new, $line);
}
@logs = @new;
$work_mesg = "予定を新規に書き込みました"
} else {
if ($in{'file'} ne '') {
if (-e "$upfile_dir$in{'orgfile'}") {
unlink("$upfile_dir$in{'orgfile'}");
}
$in{'file'} = &upfile($in{'file'}, $in{'filename'}, $in{'no'});
} elsif ($in{'orgfile'} ne '' && $in{'delfile'} eq 'on') {
if (-e "$upfile_dir$in{'orgfile'}") {
unlink("$upfile_dir$in{'orgfile'}");
}
$in{'file'} = '';
} elsif ($in{'orgfile'} ne '') {
$in{'file'} = $in{'orgfile'};
}
$line = "$in{'no'}\t0\t$in{'date'}\t\t\t\t$in{'subj'}\t$in{'text'}\t$in{'color'}\t$in{'icon'}\t$in{'file'}\t\t$in{'host'}\n";
@new = ();
@tmp = ();
foreach (@logs) {
($no, $reno) = split(/\t/);
if ($in{'no'} == $no) {
push(@tmp, $line);
} elsif ($in{'no'} == $reno) {
push(@tmp, $_);
} else {
push(@new, $_);
}
}
@logs = ();
$flag = 0;
foreach (@new) {
($no, $reno, $date) = split(/\t/);
if ($flag == 0 && $reno == 0 && $in{'date'} + 0 >= $date) {
$flag = 1;
push(@logs, @tmp);
}
push(@logs, $_);
}
if ($flag == 0) {
push(@logs, @tmp);
}
$work_mesg = "$in{'no'}の予定を修正しました"
}
open(FILE, ">$log_file") || &error("ログファイルに書き込めません");
print FILE @logs;
close(FILE);
if ($js_mode != 0) {
&output_jsfile(@logs);
}
&unlock($lock_file);
}
if ($in{'download'} ne '') {
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
print "Content-type: text/download\n\n";
print @logs;
exit;
}
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
$log_byte = &comma(int((stat($log_file))[7] / 1024));
if ($logs[0] ne '' && $log_byte == 0) {
$log_byte = 1;
}
if ($make_past == 1) {
opendir(DIR, "$past_dir") || &error("過去ログディレクトリを読み出せません");
@dir = readdir(DIR);
closedir(DIR);
$past_byte = 0;
foreach (@dir) {
if ($_ =~ /^\d+(\.\w+)$/ && $1 eq $past_ext) {
$past_byte += (stat("$past_dir$_"))[7];
}
}
$past_byte = &comma(int($past_byte / 1024));
}
$parent = 0;
foreach (@logs) {
if ((split(/\t/))[1] == 0) {
$parent++;
}
}
if ($mini_counter != 0) {
open(COUNT, "$count_log") || &error("カウントログファイルを読み出せません");
$data = ;
close(COUNT);
($sum, $today, $yesterday, $key) = split(/\t/, $data);
}
&header();
print <<"_HTML_";
管理者用
■ 削除したい投稿にチェックを入れ、削除ボタンを押してください。
■ 修正したい投稿にチェックを入れ、修正ボタンを押してください。
■ ダウンロードボタンを押すと、現在のログをダウンロードします。
_HTML_
if ($make_past == 1) {
print qq|■ 投稿が$past_size件以上になると過去ログを作成することができます。
\n|;
} else {
print qq|■ 投稿が$max_log件以上になると古い日記から削除されます。
\n|;
}
print <<"_HTML_";
_HTML_
&footer();
}
}
### 記事登録
sub regist {
®ist_check();
if ($in{'preview'} eq 'on') {
&preview();
}
if ($mobile == 0) {
$cookie{'name'} = $in{'name'};
$cookie{'mail'} = $in{'mail'};
$cookie{'url'} = $in{'url'};
$cookie{'icon'} = $in{'icon'};
$cookie{'color'} = $in{'color'};
$cookie{'pwd'} = $in{'pwd'};
$cookie{'preview'} = $in{'c_preview'};
&set_cookie(*cookie, $cookie_id, $hold_days);
}
&lock($lock_file);
open(FILE, "$log_file") || &error("ログファイルを読み出せません");
@logs = ;
close(FILE);
$no = 0;
$parent = 0;
$name = '';
$text = '';
foreach (@logs) {
if ($_ + 0 > $no) {
($no, $date, $name, $text, $ip) = (split(/\t/))[0, 2, 3, 7, 12];
}
if ((split(/\t/))[1] == 0) {
$parent++;
}
}
$no++;
if ($in{'name'} eq $name && $in{'text'} eq $text) {
&unlock($lock_file);
&error("二重投稿は禁止です");
}
chop($ip);
if (time() - $date < $wait_time && $host eq $ip) {
&unlock($lock_file);
&error("連続投稿は$wait_time秒以上時間をあけてください");
}
$date = time();
if ($in{'subj'} eq '') {
$in{'subj'} = '無題';
}
if ($in{'url'} eq 'http://') {
$in{'url'} = '';
}
if ($in{'pwd'} ne '') {
$in{'pwd'} = &encrypt($in{'pwd'});
}
if ($in{'file'} ne '') {
$in{'file'} = &upfile($in{'file'}, $in{'filename'}, $no);
}
$line = "$no\t$in{'reno'}\t$date\t$in{'name'}\t$in{'mail'}\t$in{'url'}\t$in{'subj'}\t$in{'text'}\t$in{'color'}\t$in{'icon'}\t\t$in{'pwd'}\t$host\n";
@new = ();
$flag = 0;
foreach (@logs) {
($no, $reno) = split(/\t/);
if ($flag == 0 && $in{'reno'} == $no) {
$flag = 1;
} elsif ($flag == 1 && $in{'reno'} != $reno) {
$flag = 2;
push(@new, $line);
}
push(@new, $_);
}
if ($flag == 1) {
push(@new, $line);
}
@logs = @new;
open(FILE, ">$log_file") || &error("ログファイルに書き込めません");
print FILE @logs;
close(FILE);
if ($js_mode != 0) {
&output_jsfile(@logs);
}
&unlock($lock_file);
$in{'mode'} = '';
$in{'no'} = '';
$in{'date'} = '';
return;
}
### 投稿内容のチェック
sub regist_check {
if ($ENV{'REQUEST_METHOD'} ne 'POST' && $mobile == 0) {
&error("不正なアクセスです");
}
if ($ENV{'HTTP_REFERER'} ne '' && $base_url ne '' && $ENV{'HTTP_REFERER'} !~ /^$base_url/i) {
&error("不正なアクセスです");
}
$host = $ENV{'REMOTE_HOST'};
$addr = $ENV{'REMOTE_ADDR'};
if ($host eq "" || $host eq $addr) {
if ($gethostbyaddr == 1) {
$host = gethostbyaddr(pack("C4",split(/\./,$addr)),2) || $addr;
}
}
$flag = 0;
foreach $list (@blacklist) {
if ($list ne '' && $host =~ /$list/i) {
$flag = 1; last;
}
}
if ($proxy_check == 1) {
if ($ENV{'HTTP_VIA'} ne '' || $ENV{'HTTP_FORWARDED'} ne '' || $ENV{'HTTP_X_FORWARDED_FOR'} ne '') {
$flag = 1;
}
}
if ($flag == 1) {
&error("アクセスを許可されていません");
}
$in{'name'} = &create_line($in{'name'});
$in{'mail'} = &create_line($in{'mail'});
$in{'url'} = &create_line($in{'url'});
$in{'subj'} = &create_line($in{'subj'});
$in{'pwd'} = &create_line($in{'pwd'});
$in{'text'} = &create_text($in{'text'});
if ($in{'name'} eq '') {
&error("名前が入力されていません");
}
if (length($in{'name'}) > $name_length * 2) {
&error("名前の長さは全角$name_length文字までにしてください");
}
if (($in{'mail'} ne '' && $in{'mail'} =~ /[^\w\.\@\d-_]/ && $in{'mail'} !~ /(.*)\@(.*)\.(.*)/) || length($in{'mail'}) > 50) {
&error("Eメールの入力内容が正しくありません");
}
if (length($in{'url'}) > 70) {
&error("URLの入力内容が正しくありません");
}
if ($need_subj == 1 && $in{'subj'} eq '') {
&error("題名が入力されていません");
}
if (length($in{'subj'}) > ($subj_length + 2) * 2) {
&error("題名の長さは全角" . ($subj_length + 2) . "文字までにしてください");
}
if ($in{'text'} eq '') {
&error("本文が入力されていません");
}
if (length($in{'text'}) > $text_length * 2) {
&error("本文の長さは全角$text_length文字までにしてください");
}
if (($in{'text'} =~ s/
/
/g) + 1 > $text_line) {
&error("本文は$text_line行までにしてください");
}
if ($admin_icon_mode == 1 && $in{'icon'} eq $admin_icon[0]) {
&error("管理者専用のアイコンは使用できません");
}
if ($need_pwd == 1 && $in{'pwd'} eq '') {
&error("削除キーが設定されていません");
}
if (length($in{'pwd'}) > 10) {
&error("削除キーの長さは半角10文字までにしてください");
}
return;
}
### プレビュー表示
sub preview {
if ($in{'mode'} eq 'admin') {
$date = $in{'date'};
$input_mode = ' name="regist"';
} else {
$date = time();
}
if ($in{'subj'} eq '') {
$in{'subj'} = '無題';
}
if ($in{'url'} eq 'http://') {
$in{'url'} = '';
}
$preview_text = $in{'text'};
$in{'text'} =~ s/"/"/g;
$in{'text'} =~ s/
/\n/g;
if ($upload_mode == 1 && $in{'mode'} eq 'admin' && ($in{'file'} ne '' || $in{'orgfile'} ne '')) {
if ($in{'orgfile'} ne '') {
$in{'filename'} = $in{'orgfile'};
}
$in{'filename'} =~ /([^\/\\]*)\.([^.\/\\]*)$/;
$ext = $2;
$ext =~ tr/A-Z/a-z/;
if ($in{'file'} ne '') {
open(FILE, ">$upfile_dir$temporary_file") || &error("テンポラリファイルが作成できません");
binmode(FILE);
print FILE $in{'file'};
close(FILE);
}
}
&header();
print <<"_HTML_";
プレビュー
_HTML_
$logs[0] = "XXX\t0\t$date\t$in{'name'}\t$in{'mail'}\t$in{'url'}\t$in{'subj'}\t$preview_text\t$in{'color'}\t$in{'icon'}\t$in{'file'}\t\t$in{'pwd'}\t$host\n";
&showlog(@logs);
print <<"_HTML_";
_HTML_
&footer();
}
### デコード
sub decode {
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
if ($ENV{'CONTENT_LENGTH'} > 150000) {
&error("投稿量が大きすぎます
現在の投稿量:$ENV{'CONTENT_LENGTH'} / 最大投稿量:150000");
}
$length = $ENV{'CONTENT_LENGTH'};
binmode(STDIN);
while ($length > 0) {
$length -= sysread(STDIN, $buffer, $length);
$alldata .= $buffer;
}
$in{'file_size'} = 0;
foreach $data (split(/\r\n/, $alldata)) {
if ($interval eq '') {
$interval = $data;
} else {
if ($data !~ /^$interval/i) {
if ($data =~ /^Content-Disposition: form-data; name="([^"]*)"/i && $key eq '') {
$key = $1;
if ($data =~ /filename="([^"]*)"/i) {
$in{'filename'} = $1;
}
} elsif ($data =~ /^Content-type: (\S+)/i) {
$in{'mimetype'} = $1;
} else {
$in{"$key"} .= "$data\r\n";
if ($key eq 'file') {
$in{'file_size'} += length($data);
}
}
} else {
$key = '';
}
}
}
} else {
foreach $data (split(/&/, $ENV{'QUERY_STRING'})) {
($key, $value) = split(/=/, $data);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack('C', hex($1))/eg;
$value =~ s/\t//g;
$in{"$key"} = $value;
}
}
while (($key, $value) = each(%in)) {
$value =~ s/^\r\n//;
$value =~ s/\r\n$//;
if ($key ne 'file') {
&jcode'convert(*value, 'sjis', '', 'z');
$value =~ s/&/&/g;
$value =~ s/</g;
$value =~ s/>/>/g;
$value =~ s/"/"/g;
}
if ($key eq 'del') {
foreach $del (split(/\r\n\r\n/, $value)) {
push(@delete, $del);
}
}
$in{"$key"} = $value;
}
$in{'page'} += 0;
$in{'record'} += 0;
return;
}
### HTMLヘッダ
sub header {
print <<"_HTML_";
Content-Type: text/html
$title
_HTML_
if ($upload_mode == 1 && $in{'mode'} eq 'admin' && $in{'form'} ne '') {
print <<"_HTML_";
_HTML_
}
print <<"_HTML_";
_HTML_
return;
}
### HTMLフッタ
sub footer {
print <<"_HTML_";
_HTML_
exit();
}
### エラー出力
sub error {
local($_) = @_;
if ($mobile == 1) {
print <<"_HTML_";
エラー:
$_