#!/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 ($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|
$title

\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 ($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|
$title

\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_ if ($frame_layout == 0) { print <<"_HTML_"; _HTML_ } else { print <<"_HTML_"; _HTML_ } print <<"_HTML_"; _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_"; _HTML_ foreach (0 .. 6) { $week = $week[$_]; 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||; } $i++; if ($i == 1 && $flag == 1) { $week_num++; } if ($i == 7) { print ''; $i = 0; } if ($flag == 1) { $day++; } } print <<"_HTML_";
$prev $head $next
\n|; if ($_ == 0) { print qq|$week\n|; } elsif ($_ == 6) { print qq|$week\n|; } else { print qq|$week\n|; } 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|
_HTML_ $prev = qq|<< 前の月\n|; $next = qq|次の月 >>\n|; print qq|\n|; print <<"_HTML_";
_HTML_ print qq|\n|; print qq|\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_";

_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|$file_byte byte|; } elsif ($img_align == 1) { $file_info = qq|
$file_byte byte
|; } else { $file_info = qq|$file_byte byte|; } 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|$icon|; } 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_"; _HTML_ } else { print <<"_HTML_"; _HTML_ } } print <<"_HTML_";
$subj $new $date

$icon $text  

$all_show_info $res
$partition□ $name $mail $url / $date $new

$icon $text  


_HTML_ if ($in{'mode'} ne 'search' && $in{'mode'} ne 'past' && $in{'date'} eq '' && $in{'year'} eq '' && $in{'month'} eq '' && $in{'no'} eq '') { print <<"_HTML_"; _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_ if ($icon_mode == 1) { print <<"_HTML_"; _HTML_ } if ($color_mode == 1) { print <<"_HTML_"; _HTML_ } print <<"_HTML_";
名前
Eメール
URL
本文
アイコン アイコン一覧
本文の色 _HTML_ foreach (@color) { if ($_ eq '') { next; } if ($cookie{'color'} eq $_) { print qq| / |; } else { print qq| / |; } } print <<"_HTML_";
削除キー
_HTML_ if ($show_preview == 0 || $in{'mode'} eq 'userdel') { print qq|\n|; } elsif ($show_preview == 1) { if ($cookie{'preview'} eq 'on') { print qq||; } else { print qq||; } print ' '; } else { print qq|\n|; } 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|\n|; if (($_ % 5) == 0) { print "\n"; } if ($_ == $icon_no) { foreach (1 .. (5 - ($_ % 5))) { print qq|\n|; } print "\n"; } } print <<"_HTML_";
$icon_name

$icon_name
-


_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_display != 0) { print qq|
|; if ($icon ne '') { print qq|$icon|; } print qq||; } print qq|$date   $subj $new
\n|; if ($icon_display != 0) { print qq|
\n|; } print '

'; 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|
\n|; &footer(); } ### ログ検索 sub search { &header(); print <<"_HTML_";

ログ検索

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

_HTML_ if ($make_past == 1) { print <<"_HTML_"; _HTML_ } print <<"_HTML_"; _HTML_ print <<"_HTML_";
キーワード:
検索条件:
検索対象:
_HTML_ if ($in{'string'} eq 'dis') { print qq|\n|; } else { print qq|\n|; } 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|

\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_ if ($edit_mode == 1) { print qq|\n|; } print <<"_HTML_";

スレッド数 $parent件 / $work_mesg

_HTML_ if ($edit_mode == 1) { print <<"_HTML_"; _HTML_ } print <<"_HTML_"; _HTML_ $start = $in{'page'} * $page_size; $end = $start + $page_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 ($i <= $start) { next; } if ($i > $end) { last; } if ($reno == 0) { $name = '管理者'; $subj = "$subj"; } $text =~ s/
//gi; $text =~ s//>/g; if (length($text) > 60) { $text = substr($text, 0, 60) . ' …'; } if ($reno == 0) { print <<"_HTML_"; _HTML_ } else { print <<"_HTML_"; _HTML_ } if ($edit_mode == 1) { if ($reno == 0) { print <<"_HTML_"; _HTML_ } else { print <<"_HTML_"; _HTML_ } } print <<"_HTML_"; _HTML_ } print <<"_HTML_";
削除修正No 投稿者 題名 本文
-
-$no $name $subj $text


