#!/usr/bin/perl -wT ############################################################################## # nms Formmail Version 3.14c1 # # Copyright 2001 London Perl Mongers All rights reserved # # Created 11/11/01 Last Modified 08/11/04 # # Matt's Script Archive: http://www.scriptarchive.com/ # ############################################################################## # nms Formmail has been created as a drop in replacement for the FormMail # # found at Matt's Script Archive. Both the original and nms versions of this # # script can be found at the above URL. Support for nms Formmail is # # available through: nms-cgi-support@lists.sourceforge.net # ############################################################################## # # NMS FormMail Version 3.14c1 # # This program has been modified by Ivan Raikov to 1) include the # submitted fields in the confirmation email; 2) use quotation marks # to enclose field text that contains newline characters; 3) escape # the submitted text in the notification email. # use strict; use vars qw( $DEBUGGING $emulate_matts_code $secure %more_config $allow_empty_ref $max_recipients $mailprog @referers @allow_mail_to @recipients %recipient_alias @valid_ENV $date_fmt $style $send_confirmation_mail $confirmation_text $locale $charset $no_content $double_spacing $wrap_text $wrap_style $postmaster $address_style ); # PROGRAM INFORMATION # ------------------- # FormMail.pl Version 3.14c1 # # This program is licensed in the same way as Perl # itself. You are free to choose between the GNU Public # License or # the Artistic License # # # For help on configuration or installation see the # README file or the POD documentation at the end of # this file. # USER CONFIGURATION SECTION # -------------------------- # Modify these to your own settings. You might have to # contact your system administrator if you do not run # your own web server. If the purpose of these # parameters seems unclear, please see the README file. # BEGIN { $DEBUGGING = 1; $emulate_matts_code= 0; $secure = 1; $allow_empty_ref = 0; $max_recipients = 1; $mailprog = '/usr/sbin/sendmail -oi -t'; $postmaster = 'nobody@mail.com'; @referers = qw(127.0.0.1); @allow_mail_to = (); @recipients = (); %recipient_alias = ( 'recipient' => 'recipient@mail.com', ); @valid_ENV = qw(REMOTE_HOST REMOTE_ADDR REMOTE_USER HTTP_USER_AGENT HTTP_REFERER); $locale = ''; $charset = 'utf-8'; $date_fmt = '%A, %B %d, %Y at %H:%M:%S'; $style = 'site.css'; $no_content = 0; $double_spacing = 0; $wrap_text = 0; $wrap_style = 1; $address_style = 1; $send_confirmation_mail = 1; $confirmation_text = <<'END_OF_CONFIRMATION'; From: Nobody Subject: Form Submission Thank you for your submission. END_OF_CONFIRMATION # You may need to uncomment the line below and adjust the path. # use lib './lib'; # USER CUSTOMISATION SECTION # -------------------------- # Place any custom code here # USER CUSTOMISATION << END >> # ---------------------------- # (no user serviceable parts beyond here) } # # The code below consists of module source inlined into this # script to make it a standalone CGI. # # Inlining performed by NMS inline - see /v2/buildtools/inline # in CVS at http://sourceforge.net/projects/nms-cgi for details. # BEGIN { $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer = <<'END_INLINED_CGI_NMS_Mailer'; package CGI::NMS::Mailer; use strict; use POSIX qw(strftime); =head1 NAME CGI::NMS::Mailer - email sender base class =head1 SYNOPSYS use base qw(CGI::NMS::Mailer); ... =head1 DESCRIPTION This is a base class for classes implementing low-level email sending objects for use within CGI scripts. =head1 METHODS =over =item output_trace_headers ( TRACEINFO ) Uses the print() virtual method to output email abuse tracing headers including whatever useful information can be gleaned from the CGI environment variables. The TRACEINFO parameter should be a short string giving the name and version of the CGI script. =cut sub output_trace_headers { my ($self, $traceinfo) = @_; $ENV{REMOTE_ADDR} =~ /^\[?([\d\.\:a-f]{7,100})\]?$/i or die "failed to get remote address from [$ENV{REMOTE_ADDR}], so can't send traceable email"; $self->print("Received: from [$1]\n"); my $me = ($ENV{SERVER_NAME} =~ /^([\w\-\.]{1,100})$/ ? $1 : 'unknown'); $self->print("\tby $me ($traceinfo)\n"); my $date = strftime '%a, %e %b %Y %H:%M:%S GMT', gmtime; $self->print("\twith HTTP; $date\n"); if ($ENV{SCRIPT_NAME} =~ /^([\w\-\.\/]{1,100})$/) { $self->print("\t(script-name $1)\n"); } if (defined $ENV{HTTP_HOST} and $ENV{HTTP_HOST} =~ /^([\w\-\.]{1,100})$/) { $self->print("\t(http-host $1)\n"); } my $ff = $ENV{HTTP_X_FORWARDED_FOR}; if (defined $ff) { $ff =~ /^\s*([\w\-\.\[\] ,]{1,200})\s*/ or die "malformed X-Forwarded-For [$ff], suspect attack, aborting"; $self->print("\t(http-x-forwarded-for $1)\n"); } my $ref = $ENV{HTTP_REFERER}; if (defined $ref and $ref =~ /^([\w\-\.\/\:\;\%\@\#\~\=\+\?]{1,100})$/) { $self->print("\t(http-referer $1)\n"); } } =back =head1 VIRTUAL METHODS Subclasses must implement the following methods: =over =item newmail ( TRACEINFO, SENDER, @RECIPIENTS ) Starts a new email. TRACEINFO is the script name and version, SENDER is the email address to use as the envelope sender and @RECIPIENTS is a list of recipients. Dies on error. =item print ( @ARGS ) Concatenates the arguments and appends them to the email. Both the header and the body should be sent in this way, separated by a single blank line. Dies on error. =item endmail () Finishes the email, flushing buffers and sending it. Dies on error. =back =head1 SEE ALSO L, L, L =head1 MAINTAINERS The NMS project, Ehttp://nms-cgi.sourceforge.net/E To request support or report bugs, please email Enms-cgi-support@lists.sourceforge.netE =head1 COPYRIGHT Copyright 2003 London Perl Mongers, All rights reserved =head1 LICENSE This module is free software; you are free to redistribute it and/or modify it under the same terms as Perl itself. =cut 1; END_INLINED_CGI_NMS_Mailer $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer_SMTP = <<'END_INLINED_CGI_NMS_Mailer_SMTP'; package CGI::NMS::Mailer::SMTP; use strict; use IO::Socket; BEGIN { do { unless (eval {local $SIG{__DIE__} ; require CGI::NMS::Mailer}) { eval $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer or die $@; $INC{'CGI/NMS/Mailer.pm'} = 1; } undef $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer; # to save memory }; import CGI::NMS::Mailer } use base qw(CGI::NMS::Mailer); =head1 NAME CGI::NMS::Mailer::SMTP - mail sender using SMTP =head1 SYNOPSYS my $mailer = CGI::NMS::Mailer::SMTP->new('mailhost.bigisp.net'); $mailer->newmail($from, $to); $mailer->print($email_header_and_body); $mailer->endmail; =head1 DESCRIPTION This implementation of the mailer object defined in L uses an SMTP connection to a mail relay to send the email. =head1 CONSTRUCTORS =over =item new ( MAILHOST ) MAILHOST must be the name or dotted decimal IP address of an SMTP server that will relay mail for the web server. =cut sub new { my ($pkg, $mailhost) = @_; $mailhost .= ':25' unless $mailhost =~ /:/; return bless { Mailhost => $mailhost }, $pkg; } =back =head1 METHODS See L for the user interface to these methods. =over =item newmail ( SCRIPTNAME, SENDER, @RECIPIENTS ) Opens the SMTP connection and sends trace headers. =cut sub newmail { my ($self, $scriptname, $sender, @recipients) = @_; $self->{Sock} = IO::Socket::INET->new($self->{Mailhost}); defined $self->{Sock} or die "connect to [$self->{Mailhost}]: $!"; my $banner = $self->_smtp_response; $banner =~ /^2/ or die "bad SMTP banner [$banner] from [$self->{Mailhost}]"; my $helohost = ($ENV{SERVER_NAME} =~ /^([\w\-\.]+)$/ ? $1 : '.'); $self->_smtp_command("HELO $helohost"); $self->_smtp_command("MAIL FROM:<$sender>"); foreach my $r (@recipients) { $self->_smtp_command("RCPT TO:<$r>"); } $self->_smtp_command("DATA", '3'); $self->output_trace_headers($scriptname); } =item print ( @ARGS ) Writes some email body to the SMTP socket. =cut sub print { my ($self, @args) = @_; my $text = join '', @args; $text =~ s#\n#\015\012#g; $text =~ s#^\.#..#mg; $self->{Sock}->print($text) or die "write to SMTP socket: $!"; } =item endmail () Finishes sending the mail and closes the SMTP connection. =cut sub endmail { my ($self) = @_; $self->_smtp_command("."); $self->_smtp_command("QUIT"); delete $self->{Sock}; } =back =head1 PRIVATE METHODS These methods should be called from within this module only. =over =item _smtp_getline () Reads a line from the SMTP socket, and returns it as a string, including the terminating newline sequence. =cut sub _smtp_getline { my ($self) = @_; my $sock = $self->{Sock}; my $line = <$sock>; defined $line or die "read from SMTP server: $!"; return $line; } =item _smtp_response () Reads a command response from the SMTP socket, and returns it as a single string. A multiline responses is returned as a multiline string, and the terminating newline sequence is always included. =cut sub _smtp_response { my ($self) = @_; my $line = $self->_smtp_getline; my $resp = $line; while ($line =~ /^\d\d\d\-/) { $line = $self->_smtp_getline; $resp .= $line; } return $resp; } =item _smtp_command ( COMMAND [,EXPECT] ) Sends the SMTP command COMMAND to the SMTP server, and reads a line in response. Dies unless the first character of the response is the character EXPECT, which defaults to '2'. =cut sub _smtp_command { my ($self, $command, $expect) = @_; defined $expect or $expect = '2'; $self->{Sock}->print("$command\015\012") or die "write [$command] to SMTP server: $!"; my $resp = $self->_smtp_response; unless (substr($resp, 0, 1) eq $expect) { die "SMTP command [$command] gave response [$resp]"; } } =back =head1 MAINTAINERS The NMS project, Ehttp://nms-cgi.sourceforge.net/E To request support or report bugs, please email Enms-cgi-support@lists.sourceforge.netE =head1 COPYRIGHT Copyright 2003 London Perl Mongers, All rights reserved =head1 LICENSE This module is free software; you are free to redistribute it and/or modify it under the same terms as Perl itself. =cut 1; END_INLINED_CGI_NMS_Mailer_SMTP $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer_Sendmail = <<'END_INLINED_CGI_NMS_Mailer_Sendmail'; package CGI::NMS::Mailer::Sendmail; use strict; use IO::File; BEGIN { do { unless (eval {local $SIG{__DIE__} ; require CGI::NMS::Mailer}) { eval $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer or die $@; $INC{'CGI/NMS/Mailer.pm'} = 1; } undef $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer; # to save memory }; import CGI::NMS::Mailer } use base qw(CGI::NMS::Mailer); =head1 NAME CGI::NMS::Mailer::Sendmail - mail sender using sendmail =head1 SYNOPSYS my $mailer = CGI::NMS::Mailer::Sendmail->new('/usr/lib/sendmail -oi -t'); $mailer->newmail($from, $to); $mailer->print($email_header_and_body); $mailer->endmail; =head1 DESCRIPTION This implementation of the mailer object defined in L uses a piped open to the UNIX sendmail program to send the email. =head1 CONSTRUCTORS =over =item new ( MAILPROG ) MAILPROG must be the shell command to which a pipe is opened, including all nessessary switches to cause the sendmail program to read the email recipients from the header of the email. =cut sub new { my ($pkg, $mailprog) = @_; return bless { Mailprog => $mailprog }, $pkg; } =back =head1 METHODS See L for the user interface to these methods. =over =item newmail ( SCRIPTNAME, POSTMASTER, @RECIPIENTS ) Opens the sendmail pipe and outputs trace headers. =cut sub newmail { my ($self, $scriptname, $postmaster, @recipients) = @_; my $command = $self->{Mailprog}; $command .= qq{ -f "$postmaster"} if $postmaster; my $pipe; eval { local $SIG{__DIE__}; $pipe = IO::File->new("| $command"); }; if ($@) { die $@ unless $@ =~ /Insecure directory/; delete $ENV{PATH}; $pipe = IO::File->new("| $command"); } die "Can't open mailprog [$command]\n" unless $pipe; $self->{Pipe} = $pipe; $self->output_trace_headers($scriptname); } =item print ( @ARGS ) Writes some email body to the sendmail pipe. =cut sub print { my ($self, @args) = @_; $self->{Pipe}->print(@args) or die "write to sendmail pipe: $!"; } =item endmail () Closes the sendmail pipe. =cut sub endmail { my ($self) = @_; $self->{Pipe}->close or die "close sendmail pipe failed, mailprog=[$self->{Mailprog}]"; delete $self->{Pipe}; } =back =head1 MAINTAINERS The NMS project, Ehttp://nms-cgi.sourceforge.net/E To request support or report bugs, please email Enms-cgi-support@lists.sourceforge.netE =head1 COPYRIGHT Copyright 2003 London Perl Mongers, All rights reserved =head1 LICENSE This module is free software; you are free to redistribute it and/or modify it under the same terms as Perl itself. =cut 1; END_INLINED_CGI_NMS_Mailer_Sendmail unless (eval {local $SIG{__DIE__} ; require CGI::NMS::Charset}) { eval <<'END_INLINED_CGI_NMS_Charset' or die $@; package CGI::NMS::Charset; use strict; require 5.00404; use vars qw($VERSION); $VERSION = sprintf '%d.%.2d', (q$Revision: 1.1 $ =~ /(\d+)\.(\d+)/); =head1 NAME CGI::NMS::Charset - a charset-aware object for handling text strings =head1 SYNOPSIS my $cs = CGI::NMS::Charset->new('iso-8859-1'); my $safe_to_put_in_html = $cs->escape($untrusted_user_input); my $printable = &{ $cs->strip_nonprint_coderef }( $input ); my $escaped = &{ $cs->escape_html_coderef }( $printable ); =head1 DESCRIPTION Each object of class C is bound to a particular character set when it is created. The object provides methods to generate coderefs to perform a couple of character set dependent operations on text strings. =cut =head1 CONSTRUCTORS =over =item new ( CHARSET ) Creates a new C object, suitable for handing text in the character set CHARSET. The CHARSET parameter must be a character set string, such as C or C for example. =cut sub new { my ($pkg, $charset) = @_; my $self = { CHARSET => $charset }; if ($charset =~ /^utf-8$/i) { $self->{SN} = \&_strip_nonprint_utf8; $self->{EH} = \&_escape_html_utf8; } elsif ($charset =~ /^iso-8859/i) { $self->{SN} = \&_strip_nonprint_8859; if ($charset =~ /^iso-8859-1$/i) { $self->{EH} = \&_escape_html_8859_1; } else { $self->{EH} = \&_escape_html_8859; } } elsif ($charset =~ /^us-ascii$/i) { $self->{SN} = \&_strip_nonprint_ascii; $self->{EH} = \&_escape_html_8859_1; } else { $self->{SN} = \&_strip_nonprint_weak; $self->{EH} = \&_escape_html_weak; } return bless $self, $pkg; } =back =head1 METHODS =over =item charset () Returns the CHARSET string that was passed to the constructor. =cut sub charset { my ($self) = @_; return $self->{CHARSET}; } =item escape ( STRING ) Returns a copy of STRING with runs of non-printable characters replaced with spaces and HTML metacharacters replaced with the equivalent entities. If STRING is undef then the empty string will be returned. =cut sub escape { my ($self, $string) = @_; return &{ $self->{EH} }( &{ $self->{SN} }($string) ); } =item strip_nonprint_coderef () Returns a reference to a sub to replace runs of non-printable characters with spaces, in a manner suited to the charset in use. The returned coderef points to a sub that takes a single readonly string argument and returns a modified version of the string. If undef is passed to the function then the empty string will be returned. =cut sub strip_nonprint_coderef { my ($self) = @_; return $self->{SN}; } =item escape_html_coderef () Returns a reference to a sub to escape HTML metacharacters in a manner suited to the charset in use. The returned coderef points to a sub that takes a single readonly string argument and returns a modified version of the string. =cut sub escape_html_coderef { my ($self) = @_; return $self->{EH}; } =back =head1 DATA TABLES =over =item C<%eschtml_map> The C<%eschtml_map> hash maps C characters to the equivalent HTML entities. =cut use vars qw(%eschtml_map); %eschtml_map = ( ( map {chr($_) => "&#$_;"} (0..255) ), '<' => '<', '>' => '>', '&' => '&', '"' => '"', ); =back =head1 PRIVATE FUNCTIONS These functions are returned by the strip_nonprint_coderef() and escape_html_coderef() methods and invoked by the escape() method. The function most appropriate to the character set in use will be chosen. =over =item _strip_nonprint_utf8 Returns a copy of STRING with everything but printable C characters and valid C multibyte sequences replaced with space characters. =cut sub _strip_nonprint_utf8 { my ($string) = @_; return '' unless defined $string; $string =~ s% ( [\t\n\040-\176] # printable us-ascii | [\xC2-\xDF][\x80-\xBF] # U+00000080 to U+000007FF | \xE0[\xA0-\xBF][\x80-\xBF] # U+00000800 to U+00000FFF | [\xE1-\xEF][\x80-\xBF]{2} # U+00001000 to U+0000FFFF | \xF0[\x90-\xBF][\x80-\xBF]{2} # U+00010000 to U+0003FFFF | [\xF1-\xF7][\x80-\xBF]{3} # U+00040000 to U+001FFFFF | \xF8[\x88-\xBF][\x80-\xBF]{3} # U+00200000 to U+00FFFFFF | [\xF9-\xFB][\x80-\xBF]{4} # U+01000000 to U+03FFFFFF | \xFC[\x84-\xBF][\x80-\xBF]{4} # U+04000000 to U+3FFFFFFF | \xFD[\x80-\xBF]{5} # U+40000000 to U+7FFFFFFF ) | . % defined $1 ? $1 : ' ' %gexs; # # U+FFFE, U+FFFF and U+D800 to U+DFFF are dangerous and # should be treated as invalid combinations, according to # http://www.cl.cam.ac.uk/~mgk25/unicode.html # $string =~ s%\xEF\xBF[\xBE-\xBF]% %g; $string =~ s%\xED[\xA0-\xBF][\x80-\xBF]% %g; return $string; } =item _escape_html_utf8 ( STRING ) Returns a copy of STRING with any HTML metacharacters escaped. Escapes all but the most commonly occurring C characters and bytes that might form part of valid C multibyte sequences. =cut sub _escape_html_utf8 { my ($string) = @_; $string =~ s|([^\w \t\r\n\-\.\,\x80-\xFD])| $eschtml_map{$1} |ge; return $string; } =item _strip_nonprint_weak ( STRING ) Returns a copy of STRING with sequences of NULL characters replaced with space characters. =cut sub _strip_nonprint_weak { my ($string) = @_; return '' unless defined $string; $string =~ s/\0+/ /g; return $string; } =item _escape_html_weak ( STRING ) Returns a copy of STRING with any HTML metacharacters escaped. In order to work in any charset, escapes only E, E, C<"> and C<&> characters. =cut sub _escape_html_weak { my ($string) = @_; $string =~ s/[<>"&]/$eschtml_map{$1}/eg; return $string; } =item _escape_html_8859_1 ( STRING ) Returns a copy of STRING with all but the most commonly occurring printable characters replaced with HTML entities. Only suitable for C or C input. =cut sub _escape_html_8859_1 { my ($string) = @_; $string =~ s|([^\w \t\r\n\-\.\,\/\:])| $eschtml_map{$1} |ge; return $string; } =item _escape_html_8859 ( STRING ) Returns a copy of STRING with all but the most commonly occurring printable C characters and characters that might be printable in some C charset replaced with HTML entities. =cut sub _escape_html_8859 { my ($string) = @_; $string =~ s|([^\w \t\r\n\-\.\,\/\:\240-\377])| $eschtml_map{$1} |ge; return $string; } =item _strip_nonprint_8859 ( STRING ) Returns a copy of STRING with runs of characters that are not printable in any C charset replaced with spaces. =cut sub _strip_nonprint_8859 { my ($string) = @_; return '' unless defined $string; $string =~ tr#\t\n\040-\176\240-\377# #cs; return $string; } =item _strip_nonprint_ascii ( STRING ) Returns a copy of STRING with runs of characters that are not printable C replaced with spaces. =cut sub _strip_nonprint_ascii { my ($string) = @_; return '' unless defined $string; $string =~ tr#\t\n\040-\176# #cs; return $string; } =back =head1 MAINTAINERS The NMS project, Ehttp://nms-cgi.sourceforge.net/E To request support or report bugs, please email Enms-cgi-support@lists.sourceforge.netE =head1 COPYRIGHT Copyright 2002-2003 London Perl Mongers, All rights reserved =head1 LICENSE This module is free software; you are free to redistribute it and/or modify it under the same terms as Perl itself. =cut 1; END_INLINED_CGI_NMS_Charset $INC{'CGI/NMS/Charset.pm'} = 1; } unless (eval {local $SIG{__DIE__} ; require CGI::NMS::Mailer::ByScheme}) { eval <<'END_INLINED_CGI_NMS_Mailer_ByScheme' or die $@; package CGI::NMS::Mailer::ByScheme; use strict; =head1 NAME CGI::NMS::Mailer::ByScheme - mail sending engine switch =head1 SYNOPSYS my $mailer = CGI::NMS::Mailer::ByScheme->new('/usr/lib/sendmail -oi -t'); my $mailer = CGI::NMS::Mailer::ByScheme->new('SMTP:mailhost.bigisp.net'); =head1 DESCRIPTION This implementation of the mailer object defined in L chooses between L and L based on the string passed to new(). =head1 CONSTRUCTORS =over =item new ( ARGUMENT ) ARGUMENT must either be the string C followed by the name or dotted decimal IP address of an SMTP server that will relay mail for the web server, or the path to a sendmail compatible binary, including switches. =cut sub new { my ($pkg, $argument) = @_; if ($argument =~ /^SMTP:([\w\-\.]+(:\d+)?)/i) { my $mailhost = $1; do { unless (eval {local $SIG{__DIE__} ; require CGI::NMS::Mailer::SMTP}) { eval $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer_SMTP or die $@; $INC{'CGI/NMS/Mailer/SMTP.pm'} = 1; } undef $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer_SMTP; # to save memory }; return CGI::NMS::Mailer::SMTP->new($mailhost); } else { do { unless (eval {local $SIG{__DIE__} ; require CGI::NMS::Mailer::Sendmail}) { eval $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer_Sendmail or die $@; $INC{'CGI/NMS/Mailer/Sendmail.pm'} = 1; } undef $CGI::NMS::INLINED_SOURCE::CGI_NMS_Mailer_Sendmail; # to save memory }; return CGI::NMS::Mailer::Sendmail->new($argument); } } =back =head1 MAINTAINERS The NMS project, Ehttp://nms-cgi.sourceforge.net/E To request support or report bugs, please email Enms-cgi-support@lists.sourceforge.netE =head1 COPYRIGHT Copyright 2003 London Perl Mongers, All rights reserved =head1 LICENSE This module is free software; you are free to redistribute it and/or modify it under the same terms as Perl itself. =cut 1; END_INLINED_CGI_NMS_Mailer_ByScheme $INC{'CGI/NMS/Mailer/ByScheme.pm'} = 1; } unless (eval {local $SIG{__DIE__} ; require CGI::NMS::Script}) { eval <<'END_INLINED_CGI_NMS_Script' or die $@; package CGI::NMS::Script; use strict; use CGI; use POSIX qw(locale_h strftime); use CGI::NMS::Charset; =head1 NAME CGI::NMS::Script - base class for NMS script modules =head1 SYNOPSYS use base qw(CGI::NMS::Script); ... =head1 DESCRIPTION This module is a base class for the C modules, which implement plugin replacements for Matt Wright's Perl CGI scripts. =head1 CONSTRUCTORS =over =item new ( CONFIG ) Creates a new C object and performs compile time initialisation. CONFIG is a key,value,key,value list, which will be stored as a hash within the object, under the name C. =cut sub new { my ($pkg, @cfg) = @_; my $self = bless {}, $pkg; $self->{CFG} = { DEBUGGING => 0, emulate_matts_code => 0, secure => 1, locale => '', charset => 'iso-8859-1', style => '', cgi_post_max => 1000000, cgi_disable_uploads => 1, $self->default_configuration, @cfg }; $self->{Charset} = CGI::NMS::Charset->new( $self->{CFG}{charset} ); $self->init; return $self; } =back =item CONFIGURATION SETTINGS Values for the following configuration settings can be passed to new(). Subclasses for different NMS scripts will define their own set of configuration settings, but they all inherit these as well. =over =item C If this is set to a true value, then the error message will be displayed in the browser if the script suffers a fatal error. This should be set to 0 once the script is in service, since error messages may contain sensitive information such as file paths which could be useful to attackers. Default: 0 =item C The name and version of the NMS script, as a single string. =item C When this variable is set to a true value (e.g. 1) the script will work in exactly the same way as its counterpart at Matt's Script Archive. If it is set to a false value (e.g. 0) then more advanced features and security checks are switched on. We do not recommend changing this variable to 1, as the resulting drop in security may leave your script open to abuse. Default: 0 =item C When this variable is set to a true value (e.g. 1) many additional security features are turned on. We do not recommend changing this variable to 0, as the resulting drop in security may leave your script open to abuse. Default: 1 =item C This determines the language that is used in the format_date() method - by default this is blank and the language will probably be English. Default: '' =item C The character set to use for output documents. Default: 'iso-8859-1' =item C

