home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet 1996 World Exposition
/
park.org.s3.amazonaws.com.7z
/
park.org.s3.amazonaws.com
/
cgi-bin
/
Japan
/
Examples
/
mail.cgi
< prev
next >
Wrap
Text File
|
2017-09-21
|
5KB
|
159 lines
#!/usr/local/bin/perl -- -*-perl-*-
# ------------------------------------------------------------
# Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
#
# Last updated: March 2, 1994
#
# Form-mail provides a mechanism by which users of a World-
# Wide Web browser may submit comments to the webmasters
# (or anyone else) at a site. It should be compatible with
# any CGI-compatible HTTP server.
#
# Please read the README file that came with this distribution
# for further details.
# ------------------------------------------------------------
# ------------------------------------------------------------
# This package is Copyright 1994 by The Tech.
# Form-mail is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the
# Free Software Foundation; either version 2, or (at your option) any
# later version.
# Form-mail is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with Form-mail; see the file COPYING. If not, write to the Free
# Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
# ------------------------------------------------------------
# Define fairly-constants
# This should match the mail program on your system.
#$MAILPROG = '/usr/lib/sendmail -odq';
$MAILPROG = '/usr/lib/sendmail -odb';
# This should be set to the username or alias that runs your
# WWW server.
$RECIPIENT = 'shinoda@jaist.ac.jp';
#
# This name will appear in From: field.
$WEBCGI = 'jaist-comment';
# This name will appear in the title and the first heading
$ORGANIZATION = 'the web-master, Yoichi Shinoda';
$referer = $ENV{'HTTP_REFERER'};
# Print out a content-type for HTTP/1.0 compatibility
print "Content-type: text/html\n\n";
if ($ENV{'CONTENT_LENGTH'} <= 0) {
print <<EoI;
<Head><Title>Comments to the $ORG$ORGANIZATION</Title></Head>
<Body><H2>Comments to $ORGANIZATION</H2>
<p>
Please enter any comments you might have in the space below, and
select the "Send comments" button when you are through.
If your browser doesn't support forms,
<a href="mailto:$RECIPIENT">mail</a> us your comments.
<p>
<Form method=POST action="/cgi-bin/Japan/Examples/mail.cgi?$referer">
<HR>
<inPUT NAME="username"> Your E-Mail Address<P>
<inPUT NAME="realname"> Your Name<P>
<inPUT NAME="subject"> Subject<P>
<inPUT NAME="about" Value="$referer" Type="hidden">
Please enter any comments you might have in the space below:<P>
<TEXTAREA NAME="comments" ROWS=10 COLS=70></TEXTAREA><P>
<P>
<Input TYPE="submit" VALUE="Send comments">
<Input TYPE="reset" VALUE="Erase comments"><p>
</Form>
</Body>
EoI
} else {
$referer = $ARGV[0] ;
# Print a title and initial heading
print "<Head><Title>Thank you</Title></Head>";
print "<Body>";
# Get the input
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
# Split the name-value pairs
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
# Un-Webify plus signs and %-encoding
$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;
# Uncomment for debugging purposes
# print "Setting $name to $value<P>";
$FORM{$name} = $value;
}
if (! $FORM{'username'} || ! $FORM{'subject'} || ! $FORM{'comments'}) {
print "Messages with no email address, subject or comments will not be sent.";
print "<p>";
} else {
# Now send mail to $RECIPIENT
&send_mail;
}
# Make the person feel good for writing to us
print "<hr>";
print "Your comments have been delivered. Thank you.\n";
print "<p>\n";
print "<a href=\"$referer\">Return</a>";
print "<hr>";
print "</body>\n";
}
exit 0;
#
# send mail message
#
sub send_mail {
local($about) = $FORM{'about'};
open (MAIL, "|$MAILPROG $RECIPIENT ") || die "Can't open $MAILPROG!\n";
print MAIL "From: $WEBCGI\n";
print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n";
print MAIL "Subject: $FORM{'subject'}\n\n";
print MAIL "$FORM{'username'} ($FORM{'realname'}) sent the following\n";
print MAIL "comment about $about:\n";
print MAIL "------------------------------------------------------------\n";
print MAIL "$FORM{'comments'}";
print MAIL "\n------------------------------------------------------------\n";
print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
print MAIL "User Agent: $ENV{'HTTP_USER_AGENT'}\n"
if defined($ENV{'HTTP_USER_AGENT'});
close (MAIL);
}