Perl Coop Setup

Discussion in 'Co-op Advertising Network' started by a389951l, Mar 14, 2005.

  1. #1
    I just noticed that my ads on my perl pages are suddenly not showing up. I am looking into it but I wanted to see if anyone else was seeing this issue. I am using Clickdoc's wrapper setup.

    Thanks in advance...
     
    a389951l, Mar 14, 2005 IP
  2. jfontestad

    jfontestad Well-Known Member

    Messages:
    1,236
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    148
    #2
    Same here.
    I'm using the perl version from 1/10/2005 and all the sudden yesterday ads just stopped working. They work on one site (same cgi file) but not on others. Whats going on?
    All my websites are on a shared host therefor use the same IP address. I don't think that it's blocked because if it were I wouldn't be able to get ads on ANY of the websites, but I do have the ads on ONE website. Looking into it now.
    But if anyone else has problems with the cgi version please let me know or if you have a fix it would be even better.
    Thanks.
     
    jfontestad, Mar 15, 2005 IP
  3. jfontestad

    jfontestad Well-Known Member

    Messages:
    1,236
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    148
    #3
    also another thing i noticed is that for another website the ads ARE running, but its says ads not found when validating. any suggestions ?
     
    jfontestad, Mar 15, 2005 IP
  4. a389951l

    a389951l Must Create More Content

    Messages:
    1,885
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    140
    #4
    a389951l, Mar 15, 2005 IP
  5. jfontestad

    jfontestad Well-Known Member

    Messages:
    1,236
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    148
    #5
    I don't think it's the ip. It's just that the ads themselves are timing out. I don't know why, but when I try to access the .cgi file directly sometimes it doesn't even load, then when it does it loads as a download and asks "open" save" or cancel. I haven't touched anything in the past few weeks, so I don't know why this is happening. It's happening on 2 different servers from 2 different hosting companies. So I don't know if its the script or the ads server or just pure coincidence that over the same period of days the servers suddenly became disconfigured some how???
    anyway this is the .cgi file i'm using if anyone wants to take a look at it. As I said it works on ONE of my websites, but not on others.

    #!/usr/bin/perl
    
    # $Id: ad_network.cgi,v 1.11 2005/01/08 20:52:19 cvs Exp $
    # $Revision: 1.11 $
    
    use strict;
    use LWP::UserAgent;
    use Fcntl qw(:flock);
    use Socket;
    srand;
    
    use vars qw/$ad_file $ad_url $VERSION $ad_network $ad_count $ad_separator @ad_params/;
    
    # use ini subroutine with global vars, usefull for mod_perl
    sub init {
    
    ### User Variables
    
    # edit ad_file to set the path to the ad_network_ads.txt file
    # default is to look in the same directory as where the script runs
    # just create a blank file in that directory that is writable by the
    # web server process and this script will set it up properly
    $ad_file = 'ad_network_ads.txt';
    
    # change type= here to the type of link you wish to serve
    $ad_url = qq[http://ads.digitalpoint.com/network.php?b=$ENV{'HTTP_HOST'}&type=link];
    
    # set this to the number of ads you want to display on each page
    $ad_count = 5;
    
    # set this to the text or html you want to separate the ads ex: <br> |
    $ad_separator = ',&nbsp;';
    
    if($ENV{QUERY_STRING}) {
    my @tags = split(/;/,$ENV{QUERY_STRING});
    foreach(@tags) {
    my ($name,$value) = split(/=/,$_);
    $ad_count = $value if($name eq 'ad_count');
    $ad_separator = $value if($name eq 'ad_separator');
    }
    }
    $ad_count = 5 if($ad_count > 5);
    
    ### end User Variables
    
    $VERSION = sprintf "%d.%d", qq$Revision: 1.11 $ =~ /(\d+)\.(\d+)/;
    $ad_network = '';
    }
    init();
    
    # only print content type if called as cgi (include) for other perl scripts
    # may be called with `/path/to/file/ad_network.cgi` to get output without
    # Content-type: declaration
    print qq[<p align="center"><font color="#FF0000" face="Verdana" size="1">Coop Network: &nbsp;\n\n];
    
    if(-w $ad_file) {
    if(open(FILE,"$ad_file")) {
    # if we can't get a lock that means a process is writing, just serve an ad from the existing file
    # and don't check the timestamp, this prevents a slow response from the DP server from hanging
    # every web process waiting to read an ad, there is slim a chance we could end up with a partial ad
    if(!flock(FILE, LOCK_SH|LOCK_NB)) {
    my $adlist = join('',<FILE>);
    close(FILE);
    my @ads = split(/<ad_break>/,$adlist);
    @ad_params = split(/\|/,$ads[0]);
    for(my $i=0;$i<$ad_count;$i++) {
    my $randad .= $ads[int(rand(@ads-1))+1]; # dont get control info found in position 0
    if($ENV{REMOTE_ADDR} eq $ad_params[1]) {
    $randad =~ s/" \/>/" class="$ad_params[2]" \/>/;
    } else {
    $randad =~ s/" \/>/">/;
    }
    $ad_network .= $randad;
    $ad_network .= $ad_separator if($ad_count > 1);
    }
    } else {
    my $adlist = join('',<FILE>);
    close(FILE);
    my @ads = split(/<ad_break>/,$adlist);
    @ad_params = split(/\|/,$ads[0]);
    
    # if we haven't hit our cache limit or
    # the timestamp is less than timeout
    if(@ads < $ad_params[3] + 1 && $ad_params[0] + $ad_params[5] < time() || $ad_params[0] + $ad_params[4] < time()) {
    if(open(FILE,">$ad_file")) {
    flock(FILE, LOCK_EX); # get an exclusive lock so we can write the ad_network_ads file
    my $ua = new LWP::UserAgent;
    $ua->agent("Ad-Network-Perl/$VERSION)");
    my $req = HTTP::Request->new(GET => $ad_url);
    my $res = $ua->request($req);
    if($res->is_success) {
    my $content = '';
    $content .= $res->content;
    my ($params,$newad) = split(/<ad_param>/,$content);
    my @new_params = split(/\|/,$params);
    for(my $i=0;$i<@new_params;$i++) {
    $ad_params[$i+2] = $new_params[$i];
    }
    push(@ads,'') if(@ads == 0);
    push(@ads,$newad);
    }
    if(@ads > $ad_params[3]) {
    shift @ads;
    shift @ads;
    }
    my $packedip = gethostbyname('validate.digitalpoint.com');
    my $ipadr = inet_ntoa($packedip);
    @ad_params[0] = time();
    @ad_params[1] = $ipadr;
    $ads[0] = join('|',@ad_params);
    print FILE join('<ad_break>',@ads);
    close(FILE);
    }
    for(my $i=0;$i<$ad_count;$i++) {
    if(@ads > 1) { # dont get control information
    my $randad .= pop(@ads);
    if($ENV{REMOTE_ADDR} eq $ad_params[1]) {
    $randad =~ s/" \/>/" class="$ad_params[2]" \/>/;
    } else {
    $randad =~ s/" \/>/">/;
    }
    $ad_network .= $randad;
    $ad_network .= $ad_separator if($ad_count > 1);
    }
    }
    } else {
    
    for(my $i=0;$i<$ad_count;$i++) {
    my $randad .= $ads[int(rand(@ads-1))+1]; # dont get control info found in position 0
    if($ENV{REMOTE_ADDR} eq $ad_params[1]) {
    $randad =~ s/" \/>/" class="$ad_params[2]" \/>/;
    } else {
    $randad =~ s/" \/>/">/;
    }
    $ad_network .= $randad;
    $ad_network .= $ad_separator if($ad_count > 1);
    }
    
    } # end else on check for 100 ads or timestamp older than one hour
    } # end else on if flock
    } else {
    warn qq { could not open file $ad_file because $! };
    } # end else on opening ad file
    } else {
    $ad_network = 'You must set the "ad_network_ads.txt" file to be writable.';
    } # end else on writable ad file
    
    print $ad_network . qq{\n};
    Code (markup):
    Well if my ip is blocked could that be a cause? but i have websites from 2 different hosting companies, so both of them would have to be blocked correct?
     
    jfontestad, Mar 15, 2005 IP
  6. jfontestad

    jfontestad Well-Known Member

    Messages:
    1,236
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    148
    #6
    I even downloaded the ad_network_196.php uploaded it.... said needed to set write permissions for ad_network_ads_196.txt to writable gave it 777 and now it just turns a blank page. this is what is in the ad_network_ads_196.txt:
    "1110944538|216.9.35.51"
    thats it.
    returns no ads after refreshing it a few times.
     
    jfontestad, Mar 15, 2005 IP