# The 'date' field is required. The 'time' and 'expires' fields are optional.
# The 'expires' field give explicit expiration date of the
# do not use Time::localtime ;
use Time::Local ;
# NOTE!!! September is 8 months since January!!!!
# set realduetime to 11:59:59 pm of due date
# $realduetime = timelocal(59,59,23,19,1,102) ;
$now = time ;
$SecondsPerDay = 86400 ;
use CGI ;
# Print out environment variables.
# Don't erase, good for debugging.
#
# while ( ($var, $val) = each(%ENV) ) {
# print "\n" ;
# print "$var=$val\n" ;
# print "\n" ;
# }
# use CGI.pm to parse QUERY_STRING env var.
$query = new CGI($ENV{'QUERY_STRING'}) ;
@names = $query->param ;
#
# Print out header. This is necessary!
#
print "Content-type: text/html\n\n" ;
# print "Hello World\n" ;
# Print out parameters passed.
# Don't erase, good for debugging.
#
# print "Query String paramenters
\n" ;
# print "\n" ;
# foreach $field (@names) {
# $val = $query->param($field) ;
# print "- $field = $val\n" ;
# }
# print "
\n" ;
# Get the relevant parameters from QUERY_STRING
#
$ignore = $all = $def_expire = 0 ;
if (defined $query->param('ignore') ) {
$ignore = ($query->param('ignore') != 0) ;
}
if (defined $query->param('all') ) {
$all = ($query->param('all') != 0) ;
}
undef $begin ; undef $end ;
if ( defined $query->param('from') ) {
$begin = $now - $query->param('from') * $SecondsPerDay ;
}
if ( defined $query->param('to') ) {
$end = $now - $query->param('to') * $SecondsPerDay ;
}
if ( defined $query->param('start') ) {
$foo = $query->param('start') ;
$begin = &date2timelocal($query->param('start'),"") ;
}
if ( defined $query->param('stop') ) {
$end = &date2timelocal($query->param('stop'),"") ;
}
# Default values for $begin and $end times
$begin = $now - 90 * $SecondsPerDay unless defined $begin ;
$end = $now unless defined $end ;
# print " \$begin = $begin\n" ;
# print "
\$end = $end\n" ;
# print "
\$all = $all\n" ;
# print "
\$ignore = $ignore\n" ;
$path = $ENV{'REQUEST_URI'} ;
# print "
REQUEST_URI = $path
\n" ;
# remove trailing file name, don't forget trailing /
$path =~ s#(.*)/[^/]*#\1/# ;
# print "
PATH= $path
\n" ;
# quick and dirty
# $path =~ s#^/~chang/#/home/faculty6/chang/www/# ;
#
# use ypmatch to get user's home directory
#
# if ($path =~ m#^/~([^/]*)/#) {
# $user = $1 ;
# $passline = `/bin/ypmatch $user passwd` ;
# @passfields = split(":", $passline) ;
# $homedir = $passfields[5] . "/www/";
# # print "path to home = $homedir \n" ;
#
# $path =~ s#^/~([^/]*)/#$homedir# ;
# }
# use homedir param in QUERY_STRING to get home directory
#
$homedir = $query->param('homedir') ;
# print "
HOMEDIR= $homedir
\n" ;
$homedir =~ s#$#/# unless $homedir =~ m#/$# ; # add / at end if not there
$path =~ s#^/~([^/]*)/#$homedir# ;
$filename = $query->param('file') ;
# print "
PATH= $path
\n" ;
# print "
FILE= $filename
\n" ;
chdir($path) ;
if ( !open(IF, $filename) ) {
print "
Internal Error #1\n" ;
print "
Could not open $filename for reading.\n" ;
print "
Please contact the webmaster.\n" ;
exit 1 ;
}
@lines = ;
$input = join("", @lines) ;
close IF ;
#
# Main loop
#
while ($input =~ s/(.*?)<\/NEWSITEM>//is) {
$params = $1 ;
$item = $2 ;
next unless $params =~ m/date="([^"]*?)"/is ;
$thedate = $1 ;
if ($params =~ m/time="([^"]*?)"/is ) {
$newstime = date2timelocal($thedate, $1) ;
} else {
$newstime = date2timelocal($thedate, "") ;
}
# print " \$newstime = $newstime\n" ;
if (!$all) {
if (!$ignore && ($params =~ m/expires="([^"]*?)"/is)) {
$expires = date2timelocal($1,"") ;
next if ($expires < $now) ;
} else {
next if ($newstime < $begin || $end < $newstime) ;
}
}
# translate newstime to UNIX date format
($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst)
= localtime($newstime) ;
$weekday = (Sun,Mon,Tue,Wed,Thu,Fri,Sat)[$wday] ;
$month = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec)[$mon] ;
$year2000 = 1900 + $year ;
$timestamp = sprintf("%3s %3s %02d %02d:%02d %4s",
$weekday,$month,$mday,$hour,$min,$year2000) ;
print "\n\n
[$timestamp] \n" ;
print $item ;
}
0 ;
sub date2timelocal {
local($date, $time) = @_ ;
local($month, $day, $year, $hour, $min, $sec, $result) ;
if ( $date =~ m/(\d{1,2})\/(\d{1,2})\/(\d{2,4})/is ) {
$month = $1 ; $day = $2 ; $year = $3 ;
if ($year < 50) { # fix y2k problem
$year = 100 + $year ;
}
elsif ($year >= 1900) {
$year = $year - 1900 ;
}
$result = timelocal (0,$min,$hour,$day,$month-1,$year) ;
} else {
return 0 ;
}
if ($time =~ m/(\d{2}):(\d{2})(:\d[2])?/is ) {
$hour = $1 ; $min = $2 ; # ignore seconds
$result += ((60 * $hour) + $min) * 60 ;
}
return $result ;
}