#! /usr/bin/perl
#
# upnotice.cgi
#
# 1.007 : 1/1/07 : 複数同時更新時の表示のバグを修正
# 1.006 : 11/17/06 : 時間設定オプションを追加
# 1.005 : 6/26/06 : 更新件数表示モード時に不必要なEMPTYメッセージを表示しないように修正
# 1.004 : 6/9/06 : 更新件数表示モードを追加
# 1.003 : 4/10/06 : 更新日時を表示するオプションを追加
# 1.002 : 9/24/05 : 更新された順序で表示するように修正
# Modified to be displayed with the order from new
# 1.001 : 8/14/05 : Typo fix
# 1.0 : 8/13/05 : 一般公開のためにクリーンアップ Clean up for release
# 0.2 : 10/23/04 : Modified color of dipslay
# 0.1 : 10/5/04 : Initial revision
#
# SSIで呼び出す。
#
# で起動できます。
#
# ファイルが更新されたのを指定のメッセージで一定期間お知らせする。
# ファイルとメッセージの指定はupfiles.datの中に「ファイル名,メッセージ」
# のように半角カンマで区切って記述する。ファイル名はこのCGIがある
# ディレクトリからの相対パス。第一カラムをEMIPTYにするとどのファイルも
# 更新されていない時にそれに対応するメッセージが表示されます。
# 行頭に「#」があるとその行は無視されます。
# 文の位置を合わせるための半角スペース、タブは無視されます。
# 以下にデータファイルの例。
# -----------
# bbs/bbs.dat, BBSに書き込みがありました。
# ../evcal/evcal.dat, イベントカレンダーが更新されました。
# ../diary/diary.html, 日記が更新されました。
# ../index.shtml, トップページ更新しました。
# EMPTY, 現在更新情報はありません。
# -----------
#
# A message will be displayed when specified file is updated.
# The message will be displayed for seven days in default.
# You can change the duration by changing the value of "$expire".
# File and message can be specified in upfiles.dat as "filename, message"
# which separated by a comma.
# The filename in "$datafile" is a relative path from where the CGI locates.
# If you specify "EMPTY" to the first column, the following message will be
# displayed if none of file is updated.
# "#" at the beginning of the line will be a comment line.
# Spaces and tabs will be ignored.
# An example of the data file shown below.
#
# -----------
# bbs/bbs.dat, The BBS has been updated.
# ../evcal/evcal.dat, The event calendar has been udpated.
# ../diary/diary.html, The diary has been updated.
# ../index.shtml, The top page has been updated.
# #../abc.html, This page has been removed.
# EMPTY, There is no updated page so far.
# -----------
#
# $Id: upnotice.cgi,v 1.13 2007/01/01 08:26:18 Hideki Kanayama Exp $
# Copyright(c) 2005-2007, Hideki Kanayama All rights reserved
use CGI::Carp qw(fatalsToBrowser);
use strict;
my $datafile = "upfiles.dat";
# 更新情報を表示する日数
# Message expiratoin date count
my $expire = 7;
# 更新日時を表示 1:表示 0:非表示
my $dispdate_en = 1;
# 表示モード 0以外:件数モード 0:日数モード
my $disppage = 0;
# Language 0:Japanese 1:English
my $lang = 0;
# 時間設定
my $localtime_en = 0;
my $offset = 9;
my %updates;
my @filemsg;
my $line;
print "Content-Type: text/html\n\n";
my @no_data_file;
$no_data_file[0] = "データファイル$datafileがありません。";
$no_data_file[1] = "Cannot file data file $datafile.";
my @no_file;
open(FILE, "< $datafile") or &error("$no_data_file[$lang]");
while ($line = ){
next if $line =~ /^\s*#/;
next if $line =~ /^\s*$/;
chomp($line);
@filemsg = split /,/, $line;
foreach (@filemsg){s/^\s*(.*?)\s*$/$1/;}
$no_file[0] = "$filemsg[0]が見つかりません。";
$no_file[1] = "Cannot find $filemsg[0].";
&error ("$no_file[$lang]") unless (-e "$filemsg[0]" or "$filemsg[0]" eq 'EMPTY');
$updates{$filemsg[0]} = $filemsg[1];
}
close(FILE);
my $displayed = 0;
my $gmt = time;
my $item;
my %time_item;
my %dispdate;
foreach $item (keys(%updates)){
my ($d_dev,$d_ino,$d_mode,$d_nlink,$d_uid,$d_gid,$d_rdev,$d_size,$d_atime,$d_mtime,$d_ctime,$d_blksize,$d_blocks)=stat("$item");
push @{$time_item{$d_mtime}}, $item;
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)= $localtime_en ? localtime($d_mtime) : gmtime($d_mtime + $offset * 3600);
$dispdate{$item} = sprintf("%4d年%02d月%02d日%02d時%02d分",$year+1900,$mon+1,$mday,$hour,$min);
}
my $count = 1;
foreach (sort {$b <=> $a} keys %time_item) {
my $limit_time = $_ + $expire * 3600 * 24;
if ((($disppage == 0) and ($gmt < $limit_time)) or
(($disppage != 0) and $count <= $disppage)){
foreach my $tmp (@{$time_item{$_}}){
next if ($tmp eq 'EMPTY' and $disppage != 0);
print "$updates{$tmp}";
print "($dispdate{$tmp})" if ($dispdate_en);
print "\n";
$displayed = 1;
}
}
$count++;
}
if ($displayed == 0 and exists $updates{EMPTY}){
print "$updates{EMPTY}\n";
}
sub error {
my ($msg) = shift;
print "$msg";
exit;
}