#!/usr/bin/perl # ####################################################### # Top Sites Professional # # Created by Solution Scripts # Email: solutions@solutionscripts.com # Web: http://solutionscripts.com # ####################################################### # # # COPYRIGHT NOTICE: # # Copyright 1998 Solution Scripts All Rights Reserved. # # Selling or redistributing the code for this program # without prior written consent is expressly forbidden. # In all cases copyright and header must remain intact. # ###################################################### require "variables.pl"; $cgiurl = $ENV{'SCRIPT_NAME'}; print "Content-type: text/html\n\n"; $INPUT{'action'} = $ENV{'QUERY_STRING'}; read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); @pairs = split(/&/, $buffer); foreach $pair (@pairs) { ($name, $value) = split(/=/, $pair); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; $value =~ s/<([^>]|\n)*>//g; if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; } else { $INPUT{$name} = $value; } } $version = "3.05"; $time = time; $reset_offset = $reset_offset * 3600; $time = $time + $reset_offset; ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($time); $mon++; $year += 1900; $now = "$mon.$mday.$year"; $sunday = $yday - $wday; &Header; if ($INPUT{'action'} eq "new") { &new; } elsif ($INPUT{'action'} eq "edit") { &log_edit; } elsif ($INPUT{'action'} eq "html") { &html; } elsif ($INPUT{'action'} eq "name") { &name; } elsif ($INPUT{'action'} eq "password") { &password; } elsif ($INPUT{'editfinal'}) { &editfinal; } elsif ($INPUT{'edit'}) { &edit; } elsif ($INPUT{'stats'}) { &stats; } elsif ($INPUT{'new_pass'}) { &new_pass; } elsif ($INPUT{'html_dis'}) { &html_dis; } elsif ($INPUT{'locate'}) { &locate; } elsif ($INPUT{'newaccount'}) {&newaccount; } else { &htmloptions; } exit; sub htmloptions { print < Welcome to $topsite_name
Please choose one of the following:
Create a new account
Edit, check stats on existing account
Lost html to put on page
Lost account name
Lost account password

