#!/usr/bin/perl
#
############################################
##                                        ##
##              Subscribe Me              ##
##          by CGI Script Center          ##
##       (e-mail cgi@elitehost.com)       ##
##                                        ##
##             version:  1.14             ##
##         last modified:  10/20/98       ##
##           copyright (c) 1998           ##
##                                        ##
##    latest version is available from    ##
##          The CGI Script Center         ##
##        http://cgi.elitehost.com        ##
##                                        ##
############################################

# COPYRIGHT NOTICE:
#
# Copyright 1998 Elite Host.  All Rights Reserved.
#
# This program may be used and modified free of charge by anyone, so
# long as this copyright notice and the header above remain intact.  By
# using this program you agree to indemnify Elite Host and any company
# programmers from any liability.
#
# Selling the code for this program without prior written consent is
# expressly forbidden.  Obtain permission before redistributing this
# program over the Internet or in any other medium.  In all cases
# copyright and header must remain intact.
#
# PROGRAM DESCRIPTION:
#
# This program is designed to assist users by creating an automatic
# customer/prospect mailing list that the customer/prospect can add or
# remove themselves from without the assistance of the webmaster.
# Subscribe Me has a built-in encrypted password protected form to allow 
# webmasters to mass mail their mailing list database with.
# 
# Please read the README file that comes with this program for complete
# installation and usage instructions, or visit http://cgi.elitehost.com
# for posted instructions.
#
#################################################################
# VERSION HISTORY
#################################################################
# 1.0 - Released 2/24/98
#
# 1.1 - Released 4/8/98
# Upgrades include:
# - Administration password requirement before entering the
# Mailing Form.
# - File Locking option to keep address.txt file from being
# corrupted during heavy usage.
# - Mail-back confirmation of mailing list subscription and
# removal.
#
# 1.12 - 05/05/98
# - Unix Version only upgraded.  Fix for NT version still not
# properly configured.  Fixed the "timeout" problem that occured
# when a large number of mailings were being sent.  We bypass
# the problem altogether by starting a new process.  Subscribe
# Me has been successfully tested on a 2,500 person mailing list.
# If you have a higher number of list members that you have
# successfully used Subscribe Me to mail to, please forward
# that information to:  cgi@elitehost.com
# - Added a "closing" text file to your general mailings. This
# will allow you to add a personalized message at the bottom
# of your mailing lists.
# - Added an error message to the Password.txt file creation.
# No more messages saying "Success! Password file created!"
# When in fact the permissions on the directory didn't allow
# the file to be created.
# 
# 1.13 - Skipped, for superstitious reasons.  ;)
#
# 1.14 - 10/20/98
# Two fixes.  Each deals with security issues, so we
# thought it best not to explain the details, however,
# we do highly recommend that you install this version
# as soon as possible.
#
#################################################################
# DO NOT EDIT BELOW PARAGRAPH
#################################################################

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;
	if ($INPUT{$name}) { $INPUT{$name} = $INPUT{$name}.",".$value; }
	else { $INPUT{$name} = $value; }
}

$cgiurl = $ENV{'SCRIPT_NAME'};
################################################################
# DO NOT EDIT ABOVE PARAGRAPH
################################################################

################################################################
# EDIT USER INFORMATION BELOW
################################################################

# Type the full path to your Mail program
$mailprog = '/usr/bin/sendmail';

# Type the full path to your Subscribe Me directory
$memberinfo = "/home/ethi/www/cgi/cedar/subscribe";

# Type the full path to your Administration Password directory
$passfile = "/home/ethi/www/cgi/cedar/subscribe";

# Type your email address.  Make sure to place a \ in front of the @
# As an example:  cgi\@elitehost.com
$list_mail = "cedar\@ethi.com";

# Type the name of your mailing list
$list_name = "Cedar Productions Inforamtion Center";

# Type your website URL (example: http://www.yoursite.com)
$websiteurl = "http://www.ethi.com/cedar/";

