#!/usr/local/gnu/bin/perl # # md-sub.cgi # # Author: John Orthoefer # Date: 17 Jan 1996 # # Introduction # This cgi allows people web surfing to subscribe to mailing list. # It presents the person with a form when called with out options. # when called with options it will send a mail message to the # mailing list. # # Installing # To install this software: # o put the script in the cgi-bin directory # o set the following varables up for your site # cgiloc - url of this script as refered to via the web # listsdb - where the database of lists is going to live # logfile - where the log for script activity should go # sendmail - the sending e-mail program, it should have the # option to read the incoming stream for the To # address set, '-t' on sendmail. # o initialize the database # + list all your mailing lists and contact addresses in a file # one per line as in # firewalls majordomo@greatcircle.com # warhammerfb majordomo@direwolf.com # majordomo-workers majordomo@greatcircle.com # default warhammerfb # help webmaster@here.org # # note: there are 3 special names # default -- This is the mailing list that will be # selected when the form is first # presented to the user. # help -- This is the address for people to send # help to. # info -- This is used to specify a URL for information about # a mailing list. # the format is: # info listname url # where: listname matches a list that is specifed # elsewhere in the file. # url is some url on the web. # + then run the the script with the '-C filename' option # to construct the database. The create option will only # add to the database. If you want to clear the database, # you need to 'rm $listsdb*' (there will be two file a # .dir and .pag file.) # o add a link to the scripts URL in your web pages. # + if you want to make different default mailing lists based on # which pages you came from you can do this by passing the param # default=listname # as part of the URL. # ie: # This will cause mylist to be the default selected one instead of # the database default. # # Misc # This script needs two perl libs cgi-lib.pl (included in this # distrubution.) and getopts.pl (which should be included with # your perl distrubution.) # # Scalars that need to be changed # $cgiloc = "http://stout/~jco/md-sub.cgi"; $listsdb = "/usr/jco/.md-subrc"; $logfile = "/usr/jco/md-sub.log"; #$sendmail = "|/usr/lib/sendmail -t"; $sendmail = "|/usr/bin/cat - > /tmp/test.out"; # This one is for # testing... # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # NOTHING BELOW HERE SHOULD NEED TO BE CHANGED # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! # # Required file require 'cgi-lib.pl'; use Getopt::Std; # # Version number $version = "1.0"; # # Info $info = "jco\@direwolf.com"; # # Call Getopts getopts( 'C:v'); # # Check to see if we are creating a DB if ($opt_C) { &create_lists( $opt_C); exit 0; } # # Check to see if the version is being intergated. if ($opt_v) { print "Version: $version\n"; exit 0; } # # Read the list DB &load_lists; # # Figure out if we have a filled in form or we need to send a form if (&ReadParse && !defined( $in{ 'default'})) { if (defined $in{ 'infopage'} ) { &infopage; } else { $in{ 'mailing_list'} =~ s/\*$//; # drop the * at the end of the name. &sendmessage; } } else { &form; } # # Birthday party, cheesecake, jelly bean, boom! # R.E.M. exit 0; # # create_lists # Create the DBM file. sub create_lists { local( $file) = @_; open( LISTS, $file); dbmopen( %MLRC, $listsdb, 0644); while( ) { chop; ($name, $address) = /(\S*)\s*(.*)/; if ($name =~ /info/i) { ($name, $address) = $address =~/(\S*)\s*(.*)/; $MLRC{ "LISTINFO-$name"} = $address; @info = (@info, $name); } else { @ml = (@ml, $name); $MLRC{ "LISTNAME-$name"} = $address; } } $MLRC{ 'mailing-lists'} = join( ";", @ml); $MLRC{ 'mailing-info'} = join( ";", @info); dbmclose( MLRC); } # # load_lists # read in the DBM file. sub load_lists { if (!dbmopen( %MLRC, $listsdb, undef)) { &log( "Can't open $listsdb"); exit 1; } foreach $i (split(/;/, $MLRC{'mailing-lists'})) { $ml{$i} = $MLRC{ "LISTNAME-$i"}; } foreach $i (split(/;/, $MLRC{'mailing-info'})) { $mi{$i} = $MLRC{ "LISTINFO-$i"}; } dbmclose( MLRC); } # # form # Present the form to the user to fill out sub form { # Form header print < Mailing List Subscription
Mailing List Subscription Form

To subscribe to any of these mailing lists all you need to do is fill out the form compeletly. And submit it. The form will then be processed and you should be added to the mailing list shortly.

EOF if (defined %mi) { print <here.

EOF } print <

Mailing List: EOF # Generate the list of mailing lists print "\n"; # form trailer print < Real name:
E-mail Address:

What action would you like to take?
Subscribe to the list
Unsubscribe from the list
Have a list of who is on the list mailed to you
Get a detailed description of the list mailed to you

Webmaster / \n"; foreach $i (keys %mi) { print "
  • $i\n"; } print "\n"; print <
    Webmaster / >$logfile"); print LOG &DTG; print LOG " - $msg\n"; close( LOG); } # # DTG # Date Time Group, This is a military thing. Express time in GMT (aka # Zulu) it this kinda funky format (ddhhmmZ MON YY). I used it because # it's a canned routine I have. sub DTG { local( $time) = @_; local( @months) = ( 'JAN', 'FEB', 'MAR', 'APR', 'MAY', 'JUN', 'JUL', 'AUG', 'SEP', 'OCT', 'NOV', 'DEC'); $time = time if ($time); sprintf( "%2.2d%2.2d%2.2dZ %s %2.2d", (gmtime( $time))[3], (gmtime( $time))[2], (gmtime( $time))[1], @months[(gmtime( $time))[4]], (gmtime( $time))[5]); } # # sendmessage # This is the worker routine. Sends a nice HTML message to the user and # sends a nice e-mail to the mailing list admin. # sub sendmessage { local( $i); if ($in{ 'email'} eq "") { print <
    SORRY

    I'm sorry but you must fill in your e-mail address. Press "back" and try again. EOF exit 0; } $in{ 'email'} = "$in{ 'email'}@$ENV{'REMOTE_HOST'}" if ( !( $in{ 'email'} =~ /\S*@\S*/)); &log( "<$in{ 'email'}> \"$in{ 'rname'}\" ". "$in{ 'function'} $in{ 'mailing_list'}"); open( SM, "$sendmail"); print SM < Reply-To: "$in{ 'rname'}" <$in{'email'}> $in{ 'function'} $in{'mailing_list'} EOF close( SM); print < Thank You
    THANK YOU

    Your request has been forwarded to the list owner for processing. You should be added soon.
    If the list owner has any questions about adding you they should be in touch with you shortly.

    The following information will be sent for you:

    EOF print "To: $ml{$in {'mailing_list'}}
    \n"; print "From: \"$in{ 'rname'}\" <$in{'email'}>

    \n"; print "$in{ 'function'} $in{'mailing_list'}
    \n"; print < EOF }