#!/usr/bin/perl
#
# Celeb Match 1.0
#
&parse_form; # change web form into variables we can use
&variables; # assigns variable names to questions
$LogFile = "/var/www/vhosts/jokesandhumor.com/httpdocs/tests/celebsuccess.txt";
$mailprog = '/usr/sbin/sendmail';
if ($FORM{'step'} eq "") {
print "Content-type: text/html\n\n";
&print_header;
print qq~
Step 1 of 6
Who is the perfect celberity for you? We will now ask you a series of questions which will determine which celebrity for our extensive database that you would be the most compaitble with!
Who is the perfect celberity for you? We will now ask you a series of questions which will determine which celebrity for our extensive database that you would be the most compaitble with!
How SUCCESSFUL will you be? Take the Success Test and find out!
Compare your score to your friends or family! E-mail it to them!
~;
&print_footer;
#
#
# START COUNTER STUFF
#
$data_dir = "/var/www/vhosts/jokesandhumor.com/httpdocs/tests/";
$auto_create = "1";
$lock_sec = "3";
# Print Content Type Header For Browser
#### print "Content-type: text/html\n\n";
# Get the page location from the DOCUMENT_URI environment variable.
#$count_page = "$ENV{'DOCUMENT_URI'}";
$count_page = "CELEB.txt";
# Any characters that are not letters or numbers are turned into an underscore
# $count_page =~ s/[^\w]/_/g;
$lock_file = "$count_page\.lock";
# Check to see if file is locked by program already in use.
&check_lock($lock_sec);
# If the file exists, get the date and count out of it. Otherwise, if
# auto_create is allowed, create a new account. If neither of these are
# true, return an error.
if (-e "$data_dir$count_page") {
open(COUNT,"$data_dir$count_page");
$line = ;
chop($line) if $line =~ /\n$/;
close(COUNT);
($date,$count) = split(/\|\|/,$line);
}
elsif ($auto_create == 1) {
&create;
}
else {
&error('page_not_found');
}
# Increment Count.
$count++;
$print_count = $count;
# Get Count Length for use in padding.
$count_length = length($count);
# Print the Count, Link and Date depending on what user has specified
# they wish to print.
#if ($show_date == 1) {
# if ($show_link =~ /http:\/\//) {
#
#}
#else {
# print "$print_count hits since $date";
#}
#}
#else {
# if ($show_link =~ /http:\/\//) {
# print "$print_count";
#}
#else {
# print "$print_count";
#}
#}
# Open the count file and write the new count that has been incremented.
open(COUNT,">$data_dir$count_page") || &error('could_not_increment');
print COUNT "$date\|\|$count";
close(COUNT);
# Remove Lock File for next time script is run on that HTML page.
&clean_up;
sub create {
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
@months = ("January","February","March","April","May","June","July",
"August","September","October","November","December");
$year += 1900;
$date = "$months[$mon] $mday, $year";
$count = "0";
open(COUNT,">$data_dir$count_page") || &error('count_not_created');
print COUNT "$date\|\|$count";
close(COUNT);
}
sub error {
$error = shift(@_);
if ($error eq 'page_not_found') {
print "[TextCounter Fatal Error: This Page Not Found\; Auto-Create Option Disabled]";
}
elsif ($error eq 'bad_uri') {
print "[TextCounter Fatal Error: This Page Not In Valid URI]";
}
elsif ($error eq 'count_not_created') {
print "[TextCounter Fatal Error: Could Not Write to File $datadir$count_page]";
}
elsif ($error eq 'could_not_increment') {
print "[TextCounter Fatal Error: Could Not Increment Counter]";
}
exit;
}
sub check_lock {
$time = $_[0];
for ($i = 1;$i <= $time; $i++) {
if (-e "$data_dir$lock_file") {
sleep 1;
}
else {
open(LOCK,">$data_dir$lock_file");
print LOCK "0";
close(LOCK);
last;
}
}
}
sub clean_up {
unlink("$data_dir$lock_file");
}
#
# END COUNTER STUFF
#
#
} # end step 8
#
#
# VARIABLES, Etc
#
sub variables {
if ($FORM{'hisname'}) {
$hisname = "$FORM{'hisname'}";
$hisname =~ s/"//g;
$hisname =~ s//g;
$hisname =~ s/>//g;
$hisname =~ s/\&//g;
}
if ($FORM{'age'}) {
$age = "$FORM{'age'}";
}
if ($FORM{'email'}) {
$email = "$FORM{'email'}";
}
if ($FORM{'gender'}) {
$gender = "$FORM{'gender'}";
}
if ($FORM{'celebgender'}) {
$celebgender = "$FORM{'celebgender'}";
}
if ($FORM{'location'}) {
$location = "$FORM{'location'}";
}
if ($FORM{'q1'}) {
$q1= "$FORM{'q1'}";
}
if ($FORM{'q2'}) {
$q2= "$FORM{'q2'}";
}
if ($FORM{'q3'}) {
$q3= "$FORM{'q3'}";
}
if ($FORM{'q4'}) {
$q4= "$FORM{'q4'}";
}
if ($FORM{'q5'}) {
$q5= "$FORM{'q5'}";
}
if ($FORM{'q6'}) {
$q6= "$FORM{'q6'}";
}
if ($FORM{'q7'}) {
$q7= "$FORM{'q7'}";
}
if ($FORM{'q8'}) {
$q8= "$FORM{'q8'}";
}
if ($FORM{'q9'}) {
$q9= "$FORM{'q9'}";
}
if ($FORM{'q10'}) {
$q10= "$FORM{'q10'}";
}
if ($FORM{'q11'}) {
$q11= "$FORM{'q11'}";
}
if ($FORM{'q12'}) {
$q12= "$FORM{'q12'}";
}
if ($FORM{'q13'}) {
$q13= "$FORM{'q13'}";
}
if ($FORM{'q14'}) {
$q14= "$FORM{'q14'}";
}
if ($FORM{'q15'}) {
$q15= "$FORM{'q15'}";
}
if ($FORM{'q16'}) {
$q16= "$FORM{'q16'}";
}
if ($FORM{'q17'}) {
$q17= "$FORM{'q17'}";
}
if ($FORM{'q18'}) {
$q18= "$FORM{'q18'}";
}
if ($FORM{'q19'}) {
$q19= "$FORM{'q19'}";
}
if ($FORM{'q20'}) {
$q20= "$FORM{'q20'}";
}
if ($FORM{'q30'}) {
$q30= "$FORM{'q30'}";
}
if ($FORM{'q21'}) {
$q21= "$FORM{'q21'}";
}
if ($FORM{'q22'}) {
$q22= "$FORM{'q22'}";
}
if ($FORM{'q23'}) {
$q23= "$FORM{'q23'}";
}
if ($FORM{'q24'}) {
$q24= "$FORM{'q24'}";
}
if ($FORM{'q25'}) {
$q25= "$FORM{'q25'}";
}
if ($FORM{'q26'}) {
$q26= "$FORM{'q26'}";
}
if ($FORM{'q27'}) {
$q27= "$FORM{'q27'}";
}
if ($FORM{'q28'}) {
$q28= "$FORM{'q28'}";
}
if ($FORM{'q29'}) {
$q29= "$FORM{'q29'}";
}
if ($FORM{'q40'}) {
$q40= "$FORM{'q40'}";
}
if ($FORM{'q31'}) {
$q31= "$FORM{'q31'}";
}
if ($FORM{'q32'}) {
$q32= "$FORM{'q32'}";
}
if ($FORM{'q33'}) {
$q33= "$FORM{'q33'}";
}
if ($FORM{'q34'}) {
$q34= "$FORM{'q34'}";
}
if ($FORM{'q35'}) {
$q35= "$FORM{'q35'}";
}
if ($FORM{'q36'}) {
$q36= "$FORM{'q36'}";
}
if ($FORM{'q37'}) {
$q37= "$FORM{'q37'}";
}
if ($FORM{'q38'}) {
$q38= "$FORM{'q38'}";
}
if ($FORM{'q39'}) {
$q39= "$FORM{'q39'}";
}
if ($FORM{'recipient'}) {
$recipient= "$FORM{'recipient'}";
}
if ($FORM{'recipient2'}) {
$recipient2= "$FORM{'recipient2'}";
}
if ($FORM{'recipient3'}) {
$recipient3= "$FORM{'recipient3'}";
}
if ($FORM{'recipient4'}) {
$recipient4= "$FORM{'recipient4'}";
}
if ($FORM{'recipient5'}) {
$recipient5= "$FORM{'recipient5'}";
}
if ($FORM{'recipient6'}) {
$recipient6= "$FORM{'recipient6'}";
}
if ($FORM{'recipient7'}) {
$recipient7= "$FORM{'recipient7'}";
}
if ($FORM{'recipient8'}) {
$recipient8= "$FORM{'recipient8'}";
}
} # end sub variables
sub parse_form {
local($name,$value);
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
# Remove any NULL characters, Server Side Includes
$value =~ s/\0//g;
$value =~ s///g;
if ($allow_html != 1) {
$value =~ s/<([^>]|\n)*>//g;
}
else {
unless ($name eq 'body') {
$value =~ s/<([^>]|\n)*>//g;
}
}
$FORM{$name} = $value;
}
}
sub print_header {
open (HEAD, ") {
$heading .= $_;
}
close HEAD;
open (SIDE, ") {
$sidebar .= $_;
}
close SIDE;
open (BOTTOM, "/var/www/vhosts/jokesandhumor.com/httpdocs/tests/celebrity-love-match/bottom.txt");
$bottom = "";
while () {
$bottom .= $_;
}
close BOTTOM;
print qq~
Celebrity Love Match
$heading
~;
#$ADVNoPrint = 1;
# $ADVQuery = "";
# require "/home/virtual/site2/fst/var/www/cgi-bin/ads.pl";
# end of print header
} #end of sub print_header
sub print_footer {
print qq~
$bottom
~;
} #end of sub print_footer
sub emailforlists {
if ($recipient) {
open(MAIL,"|$mailprog -t");
print MAIL "To: join-jokesandhumor\@list.netatlantic.com\n";
print MAIL "From: $email ($hisname)\n";
# Check for Message Subject
print MAIL "Subject: SUBSCRIBE\n\n";
print MAIL "Subscribe Me\n";
print MAIL "($email) on $date\n";
print MAIL "-" x 75 . "\n\n";
} # end recipient
if ($recipient2) {
open(MAIL,"|$mailprog -t");
print MAIL "To: jokesandhumorweekly-subscribe\@topica.com\n";
print MAIL "From: $email ($hisname)\n";
# Check for Message Subject
print MAIL "Subject: SUBSCRIBE\n\n";
print MAIL "Subscribe Me\n";
print MAIL "($email) on $date\n";
print MAIL "-" x 75 . "\n\n";
} # end recipient
if ($recipient3) {
open(MAIL,"|$mailprog -t");
print MAIL "To: hotbabedaily-subscribe\@topica.com\n";
print MAIL "From: $email ($hisname)\n";
# Check for Message Subject
print MAIL "Subject: SUBSCRIBE\n\n";
print MAIL "Subscribe Me\n";
print MAIL "($email) on $date\n";
print MAIL "-" x 75 . "\n\n";
} # end recipient
if ($recipient4) {
open(MAIL,"|$mailprog -t");
print MAIL "To: riddlesjh-subscribe\@topica.com\n";
print MAIL "From: $email ($hisname)\n";
# Check for Message Subject
print MAIL "Subject: SUBSCRIBE\n\n";
print MAIL "Subscribe Me\n";
print MAIL "($email) on $date\n";
print MAIL "-" x 75 . "\n\n";
} # end recipient
if ($recipient5) {
open(MAIL,"|$mailprog -t");
print MAIL "To: jokesandhumorclean-subscribe\@topica.com\n";
print MAIL "From: $email ($hisname)\n";
# Check for Message Subject
print MAIL "Subject: SUBSCRIBE\n\n";
print MAIL "Subscribe Me\n";
print MAIL "($email) on $date\n";
print MAIL "-" x 75 . "\n\n";
} # end recipient
if ($recipient6) {
open(MAIL,"|$mailprog -t");
print MAIL "To: wordofthedayjh-subscribe\@topica.com\n";
print MAIL "From: $email ($hisname)\n";
# Check for Message Subject
print MAIL "Subject: SUBSCRIBE\n\n";
print MAIL "Subscribe Me\n";
print MAIL "($email) on $date\n";
print MAIL "-" x 75 . "\n\n";
} # end recipient
if ($recipient7) {
open(MAIL,"|$mailprog -t");
print MAIL "To: drinksjh-subscribe\@topica.com\n";
print MAIL "From: $email ($hisname)\n";
# Check for Message Subject
print MAIL "Subject: SUBSCRIBE\n\n";
print MAIL "Subscribe Me\n";
print MAIL "($email) on $date\n";
print MAIL "-" x 75 . "\n\n";
} # end recipient
if ($recipient8) {
open(MAIL,"|$mailprog -t");
print MAIL "To: freebiesjh-subscribe\@topica.com\n";
print MAIL "From: $email ($hisname)\n";
# Check for Message Subject
print MAIL "Subject: SUBSCRIBE\n\n";
print MAIL "Subscribe Me\n";
print MAIL "($email) on $date\n";
print MAIL "-" x 75 . "\n\n";
} # end recipient
} # end subroutine
sub get_date {
# Define arrays for the day of the week and month of the year. #
@days = ('Sunday','Monday','Tuesday','Wednesday',
'Thursday','Friday','Saturday');
@months = ('January','February','March','April','May','June','July',
'August','September','October','November','December');
# Get the current time and format the hour, minutes and seconds. Add #
# 1900 to the year to get the full 4 digit year. #
($sec,$min,$hour,$mday,$mon,$year,$wday) = (localtime(time))[0,1,2,3,4,5,6];
$time = sprintf("%02d:%02d:%02d",$hour,$min,$sec);
$year += 1900;
$mon2 = $mon + 1;
# Format the date. #
$date = "$days[$wday], $months[$mon] $mday, $year at $time";
$date2 = "$mon2/$mday/$year";
}