#!/usr/bin/perl #| My Diary Version 1.21.02c #| This script is free. #| #| Author Shigeto Nakazawa.(1998/08/14) #| E-Mail jawa@www.big.or.jp #| HomePageUrl http://www7.big.or.jp/~jawa/ #| #| Special Thanks あっぽー #| E-Mail caa95880@pop06.odn.ne.jp #| HomePageUrl http://appoh.system.to/ #| #| 中文化:哈泥蛙 #| E-Mail haniwa@bigfoot.com #| HomePageUrl http://www.haniwa.idv.tw/ #| #| 中文化作業包含了以下部分: #| 1.內文(含說明)中文化 #| 2.解除Jcode之編碼檢查 #| 3.加入連結自動偵測之功能 #| # ////////////////////////////////////////////////////////// # 以下為可變更的設定項目。 # 變更時可以參考readme.htm(但為日文格式)。 # 在變更設定時請務必小心。 # ////////////////////////////////////////////////////////// # ---------------------------------------------------------- # 日記管理者(就是你)的資料。 # ---------------------------------------------------------- $admin_name = '游牧巫師'; # 請寫入你的名字 $admin_email = 'joshuayip@hotmail.com'; # 你的Email $master = '12345'; # 管理用密碼設定 # ---------------------------------------------------------- # 本日記之個人設定項目。 # ---------------------------------------------------------- $diary_title = "游牧事記"; # 日記頁面標題(不可使用語法標籤) $body_text = '#000000'; # 標籤之設定 $body_link = '#0000FF'; $body_alink = '#0000DD'; $body_vlink = '#FF0000'; $body_bgcolor = '#FFFFFF'; $body_back = 'diaryback.gif'; $back_url = "http://applepig.idv.tw/NW/index.cgi"; # 主頁URL(建議使用絕對URL) $image_url = "http://applepig.idv.tw/NW/"; # 圖像所在URL(建議使用絕對URL) $title_color = '#0000FF'; # 日記標題之顏色 $title_bgcolor = '#FFEEEE'; # 日記標題之背景色 $title_brcolor = '#000000'; # 日記邊框顏色 $msg_bgcolor = '#FFFCFC'; # 日記內容之背景色 $date_color = '#FF0000'; # 日期之顏色 $youbi[0] = "日曜日"; # 星期之設定 $youbi[1] = "月曜日"; $youbi[2] = "火曜日"; $youbi[3] = "水曜日"; $youbi[4] = "木曜日"; $youbi[5] = "金曜日"; $youbi[6] = "土曜日"; # -------------------- # 天氣用圖像檔案 # 不變更的話就不用修改 $tenki_gif[0] = "hare.gif"; $tenki_name[0] = "晴天"; $tenki_gif[1] = "kumori.gif"; $tenki_name[1] = "陰天"; $tenki_gif[2] = "ame.gif"; $tenki_name[2] = "雨天"; $tenki_gif[3] = "taifu.gif"; $tenki_name[3] = "颱風"; $tenki_gif[4] = "yuki.gif"; $tenki_name[4] = "下雪"; $html_layout = 0; # HTML輸出格式變更 (0 - 1) $page_layout = 0; # PAGE輸出格式變更 (0 - 1) $tenki_flag = 0; # 天氣圖像表示 (0:否 1:是) $page = 15; # 每一頁顯示的日記天數 # (PAGE輸出格式為 0 時才有效) $admin_enter = 2; # 管理者用入口之位置 $max_size = 1024 * 99; # 登錄最大byte數 (1Kbyte = 1024byte) $end_date = 0; # 日期是否要延遲十二小時 (0:否 1:是) # -------------------- # 以下為檔案處理相關的設定,原則上不需變更 $method = 'POST'; # METHOD設定('POST' or 'GET') $tz = "UTC-5"; # 時區 #$cashe = 1; # (未使用) $cginame = 'index.cgi'; # 本CGI之檔名 #$jcode = './jcode.pl'; # jcode.pl位置 $logfile = './diary_utf8.log'; # 記錄用檔案名 $savetype = 0; # 日記記錄方式 0:標準 1:Temp利用 $lock1 = './diary1_utf8.lock'; # 鎖定用檔案(1) $lock2 = './diary2_utf8.lock'; # 鎖定用檔案(2) $lock_flag = 1; # 鎖定用檔案 1:使用 0:不使用 $htmldir = './'; # 過去記錄自動匯出之路徑 $htmldir_url = './'; # 過去記錄自動匯出之URL $htmldir_flag = 1; # 過去記錄自動匯出為HTML功能 1:使用 0:不使用 $charset_code='UTF-8'; # 文件語系設定 # -------------------- # 標題部分的HTML內文 $html_title=<<"_EOF_";

