#!/usr/bin/perl # You may have to change the line above to refer to where perl # is located on your system. At the Unix prompt, type whereis perl # and a list of locations of perl on your server will be shown. # Change the line above to match one of those locations. ##KloakItPAGE.HTM##################################################### # # (C) Copyright 2000 Volatile Graphix, Inc. All rights reserved. # This script may not be copied or modified in any way without # permission in writing from Volatile Graphix, Inc. # # Limitation of Liability: KloakIt is to be used at your own risk # Volatile Graphix, Inc. d.b.a. KloakIt expressly disclaims any and # all liability from any and all consequences arising from the use # of this and all scripts that Volatile Graphix, Inc. d.b.a. KloakIt # have written. By using this script in whole or in part, the user # hereby agrees to abide by this statement. # ###################################################################### ###################################################################### # # Make $redir equal to the URL (web page address) of the page you want # normal people to see. $redir = "http://www.test-italy.com.com/index.html"; # OPTIONAL # If you change the name of the data directory, make $writedir equal # to the new name and path of the directory. $writedir = "testdata"; # OPTIONAL # Set timeModifier to equal the difference between your server time # and your local time. $timeModifier = "0"; ###################################################################### ############# NO EDITING NECESSARY BELOW HERE ######################## ############# NO EDITING NECESSARY BELOW HERE ######################## ############# NO EDITING NECESSARY BELOW HERE ######################## ###################################################################### #open (STDERR, ">>pageerrorlog.txt"); $temp=""; $keywordarray=""; $tobedisplayed=""; if ($ENV{'SERVER_SOFTWARE'} =~ /Win/i) {$winserver = 1;} $loc = "http://" . $ENV{'SERVER_NAME'}; $myname = $ENV{'SCRIPT_NAME'}; $myname =~ s/^\/.*\///; $myname =~ s/^\///; $gethost = $ENV{'REMOTE_HOST'}; $getaddr = $ENV{'REMOTE_ADDR'}; $ref = $ENV{'HTTP_REFERER'}; $agent = $ENV{'HTTP_USER_AGENT'}; $localdirectory = $ENV{'SCRIPT_NAME'}; $localdirectory =~ s/^(.+)\/.+\.[ch][gt][im]$/$1/; if (-e "$writedir/randompages.txt"){ open (RA, "$writedir/randompages.txt"); @randompages = ; @randompagesInUse = @randompages; close (RA); } if (-e "$writedir/nolistlinks.daq") { $listLinks = "0";} else { $listLinks = "1";} open (REDIR, "$writedir/altredir.txt"); @redirlist=; close (REDIR); $stop=0; foreach (@redirlist){ chomp; ($pageName,$altRedir,$customTemplate,$randomSeed) = split (/#/, $_); if ($myname eq $pageName) { if ($altRedir ne "") { $redir = $altRedir; } if ($customTemplate ne "") { $altTempl = 1; } $randseed = $randomSeed; last; } } foreach (@redirlist){ chomp; ($linkName,$tempfoo,$tempfoo2) = split (/#/, $_); push (@cloakedURLs, $linkName); } @cloakedURLsInUse = @cloakedURLs; open (K, "$writedir/gr.daq"); flock (K, 2) unless($winserver); $c = ; flock (K, 8) unless($winserver); close (K); if (-e "$writedir/nocache.daq") { $nocache = 1; } unless (($c =~ /$ENV{'SERVER_NAME'}/) or ($c =~ /kk.+ .+/)) { open (A, "$writedir/gra.daq"); flock (A, 2) unless($winserver); @gra = ; flock (A, 8) unless($winserver); close (A); } if ($localdirectory =~ /\.[ch][gt][im]$/) { $localdirectory =~ s/.+.[ch][gt][im]$//; } if (-e "$writedir/nocloak.daq"){ $nocloakcheck=1; open (NOCLOAK, "$writedir/nocloak.daq"); @nocl = ; close (NOCLOAK); foreach (@nocl){ chomp; ($enginename, $switch) = split(/\t/, $_); $nocloak{$enginename} = $switch; } } @exclude = ("204.123.9.65", # @exclude is for certain applications "204.123.9.66", # sponsored by search engines such "204.123.9.67", # as Babelfish that translate pages into "204.123.9.68", # other languages and display them. You "204.123.9.106", # don't want humans seeing this, so I "204.123.9.107", # made an exclude list. "204.152.191.27", "204.152.191.28", "204.152.191.29", "204.152.190.27", "204.152.190.28", "204.152.190.29", "204.152.190.37", "204.152.190.154", "204.162.96.104", "204.162.96.154", "204.162.96.176", "209.247.194.35", "209.247.194.100", "64.208.35.5"); if (-e "$writedir/customexclude.daq"){ open (CUSTOMEXCLUDE, "$writedir/customexclude.daq"); @customexclude = ; close (CUSTOMEXCLUDE); } else { open (CUSTOMEXCLUDE, "+>$writedir/customexclude.daq"); close (CUSTOMEXCLUDE); chmod (0777, "$writedir/customexclude.daq"); } if ($gethost eq "") { $gethost = $getaddr; } for ($count=1; $count<=10; $count++){ open (ENGINELIST, "$writedir\/$count" . ".list"); flock(ENGINELIST, 2) unless($winserver); @enginelist1= if $count eq 1; @enginelist2= if $count eq 2; @enginelist3= if $count eq 3; @enginelist4= if $count eq 4; @enginelist5= if $count eq 5; @enginelist6= if $count eq 6; @enginelist7= if $count eq 7; @enginelist8= if $count eq 8; @enginelist9= if $count eq 9; @enginelist10= if $count eq 10; flock(ENGINELIST, 8) unless($winserver); close (ENGINELIST); } ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time+ (3600*$timeModifier)); # set time if (length ($min) eq 1) {$min= '0'.$min;} $mon++; $year =~ s/.+(..)$/$1/; $date="$mon/$mday/$year, $hour:$min"; # MAIN PROGRAM ###################################################################### ###################################################################### # Do not cloak if cloaking is turned off. open (IFCL, "<$writedir/ifcl.daq");#" flock (IFCL, 2) unless($winserver); $ifcl = ; flock (IFCL, 8) unless($winserver); close (IFCL); if (!$ifcl) { &detect; &robot; exit; } # Detect if requestor is a robot or a normal person &detect; # Display normal page to normal person or entrance page to robot if ($isRobot ne "0") { &robot; } else { &normal; } exit; ###################################################################### # DETECT IF REQUESTOR IS ROBOT OR NORMAL ###################################################################### ###################################################################### sub detect{ $isRobot = 0; $classCclient = $getaddr; $classCclient =~ s/\.\d+$//; for ($count=1;$count<=11;$count++){ @list = @enginelist1 if $count eq 1; # Infoseek $SE = "Infoseek" if $count eq 1; @list = @enginelist2 if $count eq 2; # Alta Vista $SE = "Alta Vista" if $count eq 2; @list = @enginelist3 if $count eq 3; # Lycos $SE = "Lycos" if $count eq 3; @list = @enginelist4 if $count eq 4; # Inktomi $SE = "Inktomi" if $count eq 4; @list = @enginelist5 if $count eq 5; # Excite $SE = "Excite" if $count eq 5; @list = @enginelist6 if $count eq 6; # Google $SE = "Google" if $count eq 6; @list = @enginelist7 if $count eq 7; # Northern Light $SE = "Northern Light" if $count eq 7; @list = @enginelist8 if $count eq 8; # Misc $SE = "Misc" if $count eq 8; @list = @enginelist9 if $count eq 9; # Custom List 1 $SE = "Custom List 1" if $count eq 9; @list = @enginelist10 if $count eq 10; # Custom List 2 $SE = "Custom List 2" if $count eq 10; $SE = "" if $count eq 11; foreach $line (@list) { chomp $line; next if $line eq ""; next if $line =~ /^\#/; $line =~ s/ //g; if (($gethost =~ /$line/i) and ($gethost =~ /[abcdefghijklmnopqrstuvwxyz\-]+/i)) { $isRobot = $count; } if ($getaddr eq $line){ $isRobot = $count; } if ($line =~ /^\d+\.\d+\.\d+$/){ if ($classCclient eq $line){ $isRobot = $count; } } last if $isRobot eq $count; } last if $isRobot eq $count; } if ($isRobot eq 0) { $count=10; $isRobot = 10; $SE = "SURFER" } else { # protect against translators if ($gethost =~ /babelfish/i) { $translator = " -- Translator"; $SE = ""; $isRobot = 0; } # protect against BabelFish using Scooter IPs if ($getaddr eq "209.73.164.50"){ unless ($agent =~ /scooter/i){ $translator = " -- Translator"; $SE = ""; $isRobot = 0; } } foreach $ip (@exclude) { if ($getaddr eq $ip) { $isRobot = 0; $translator = " -- Translator"; $SE = ""; } } # check for custom excludes foreach $ip (@customexclude) { chomp($ip); if ($getaddr eq $ip) { $isRobot = 0; $NoCloak = " -- Exclude on for $getaddr "; $SE = ""; } } # check for nocloak if ($nocloak{$SE}) { $NoCloak = " -- Cloaking off for $SE "; $isRobot = 0; } } } ###################################################################### # SERVE NORMAL PAGE TO NORMAL REQUESTOR ###################################################################### ###################################################################### sub normal{ # Log the access open (ACCESSLOG, "<$writedir/access.log"); flock(ACCESSLOG, 2) unless($winserver); @accesslog = ; flock(ACCESSLOG, 8) unless($winserver); close (ACCESSLOG); open (ACCESSLOG, ">$writedir/access.log"); flock(ACCESSLOG, 2) unless($winserver); print ACCESSLOG " $date -- $gethost -- $agent -- $myname -- $NoCloak$ref$translator\n"; $count=1; foreach $occurance (@accesslog){ print ACCESSLOG $occurance; last if $count eq 10000; $count++; } flock(ACCESSLOG, 8) unless($winserver); close (ACCESSLOG); if ($redir ne "") { use LWP::Simple; $redirectedpage = get "$redir"; print STDOUT "Content-type: text/html\n\n"; print STDOUT @gra unless $gra[0] eq ""; if ($redir =~ /\.htm.*$/i){ $redir =~ s/^(.+\/).+\.htm.*$/$1/i; } if ($redir !~ /\/$/) { $redir = $redir . "/";} @htmlout = split (/\n/, $redirectedpage); $bhref = $redir; $bhref =~ s/(\/)[^\/]+$/$1/; $count=0; foreach $li (@htmlout){ if ($li =~ /\<\/head\>/i){ $li =~ s/^(.*)\<\/[hH][eE][aA][dD]\>(.*)$/$1\<\/head\>$2/; $htmlout[$count] = $li; last; } $count++; } #print STDOUT "\n"; #print STDOUT $redirectedpage; foreach (@htmlout){ print STDOUT "$_\n"; } exit; } } ###################################################################### # SERVE ROBOT PAGE TO ROBOT REQUESTOR ###################################################################### ###################################################################### sub robot{ # determine primary keyword $keyword = $myname; $keyword =~ s/\.[ch][gt][im]//; $keyword =~ s/\-/ /g; $keyword =~ s/^\///; if ($keyword eq "index") { open (KEY, "<$writedir/indexkeywords.daq");#" flock (KEY, 2) unless($winserver); $keyword = ; flock (KEY, 8) unless($winserver); close (KEY); } if ($keyword eq "sitemap") { open (KEY, "<$writedir/indexkeywords.daq");#" flock (KEY, 2) unless($winserver); $titlekeyword = ; flock (KEY, 8) unless($winserver); close (KEY); } @keywordarray = split (/ /, $keyword); @keyword = split (/ /, $keyword); $lckey = lc($keyword); $uckey = uc($keyword); $ucfirstkey = ""; foreach $circ (@keyword){ $circ = ucfirst($circ); $ucfirstkey = $ucfirstkey . " " . $circ; } $ucfirstkey =~ s/^ //; if (($nocache) and ($SE eq "Google")) { $SE = "Google NoCache"; $nocache = 1; } else { $nocache = 0; } open (RANDOM, "$writedir/random.txt"); flock (RANDOM, 2) unless($winserver); @random = ; flock (RANDOM, 8) unless($winserver); close (RANDOM); # initialize random stuff $randomset = 0; $randomdyn = 0; srand($randseed); $nothing = rand(10); @randomInUse = @random; @randomdynamic = @random; @randomdynamicInUse = @random; $SEsymbol = "# "; if (!$ifcl) { if ($SE eq "") { $SE = "web surfer"; $SEsymbol = " "; } $SE = $SE . " (cloaking disabled)"; $count = 9; } # access secondary keyword list open (SECONDARYKEYWORDS, "$writedir/keywords.txt"); flock(SECONDARYKEYWORDS, 2) unless($winserver); @secondarykeywords = ; flock(SECONDARYKEYWORDS, 8) unless($winserver); @secondarykeywordsInUse = @secondarykeywords; # open template if ($count eq 11) { $count=6; $SEsymbol = " "; } unless ($altTempl){ open (TEMPLATE, "$writedir/template" . $count . ".txt"); } else { open (TEMPLATE, "$writedir/$customTemplate"); } flock(TEMPLATE, 2) unless($winserver); @template =