# If you are run the script and receive File Locking (flock)
# errors, remove the number 2 from between the quotes.
# Then it would appear: $LOCK_EX = "";
$LOCK_EX = "2";

# If you would like your mailings to have a closing message,
# create a text file called email.txt and upload it to the
# directory that you define below.  This message will be added
# to the end of your mailings.
$closing = "/home/ethi/www/cgi/cedar/subscribe";

###############################################################
# DO NOT EDIT BELOW THIS LINE
###############################################################

$version = "1.14";

if ($INPUT{'subscribe'} eq "subscribe") { &subscribe; }
elsif ($INPUT{'subscribe'} eq "unsubscribe")  {&unsubscribe; }
elsif ($INPUT{'mailing'}) {&mailing; }
elsif ($INPUT{'setpwd'}) {&setpwd; }
elsif ($INPUT{'passcheck'}) {&passcheck; }
else {&form; }
exit;




#$cgiurl = $ENV{'SCRIPT_NAME'};

# 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;

    # Format the date.                                                       #
    $date = "$days[$wday], $months[$mon] $mday, $year at $time";




########################################################
# Subroutine FIND - Will find member info and email it
########################################################

sub setpassword {

print "<HTML><HEAD><TITLE>Subscribe Me: Set Password!</TITLE></HEAD><BODY
BGCOLOR=\"#FFFFFF\"><FORM ACTION=\"$cgiurl\" METHOD=\"POST\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Set Password!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">You have not yet set your
administration password!  Please enter your password below, once to set the
password and the second time to confirm it.</FONT></P>
<CENTER><TABLE BORDER=\"0\"><TBODY><COLDEFS><COLDEF><COLDEF></COLDEFS><ROWS><TR
><TD ALIGN=\"RIGHT\" COLSTART=\"1\"><INPUT TYPE=\"PASSWORD\" NAME=\"pwd\"></TD><TD
COLSTART=\"2\"><FONT SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">password</FONT></TD></TR>
<TR><TD ALIGN=\"RIGHT\" COLSTART=\"1\"><INPUT TYPE=\"PASSWORD\" NAME=\"pwd2\"></TD><TD
COLSTART=\"2\"><FONT SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">confirmation</FONT></TD></TR>
<TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><BR><INPUT
TYPE=\"SUBMIT\" NAME=\"setpwd\" VALUE=\"  Set Password  \"></TD><TD COLSTART=\"2\"><BR><INPUT
TYPE=\"RESET\" NAME=\"\"></TD></TR></ROWS></TBODY></TABLE></CENTER><CENTER><TABLE
BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></FORM></BODY></HTML>";

exit;

}

