#!/usr/bin/perl ############################################################## # # # Ultimate Affiliate # # ***********SQL EDITION********** # # By Steve Miles # # http://www.groundbreak.com # # # # Copyright 1999-2001 # # # # Selling or distributing this software or # # modifications of this software without # # permission is expressly forbidden. Permission # # to modify the script for personal use is granted. # # In all cases this header and copyright # # must remain intact. All violators will be # # PROSECUTED to the full extent. # # # ############################################################## use CGI::Carp qw(fatalsToBrowser); use CGI qw (:standard); $q = new CGI; $|++; foreach ($q->param) {${$_} = $q->param($_);} require "config.cgi"; require "common.cgi"; $referer = $q->referer(); $ip = $q->remote_host(); $time = time(); &date; &headers_footers; &Create_DB_Connection; &find_cookie; print $q->header; if ($action) { &check_referer; &check_form; &record_info; if ($affiliate_valid_email eq 1) { &send_valid;} elsif ($affiliates_pending eq 1) { &send_pending;} else { &normal_finish; } exit; } elsif ($secret) { &check_validation; } else { &print_form; } ######################## CHECK FORM REFERER sub check_referer { if ($check_referring_urls_signup eq 1) { if ($referer !~ /$refurl/ig) { &print_default("You can't get in from here"); }} } ######################## FIND THE COOKIE sub find_cookie { if ($affiliate) { $getcookie = $affiliate; } else { $getcookie = $q->cookie($cookiename); $sponsor = "NO_SPONSOR"; if ($getcookie) { $sponsor = $getcookie; } else { $SQL="SELECT * FROM ua_hits WHERE Ip like '$ip'"; &Do_SQL; while ($pointer = $sth->fetchrow_hashref){ $getcookie = $pointer->{'Id'}; } $sth->finish; } if ($getcookie eq "") {$getcookie = "NO_SPONSOR";} } $Sponsor = $getcookie; } ########### # MAKE SURE EVERYTHING IS PROPER ########### sub check_form { my $count; if (!$Username || $Username !~ /^[A-Za-z0-9]+$/) { $error .= "
  • Username must consist of numbers and letters only";} if (!$Password || $Password !~ /^[A-Za-z0-9]+$/) { $error .= "
  • Passwords do not match";} $count++ while $Username =~ /[A-Za-z0-9]/g; if (4 > $count) { $error .= "
  • You need more than 3 and less than 21 characters in your username";} $count = 0; $count++ while $Password =~ /[A-Za-z0-9]/g; if (4 > $count) { $error .= "
  • You need more than 3 and less than 21 characters in your password";} if ($Password ne $Password2) { $error .= "
  • Password and verify password don't match";} if ($Email !~ /^[\w\-\.]+\@[\w\-]+\.[\w\-\.]+\w$/) { $error .= "
  • Email is not in a valid format";} if (!$Name) { $error .= "
  • You must specify a name";} if ($Terms ne "yes") { $error .= "
  • You did not agree to the terms and conditions";} if (!$auto_usernames) { $SQL = "SELECT * FROM users WHERE Username like '$Username'"; &Do_SQL; if ($sth->rows) { $error .= "
  • Username already exists";} } $SQL = "SELECT * FROM users WHERE Email like '$Email'"; &Do_SQL; if ($sth->rows) { $error .= "
  • This email already exists in the system. Please visit our stats page to have your login info sent to you.";} } ######################## RECORD THE INFORMATION sub record_info { if ($error) { &print_form; } if ($affiliates_pending eq 1) { $status = "PENDING"; } if ($affiliate_valid_email eq 1) { srand; @chars = ("A" .. "Z", "a" .. "z", 0 .. 9); $valid_email = join("", @chars[ map {rand @chars } ( 1 .. 10) ]); $status .= "VALIDATED=$valid_email"; } @temp = (Field1,Field2,Field3,Field4,Field5); foreach $item (@temp) { push (@signupfields, $item); } if ($Username eq $Sponsor) { $Sponsor = "NO_SPONSOR"; } foreach ($q->param) { ${$_} =~ s/\'/\\\'/g; ${$_} =~ s/\"/\\\"/g; } $SQL = "INSERT INTO users (Year,Month,Day,Sponsor,Tier,Status,Username,Password,Email,Name,Address1,Address2,City,State,Zip,Country,Company,Sitename,Siteurl,Terms,Checkname,Phone,Fax,SSNumber, Field1, Field2, Field3, Field4, Field5) VALUES ('$year','$month','$day','$Sponsor','$tier','$status','$Username','$Password','$Email','$Name','$Address1','$Address2','$City','$State','$Zip','$Country','$Company','$Sitename','$Siteurl','$Terms','$Checkname','$Phone','$Fax','$SSNumber','$Field1','$Field2','$Field3','$Field4','$Field5')"; &Do_SQL; $sth->finish; } ######################## SEND EMAIL VALIDATION INFO sub send_valid { print< $header
     
    Thank You for Signing Up!
    We require that you have a valid email address to join our affiliate program. An email has just been sent to $Email containing a validation url to activate your account. Once you click on this link, you will be able to log into the affiliate stats area.
    You will hear from us shortly!

    You will be forwarded to our main page in 10 seconds. If not, Click Here.

    $footer EOF open (FILE, "$path_to_emails/validation_email.txt"); flock(FILE, 2); (@email_stuff) = (); flock(FILE, 8); close (FILE); $subject = shift (@email_stuff); chomp $subject; foreach $email_stuff (@email_stuff) { $message .= $email_stuff; } foreach $thing ($q->param) { $subject =~ s/\%\%$thing\%\%/${$thing}/ig; $message =~ s/\%\%$thing\%\%/${$thing}/ig; } $temp_url = $url_to_clickthru; $temp_url =~ s//$Username/ig; $subject =~ s/\%\%affiliateurl\%\%/$temp_url/ig; $message =~ s/\%\%affiliateurl\%\%/$temp_url/ig; ($firstname,$junk) = split (/ /, $Name); $subject =~ s/\%\%firstname\%\%/$firstname/ig; $message =~ s/\%\%firstname\%\%/$firstname/ig; $url_to_stats = "$url_to_cgi_directory/stats.cgi?user=$Username&pass=$Password"; $subject =~ s/\%\%statsurl\%\%/$url_to_stats/ig; $message =~ s/\%\%statsurl\%\%/$url_to_stats/ig; $validation_url = "$url_to_cgi_directory/signup.cgi?secret=$valid_email"; $subject =~ s/\%\%validationurl\%\%/$validation_url/ig; $message =~ s/\%\%validationurl\%\%/$validation_url/ig; if ($smtphost) { $smtp = Net::SMTP->new($smtphost); $smtp->mail($admin_email); $smtp->to($Email); $smtp->data(); $smtp->datasend("From: $admin_email\n"); $smtp->datasend("To: $Email\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("\n"); $smtp->datasend("$message\n\n"); $smtp->dataend(); $smtp->quit(); } else { open (MAIL, "|$mailprog -oi -t") || die "Can't open $path_to_sendmail!\n"; print MAIL < $header
    Thank You for Signing Up!
    Your affiliate status is awaiting our approval. Once you are approved you will receive an email with all of the important login info and urls. Thank you.
    You will hear from us shortly!

    You will be forwarded to our main page in 10 seconds. If not, Click Here.

    $footer EOF open (FILE, "$path_to_emails/pending_email.txt"); flock(FILE, 2); (@email_stuff) = (); flock(FILE, 8); close (FILE); $subject = shift (@email_stuff); chomp $subject; foreach $email_stuff (@email_stuff) { $message .= $email_stuff; } if ($checked_validation) { foreach $thing (@signupfields) { $subject =~ s/\%\%$thing\%\%/${$thing}/ig; $message =~ s/\%\%$thing\%\%/${$thing}/ig; } } else { foreach $thing ($q->param) { $subject =~ s/\%\%$thing\%\%/${$thing}/ig; $message =~ s/\%\%$thing\%\%/${$thing}/ig; } } ($firstname,$junk) = split (/ /, $Name); $subject =~ s/\%\%firstname\%\%/$firstname/ig; $message =~ s/\%\%firstname\%\%/$firstname/ig; $temp_url = $url_to_clickthru; $temp_url =~ s//$Username/ig; $subject =~ s/\%\%affiliateurl\%\%/$temp_url/ig; $message =~ s/\%\%affiliateurl\%\%/$temp_url/ig; $url_to_stats = "$url_to_cgi_directory/stats.cgi?user=$Username&pass=$Password"; $subject =~ s/\%\%statsurl\%\%/$url_to_stats/ig; $message =~ s/\%\%statsurl\%\%/$url_to_stats/ig; if ($smtphost) { $smtp = Net::SMTP->new($smtphost); $smtp->mail($admin_email); $smtp->to($Email); $smtp->data(); $smtp->datasend("From: $admin_email\n"); $smtp->datasend("To: $Email\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("\n"); $smtp->datasend("$message\n\n"); $smtp->dataend(); $smtp->quit(); } else { open (MAIL, "|$mailprog -oi -t") || die "Can't open $path_to_sendmail!\n"; print MAIL <new($smtphost); $smtp->mail($admin_email); $smtp->to($Email); $smtp->data(); $smtp->datasend("From: $admin_email\n"); $smtp->datasend("To: $Email\n"); $smtp->datasend("Subject: Another $main_site_name affiliate signup up!\n"); $smtp->datasend("\n"); $smtp->datasend("Another member has joined!\n\n"); foreach $field (@signupfields){ $smtp->datasend("$field : ${$field}\n"); } $smtp->datasend("\n\n"); $smtp->datasend("Come check out your current affiliate statistics at:\n"); $smtp->datasend("$url_to_cgi_directory/admin.cgi"); $smtp->dataend(); $smtp->quit(); } else { open (MAIL, "|$mailprog -oi -t") || die "Can't open /usr/sbin/sendmail!\n"; print MAIL <) { $filestuff .= $_; } flock(FILE, 8); close (FILE); $filestuff =~ s/\%\%([a-zA-Z0-9_]+)\%\%/${$1}/ig; $file =~ s/$path_to_templates//; open (NEWFILE, ">$path_to_replicated_pages/$Username$file"); flock(NEWFILE, 2); print NEWFILE $filestuff; flock(NEWFILE, 8); close (NEWFILE); $filestuff = ""; } } } ####################### NORMAL FINISH sub normal_finish { $aftersignup =~ s//$Username/ig; print< SUCCESSFUL SIGNUP!
     
    Successful Signup
    You will be forwarded in 5 seconds to the affiliate login page.

    Click Here if nothing happens.

    EOF if ($email_to_admin_after_signup eq 1) { open (FILE, "$path_to_emails/affiliate_after_signup.txt"); flock(FILE, 2); (@email_stuff) = (); flock(FILE, 8); close (FILE); $subject = shift (@email_stuff); chomp $subject; foreach $email_stuff (@email_stuff) { $message .= $email_stuff; } if ($checked_validation) { foreach $thing (@signupfields) { $subject =~ s/\%\%$thing\%\%/${$thing}/ig; $message =~ s/\%\%$thing\%\%/${$thing}/ig; } } else { foreach $thing ($q->param) { $subject =~ s/\%\%$thing\%\%/${$thing}/ig; $message =~ s/\%\%$thing\%\%/${$thing}/ig; } } ($firstname,$junk) = split (/ /, $Name); $subject =~ s/\%\%firstname\%\%/$firstname/ig; $message =~ s/\%\%firstname\%\%/$firstname/ig; $temp_url = $url_to_clickthru; $temp_url =~ s//$Username/ig; $subject =~ s/\%\%affiliateurl\%\%/$temp_url/ig; $message =~ s/\%\%affiliateurl\%\%/$temp_url/ig; $url_to_stats = "$url_to_cgi_directory/stats.cgi?user=$Username&pass=$Password"; $subject =~ s/\%\%statsurl\%\%/$url_to_stats/ig; $message =~ s/\%\%statsurl\%\%/$url_to_stats/ig; if ($smtphost) { $smtp = Net::SMTP->new($smtphost); $smtp->mail($admin_email); $smtp->to($Email); $smtp->data(); $smtp->datasend("From: $admin_email\n"); $smtp->datasend("To: $Email\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("\n"); $smtp->datasend("$message\n\n"); $smtp->dataend(); $smtp->quit(); } else { open (MAIL, "|$mailprog -oi -t") || die "Can't open $path_to_sendmail!\n"; print MAIL <fetchrow_hashref){ foreach $field (@signupfields){ ${$field} = $pointer->{$field}; } $Sponsor = $pointer->{'Sponsor'}; $go_email = "YES"; } if ($go_email eq "YES") { open (FILE, "$path_to_emails/affiliate_after_downline.txt"); flock(FILE, 2); (@email_stuff) = (); flock(FILE, 8); close (FILE); $subject = shift (@email_stuff); chomp $subject; foreach $email_stuff (@email_stuff) { $message .= $email_stuff; } if ($checked_validation) { foreach $thing (@signupfields) { $subject =~ s/\%\%$thing\%\%/${$thing}/ig; $message =~ s/\%\%$thing\%\%/${$thing}/ig; } } else { foreach $thing ($q->param) { $subject =~ s/\%\%$thing\%\%/${$thing}/ig; $message =~ s/\%\%$thing\%\%/${$thing}/ig; } } ($firstname,$junk) = split (/ /, $Name); $subject =~ s/\%\%firstname\%\%/$firstname/ig; $message =~ s/\%\%firstname\%\%/$firstname/ig; $temp_url = $url_to_clickthru; $temp_url =~ s//$Username/ig; $subject =~ s/\%\%affiliateurl\%\%/$temp_url/ig; $message =~ s/\%\%affiliateurl\%\%/$temp_url/ig; $url_to_stats = "$url_to_cgi_directory/stats.cgi?user=$Username&pass=$Password"; $subject =~ s/\%\%statsurl\%\%/$url_to_stats/ig; $message =~ s/\%\%statsurl\%\%/$url_to_stats/ig; if ($smtphost) { $smtp = Net::SMTP->new($smtphost); $smtp->mail($admin_email); $smtp->to($Email); $smtp->data(); $smtp->datasend("From: $admin_email\n"); $smtp->datasend("To: $Email\n"); $smtp->datasend("Subject: $subject\n"); $smtp->datasend("\n"); $smtp->datasend("$message\n\n"); $smtp->dataend(); $smtp->quit(); } else { open (MAIL, "|$mailprog -oi -t") || die "Can't open $path_to_sendmail!\n"; print MAIL <fetchrow_hashref){ $found = "YES"; foreach $field (@signupfields){ ${$field} = $pointer->{$field}; } $Sponsor = $pointer->{'Sponsor'}; } if ($found ne "YES") { &print_default("Invalid attempt to Validate Email."); exit;} $Status =~ s/VALIDATED=$secret//ig; $SQL="UPDATE users SET Status = '$Status' WHERE Username = '$Username'"; &Do_SQL; $sth->finish; $checked_validation++; if ($affiliates_pending eq 1) { &send_pending; exit; } &normal_finish; } ########### # PRINT OUT THE SIGN UP PAGE ########### sub print_form { open (FILE, "signup.html"); flock(FILE, 2); while () { $file .= $_; } flock(FILE, 8); close (FILE); $file =~ s//$ip/ig; $file =~ s//$month\/$day\/$year/ig; if ($getcookie) { $SQL = "SELECT * FROM users WHERE Username = '$getcookie'"; &Do_SQL; $row = $sth->fetchrow_hashref; $sponsor_name = $row->{'Name'}; if ($sth->rows) { $file =~ s//$getcookie/ig; $file =~ s//$sponsor_name/ig; } } if ($Terms eq "yes") { $file =~ s//selected/ig; } if ($error) { $error = "
      ERROR:
      $error
    "; } $file =~ s//$error/ig; foreach ($q->param) {$file =~ s//${$_}/ig;} $file =~ s///g; print $file; exit; } ############################## ERROR HTML sub print_default { print< Affiliate Program
    $_[0]

    Go Back
    EOF exit; } ############################## CALCULATE DATE sub date { ($sec, $min, $hour, $day, $mon, $year, $dweek, $dyear, $daylight) = localtime($time); $month = $mon + 1; $year = $year + 1900; } ############################## PREPARE HEADERS AND FOOTERS sub headers_footers { open (FILE, "<$path_to_header"); flock(FILE, 2); while () { $header .= "$_"; } flock(FILE, 8); close (FILE); open (FILE, "<$path_to_footer"); flock(FILE, 2); while () { $footer .= "$_"; } flock(FILE, 8); close (FILE); }