#!/usr/local/bin/perl #====================================================== # a-Nikki v1.06 (2001/03/08) # a-Nikki v1.05 (2001/03/08) # a-Nikki v1.04 (2001/01/19) # a-Nikki v1.03 (2001/01/07) # a-Nikki v1.02 (2000/12/10) # a-Nikki v1.01 (2000/12/07) # a-Nikki v1.00 (2000/10/28) #------------------------------------------------------ # HomePage : http://www.appleple.com/ # E-Mail : Kazumich@appleple.com #====================================================== $version = "1.06"; $site_url= "http://www.appleple.com/cgi/"; $email = 'kazumich@appleple.com'; require './jcode.pl'; #設定ファイル読み込み require './setup.cgi'; use Time::Local; @days = (31,28,31,30,31,30,31,31,30,31,30,31); $err_sw = 0; $upinfo_file = "upinfo.dat"; if ($kaizo eq 1) { $kaizo = "+"; } else { $kaizo = ""; } if (@yobi_array2 eq 0) { @yobi_array2 = @yobi_array; } if ($ya_prev eq "") { $ya_prev = "←"; $ya_next = "→"; } #--------------------------------------------------------------- #今日の日付を取得 $now_time = time; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($now_time); $now_year = ($year + 1900); $now_month = sprintf("%02d",$mon + 1); $now_day = sprintf("%02d",$mday); #バッファ初期処理 if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; } @pairs = split(/&/,$buffer); foreach $pair (@pairs) { ($name,$value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; &jcode'convert(*value,'sjis'); #' if ($cr_sw eq 0) { $value =~ s/\n//g; } else { $value =~ s/\n/
/g; } $value =~ s/\r//g; $value =~ s/\t//g; $FORM{$name} = $value; } if ($FORM{'date'} eq "") { $FORM{'date'} = "$now_year.$now_month.$now_day"; } ($f_year,$f_month,$f_day) = split(/\./,$FORM{'date'}); # パスワードチェック $admin_ok = &pass_check($FORM{'pass'}); #----- テンプレート表示前振分処理 ----- if ($admin_ok eq 1) { if ($FORM{'action'} eq "regist") { ®ist; } if ($FORM{'action'} eq "update2") { &update2; } if ($FORM{'action'} eq "add2") { &add2; } if ($FORM{'action'} eq "Delete") { &delete; } } #----- テンプレートファイル読み込み ----- open(TEMPFILE, $template_file) || &error('ファイル読込エラー', 'テンプレートファイルが開けません。'); @TEMPLATE = ; close(TEMPFILE); #----- 先月、来月の設定 ----- $prev_year = $f_year; $prev_month = sprintf("%02d",$f_month - 1); if ($prev_month eq "00") { $prev_year = $prev_year - 1; $prev_month = 12; } $last_day = mday($prev_month,$prev_year); $prev_date = sprintf("%04d.%02d.%02d",$prev_year,$prev_month,$last_day); $next_year = $f_year; $next_month = sprintf("%02d",$f_month + 1); if ($next_month eq "13") { $next_year = $next_year + 1; $next_month = 1; } $last_day = mday($next_month,$next_year); $next_date = sprintf("%04d.%02d.%02d",$next_year,$next_month,$last_day); #----- 処理月のファイル名を取得 ----- $dir = "$site_path/$f_year/$f_month"; if (-e $dir) { if ($not_glob eq 1) { ¬_glob; } else { @files = glob("$dir/*.html"); } @files = sort { $b cmp $a} @files; $hit = 0; $start = 0; @stat = stat $files[0]; foreach $data (@files) { if ( $data =~ /(.*)\/(.*)\/(.*)\/(.*).html/ ) { $c_year = $2; $c_month = $3; $c_day = $4; if ($f_day >= $c_day) { last; } $start = $start + 1; } } &extract_file; } #----- 先月のファイル名を取得 ----- $dir = "$site_path/$prev_year/$prev_month"; if (-e $dir) { if ($hit ne $page) { $prev_month = sprintf("%02d",$prev_month); @files = glob("$dir/*.html"); if ($not_glob eq 1) { ¬_glob; } else { @files = glob("$dir/*.html"); } @files = sort { $b cmp $a} @files; $start = 0; &extract_file; } } #---- 画面表示 ------ if ($FORM{'cal'} eq "out") { &calender2; exit; } $err_sw = 1; print "Content-type: text/html\n\n"; if ($template_mode eq 0) { foreach $line (@TEMPLATE) { &updatetime_print; if ($line =~ //i) { ($mae_print,$ato_print) = split(//,$line); print $mae_print; if ($FORM{'action'} eq "Update") { &update; } elsif ($FORM{'action'} eq "new") { &new; } else { &diary; } print $ato_print; } elsif ($line =~ //i) { ($mae_print,$ato_print) = split(//,$line); print $mae_print; if ($calender_sw eq 1) { &calender; } else { &calender_open; } print $ato_print; } elsif ($line =~ //i) { ($mae_print,$ato_print) = split(//,$line); print $mae_print; if ($calender_sw eq 1) { print "\n"; } else { print "\n"; } print $ato_print; } else { print $line; } } } else { $clear_sw = 0; foreach $line (@TEMPLATE) { &updatetime_print; if ($line =~ /$start_tag/i) { ($mae_print,$ato_print) = split(/$start_tag/,$line); print $mae_print; if ($FORM{'action'} eq "Update") { &update; } elsif ($FORM{'action'} eq "new") { &new; } else { &diary; } $clear_sw = 1; if ($ato_print =~ /$end_tag/i) { ($mae_print2,$ato_print2) = split(/$end_tag/,$ato_print); print $ato_print2; $clear_sw = 0; } } elsif ($line =~ /$end_tag/i) { if ($clear_sw eq 1) { ($mae_print,$ato_print) = split(/$end_tag/,$line); print $ato_print; $clear_sw = 0; } else { print $line; } } elsif ($clear_sw eq 1) { next; } elsif ($line =~ //i) { ($mae_print,$ato_print) = split(//,$line); print $mae_print; if ($calender_sw eq 1) { &calender; } elsif ($calender_sw eq 2) { &calender_open; } print $ato_print; } elsif ($line =~ //i) { ($mae_print,$ato_print) = split(//,$line); print $mae_print; if ($calender_sw eq 1) { print "\n"; } else { print "\n"; } print $ato_print; } else { print $line; } } } exit; #----- 必要なファイルを抽出する ----- sub extract_file { foreach $num ($start .. $#files) { if ($hit eq $page) { last; } else { push(@files2,$files[$num]); $hit++; } } } #----- 必要なファイルを抽出する ----- sub not_glob { opendir (DIR,"$dir") || &error('ファイル読込エラー', 'ディレクトリが開けません。'); foreach $data (readdir(DIR)){ if ($data =~ /.*\.html/){ push(@files,"$dir/$data"); } } closedir(DIR); } #----- メイン日記表示処理 ----- sub diary { if ( $files2[0] =~ /(.*)\/(.*)\/(.*)\/(.*).html/ ) { $first_date = "$2.$3.$4"; } print "