sub setpwd {
print "Content-type: text/html\n\n";
unless ($INPUT{'pwd'} && $INPUT{'pwd2'}) {

print "<HTML><HEAD><TITLE>Subscribe Me: Password Error!</TITLE></HEAD><BODY
BGCOLOR=\"#FFFFFF\"><FORM ACTION=\"$cgiurl\" METHOD=\"POST\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Password Error!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Please enter your password twice.  Once to set it, and once to confirm it.</FONT></P>
<CENTER><TABLE BORDER=\"0\"><TBODY><COLDEFS><COLDEF><COLDEF></COLDEFS><ROWS><TR
><TD ALIGN=\"RIGHT\" COLSTART=\"1\"><INPUT TYPE=\"PASSWORD\" NAME=\"pwd\"></TD><TD
COLSTART=\"2\"><FONT SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">password</FONT></TD></TR>
<TR><TD ALIGN=\"RIGHT\" COLSTART=\"1\"><INPUT TYPE=\"PASSWORD\" NAME=\"pwd2\"></TD><TD
COLSTART=\"2\"><FONT SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">confirmation</FONT></TD></TR>
<TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><BR><INPUT
TYPE=\"SUBMIT\" NAME=\"setpwd\" VALUE=\"  Set Password  \"></TD><TD COLSTART=\"2\"><BR><INPUT
TYPE=\"RESET\" NAME=\"\"></TD></TR></ROWS></TBODY></TABLE></CENTER><CENTER><TABLE
BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></FORM></BODY></HTML>";

exit;
}
if ($INPUT{'pwd'} && $INPUT{'pwd2'}) {
    if ($INPUT{'pwd'} ne $INPUT{'pwd2'}) {

print "<HTML><HEAD><TITLE>Subscribe Me: Password Mismatch!</TITLE></HEAD><BODY
BGCOLOR=\"#FFFFFF\"><FORM ACTION=\"$cgiurl\" METHOD=\"POST\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Password Mismatch!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">The confirmation password you entered did not match the orginal password.  Please try again.</FONT></P>
<CENTER><TABLE BORDER=\"0\"><TBODY><COLDEFS><COLDEF><COLDEF></COLDEFS><ROWS><TR
><TD ALIGN=\"RIGHT\" COLSTART=\"1\"><INPUT TYPE=\"PASSWORD\" NAME=\"pwd\"></TD><TD
COLSTART=\"2\"><FONT SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">password</FONT></TD></TR>
<TR><TD ALIGN=\"RIGHT\" COLSTART=\"1\"><INPUT TYPE=\"PASSWORD\" NAME=\"pwd2\"></TD><TD
COLSTART=\"2\"><FONT SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">confirmation</FONT></TD></TR>
<TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><BR><INPUT
TYPE=\"SUBMIT\" NAME=\"setpwd\" VALUE=\"  Set Password  \"></TD><TD COLSTART=\"2\"><BR><INPUT
TYPE=\"RESET\" NAME=\"\"></TD></TR></ROWS></TBODY></TABLE></CENTER><CENTER><TABLE
BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></FORM></BODY></HTML>";

exit;


}
}

chop ($pwd) if ($pwd =~ /\n$/);
		$newpassword = crypt($INPUT{'pwd'}, aa);

open (PASSWORD, ">$passfile/password.txt")|| die print "Unable to create password.txt file.  Check your directory permissions";
     
    if ($LOCK_EX){ 
      flock(PASSWORD, $LOCK_EX); #Locks the file
	}
      print PASSWORD "$newpassword";
	close (PASSWORD);

print "<HTML><HEAD><TITLE>Subscribe Me: Password Success!</TITLE></HEAD><BODY BGCOLOR=\"#FFFFFF\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe
Me</FONT> Status: Password Success!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Your Administration password has been set!  You will not be able to send mail without your password, so please write it down.</FONT></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">To mail to your Subscribe Me mailing list, use your <A
HREF=\"$cgiurl\">built-in form</A>.</FONT></P>
<CENTER><TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR
><TD COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></BODY></HTML>";
exit;
}


