home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Internet 1996 World Exposition
/
park.org.s3.amazonaws.com.7z
/
park.org.s3.amazonaws.com
/
cgi-bin
/
cgi-lib.pl-
< prev
next >
Wrap
Text File
|
2017-09-21
|
2KB
|
94 lines
#
# file: cgi-lib.pl
#
# auth: Brad Burdick
# desc: This library deals with basic CGI POST or GET method request
# elements such as those delivered by an HTTPD form, i.e. a url
# encoded line: a=b&b=c&c=d
#
# Also handles <ISINDEX> GET requests.
#
# Needs a 'require "cgi-lib.pl";' line in the main script
#
#
# parse_request reads the POST or GET request from STDIN, and then splits
# it into its name=value pairs. Special test for <ISINDEX> input.
#
sub parse_request {
if ($ENV{'REQUEST_METHOD'} eq "POST") {
# assumes read gets everything!!
read(STDIN, $raw_query, $ENV{'CONTENT_LENGTH'});
} elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) {
$raw_query = $ENV{'QUERY_STRING'};
} else {
# unrecognized request method
return;
}
# Decode HEX values and spaces, if any
if ($raw_query !~ /[&=]/) { # handle <ISINDEX> input
$isindex = $raw_query;
&decode_url($isindex);
} else {
%query = &decode_url(split(/[&=]/, $raw_query));
}
}
#
# Decode a URL encoded string or array of strings
# + -> space
# %xx -> character xx
#
sub decode_url {
foreach (@_) {
tr/+/ /;
s/%(..)/pack("c",hex($1))/ge;
}
@_;
}
#
# html_header sends an HTML header for the document to be returned
#
sub html_header {
local($title) = shift;
print "Content-type: text/html\n\n";
print "<html><head>\n";
print "<title>$title</title>\n";
print "</head>\n";
print "<body>\n";
}
#
# html_trailer sends the HTML trailing material to STDOUT.
#
sub html_trailer {
local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
localtime;
local(@days) = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
'Friday', 'Saturday');
local(@months) = ('January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December');
# print "<p>\nGenerated by the ";
# print "<a href=\"/\">Internet Multicasting Service</a>";
# print " at ", sprintf("%02d:%02d:%02d %s on %s %d, %d", $hour, $min, $sec,
# ($isdst>0 ? "EDT" : "EST"), $months[$mon], $mday, 1900+$year);
print "<p>\n";
print "<ul>\n";
print "<li><a href=\"http://park.org/cgi-bin/form-mail\">Comments or suggestions to Fairmaster</a>\n";
print "<li><a href=\"http://park.org/\">Home Page\n";
print "</ul>\n";
print "<hr>\n";
print "</body></html>\n";
}
# keep require happy
1;