_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_display != 0) { print qq|
|; if ($icon ne '') { print qq|$icon|; } print qq||; } print qq|$date   $subj
\n|; 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_ if ($icon_mode == 1) { print <<"_HTML_"; _HTML_ } if ($color_mode == 1) { print <<"_HTML_"; _HTML_ } if ($upload_mode == 1) { print <<"_HTML_"; _HTML_ } print <<"_HTML_"; _HTML_ if ($file ne '') { print <<"_HTML_"; _HTML_ } print <<"_HTML_";
題名
日付 _HTML_ if ($year_mode == 1) { print qq|\n|; } else { print qq|\n|; } print qq|\n|; print qq|\n|; print <<"_HTML_";
アイコン アイコン一覧
本文の色 _HTML_ foreach (@color) { if ($_ eq '') { next; } if ($cookie{'color'} eq $_) { print qq| / |; } else { print qq| / |; } } print <<"_HTML_";
ファイル
本文
 
_HTML_ if ($show_preview == 0 || $in{'modify'} ne '') { print qq|\n|; } elsif ($show_preview == 1) { if ($cookie{'preview'} eq 'on') { print qq||; } else { print qq||; } print ' '; } else { print qq|\n|; } 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_ if ($make_past == 1 && $parent > $past_size) { print qq|\n|; } if ($make_past == 1 && $past_byte > 0) { print qq|\n|; } print <<"_HTML_";

ログサイズ $log_byteKB / _HTML_ if ($make_past == 1) { print qq|過去ログサイズ $past_byteKB / \n|; } print <<"_HTML_"; 投稿数 $parent件 / $work_mesg
_HTML_ if ($mini_counter != 0) { printf("総アクセス %0${count_figure}d / 今日 %0${count_figure}d / 昨日 %0${count_figure}d
", $sum, $today, $yesterday); } print <<"_HTML_";
_HTML_ if ($res_mode == 1) { print <<"_HTML_"; _HTML_ } print <<"_HTML_"; _HTML_ if ($upload_mode == 1) { print <<"_HTML_"; _HTML_ } if ($res_mode == 1) { print <<"_HTML_"; _HTML_ } print <<"_HTML_"; _HTML_ $start = $in{'page'} * $page_size; $end = $start + $page_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 ($i <= $start) { next; } if ($i > $end) { last; } if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) { $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)", $year + 1900, $mon + 1, $day, $week[$week]); } if ($reno == 0) { $name = '管理者'; $modi = qq||; } else { $modi = '-'; } $text =~ s/
//gi; $text =~ s//>/g; if (length($text) > 60) { $text = substr($text, 0, 60) . ' …'; } if ($file eq '') { $file = '-'; } else { $file = qq|$file|; } chop($host); print <<"_HTML_"; _HTML_ if ($res_mode == 1) { print <<"_HTML_"; _HTML_ } print <<"_HTML_"; _HTML_ if ($upload_mode == 1) { print <<"_HTML_"; _HTML_ } if ($res_mode == 1) { print <<"_HTML_"; _HTML_ } print <<"_HTML_"; _HTML_ } print <<"_HTML_";
削除 修正 No 日付投稿者題名 本文ファイルホスト
$modi $no $date$name$subj $text$file$host


_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; } 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_";

エラー:
$_

_HTML_ exit(); } &header(); print <<"_HTML_";




エラーが発生しました

$_



