#!/usr/bin/perl BEGIN { $ENV{'PATH'} = '/bin:/usr/bin'; use CGI::Carp qw(carpout); open(ERRORLOG, ">>Errors") or die("Unable to open Errors: $!\n"); carpout(ERRORLOG); } use strict; use CGI::Carp; use Time::Local; use CGI; ########################################################################### my $NEWSDIR = "Current"; my $NEWS_HEAD = "marathon_news.head"; my $NEWS_TAIL = "marathon_news.tail"; my $MAX_BYTES = 15000; ########################################################################### print "Content-type: text/html\n\n"; my $cgi = new CGI; my $remote_mins=$cgi->param('mins'); # mins of day on remote machine # The local offset from GMT in hours # my ($tsec,$tmin,$thour,@tarray) = localtime(0); $::TZ = $thour - 24; # The remote offset from GMT in seconds # ($tsec,$tmin,$thour,@tarray) = gmtime(); if ( $remote_mins ) { $::TZD = ($remote_mins - ($thour*60 + $tmin) ) * 60; } else { $::TZD = 0; } print "\n\n"; # Print out the page header read from file # open(FILE, "$NEWS_HEAD"); while () { print $_; } close(FILE); # Print out contact details # my ($date, $time) = &Get_Date(time); print qq(
Current time: $time Send Us News
); # Get a list of all news posts # opendir(DIRLIST, $NEWSDIR) || die "Cant read from $NEWSDIR\n"; my @messages = readdir(DIRLIST); @messages = sort {$b<=>$a} @messages; closedir(DIRLIST); my $olddate=""; my ( $bytecount, $message ); # Loop through outputting each news post # foreach $message (@messages) { if ( length($message) < 3 ) { $bytecount = $MAX_BYTES; } if ( $bytecount < $MAX_BYTES ) { open(FILE, "$NEWSDIR/$message"); my @this_message = ; close(FILE); ($date, $time) = &Get_Date($message); my ( $linecount, $line, $updater, $subject, $user ); foreach $line (@this_message) { $linecount++; if ($linecount == 1) { $updater = $line; } elsif ($linecount == 2) { $subject = $line; } elsif ($linecount == 3) { $user = $line; if ( $date ne $olddate ) { print qq(
$date ); } print qq(
$time $subject - $updater
); } else { # Increment the count of bytes displayed so far # $bytecount = $bytecount + length($line); # Ensure that 's aren't framed # $line =~ s/
\n"; $olddate = $date; } } open(FILE, "$NEWS_TAIL"); while () { print $_; } close(FILE); exit(0); sub Get_Date { my ( $intime ) = @_; my @days = ("Sunday","Monday","Tuesday","Wednesday", "Thursday","Friday","Saturday"); my @months = ("January","February","March","April","May","June", "July","August","September","October","November","December"); my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = gmtime($intime + $::TZD); my $ampm = "a.m."; if ($hour eq 12) { $ampm = "p.m."; } if ($hour eq 0) { $hour = "12"; } if ($hour > 12) { $hour = ($hour - 12); $ampm = "p.m."; } if ($min < 10) { $min = "0$min"; } $year = 1900+$year; # Monday, 12 January 1998 at 12:32 p.m. my $todaydate = "$days[$wday], $mday $months[$mon] $year"; my $todaytime = "$hour\:$min\ $ampm"; $todaydate, $todaytime; } 1;