#!/usr/bin/perl # Another add-on to urllist.cgi. This script automatically redirects to the last URL # catched from the channel which is given as parameter. # Copyright 2003 by Susanna Winter # Version history: # v0.1 - May 2003: Initial version # v0.2 - May 2003: Getting fed up with having to edit numerous scripts every time I # change something in the site layout I've now changed the SSI files to # be read into the scripts rather than have static html code # -> flexible for me but, overall, not very portable. # v0.2.1 - June 2003: Added msgs to the channel list if no parameters. use strict; use CGI qw(:standard); use File::stat; use Time::localtime; # globals my $filename = "lasturl.pl"; my @channel_list = ("#example"); my $path_to_files = "\/path\/to\/files\/"; # addresses from where it's allowed to see addresses sent via msg my @msgallowedhosts = (""); # sub's # check if msg option is allowed sub check_host { foreach my $host (@msgallowedhosts) { if ($ENV{'REMOTE_HOST'} eq $host) { return 1; } } } #end of check_host sub fix_month { my $fixed_month = $_[0]; $fixed_month =~ s/Jan/01/; $fixed_month =~ s/Feb/02/; $fixed_month =~ s/Mar/03/; $fixed_month =~ s/Apr/04/; $fixed_month =~ s/May/05/; $fixed_month =~ s/Jun/06/; $fixed_month =~ s/Jul/07/; $fixed_month =~ s/Aug/08/; $fixed_month =~ s/Sep/09/; $fixed_month =~ s/Oct/10/; $fixed_month =~ s/Nov/11/; $fixed_month =~ s/Dec/12/; return $fixed_month; } #end of fix_month # sub's declared my $query = ""; $query = param("keywords"); my $no_channel = 1; foreach (@channel_list) { if ("#" . $query eq $_) { $no_channel = 0; } } if (($query eq "msg") && check_host()) { $no_channel = 0; } # no parameters -> print the main urllist.cgi page if ( !(param()) || ($no_channel) ) { print "Content-type:text/html\n\n"; print "Lasturl.pl\n\t"; print "\n"; print "\t

Irkistä kerättyjä URLeja

\n\t"; print "\n\n\t"; print "
\n\t"; print "\n\t\n\t\t\n\t\n\t
\n\t\t\n\t\t\n\t\t\t"; print "\n\t\t\n\n\t\t\n\t\t\t"; print "\n\t\t\n\t\t
Search for on channel(s)\n\t\t\t
\n\t\t\t  Advanced search"; print "
\n\t
\n\n"; #print the rest of the page my $last_modified = (ctime(stat($filename)->mtime)); my ($day_of_week, $month, $day, $time, $year) = split(" ", $last_modified, 5); print "$filename viimeksi päivitetty: $day." . fix_month($month) . ".$year. © $year by Susanna Winter.
\n"; print "Kysymykset ja kommentit osoitteeseen susanna.winter\@lut.fi
\n\n\n\n"; } else { my $last_url = ""; if ($query ne "msg") { $query = "#" . $query; } #my $file = $path_to_files . $query . "/" . $query . ".1"; my $i; for ($i = 1; $i <= 8; $i++) { my $file = $path_to_files . $query . "/" . $query . "."; if ($i < 8) { $file = $file . $i; } else { $file = $file . "old"; } if (-e $file) { $last_url = `/usr/bin/tail -1 $file`; my $junk = ""; my $url = ""; ($junk, $junk, $junk, $junk, $junk, $junk, $junk, $url) = split(/\s+/, $last_url); # Usenet msg-id if ($url =~ /^<.*>$/) { $url =~ s//\%3E/g; $url = "http://groups.google.com/groups?q=msgid$url"; } # Iltalehti elsif ($url =~ /^http:\/\/www\.iltalehti\.fi/ && $url !~ /^http:\/\/www\.iltalehti\.fi\/light\//) { $url =~ s/^http:\/\/www\.iltalehti\.fi\//http:\/\/www\.iltalehti\.fi\/light\//; } print "Location: $url\n\n"; print "URI: $url\n\n"; } else { next; } } if ($last_url eq "") { print "Content-type:text/html\n\n"; print "Lasturl.pl\n\t"; print "\n"; print "

Irkistä kerättyjä URLeja

\n\t"; print "

Ei uusia URLeja kanavalta $query.

\n"; my $last_modified = (ctime(stat($filename)->mtime)); my ($day_of_week, $month, $day, $time, $year) = split(" ", $last_modified, 5); print "$filename viimeksi päivitetty: $day." . fix_month($month) . ".$year. © $year by Susanna Winter.
\n"; print "Kysymykset ja kommentit osoitteeseen susanna.winter\@lut.fi
\n\n\n\n"; } }