sub subscribe {

&checkaddress;

open (DAT,"$memberinfo/address.txt");
if ($LOCK_EX){ 
      flock(DAT, $LOCK_EX); #Locks the file
	}
@database_array = <DAT>;
close(DAT);

        foreach $lines(@database_array) {
         chomp($lines);            


&parseemail;

if ($existing eq $email) {
         
# if ($lines =~ /$INPUT{'email'}/i) {

      print "Content-type: text/html\n\n";
      print "<HTML><HEAD><TITLE>Subscribe Me: Already Listed!</TITLE></HEAD><BODY BGCOLOR=\"#FFFFFF\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Already Listed!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Your email address:
$INPUT{'email'} is already in our database!</FONT></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">If you believe you are not receiving our intended mailings, please contact us at <A
HREF=\"mailto:$list_mail\">$list_mail</A> for assistance.</FONT></P>
<CENTER><TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR
><TD COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></BODY></HTML>";
      exit;

 } 
 }
      print "Content-type: text/html\n\n";
      open (DAT,">>$memberinfo/address.txt") || die print"Permissions Error - Can't open address.txt file.";
      if ($LOCK_EX){ 
      flock(DAT, $LOCK_EX); #Locks the file
	}
         print DAT "$INPUT{'email'}\n" || die print"Permissions Error - can't write to address.txt file.";
              close (DAT);
              print "<HTML><HEAD><TITLE>Subscribe Me: Success!</TITLE></HEAD><BODY BGCOLOR=\"#FFFFFF\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Success!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Your email address:  $INPUT{'email'} has been added to the $list_name mailing list.</FONT></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">If at any time you desire to be removed from our list, you may do so <A
HREF=\"$websiteurl\">at our website</A>.  Please contact
<A HREF= \"mailto:$list_mail\">$list_mail</A> if you
need any further assistance.</FONT></P>
<CENTER><TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR
><TD COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></BODY></HTML>";




open (MAIL, "|$mailprog -t")
	            || print "Can't start mail program";
			print MAIL "To: $INPUT{'email'}\n";
		      print MAIL  "From: $list_mail\n";
			print MAIL  "Subject: You've Been Added!\n\n";
				

    print MAIL "This message is to confirm the addition of your\n";
    print MAIL "email address: $INPUT{'email'} to the $list_name\n";
    print MAIL "Subscribe Me mailing list.\n\n";
    print MAIL "If you feel you have received this notice in error,\n";
    print MAIL "please visit the $list_name Subscribe Me mailing list\n";
    print MAIL "at our website: $websiteurl\n";
    print MAIL "to remove yourself automatically.\n\n";
    print MAIL "Thank you,\n\n";
    print MAIL "$list_name\n\n";
				  
				close (MAIL);

exit;
}

sub unsubscribe {

&checkaddress;

open (DAT,"$memberinfo/address.txt");
if ($LOCK_EX){ 
      flock(DAT, $LOCK_EX); #Locks the file
	}
@database_array = <DAT>;
close(DAT);

print "Content-type: text/html\n\n";

open (DAT,"<$memberinfo/address.txt");
      if ($LOCK_EX){ 
      flock(DAT, $LOCK_EX); #Locks the file
	}
         foreach $lines(@database_array) {
         chomp($lines);
         
&parseemail;


if ($existing eq $email) {

# if ($lines =~ /$INPUT{'email'}/i) {

              print "<HTML><HEAD><TITLE>Subscribe Me: Removed!</TITLE></HEAD><BODY BGCOLOR=\"#FFFFFF\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Removed!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Your email address: $INPUT{'email'} has been removed from our database.  We are sorry to see you go!</FONT></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">If ever you desire to be re-added to our mailing list, you may do so <A
HREF=\"$websiteurl\">at our website</A>.  Please contact
<A HREF=\"mailto:$list_mail\">$list_mail</A> for assistance.</FONT></P>
<CENTER><TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR
><TD COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></BODY></HTML>";


close (DAT);

    
        
   open (DAT,">$memberinfo/address.txt");
       if ($LOCK_EX){ 
      flock(DAT, $LOCK_EX); #Locks the file
	}
         foreach $lines(@database_array) {
         chomp($lines);

&parseemail;


if ($existing ne $email) {


#   if ($lines !~ /$INPUT{'email'}/i) {
       
              print DAT "$lines\n";
              
              }
}
              close (DAT);



open (MAIL, "|$mailprog -t")
	            || print "Can't start mail program";
			print MAIL "To: $INPUT{'email'}\n";
		      print MAIL  "From: $list_mail\n";
			print MAIL  "Subject: You've Been Removed!\n\n";
				

    print MAIL "This message is to confirm the removal of your\n";
    print MAIL "email address: $INPUT{'email'} from the $list_name\n";
    print MAIL "Subscribe Me mailing list.\n\n";
    print MAIL "We're sorry to see you go!\n\n";
    print MAIL "If you change your mind, you may resubscribe\n";
    print MAIL "at: $websiteurl\n\n";
    print MAIL "Thank you,\n\n";
    print MAIL "$list_name\n\n";
				close (MAIL);


exit;
}
}
print "<HTML><HEAD><TITLE>Subscribe Me: Not Found!</TITLE></HEAD><BODY BGCOLOR=\"#FFFFFF\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Not Found!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Your email address: $INPUT{'email'} was not found in our database.  Please make sure you spelled the address properly and that
you used the same email address that you created your account with.</FONT></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">If you need further assistance, please contact 
<A HREF=\"mailto:$list_mail\">$list_mail</A>.</FONT></P>
<CENTER><TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR
><TD COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></BODY></HTML>";

close (DAT);



exit;       
}


