#!/usr/bin/perl ############################################################## # # signup.pl # # written by Duc M. Do (ducdo@mis.net) to be a stand-alone # subscribe/unsubscribe interface for a majordomo mailing list. # ############################################################## # # COPYRIGHT NOTICE: # # Copyright ©1998 Duc M. Do. All rights reserved. # # This script file is being distributed as freeware. It may # be used and modified by anyone, so long as this copyright # notice and the header above remain intact. By using this # script file, you agree to indemnify the author, Duc M. Do, # from any liability. # # Selling the code for this script file without prior written # consent is expressly forbidden. Please obtain permission # before redistributing this script file over the Internet # or by any other medium. In all cases, the copyright notice # and header must remain intact. # ############################################################## # # Revision History: # # 1/11/98 DMD v1.00 first hack to use for subscription to # my own list # 3/14/98 DMD v1.10 hack it again to use for unsubscribe # also; generate the form HTML file as # well as the resulting welcome/sorry # HTML files directly from this script; # rename it signup.pl # 3/20/98 DMD v1.11 rewrite in general term so other people # can use it too # ############################################################## # define variables # $cgiurl should contain the complete path to your signup.pl # script as you would type it in yourself in the address field # of your browser $cgiurl = "http://www.foo.com/username/cgi-bin/signup.pl"; # define your list name, without the "@cycling.org" domain $listname = "mylistname"; # $domain defines the domain name where the mailing list(s) # and majordomo reside $domain = "cycling.org"; # typically a mojordomo-hosted mailing list also has a digest # form. If yours doesn't, you need to change this variable to # be 0 $digest = 1; # if your list's subscription policy is "open+confirm" which # means that anybody can subscribe to your list, but he/she # has to send a confirmation message back to majordomo upon # submitting the subscribe request, leave this option at 1. # If your list is truly open, set this option to 0. $confirmopt = 1; # the next two variables define the user-supplied header and # footer files that can be used to patch together a custom # look for your script-generated HTML files. # # The header file should contain all of your HTML codes that # define the top part of your page. This should include the # tag, the
tags, the tag (and its # parameters) and any graphic component and/or navigational # buttons at the top of your page. # # The footer file should contain any graphic component and/or # navigational buttons at the bottom of your page. It also # should close out the HTML page by including the and # tags. # # If the header and footer files are not in the same directory # as the signup.pl script, you'll need to supply the # *relative path* from the cgi directory to wherever these # files reside (for example: "../../textfile/header.txt") $HeaderFile = "header.txt"; $FooterFile = "footer.txt"; # the $mailprog defines the program a typical Unix system # uses to send mail. The path (/usr/lib) will vary from # installation to installation. You'll have to contact your # ISP to determine this. I have no idea what the path to # 'sendmail' on your server is, so please don't contact me # for this. $mailprog = '/usr/lib/sendmail'; ############################################################## # Nothing needs to be modified below this point ############################################################## # use cgi-lib.pl require("cgi-lib.pl"); print "Content-type: text/html\n\n"; # parse the form data &Parse(*FORM); # Create the form for them to use the first time the script # is executed if (!$FORM{'action'}) { &Header; &PrintForm; &Footer; } else { # Process the request and show them the proper response to # their action &CheckError; &SendMail; &Header; if ($FORM{'action'} eq "subscribe") { &SubMesg; } else { &UnsubMesg; } &Footer; } exit; ############################################################## # parse the form ############################################################## sub Parse { 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; $FORM{$name} = $value; } } ############################################################## # check for missing fields in the form ############################################################## sub CheckError { if (!$FORM{'email'}) { &Error("You must enter an e-mail address!"); } if (!&CheckEmail($FORM{'email'})) { &Error("You must enter a VALID e-mail address!"); } } ############################################################## # generic error message ############################################################## sub Error { local($MsgText) = $_[0]; &Header; print "Please return to the sign-up form and fill in "; print "your e-mail address properly, and try again.\n"; &Footer; exit; } ############################################################## # generic verification of valid email address format ############################################################## sub CheckEmail { $email = $_[0]; if ($email =~ /(@.*@)|(\.\.)|(@\.)|(^\.)/ || $email !~ /^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,3}|[0-9]{1,3})(\]?)$/) { return 0; } else { return 1; } } ############################################################## # send subscribe/unsubscribe request to majordomo ############################################################## sub SendMail { $email = $FORM{'email'}; # open mail program open (MAIL,"|$mailprog -t") || die("Can't open mail program: $!\n"); # print out email body print MAIL "Reply-to: $email\n"; print MAIL "From: $email\n"; print MAIL "To: majordomo\@$domain\n"; # if included in form, cc original sender if (defined($FORM{'cc'}) && $FORM{'cc'} eq "on") { print MAIL "Cc: $email\n"; } # blank line between header and body print MAIL "\n"; # print body command line and an 'end' command print MAIL "$FORM{'action'} $FORM{'list'} $email\n"; print MAIL "end\n"; # close mail and send close MAIL; } ############################################################## # generate the form for them to use ############################################################## sub PrintForm { print <<"(END HTML BODY 1)";
To subscribe to or unsubscribe from $listname mailing list, enter your e-mail address in the box below and select the proper action. (END HTML BODY 1) if ($confirmopt) { print <<"(END HTML BODY 2)"; If you select “Subscribe,” you will receive a confirmation message at the address you enter here. You must follow the instructions in that message to complete your subscription. (END HTML BODY 2) } print <<"(END HTML BODY 3)";
(END HTML BODY 7) } ############################################################## # create the welcome message if the user subscribes ############################################################## sub SubMesg { print <<"(END HTML SUBMESG 1)";Thank you for joining $FORM{'list'} mailing list. (END HTML SUBMESG 1) if ($confirmopt) { print <<"(END HTML SUBMESG 2)"; Shortly you will receive a confirmation e-mail from majordomo at the e-mail address $FORM{'email'}. Follow the enclosed instructions to complete your subscription. (END HTML SUBMESG 2) } print <<"(END HTML SUBMESG 3)";
Please save the “welcome” message you receive once your subscription is processed. It provides information about the list and how to unsubscribe (which may be handy someday!).
We look forward to your participation on the mailing list. If you have any question, please contact the list-owner. (END HTML SUBMESG 3) } ############################################################## # create the farewell message if the user unsubscribes ############################################################## sub UnsubMesg { print <<"(END HTML UNSUBMESG)";
We’re sorry you are leaving $FORM{'list'}. We hope
you’ll rejoin us in the future.
(END HTML UNSUBMESG)
}
##############################################################
# create the header for the HTML files
##############################################################
sub Header {
if ($HeaderFile) {
open (HEADER,"$HeaderFile");
@header =