$title

Below is what you submitted $torecipient on $date


END } =item success_page_fields () Outputs success page HTML output for each input field. =cut sub success_page_fields { my ($self) = @_; foreach my $f (@{ $self->{Field_Order} }) { my $val = (defined $self->{Form}{$f} ? $self->{Form}{$f} : ''); $self->success_page_field( $self->escape_html($f), $self->escape_html($val) ); } } =item success_page_field ( NAME, VALUE ) { Outputs success page HTML for a single input field. NAME and VALUE are the HTML escaped field name and value. =cut sub success_page_field { my ($self, $name, $value) = @_; print "

$name: $value

\n"; } =item success_page_footer () Outputs the footer of the success page, including the return link if configured. =cut sub success_page_footer { my ($self) = @_; print qq{


\n}; $self->success_page_return_link; print <

nms FormMail © 2001 London Perl Mongers
Written as drop-in replacement for FormMail at Matt's Script Archive

END } =item success_page_return_link () Outputs the success page return link if any is configured. =cut sub success_page_return_link { my ($self) = @_; if ($self->{FormConfig}{return_link_url} and $self->{FormConfig}{return_link_title}) { print "\n"; } } =item body_attributes () Gets the body attributes for the success page from the form configuration, and returns the string that should go inside the C tag. =cut sub body_attributes { my ($self) = @_; my %attrs = (bgcolor => 'bgcolor', background => 'background', link_color => 'link', vlink_color => 'vlink', alink_color => 'alink', text_color => 'text'); my $attr = ''; foreach my $at (keys %attrs) { my $val = $self->{FormConfig}{$at}; next unless $val; if ($at =~ /color$/) { $val = $self->validate_html_color($val); } elsif ($at eq 'background') { $val = $self->validate_url($val); } else { die "no check defined for body attribute [$at]"; } $attr .= qq( $attrs{$at}=") . $self->escape_html($val) . '"' if $val; } return $attr; } =item error_page( TITLE, ERROR_BODY ) Outputs a FormMail error page, giving the HTML document the title TITLE and displaying the HTML error message ERROR_BODY. =cut sub error_page { my ($self, $title, $error_body) = @_; $self->output_cgi_html_header; my $etitle = $self->escape_html($title); print < $etitle END print < END $self->output_style_element; print <
$etitle
$error_body

nms FormMail © 2001 London Perl Mongers
Written as drop-in replacement for FormMail at Matt's Script Archive

END } =item mailer () Returns an object satisfying the definition in L, to be used for sending outgoing email. =cut sub mailer { my ($self) = @_; return $self->{Mailer}; } =back =head1 SEE ALSO L =head1 MAINTAINERS The NMS project, Ehttp://nms-cgi.sourceforge.net/E To request support or report bugs, please email Enms-cgi-support@lists.sourceforge.netE =head1 COPYRIGHT Copyright 2003 London Perl Mongers, All rights reserved =head1 LICENSE This module is free software; you are free to redistribute it and/or modify it under the same terms as Perl itself. =cut 1; END_INLINED_CGI_NMS_Script_FormMail $INC{'CGI/NMS/Script/FormMail.pm'} = 1; } } # # End of inlined modules # use CGI::NMS::Script::FormMail; use base qw(CGI::NMS::Script::FormMail); use vars qw($script); BEGIN { $script = __PACKAGE__->new( DEBUGGING => $DEBUGGING, name_and_version => 'NMS FormMail 3.14c1', emulate_matts_code => $emulate_matts_code, secure => $secure, allow_empty_ref => $allow_empty_ref, max_recipients => $max_recipients, mailprog => $mailprog, postmaster => $postmaster, referers => [@referers], allow_mail_to => [@allow_mail_to], recipients => [@recipients], recipient_alias => {%recipient_alias}, valid_ENV => [@valid_ENV], locale => $locale, charset => $charset, date_fmt => $date_fmt, style => $style, no_content => $no_content, double_spacing => $double_spacing, wrap_text => $wrap_text, wrap_style => $wrap_style, send_confirmation_mail => $send_confirmation_mail, confirmation_text => $confirmation_text, address_style => $address_style, %more_config ); } $script->request;