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 >
Text File  |  2017-09-21  |  5KB  |  159 lines

  1. #!/usr/local/bin/perl -- -*-perl-*-
  2.  
  3. # ------------------------------------------------------------
  4. # Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
  5. #
  6. # Last updated: March 2, 1994
  7. #
  8. # Form-mail provides a mechanism by which users of a World-
  9. # Wide Web browser may submit comments to the webmasters
  10. # (or anyone else) at a site.  It should be compatible with
  11. # any CGI-compatible HTTP server.
  12. # Please read the README file that came with this distribution
  13. # for further details.
  14. # ------------------------------------------------------------
  15.  
  16. # ------------------------------------------------------------
  17. # This package is Copyright 1994 by The Tech. 
  18.  
  19. # Form-mail is free software; you can redistribute it and/or modify it
  20. # under the terms of the GNU General Public License as published by the
  21. # Free Software Foundation; either version 2, or (at your option) any
  22. # later version.
  23.  
  24. # Form-mail is distributed in the hope that it will be useful, but
  25. # WITHOUT ANY WARRANTY; without even the implied warranty of
  26. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  27. # General Public License for more details.
  28.  
  29. # You should have received a copy of the GNU General Public License
  30. # along with Form-mail; see the file COPYING.  If not, write to the Free
  31. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  32. # ------------------------------------------------------------
  33.  
  34. # Define fairly-constants
  35.  
  36. # This should match the mail program on your system.
  37. #$MAILPROG = '/usr/lib/sendmail -odq';
  38. $MAILPROG = '/usr/lib/sendmail -odb';
  39.  
  40. # This should be set to the username or alias that runs your
  41. # WWW server.
  42. $RECIPIENT = 'shinoda@jaist.ac.jp';
  43. #
  44. # This name will appear in From: field.
  45. $WEBCGI = 'jaist-comment';
  46.  
  47. # This name will appear in the title and the first heading
  48. $ORGANIZATION = 'the web-master, Yoichi Shinoda';
  49.  
  50. $referer = $ENV{'HTTP_REFERER'};
  51.  
  52. # Print out a content-type for HTTP/1.0 compatibility
  53. print "Content-type: text/html\n\n";
  54.  
  55. if ($ENV{'CONTENT_LENGTH'} <= 0) {
  56.     print <<EoI;
  57. <Head><Title>Comments to the $ORG$ORGANIZATION</Title></Head>
  58. <Body><H2>Comments to $ORGANIZATION</H2>
  59.  
  60. <p>
  61. Please enter any comments you might have in the space below, and
  62. select the "Send comments" button when you are through.
  63. If your browser doesn't support forms, 
  64. <a href="mailto:$RECIPIENT">mail</a> us your comments.
  65. <p>
  66.  
  67. <Form method=POST action="/cgi-bin/Japan/Examples/mail.cgi?$referer">
  68.  
  69. <HR>
  70. <inPUT NAME="username"> Your E-Mail Address<P>
  71. <inPUT NAME="realname"> Your Name<P>
  72. <inPUT NAME="subject"> Subject<P>
  73. <inPUT NAME="about" Value="$referer" Type="hidden">
  74. Please enter any comments you might have in the space below:<P>
  75.  
  76. <TEXTAREA NAME="comments" ROWS=10 COLS=70></TEXTAREA><P>
  77.  
  78. <P>
  79.  
  80. <Input TYPE="submit" VALUE="Send comments">
  81. <Input TYPE="reset" VALUE="Erase comments"><p>
  82. </Form>
  83.  
  84. </Body>
  85.  
  86. EoI
  87.  
  88. } else {
  89.     $referer = $ARGV[0] ;
  90.     # Print a title and initial heading
  91.     print "<Head><Title>Thank you</Title></Head>";
  92.     print "<Body>";
  93.  
  94.     # Get the input
  95.     read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  96.  
  97.     # Split the name-value pairs
  98.     @pairs = split(/&/, $buffer);
  99.  
  100.     foreach $pair (@pairs) {
  101.         ($name, $value) = split(/=/, $pair);
  102.  
  103.         # Un-Webify plus signs and %-encoding
  104.         $value =~ tr/+/ /;
  105.         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  106.  
  107.         # Stop people from using subshells to execute commands
  108.         $value =~ s/~!/ ~!/g; 
  109.  
  110.         # Uncomment for debugging purposes
  111.         # print "Setting $name to $value<P>";
  112.  
  113.         $FORM{$name} = $value;
  114.     }
  115.  
  116.     if (! $FORM{'username'} || ! $FORM{'subject'} || ! $FORM{'comments'}) {
  117.         print "Messages with no email address, subject or comments will not be sent.";
  118.         print "<p>";
  119.     } else {
  120.         # Now send mail to $RECIPIENT
  121.         &send_mail;
  122.     }
  123.  
  124.     # Make the person feel good for writing to us
  125.     print "<hr>";
  126.     print "Your comments have been delivered.  Thank you.\n";
  127.     print "<p>\n";
  128.     print "<a href=\"$referer\">Return</a>";
  129.     print "<hr>";
  130.     print "</body>\n";
  131. }
  132.  
  133. exit 0;
  134.  
  135. #
  136. #  send mail message
  137. #
  138. sub send_mail {
  139.     local($about) = $FORM{'about'};
  140.  
  141.     open (MAIL, "|$MAILPROG $RECIPIENT ") || die "Can't open $MAILPROG!\n";
  142.     print MAIL "From: $WEBCGI\n";
  143.     print MAIL "Reply-to: $FORM{'username'} ($FORM{'realname'})\n";
  144.     print MAIL "Subject: $FORM{'subject'}\n\n";
  145.     print MAIL "$FORM{'username'} ($FORM{'realname'}) sent the following\n";
  146.     print MAIL "comment about $about:\n";
  147.     print MAIL  "------------------------------------------------------------\n";
  148.     print MAIL "$FORM{'comments'}";
  149.     print MAIL "\n------------------------------------------------------------\n";
  150.     print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
  151.     print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
  152.     print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
  153.     print MAIL "User Agent: $ENV{'HTTP_USER_AGENT'}\n"
  154.       if defined($ENV{'HTTP_USER_AGENT'});
  155.     close (MAIL);
  156. }
  157.  
  158.