#!/usr/bin/perl ################################################################################ ##THIS FILE REQUIRES NO EDITING. CHANGES MAY CAUSE SCRIPT TO STOP FUNCTIONING.## ################################################################################ # # ProAnalyzer 1.85 - action.cgi # # Copyright (C) SimplerMarketing.Com/ProAnalyzer.Com # # http://www.simplermarketing.com # http://www.proanalyzer.com # # Use of this software constitutes agreement to the Lisence agreement # found at http://www.proanalyzer.com/license.html. # ################################################################################ # # This script is called via a image tag. Please visit the Administration # interface for instructions. # ################################################################################ require "config.pl" || die "Could not locate config file"; &get_info; &write_database; &print_output; sub get_info { $ip = $ENV{'REMOTE_ADDR'}; @ip = split (/\./, $ip); $address = pack("C4", @ip); $host = gethostbyaddr($address, 2); $text = $ENV{'QUERY_STRING'}; my @input = split (/&/,$text); my %form_results = (); foreach $pair (@input) { ($key, $value) = split (/=/,$pair); $value =~ tr/+/ /; $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/pack ("C", hex ($1))/eg; $form_results{$key} = $value; } $action = $form_results{action}; if ($action eq "sale") { $amount = $form_results{amount}; } else { $amount = "null"; } $amount =~ s/^\$+// ; @nvpairs=split(/; /, $ENV{'HTTP_COOKIE'}); foreach $pair (@nvpairs) { ($name, $value) = split(/=/, $pair); $cookie{$name} = $value; } $campaign = $cookie{'campaign'}; $subcampaign = $cookie{'subcampaign'}; $redirect = $cookie{'redirect'}; if ($campaign eq "") { open (CLICKS, "$datapath/clicks.db"); flock(CLICKS, 2); @clicks=; flock(CLICKS, 8); close CLICKS; foreach $clicks (@clicks) { chomp $clicks; ($lcampaign,$lsubcampaign,$lcost,$ltime,$lreferer,$lbrowser,$lip,$lhost,$lredirect) = split(/$delimiter/,$clicks); if ($ip eq $lip) { $campaign = $lcampaign; $subcampaign = $lsubcampaign; $redirect = $lredirect; } } } } sub write_database { $time = time; open (ACTIONS, "$datapath/actions.db"); @actions=; close ACTIONS; foreach $actions (@actions) { chomp $actions; ($acampaign,$asubcampaign,$aaction,$aamount,$atime,$aip,$ahost,$aredirect) = split(/$delimiter/,$actions); if ($aip eq $ip) { if ($aaction eq $action) { $requiredtime = $atime + 86400; if ($requiredtime > $time) {$write = "no";} } } } if ($write ne "no") { if ($campaign eq "") {$campaign = "Not Tracked";} if ($subcampaign eq "") {$subcampaign = "null";} if ($redirect eq "") {$redirect = "na";} if ($host eq "") {$host = "na";} my $lockfile = "$datapath/actions.db" . ".lock"; open (LOCK, ">$lockfile"); flock LOCK, 2; $new_action = join $delimiter, $campaign, $subcampaign, $action, $amount, $time, $ip, $host, $redirect; open (ACTIONS, ">>$datapath/actions.db"); print ACTIONS "$new_action\n"; close (ACTIONS); flock LOCK, 8; close LOCK; } } sub print_output { print "Content-type:image/gif\n\n"; open (FILE, "$invis_image"); flock(FILE, 2); print ; flock(FILE, 8); close (FILE); }