\n"; if ($pass_ichi eq 1) { print <<"EOF";
EOF } if ($admin_ok eq 1) { print <<"EOF";

EOF } foreach (@files2) { if ( $_ =~ /(.*)\/(.*)\/(.*)\/(.*).html/ ) { $f_year = $2; $f_month = $3; $f_day = $4; $date = "$f_year.$f_month.$f_day"; } if ($yobi_sw ne 1) { $print_date = $date; $update_date = sprintf("%04d.%02d.%02d",$f_year,$f_month,$f_day); } else { $date2 = &timelocal(0,0,0,$f_day,$f_month - 1,$f_year); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($date2); $print_date = sprintf("%04d/%02d/%02d (%s)",$year+1900,$mon+1,$mday,$yobi_array[$wday]); $update_date = sprintf("%04d.%02d.%02d",$year+1900,$mon+1,$mday); } if ($wday eq 0) { $date_class = "date0"; } elsif ($wday eq 6) { $date_class = "date6"; } else { $date_class = "date"; } if ($admin_ok eq 1) { if ($form_ichi eq 1) { if ($FORM{'action'} eq "Add") { &add; } } } print "
\n"; print "

$print_date

"; if (!open(IN,"$_")) { &error('データ読取エラー','復旧をお待ちください.'); } @BASE = ; close(IN); foreach (@BASE) { if ($maru_sw eq 1) {$_ =~ s/

/

$maru<\/span>/g; } print "$_\n"; } if ($admin_ok eq 1) { print "

 
\n"; } if ($hr_size ne 0) { print "
\n"; } print "
\n"; if ($admin_ok eq 1) { if ($FORM{'action'} eq "Add") { if ($form_ichi eq 1) { last; } else { &add; last; } } } } if ($notold_sw ne '1') { if ($hit eq $page) { $n_day = sprintf("%02d",$f_day - 1); if ($n_day <= 0) { $n_month = $f_month - 1; if ($n_month <= 0) { $n_year = $f_year - 1; $n_month = "12"; } else { $n_month = sprintf("%02d",$n_month); } $n_day = mday($prev_month,$prev_year); } else { $n_year = $f_year; $n_month = $f_month; } $btn_name = " 次の$page件の$nikkiへ "; } else { $n_month = $f_month - 1; if ($n_month <= 0) { $n_year = $f_year - 1; $n_month = "12"; } else { $n_year = $f_year; $n_month = sprintf("%02d",$n_month); } $n_day = mday($n_month,$n_year); $btn_name = "  $n_year年$n_month月の$nikkiへ "; } print <<"EOF";
EOF } print "
\n"; if ($pass_ichi eq 0) { print <<"EOF";
EOF } # 著作権表示(以下の5行は削除不可です) print <<"EOF";
a-Nikki$kaizo $version
EOF } sub regist { if ($f_day eq "") { &error("入力チェックエラー","日の入力がありません。"); } if ($FORM{'diary'} eq "" && $FORM{'title'} eq "") { &error("入力チェックエラー","題名と内容が書かれていません。"); } $check_date = "$f_year.$f_month.$f_day"; if (!($check_date =~ /^[0-9]{4}\.[0-9][0-9]\.[0-9][0-9]$/)) { &error("入力チェックエラー","日付の入力が正しくありません。"); } #年ディレクトリチェックと作成 $dirpath = "$site_path/$f_year"; unless(-e $dirpath){ mkdir($dirpath, 0755); } $cnt_chmod = chmod(0777, $dirpath); #月ディレクトリチェックと作成 $dirpath = "$site_path/$f_year/$f_month"; unless(-e $dirpath){ mkdir($dirpath, 0755); } $cnt_chmod = chmod(0777, $dirpath); #新規HTMLファイル作成 $diary_file = "$site_path/$f_year/$f_month/$f_day.html"; if (-e $diary_file) { &error('データ書き込みエラー',"$f_year/$f_month/$f_dayの$nikkiは既にありますよ。"); } $diary_title = "

$FORM{'title'}

\n"; open (OUT,">$diary_file"); print OUT $diary_title; $diary_data = "

$FORM{'diary'}

\n"; print OUT $diary_data; close(OUT); $ret = chmod(0666, "$diary_file"); #更新日時の更新 &upinfo_update; } sub update { $update_file = "$site_path/$f_year/$f_month/$f_day.html"; if (!open(IN,"$update_file")) { &error('データ読取エラー','復旧をお待ちください.'); } @BASE = ; close(IN); foreach (@BASE) { $_ =~ s/

//g; $_ =~ s/

//g; $_ =~ s/<\/p>//g; $_ =~ s/\n//g; if ($cr_sw eq 1) { $_ =~ s/
/\n/g; } if ($_ eq "") { next; } else { push(@DATA,$_); } } $BASE[0] =~ s/

