Chris Devers wrote:
> 
> On Wed, 26 Sep 2001, Musar Information Network wrote:
> 
> > If you're familiar with MAILTO.EXE that's all I want to do.
> 
> Never heard of it... :/
> 
> > It should be really simple except I'm at a loss because I usually
> > define the variables to specifically match form data and in this case
> > it needs to be flexible enough to handle a variety of different field
> > names and a various number of fields.
> 
> Ok then, here's excerpts from a script I finished debugging yesterday.
> It's meant to receive input from an error page's form (a 404 handler),
> grab all of the data from that page, including both the form data and
> anythign I can glean from the environment, and then dump it into an email
> & redirect the web user to a different page on success. This is, broadly,
> the same sort of thing you're trying to do, I think. Here we go:
> 
>     #!/usr/bin/perl -w
> 
>     use strict;
>     use CGI;
>     use MIME::Lite;
> 
>     #
>     # data dictionary
>     # grab info from the environment & parameters,
>     # using backups & default values as needed
>     # note that most are dynamic, but some, such as $to,
>     # are hard-coded for reasons of security & robustness.
>     #
>     my $cgi        = new CGI;
>     my $server     = $ENV{'SERVER_NAME'}       || "domain.com";
>     my $referer    = $ENV{'HTTP_REFERER'}      || "unavailable";
>     my $document   = $ENV{'DOCUMENT_URI'}      || $ENV{'REQUEST_URI'} || "uri 
>unavailable";
>     my $remoteaddr = $ENV{'REMOTE_HOST'}       || $ENV{'REMOTE_HOST'} || 
>"unavailable";
>     my $query      = $ENV{'QUERY_STRING'}      || "unavailable";
>     my $date_gmt   = $cgi->param('date_gmt')   || $ENV{'DATE_GMT'}    || gmtime;
>     my $date_local = $cgi->param('date_local') || $ENV{'DATE_LOCAL'}  || localtime;
>     my $mailsrv    = "mail.domain.com";
>     my $to         = '[EMAIL PROTECTED]';
>     my $from       = $cgi->param('email')      || "web-user\@$server";
>        $from = "$from\@nowhere" unless ($from =~ m/\@/);
>     my $subject    = $cgi->param('subject')    || "Error Report";
>     my $name       = $cgi->param('name')       || "anonymous";
>     my $phone      = $cgi->param('phone')      || "not provided";
>     my $fax        = $cgi->param('fax')        || "not provided";
>     my $contact    = $cgi->param('method')     || "not provided";
>     my $return_url = $cgi->param('return')     || "/misc/error_thanks.html";
>     my $comments   = $cgi->param('comments')   || "none provided";;

Most of this info is unusable on an error page handler.  Some more relevant 
ones are (not all may be present on a given error doc):

REDIRECT_STATUS         These two are the most useful
REDIRECT_URL

REDIRECT_HTTP_ACCEPT
REDIRECT_HTTP_USER_AGENT
REDIRECT_PATH
REDIRECT_QUERY_STRING
REDIRECT_REMOTE_ADDR or REMOTE_ADDR
REDIRECT_REMOTE_HOST
REDIRECT_REQUEST_METHOD
REDIRECT_SERVER_NAME
REDIRECT_SERVER_PORT
REDIRECT_SERVER_SOFTWARE

You can base your processing on the REDIRECT_STATUS.  In the case of a 404 
error I usually check for stuff like:

        /stream\.key/
        /favicon\.ico/
        /frame-edge-bg\.gif/
        /\/NOFRAMES/
        /default\.ida/
        /(cmd|root)\.exe$/

which are errors that may occur due to a particular browser or virus.  I 
don't want to email myself on these frequent normal conditions - maybe just 
log them.

>     #
>     # generate the main message contents for the email
>     #
>     my $message_body = qq{
>         Information submitted by the web user:
>         Name:                       $name
>         Email:                      $from
>         Phone:                      $phone
>         Fax:                        $fax
>         Preferred contact method:   $contact
>         GMT time noted:             $date_gmt
>         Local time noted:           $date_local
>         Referring page:             $referer
>         Query string:               $query
>         Comments:
>             $comments
>         Other data:
> 
>         Hidden variables from the web page:
>     };
> 
>     #
>     # get the form data, then the environment data
>     #
>     foreach $name ( $cgi->param() ) {
>         my $value      = $cgi->param( -name=> $name );
>         $message_body .= "      $name: \t$value\n";
>     }

Normally there is no form data on error pages (but not impossible).  I 
just include the query string and stdin in the email.

>     $message_body .= "\n\nEnvironment variables from the web client:\n";
>     foreach $name (sort keys %ENV) {
>         my $value      = $ENV{$name};
>         $message_body .= "        $name: \t$value\n";
>     }
> 
>     #
>     # actually prepare & send mail
>     #
>     my $msg = new MIME::Lite (
>               From     => $from,
>               To       => $to,
>               Type     => 'text/plain',
>               Subject  => "$subject - $document - $remoteaddr",
>               Data     => $message_body,
>     );
>     $msg->send;
> 
>     #
>     # redirect to a new page
>     #
>     print "Location: http://www.domain.com/$return_url\n\n";;

I would use a custom page here indicating what error occurred and what to do 
about it.  Include the redirect status and URL for reference.

> Etc. Provided that you have MIME::Lite (and maybe Net::SMTP, I forget), or
> can get what you need, this is running code. You should be able to modify
> the parameters grabbed, and the format they're translated into (everything
> that gets put into $message_body) so suit your needs.

Net::SMTP could be used if sendmail isn't available (you would need to override 
the default mailer).

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:[EMAIL PROTECTED] 
  / ) /--<  o // //      http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web

Reply via email to