sub form {

print "Content-type: text/html\n\n";


unless (-e "$passfile/password.txt") {

&setpassword;

}

&adminpass;

}


sub form2 {

print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>$list_name's Subscribe Me Mailing Form</TITLE></HEAD><BODY
BGCOLOR=\"#FFFFFF\"><FORM
 ACTION=\"$cgiurl\" METHOD=\"POST\"><CENTER><TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS
><COLDEF></COLDEFS><ROWS><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"+2\" FACE=\"verdana, arial, helvetica\"><FONT COLOR=\"#FF0000\">Subscribe
Me:</FONT> Mailing Form<BR><BR></FONT><TABLE BORDER=\"0\"><TBODY><COLDEFS><COLDEF>
<COLDEF></COLDEFS><ROWS><TR><TD VALIGN=\"TOP\" COLSTART=\"1\"><FONT
SIZE=\"-1\" FACE=\"verdana, arial, helvetica\"><B>Subject:</B></FONT></TD><TD
VALIGN=\"TOP\" COLSTART=\"2\"><INPUT TYPE=\"TEXT\" SIZE=\"40\" NAME=\"mail_subject\"></TD></TR>
<TR><TD COLSTART=\"1\"><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\"><B>Administration Password:</B></FONT></TD>
<TD VALIGN=\"TOP\" COLSTART=\"2\"><INPUT TYPE=\"PASSWORD\" NAME=\"password\"></TD></TR></ROWS></TBODY></TABLE>

<TEXTAREA NAME=\"message\" ROWS=\"12\" COLS=\"50\" WRAP=\"OFF\"></TEXTAREA><BR><INPUT
TYPE=\"SUBMIT\" VALUE=\"    Send    \" NAME=\"mailing\"><INPUT TYPE=\"RESET\" NAME=\"\">

</TD></TR></ROWS></TBODY></TABLE></CENTER></FORM><FORM
ACTION=\"$cgiurl\" METHOD=\"POST\"><CENTER><TABLE BORDER=\"0\"><TBODY><COLDEFS><COLDEF></COLDEFS>
<ROWS><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><HR SIZE=\"1\" WIDTH=\"400\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\"><B>Subscribe
or Unsubscribe<BR>any addresses here</B></FONT>
<CENTER><INPUT TYPE=\"TEXT\" SIZE=\"15\" NAME=\"email\"></CENTER>
<TABLE BORDER=\"0\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><INPUT
TYPE=\"RADIO\" NAME=\"subscribe\" VALUE=\"subscribe\" CHECKED=\"CHECKED\" ALIGN=\"TOP\"><FONT
SIZE=\"-2\" COLOR=\"#000000\" FACE=\"verdana, arial, helvetica\"><B>subscribe</B></FONT><BR><INPUT
TYPE=\"RADIO\" NAME=\"subscribe\" VALUE=\"unsubscribe\" ALIGN=\"TOP\">
<FONT SIZE=\"-2\" COLOR=\"#000000\" FACE=\"verdana, arial, helvetica\"><B>unsubscribe</B></FONT></TD></TR></ROWS></TBODY></TABLE><CENTER><INPUT
TYPE=\"SUBMIT\" VALUE=\"  Submit  \"></CENTER>
<CENTER><TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR
><TD COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></FORM></BODY></HTML>";
exit;
}

