akersche
February 16th, 2001, 15:01
hi,
i am a newbie concerning cgi-scripts, but programing and computer literate (graduate student of cs)
I am not sure wheater I am making something wrong, or the problem is with my free site at virtualave.net.
I just want to start with a simple online form and want the input to be emailed to me via cgi and sendmail.
BUT it didn't work at all:-( got an error, but I couldn't find an error, when opening the cgi-error file of my free site.
Would be great if anybody could go through the script or tell me what problems at virualave.net could be:-)
TIA
ARNO
What i did is write the following html-page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD><TITLE>Test FORM</title></head>
<body>
<FORM ACTION="webmail.cgi" METHOD="post">
<INPUT TYPE=hidden NAME="send_to" VALUE="from_form@kersche.net">
<INPUT TYPE=hidden NAME="subject" VALUE="Online Form Submitted">
<INPUT TYPE=hidden NAME="response_url" VALUE="http://www.kersche.net/">
<INPUT type="text" size="30" VALUE="TestFeld">
<input TYPE=submit border=0 Name="Sent" VALUE="Sent">
</FORM>
</body>
</html>
And I am using the following cgi-script, which i modified to the needed settings. (also set permissions and it's in the same directory, which i called cgi-bin as the html page)
!/usr/local/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 = "/var/qmail/bin/qmail-inject"; # Adjust as needed
# FROM_EMAIL is only used in mode '2' (sendmail mode)
$FROM_EMAIL = 'form\@kersche.net';
# REPLY_EMAIL is only used in mode '2' (sendmail mode)
$REPLY_EMAIL = 'arno\@kersche.net';
# 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 being
emailed 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
# ************************************************************ ************
i am a newbie concerning cgi-scripts, but programing and computer literate (graduate student of cs)
I am not sure wheater I am making something wrong, or the problem is with my free site at virtualave.net.
I just want to start with a simple online form and want the input to be emailed to me via cgi and sendmail.
BUT it didn't work at all:-( got an error, but I couldn't find an error, when opening the cgi-error file of my free site.
Would be great if anybody could go through the script or tell me what problems at virualave.net could be:-)
TIA
ARNO
What i did is write the following html-page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD><TITLE>Test FORM</title></head>
<body>
<FORM ACTION="webmail.cgi" METHOD="post">
<INPUT TYPE=hidden NAME="send_to" VALUE="from_form@kersche.net">
<INPUT TYPE=hidden NAME="subject" VALUE="Online Form Submitted">
<INPUT TYPE=hidden NAME="response_url" VALUE="http://www.kersche.net/">
<INPUT type="text" size="30" VALUE="TestFeld">
<input TYPE=submit border=0 Name="Sent" VALUE="Sent">
</FORM>
</body>
</html>
And I am using the following cgi-script, which i modified to the needed settings. (also set permissions and it's in the same directory, which i called cgi-bin as the html page)
!/usr/local/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 = "/var/qmail/bin/qmail-inject"; # Adjust as needed
# FROM_EMAIL is only used in mode '2' (sendmail mode)
$FROM_EMAIL = 'form\@kersche.net';
# REPLY_EMAIL is only used in mode '2' (sendmail mode)
$REPLY_EMAIL = 'arno\@kersche.net';
# 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 being
emailed 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
# ************************************************************ ************