#!/usr/local/bin/perl # # clariweb.cgi - output a list of stories based on a web/news overview file. # # Version: 3.00 # Last Modified: Feb 23, 1998 # Make sure we search the script's directory for the config file. $SCRIPTDIR = $0 =~ m%^(/.+)/[^/]+$%? $1 : '.'; unshift(@INC, $SCRIPTDIR); $PREFIX = 'custom' unless $PREFIX = $ENV{'CLARIWEB_PREFIX'}; $CONFIG_FILE = "${PREFIX}_config.pl" unless $CONFIG_FILE = $ENV{'CLARIWEB_CONFIG'}; $CUSTOM_FILE = "$SCRIPTDIR/${PREFIX}_grouplist.pl"; require $CONFIG_FILE; require $CUSTOM_FILE if -f $CUSTOM_FILE; require 'Date/Parse.pm' unless $WEBOV; ($_ = $ENV{'PATH_INFO'}) =~ s%^/%%; s%\.%/%g; if (m%^clari/%) { s%^clari/%clari/web/% unless m%^clari/web/%; } elsif (m%^webnews/%) { s%^%biz/clarinet/%; } elsif (!m%^biz/clarinet\b%) { s%^%clari/web/%; } $dir = $_; ($group = $_) =~ s%/%.%g; ($grp = $group) =~ s/^clari\.web\.//; $all = $ENV{'QUERY_STRING'} =~ /\ball\b/; print "Content-type: text/html\n\n"; if ($WEBOV) { chdir("$NDIR/$WEBOV"); &html_msg_exit('No Such Group', "I can't find $group on this machine.") unless -f $group; &html_msg_exit('No Stories', "There are no stories in $group at this time.") unless -s _; open(IN, $group) || &html_msg_exit('Open Error', "Unable to open overview file for $group"); # Check if the weboverview files are still in the old format. $_ = ; seek(IN, 0, 0); if (/\texpires: \d+,\d+/) { @items = reverse sort { $a <=> $b } grep(s/^\d+(.*)\texpires: \d+,(\d+)/$2$1/ || 1, ); } else { @items = reverse sort { $a <=> $b } ; } close(IN); } else { chdir($OVFILES); &html_msg_exit('No Such Group', "I can't find $group on this machine.") unless -d $dir; &html_msg_exit('No Stories', "There are no stories in $group at this time.") unless -s "$dir/.overview"; open(IN, "$dir/.overview") || &html_msg_exit('Open Error', "Unable to open overview file for $group"); while () { ($datestr) = (split(/\t/))[3]; $artdate = &str2time($datestr); s/^\d+/$artdate/; push(@items, $_); } @items = reverse sort { $a <=> $b } @items; close(IN); } chdir($NDIR) || &html_msg_exit("Unable to chdir to $NDIR\n"); # The "removed" subdir optimizes removed files so we don't have to # stat() them all. if (opendir(DP, "removed")) { while (defined($_ = readdir(DP))) { next if /^\./; $hash_index{$_} = 1; } closedir(DP); } $limit = $INITIAL_PAGE_SIZE if !$all; if (defined(&format_header)) { $_ = &format_header($group, $grp); } else { $_ = < Newsgroup $group EOT if ($grp ne $group) { $_ .= "

ClariNews in $grp

\n"; } else { $_ .= "

Newsgroup $grp

\n"; } $_ .= "\n"; } print; foreach (@items) { next unless ($fname) = /\tx-fn: (\S+)/i; ($name) = $fname =~ m%/([^/]+)$%; next if defined($hash_index{$name}); $hash_index{$name} = 1; ($artdate,$subject,$from,$datestr) = split(/\t/); $from =~ s%^.+\(\s*([^,)/]+).*%$1%; $from =~ s/\s+$//; $from =~ s/united press international/UPI/i; $from =~ s/^reuter$/Reuters/i; $from =~ s/^the (\S+) editors$/$1/i; my($wday,$day,$month,$hr,$mn,$tz) = ($datestr =~ /^([A-Za-z]+,? )? *(\d+) +(\w+) +\d+ +(\d+):(\d+):\d+ (.*)/); $subject =~ s% *([/[][ /[]*$month .*)%%; if (defined(&format_item)) { $_ = &format_item($fname,$subject,$from,$datestr,$artdate); } else { my($icon) = $subject =~ s/^\[P\] //? $PHOTO_TAG : ''; my($amorpm) = $hr >= 12? 'pm' : 'am'; $hr = 12 if $hr == 0; $hr -= 12 if $hr > 12; $_ = <$subject  $icon $from / $wday$month $day, $hr:$mn$amorpm $tz EOT } next unless $_; print; last if !$all && --$limit <= 0; } if (!$all && @items > $INITIAL_PAGE_SIZE) { if (defined(&format_allref)) { print &format_allref("$grp?all"); } else { print "

Show all articles\n"; } } if (defined(&format_footer)) { $_ = &format_footer; } else { $_ = "\n"; } print; exit; sub html_msg_exit { local ($_); $_ = shift @_; print "$_\n"; print "

$_

\n"; foreach (@_) { print "

$_

\n"; } exit; }