#!/opt/internet/bin/perl # script to process e-mail sent from SunWorld. # this is a kludge until the html mailto becomes ubiquitous. # # usage: swol-feedback.cgi [ | send ] # # if 'send' is the last command-line argument, swol-feedback.cgi assumes # that it is to send the enclosed datastream to the recipient denoted by # the first command-line argument. otherwise, it interprets the second # and third command-line arguments as a return href and tag for 'back-to' # functionality. # # it's fairly crucial that the e-mail address does not contain + # signs, as this will confuse swol-feedback.cgi's interpretation of # command-line arguments. # # complain to david.burnette@sunworld.com if there are problems. if ("$ARGV[$#ARGV]" eq "send") { # catch message from first run of swol-feedback.cgi $fromadd="sunworldonline\@sunworld.com"; $fromname="SunWorld"; $mailprog="/usr/lib/sendmail"; $bcc="swolbcc\@sunworld.com"; # recipient of failsafe copy $bccname="SWOL bcc"; $bccsubject="bccmail to $ARGV[0]"; $date=`date`; chop($date); read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); if (@ARGV == 1) { $recipient="david.burnette\@sunworld.com"; $href1="/sunworldonline/index.html"; $src1="/sunworldonline/icons/b-thismonth.gif"; $alt1="[This month's table of contents]"; } elsif (@ARGV == 2) { $recipient="$ARGV[0]"; $href1="/sunworldonline/index.html"; $src1="/sunworldonline/icons/b-thismonth.gif"; $alt1="[This month's table of contents]"; } elsif (@ARGV == 3) { $recipient="$ARGV[0]"; $href1="$ARGV[1]"; $src1="/sunworldonline/icons/b-thismonth.gif"; $alt1="[This month's table of contents]"; } else { $recipient="$ARGV[0]"; $href1="/sunworldonline/index.html"; $src1="/sunworldonline/icons/b-thismonth.gif"; $alt1="[This month's table of contents]"; $href2="$ARGV[1]#$ARGV[2]"; $src2="/sunworldonline/icons/b-backtostory.gif"; $alt2="[Back to story]"; } $HREF1="\"$alt1\""; if (defined($href2)) { $HREF2="\"$alt2\""; } # Split the name-value pairs @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; # Stop people from using subshells to execute commands $value =~ s/~!/ ~!/g; $FORM{$name} = $value; } # check for empty message; thwart bastards if ($FORM{'name'} =~ /^[\s]*$/ || $FORM{'email'} =~ /^[\s]*$/ || $FORM{'message'} =~ /^[\s]*$/) { print < SunWorld E-mail Form

An empty message cannot be sent. It must contain a name, e-mail address, and message.

To send a message, return to the mail form by hitting your browser's back button.

EOM } else { # send thank-you note to browser print < SunWorld $HREF1$HREF2

Thank you for sending mail to $recipient. We appreciate your patronage.

EOM if ($FORM{'printletter'} eq "Yes") { print "

Per your request, we WILL consider your message as a candidate for our letters page.

\n"; } elsif ($FORM{'printletter'} eq "No") { print "

Per your request, we will NOT consider your message as a candidate for our letters page.

\n"; } elsif (! defined($FORM{'printletter'})) { print "

We will consider your message as a candidate for our letters page.

\n"; } print "\n"; print "\n"; # send failsafe copy of raw data to bcc open (MAIL, "|$mailprog $bcc") || die "Can't open $mailprog!\n"; print MAIL "From: $fromadd ($fromname)\n"; print MAIL "To: $bcc\n"; print MAIL "Subject: $bccsubject\n\n"; print MAIL "BEGIN RECORD $date\n"; print MAIL "recipient=$recipient\n"; print MAIL "href1=$href1\n"; print MAIL "src1=$src1\n"; print MAIL "alt1=$alt1\n"; print MAIL "href2=$href2\n"; print MAIL "src2=$src2\n"; print MAIL "alt2=$alt2\n"; foreach $i (sort(keys %ENV)) { print MAIL "$i=$ENV{$i}\n"; } print MAIL "ARGV=@ARGV\n"; print MAIL "STDINDATA=$buffer\n"; print MAIL "END RECORD $date\n"; close(MAIL); # send mail to $recipient open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n"; print MAIL "From: $FORM{'email'} ($FORM{'name'})\n"; print MAIL "To: $recipient\n"; print MAIL "Subject: $FORM{'subject'}\n\n"; print MAIL "$FORM{'message'}\n"; print MAIL "\n------------------------------------------------------------\n\n"; print MAIL "E-mail from SunWorld (http://www.sunworld.com)\n\n"; if ($FORM{'printletter'} eq "Yes" || ! defined($FORM{'printletter'})) { print MAIL "WILL be considered for letters page.\n"; } elsif ($FORM{'printletter'} eq "No") { print MAIL "Will NOT be considered for letters page.\n"; } print MAIL "Agent: $ENV{'HTTP_USER_AGENT'}\n"; print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n"; print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n\n"; close(MAIL); } # end of if bastard else sendmail exit(0); } else { # present message form to browser if (@ARGV == 0) { $recipient="webmaster\@sunworld.com"; $href="/sunworldonline/index.html"; } elsif (@ARGV == 1) { $recipient="$ARGV[0]"; $href="/sunworldonline/index.html"; } elsif (@ARGV == 2) { $recipient="$ARGV[0]"; $href="$ARGV[1]"; } else { $recipient="$ARGV[0]"; $href="$ARGV[1]+$ARGV[2]"; } $banner="Send mail to $recipient"; print < SunWorld E-mail Form

Reader feedback form

The editors at SunWorld welcome your feedback!

Please note SunWorld is an independent publication of IDG Communications and is not owned by Sun Microsystems nor is it responsible for www.sun.com.

May we share your message with other readers in our letters-to-the-editor page? Yes No

$banner

Your Name:

Your e-mail address:

Subject:

Please enter your message below:

END_OF_FORM exit(0); }