#!/usr/local/bin/perl ############################################################### # ------------- # # IPush # # ------------- # # Redirector Script # # # # Description: Redirects based on IP Addresses. # # Author: Scott Beck # ############################################################### require "IPush.cfg"; require "log.pl"; ######################################################################## # Main Script # ######################################################################## $page = "$ENV{'QUERY_STRING'}"; $ref = "$ENV{'HTTP_REFERER'}"; $getaddr = "$ENV{'REMOTE_ADDR'}"; ✓ &get_date; open (PAGE, "$root_path/$defalt_page/$page"); @page = ; close (PAGE); print STDOUT "Content-type: text/html\n\n"; print STDOUT @page; if ($logging eq "yes") { &log; } elsif (($logging eq "bots") && ($isRobot eq "yes")) { &log_bots; } ####################################################################### # Check IP and set Redirect URL # ####################################################################### sub check { $isRobot = "no"; foreach $key (keys %redirect) { if ($getaddr eq "$key") { $defalt_page = "$redirect{$key}"; $isRobot = "yes"; } elsif ($getaddr =~ /$key\d+$/) { $defalt_page = "$redirect{$key}"; $isRobot = "yes"; } $key =~ /^(\d+\.\d+\.\d+\.)\d+-\d+/; $first_match = "$1"; if ($getaddr =~ /^$first_match\d+/) { $key =~ /^\d+\.\d+\.\d+\.(\d+)-(\d+)/; $from="$1"; $to="$2"; $getaddr =~ /^\d+\.\d+\.\d+\.(\d+)/; $last_octect="$1"; if (($last_octect >= $from) && ($last_octect <= $to)) { $defalt_page = "$redirect{$key}"; $isRobot = "yes"; } } } } ######################################################################## # Get the Date # ######################################################################## sub get_date { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time); # set time if (length ($min) eq 1) {$min= '0'.$min;} $mon++; $date="$mon/$mday/$year, $hour:$min"; }