home *** CD-ROM | disk | FTP | other *** search
- Content-type: text/plain
-
-
- #!/usr/local/bin/perl
-
- #perltest.p
- #for testing cgi-bin interface
- # Put this in your cgi-bin directory, changing the email address below...
-
- #sub to remove cgi-encoding
- sub unescape {
- ($_)=@_;
- # s!\\(.)!$1!ge; # This is sometimes required to remove shell escapes
- tr/+/ /;
- s/%(..)/pack("c",hex($1))/ge;
- $_;
- }
-
- # ---------------------------------------------------------------------------
- # The escape and unescape functions are taken from the wwwurl.pl package
- # developed by Roy Fielding <fielding@ics.uci.edu> as part of the Arcadia
- # project at the University of California, Irvine. It is distributed
- # under the Artistic License (included with your Perl distribution
- # files).
- # ---------------------------------------------------------------------------
-
- #++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
- #.PURPOSE Encodes a string so it doesn't cause problems in URL.
- #
- #.REMARKS
- #
- #.RETURNS The encoded string
- #------------------------------------------------------------------------------
-
- sub cgi_encode
- {
- local ($str) = @_;
- $str = &escape($str,'[\x00-\x20"#%/+;<>?\x7F-\xFF]');
- $str =~ s/ /+/g;
- return( $str );
- }
-
- # ===========================================================================
- # escape(): Return the passed string after replacing all characters matching
- # the passed pattern with their %XX hex escape chars. Note that
- # the caller must be sure not to escape reserved URL characters
- # (e.g. / in pathnames, ':' between address and port, etc.) and thus
- # this routine can only be applied to each URL part separately. E.g.
- #
- # $escname = &escape($name,'[\x00-\x20"#%/;<>?\x7F-\xFF]');
- #
- sub escape
- {
- local($str, $pat) = @_;
-
- $str =~ s/($pat)/sprintf("%%%02lx",unpack('C',$1))/ge;
- return($str);
- }
-
- #now the main program begins
-
- #testing environment variables passed via URL...
- print "Content-type: text/plain","\n";
- print "\n";
-
- open (MAIL,"| mail name@foo.edu") ||
- die "Error: Can't start mail program - Please report this error to name@foo.edu";
-
-
- print MAIL "Matt's New cgi-test script report","\n";
- print MAIL "\n";
- print MAIL "\n";
- print MAIL "Environment variables" ,"\n";
- print MAIL "\n";
-
- foreach(sort keys %ENV) #list all environment variables
- {
- $MyEnvName=$_;
- $MyEnvValue=$ENV{$MyEnvName};
- $URLed = &cgi_encode($MyEnvValue);
- $UnURLed = &unescape($MyEnvValue);
- print MAIL $MyEnvName,"\n";
- print MAIL "Value: ",$MyEnvValue,"\n";
- print MAIL "URLed: ",$URLed,"\n";
- print MAIL "UnURLed: ",$UnURLed,"\n";
- print MAIL "\n";
- }
-
- if ($ENV{'REQUEST_METHOD'} eq "POST")
- {#POST data
-
- print MAIL "POST data \n";
-
- for ($i = 0; $i < $ENV{'CONTENT_LENGTH'}; $i++)
- {
- $MyBuffer .= getc;
- }
-
- print MAIL "Original data: \n";
- print MAIL $MyBuffer,"\n";
- print MAIL "unURLed: \n";
- print MAIL &unescape($MyBuffer), "\n\n";
-
- @MyBuffer = split(/&/,$MyBuffer);
-
- foreach $i (0 .. $#MyBuffer)
- {
- print MAIL $MyBuffer[$i],"\n";
- print MAIL "FName:",&unescape($MyBuffer[$i]),"\n";
- }
- }
-
-
- close ( MAIL );
-
- print "\n";
- print "Thanks for filling out this form !\n";
- print "It has been sent to name@foo.edu\n<p>\n";
-
-