EOF &Footer; exit; } sub new { print <
Sign up for an account at $topsite_name

EOF if ($terms) { open (PASSWORD, "$path/data/rules.txt"); @rules = ; close (PASSWORD); print < Terms and Conditions

@rules

-- I Agree
EOF } print < Account Name:
Must be 3-12 characters,
letters and numbers only Site Name: Your Email: Site URL: Site Desrciption:
Enter only Letters/Numbers/Spaces and: .,!*() Site image: Password: Retype Password:

EOF &Footer; exit; } sub log_edit { print <
Edit your account - Check stats

Account Name:
Password:

EOF &Footer; exit; } sub edit { unless ($INPUT{'id'}) { print <
You must enter an account number

EOF &Footer; exit; } unless ($INPUT{'pass'}) { print <
The password you entered for account $mem is incorrect!

EOF &Footer; exit; } $mem = $INPUT{'id'}; open (DAT,"<$path/members/$mem.txt") || &error("No such member as $mem"); if ($use_flock) { flock DAT, 2; } @edit_array = ; close (DAT); open (DAT,"<$path/members/$mem.dat"); if ($use_flock) { flock DAT, 2; } @data = ; close (DAT); chomp ($edit_array[10]); chomp ($edit_array[11]); chomp ($edit_array[9]); chomp ($edit_array[13]); chomp ($edit_array[15]); chomp ($edit_array[16]); chomp ($edit_array[18]); unless ($edit_array[9] eq $now) { $edit_array[1] = 0; $edit_array[10] = 0; } unless ($edit_array[13] eq $mon) { $edit_array[14] = 0; $edit_array[15] = 0; } unless ($edit_array[16] eq $sunday) { $edit_array[17] = 0; $edit_array[18] = 0; } $rank = pop(@data); @ranks = split(/\|/,$rank); $newpassword = crypt($INPUT{'pass'}, aa); $newpassword .= "\n"; unless ($newpassword eq $edit_array[12]) { print <
The password you entered for account $mem is incorrect!

EOF &Footer; exit; } print < Account $mem
$message
Stats for $mem
Current Rank: $ranks[3]
Time In Out
Total $edit_array[0] $edit_array[11]
Today $edit_array[1] $edit_array[10]
Week $edit_array[17] $edit_array[18]
Month $edit_array[14] $edit_array[15]

Edit account $mem

Site Name:
Site URL:
Site Image:
Email Address:
Description:
New Password:


EOF &Footer; exit; } sub editfinal { $error=0; $err = ""; unless($INPUT{'pass'}) { $err .= "You must enter your password to edit your account
"; $error=1; } unless($INPUT{'url'}=~/\http:/) { $err .= "You must enter a valid url
"; $error = 1; } unless($INPUT{'email'}=~/\@/) { $err.= "You must enter a valid email address
"; $error = 1; } if ($error == 1 ) { print <
Error found, please go back and fix the following:

$err
EOF &Footer; exit; } $num_edit=0; $mem = $INPUT{'id'}; open (DAT,"<$path/members/$mem.txt") || &error("No account"); if ($use_flock) { flock DAT, 2; } @edit_array = ; close (DAT); $newpassword = crypt($INPUT{'pass'}, aa); $newpassword .= "\n"; unless ($newpassword eq $edit_array[12]) { print <
The password you entered for account $mem is incorrect!

EOF &Footer; exit; } $edit_array[5] = "$INPUT{'name'}\n"; $edit_array[4] = "$INPUT{'url'}\n"; $edit_array[6] = "$INPUT{'email'}\n"; $edit_array[7] = "$INPUT{'descrip'}\n"; $edit_array[8] = "$INPUT{'banner'}\n"; if ($INPUT{'passw'}) { $INPUT{'pass'} = $INPUT{'passw'}; $newpass =crypt($INPUT{'passw'}, aa); $newpass .="\n"; $edit_array[12] = $newpass; } open (DATA,">$path/members/$mem.txt") || &error; if ($use_flock) { flock DATA, 2; } print DATA @edit_array; close (DATA); $message = "
Account $mem information updated
"; &edit; exit; } sub newaccount { if ($terms) { unless ($INPUT{'agree'}) { print <
You must agree to the terms and conditions before joining,

please go back and read them, then check the "I agree box"

EOF &Footer; exit; } } $new_id = $INPUT{'account'}; @out = split(//,$new_id); $a=0; foreach $char (@out) { $a++; unless ($char =~ /[a-z0-9]/) { print <
You entered an invalid account name
Make sure you only enter letters and numbers, but nothing else
and that it is only 3 to 12 characters


EOF &Footer; exit; } } $new_id2 = $INPUT{'des'}; @out = split(//,$new_id2); $b=0; foreach $char2 (@out) { $b++; unless ($char2 =~ /[a-zA-Z0-9 ..,!*()]/) { print <
You entered an invalid description
Make sure you only enter letters, numbers,
spaces, and the following: .,!*()


EOF &Footer; exit; } } $new_id3 = $INPUT{'name'}; @out = split(//,$new_id3); $c=0; foreach $char3 (@out) { $c++; unless ($char3 =~ /[a-zA-Z0-9 .,!*()]/) { print <
You entered an invalid site name
Make sure you only enter letters, and numbers.


EOF &Footer; exit; } } if ($a < 3 || $a > 12) { print <
You entered an invalid account name
Make sure you only enter letters and numbers, but nothing else
and that it is only 3 to 12 characters


EOF &Footer; exit; } if (-e "$path/members/$new_id.txt") { print <
The account name you selected is already in use,
please select another one.


EOF &Footer; exit; } $error=0; unless ($INPUT{'name'}) { $err .= "You must enter the site name
"; $error = 1; } unless ($INPUT{'url'}=~/\http:/) { $err.= "You have entered an invalid url for you site
\n"; $error =1; } unless ($INPUT{'email'}=~/\@/) { $err .="You have entered an invalid e-mail address
\n"; $error=1; } unless ($INPUT{'pass'}) { $err .= "You must enter a password
"; $error = 1; } unless ($INPUT{'pass'} eq $INPUT{'pass2'}) { $err .= "The two passwords you entered must be the same
\n"; $error=1; } if ($error) { print <
Errors were found in your sign up form.
They were:

$err
Please go back and fix them.


EOF &Footer; exit; } open (BLOCK, "$path/data/block.txt"); @block = ; close (BLOCK); $found=0; $ipaddress = $ENV{'REMOTE_ADDR'}; foreach $line (@block) { chomp($line); if ($ipaddress =~ /^$line/i) { $found = 1; last; } if ($INPUT{'url'} =~ /^$line/i) { $found = 1; last; } if ($INPUT{'email'} =~ /^$line/i) { $found = 1; last; } } if ($found) { print <
We are sorry, you can not create an account at this time


EOF &Footer; exit; } $password = crypt($INPUT{'pass'}, aa); $current_time = time(); open(DB, ">$path/members/$new_id.txt") || &error("Unable to create file $new_id.txt $!"); if ($use_flock) { flock DB, 2; } print DB "0\n"; print DB "0\n"; print DB "$current_time\n"; print DB "0\n"; print DB "$INPUT{'url'}\n"; print DB "$INPUT{'name'}\n"; print DB "$INPUT{'email'}\n"; print DB "$INPUT{'des'}\n"; print DB "$INPUT{'banner'}\n"; print DB "0\n"; print DB "0\n"; print DB "0\n"; print DB "$password\n"; print DB "0\n"; print DB "0\n"; print DB "0\n"; print DB "0\n"; print DB "0\n"; print DB "0\n"; close (DB); open (DAT,"<$path/data/code.txt"); @code = ; close (DAT); open (DAT,"<$path/data/codeh.txt"); @codeh = ; close (DAT); open (DAT,"<$path/data/codem.txt"); @codem = ; close (DAT); unless (@code) { $code[0] = "\n"; $code[1] =""; } print <
Thank you for joining $topsite_name