sub mailing {

######################################
open (PASSWORD, "$passfile/password.txt");
		$password = <PASSWORD>;
		close (PASSWORD);
		chop ($password) if ($password =~ /\n$/);


		if ($INPUT{'password'}) {
			$newpassword = crypt($INPUT{'password'}, aa);
		}
		else {
                  print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Subscribe Me: Password Error!</TITLE></HEAD><BODY
BGCOLOR=\"#FFFFFF\"><FORM ACTION=\"$cgiurl\" METHOD=\"POST\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Password Error!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Please enter your password!</FONT></P>
<CENTER><TABLE
BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with<A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></FORM></BODY></HTML>";
exit;
		}
		unless ($newpassword eq $password) {
                  print "Content-type: text/html\n\n";

print "<HTML><HEAD><TITLE>Subscribe Me: Password Error!</TITLE></HEAD><BODY
BGCOLOR=\"#FFFFFF\"><FORM ACTION=\"$cgiurl\" METHOD=\"POST\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Password Error!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Incorrect password!  Please enter the correct password.</FONT></P>
<CENTER><TABLE
BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with<A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER>
</TD></TR></ROWS></TBODY></TABLE></CENTER></FORM></BODY></HTML>";
exit;
		}

########################################



$pid = fork();
print "Content-type: text/html \n\n fork failed: $!" unless defined 

$pid;
if ($pid) {
	#parent
print "Content-type: text/html \n\n";
#&header;	
print <<EOF;
<HTML><HEAD><TITLE>Subscribe Me: Mailing Success!</TITLE></HEAD><BODY
BGCOLOR=\"#FFFFFF\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe
Me</FONT> Status: Mailing Success!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Your mailing has been successfully sent to your Subscribe Me mailing list!</FONT></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Thank you for using Subscribe Me.  Please let us know if there any improvements you would like us to consider for the next release of our program, at <A
HREF=\"mailto:cgi\@elitehost.com\">cgi\@elitehost.com</A>.</FONT></P>
<CENTER><TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR
><TD COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></BODY></HTML>

EOF
#&footer;
	exit(0);
	}
else {
	#child

	close (STDOUT);
##### SEND OUT EMAILS HERE ############
       
#&passcheck;

######### Here is where we did the addition ###################
###############################################################

# First, tell the script where to find your email text file
open (FILE,"$closing/email.txt"); #### Full path name from root.

# Now we read in the email text 
@closing  = <FILE>;

# Now that's its been read, we can close the text file
 close(FILE);

open (LIST,"<$memberinfo/address.txt");
 if ($LOCK_EX){ 
      flock(LIST, $LOCK_EX); #Locks the file
	}
 @database_array = <LIST>;
 close (LIST);

foreach $lines(@database_array) {
         chomp($lines);

open (MAIL, "|$mailprog -t")
	            || print "Can't start mail program";
			print MAIL "To: $lines\n";
		      print MAIL  "From: $list_mail\n";
			print MAIL  "Subject: $INPUT{'mail_subject'}\n\n";
				

                        print MAIL "$INPUT{'message'}";  
				  
			# Now we tell the script to read each line from your email text file
# and paste it into your actual outgoing email.
                        
                        foreach $line(@closing) {
                        print MAIL "$line";
                        }

# All done
                        print MAIL"\n\n";
                        close (MAIL);


}
}
}


sub checkaddress {

$INPUT{'email'} =~ s/\s//g;

unless ($INPUT{'email'} =~ /(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)|(,)/
	  || $INPUT{'email'} !~
	  /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/)
	  {
         $legalemail = 1;
        } else {
         $legalemail = 0;
        }


if ($legalemail !~ 1) {

print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Subscribe Me: Improper Email Address!</TITLE></HEAD><BODY
BGCOLOR=\"#FFFFFF\"><CENTER
><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Improper Email Address!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">You have entered an improper email address.  Please make sure your email address appears in this manner:  username\@domain.com, or username\@domain.net, etc. !</FONT></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">If you need extra assistance, please contact us at <A
HREF=\"mailto:$list_mail\">$list_mail</A> for assistance.</FONT></P>
<CENTER><TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR
><TD COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></BODY></HTML>";
exit;
}
}

