#!/usr/bin/perl ########################### ## AutoRank Pro v3.0.x ## ################################################## ## rankem.cgi - track incoming hits ## ################################################## package rank; #use strict; #push(@INC, 'c:/full/path/to/cgi/scripts'); ## NT support - uncomment and fill in correct path if necessary. my $DDIR = './data'; my $NT = 0; ## NT support - set this to 1 (one) if you are having problems with cookies. my %QRY; eval { require "$DDIR/vars.dat"; main(); }; err("$@", 'rankem.cgi') if( $@ ); exit; ##################################################################### ## Removing the link back to CGI Works is a copyright violation. ## ## Altering or removing any of the code that is responsible, in ## ## any way, for generating that link is strictly forbidden. ## ## Anyone violating the above policy will have their license ## ## terminated on the spot. Do not remove that link - ever. ## ##################################################################### sub main { parseget(); $OPT::GAT ? gateway($QRY{'id'}, $QRY{'ses'}) : give_hit($QRY{'id'}); } sub gateway { my( $id, $ses ) = @_; if( $ses ) { checkses($ses, $id); give_hit($QRY{'id'}); } else { display_gate($id, newsession()); } } sub give_hit { my( $id, $ct, $url) = shift; cheat("Using Proxy Server", $id) if( $OPT::PXY && ($ENV{'HTTP_VIA'} || $ENV{'HTTP_X_FORWARDED_FOR'}) ); check_cookie( $id ) if( $OPT::COK ); check_ip( $id ) if( $OPT::ILG ); if( -e "$DDIR/members/$id.cnt" ) { open(MEM, "+<$DDIR/members/$id.cnt") || err($!, "$DDIR/members/$id.cnt"); flock(MEM, 1); my @cd = split(/\|/, ); flock(MEM, 8); if( $cd[8] eq '' ) { close(MEM); repair($id); } $cd[0]++; $cd[2]++; $ct = $cd[6]; flock(MEM, 2); truncate(MEM, 0); seek(MEM, 0, 0); print MEM join('|', @cd); flock(MEM, 8); close(MEM); } checktime() if( !$OPT::CRN ); $url = $VAR::FU; $url = $VAR::HU . '/' . htmlname($ct) . '.' . $VAR::FE if( $OPT::FCP && $ct ne '' ); print "Location: $url\n\n"; } sub display_gate { my ( $id, $ses ) = @_; print "Content-type: text/html\n\n"; print < Enter

Enter This Site

