#!/usr/bin/perl if (!-e "location.cfg"){ print "Content-type: text/html\n\n"; print qq~
Error - "location.cfg" file was not found.
~; exit; }else{ require "location.cfg"; } $data_name = "data.txt"; $gtext_name = "link.txt"; $pass_name = "pass.txt"; $data_file = ($data_directory . $data_name); $gtext_file = ($data_directory . $gtext_name); $pass_file = ($data_directory . $pass_name); $old_data_file = "ads.txt"; $old_text_file = "gtext.txt"; $version="2.3"; $button_title="Login"; @chars = ('a'..'z','A'..'Z','0'..'9'); $salt = $chars[rand(63)] . $chars[rand(63)]; $req="\*"; if (-e "$old_data_file"){ &convert; } ################################################################### @cookie=split(/; /, $ENV{'HTTP_COOKIE'}); foreach $pair (@cookie) { ($name, $value) = split(/=/, $pair); $COOKIE{$name} = $value; } $pass = $COOKIE{'pass'}; ################################################################### $stringpassed=$ENV{'QUERY_STRING'}; $stringpassed=~s/\+/ /g; @stringpassed=split(/\&/,$stringpassed); foreach $line (@stringpassed){ ($name,$value)=split(/\=/, $line); $stringsplit{$name}="$value"; } if ($stringsplit{'tell'}){ $tell="$stringsplit{'tell'}"; if ($tell eq "textlink"){ &textlink_redirect; exit; }elsif($tell eq "admin"){ &login_test; exit; }elsif($tell eq "js"){ $call_method="javascript"; &show_banner; exit; }else{ &banner_redirect; exit; } } if ($stringsplit{'jscount'}){ $jscount="$stringsplit{'jscount'}"; &js_count; exit; } ################################################################### read(STDIN, $input, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $input); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $FORM{$name} = $value; } ################################################################### $line_to_view=$FORM{'line_to_view'}; $line_to_change=$FORM{'line_to_change'}; $line_to_delete=$FORM{'line_to_delete'}; $ad_name=$FORM{'*ad_name'}; $ad_name_value=$FORM{'*ad_name'}; $ad_name_value=~s/\%22/\"/g; $ad_html=$FORM{'*ad_html'}; $ad_html=~s/\|/\%7C/g; $ad_html=~s/\%22/\"/g; $ad_html=~s/\ \ +/\ /g; $ad_html=~s/\n//g; $ad_html=~s/\r//g; $ad_input_value=$FORM{'*ad_html'}; $ad_input_value=~s/\|/\%7C/g; $ad_input_value=~s/\%22/\"/g; $ad_input_value=~s/\ \ +/\ /g; $ad_input_value=~s/\n//g; $ad_input_value=~s/\r//g; $reset_count=$FORM{'reset_count'}; $mode=$FORM{'mode'}; $gtext_impressions=$FORM{'gtext_impressions'}; $gtext_clicks=$FORM{'gtext_clicks'}; $gtext_text=$FORM{'*gtext_text'}; $gtext_url=$FORM{'*gtext_url'}; $gtext_color=$FORM{'gtext_color'}; $text_target=$FORM{'text_target'}; $image_url=$FORM{'*image_url'}; $border=$FORM{'border'}; $link_url=$FORM{'*link_url'}; $image_target=$FORM{'image_target'}; $ad_id=$FORM{'ad_id'}; $action=$FORM{'action'}; $form_password=$FORM{'password'}; $impressions=$FORM{'impressions'}; if ($impressions eq ""){ $impressions = 0; } $clicks=$FORM{'clicks'}; if ($clicks eq ""){ $clicks = 0; } $weight=$FORM{'weight'}; if ($weight eq ""){ $weight = 1; } ################################################################### if ($action eq "Set Password"){ $error_message="Cannot create password file - make sure directory permissions are set to chmod 777"; open(PASSFILE,">$pass_file") || &error_pass; chmod oct 777,("$pass_file"); $crypt_pass = crypt($form_password, $salt); print PASSFILE "$crypt_pass\n"; close(PASSFILE); $message="Password is set\! You may now log in"; $title="CAROUSEL - Password Set"; &login; exit; } if ($action eq "Login"){ open(PASSFILE,"$pass_file") || &error_pass; $my_password = ; close(PASSFILE); chomp ($my_password); $submitted_password = crypt($form_password, $my_password); if ($submitted_password ne $my_password){ $message="Your password does not match"; $title="CAROUSEL - Wrong Password"; &login; exit; }else{ print "Set-Cookie:pass = 2;\n"; $title="CAROUSEL - Logged In"; $text="You have successfully logged in"; &header; &stats; &footer; exit; } } ################################################################### if ($pass != 2){ &show_banner; exit; } ################################################################### if ($action eq "add"){ $title="CAROUSEL - Paste Affiliate Code"; $text="Paste HTML banner code into form box and choose a name for this ad.
If you don't have ready-to-paste code, use \"Create New Banner\""; &header; &add_form; &footer; exit; } if ($action eq "write"){ $title="CAROUSEL - New Banner Added"; $text="Your banner has been added"; &header; &write; &stats; &footer; exit; } if ($action eq "stats"){ $title="CAROUSEL - Statistics"; $text="View statistics for your ads
Click \"Edit\" to view or modify an ad, \"Delete\" to remove an ad"; &header; &stats; &footer; exit; } if ($action eq "delete"){ $title="CAROUSEL - Item Deleted"; $text="Selected ad has been deleted"; &header; &delete; &stats; &footer; exit; } if ($action eq "reset"){ $title="CAROUSEL - Counters Reset"; $text="Ad counters have been reset"; &header; &reset; &stats; &footer; exit; } if ($action eq "save"){ $title="CAROUSEL - Changes Saved"; $text="Changes to selected ad have been saved"; &header; &save; &stats; &footer; exit; } if ($action eq "gtext"){ $title="CAROUSEL - Text Link Setup"; $text="Text Link setup
When enabled, this will put the same text link under all your ad banners"; &header; >ext_setup; &footer; exit; } if ($action eq "set_gtext"){ $title="CAROUSEL - Text Link"; $text="Text Link has been changed"; &header; &set_gtext; >ext_setup; &footer; exit; } if ($action eq "view"){ $title="CAROUSEL - View Ad"; $text="Showing selected ad
You may reset the counter, edit the name, weight or HTML code if desired.
\(Entering a weight of \"0\" will deactivate, but not remove the ad.\)"; &header; &view_ad; &footer; exit; } if ($action eq "code"){ $title="CAROUSEL - Generate Code"; $text="Copy and paste this code into your web page where you want your ads to appear:"; &header; &get_code; &footer; exit; } if ($action eq "preview"){ $title="CAROUSEL - Preview New Ad"; $text="Verify your new banner before installing
Click \"Install Banner\" to finish"; &header; &preview; &footer; exit; } if ($action eq "pre_modify"){ $title="CAROUSEL - Preview Changes"; $text="Verify your changes before modification
Click \"Save Changes\" to finish"; &header; &pre_modify; &footer; exit; } if ($action eq "create"){ $title="CAROUSEL - Create New Banner"; $text="Enter Image URL, Link URL and choose a name for this ad.
If you have ready-to-paste HTML code, use \"Paste Affiliate Code\""; &header; &create; &footer; exit; } ################################################################### sub login_test{ if (!-e "$pass_file"){ $message="You need to set an administration password for Carousel"; $button_title="Set Password"; $title="CAROUSEL - Set Admin Password"; &login; exit; } if ($pass == 2){ $title="CAROUSEL - Logged In"; $text="You are logged in"; &header; &stats; &footer; exit; }else{ $title="CAROUSEL - Login"; &login; exit; } } sub convert{ $error_message="Cannot create new data file - make sure directory permissions are set to chmod 777"; while (-e "$old_data_file.tmp"){ sleep(1); } open(NEWFILE,">$data_file") || &error; $error_message="Cannot open data file - make sure permissions are set to chmod 777"; open(OLDFILE,"$old_data_file") || &error_data; @old_file_data = ; close(OLDFILE); $new_id_num=10000000; foreach $line (@old_file_data) { ($ad_name, $ad_html) = split(/\|/, $line); $new_id_num++; $new_line="$new_id_num\|0\|0\|1\|$ad_name\|$ad_html"; if (length($new_line) < 1){ next; } $new_line=~s/\ \ +/\ /g; $new_line=~s/\n//g; $new_line=~s/\r//g; print NEWFILE "$new_line\n"; } close(NEWFILE); chmod oct 777,("$data_file"); unlink ("$old_data_file"); if (-e "$old_text_file"){ open(OLDTEXTFILE,"$old_text_file") || &error; $old_text_data = ; chomp ($old_text_data); ($gtext_text, $gtext_color, $gtext_url, $text_target) = split(/\|/, $old_text_data); open(NEWTEXTFILE,">$gtext_file") || &error; print NEWTEXTFILE "0\|0\|$gtext_text\|$gtext_color\|$gtext_url\|$text_target\n"; close(NEWTEXTFILE); chmod oct 777,("$gtext_file"); close(OLDTEXTFILE); unlink ("$old_text_file"); } } sub show_banner{ if (-e "$data_file"){ open(DATAFILE,"$data_file") || &error_data; }else{ if ($call_method eq "javascript"){ print "Content-type: text/plain\n\n"; print qq~banner=('You have no ads installed - Click here to log in to control panel');~; print qq~document.write(banner);~; exit; }else{ print "Content-type: text/html\n\n"; print qq~You have no ads installed - Click here to log in to control panel~; exit; } } @ad_file = ; close(DATAFILE); $line=0; foreach $ad (@ad_file) { $line++; } $lines=$line - 1; if ($lines < 0){ if ($call_method eq "javascript"){ print "Content-type: text/plain\n\n"; print qq~banner=('You have no ads installed - Click here to log in to control panel');~; print qq~document.write(banner);~; exit; }else{ print "Content-type: text/html\n\n"; print qq~You have no ads installed - Click here to log in to control panel~; exit; } } @banners = (); $weight_line=0; foreach $ad (@ad_file) { ($ad_id,$impressions,$clicks,$weight,$ad_name,$ad_html) = split(/\|/, $ad); while ($weight > 0){ push (@banners, $weight_line); $weight--; } $weight_line++; } $rand_num = rand(@banners); $rand_pick=$banners[$rand_num]; $rand_line=$ad_file[$rand_pick]; $line_to_change=$rand_pick; $line_to_change++; ($ad_id,$impressions,$clicks,$weight,$ad_name,$ad_html) = split(/\|/, $rand_line); $impressions++; $changed_line="$ad_id\|$impressions\|$clicks\|$weight\|$ad_name\|$ad_html"; &update_log; if (($ad_html =~ /FORM/i)&&($ad_html =~ /ACTION/i)&&($ad_html =~ /METHOD/i)){ $ad_html=~s/\>/\>|/g; @html_array=split(/\|/,$ad_html); foreach $tag (@html_array){ if (($tag =~ /FORM/i)&&($tag =~ /ACTION/i)&&($tag =~ /METHOD/i)){ $tag =~s/\>/ onSubmit\=\'jsCount\=window.open\(\"$this_URL\?jscount\=$ad_id\"\,\"countWindow\"\,\"toolbar\=no\,location\=no\,directories\=no\,status\=no\,menubar\=no\,scrollbars\=no\,resizable\=no\,width\=1\,height\=1\"\)\; return true\'\>/; push (@my_array, $tag); }else{ push (@my_array, $tag); } } $my_html=join("",@my_array); }elsif (($ad_html =~ /SCRIPT/i)&&($ad_html =~ /\/SCRIPT/i)){ $my_html="$ad_html"; }else{ $ad_html=~s/\>/\>|/g; @html_array=split(/\|/,$ad_html); foreach $tag (@html_array){ if ($tag =~ /a href/i){ @link_tag =split( /\"/,$tag); $redirect_url=$link_tag [1]; $ad_target=$link_tag [3]; last; } } $click_url="$this_URL\?tell\=$ad_id"; if (!$ad_target){ $target_html=""; }else{ $target_html=" TARGET\=\"$ad_target\""; } $my_redir_tag=""; @my_array = (); foreach $tag (@html_array){ if ($tag =~ /a href/i){ push (@my_array, $my_redir_tag); }else{ push (@my_array, $tag); } } $my_html=join("",@my_array); } $my_html=~s/\%7C/\|/g; if (-e "$gtext_file"){ while (-e "$gtext_file.tmp"){ sleep(1); } open(TEMPFILE,">$gtext_file.tmp") || &error_gtext_banner; open(GTEXTFILE,"$gtext_file") || &error_gtext_banner; $gtext_data = ; close(GTEXTFILE); chop ($gtext_data); ($gtext_impressions, $gtext_clicks, $gtext_text, $gtext_color, $gtext_url, $text_target) = split(/\|/, $gtext_data); $gtext_impressions++; print TEMPFILE "$gtext_impressions\|$gtext_clicks\|$gtext_text\|$gtext_color\|$gtext_url\|$text_target\n"; close(TEMPFILE); chmod oct 777,("$gtext_file.tmp"); $error_message="Cannot rename temp file to master file after edit - make sure directory permissions are set to chmod 777"; rename("$gtext_file.tmp", "$gtext_file") || &error; ($color_hex, $color_name) = split(/\-/, $gtext_color); if ($text_target ne ""){ $target="TARGET=\"$text_target\""; }else{ $target=""; } if ($color_hex eq ""){ $text_link="$gtext_text"; }else{ $text_link="$gtext_text"; } $whole_banner="
$my_html
$text_link
"; }else{ $whole_banner="$my_html"; } if ($call_method eq "javascript"){ $whole_banner=~s/\|/\\|/g; $whole_banner=~s/\"/\\"/g; $whole_banner=~s/\'/\\'/g; $whole_banner=~s/\~/\\~/g; $whole_banner=~s/\n//g; $whole_banner=~s/\r//g; print "Content-type: text/plain\n\n"; print qq~banner=('$whole_banner');~; print qq~document.write(banner);~; exit; }else{ print "Content-type: text/html\n\n"; print "$whole_banner\n"; exit; } } sub textlink_redirect{ if (!-e "$gtext_file"){ if ($call_method eq "javascript"){ print "Content-type: text/plain\n\n"; print qq~banner=('Error - Record Not Found');~; print qq~document.write(banner);~; exit; }else{ print "Content-type: text/html\n\n"; print qq~Error - Record Not Found~; exit; } } while (-e "$gtext_file.tmp"){ sleep(1); } open(TEMPFILE,">$gtext_file.tmp") || &error_gtext_banner; open(GTEXTFILE,"$gtext_file") || &error_gtext_banner; $gtext_data = ; close(GTEXTFILE); chomp ($gtext_data); ($gtext_impressions, $gtext_clicks, $gtext_text, $gtext_color, $gtext_url, $text_target) = split(/\|/, $gtext_data); $gtext_clicks++; print TEMPFILE "$gtext_impressions\|$gtext_clicks\|$gtext_text\|$gtext_color\|$gtext_url\|$text_target\n"; close(TEMPFILE); chmod oct 777,("$gtext_file.tmp"); $error_message="Cannot rename temp file to master file after edit - make sure directory permissions are set to chmod 777"; rename("$gtext_file.tmp", "$gtext_file") || &error; print "Location: $gtext_url\n\n"; exit; } sub banner_redirect{ if (-e "$data_file"){ open(DATAFILE,"$data_file") || &error_data; }else{ print "Content-type: text/html\n\n"; print qq~You have no ads installed - Click here to log in to control panel~; exit; } @ad_file = ; close(DATAFILE); $line=0; foreach $ad (@ad_file) { $line++; ($ad_id,$impressions,$clicks,$weight,$ad_name,$ad_html) = split(/\|/, $ad); if ($tell == $ad_id){ $id_found = 1; $clicks++; last; } } $line_to_change=$line; $changed_line="$ad_id\|$impressions\|$clicks\|$weight\|$ad_name\|$ad_html"; &update_log; if ($ad_html =~ /