Grizzly Century - Oct 2, 2004

Back to Event Page|Previous Page|Next Page

P041002095605055dk.jpg
Click Photo to Order
P041002095608056dk.jpg
Click Photo to Order
P041002095608057dk.jpg
Click Photo to Order
#!/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 # adcycle.cgi - the script that serves the media #use strict; use AdLog; use AdEnv; my $env=AdEnv->new; use CGI 'cgi'; my $query=CGI->new; use AdConfig; my $config=AdConfig->new; $config->connect; my $dbh=$config->get_dbh; # IMPORTANT VARS my $sth; my $FOUND; my @C; my $k; my @camp; my @cp; my @df; my @ky_cp; my @ky_df; my @log; my @manban; my $match; my $selected_cp=0; my $banner; my $url; my $status; my $rc; 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 $remote_host=$env->get_remote_host; my $refer=$env->get_refer; my $hour=$env->get_hour; my $remote=$env->get_remote; my $agent=$env->get_agent; my $datestamp=$env->get_datestamp; my $querystring=$env->get_query; my @FORMAT; $FORMAT[0]=$config->get_format->[0]; $FORMAT[1]=$config->get_format->[1]; $FORMAT[2]=$config->get_format->[2]; $FORMAT[3]=$config->get_format->[3]; $FORMAT[4]=$config->get_format->[4]; $FORMAT[5]=$config->get_format->[5]; $FORMAT[6]=$config->get_format->[6]; $FORMAT[7]=$config->get_format->[7]; my $dat2=$banner_qty*9; # IMPORTANT VARS # GENERATE RANDOM NUMBER srand(); my $RANDOM=int(rand(1000))+1; # GENERATE RANDOM NUMBER # GET TOKENS my $pool=1; $pool=$query->param('group'); if($pool+0==0){$pool=1;} my $id=1; $id=$query->param('id').""; if($id+0==0){$id=$RANDOM;} my $media=1; $media=$query->param('media')+0; if($media+0==0){$media=1;} my $delivery=""; $delivery=$query->param('delivery').""; my $campaign=""; $campaign=$query->param('campaign').""; my $key=""; $key=$query->param('keywords').""; my $BANNER_OUTPUT="NO"; my $TOTAL=0; my $ky_TOTAL=0; # GET TOKENS # WORK THE COOKIE my $new_cookie=$cookie; if(index($cookie,"ADCYCLE\.COM")!=-1){ my $start=index($cookie,"ADCYCLE\.COM"); my $end=index($cookie,"ADCYCLE|"); $cookie=substr($cookie,$start,$end-$start); @C=split(/\|/,$cookie); } $FOUND=0; if($C[22]!=$hour && length($cookie)>15){ for($k=1;$k<25;$k++){ $C[$k]=""; } } # media parameters my $mtype=$FORMAT[$media]; my ($width,$height)=split(/x/,$mtype); # set the lock $sth = $dbh->do("SELECT GET_LOCK('cplock',5)"); # global vars my $good_campaign=1; my $ADLOG="NO"; my $cp_datum; my $df_datum; my $ky_cp_datum; my $ky_df_datum; my $DF_RAND; my $counter; my @scram; my @actual; my $last_scram; my $loop=0; start: @camp=0; $cp_datum=0; $df_datum=0; $ky_cp_datum=0; $ky_df_datum=0; $DF_RAND=0; $counter=0; @scram=0; @actual=0; $last_scram=0; $ADLOG="NO"; # get the campaign list if(length($campaign)>1){ $sth = $dbh->prepare("SELECT * FROM cp WHERE C0='$campaign' && C11=$media && C12>=1.0 && C13>=1.0"); $sth->execute; }else{ $sth = $dbh->prepare("SELECT * FROM cp WHERE C11=$media && C12>=1.0 && C13>=1.0 && PL$pool > 0 ORDER BY C4 DESC"); $sth->execute; } while(@camp = $sth->fetchrow_array){ $counter++; $match=1; $good_campaign=1; if($camp[10]+0!=0){ for($k=1;$k<20;$k++){ if($C[$k] eq $camp[0]){ $match++; } } } if($hour!=$camp[41]){ $ADLOG="YES"; } if($camp[49] eq "RICH" && $delivery ne "iframe" && $delivery ne "ssi"){ $good_campaign=0; } my $display_ck="YES"; if(length($cookie)<5 && $camp[75] eq "ON"){ $display_ck="NO"; $good_campaign=0; } if($good_campaign==1 && length($camp[26])>2){ for(my $k=26;$k<31;$k++){ my $ip_length=length($camp[$k]); my $temp_remote=substr($remote,0,$ip_length); if($camp[$k] eq $temp_remote && $ip_length>2){ $good_campaign=0; } } } if($good_campaign==1 && length($camp[31])>2){ $good_campaign=0; for(my $k=31;$k<36;$k++){ my $ip_length=length($camp[$k]); my $temp_remote=substr($remote,0,$ip_length); if($camp[$k] eq $temp_remote && $ip_length>2){ $good_campaign=1; } } } if($good_campaign==1 && length($camp[50])>2){ for(my $k=50;$k<55;$k++){ my $ip_length=length($camp[$k]); my $rh_length=length($remote_host); my $temp_remote=substr($remote,$rh_length-$ip_length,$ip_length); if($camp[$k] eq $temp_remote && $ip_length>2){ $good_campaign=0; } } } if($good_campaign==1 && length($camp[55])>2){ $good_campaign=0; for(my $k=55;$k<60;$k++){ my $ip_length=length($camp[$k]); my $rh_length=length($remote_host); my $temp_remote=substr($remote,$rh_length-$ip_length,$ip_length); if($camp[$k] eq $temp_remote && $ip_length>2){ $good_campaign=1; } } } if($good_campaign==1 && length($camp[60])>2){ for(my $k=60;$k<65;$k++){ if(length($camp[$k])>2 && index($refer,$camp[$k])!=-1){ $good_campaign=0; } } } if($good_campaign==1 && length($camp[65])>2){ $good_campaign=0; for(my $k=65;$k<75;$k++){ if(length($camp[$k])>2 && index($refer,$camp[$k])!=-1){ $good_campaign=1; } } } ##NEW if(($match<=$camp[10] || $camp[10]==0) && $good_campaign==1 && $ADLOG eq "NO"){ #KY my $FOUND_KEY=0; if(length($key)>0){ if(index($camp[7],"KEYWORDS")!=-1){ my @keys=split(/\,/,$camp[8]); my $skeys=@keys; my $stop_search="NO"; for(my $h=0;$h<$skeys;$h++){ if(index($key,$keys[$h])!=-1 && length($keys[$h])>1 && $stop_search eq "NO"){ if($camp[4]>0){ for($k=0;$k<90+$dat2;$k++){ $ky_cp[$ky_cp_datum][$k]=$camp[$k]; } $ky_TOTAL=$ky_TOTAL+$camp[4]; $ky_cp_datum++; }else{ for($k=0;$k<90+$dat2;$k++){ $ky_df[$ky_df_datum][$k]=$camp[$k]; } $ky_df_datum++; } $FOUND=1; $stop_search="YES"; } } } } #KY if(index($camp[7],"KEYWORDS")==-1){ if($camp[4]>0){ for($k=0;$k<90+$dat2;$k++){ $cp[$cp_datum][$k]=$camp[$k]; } $TOTAL=$TOTAL+$camp[4]; if($cp_datum==0){ $scram[0]=$cp_datum; $actual[0]=$camp[48]; }else{ my $set="NO"; my $max=0; my $value=0; for($k=0;$k<$cp_datum;$k++){ if($camp[48] > $actual[$k]){ $max=$k; $value=$camp[48]; } } if($value < 1){ unshift(@scram,$cp_datum); unshift(@actual,$camp[48]); }else{ splice(@scram,$max+1,0,$cp_datum); splice(@actual,$max+1,0,$value); } }#end of else loop $cp_datum++; }else{ for($k=0;$k<90+$dat2;$k++){ $df[$df_datum][$k]=$camp[$k]; } $df_datum++; } $FOUND=1; } } ##NEW }#end while $sth->finish(); ### NORMAL PART ### # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if($ADLOG eq "YES" && $loop!=1){ AdLog::rotate_logs($env,$config,$query); $loop=1; goto start; #yes, the dreaded goto... the cheap patch } my $old_value=0; my $FOUND_cp=0; my @rank=0; my $run=0; my $done="NO"; @camp=0; ## FIGURE OUT WHICH CAMPAIGN TO DISPLAY if($ky_cp_datum>0){ #then a campaign will be displayed $run=0; $FOUND_cp=0; @rank=0; my $MULT=1000/$ky_TOTAL; for($k=0;$k<$ky_cp_datum;$k++){ $rank[$k]=$run+int($ky_cp[$k][4]*$MULT); $run=$rank[$k]+1; if($rank[$k]>=$RANDOM && $rank[$k]>=$old_value && $FOUND_cp!=10){ $selected_cp=$k; $FOUND_cp=10; $done="YES"; } $old_value=$rank[$k]; } for($k=0;$k<90+$dat2;$k++){ $camp[$k]=$ky_cp[$selected_cp][$k]; } } if($ky_df_datum>0 && $done ne "YES"){#default banner $DF_RAND=int(rand($ky_df_datum)); for($k=0;$k<90+$dat2;$k++){ $camp[$k]=$ky_df[$DF_RAND][$k]; } $done="YES" } if($cp_datum>0 && $done ne "YES"){ #then a campaign will be displayed my $match_count=0; my $flex_count=0; my $flex_stop=0; my @match_array; my $cp_actual; $run=0; $FOUND_cp=0; my $MULT=1000/$TOTAL; for($k=19;$k>14;$k--){ if(length($C[$k])==4){ $match_array[$match_count]=$C[$k]; $match_count++; } } while($match_count>=0 && $FOUND_cp!=10){ my $run=0; my $rank=0; for($k=0;$k<$cp_datum;$k++){ $flex_stop=1; if($flex_count==0){ $rank=$run+int($cp[$k][4]*$MULT); $run=$rank+1; if($rank>=$RANDOM && $rank>=$old_value){ $flex_stop=0; $flex_count++; $cp_actual=$k; $k=$cp_datum; } }else{ $flex_stop=0; $cp_actual=$scram[$k]; } if($flex_stop==0 && $FOUND_cp!=10){ my $match_cp=0; for(my $p=0;$p<$match_count;$p++){ if($match_array[$p] eq $cp[$cp_actual][0]){ $match_cp++; } } if($match_cp==0){ $selected_cp=$cp_actual; $FOUND_cp=10; $done="YES" } } $old_value=$rank; }#end for loop $match_count--; } for($k=0;$k<90+$dat2;$k++){ $camp[$k]=$cp[$selected_cp][$k]; } } $DF_RAND=int(rand($df_datum)); if($df_datum>0 && $done ne "YES"){#default banner for($k=0;$k<90+$dat2;$k++){ $camp[$k]=$df[$DF_RAND][$k]; } $done="YES-DEFAULT" } ## FIGURE OUT WHICH CAMPAIGN TO DISPLAY #### IF MATCH WAS FOUND #### if($FOUND==1){ my $cp_list=""; srand(); my $BNRAND=int(rand(100)); my $INSIDE=0; my $total_banner=0; for($k=0;$k<$banner_qty;$k++){ my $dat3=$k*9; $total_banner=$total_banner+$camp[$dat3+81]; } my $MULT=100/$total_banner; my $RUN=0; my @bannerx=0; for($k=0;$k<$banner_qty;$k++){ my $dat3=$k*9; if($camp[$dat3+81]!=0){ $bannerx[$k]=$RUN+($camp[$dat3+81]*$MULT); $RUN=$bannerx[$k]; }else{ $bannerx[$k]=0; } } #select banner for($k=0;$k<$banner_qty;$k++){ my $dat3=$k*9; if($BNRAND < $bannerx[$k] && $INSIDE==0){ $banner=$k; $camp[84+$dat3]++; $camp[86+$dat3]++; my $cp_num1=$k+1; my $cp_num2=$k+1; $url=$camp[82+$dat3]; $cp_list=$cp_list."BN$cp_num1\_IMP_HISTORY=$camp[84+$dat3],BN$cp_num2\_IMP_TEMP=$camp[86+$dat3],"; $INSIDE=1; } } #select banner my $dat=$banner*9; $camp[12]=$camp[12]-1.0; $camp[14]++; $camp[20]++; $camp[22]++; $camp[24]++; $camp[46]++; my $turbo=$BNRAND+2; $cp_list=$cp_list."C12=$camp[12],C20=$camp[20],C22=$camp[22],C24=$camp[24],C46=$camp[46],C14=$camp[14],C48='$turbo'"; $sth=$dbh->do("UPDATE cp SET $cp_list WHERE C0='$camp[0]'"); $sth = $dbh->do("SELECT RELEASE_LOCK('cplock')"); $banner++;#id build $status="GOOD"; if(length($cookie)>1){$status=$status."-C";} #$status=$status."|$df_datum:$DF_RAND|$cp_datum|$done|"; ################ $agent=~s/'//g; $refer=~s/'//g; #my $log_list="'$remote','$id','$pool','$camp[0]','$banner','$media','$agent','$status','$datestamp'"; my $col_list; $col_list=$col_list.$dbh->quote($remote).","; $col_list=$col_list.$dbh->quote($id).","; $col_list=$col_list.$dbh->quote($pool).","; $col_list=$col_list.$dbh->quote($camp[0]).","; $col_list=$col_list.$dbh->quote($banner).","; $col_list=$col_list.$dbh->quote($media).","; $col_list=$col_list.$dbh->quote($agent).","; $col_list=$col_list.$dbh->quote($status).","; $col_list=$col_list.$dbh->quote($datestamp).","; chop($col_list); $sth = $dbh->do("INSERT INTO iplog (remote,pg,pool,cid,banner,media,agent,status,stime) VALUES ($col_list)"); if($camp[36] eq "ON"){ if(index($refer,"\?")!=-1){ my $sq=index($refer,"\?"); $refer=substr($refer,0,$sq); } #my $log_list="'$camp[0]','1','$banner','$remote','$pool','$refer','$agent','$datestamp'"; my $col_list; $col_list=$col_list.$dbh->quote($camp[0]).","; $col_list=$col_list.$dbh->quote("1").","; $col_list=$col_list.$dbh->quote($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 INTO real_log (cid,type,banner,remote,pool,refer,agent,stamp) VALUES ($col_list)"); } # 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 print "Set-Cookie: ADCYCLE.COM=|$C[2]|$C[3]|$C[4]|$C[5]|$C[6]|$C[7]|$C[8]|$C[9]|$C[10]|$C[11]|$C[12]|$C[13]|$C[14]|$C[15]|$C[16]|$C[17]|$C[18]|$C[19]|$camp[0]|$banner|$id|$hour|ADCYCLE|\n"; $url=~s/IDNUMBER+/$id/g; ## REPEATED AGAIN ABOVE if($delivery eq "iframe" || $delivery eq "ssi"){############## # RICH MEDIA DELIVERY my($on_off,$border,$align,$target,$alt)=split(/\|/,$camp[$dat+88]); my $optional=$camp[$dat+89]; $optional=~s/"/\"/g; $optional=~s/\r\n//g; $optional=~s/IDNUMBER+/$id/g; my $temp_url=$camp[82+$dat]; $temp_url=~s/IDNUMBER+/$id/g; if($on_off eq "AUTO"){## START AUTO my $bhref; my $tget; my $algn; my $ad_code; if($target ne "NONE"){$tget=" target=\"$target\"";} if(length($optional)>1){$bhref="$optional";} if($align ne "NONE" && $align ne "CENTER"){$algn=" align=\"$align\"";} $ad_code=qq~
$bhref~; if($align eq "CENTER"){$ad_code="
".$ad_code."
";} $ad_code="".$ad_code.""; print "Cache-Control: no-cache\n"; print "Pragma: no-cache\n"; print "Expires: 0\n"; print "Content-Type: text/html\n\n"; print qq~$ad_code\n~; if($delivery eq "ssi"){ print qq~ ~; } }else{#for auto $sth = $dbh->prepare("SELECT BANNER$banner FROM banners WHERE CID='$camp[0]'"); $sth->execute; while(@log = $sth->fetchrow_array){ @manban=@log; } $sth->finish(); $manban[0]=~s/"/\"/g; $manban[0]=~s/\&\#39\;/\'/g; $manban[0]=~s/IDNUMBER+/$id/g; print "Cache-Control: no-cache\n"; print "Pragma: no-cache\n"; print "Expires: 0\n"; print "Content-Type: text/html\n\n"; print qq~$manban[0]\n~; if($delivery eq "ssi"){ print qq~ ~; } }## end of auto }else{ if(length($url)>7){ print "Cache-Control: no-cache\n"; print "Pragma: no-cache\n"; print "Expires: 0\n"; print "Location: $url\n\n"; }else{ print "Cache-Control: no-cache\n"; print "Pragma: no-cache\n"; print "Expires: 0\n"; print "Location: ".$env->get_images_url."/banner$media\.gif\n\n"; } }#rich end $dbh->disconnect; exit(0); #end of normal delivery }else{#end good display #nothing found, send dead adcycle banner if($delivery eq "iframe" || $delivery eq "ssi"){ print "Cache-Control: no-cache\n"; print "Pragma: no-cache\n"; print "Expires: 0\n"; print "Content-Type: text/html\n\n"; print qq~~; }else{ print "Cache-Control: no-cache\n"; print "Pragma: no-cache\n"; print "Expires: 0\n"; print "Location: $images_url/banner$media\.gif\n\n"; } #nothing found, send dead adcycle banner $status="DEAD BANNER"; if(length($cookie)>1){$status=$status."-C";} $status=$status."|$df_datum:$DF_RAND|$cp_datum|$done|"; my $col_list; $col_list=$col_list.$dbh->quote($remote).","; $col_list=$col_list.$dbh->quote($id).","; $col_list=$col_list.$dbh->quote($pool).","; $col_list=$col_list.$dbh->quote($camp[0]).","; $col_list=$col_list.$dbh->quote($banner).","; $col_list=$col_list.$dbh->quote($media).","; $col_list=$col_list.$dbh->quote($agent).","; $col_list=$col_list.$dbh->quote($status).","; $col_list=$col_list.$dbh->quote($datestamp).","; chop($col_list); $sth = $dbh->do("INSERT INTO iplog (remote,pg,pool,cid,banner,media,agent,status,stime) VALUES ($col_list)"); }#end good display $sth = $dbh->do("SELECT RELEASE_LOCK('cplock')"); $dbh->disconnect; exit(0); # Copyright (c) 1999,2000 AdCycle.com All rights reserved. # http://www.adcycle.com - download the lastest version of adcycle

Page 30 of 79