Cantabrian回旋運動(仮)

_EOF_ # ↑ _EOF_這幾個字請務必留著! # -------------------- # 自創的JavaScript或CSS請寫在這裡 $html_head=<<"_EOF_"; _EOF_ # -------------------- # 需要在頁首加入廣告的話請寫在這裡 $html_topbanner=<<"_EOF_"; _EOF_ # ↑ _EOF_這幾個字請務必留著! # -------------------- # 需要在頁尾加入廣告的話請寫在這裡 $html_bottombanner=<<"_EOF_"; _EOF_ # ↑ _EOF_這幾個字請務必留著! # ------------------------------------------ # # (警告) 以下為著作權相關的部分。(警告) # # 請仔細閱讀readme.htm。 # # ------------------------------------------ # $image_auther_url = "http://www.ushikai.com/"; # 圖像作者之URL (若有引用請尊重原作者) $image_auther = "牛飼い"; # 圖像作者名 (若有引用請尊重原作者) # ////////////////////////////////////////////////////////// # 個人化設定到此為止。 # 以下為 CGI 之主程式。 # 要修改的話請自行負責。 # ////////////////////////////////////////////////////////// $image_url =~ s/\/$//; $htmldir =~ s/\/$//; $htmldir_url =~ s/\/$//; if ($max_size <1500) { $max_size = 1500; } &read_form; if ($FORM{'l'} ne '') { $html_layout = $FORM{'l'}; } if ($FORM{'p'} ne '') { $page_layout = $FORM{'p'}; } if ($FORM{'t'} ne '') { $tenki_flag = $FORM{'t'}; } if ($FORM{'pass'} eq $master) { @logs = &read_file($logfile); if ($FORM{'func'} eq 'bookmark') { &editor_bookmark; exit;} if ($FORM{'func'} eq 'checklog') { &editor_checklog; exit;} if ($FORM{'func'} eq 'checkcgi') { &check_mode; exit; } if ($FORM{'func'} eq 'del') { &editor_del;} if ($FORM{'func'} eq 'download') { &editor_download; exit;} print "Content-type: text/html\n\n"; print &html_header; &html_editor; print &html_footer; } elsif ($FORM{'mode'} eq 'test') { &check_mode; } else { @logs = &read_file($logfile); print "Content-type: text/html\n\n"; print &html_header; if ($admin_enter == 0) { &html_adminenter; } print &html_title; if ($admin_enter == 1) { &html_adminenter; } &html_layout; if ($admin_enter > 1) { &html_adminenter; } print &html_footer; } exit 0; # [ HTML檔頭部分 ] # sub html_header{ if (-f "$htmldir/kako.html") { $html = "▲過去日記紀錄"; } return <<"_EOF_"; $diary_title $html_head $html_topbanner
回到首頁
$html
_EOF_ } # [ 著作權之顯示(請務必留下本部分) ] # sub html_footer{ if ($tenki_flag) { $tmp = "圖檔:$image_auther"; } return <<"_EOF_";

My Diary Version 1.21c
原作:じゃわ 中文化:哈泥蛙
管理者:$admin_name $tmp
$html_bottombanner _EOF_ } # [ HTML標題部分 ] # sub html_title { return <<"_EOF_"; $html_title
_EOF_ } # [ 日記內容表示部分格式輸出 ] # sub html_layout { local($start,$end) = &page_log; for ($i = $start;$i<$end;$i++) { ($date,$title,$tenki,$message) = &get_data($i); if ($FORM{'pass'} eq $master) { print "
[刪除] [編輯]\n"; } $date = &get_weekly_date($date); print &html_format($date,$title,$tenki,$message); } } # [ 網頁格式輸出 ] # sub page_log { local($start,$end); if ($page_layout == 0) { $start = $FORM{'start'}; $end = $start + $page; if ($start < 0 || $start > @logs) { $start = 0; } if ($end < 0) { $end = 0;} if ($end > @logs) { $end = @logs; } print "