_HTML_ &footer(); } ### モバイル表示 sub mobile { $agent = $ENV{'HTTP_USER_AGENT'}; if ($agent !~ /DoCoMo/i && $agent !~ /J-PHONE/i && $agent !~ /UP\.Browser/i) { return; } else { $mobile = 1; } print <<"_HTML_"; Content-Type: text/html $title _HTML_ if ($ENV{'REQUEST_METHOD'} eq 'POST') { if ($ENV{'CONTENT_LENGTH'} > 15000) { &error("投稿量が大きすぎます
現在の投稿量:$ENV{'CONTENT_LENGTH'} / 最大投稿量:15000"); } read(STDIN, $alldata, $ENV{'CONTENT_LENGTH'}); } else { $alldata = $ENV{'QUERY_STRING'}; } foreach $data (split(/&/, $alldata)) { ($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; &jcode'convert(*value, 'sjis', '', 'z'); $value =~ s/&/&/g; $value =~ s//>/g; $value =~ s/"/"/g; if ($key eq 'del') { push(@delete, $value); } $in{"$key"} = $value; } $in{'page'} += 0; if ($in{'mode'} eq 'regist') { if ($in{'adminpwd'} ne $admin_pwd) { &error("パスワードが違います"); } $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{'subj'} eq '') { &error("題名が入力されていません"); } if ($in{'date'} !~ /^\d\d\d\d\d\d\d\d$/) { &error("日付の値が不正です"); } if ($in{'text'} eq '') { &error("本文が入力されていません"); } &lock($lock_file); open(FILE, "$log_file") || &error("ログファイルを読み出せません"); @logs = ; close(FILE); $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("すでに書き込まれています"); } $line = "$no\t0\t$in{'date'}\t\t\t\t$in{'subj'}\t$in{'text'}\t\t\t\t\t$host\n"; if ($make_past == 0 && $parent >= $max_log) { foreach (0 .. ($parent - $max_log)) { ($no, $reno) = split(/\t/, $logs[$#logs]); if ($reno == 0) { pop(@logs); } else { while ((split(/\t/, $logs[$#logs]))[1] != 0) { pop(@logs) } pop(@logs); } } } @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; open(FILE, ">$log_file") || &error("ログファイルに書き込めません"); print FILE @logs; close(FILE); if ($js_mode != 0) { &output_jsfile(@logs); } &unlock($lock_file); $in{'mode'} = ''; } elsif ($in{'mode'} eq 'responce') { ®ist(); } open(FILE, "$log_file") || &error("ログファイルを読み出せません"); @logs = ; close(FILE); $parent = 0; foreach (@logs) { if ((split(/\t/))[1] == 0) { $parent++; } } if ($in{'mode'} eq 'form') { if ($agent =~ /DoCoMo/i) { $method = 'post'; } else { $method = 'get'; } if ($in{'adminpwd'} eq '') { print <<"_HTML_";

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


戻る

_HTML_ } else { if ($in{'adminpwd'} ne $admin_pwd) { &error("パスワードが違います"); } ($sec, $min, $hour, $day, $mon, $year, $week) = localtime(time()); $date = sprintf("%04d%02d%02d", $year + 1900, $mon + 1, $day); print <<"_HTML_";

■ 情報投稿


題名

日付

本文


戻る

_HTML_ } } elsif ($in{'mode'} eq 'res') { if ($agent =~ /DoCoMo/i) { $method = 'post'; } else { $method = 'get'; } foreach (@logs) { ($no, $reno, $date, $name, $mail, $url, $subj) = split(/\t/); if ($in{'no'} == $no) { $subj = 'Re:' . $subj; last; } } print <<"_HTML_";

■ 記事投稿


名前

Eメール

URL

本文

削除キー


戻る

_HTML_ } elsif ($in{'mode'} eq 'delete') { if ($in{'del'} ne '') { 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) { if ($in{'user_pwd'} ne $admin_pwd) { &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]"; } } if ($del_list eq '') { &error("該当記事がありません"); } $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 ($agent =~ /DoCoMo/i) { $method = 'post'; } else { $method = 'get'; } print <<"_HTML_";

■ 記事削除


$work_mesg
削除する記事の番号

削除キー


戻る

_HTML_ } elsif ($in{'mode'} eq 'all') { print '

■ 投稿表示
'; foreach (@logs) { ($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $rank, $pwd, $host) = split(/\t/); if ($in{'no'} != $no && $in{'no'} != $reno) { next; } &jcode'convert(*subj, 'sjis', '', 'h'); &jcode'convert(*text, 'sjis', '', 'h'); 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)|; } else { ($sec, $min, $hour, $day, $mon, $year, $week) = localtime($date); $date = sprintf("%02d月%02d日%02d:%02d", $mon + 1, $day, $hour, $min); } if ($mail ne '') { $mail = qq|Eメール|; } if ($url ne '') { $url = qq|URL|; } if ($auto_link == 1) { $text = &auto_link($text); } if ($file ne '' && -e "$upfile_dir$file") { $file = qq|ファイル|; } if ($res_mode == 1 && $logs[0] + 0 != 0) { $res = qq|返信する
|; } chop($host); if ($reno == 0) { print <<"_HTML_";


[$no] $subj $file

$text

$date
_HTML_ } else { print <<"_HTML_";
[$no] $subj

$name $mail $url $file

$text

$date
_HTML_ } } print <<"_HTML_";
$res

