#!/usr/bin/perl # If required, adjust line above to point to Perl 5. ###################################################################### # fantomas shadowMaker(TM) # ###################################################################### # $vers = "ver. 01.01.01"; # 2002-12-20 # ###################################################################### # (c) Copyright 2002 by fantomaster.com # # All rights reserved. # # Copying, modification or distribution requires permission # # in writing by copyright holder. # # fantomas shadowMaker(TM) is the protected trade mark of # # fantomaster.com. # # URL: < http://fantomaster.com > # ###################################################################### ###################################################################### ########## PLEASE ADJUST THE FOLLOWING VARIABLES! ################ # # # "$standard" = denotes the core domain you want to redirect # # your "normal" visitors to # # (i.e. NO searchbots, etc.) # # "$stats_dir" = Directory for log files and admin files # # (Default name is: "stats") # # "$hits_log_file" = Log file listing SD hits # # (Default name is: "hits.log") # # " $human_log_file" = Log file listing SD hits from human visitors # # (Default name is: "human-hits.log") # # "$links_list_file" = Links list file name as generated in step 4 # # (Default name is: "links.txt") # # "$selist_file" = Search engine referrer parsing routines # # (Default name is: "selist.txt") # # "$botbase_dir" = Directory of fantomas spiderSpy(TM) botBase # # (Default name is: "stats") # # "$botbase_file" = file containing spider robots list # # (Default name is: "spiderspy.txt") # ###################################################################### $standard = "http://banner.onlybingo.com/cgi-bin/redir.cgi?id=N&member=seeding2&profile=shadob"; $stats_dir = "../stats"; $hits_log_file = "hits.log"; $humans_log_file = "human-hits.log"; $links_list_file = "links.txt"; $selist_file = "selist.txt"; $botbase_dir = "/www/botbase"; $botbase_file = "spiderspy.txt"; ###################################################################### ############# NO EDITING BEYOND THIS LINE! ####################### ###################################################################### $query_string = "$ENV{'QUERY_STRING'}"; $remote_host = "$ENV{'REMOTE_HOST'}"; $remote_addr = "$ENV{'REMOTE_ADDR'}"; $user_agent = "$ENV{'HTTP_USER_AGENT'}"; $referer = "$ENV{'HTTP_REFERER'}"; $method = "$ENV{'REQUEST_METHOD'}"; ###################################################################### $switch_name = $query_string; $switch_name =~ s/^\///; $fantom_name = $switch_name; ###################################################################### &get_date; &process_register; if ($search_engine) { &fantom } else { &standard } exit; ###################################################################### sub get_date { ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(); $mon++; $sec = sprintf ("%02d", $sec); $min = sprintf ("%02d", $min); $hour = sprintf ("%02d", $hour); $mday = sprintf ("%02d", $mday); $mon = sprintf ("%02d", $mon); $year = scalar localtime; $year =~ s/.*?(\d{4})/$1/; $date="$year-$mon-$mday, $hour:$min:$sec"; return; } ###################################################################### sub process_register { open (REGISTER, "$botbase_dir/$botbase_file"); @register=; close (REGISTER); $search_engine = (); foreach $botbase (@register) { next if ($botbase =~ /^[#-]/); next if ($botbase =~ /^\s*$/); chomp $botbase; if ( $remote_addr eq $botbase ){ $search_engine = 1; last; } } return; } ###################################################################### sub standard { if (-f "$stats_dir/$links_list_file" ) { if ($referer) { &process_engine_list; $keywords = &parse_referer($referer); } open (STANDARD, "$stats_dir/$links_list_file"); @list=; close (STANDARD); foreach $line (@list) { next if ($line =~ /^[#-]/); next if ($line =~ /^\s*$/); chomp $line; ($field1, $field2) = split (/:::/, $line); $links{$field1} = $field2; } if ( $links{$keywords} ) { if ( $links{$keywords} eq '<>' ) { print "Location: $standard\n\n"; } else { print "Location: $links{$keywords}\n\n"; } } else { $switch_name =~ /^(.+?)\-\d{2}/; $keywords = $1; $keywords =~ s/(\_|\-)/ /g; if ( $links{$keywords} ) { if ( $links{$keywords} eq '<>' ) { print "Location: $standard\n\n"; } else { print "Location: $links{$keywords}\n\n"; } } else { print "Location: $standard\n\n"; } } } else { print "Location: $standard\n\n"; } &log_hits ("$date -- $remote_host -- $remote_addr -- $switch_name -- $user_agent -- $referer -- $keywords -- $links{$keywords} -- $method\n"); &log_human_hits ("$date -- $remote_host -- $remote_addr -- $switch_name -- $user_agent -- $referer -- $keywords -- $links{$keywords} -- $method\n"); return; } ###################################################################### sub fantom { # Unterprogramm zur Darstellung der Fantom-Seite @HTML = (); print "Content-type: text/html\n\n"; if (! -f "$fantom_name") { $fantom_name = "index.html" } open (FANTOM, "$fantom_name"); while () { $html_string .= $_; } close (FANTOM); $html_string =~ s|<\!--\#include virtual=\"(.+?)\"-->|&include_file($1)|egi; print $html_string; &log_hits ("!!$date -- $remote_host -- $remote_addr -- $switch_name -- $user_agent -- $referer -- $method\n"); return; } ###################################################################### sub include_file { my ($include_file) = @_; my $include_string; $include_file =~ s|^/||; open (FILE, "$include_file"); while () { $include_string .= $_; } close (FILE); return $include_string; } ###################################################################### sub log_hits { open (HITS, ">>$stats_dir/$hits_log_file"); print HITS @_; close (HITS); return; } ###################################################################### sub log_human_hits { open (HITS, ">>$stats_dir/$humans_log_file"); print HITS @_; close (HITS); return; } ###################################################################### sub parse_referer { my ($referer) = @_; my ($keywords); foreach $se (@se) { foreach $query ( @{ $query{$se} } ) { if ($referer =~ m§^http://($domain{$se})(.*?)($query)(.*?)(\&|$)§i){ $keywords = $4; if (! $keywords) {next} $keywords =~ s|^cache\:(.+)\+(.*?)\&|$2|; $keywords = &decode_keywords($keywords); $keywords =~ s|^\s+||; $keywords =~ s|\s+$||; $keywords =~ s|\s+| |g; } } } return ($keywords); } ###################################################################### sub process_engine_list { open (ENGINES, "$botbase_dir/$selist_file") || die "$botbase_dir/$selist_file: $!"; $i = -1; @engines = (); @engine_referer = (); @engine_submit = (); while (){ next if /^\s*$/; next if /^\s*#/; chomp; $_ =~ s/^ *(.+?) *$/$1/g; if (/^\[(.+)\]$/){ $i++; $se = $1; $se[$i] = $se; } if (/domain:\s*(.+)$/){ $domain = quotemeta $1; if ($domain{$se}){ $domain{$se} = join ("|", $domain{$se}, $domain); } else { $domain{$se} = $domain; } } if (/query:\s*(.+)$/){ $query = quotemeta $1; push ( @{ $query{$se} }, $query ); } } close (ENGINES); return; } ###################################################################### sub decode_keywords { my ($keywords) = @_; $keywords =~ s/\+/ /g; $keywords =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; return $keywords; } ######################################################################