#! c:/perl/bin/perl # # upnotice.cgi # # upnotice.cgi # # 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 # # 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. # ../dialy/dialy.html, The dialy 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.5 2005/09/25 17:33:53 Hideki Kanayama Exp $ use CGI::Carp qw(fatalsToBrowser); use strict; my $datafile = "upfiles.dat"; # 更新情報を表示する日数 # Message expiratoin date count my $expire = 7; # Language 0:Japanese 1:English my $lang = 1; 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; 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"); $time_item{$d_mtime} = $item; } foreach (sort {$b <=> $a} keys %time_item) { my $limit_time = $_ + $expire * 3600 * 24; if ($gmt < $limit_time){ print "
  • $updates{$time_item{$_}}
  • \n"; $displayed = 1; } } if ($displayed == 0 and exists $updates{EMPTY}){ print "
  • $updates{EMPTY}
  • \n"; } sub error { my ($msg) = shift; print "$msg"; exit; }