sub adminpass {

print<<EOF;
<HTML><HEAD><TITLE>Subscribe Me: Administration Areaa</TITLE></HEAD><BODY
BGCOLOR="#FFFFFF"><FORM ACTION="$cgiurl" METHOD="POST"><CENTER><BR>
<TABLE BORDER="0" WIDTH="400"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART="1"><P ALIGN="CENTER"><B><FONT FACE="verdana, arial, helvetica"><FONT
COLOR="#FF0000">Subscribe
Me</FONT> Status:<BR>Admininstration Password</FONT></B></P>
<P><FONT SIZE="-1" FACE="verdana, arial, helvetica">The Administration section is restricted to authorized individuals only.  Please enter the Administration password below.</FONT></P>
<CENTER><TABLE BORDER="0"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
ALIGN="CENTER" COLSTART="1"><FONT SIZE="-1" FACE="verdana, arial, helvetica"><B>Password</B></FONT><BR><INPUT
TYPE="PASSWORD" NAME="pwd"></TD></TR><TR><TD ALIGN="CENTER" COLSTART="1"><BR><INPUT
TYPE="SUBMIT" NAME="passcheck" VALUE="  Enter Password  "><INPUT
TYPE="RESET" NAME=""></TD></TR></ROWS></TBODY></TABLE></CENTER>
<CENTER><TABLE BORDER="0" WIDTH="400"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR
><TD COLSTART="1"><HR SIZE="1"></TD></TR><TR><TD ALIGN="CENTER" COLSTART="1"><FONT
SIZE="-2" FACE="verdana, arial, helvetica">$list_name
maintained with <A HREF="http://cgi.elitehost.com/"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></FORM></BODY></HTML>
EOF
exit;
}

sub passcheck {

open (PASSWORD, "$passfile/password.txt");
           if ($LOCK_EX){ 
      flock(PASSWORD, $LOCK_EX); #Locks the file
	}
		$password = <PASSWORD>;
		close (PASSWORD);
		chop ($password) if ($password =~ /\n$/);


		if ($INPUT{'pwd'}) {
			$newpassword = crypt($INPUT{'pwd'}, aa);
		}
		else {
                  print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Subscribe Me: Password Error!</TITLE></HEAD><BODY
BGCOLOR=\"#FFFFFF\"><FORM ACTION=\"$cgiurl\" METHOD=\"POST\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Password Error!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Please enter your password!</FONT></P>
<CENTER><TABLE
BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></FORM></BODY></HTML>";
exit;
		}
		unless ($newpassword eq $password) {
                  print "Content-type: text/html\n\n";
print "<HTML><HEAD><TITLE>Subscribe Me: Password Error!</TITLE></HEAD><BODY
BGCOLOR=\"#FFFFFF\"><FORM ACTION=\"$cgiurl\" METHOD=\"POST\"><CENTER><BR>
<TABLE BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><P><B><FONT FACE=\"verdana, arial, helvetica\"><FONT
COLOR=\"#FF0000\">Subscribe Me</FONT> Status:  Password Error!</FONT></B></P>
<P><FONT SIZE=\"-1\" FACE=\"verdana, arial, helvetica\">Incorrect password!  Please enter the correct password.</FONT></P>
<CENTER><TABLE
BORDER=\"0\" WIDTH=\"400\"><TBODY><COLDEFS><COLDEF></COLDEFS><ROWS><TR><TD
COLSTART=\"1\"><HR SIZE=\"1\"></TD></TR><TR><TD ALIGN=\"CENTER\" COLSTART=\"1\"><FONT
SIZE=\"-2\" FACE=\"verdana, arial, helvetica\">$list_name
maintained with  <A HREF=\"http://cgi.elitehost.com/\"><B>Subscribe
Me $version</B></A></FONT></TD></TR></ROWS></TBODY></TABLE></CENTER></TD></TR></ROWS></TBODY></TABLE></CENTER></FORM></BODY></HTML>";
exit;
		}
&form2;
}


sub parseemail {

$email = $INPUT{'email'};
$existing = $lines;
$existing =~ tr/A-Z/a-z/;
$email =~ tr/A-Z/a-z/;

}

