Netwrkengeer
IS-IT--Management
I'm trying to setup a simple perl script on a Unix box, but I keep getting an error. Maybe it is a rights issue maybe it is that I don't know what directories to put the file in. I don't know (there are 3 files The HTML, The CGI, and The .PL) Thanks for your help
This is the error.
"Method Not Allowed
The requested method POST is not allowed for the URL /simple-form.cgi.
Here is the HTML.
[<html>
<head>
<title>A simple form example</title>
</head>
<body>
<H1>This is a simple form using cgi-lib.pl</H1>
<P>
This is a sample form which demonstrates the use of
the <B><A HREF="cgi-lib.pl">cgi-lib.pl</A></B> library of
routines for managing form input.
</P>
<HR>
<form method="post" action="simple-form.cgi">
<H2> Pop Quiz: </H2>
What is thy name: <input name="name"><P>
What is thy quest: <input name="quest"><P>
Press <input type="submit" value="here"> to submit your query.
</form>
</body>
</html> ]
----------------------------------------
here is the script.
[ #!/usr/bin/perl
# $Header: /cys/people/brenner/http/docs/web/RCS/simple-form.cgi,v 1.4 1996/03/29 22:07:56 brenner Exp $
# Copyright (C) 1994 Steven E. Brenner
# This is a small demonstration script to demonstrate the use of
# the cgi-lib.pl library
require "cgi-lib.pl";
MAIN:
{
# Read in all the variables set by the form
&ReadParse(*input);
# Print the header
print &PrintHeader;
print &HtmlTop ("cgi-lib.pl demo form output"
;
# Do some processing, and print some output
($text = $input{'text'}) =~ s/\n/\n<BR>/g;
# add <BR>'s after carriage returns
# to multline input, since HTML does not
# preserve line breaks
print <<ENDOFTEXT;
You, $input{'name'}, whose favorite color is $input{'color'} are on a
quest which is $input{'quest'}, and are looking for the weight of an
$input{'swallow'} swallow. And this is what you have to say for
yourself:<P> $text<P>
ENDOFTEXT
# If you want, just print out a list of all of the variables.
print "<HR>And here is a list of the variables you entered...<P>";
print &PrintVariables(*input);
# Close the document cleanly.
print &HtmlBot;
} ]
------------------------------
Here is the include.
[ #!/usr/bin/perl
# Perl Routines to Manipulate CGI input
#
# Copyright (c) 1995 Steven E. Brenner
# Permission granted to use and modify this library so long as the
# copyright above is maintained, modifications are documented, and
# credit is given for any use of the library.
#
# Thanks are due to many people for reporting bugs and suggestions
# especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen,
# Andrew Dalke, Mark-Jason Dominus, Dave Dittrich, Jason Mathews
# For more information, see:
# #
# Minimalist http form and script (#
# require "cgi-lib.pl";
# if (&ReadParse(*input)) {
# print &PrintHeader, &PrintVariables(%input);
# } else {
# print &PrintHeader,'<form><input type="submit"> Data: <input name="myfield">';
#}
# ReadParse
# Reads in GET or POST data, converts it to unescaped text,
# creates key/value pairs in %in, using '\0' to separate multiple
# selections
# Returns TRUE if there was input, FALSE if there was no input
# UNDEF may be used in the future to indicate some failure.
# Now that cgi scripts can be put in the normal file space, it is useful
# to combine both the form and the script in one place. If no parameters
# are given (i.e., ReadParse returns FALSE), then a form could be output.
# If a variable-glob parameter (e.g., *cgi_input) is passed to ReadParse,
# information is stored there, rather than in $in, @in, and %in.
sub ReadParse {
local (*in) = @_ if @_;
local ($i, $key, $val);
# Read in text
if (&MethGet) {
$in = $ENV{'QUERY_STRING'};
} elsif (&MethPost) {
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
}
@in = split(/[&;]/,$in);
foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;
# Split into key and value.
($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
# Convert %XX from hex numbers to alphanumeric
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
# Associate key and value
$in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;
}
return scalar(@in);
}
# PrintHeader
# Returns the magic line which tells we're an HTML document
sub PrintHeader {
return "Content-type: text/html\n\n";
}
# HtmlTop
# Returns the <head> of a document and the beginning of the body
# with the title and a body <h1> header as specified by the parameter
sub HtmlTop
{
local ($title) = @_;
return <<END_OF_TEXT;
<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>
END_OF_TEXT
}
# Html Bot
# Returns the </body>, </html> codes for the bottom of every HTML page
sub HtmlBot
{
return "</body>\n</html>\n";
}
# MethGet
# Return true if this cgi call was using the GET request, false otherwise
sub MethGet {
return ($ENV{'REQUEST_METHOD'} eq "GET"
;
}
# MethPost
# Return true if this cgi call was using the POST request, false otherwise
sub MethPost {
return ($ENV{'REQUEST_METHOD'} eq "POST"
;
}
# MyURL
# Returns a URL to the script
sub MyURL {
local ($port);
$port = ":" . $ENV{'SERVER_PORT'} if $ENV{'SERVER_PORT'} != 80;
return ' . $ENV{'SERVER_NAME'} . $port . $ENV{'SCRIPT_NAME'};
}
# CgiError
# Prints out an error message which which containes appropriate headers,
# markup, etcetera.
# Parameters:
# If no parameters, gives a generic error message
# Otherwise, the first parameter will be the title and the rest will
# be given as different paragraphs of the body
sub CgiError {
local (@msg) = @_;
local ($i,$name);
if (!@msg) {
$name = &MyURL;
@msg = ("Error: script $name encountered fatal error"
;
};
print &PrintHeader;
print "<html><head><title>$msg[0]</title></head>\n";
print "<body><h1>$msg[0]</h1>\n";
foreach $i (1 .. $#msg) {
print "<p>$msg[$i]</p>\n";
}
print "</body></html>\n";
}
# CgiDie
# Identical to CgiError, but also quits with the passed error message.
sub CgiDie {
local (@msg) = @_;
&CgiError (@msg);
die @msg;
}
# PrintVariables
# Nicely formats variables in an associative array passed as a parameter
# And returns the HTML string.
sub PrintVariables {
local (%in) = @_;
local ($old, $out, $output);
$old = $*; $* =1;
$output .= "\n<dl compact>\n";
foreach $key (sort keys(%in)) {
foreach (split("\0", $in{$key})) {
($out = $_) =~ s/\n/<br>\n/g;
$output .= "<dt><b>$key</b>\n <dd><i>$out</i><br>\n";
}
}
$output .= "</dl>\n";
$* = $old;
return $output;
}
# PrintVariablesShort
# Now obsolete; just calls PrintVariables
sub PrintVariablesShort {
return &PrintVariables(@_);
}
1; #return true ]
This is the error.
"Method Not Allowed
The requested method POST is not allowed for the URL /simple-form.cgi.
Here is the HTML.
[<html>
<head>
<title>A simple form example</title>
</head>
<body>
<H1>This is a simple form using cgi-lib.pl</H1>
<P>
This is a sample form which demonstrates the use of
the <B><A HREF="cgi-lib.pl">cgi-lib.pl</A></B> library of
routines for managing form input.
</P>
<HR>
<form method="post" action="simple-form.cgi">
<H2> Pop Quiz: </H2>
What is thy name: <input name="name"><P>
What is thy quest: <input name="quest"><P>
Press <input type="submit" value="here"> to submit your query.
</form>
</body>
</html> ]
----------------------------------------
here is the script.
[ #!/usr/bin/perl
# $Header: /cys/people/brenner/http/docs/web/RCS/simple-form.cgi,v 1.4 1996/03/29 22:07:56 brenner Exp $
# Copyright (C) 1994 Steven E. Brenner
# This is a small demonstration script to demonstrate the use of
# the cgi-lib.pl library
require "cgi-lib.pl";
MAIN:
{
# Read in all the variables set by the form
&ReadParse(*input);
# Print the header
print &PrintHeader;
print &HtmlTop ("cgi-lib.pl demo form output"
# Do some processing, and print some output
($text = $input{'text'}) =~ s/\n/\n<BR>/g;
# add <BR>'s after carriage returns
# to multline input, since HTML does not
# preserve line breaks
print <<ENDOFTEXT;
You, $input{'name'}, whose favorite color is $input{'color'} are on a
quest which is $input{'quest'}, and are looking for the weight of an
$input{'swallow'} swallow. And this is what you have to say for
yourself:<P> $text<P>
ENDOFTEXT
# If you want, just print out a list of all of the variables.
print "<HR>And here is a list of the variables you entered...<P>";
print &PrintVariables(*input);
# Close the document cleanly.
print &HtmlBot;
} ]
------------------------------
Here is the include.
[ #!/usr/bin/perl
# Perl Routines to Manipulate CGI input
#
# Copyright (c) 1995 Steven E. Brenner
# Permission granted to use and modify this library so long as the
# copyright above is maintained, modifications are documented, and
# credit is given for any use of the library.
#
# Thanks are due to many people for reporting bugs and suggestions
# especially Meng Weng Wong, Maki Watanabe, Bo Frese Rasmussen,
# Andrew Dalke, Mark-Jason Dominus, Dave Dittrich, Jason Mathews
# For more information, see:
# #
# Minimalist http form and script (#
# require "cgi-lib.pl";
# if (&ReadParse(*input)) {
# print &PrintHeader, &PrintVariables(%input);
# } else {
# print &PrintHeader,'<form><input type="submit"> Data: <input name="myfield">';
#}
# ReadParse
# Reads in GET or POST data, converts it to unescaped text,
# creates key/value pairs in %in, using '\0' to separate multiple
# selections
# Returns TRUE if there was input, FALSE if there was no input
# UNDEF may be used in the future to indicate some failure.
# Now that cgi scripts can be put in the normal file space, it is useful
# to combine both the form and the script in one place. If no parameters
# are given (i.e., ReadParse returns FALSE), then a form could be output.
# If a variable-glob parameter (e.g., *cgi_input) is passed to ReadParse,
# information is stored there, rather than in $in, @in, and %in.
sub ReadParse {
local (*in) = @_ if @_;
local ($i, $key, $val);
# Read in text
if (&MethGet) {
$in = $ENV{'QUERY_STRING'};
} elsif (&MethPost) {
read(STDIN,$in,$ENV{'CONTENT_LENGTH'});
}
@in = split(/[&;]/,$in);
foreach $i (0 .. $#in) {
# Convert plus's to spaces
$in[$i] =~ s/\+/ /g;
# Split into key and value.
($key, $val) = split(/=/,$in[$i],2); # splits on the first =.
# Convert %XX from hex numbers to alphanumeric
$key =~ s/%(..)/pack("c",hex($1))/ge;
$val =~ s/%(..)/pack("c",hex($1))/ge;
# Associate key and value
$in{$key} .= "\0" if (defined($in{$key})); # \0 is the multiple separator
$in{$key} .= $val;
}
return scalar(@in);
}
# PrintHeader
# Returns the magic line which tells we're an HTML document
sub PrintHeader {
return "Content-type: text/html\n\n";
}
# HtmlTop
# Returns the <head> of a document and the beginning of the body
# with the title and a body <h1> header as specified by the parameter
sub HtmlTop
{
local ($title) = @_;
return <<END_OF_TEXT;
<html>
<head>
<title>$title</title>
</head>
<body>
<h1>$title</h1>
END_OF_TEXT
}
# Html Bot
# Returns the </body>, </html> codes for the bottom of every HTML page
sub HtmlBot
{
return "</body>\n</html>\n";
}
# MethGet
# Return true if this cgi call was using the GET request, false otherwise
sub MethGet {
return ($ENV{'REQUEST_METHOD'} eq "GET"
}
# MethPost
# Return true if this cgi call was using the POST request, false otherwise
sub MethPost {
return ($ENV{'REQUEST_METHOD'} eq "POST"
}
# MyURL
# Returns a URL to the script
sub MyURL {
local ($port);
$port = ":" . $ENV{'SERVER_PORT'} if $ENV{'SERVER_PORT'} != 80;
return ' . $ENV{'SERVER_NAME'} . $port . $ENV{'SCRIPT_NAME'};
}
# CgiError
# Prints out an error message which which containes appropriate headers,
# markup, etcetera.
# Parameters:
# If no parameters, gives a generic error message
# Otherwise, the first parameter will be the title and the rest will
# be given as different paragraphs of the body
sub CgiError {
local (@msg) = @_;
local ($i,$name);
if (!@msg) {
$name = &MyURL;
@msg = ("Error: script $name encountered fatal error"
};
print &PrintHeader;
print "<html><head><title>$msg[0]</title></head>\n";
print "<body><h1>$msg[0]</h1>\n";
foreach $i (1 .. $#msg) {
print "<p>$msg[$i]</p>\n";
}
print "</body></html>\n";
}
# CgiDie
# Identical to CgiError, but also quits with the passed error message.
sub CgiDie {
local (@msg) = @_;
&CgiError (@msg);
die @msg;
}
# PrintVariables
# Nicely formats variables in an associative array passed as a parameter
# And returns the HTML string.
sub PrintVariables {
local (%in) = @_;
local ($old, $out, $output);
$old = $*; $* =1;
$output .= "\n<dl compact>\n";
foreach $key (sort keys(%in)) {
foreach (split("\0", $in{$key})) {
($out = $_) =~ s/\n/<br>\n/g;
$output .= "<dt><b>$key</b>\n <dd><i>$out</i><br>\n";
}
}
$output .= "</dl>\n";
$* = $old;
return $output;
}
# PrintVariablesShort
# Now obsolete; just calls PrintVariables
sub PrintVariablesShort {
return &PrintVariables(@_);
}
1; #return true ]