戻る

_HTML_ } else { print '

'; $start = $in{'page'} * $page_size; $end = $start + $page_size; $i = 0; foreach (@logs) { ($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $rank, $pwd, $host) = split(/\t/); if ($reno == 0) { $i++; } else { next; } if ($i <= $start) { next; } if ($i > $end) { last; } &jcode'convert(*subj, 'sjis', '', 'h'); if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) { $year = sprintf("%04d", $1); $month = sprintf("%02d", $2); $day = sprintf("%02d", $3); $week = $week[&getweek($day, $year, $month)]; $date = qq|$month月$day日($week)|; } chop($host); print qq|■ $subj - $date
\n|; } print '
'; if ($in{'page'} > 0) { $n = $in{'page'} - 1; print qq|前のページ
\n|; } if (int(($parent - 1) / $page_size) > $in{'page'}) { $n = $in{'page'} + 1; print qq|次のページ
\n|; } print <<"_HTML_";

情報投稿
記事削除

戻る

_HTML_ } print <<"_HTML_";
_HTML_ exit(); } ### ミニアクセスカウンタカウントアップ sub count_up { if ($no_count_list[0] 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; } else { $host = $addr; } } $flag = 0; foreach $list (@no_count_list) { if ($list ne '' && $host =~ /$list/i) { $flag = 1; last; } } if ($flag == 1) { return; } } &lock($lock_file); open(COUNT, "$count_log") || &error("カウントログファイルを読み出せません"); $data = ; close(COUNT); local($sum, $today, $yesterday, $key) = split(/\t/, $data); local($sec, $min, $hour, $day) = localtime(time()); if ($key == $day) { $today++; } else { $yesterday = $today; $today = 1; } $sum++; $data = "$sum\t$today\t$yesterday\t$day"; open(COUNT, ">$count_log") || &error("カウントログファイルに書き込めません"); print COUNT $data; close(COUNT); &unlock($lock_file); return; } ### JSファイル出力 sub output_jsfile { local(@logs) = @_; if ($js_mode == 1 || $js_mode == 3) { @js_logs = (); $i = 0; foreach (@logs) { ($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/); if ($reno != 0) { next; } if ($i >= $js_output_text) { last; } if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) { $date = "$1/$2/$3"; } $subj =~ s/\'/\\\'/g; $text =~ s/\'/\\\'/g; $line = qq|document.write('■ $subj ... $date

