#!/usr/bin/perl -w ############################################################################## # # # script to track clicks, and switch redirect up if Googlebot comes crawling # # # # # ############################################################################## use strict; my $site = "http://www.la-los-angeles-college.com/"; my $query = &readQuery; my %query = &httpQueryVars('text', $query); my %hexQuery = &httpQueryVars('urlencoded', $query); my %htmlQuery = &httpQueryVars('html', $query); my $redirect = ''; my $ua = $ENV{'HTTP_USER_AGENT'}; my $camp = $query{'var'}; if ($ua =~ /google/ig ) { $redirect = $site; } else { if ($camp eq "tra") { # Platt college redirect $redirect = "http://4valen.com/clk/idensohoukemumaidon"; } } print "Location: $redirect\n\n"; exit; #--- Subroutines -----------------------------------------------# sub readQuery { my $string = ''; if($ARGV[0]) { $string = $ARGV[0]; } elsif($ENV{'REQUEST_METHOD'} eq 'GET'){ #method='get' $string = $ENV{'QUERY_STRING'}; } elsif($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $string, $ENV{'CONTENT_LENGTH'}); #method='post' } return $string; } sub httpQueryVars { #Either "text", "html", "urlencoded", or none my $query = pop @_; my $type = lc pop(@_); my $pair = ''; my(%query,%hexQuery,%htmlQuery) = (); #$query =~ s/%0D%0A/\n/gi; #Parse and set the query variables into %query and %hexQuery foreach $pair (split(/&/, $query)){ #Cycle through each value pairs my($key, $value) = split(/=/, $pair); #Separate name and value $key =~ tr/+/ /; $key =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $hexQuery{lc($key)} = $value; #Assign URL encoded variable to a %hexQuery variable next if $type eq 'urlencoded'; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $query{lc($key)} = $value; #Assign name and varible to a hash variable next if $type eq 'text'; $htmlQuery{lc($key)} = scalar &htmlEntities($value); } return %query if $type eq "text"; return %hexQuery if $type eq "urlencoded"; return %htmlQuery if $type eq "html"; } sub htmlEntities { my(@array) = (); my(@items) = @_; for(@items){ s/&/&/g; s/"/"/g; s/'/'/g; s//>/g; push(@array, $_); } return @array if(scalar(@items) > 1); return $array[0] if(scalar(@items) == 1); }