#!/usr/bin/perl ####################################### # MeySoft Banner Manager - Version 2.60 # # Last Update 10-NOV-2000 # # Copyright (c) 2000 MeySoft # Author: Jeffrey L. Meyer # WebMaster@MeySoft.com # # THIS HEADER MUST REMAIN INTACT ########################################################################## # If you make ANY changes, other than the perl path, MeySoft cannot accept # responsibilty for any adverse affects, and do not expect MeySoft to fix # it for you. If you make any modifications at all below the perl line # above, you are in violation of the license agreement and forfeit any # and all rights under the license agreement, and you will lose the right # to technical support. Do not expect our help nor any refund if you # violate the license agreement. ########################################################################## require "bm260fn.cgi"; &load_vars; require "flush.pl"; require "bm260_sql.lib"; alarm(600); @bans=(); @BAN=(); @CTRL=(); @ACCT=(); @PAGE=(); @CLICK=(); $acct_num=0; $style=""; $loglists=0; $logip=0; $data=$ENV{'QUERY_STRING'}; $data=~ s/\&\;/\&/g; @fields = split(/&/,$data); foreach $fields(@fields){ ($field_name,$field_val)=split(/=/,$fields); $field_val=~ s/\+/ /g; $field_val=~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; $field_val=~ s/\,/./g; $field_val=~ s/\&//g; $field_val=~ s/\"//g; $field_val=~ s/\'//g; $field_val=~ s/\`//g; $field_val=~ s/\*//g; $field_val=~ s/\\//g; $field_val=~ s/ //g; $field_val=~ s///g; $field_val=~ s/<([^>]|\n)*>//g; $DATA{$field_name}=$field_val; } if($DATA{'debug'}){ $debug=1; print "Content-type: text/plain\n\n"; }else{ $debug=0; } if($debug){print "QUERY: $ENV{'QUERY_STRING'}\n"; print "acct_num=$DATA{'a'} style=$DATA{'s'}\n"; } if($DATA{'s'} eq ''){ &serr("Missing style field ID---QUERY: $ENV{'QUERY_STRING'}\n"); &end; # REQUIRED QUERY FIELD }else{ $style="$DATA{'s'}"; } if($DATA{'a'} eq ''){ &serr("Missing aid field ID---QUERY: $ENV{'QUERY_STRING'}\n"); &end; }else{ $acct_num="$DATA{'a'}"; } if($acct_num =~ /p/){ ($acct_num,$page)=split(/p/,$acct_num); if($page <1){ $page=1; } }else{ $page=1; } if($acct_num <1){$acct_num=1;} #if(($page>1)&&($page<3)){ sleep 1;} #if(($page>3)&&($page<5)){ sleep 1;} $dbp="$CFG{'acct_dir'}/$style"; $si=&style_index("$style"); $aid="$acct_num-$si"; if($page >10){ $page=10;} &get_date; if($debug){&end;} &sql_connect; &sql_getCTRLData("$style"); if(($acct_num > $CTRL[2])||($acct_num < 1)){ $acct_num=1; &send_dflt; &end; } $reload=0; $rid="$ENV{'REMOTE_ADDR'}"; if((length($rid) > 16)||(length($rid)<1)){ $rid="_blank_"; $ENV{'REMOTE_ADDR'}="_blank_"; } if($logip==1){ open(LOG,">>script_error.log") or die "$!"; flock(LOG,2); print LOG "REQ: $rid $date\n"; flock(LOG,8); close(LOG); } $click_id="C_" . "$acct_num" . "_$page" . "_$rid"; if($debug){ print "CLICK ID: $click_id\n";} if($CFG{'block_reloads'}==1){ $cb=&sql_getClickPTR("$style","$click_id"); if($cb != -1){ if($CLICK[5] > 0){ if($CLICK[2] > $CTRL[2]){ $CLICK[2]=0; } $reload=1; if($CLICK[2]<1){$CLICK[2]="1";} &sql_getBannerInfo("$CLICK[2]-$si"); #MUST HAVE #-# FORMAT &send_image("$CLICK[2]"); &end; } } } if(&is_swap_due==1){ $tp="swap"; &pick_ban; }else{ $tp="paid"; &pick_ban; } &end; # END # sub pick_ban{ &sql_getAccountInfo("$aid"); if($ACCT[12] eq ''){ print "Location: $CFG{'images'}/deleted.gif\n\n"; &end; } &sql_getPageInfo("$aid","$page"); $PAGE[14]="$ENV{'HTTP_REFERER'}"; $PAGE[2]+=1; $PAGE[4]+=1; $PAGE[6]+=1; &sql_updatePageInfo("$aid","$page"); if($tp eq 'paid'){ $ACCT[14]+=1; }else{ $ACCT[15]+=1; } if($CFG{'credit_based'}==1){ if($ACCT[12] ne 'click'){ $ACCT[16] += $CFG{'credit_earn'}; } } $rslt=0; &sql_updateAccountInfo("$aid"); @bans=(); $rslt=&sql_getPriorityList("$style"); if($loglists==1){ open(LOG,">>script_error.log") or die "$!"; print LOG "RSLT_P: \'$rslt\' $style $tp\n"; foreach(@bans){ print LOG "$_,";}print LOG "\n"; } if($rslt<10){ $rslt=&sql_getRotationList("$style","$tp"); # Fetches 100 MAX if($loglists==1){print LOG "RSLT_1: \'$rslt\' $style $tp\n"; foreach(@bans){ print LOG "$_,";}print LOG "\n"; } if(($tp eq 'paid')&&($rslt <10)){ $rslt=&sql_getRotationList("$style","swap"); if($loglists==1){ print LOG "RSLT_2: \'$rslt\' $style $tp\n"; foreach(@bans){ print LOG "$_,";}print LOG "\n"; } } if(($tp eq 'swap')&&($rslt <10)){ $rslt=&sql_getRotationList("$style","paid"); if($loglists==1){ print LOG "RSLT_3: \'$rslt\' $style $tp \n"; foreach(@bans){ print LOG "$_,";}print LOG "\n"; } } if($rslt <10){ &sql_flush; &sql_RescanDatabase("$style","NA"); sleep 1; $rslt=&sql_getRotationList("$style","$tp"); if($loglists==1){ print LOG "RSLT_4R: \'$rslt\' $style $tp \n"; foreach(@bans){ print LOG "$_,";}print LOG "\n"; } if(($tp eq 'paid')&&($rslt <10)){ $rslt=&sql_getRotationList("$style","swap"); if($loglists==1){ print LOG "RSLT_5R: \'$rslt\' $style $tp \n"; foreach(@bans){ print LOG "$_,";}print LOG "\n"; } } if(($tp eq 'swap')&&($rslt <10)){ $rslt=&sql_getRotationList("$style","paid"); if($loglists==1){ print LOG "RSLT_6R: \'$rslt\' $style $tp\n"; foreach(@bans){ print LOG "$_,";}print LOG "\n";} } } } &sql_getAccountInfo("$aid"); ############################ ## TARGET/BLOCK SELECTOR if($CFG{'use_targeting'}==1){ if($rslt > 0){ $fnd=0; $blocked=1; $targeted=0; ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); $loop2=0; $limit=$rslt; while((&is_target_site("$acct_num","$ban")==0)&&($loop2 < $limit)){ $loop2++; ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); } }else{ $banid="1-1"; # MEANS NO LIST WAS LOADED, SO SEND DEFAULT } }else{ ($banid,$cat)=split(/\:/,shift(@bans)); $blocked=0; $targeted=1; } ######################### if(($page==2)&&($rslt>2)){ ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); } if(($page==3)&&($rslt>3)){ ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); } if(($page==4)&&($rslt>4)){ ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); } if(($page==5)&&($rslt>5)){ ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); } if(($page==6)&&($rslt>6)){ ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); } if(($page==7)&&($rslt>7)){ ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); } if(($page==8)&&($rslt>8)){ ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); } if(($page==9)&&($rslt>9)){ ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); } if(($page==10)&&($rslt>10)){ ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($banid,$cat)=split(/\:/,shift(@bans)); ($ban,$bi)=split(/\-/,$banid); } if($loglists==1){ print LOG "BANSEL: $banid\n"; close(LOG); } if(($banid eq '')||(length($banid)<3)){ $banid="1-1"; } &sql_getBannerInfo("$banid"); if($BAN[16] >= $CFG{'credit_use'}){ $BAN[6]++; if($BAN[12] ne 'click'){ $BAN[16]=($BAN[16] - $CFG{'credit_use'}); } if($BAN[16] < $CFG{'credit_use'}){ if($BAN[16] < 0){ $BAN[16]=0; } $BAN[12]="$BAN[4]"; } }else{ $BAN[12]="$BAN[4]"; } &sql_updateRotationList("$style","$BAN[12]","$banid"); #marks ban as displayed &sql_getXStats("$style"); &sql_updateXStats("AddIMP","$style"); $didx=($wday * 2) + 24; $BAN[$didx]++; &sql_updateBannerInfo("$banid"); $ACCT[9]="$banid"; $ex_date=&get_expiration($CFG{'expiration_period'}); $ACCT[13]="$ex_date"; $CTRL[1]="$banid"; &sql_updateAccountInfo("$aid"); &sql_updateCTRLData("$style"); &send_image("$banid"); } ############# sub send_dflt{ $si=&style_index("$style"); $CTRL[1]=1; alarm(600); &sql_getAccountInfo("1-$si"); &sql_getBannerInfo("1-$si"); $ACCT[9]=0; $ACCT[15]++; $ACCT[6]++; if($CFG{'credit_based'}==1){ if($ACCT[12] eq 'swap'){ $ACCT[16]=($ACCT[16] + $CFG{'credit_earn'}); } } &get_date; &sql_getXStats("$style"); &sql_updateXStats("AddIMP","$style"); $didx=($wday * 2) + 24; $BAN[$didx]++; &sql_updateBannerInfo("1-$si"); $ACCT[9]="$ban"; &sql_updateAccountInfo("1-$si"); &send_image("1-$si"); } ################ sub is_swap_due{ if($CTRL[7] >= $CFG{'cycle_val'}){ $CTRL[7]=1; $CTRL[0]=1; }else{ $CTRL[0]=0; $CTRL[7]++; } if($CTRL[4]==0){ #if paid_qty is 0 $CTRL[0]=1; $CTRL[7]=$CFG{'cycle_val'}; } &sql_updateCTRLData("$style"); return $CTRL[0]; } ############### sub send_image{ my($banidnum)=@_; ($bannum,$bi)=split(/\-/,$banidnum); &sql_getBannerInfo("$banidnum"); $ext=substr($BAN[10],rindex($BAN[10],".")+1); if(($ext eq 'jpg')||($ext eq 'JPG')||($ext eq 'jpeg')||($ext eq 'JPEG')){ $mime="jpeg"; }else{ $mime="gif"; } if($ext eq 'N/A'){ $mime="gif"; $BAN[10]="$CFG{'images'}/missing.gif"; } if($reload==0){ $CLICK[0]="$style"; $CLICK[1]="$rid"; $CLICK[2]="$bannum"; $CLICK[4]="$ENV{'HTTP_REFERER'}"; $CLICK[5]=1; &sql_setClickPTR("$style","$click_id"); }else{ &sql_updateClickPTR("$style","$click_id"); } if($CFG{'use_upload'}==1){ if(-e "$dbp/bans/$bannum.$ext"){ if($CFG{'use_pragma_nocache'}==1){ print "Pragma: no-cache\n"; } print "Content-type: image/$mime\n\n"; open(IMG,"$dbp/bans/$bannum.$ext"); if(alarm()<=100){alarm(600);} binmode(IMG); binmode(STDOUT); binmode(STDIN); while(read IMG,$buffer,1){ print $buffer; } close(IMG); &flush(STDOUT); }else{ print "Location: $CFG{'images'}/missing.gif\n\n"; } }else{ print "Location: $BAN[10]\n\n"; } &sql_flush; } ######################## sub is_target_site{ local($anum,$bnum)=@_; if($anum==$bnum){ return 0; } alarm(600); @blocked_sites=(); $calling_site=""; $ban_site=""; $rst=0; if($CFG{'use_targeting'}==1){ $call_site="$ACCT[17]"; $call_site=~ s/ //g; $call_site=~ s/C//g; @blocked_sites=split(/\-/,$ACCT[23]); &sql_getBannerInfo("$bnum-$si"); @targets=split(/\-/,$BAN[22]); $ban_site="$BAN[17]"; $ban_site=~ s/ //g; $ban_site=~ s/C//g; ## Check Targets if(($targets[0] eq 'TALL')||($targets[0] eq 'ALL')){ $rst=1;} foreach $target(@targets){ if(alarm()<=20){alarm(600);} $target=~ s/(\n|\r)//g; $target=~ s/ //g; $target=~ s/T//g; if($target eq $call_site){ $rst=1; } } foreach $block(@blocked_sites){ if(alarm()<=20){alarm(600);} $block=~ s/ //g; $block=~ s/B//g; if("$block" eq "$ban_site"){ $rst=0; #BLOCKED SITE } } }else{ $rst=1; } if(($call_site eq 'N/A')||($ban_site eq 'N/A')){ $rst=1; } return $rst; } #### #EOS