$text
');\n|; push(@js_logs, $line); $i++; } $line = qq|document.write('');\n|; push(@js_logs, $line); open(FILE, ">$js_text_file") || &error("JSファイルに書き込めません"); print FILE @js_logs; close(FILE); } if ($js_mode == 2 || $js_mode == 3) { @js_logs = (); $i = 0; foreach (@logs) { ($no, $reno, $date, $name, $mail, $url, $subj, $text, $color, $icon, $file, $pwd, $host) = split(/\t/); if ($reno != 0) { next; } if ($i >= $js_output_title) { last; } if ($date =~ /^(\d\d\d\d)(\d\d)(\d\d)$/) { $date = "$1/$2/$3"; } if ($js_title_url ne '') { $subj = qq|$subj|; } $subj =~ s/\'/\\\'/g; $text =~ s/\'/\\\'/g; $line = qq|document.write('$date ... $subj
');\n|; push(@js_logs, $line); $i++; } open(FILE, ">$js_title_file") || &error("JSファイルに書き込めません"); print FILE @js_logs; close(FILE); } return; } ### INPUT情報正規化 sub create_line { local($_) = @_; $_ =~ s/^\s+//; $_ =~ s/\s+$//; return $_; } ### TEXTAREA情報正規化 sub create_text { local($_) = @_; $_ =~ s/\r?\n/\r/g; $_ =~ s/^\r+//; $_ =~ s/\r+$//; $_ =~ s/\r/
/g; return $_; } ### オートリンク sub auto_link { local($_) = @_; $_ =~ s/(https?:\/\/[\w\.\~\-\/\?\&\#\+\=\:\;\@\%]+)/$1<\/a>/gi; $_ =~ s/([\w\-]+\@[\w\-\.]+)/$1<\/a>/gi; return $_; } ### コンマの付加 sub comma { local($_) = @_; while ($_ =~ s/^([-+]?\d+)(\d\d\d)/$1,$2/) {} return $_; } ### 削除キー暗号化 sub encrypt { local($_) = @_; srand(time + $$); local $salt = pack('CC', int(rand(26) + 65), int(rand(10) + 48)); return crypt($_, $salt); } ### 削除キー照合 sub decrypt { local($inpwd, $pwd) = @_; if ($pwd eq '') { &error("該当記事には削除キーが設定されていません"); } if (crypt($inpwd, $pwd) ne $pwd) { &error("削除キーが違います"); } return; } ### 曜日を取得 sub getweek { local($day, $year, $month) = @_; if ($month == 1 || $month == 2) { $year--; $month += 12; } return int($year + int($year / 4) - int($year / 100) + int($year / 400) + int ((13 * $month + 8) / 5) + $day) % 7; } ### ファイルアップロード sub upfile { local($file, $filename, $no) = @_; $filename =~ /([^\/\\]*)\.([^.\/\\]*)$/; $ext = $2; $ext =~ tr/A-Z/a-z/; open(FILE, ">$upfile_dir$no.$ext") || &error("アップロードファイルが保存できません"); binmode(FILE); print FILE $file; close(FILE); return "$no.$ext"; } ### ログ移動処理 sub move_log { local(*logs, *past, $size) = @_; if ($size ne 're') { foreach (1 .. $size) { while ((split(/\t/, $logs[$#logs]))[1] != 0) { unshift(@past, pop(@logs)); } unshift(@past, pop(@logs)); } } else { foreach (@past) { push(@logs, $_); } } return (*logs, *past); } ### ファイルロック sub lock { local($lock_file) = @_; local $flag = 0; foreach (1 .. 5) { if (-e $lock_file) { if (time() > (stat($lock_file))[9] + 60) { &unlock($lock_file); next; } sleep(1); } else { open(LOCK, ">$lock_file") || &error("ロックファイルが作成できません"); close(LOCK); $flag = 1; last; } } if ($flag == 0) { &error("ファイルがロックされています
時間をおいてもう一度投稿してください"); } return; } ### ファイルロック解除 sub unlock { local($_) = @_; unlink($_); return; } ### GIF,JPEG,PNGサイズ取得(参考:WWWimagesize ... http://www.bloodyeck.com/wwwis/) sub gifsize{ local($GIF) = @_; local($type, $a, $b, $c, $d, $s) = (0, 0, 0, 0, 0, 0); if (defined($GIF) && read($GIF, $type, 6) && $type =~ /GIF8[7,9]a/ && read($GIF, $s, 4) == 4) { ($a, $b, $c, $d) = unpack("C"x4, $s); return ($b << 8 | $a, $d << 8 | $c); } return (0, 0); } sub jpegsize { local($JPEG) = @_; local($done) = 0; local($c1, $c2, $ch, $s, $length, $dummy) = (0, 0, 0, 0, 0, 0); local($a, $b, $c, $d); if (defined($JPEG) && read($JPEG, $c1, 1) && read($JPEG, $c2, 1) && ord($c1) == 0xFF && ord($c2) == 0xD8) { while (ord($ch) != 0xDA && !$done) { while (ord($ch) != 0xFF) { return(0, 0) unless read($JPEG, $ch, 1); } while (ord($ch) == 0xFF) { return(0, 0) unless read($JPEG, $ch, 1); } if ((ord($ch) >= 0xC0) && (ord($ch) <= 0xC3)) { return(0, 0) unless read($JPEG, $dummy, 3); return(0, 0) unless read($JPEG, $s, 4); ($a, $b, $c, $d) = unpack("C"x4, $s); return ($c << 8 | $d, $a << 8 | $b); } else { return(0, 0) unless read ($JPEG, $s, 2); ($c1, $c2) = unpack("C"x2, $s); $length = $c1 << 8 | $c2; last if (!defined($length) || $length < 2); read($JPEG, $dummy, $length - 2); } } } return (0, 0); } sub pngsize { local($PNG) = @_; local($head) = ""; local($a, $b, $c, $d, $e, $f, $g, $h) = 0; if (defined($PNG) && read($PNG, $head, 8) == 8 && $head eq "\x89\x50\x4e\x47\x0d\x0a\x1a\x0a" && read($PNG, $head, 4) == 4 && read($PNG, $head, 4) == 4 && $head eq "IHDR" && read($PNG, $head, 8) == 8){ ($a, $b, $c, $d, $e, $f, $g, $h) = unpack("C"x8, $head); return ($a << 24 | $b << 16 | $c << 8 | $d, $e << 24 | $f << 16 | $g << 8 | $h); } return (0, 0); } ### クッキー関連の処理 sub get_cookie { local($cookie_id) = @_; local %all_cookies = (); foreach (split(/; /, $ENV{'HTTP_COOKIE'})) { local($key, $value) = split(/=/); $all_cookies{"$key"} = $value; } foreach (split(/&/, $all_cookies{"$cookie_id"})) { local ($key, $value) = split(/:/); $value =~ s/&/&/g; $value =~ s//>/g; $value =~ s/"/"/g; $cookie{&unescape($key)} = &unescape($value); } return %cookie; } sub set_cookie { local(*cookie, $cookie_id, $hold_days) = @_; if (time() > $cookie{'refresh'} + 60 * 60 * 24 * 30) { $cookie{'refresh'} = time(); } local @pairs = (); foreach (sort keys %cookie) { push(@pairs, &escape($_) . ':' . &escape($cookie{"$_"})); } local $new_cookie = join('&', @pairs); local $date = &gmt_date(time + 60 * 60 * 24 * $hold_days); if ($new_cookie ne $all_cookies{"$cookie_id"}) { print "Set-Cookie: $cookie_id=$new_cookie; expires=$date\n"; } return; } sub escape { local($_) = @_; $_ =~ s/([&:;=%\x00-\x21])/sprintf("%%%02X", unpack('C',$1))/ge; return $_; } sub unescape { local($_) = @_; $_ =~ s/%([0-9A-Fa-f][0-9A-Fa-f])/pack('C', hex($1))/ge; return $_; } sub gmt_date { local($_) = @_; local($sec, $min, $hour, $day, $mon, $year, $wday) = gmtime($_); local @week = ('Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'); local @month = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); return sprintf("%s, %02d %s %04d %02d:%02d:%02d GMT", $week[$wday], $day, $month[$mon], $year + 1900, $hour, $min, $sec); }