home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 98 / Skunkware 98.iso / osr5 / sco / scripts / www / comment-mail.pl next >
Encoding:
Perl Script  |  1997-08-26  |  4.9 KB  |  145 lines

  1. #!/usr/local/bin/perl -- -*-perl-*-
  2. # @(#) comment-mail.perl 1.1 96/03/16
  3.  
  4. # ------------------------------------------------------------
  5. # Form-mail.pl, by Reuven M. Lerner (reuven@the-tech.mit.edu).
  6. #
  7. # Last updated: March 14, 1994
  8. #
  9. # Form-mail provides a mechanism by which users of a World-
  10. # Wide Web browser may submit comments to the webmasters
  11. # (or anyone else) at a site.  It should be compatible with
  12. # any CGI-compatible HTTP server.
  13. # Please read the README file that came with this distribution
  14. # for further details.
  15. # ------------------------------------------------------------
  16. # 94/04/02 john@armory.com   Generalized a bit.
  17. # 96/02/09 john@armory.com   Fixed to deal with trailing / in PATH_INFO
  18. # 96/02/10 john@armory.com   Deal with trailing newline in hostname;
  19. #                            added processing of subject field.
  20. # 96/03/16 john@armory.com   Print a few more env vars if available.
  21.  
  22. # ------------------------------------------------------------
  23. # This package is Copyright 1994 by The Tech. 
  24.  
  25. # Form-mail is free software; you can redistribute it and/or modify it
  26. # under the terms of the GNU General Public License as published by the
  27. # Free Software Foundation; either version 2, or (at your option) any
  28. # later version.
  29.  
  30. # Form-mail is distributed in the hope that it will be useful, but
  31. # WITHOUT ANY WARRANTY; without even the implied warranty of
  32. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  33. # General Public License for more details.
  34.  
  35. # You should have received a copy of the GNU General Public License
  36. # along with Form-mail; see the file COPYING.  If not, write to the Free
  37. # Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  38. # ------------------------------------------------------------
  39.  
  40. # Define fairly-constants
  41.  
  42. # This should match the mail program on your system.
  43. #$mailprog = '/usr/lib/mail/execmail';
  44. $mailprog = '/usr/lib/sendmail';
  45. $host = `hostname`;
  46. $host =~ s/\n//g;    # get rid of trailing newline if any 
  47. # PATH_INFO will be set to /recip=username
  48. $pinfo = substr($ENV{'PATH_INFO'},7);
  49. # Get rid of trailing / if PATH_INFO was set to /recip=username/
  50. if (substr($pinfo,(length $pinfo) - 1,1) eq '/') {
  51.     $pinfo = substr($pinfo,0,(length $pinfo) - 1);
  52. }
  53. $recipient = $pinfo . '@' . $host;
  54.  
  55. # Print out a content-type for HTTP/1.0 compatibility
  56. print "Content-type: text/html\n\n";
  57.  
  58. # Print a title and initial heading
  59. print "<Head><Title>Comment Reply</Title></Head>\n";
  60.  
  61. # Get the input
  62. read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  63.  
  64. # Split the name-value pairs
  65. @pairs = split(/&/, $buffer);
  66.  
  67. foreach $pair (@pairs)
  68. {
  69.     ($name, $value) = split(/=/, $pair);
  70.  
  71.     # Un-Webify plus signs and %-encoding
  72.     $value =~ tr/+/ /;
  73.     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  74.  
  75.     # Stop people from using subshells to execute commands
  76.     # Not a big deal when using sendmail, but very important
  77.     # when using UCB mail (aka mailx).
  78.     # $value =~ s/~!/ ~!/g; 
  79.  
  80.     # Uncomment for debugging purposes
  81.     # print "Setting $name to $value<P>";
  82.  
  83.     $FORM{$name} = $value;
  84. }
  85.  
  86. # If the comments are blank, then give a "blank form" response
  87. &blank_response unless $FORM{'comments'};
  88. &name_response unless $FORM{'name'};
  89. if ($pinfo !~ /^[-a-zA-Z0-9_.=]+$/) {
  90.     &recip_response
  91. }
  92.  
  93. # Now send mail to $recipient
  94.  
  95. open (MAIL, "|$mailprog $recipient") || die "Can't open $mailprog!\n";
  96. print MAIL "Reply-to: $FORM{'email'} ($FORM{'name'})\n";
  97. print MAIL "From: www@" . $host . "\n";
  98. print MAIL "Subject: WWW comments" . ( $FORM{'subject'} ne '' ?
  99. " re: " . $FORM{'subject'} : " (Forms submission)" ) . "\n\n";
  100. print MAIL "$FORM{'name'} ($FORM{'email'}) sent the following\n";
  101. print MAIL "comment about your WWW page:\n\n";
  102. if ($FORM{'url'}) {
  103.     print MAIL  "----------------------------------------------------------\n";
  104.     print MAIL "URL: $FORM{'url'}\n";
  105. }
  106. print MAIL  "----------------------------------------------------------\n";
  107. print MAIL "$FORM{'comments'}";
  108. print MAIL "\n----------------------------------------------------------\n";
  109. print MAIL "Server protocol: $ENV{'SERVER_PROTOCOL'}\n";
  110. if ($ENV{'REMOTE_HOST'}) {
  111.     print MAIL "Remote host: $ENV{'REMOTE_HOST'}\n";
  112. }
  113. print MAIL "Remote IP address: $ENV{'REMOTE_ADDR'}\n";
  114. if ($ENV{'HTTP_REFERER'}) {
  115.     print MAIL "Referer: $ENV{'HTTP_REFERER'}\n";
  116. }
  117. if ($ENV{'HTTP_USER_AGENT'}) {
  118.     print MAIL "Referer: $ENV{'HTTP_USER_AGENT'}\n";
  119. }
  120. close (MAIL);
  121.  
  122. print "<Body><h1>Your comments have been sent.  Thank you!</H1>\n";
  123.  
  124. sub blank_response
  125. {
  126.     print "Your comment submission appears to be blank, and thus was not sent.";
  127.     print "  Please re-enter and submit.\n";
  128.     exit;
  129. }
  130.  
  131. sub name_response
  132. {
  133.     print "Your comment did not include a name, and thus was not sent.";
  134.     print "  Please re-enter and submit.\n";
  135.     exit;
  136. }
  137.  
  138. sub recip_response
  139. {
  140.     print "The recipient ($pinfo) specified on this form is not a user on";
  141.     print "the local machine, so this form was not processed.\n";
  142.     exit;
  143. }
  144.