//g; $BASE[0] =~ s/

//g; print <<"EOF";

EOF foreach $num (1 .. $#DATA) { print <<"EOF"; EOF } print <<"EOF";
日付 $f_year/$f_month/$f_day
題名
内容

内容欄を空欄にすると削除できます。

 
EOF } sub update2 { $diary_file = "$site_path/$f_year/$f_month/$f_day.html"; $diary_title = "

$FORM{'title'}

\n"; open (OUT,">$diary_file"); print OUT $diary_title; $i = 0; while ($i < $FORM{'count'} + 1) { $diary = $FORM{"diary$i"}; if ($diary) { $diary_data = "

$diary

\n"; print OUT $diary_data; } $i = $i + 1; } close(OUT); #更新日時の更新 &upinfo_update; } sub add { &tag_editor; print <<"EOF";

 


EOF } sub tag_editor { print <<"EOF";

簡易タグエディタ:URL挿入Bold挿入
EOF } sub add2 { if ($FORM{'diary'} eq "" && $FORM{'title'} eq "") { &error("入力チェックエラー","題名と内容が書かれていません。"); } $diary_file = "$site_path/$f_year/$f_month/$f_day.html"; if (!open(IN,"$diary_file")) { &error('データ読取エラー','復旧をお待ちください.'); } @BASE = ; close(IN); $diary_data = "

$FORM{'diary'}

\n"; open (OUT,">$diary_file"); print OUT $BASE[0]; if ($add_ichi eq 1) { print OUT $diary_data; } foreach $num (1 .. $#BASE) { print OUT $BASE[$num]; } if ($add_ichi eq 0) { print OUT $diary_data; } close(OUT); #更新日時の更新 &upinfo_update; } sub delete { $diary_file = "$site_path/$f_year/$f_month/$f_day.html"; $del = unlink $diary_file; #更新日時の更新 &upinfo_update; } sub new { $update_file = "$f_year/$f_month/$f_day.html"; &tag_editor; print <<"EOF";
日付
題名
内容

 


要望・バグ情報・感想等 メールをお待ちしております。
EOF } #------------------------------------------------------------ # カレンダー処理 #------------------------------------------------------------ sub calender{ $loop_day = mday($f_month,$f_year); $first_day = &timelocal(0,0,0,1,$f_month - 1,$f_year); $month_2 = (localtime($first_day))[6]; $p_mon = sprintf("%02d",$p_mon); #---( ヘッダ部分の表示 )--- print <<"EOF"; EOF #---( 先月分の空白の表示 )--- $i = 0; while ($i < $month_2) { print "\n"; ++$i; } $i = 1; $j = $month_2 + 1; #---( 日数分のループ処理 )--- while ($i <= $loop_day) { if ($zero_cut eq 1) { $p_day = $i; } else { $p_day = sprintf("%02d",$i); } $check_day = sprintf("%02d",$i); $check_file = "$site_path/$f_year/$f_month/$check_day.html"; if (-e $check_file) { if ($FORM{'cal'} eq "out") { print "\n"; } else { print "\n"; } } else { print "\n"; } if ($j >6) { if ($i ne $loop_day) { print "\n"; $j = 0; } } ++$i; ++$j; } #---( 来月分の空白の表示 )--- if ($j ne 1) { while ($j < 8) { print "\n"; ++$j; } } print "
$ya_prev $f_year/$f_month $ya_next
$yobi_array2[0] $yobi_array2[1]$yobi_array2[2]$yobi_array2[3]$yobi_array2[4]$yobi_array2[5] $yobi_array2[6]
 $p_day$p_day$p_day
 
