📄 webmail.cgi
字号:
#!/usr/bin/perl#**********************************************************************#* Program: WebMail from Radiation *#* Version: 2.0 *#* Author: Andrew Cowan (icculus@radiation.com) for Radiation *#* Date: January 7, 1997 *#* LastModified: August 8, 1999#* Product Info: http://www.radiation.com/gizmos/webmail.html *#* *#* This program is the copyrighted property of Radiation, a venture *#* of GlobalMedia Design. Any use of this program is subject to the *#* the terms of the license agreement (LICENSE.TXT) included as part *#* of this distribution archive. Any other uses are stictly *#* prohibited without the written permission of GlobalMedia Design *#* and all other rights are reserved. *#* *#* Support for this software is available only to registered users. *#* For registration information, consult the REGISTER.TXT document *#* included as part of this distribution archive, or visit the Gizmos *#* section of the Radiation website at: *#* *#* http://www.radiation.com/gizmos/ *#* *#**********************************************************************# ************************************************************************# WebMail Installation and Usage Instructions# ************************************************************************## This script requires perl 4.036 or any newer version. Put the webmail.cgi# script in a CGI executable directory. For Unix systems, be sure to make the# file executable itself if it is not already. The command to do this is:## chmod 755 webmail.cgi## If you are using a Dos-based or Macintosh system you will need to make# sure that .cgi files are running the perl interpreter. If this is a problem# you can always rename the file to run the interpreter correctly.## All that remains is to create the form you want to integrate with the# script (we assume you know how to write forms to call existing programs).# The hidden form fields you will use are as follows:## * send_to - Set the value of this field to be the email address you# want the mail sent to.## * subject - Set this field to what you would like the subject of your# mail to be.## * response_url - This field is optional, if not set a default response# will be printed. If set, the user's web browser will be redirected# to the url you specify. Be sure to use absolute urls for your responses.## If you experience problems with the mail (i.e. It doesn't get sent) you# will probably need to adjust the $MAIL setting in the script. Ask your# system administrator the location to use for the system's mail program.## ************************************************************************# Configuration Section# ************************************************************************## ************************************************************************# Set MODE to '1' - normal mail '2' - sendmail$MODE = '2';# If MODE set to '2' this SENDMAIL program is used$SENDMAIL = "/usr/sbin/sendmail"; # Adjust as needed# FROM_EMAIL is only used in mode '2' (sendmail mode)$FROM_EMAIL = 'youremail@yourdomain.com';# REPLY_EMAIL is only used in mode '2' (sendmail mode)$REPLY_EMAIL = 'replytoemail@yourdomain.com';# Set SORT_MODE to '1' - alphabetic sorting or '2' for sorting as found$SORT_MODE = '1';# If you are using mod_perl with auto-content-type display set, uncomment# the next line, to avoid the content type from being duplicated#$MOD_PERL = 1;# ************************************************************************# Main Routine Section# ************************************************************************&cgiparse;# Prevent malicious use and check for valid email address$elements{'send_to'} =~ s/\;//g;$elements{'send_to'} =~ s/^\s+//g;$elements{'send_to'} =~ s/\s+$//g;if ($elements{'send_to'} =~ /^\S+\@\S+$/){ &send_mail;}if (defined($elements{'response_url'})){ print "Location: $elements{'response_url'} \n\n";}else{ unless ($MOD_PERL){ print "Content-type: text/html \n\n"; } &print_default;}exit(0);# ************************************************************************# Subroutine Declarations# ************************************************************************# ************************************************************************# Send_Mail - Send mail to the specified location# ************************************************************************sub send_mail{ if ($MODE eq '1'){ # Normal mail front-end program mode open(MAIL, "|mail -s \"$elements{'subject'}\" $elements{'send_to'}"); }else{ # sendmail program mode open(MAIL, "|$SENDMAIL -f $FROM_EMAIL -t $elements{'send_to'}"); print MAIL "Subject: $elements{'subject'}\n" . "Reply-to: $REPLY_EMAIL \n" . "From: $FROM_EMAIL \n\n"; } print MAIL <<"EOM1";-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-* $elements{'subject'} *EOM1 if ($SORT_MODE eq '1'){ foreach $key (sort by_alph keys(%elements)){ next if $key =~ /^(send_to|subject|response_url)$/; print MAIL "[$key]: \n$elements{$key} \n\n"; } }else{ for ($i = 0; $i <= $#elements2 ; $i+=2){ local($key) = $elements2[$i]; local($val) = $elements2[$i+1]; unless ($key =~ /^(send_to|subject|response_url)$/){ print MAIL "[$key]: \n$val \n\n"; } } } print MAIL <<"EOM2";-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-EOM2 close(MAIL);}# ************************************************************************# By_Alph - Sort by alphabetical order# ************************************************************************sub by_alph{ local $newa = uc($a); local $newb = uc($b); $newa cmp $newb;}# ************************************************************************# Print_Default - Print a default response if no response page defined# ************************************************************************sub print_default{ print <<"EOF";<html><head><title>WebMail Response</title></head><body bgcolor=#FFFFFF><center><h1>WebMail Response</h1></center><center>Thank you for your submission. The information you provided is beingemailed to <a href="mailto:$elements{'send_to'}">$elements{'send_to'}</a>.</center><p><hr><p><center><font size=-1>WebMail is copyright © 1996 - 1999<a href="http://www.radiation.com/">Radiation</a><br>a service mark of <a href="http://www.radzone.org/gmd/">GlobalMedia Design Inc.</a></font></center></body></html>EOF}# ************************************************************************# Urldecode Routines# ************************************************************************# Copyright & Disclaimer. (James Tappin)# This set of routines may be freely distributed, modified and# used, provided this copyright & disclaimer remains intact.# This package is used at your own risk, if it does what you# want, good; if it doesn't, modify it or use something else--but# don't blame me. Support level = negligable (i.e. mail bugs but# not requests for extensions)# ************************************************************************sub cgiparse { if ($ENV{'REQUEST_METHOD'} eq "POST") { read(STDIN, $data, $ENV{'CONTENT_LENGTH'}); } elsif ($ENV{'REQUEST_METHOD'} eq "GET") { $data = $ENV{'QUERY_STRING'}; } else { # # Bad request method report and exit. # &method_error; } %elements = &url_decode(split(/[&=]/,$data)); @elements2 = &url_decode(split(/[&=]/,$data)); %elements;}sub method_error { print "\nCGI Script Requires use of method POST or GET.\n"; exit;}sub url_decode { foreach (@_) { tr/+/ /; s/%(..)/pack("c",hex($1))/ge; } @_;}# ************************************************************************# End of Generic Form Mailer# ************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -