#!/usr/bin/perl
#print "Location: http://robhansen.com\n\n";
#die;

###
###  PRINT ALL ENV VARIABLES (uncomment)
###
#   print "Content-type: text/html\n\n"; 
#   print "<tt>\n"; 
#   foreach $key (sort keys(%ENV)) { 
#      print "$key = $ENV{$key}<p>"; 
#   } 
#   die;

###
### This script executes only if a top-level domain is requested
### because it's named index.cgi and resides in wwwroot.
###


### What time is it?
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
$mon = $mon +1;
$year = $year +1900;
$date_string = sprintf("%02d-%02d-%04d", $mon, $mday, $year);
$time_string = sprintf("%02d:%02d:%02d", $hour, $min, $sec);



### Which domain is being requested?
if (defined $ENV{'SERVER_NAME'}) {
    $server_name = $ENV{'SERVER_NAME'};
} else {
    $server_name = "";
} 


### and by whom?
if (defined $ENV{'REMOTE_ADDR'}) {
    $remote_host = $ENV{'REMOTE_ADDR'};
} else {
    $remote_host = "";
} 


if (defined $ENV{'HTTP_REFERER'}) {
    $referer = $ENV{'HTTP_REFERER'};
} else {
    $referer = "";
} 


### IP addresses that appear to be the source of hacking / virus attempts
### 
if ($remote_host eq "216.103.200.102" ||
	$remote_host eq "210.21.10.137" ||
	$remote_host eq "212.57.174.110" ||
	$remote_host eq "216.216.143.12" ||
	$remote_host eq "216.30.42.69" ||
	$remote_host eq "216.242.132.134" ||
	$remote_host eq "216.78.163.207" ||
	$remote_host eq "216.133.225.91" 
	)  {
	print "Location: http://www.fbi.gov/\n\n"; 
	die;
}

#
# Set any ID flags...
#
if ($remote_host eq "24.5.106.85") { $flag = "9IRC"; }
if ($remote_host eq "68.7.180.149") { $flag = "PARENTS"; }
if ($remote_host eq "64.32.236.50") { $flag = "GBWM"; }
if (substr($remote_host,0,7) eq "158.184") { $flag = "LORAL"; }


##  if this IP (llv/loral) requests wedding, show them zipsend instead
##
if ($flag eq "LORAL")  {
        if ($server_name =~ /wedding/i)  {
	    print "Location: http://www.robhansen.com\n\n"; 
            open(HITS, ">>hits.txt") || die "couldn't open hits.txt";
            print HITS "$date_string, $time_string - $remote_host ($flag) - $referer  - $server_name [redirected] \n" ;
            close (HITS);
            exit 0; }
}


### Log the hit (unless it's me)
unless ($flag eq "X9IRC") {
    open(HITS, ">>hits.txt") || die "couldn't open hits.txt";
    print HITS "$date_string, $time_string - $remote_host ($flag) - $referer  - $server_name \n" ;
    close (HITS);
}


### send them the right page, based on domain name

## NOTE: baypet.com is now redirected using .htaccess and Redirect 301 / http://woodlandspet.com/
## This is a better method, and other domains should be moved to this when time permits.
## If you need to create content for baypet, remove the redirect in baypet/html/.htaccess 

if ($server_name =~ /woodlandpet|woodlandpets|woodlandspets|baypet/i) {   
    print "Location: http://www.woodlandspet.com/\n\n"; exit 0 }

if ($server_name =~ /woodlandspet/i) {   
    print "Location: http://www.woodlandspet.com/\n\n"; exit 0 }

if ($server_name =~ /zipsend/i) {   
	open FH, "< ./robhansen/index.html";
	$/ = undef; 
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /zipgift/i) {   
    print "Location: http://www.amazon.com/b?_encoding=UTF8&camp=1789&creative=9325&linkCode=ur2&node=2238192011&site-redirect=&tag=zipgicom-20&linkId=C6YBVOJB56RLZLOT\n\n"; exit 0 }