\n"; $temp = $start-$page; if ($start>0) { print "[BACK] "; } else { print "[BACK] "; } $temp = $start+$page; if ($end<@logs) { print "[NEXT] "; } else { print "[NEXT] "; } } else { $start = $FORM{'start'}; $end = @logs; if ($start < 0 || $start > @logs) { $start = 0; } $target_time = substr((&get_data($start))[0],0,6); $flag = 0; for($i=0;$i<@logs;$i++) { $time = substr((&get_data($i))[0],0,6); if ($time eq $target_time) { if ($flag == 0) { $start = $i;$flag = 1; } } elsif ($flag == 1) { $end = $i; last;} } if ($start>0) { $start--; $time = substr((&get_data($start))[0],0,6); $temp = substr($time,0,4) . "/" . substr($time,4,2); print "$temp << "; $start++; } if ($end<@logs) { $time = substr((&get_data($end))[0],0,6); $temp = substr($time,0,4) . "/" . substr($time,4,2); print " >> $temp "; } } return ($start,$end); } # [ HTML格式輸出 ] # sub html_format { ($date,$title,$tenki,$message) = @_; $html = ""; if ($html_layout == 0) { $html .= "\n

\n"; $html .= "
\n"; $html .= "\n"; $html .= "\n"; $html .= "
\n"; $html .= "[ $title ]\n"; $html .= "
\n"; $html .= "$message
\n"; $html .= "
\n"; $html .= "$date\n"; if ($tenki_flag) { $html .= "\"$tenki_name[$tenki]\"\n"; } $html .= "
\n"; $html .= "
\n"; $html .= "
\n"; } else { $html .="\n

\n"; $html .= "
\n"; $html .= "\n"; $html .= "\n"; $html .= "
\n"; $html .= "$date
\n"; $html .= "$title\n"; $html .= "
\n"; $html .= "$message
\n"; if ($tenki_flag) { $html .= "
\"$tenki_name[$tenki]\"
\n"; } $html .= "
\n"; $html .= "
\n"; } return $html; } # [ 日記內容取得部分 ] sub get_data { local($date,$title,$tenki,$message) = split(/<>/,$logs[$_[0]]); $message =~ s/\n//; #自動連結功能 $message =~ s/([^=^\"]|^)(http|ftp)([\w|\!\#\&\=\-\%\@\~\;\+\:\.\?\/]+)/$1$2$3<\/a>/g; return ($date,$title,$tenki,$message); } # [ 取得日期 ] # sub get_weekly_date { local($date) = $_[0]; local($year,$mon,$day,$week) = (substr($date,0,4),substr($date,4,2),substr($date,6,2),0); if ($mon < 3) { $year--; $mon += 12; } $week = (int($year) + int($year/4) - int($year/100) + int($year/400) + int(($mon*13+8)/5) + $day) % 7; local($year,$mon) = (substr($date,0,4),substr($date,4,2)); $date = $year."/".$mon."/".$day."($youbi[$week])"; return $date; } # [ 管理者用入口 ] # sub html_adminenter { print<<"_EOF_";
_EOF_ } # [ 管理用畫面之表示 ] # sub html_editor { &editor_edit; if ($editno == 0) { ($year,$mon,$day) = &get_date; } else { ($year,$mon,$day) = (substr($editno,0,4),substr($editno,4,2),substr($editno,6,2)) } for($i=0;$i<@logs;$i++) { if ("$year$mon$day" eq substr((&get_data($i))[0],0,8)) { ($date,$title,$tenki,$message) = &get_data($i); $message =~ s/
/\n/g; } } $kiji = @logs; $size = (stat($logfile))[7]; $lmsize = $max_size - $size; print<<"_EOF_";
取消編輯

My Diary Editor


目前共有$kiji天分的日記,記錄檔現有$sizebyte的大小。
系統設定日記的大小限制為$max_sizebyte,目前還有$lmsizebyte的空間可以使用。

標題:
日期: ←須使用半形數字 _EOF_ print "\n"; print "\n"; print "天氣:\n"; print "\n"; print<<"_EOF_";
日記內容
  
_EOF_ &html_layout; print<<"_EOF_"

