Code:
#!/usr/bin/perl5 -w
# Prints the
Gossamer Threads Home Page greeting.
# Author: Alex Krohn (alex@gossamer-threads.com)
# NOTE: You need the list of domains to country names. I got mine from Analog and
# you can find it here:
#
# http://www.gossamer-threads.com/scripts/source/domains.tab
#
use strict;
print "Content-type: text/html\n\n";
my ($time, $greeting) = &get_date;
my $country = &get_country;
print qq~
<TABLE BORDER=0 WIDTH=100% CELLSPACING=10 CELLPADDING=10>
<TR BGCOLOR=#FF0000>
<TD>
~;
if ($ENV{'REMOTE_ADDR'}=='123.45.6.789') {
print qq|Dear collegue! Please <a href="add.cgi">add your favorite link</a> to our directory|;
}
elsif (defined $country) {
print qq|Browse our directory ...|;
}
print qq~</td></tr></table>
~;
exit;
sub get_country {
# --------------------------------------------------------------
my ($match, $code, $name);
if (exists $ENV{'REMOTE_HOST'} and ($ENV{'REMOTE_HOST'} =~ /\.(..)$/)) {
$match = $1;
open (DOMAINS, "./domains.tab") or (print "SYSTEM ERR: CANT OPEN FILE" and exit);
while (<DOMAINS>) {
chomp;
($code, $name) = split (/:/);
($code eq $match) and close DOMAINS and return $name;
}
close DOMAINS;
}
return undef;
}
sub get_date {
# --------------------------------------------------------------
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) = localtime(time - 10800);
($hour < 10) and ($hour = "0$hour");
($min < 10) and ($min = "0$min");
($sec < 10) and ($sec = "0$sec");
my $date = "$days[$wday] $months[$mon] $mday";
my ($greeting, $noon);
if ($hour < 12) { $greeting = "Good Morning"; }
elsif ($hour >=12 && $hour < 17) { $greeting = "Good Afternoon"; }
elsif ($hour >=17 && $hour < 24) { $greeting = "Good Evening"; }
else { $greeting = "Hello"; }
($hour < 12) and ($noon = "am");
($hour > 12) and ($hour = $hour - 12) and ($noon = "pm");
($hour == 00) and ($hour = 12);
($hour == 12) and ($noon = "pm");
return "$hour\:$min $noon on $days[$wday], $months[$mon] $mday", $greeting;
}
I haven't removed the time/date thing and stuff, but this should give you the idea. Of course, you need to edit the IP-address to your own.