Your account information is as follows:
Account Name: $new_id
Password: $INPUT{'pass'}
Your Name: $INPUT{'name'}
Your Email: $INPUT{'email'}
Web Site Url: $INPUT{'url'}

Below is the html code you need to insert into your web site. Once this has been inserted into your html pages, the first time you send a hit to Top Sites, your account will be activated.

EOF foreach $cd(@code) { $cd =~ s/\$url_to_cgi/$url_to_cgi/ig; $cd =~ s/\$new_id/$new_id/ig; $cd =~ s//\>\;/ig; $cd =~ s/\n/
/ig; print "$cd"; } print < @codeh

To view the site rankings, you may go to $url/$topsite_file.
If you would like to edit your account info or check your stats, you may go to $url_to_cgi/editmember.cgi?edit.


EOF &Footer; $toemail = $INPUT{'email'}; $messages = ''; $messages .= "Thank you for submitting your site to $topsite_name \n\n"; $messages .= "Your account name and password are as follows:\n"; $messages .= "Account name: $new_id\n"; $messages .= "Password: $INPUT{'pass'}\n\n"; $messages .= "You need to put the following html code on your web site:\n\n"; foreach $cf(@code) { $cf =~ s/\<\;//ig; $cf =~ s/
/\n/ig; $messages .= "$cf"; } $messages .= "\n@codem\n\n"; $messages .= "View the $topsite_name at $url/$topsite_file\n\n"; $messages .= "Edit your account and view stats at $url_to_cgi/editmember.cgi?edit\n\n"; &emails($toemail,$topsite_name,$messages); exit; } sub locate { opendir (DIR, "$path/members") || &error("Unable to open members dir. for reading"); @file = grep { /.txt/ } readdir(DIR); close (DIR); $found =0; foreach $line(@file) { open (DAT,"<$path/members/$line") || &error("Unable to open file $line for reading"); if ($use_flock) { flock DAT, 2; } @array = ; close (DAT); chomp ($array[6]); if ($INPUT{'email'} eq $array[6]) { $account = $line; $account =~s/\.txt//; $new_id = $account; open (DAT,"<$path/data/code.txt"); @code = ; close (DAT); open (DAT,"<$path/data/codem.txt"); @codem = ; close (DAT); unless (@code) { $code[0] = "\n"; $code[1] =""; } $toemail = $INPUT{'email'}; $messages = ''; $messages .= "This is the info you requested from $topsite_name \n\n"; $messages .= "Your account name is: $account\n\n"; $messages .= "The following is the html code that should be on your web site:\n\n"; foreach $cf(@code) { $cf =~ s/\$url_to_cgi/$url_to_cgi/ig; $cf =~ s/\$new_id/$new_id/ig; $messages .= "$cf"; } $messages .= "\n@codem\n\n"; $messages .= "View the $topsite_name at $url/$topsite_file\n\n"; $messages .= "Edit your account and view stats at $url_to_cgi/editmember.cgi?edit\n\n"; &emails($toemail,$topsite_name,$messages); $found=1; } } if ($found) { print <
Account Found

An account was found for the email address that was entered
An email including the account name has been sent to $INPUT{'email'}

EOF &Footer; exit; } else { print <
We are sorry,
There is no account for the email $INPUT{'email'}

EOF &Footer; exit; } } sub html { print <
Please enter you account name below and we will show you your customized html you need to put on your web site.

Account Name:


EOF &Footer; exit; } sub html_dis { $new_id= $INPUT{'id'}; print <
Below is the html code you need for account $new_id
You can copy and paste it into any html page you wish

EOF open (DAT,"<$path/data/code.txt"); @code = ; close (DAT); open (DAT,"<$path/data/codeh.txt"); @codeh = ; close (DAT); unless (@code) { $code[0] = "\n"; $code[1] =""; } foreach $cd(@code) { $cd =~ s/\$url_to_cgi/$url_to_cgi/ig; $cd =~ s/\$new_id/$new_id/ig; $cd =~ s//\>\;/ig; $cd =~ s/\n/
/ig; print "$cd"; } print <
@codeh


EOF &Footer; exit; } sub name { print <
Forget your account number?
Enter you email address

EOF &Footer; exit; } sub password { print <
Forget your account password?
Enter you account name and email address and we will send you a new password
Account:
Email:

EOF &Footer; exit; } sub new_pass { open (DAT,"<$path/members/$INPUT{'account'}.txt") || &error("No such account as $INPUT{'account'}"); if ($use_flock) { flock DAT, 2; } @array = ; close (DAT); chomp ($array[6]); if ($INPUT{'email'} eq $array[6]) { # NEW PASS # generate random password srand($time); $password =""; @passset = ('a'..'k', 'm'..'z', 'A'..'N', 'P'..'Z', '2'..'9'); for ($i = 0; $i < 8; $i++) { $randum_num = int(rand($#passset + 1)); $password .= @passset[$randum_num]; } $newpass =crypt($password, aa); $newpass .="\n"; $array[12] = $newpass; $array[6] .= "\n"; open (DATA,">$path/members/$INPUT{'account'}.txt") || &error; if ($use_flock) { flock DATA, 2; } print DATA @array; close (DATA); $messages =""; $toemail = $INPUT{'email'}; $new_id = $INPUT{'account'}; $messages .= "Here is the new password you requested from $topsite_name\n\n"; $messages .= "Account: $INPUT{'account'}\n"; $messages .= "New Password: $password\n\n"; $messages .= "The following is the html code that should be on your web site:\n\n"; open (DAT,"<$path/data/code.txt"); @code = ; close (DAT); open (DAT,"<$path/data/codem.txt"); @codem = ; close (DAT); unless (@code) { $code[0] = "\n"; $code[1] =""; } foreach $cf(@code) { $cf =~ s/\$url_to_cgi/$url_to_cgi/ig; $cf =~ s/\$new_id/$new_id/ig; $messages .= "$cf"; } $messages .= "\n@codem\n\n"; $messages .= "View the $topsite_name at $url/$topsite_file\n\n"; $messages .= "Edit your account and view stats at $url_to_cgi/editmember.cgi?edit\n\n"; $subject = "$topsite_name\n"; &emails($toemail,$subject,$messages); print < The account was located and a new password has been set, the password was mailed to the email address you entered.

EOF &Footer; exit; } else { print < We are sorry, the email address you entered was different from the one we had on record for the account $INPUT{'account'}

Therefore we can not send you the new password....

EOF &Footer; exit; } } sub stats { $mem = $INPUT{'id'}; open (DAT,"<$path/members/$mem.txt") || &error("No account"); if ($use_flock) { flock DAT, 2; } @edit_array = ; close (DAT); $newpassword = crypt($INPUT{'pass'}, aa); $newpassword .= "\n"; unless ($newpassword eq $edit_array[12]) { print <
The password you entered for account $mem is incorrect!

EOF &Footer; exit; } open (PASSWORD, "$path/members/$mem.dat"); @daily = ; close (PASSWORD); @daily = reverse(@daily); if ($how_rank eq "total") { $hows = "the total amount of hits sent in"; $howw = "the total number people you have sent since you have been an member"; } elsif ($how_rank eq "hitsday") { $hows = "the average amount of hits you send each day"; $howw = "the number of total hits you have sent, diveded by the number of days you have been a member"; } elsif ($how_rank eq 'today') { $hows = "the number of hits sent today"; $howw = "the total amount of people you have sent just today, reset everyday"; } elsif ($how_rank eq 'week') { $hows = "the number of hits sent this week"; $howw = "the total amount of people you have sent just this week, reset every Sunday"; } elsif ($how_rank eq 'month') { $hows = "the number of hits sent this month"; $howw = "the total amount of people you have sent just this month, reset the 1rst of every month"; } print < Daily log Date In Out Rank EOF foreach $entry(@daily) { @out = split(/\|/,$entry); print < $out[0] $out[1] $out[2] $out[3] EOF } print <
$topsite_name is ranked on $hows meaning its ranked on $howw
EOF &Footer; exit; } sub emails { $recipient = $_[0]; $subject = $_[1]; $message = $_[2]; ### SMTP ### if ($smtp) { $smtp_server = $smtp; $emailfrom = $your_email; ($x,$x,$x,$x, $here) = gethostbyname($null); ($x,$x,$x,$x, $there) = gethostbyname($smtp_server); $thisserver = pack('S n a4 x8',2,0,$here); $remoteserver = pack('S n a4 x8',2,25,$there); #NOTE, if Solaris, uncomment the line below and delete the one below it...leave alone for NT #(!(socket(S,2,2,6))) && (&error("SMTP EMAIL: Connect error!")); (!(socket(S,2,1,6))) && (&error("SMTP EMAIL: Connect error! socket")); (!(bind(S,$thisserver))) && (&error("SMTP EMAIL: Connect error! bind")); (!(connect(S,$remoteserver))) && (&error("SMTP EMAIL: connection to $smtp_server has failed!")); select(S); $| = 1; select(STDOUT); $DATA_IN = ; ($DATA_IN !~ /^220/) && (&error("SMTP EMAIL: data in Connect error - 220")); print S "HELO $ENV{REMOTE_HOST}\r\n"; $DATA_IN = ; ($DATA_IN !~ /^250/) && (&error("SMTP EMAIL: data in Connect error - 250")); print S "MAIL FROM:<$emailfrom>\n"; $DATA_IN = ; ($DATA_IN !~ /^250/) && (&error("SMTP EMAIL: $emailfrom address not valid")); print S "RCPT TO:<$recipient>\n"; $DATA_IN = ; ($DATA_IN !~ /^250/) && (&error("SMTP EMAIL: $recipient address not valid")); print S "DATA\n"; $DATA_IN = ; ($DATA_IN !~ /^354/) && (&error("SMTP EMAIL: Message send failed - 354")); print S <; ($DATA_IN !~ /^250/) && (&error("SMTP EMAIL: Message send failed - try again - 250")); print S "QUIT\n"; } else { open(MAIL, "|$mail_prog -t") || &error("Could not send out emails"); print MAIL "To: $recipient \n"; print MAIL "From: $your_email \n"; print MAIL "Subject: $subject \n\n"; print MAIL $message; print MAIL "\n\n"; close (MAIL); } } ########## CGI HEADER ########## sub Header { print "$topsite_name\n"; print "\n"; open (HEAD, "$path/data/header.txt"); @head = ; close (HEAD); foreach $line (@head) { print "$line"; } print "

"; } ########## CGI FOOTER ########## sub Footer { print HTML"
"; open (HEAD, "$path/data/footer.txt"); @foot = ; close (HEAD); foreach $line (@foot) { print "$line"; } if ($credit) { print "

Top Sites Professional v$version
Created by Solution Scripts

"; } print "\n"; } sub error{ $errors = $_[0] ; print"Top Sites error
"; print"
Top Sites error has occured in editmember.cgi
"; print"The error is:
$errors -- $!

"; print"If you do not run this Top Sites and just clicked thru, please let $your_email of the error that just occured

"; print"If you are the operator of this Top Sites and are having trouble getting Top Sites to run, please consult the Top Sites Pro online manual or post a message in the forum in the Top Sites Pro members lounge.
"; print "


Top Sites Professional
Created by: Solution Scripts

"; exit; }