[注意]
輔助工具一般並不需要使用
真的需要使用的話,請詳讀readme.htm
選擇輔助工具:
_EOF_ } # [ 日記內容之登錄編輯 ] sub editor_edit { # 檢查登錄內容 if ($FORM{'year'}< 1583 || $FORM{'year'}> 9999) { return; } if ($FORM{'mon'}< 1 || $FORM{'mon'}> 12) { return; } if ($FORM{'day'}< 1 || $FORM{'day'}> (0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31)[$FORM{'mon'}]) { return; } if ($FORM{'mon'} == 2 && $FORM{'day'} == 29) { if (($FORM{'year'} % 4 != 0 && $FORM{'year'} % 100 == 0) || ($FORM{'year'} % 400 != 0)) { return; } } $FORM{'mon'} = substr("0$FORM{'mon'}",length($FORM{'mon'})-1,2); $FORM{'day'} = substr("0$FORM{'day'}",length($FORM{'day'})-1,2); $date = "$FORM{'year'}$FORM{'mon'}$FORM{'day'}"; $FORM{'message'} =~ s/\r\n/
/g; $FORM{'message'} =~ s/\r|\n/
/g; # 記錄檔登錄處理 $edit_flag = 0; foreach $data (@logs) { $target_date = (split(/<>/,$data))[0]; if (!$del{$target_date}) { # 不是刪除 if ($target_date eq $date) { if ($FORM{'message'} ne '') { # 覆蓋 push(@new,"$date<>$FORM{'title'}<>$FORM{'tenki'}<>$FORM{'message'}\n"); $edit_flag = 1; $edit{substr($target_date,0,6)} = 1; } } else { if ($target_date < $date && !$edit_flag) { if ($FORM{'message'} ne '') { # 寫入新記錄檔 push(@new,"$date<>$FORM{'title'}<>$FORM{'tenki'}<>$FORM{'message'}\n"); $edit_flag = 1; $edit{substr($target_date,0,6)} = 1; } } push (@new,$data); } } else { $edit_flag = 1; $edit{substr($target_date,0,6)} = 1; } } if (!$edit_flag && $FORM{'message'} ne '') { # 寫入新記錄檔 push(@new,"$date<>$FORM{'title'}<>$FORM{'tenki'}<>$FORM{'message'}\n"); $edit_flag = 1; $edit{substr($date,0,6)} = 1; } # 登錄限制刪除處理 if ($edit_flag) { $size = (stat($logfile))[7]; while ($size > $max_size) { $size -= length(pop(@new)); } @logs = &write_file($logfile,@new); undef @new; } # 過去記錄自動編輯為HTML功能 if (!$htmldir_flag) { return 0; } $target_date = 0;$edit_flag = 0; push(@logs,"dummy<><><>\n"); foreach $data (@logs) { if ($target_date ne substr((split(/<>/,$data))[0],0,6)) { if ($edit_flag) { $htmlfile = "$htmldir/wd$target_date.html"; if (!open(HTML,">$htmlfile")) { &error(1,"無法做成HTML檔案。"); } print HTML &html_header; print HTML "
看其他月份
\n"; print HTML &html_title; $date = substr($target_date,0,4).'/'.substr($target_date,4,2); print HTML "
($date)
\n"; foreach $data (@new) { local($date,$title,$tenki,$message) = split(/<>/,$data); $message =~ s/\n//; $date = &get_weekly_date($date); print HTML &html_format($date,$title,$tenki,$message); } print HTML &html_footer; close(HTML); chmod(0666,$htmlfile); if (!opendir(DIR,$htmldir)) { &error(1,"無法讀取目錄。"); } local(@files) = readdir(DIR); closedir(DIR); @files = reverse(sort(@files)); if (!open(HTML,">$htmldir/kako.html")) { &error(1,"無法做成HTML檔案。"); } print HTML &html_header; print HTML "$html_title\n"; print HTML "
\n"; print HTML "以下是之前的日記,請點選想看的月份。\n

\n"; foreach $file (@files) { if (substr($file,0,2) eq "wd") { $date = substr($file,2,4)."年".substr($file,6,2)."月"; print HTML "過去的日記 ($date)"; if ($edit{substr($file,2,6)}) { print HTML " UPDATE"; } print HTML "
\n"; } } print HTML "
\n"; print HTML &html_footer; close (HTML); chmod(0666,"$htmldir/diarykako.html"); } $target_date = substr((split(/<>/,$data))[0],0,6); $edit_flag = 0; undef @new; } if ($edit{$target_date}) { push(@new,$data); $edit_flag = 1; } } pop(@logs); } # [ 下載記錄檔(編輯模式) ] # sub editor_download { print "Content-type: text/download\n\n"; print @logs; exit 0; } # [ 記錄檔初期化(編輯模式) ] # sub editor_del { @logs = &write_file($logfile,''); @logs = (); } # [ CGI動作檢查 ] # sub check_mode { if (!(-f $logfile)) { $axs = "Not Found" } if (-r $logfile) { $axs = "r" } if (-w $logfile) { $axs .= "w" } print "Content-type: text/html\n\n"; print<<"_EOF_";
    MyDiary Version 1.21.00c -TestMode-

[Option] logfile[$axs] LockFlag:$lock_flag ImageUrl:$image_url Method:$method FileName:$cginame TimeZone:$tz Owner:$admin_name ($admin_email)

[Perl] Path:#!$^X Version:$]

[TestForm] TestFormText:$FORM{'test'}