\n"; } #----- ある年月の末日チェック処理 sub mday ($;$) { my ($month,$year) = @_; if ($month < 1 || $month >12 ) { $month = (localtime)[4] + 1} if ($year == 0) { $year = 1900 + (localtime)[5]} if ($month == 2 && leapyear($year)) { return 29; } else { return $days[$month -1]; } } sub leapyear ($) { my $year = shift; return ((($year % 4 == 0) && ($year % 100 != 0) || ($year % 400 == 0)) ? 1 : ''); } sub calender_open { print <<"EOF"; $print_calendar EOF } sub calender2 { print "Content-type: text/html\n\n"; print <<"EOF"; Calender
EOF &calender; print "\n"; } sub error { if ($err_sw eq 0) { print "Content-type: text/html\n\n"; } print "error\n"; print "
\n"; print "

$_[0]

\n"; print "

$_[1]

\n"; print "

ブラウザの戻るボタンで前の画面に戻って下さい。

"; print "

\n"; print "\n"; exit; } sub pass_check ($) { if ($crypt_sw eq 1) { $pass_check = shift; $crypted = crypt ( $pass_check , $pass_check ); } else { $crypted = shift; } if ($passwd eq $crypted) { return 1; } else { return 0; } } sub updatetime_print { $dir_file = "$site_path/$upinfo_file"; if (-e $dir_file) { open(IN,"$dir_file"); @UPFILE = ; close(IN); $check_time = $UPFILE[0]; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($check_time); $up_year = $year + 1900; $up_month = ($mon + 1); $up_day = $mday; $update_time = sprintf("%04d/%02d/%02d %02d:%02d:%02d",$up_year,$up_month,$up_day,$hour,$min,$sec); } else { $update_time = "????/??/?? ??:??:??"; } $line =~ s//$update_time/g; } sub upinfo_update { if ($update_day ne 0) { $dir_file = "$site_path/$upinfo_file"; if (-e $dir_file) { open (OUT,">$dir_file"); print OUT $now_time; close(OUT); } else { open (OUT,">$dir_file"); print OUT $now_time; close(OUT); $ret = chmod(0666, "$dir_file"); } } }