#!/usr/bin/perl # ******* Update the header "#!/usr/bin/perl" to point to perl on your system ******* # ******* In most cases the default will work. ******* # Copyright (c) 1999,2000 AdCycle.com All rights reserved. # http://www.adcycle.com - download the lastest version of adcycle # click.cgi - the script that deals with media clicks [with FastCGI!] ##################################################################### #### Installation Notes for click.cgi #### ##################################################################### # # * Update first line for perl5 path (usually the default will work) # * No other mods are required for this file # ################################################################### #### End Installation Notes #### ################################################################### #use strict; use CGI::Carp 'fatalsToBrowser'; use lib '.'; use CGI; use CGI::Fast; use AdLog; use AdEnv; use AdConfig; my $config=AdConfig->new; $config->connect; my $dbh=$config->get_dbh; my $use_fastcgi=$config->get_use_fastcgi; my $last=0; my $use_delayed_insert = $config->get_use_delayed_insert; # THE BEGINNING OF THE FASTCGI REQUEST LOOP FASTCGI_LOOP: while (!$last) { my $query; if ($use_fastcgi) { $query = CGI::Fast->new; } else { $query = CGI->new; $last=1; } my $env = AdEnv->new; srand(); my $RANDOM=int(rand(1000)); my $rc; my $pool=$query->param('g')+0; my $id=$query->param('id').""; my $key=$query->param('k').""; my $cid=$query->param('c').""; my $banner=$query->param('b').""; my $images_url=$config->get_images_url; my $banner_qty=$config->get_banner_qty; my $cgi_bin_url=$config->get_cgi_bin_url; my $cookie=$env->get_cookie; my $hour=$env->get_hour; my $remote=$env->get_remote; my $agent=$env->get_agent; my $refer=$env->get_refer; my $datestamp=$env->get_datestamp; my $querystring=$env->get_query; my @camp; my @log; # SET THE LOCK my $sth; ##$sth = $dbh->do("SELECT GET_LOCK('cplock',5)"); # SET THE LOCK my @C; my $id_c; my $cid_c; my $banner_c; my $hour_c; my $before_c=$cookie; my $found_by="CLICK PROBLEM"; if(index($cookie,'FASTADCYCLE')!=-1){ my $start=index($cookie,'FASTADCYCLE'); my $end=index($cookie,'FASTADCYCLE|'); $cookie=substr($cookie,$start,$end-$start); @C=split(/\|/,$cookie); $id_c=$C[21]; $banner_c=$C[20]; $cid_c=$C[19]; $hour_c=$C[22]; } ## FORCE if(length($cid)==0 || length($cid) > 4 || $banner < 1){ ## force check if(length($cid_c)>2 && $banner_c <= $banner_qty && $id eq $id_c && $banner < 1){ $cid=$cid_c; $banner=$banner_c; $found_by="COOKIE"; } # my $log_list="'$remote','$id','$pool','$cid','$last_banner','$media','$agent','$found_by','$datestamp'"; if($banner < 1 || length($cid)==0){ my $FOUND=0; my @ip; $sth = $dbh->prepare("SELECT * FROM iplog WHERE remote='$remote' && pg='$id' ORDER BY stime DESC"); $sth->execute; while($FOUND==0 && (@ip = $sth->fetchrow_array)){ if(length($ip[0])>0 && $ip[5]!=99){ $FOUND=1; $banner=$ip[4]; $cid=$ip[3]; $found_by="IP1"; } } $sth->finish(); } # my $log_list="'$remote','$id','$pool','$cid','$last_banner','$media','$agent','$found_by','$datestamp'"; if($banner < 1 || length($cid)==0){ my $FOUND=0; my @ip; $sth = $dbh->prepare("SELECT * FROM iplog WHERE agent='$agent' && pg='$id' ORDER BY stime DESC"); $sth->execute; while($FOUND==0 && (@ip = $sth->fetchrow_array)){ if(length($ip[0])>0 && $ip[5]!=99){ $FOUND=1; $banner=$ip[4]; $cid=$ip[3]; $found_by="IP2"; } } $sth->finish(); } }else{ $found_by="JAVASCRIPT"; } ##end force check my $actual_banner=$banner; if($banner > 0){ $banner--; my $dat=$banner*9; $sth = $dbh->prepare("SELECT * FROM cp WHERE C0='$cid' AND C2='ON'"); $sth->execute; while(@log = $sth->fetchrow_array){ @camp=@log; } $sth->finish(); my $bad_click="NO"; if($camp[76] eq "ON" && ($remote eq $camp[77] || $remote eq $camp[78])){ $bad_click="YES"; } if($bad_click eq "NO"){ $camp[13]--; $camp[15]++; $camp[21]++; $camp[23]++; $camp[25]++; $camp[47]++; $camp[85+$dat]++; $camp[87+$dat]++; my $cp_num1=85+$dat; my $cp_num2=87+$dat; my $ban_dat=$banner+1; my $cp_list; $cp_list=$cp_list."BN$ban_dat\_CLI_HISTORY=$camp[85+$dat],BN$ban_dat\_CLI_TEMP=$camp[87+$dat],"; $cp_list=$cp_list."C13='$camp[13]',C21='$camp[21]',C23='$camp[23]',C25='$camp[25]',C47='$camp[47]',C15='$camp[15]',C77='$camp[78]',C78='$remote'"; $sth=$dbh->do("UPDATE cp SET $cp_list WHERE C0='$cid'"); }#end bad click $agent=~s/'//g; $refer=~s/'//g; my $col_list; $col_list=$col_list.$dbh->quote($remote).","; $col_list=$col_list.$dbh->quote($id).","; $col_list=$col_list.$dbh->quote("0").","; $col_list=$col_list.$dbh->quote($cid).","; $col_list=$col_list.$dbh->quote($actual_banner).","; $col_list=$col_list.$dbh->quote("99").","; $col_list=$col_list.$dbh->quote($agent).","; $col_list=$col_list.$dbh->quote($found_by).","; $col_list=$col_list.$dbh->quote($datestamp).","; chop($col_list); $sth = $dbh->do("INSERT ${\($use_delayed_insert ? 'DELAYED':'')} INTO iplog (remote,pg,pool,cid,banner,media,agent,status,stime) VALUES ($col_list)"); if($camp[38] eq "ON"){ if(index($refer,"\?")!=-1){ my $sq=index($refer,"\?"); $refer=substr($refer,0,$sq); } my $col_list; $col_list=$col_list.$dbh->quote($camp[0]).","; $col_list=$col_list.$dbh->quote("0").","; $col_list=$col_list.$dbh->quote($actual_banner).","; $col_list=$col_list.$dbh->quote($remote).","; $col_list=$col_list.$dbh->quote($pool).","; $col_list=$col_list.$dbh->quote($refer).","; $col_list=$col_list.$dbh->quote($agent).","; $col_list=$col_list.$dbh->quote($datestamp).","; chop($col_list); $sth = $dbh->do("INSERT ${\($use_delayed_insert ? 'DELAYED':'')} INTO real_log (cid,type,banner,remote,pool,refer,agent,stamp) VALUES ($col_list)"); } $camp[83+$dat]=~s/IDNUMBER+/$id/g; print "Location: $camp[83+$dat]\n\n"; }else{ my $col_list; $col_list=$col_list.$dbh->quote($remote).","; $col_list=$col_list.$dbh->quote($id).","; $col_list=$col_list.$dbh->quote("0").","; $col_list=$col_list.$dbh->quote($cid).","; $col_list=$col_list.$dbh->quote($actual_banner).","; $col_list=$col_list.$dbh->quote("99").","; $col_list=$col_list.$dbh->quote($agent).","; $col_list=$col_list.$dbh->quote($found_by).","; $col_list=$col_list.$dbh->quote($datestamp).","; chop($col_list); $sth = $dbh->do("INSERT ${\($use_delayed_insert ? 'DELAYED':'')} INTO iplog (remote,pg,pool,cid,banner,media,agent,status,stime) VALUES ($col_list)"); print "Location: http://www.ad.server.pl/fastadcycle/click-error.html\n\n"; } ##$sth = $dbh->do("SELECT RELEASE_LOCK('cplock')"); # THE END OF THE FASTCGI REQUEST LOOP } $dbh->disconnect; exit(0); # Copyright (c) 1999,2000 AdCycle.com All rights reserved. # http://www.adcycle.com - download the lastest version of adcycle