#	open FH, "< ./zipgift/index.html";
#	$/ = undef; 
#	$slurp = <FH>;
#	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /business|resume|bussiness|biz/i) {   
	open FH, "< ./business/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /hire/i) {   
	open FH, "< ./hire/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /tea|bear/i) {   
	open FH, "< ./tea/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /christmas|xmas/i) {   
	open FH, "< ./xmas/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /thanksgiving|turkey/i) {   
    print "Location: http://robhansen.com/thanksgiving/thanksgiving2006/\n\n"; }

if ($server_name =~ /home/i) {   
	open FH, "< ./home/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }


if ($server_name =~ /birch.robhansen/i) {   
    print "Location: http://home.robhansen.com/\n\n"; }

if ($server_name =~ /birch.suesanta/i) {   
    print "Location: http://home.suesanta.com/\n\n"; }

if ($server_name =~ /lucy2./i) {
    print "Location: https://photos.app.goo.gl/JiSPMvxxNVnYEi4A8\n\n"; exit 0;}

if ($server_name =~ /lucy/i) {
    print "Location: https://photos.app.goo.gl/bJjKynk31LrKgnVd8\n\n"; exit 0;}

if ($referer =~ /page.robhansen.net/i) {   
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/page/favicon.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/page/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /page.robhansen/i) {
    print "Content-type: text/html\n\n<frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/page/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /italy.robhansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/italy/favicon.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/italy/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /italia.robhansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/italy/favicon.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/italy/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /greece.robhansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/greece/favicon.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/greece/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /london.robhansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/greece/favicon.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/london/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /lake.robhansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/greece/favicon.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://robhansen.com/lake/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /paris.robhansen/i) {
	open FH, "< ./paris/index.shtml";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /yikes.redday/i) {
    print "Content-type: text/html\n\n<html><frameset rows=\"*,0\" border=0 framespacing=0 frameborder=0 ><frame src=\"http://www.hansen1.com/yikes/\" name=yikes scrolling=yes MARGINHEIGHT=1></frameset></html>"; die;  }

if ($server_name =~ /redday/i) {
    print "Location: http://$server_name/default/\n\n"; }
#    print "Location: http://$server_name/rd/\n\n"; }

if ($server_name =~ /amazon/i) {
    print "Location: http://$server_name/default/\n\n"; }

if ($server_name =~ /ebay/i) {
    print "Location: http://www.ebay.com/\n\n"; }

if ($server_name =~ /bugreaper/i) {
	open FH, "< ./br/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; die;  }

if ($server_name =~ /live105/i) {
    print "Location: http://$server_name/music/\n\n"; }

### This is currently never hit, since totalgift = givechocolate in DNS
if ($server_name =~ /totalgift/i) {
	open FH, "< ./givechocolate/index.cgi";
	$/ = undef; 
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /givechocolate/i) {
    print "Location: http://www.givechocolate.com/\n\n"; }

if ($server_name =~ /gretchen/i) {
    print "Location: http://www.hansen1.com/gretchen/\n\n"; }

if ($server_name =~ /rv.robhansen/i) {
	open FH, "< ./rv/index.shtml";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /wedding.robhansen/i) {
	open FH, "< ./wedding/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /sec.robhansen/i) {
    print "Location: http://64.32.236.50/view/muxer/cam3.htm?picsize=2&picsizename=fullsize&camera=1\n\n"; exit 0;}


## Catch-all for robhansen.com
if ($server_name =~ /robhansen/i) {   
	open FH, "< ./robhansen/index.html";
	$/ = undef; 
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }




###
### Sue Santa's Section
###

# webmail
if ($server_name =~ /mail.suesanta/i) {
    print "Content-type: text/html\n\n<frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://suesanta.com/cgi-bin/openwebmail/openwebmail.pl\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /wedding.suesanta/i) {
	open FH, "< ./wedding/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /rv.suesanta/i) {
	open FH, "< ./rv/index.shtml";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /vegas.suesanta/i) {
	open FH, "< ./vegas/index.shtml";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /tahoe.suesanta/i) {
    print "Location: http://groups.yahoo.com/group/santasintahoe/\n\n"; exit 0;}

if ($server_name =~ /security.suesanta/i) {
    print "Location: http://64.32.236.50/view/muxer/cam3.htm?picsize=2&picsizename=fullsize&camera=1\n\n"; exit 0;}

if ($server_name =~ /italy.suesanta/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/sue_48.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/italy/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /italia.suesanta/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/sue_48.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/italy/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /greece.suesanta/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/sue_48.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/greece/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /london.suesanta/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/sue_48.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/london/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /lake.suesanta/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/sue_48.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.suesanta.com/lake/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /paris.suesanta/i) {
	open FH, "< ./paris/index.shtml";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /photos.suesanta|photo.suesanta/i) {
	open FH, "< ./photos/sue/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }


if ($server_name =~ /gunst.suesanta/i) {
	open FH, "< ./gunst/index2.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }



###
### Sue Hansen's Section
###

if ($server_name =~ /wedding.suehansen/i) {
	open FH, "< ./wedding/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /rv.suehansen/i) {
	open FH, "< ./rv/index.shtml";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /tahoe.suehansen/i) {
    print "Location: http://groups.yahoo.com/group/santasintahoe/\n\n"; exit 0;}

if ($server_name =~ /security.suehansen/i) {
    print "Location: http://64.32.236.50/view/muxer/cam3.htm?picsize=2&picsizename=fullsize&camera=1\n\n"; exit 0;}

if ($server_name =~ /italy.suehansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/sue_48.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/italy/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /italia.suehansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/sue_48.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/italy/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /greece.suehansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/sue_48.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/greece/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /london.suehansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/sue_48.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.hansen1.com/london/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /lake.suehansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/sue_48.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.suehansen.com/lake/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /paris.suehansen/i) {
	open FH, "< ./paris/index.shtml";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /photos.suehansen/i) {
	open FH, "< ./photos/sue/index.html";
	$/ = undef;
	$slurp = <FH>;
	print "Content-type: text/html\n\n$slurp"; exit 0;  }

if ($server_name =~ /suehansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/woodlandsfavicon.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.woodlandsmarket.com\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

if ($server_name =~ /suesanta/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.hansen1.com/gifs/woodlandsfavicon.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.woodlandsmarket.com/employee-spotlight-sue-santa/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }




###
### Nick Hansen's Section
###



# webmail
if ($server_name =~ /mail.nickhansen/i) {
    print "Content-type: text/html\n\n<frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://nickhansen.com/cgi-bin/openwebmail/openwebmail.pl\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }

# all other web pages
if ($server_name =~ /nickhansen/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://www.robhansen.net/favicon.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://picasaweb.google.com/nickruns/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; die;  }



###
### Don Santa's Section
###

### Obsolete as of 4/14/17 when I set up a simple forward on the Plesk server.  If this section is needed in future, alias donsanta.com to robhansen.net and add apache server alias directive.
if ($server_name =~ /security.donsanta/i) {
    print "Location: http://64.32.236.50/view/muxer/cam3.htm?picsize=2&picsizename=fullsize&camera=1\n\n"; exit 0;}

if ($server_name =~ /tahoe.donsanta/i) {
    print "Location: http://groups.yahoo.com/group/santasintahoe/\n\n"; }

if ($server_name =~ /donsanta/i) {
    print "Content-type: text/html\n\n<LINK REL=\"SHORTCUT ICON\" HREF=\"http://static.woodlandsmarket.com/wp-content/uploads/2013/06/favicon.ico\"><frameset rows=\"*,0\" border=0 framespacing=no frameborder=no ><frame src=\"http://www.woodlandsmarket.com/about/about-woodlands/\" name=page scrolling=yes MARGINHEIGHT=1><frame src=\"\" name=empty scrolling=no></frameset>"; exit 0;  }




###
### Catch-all
###

# if they are requesting us by IP address, show blank page
# (69.5.74.87???)
if ($server_name =~ /66.197.68.30/i) {
    print "Location: http://66.197.68.30/default/\n\n"; }

# otherwise, show (blank page for now)
print "Location: http://$server_name/default/\n\n";
die;