Click here to enter!
HTML } sub cheat { my( $desc, $id ) = @_; fappend("$DDIR/cheat.log", "[ " . scalar( localtime ) . " ] [ $desc ] [ $id ] [ $ENV{'REMOTE_ADDR'} ($ENV{'HTTP_X_FORWARDED_FOR'}) ]\n") if( $OPT::CLG ); checktime() if( !$OPT::CRN ); print "Location: $VAR::FU\n\n"; exit; } sub parseget { my @pairs = split(/&/, $ENV{'QUERY_STRING'}); my ($name, $value); for (@pairs) { ($name, $value) = split(/=/, $_); $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $QRY{$name} = $value; } } sub checktime { if( getage("$DDIR/times/rerank") >= $VAR::RR ) { fwrite("$DDIR/times/rerank", 'rankem.cgi'); require 'arp.pl'; arp::rerank($OPT::BCR); } if( $VAR::RS ne '-1' && getage("$DDIR/times/reset") >= $VAR::RS ) { fwrite("$DDIR/times/reset", 'rankem.cgi'); require 'arp.pl'; arp::resetlist(); } if( getage("$DDIR/times/clean") >= $VAR::CN ) { fwrite("$DDIR/times/clean", 'rankem.cgi'); for( 1..255 ) { open(FILE, ">$DDIR/ips/$_") || err($!, "$DDIR/ips/$_"); close(FILE); } } } sub check_ip { my $id = shift; my $rm = (split(/\./, $ENV{'REMOTE_ADDR'}))[0]; open(IP, "$DDIR/ips/$rm"); for( reverse ) { if( $_ eq "$ENV{'REMOTE_ADDR'}|$id\n" ) { close(IP); cheat("Multiple Click - IP Add", $id); } } close(IP); open(APP, ">>$DDIR/ips/$rm") || err($!, "$DDIR/ips/$rm"); print APP "$ENV{'REMOTE_ADDR'}|$id\n"; close(APP); } sub check_cookie { my $id = shift; cheat("Multiple Click - Cookie", $id) if( $ENV{'HTTP_COOKIE'} =~ /arp-$id=/ ); set_cookie( $id, $VAR::ET ); } sub set_cookie { my ( $id, $exp ) = @_; my %mths = ( 0 => 'Jan', 1 => 'Feb', 2 => 'Mar', 3 => 'Apr', 4 => 'May', 5 => 'Jun', 6 => 'Jul', 7 => 'Aug', 8 => 'Sep', 9 => 'Oct', 10 => 'Nov', 11 => 'Dec'); my %days = ( 0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', 3 => 'Wednesday', 4 => 'Thursday', 5 => 'Friday', 6 => 'Saturday'); my @date = gmtime(time + $exp); my $year = substr($date[5] + 1900, 2, 2); my $mins = length($date[1]) < 2 ? "0" . $date[1] : $date[1]; my $secs = length($date[0]) < 2 ? "0" . $date[0] : $date[0]; print "HTTP/1.0 302 Found\n" if( $NT ); print "Set-Cookie: arp-$id=" . time . "; Expires=$days{$date[6]}, $date[3]-$mths{$date[4]}-$year $date[2]:$mins:$secs GMT\n"; } sub newsession { my @chars = ('a'..'z', 'A'..'Z', '0'..'9'); my $time = time; my $str = $time; $str =~ tr/0-9//s; for( 0..9 ) { my $rand = $chars[ int(rand($#chars + 1)) ]; $str =~ s/$_/$rand/g; } fwrite("$DDIR/ses/$str", $time); return $str; } sub checkses { my( $ses, $id ) = @_; if( -e "$DDIR/ses/$ses" ) { my $time = (stat("$DDIR/ses/$ses"))[9]; unlink("$DDIR/ses/$ses") || err($!, "ses/$ses"); cheat("Expired Gateway Session", $id) if(time - $time > $VAR::ST); } else { cheat("Invalid Gateway Session", $id); } } sub getage { my $file = shift; return time - (stat($file))[9]; } sub repair { my $id = shift; my @md = split(/\|/, freadline("$DDIR/members/$id.dat")); fwrite("$DDIR/members/$id.cnt", join('|', 0, 0, 0, 0, $md[11], $md[12], $md[8], $md[20], time)); $md[10] = time; fwrite("$DDIR/members/$id.dat", join('|', @md)); checktime() if( !$OPT::CRN ); print "Location: $VAR::FU\n\n"; exit; } sub freadline { my($file) = shift; open(FILE, $file) || err($!, $file); flock(FILE, 1); my $line = ; flock(FILE, 8); close(FILE); chomp($line); return $line; } sub fappend { my($file, $data) = @_; open(FILE, ">>$file") || err($!, $file); flock(FILE, 2); print FILE $data; flock(FILE, 8); close(FILE); chmod(0666, $file) if( -O $file ); } sub fwrite { my($file, $data) = @_; open(FILE, ">$file") || err($!, $file); flock(FILE, 2); print FILE $data; flock(FILE, 8); close(FILE); chmod(0666, $file) if( -O $file ); } sub htmlname { my $name = lc( shift ); $name =~ s/[^a-zA-Z0-9_]//g; return $name; } sub err { my($cause, $file) = @_; my @from = caller(1); chomp($cause); print "Content-type: text/html\n\n"; print "
\n";
  print "A CGI ERROR HAS OCCURRED\n========================\n";
  print "Error Message     :  $cause\n";   
  print "Accessing File    :  $file\n";
  print "Calling Function  :  $from[3] from $from[1]" if( $from[3] ne "" );
  exit;
}