_EOF_ exit; } # [ 書籤登錄 ] # sub editor_bookmark { print "Content-type: text/html\n\n"; print<<"_EOF_"; MyDiaryEditor [寫日記]
    注意!

    本工具提供管理者在我的最愛(書籤)中直接加入連往編輯模式的連結。
    只要加入連結之後,不需打入密碼也能夠從連結進入編輯模式。
    不過也因此必須注意,千萬別讓他人使用自己的電腦或瀏覽器。
    (也就是不要讓他人能夠使用自己的書籤。)

    ‧確定要登錄的話,在IE中請按滑鼠右鍵之後選擇「加到我的最愛」。
    ‧NN則是選擇「加入書籤」。

    請在這裡按滑鼠右鍵→ [進入MyDiaryEditor]
    
_EOF_
}

# [ 記錄檔之處理 ]
#

sub read_file {
    local($logfile) = $_[0];
    if (!open(IN,$logfile)) {
        &error(1,"禁止寫入記錄檔");
    }
    local(@files) = ;
    close(IN);
    return @files;
}
sub write_file {
    local($logfile,@lines) = @_;
    &dubble_lock_file;
    if ($lock_error) { &error(1,"發現鎖定用檔案,請稍待片刻之後再使用。"); }

    if (!$savetype) {
        # 所有OS共通之標準型
        if (!open(OUT,">$logfile")) {
            &dubble_unlock_file;
            &error(1,"禁止寫入記錄檔");
        }
        print OUT @lines;
        close(OUT);
    } else {
        # 使用改良型chmod
        $tmpfile = "$$\.tmp";
        if (!open(OUT,">$tmpfile")) {
            &dubble_unlock_file;
            &error(1,"並未對應使用暫存檔案之記錄方式。");
        }
        close(OUT);
        chmod 0666,$tmpfile;
        if (!open(OUT,">$tmpfile")) {
            &dubble_unlock_file;
            &error(1,"並未對應使用暫存檔案之記錄方式。");
        }
        print OUT @lines;
        close(OUT);
        rename($tmpfile,$logfile);
        if (-e $tmpfile) { unlink($tmpfile); }
    }
    &dubble_unlock_file;
    return @lines;
}

# [ 鎖定機制 ]
#
sub dubble_lock_file {
    if (!(&lock_file($lock1))) { &dubble_unlock_file; }
    elsif (!(&lock_file($lock2))) { &dubble_unlock_file; }
}
sub dubble_unlock_file {
    &unlock_file($lock2);&unlock_file($lock1);
}
sub lock_file {
    local($lockfile) = $_[0];
    if (!$lock_flag) { return 1; }
    local($retry) = 5;
    while (-f $lockfile) {
        if ($retry-- <= 0) {
            local($mtime) = (stat($lockfile))[9];
            if ($mtime < time()-60*15) { return 0; }
            $lock_error = 1;
            return 1;
        }
        sleep 1;
    }
    open (LOCK,">$lockfile");
    close(LOCK);
    return 1;
}
sub unlock_file {
    local($lockfile) = $_[0];
    unlink($lockfile);
}

# [ 取得日期 ]
#

sub get_date {
    $ENV{'TZ'} = $tz;
    ($sec,$min,$hour,$day,$mon,$year,$youbi) = localtime(time);
    if ($hour < 12 && $end_date) {
        ($sec,$min,$hour,$day,$mon,$year) = localtime(time-12*60*60);
    }
    $mon++;
    if ($mon  < 10)  { $mon  = "0$mon";  }
    if ($day  < 10)  { $day  = "0$day";  }
    if ($year < 99) { $year += 100; }
    $year += 1900;
    $youbi = ('Sun','Mon','Tue','Wed','Thu','Fri','Sat')[$youbi];
    return ($year,$mon,$day,$hour,$min,$sec,$youbi);
}

# [ 從表單中取得資料 ]
#

sub read_form {
    if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); } else { $buffer = $ENV{'QUERY_STRING'}; }
    local(@pairs) = split(/&/,$buffer);
    foreach (@pairs) {
        local($name,$value) = split(/=/,$_);
        $value =~ tr/+/ /;
        $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
        if ($name eq 'edit') { $editno = $value; }
        elsif ($name eq 'del') { $del{$value} = 1; }
        else { $FORM{$name} = &change_code($value); }
    }
}

# [ 符號更換 ]
#

sub change_code {
    local($text)=$_[0];
    $text =~ s/<>/<>/g;
    return $text;
}

# [ 錯誤處理 ]
#

sub error {
    ($err,$err_msg) = @_;
    if ($err) { print "Content-type: text/html\n\n"; }
    print<<"_EOF_";
    

錯誤:$err_msg

_EOF_ exit; }