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 >
Text File  |  2017-09-21  |  2KB  |  94 lines

  1. #
  2. #  file: cgi-lib.pl
  3. #
  4. #  auth: Brad Burdick
  5. #  desc: This library deals with basic CGI POST or GET method request
  6. #        elements such as those delivered by an HTTPD form, i.e. a url
  7. #        encoded line:  a=b&b=c&c=d
  8. #
  9. #        Also handles <ISINDEX> GET requests.
  10. #
  11. #           Needs a 'require "cgi-lib.pl";' line in the main script
  12. #
  13.  
  14. #
  15. # parse_request reads the POST or GET request from STDIN, and then splits
  16. # it into its name=value pairs.  Special test for <ISINDEX> input.
  17. #
  18. sub parse_request {
  19.  
  20.     if ($ENV{'REQUEST_METHOD'} eq "POST") {
  21.         # assumes read gets everything!!
  22.         read(STDIN, $raw_query, $ENV{'CONTENT_LENGTH'});
  23.     } elsif ($ENV{'REQUEST_METHOD'} eq "GET" ) {
  24.         $raw_query = $ENV{'QUERY_STRING'};
  25.     } else {
  26.         # unrecognized request method
  27.         return;
  28.     }
  29.  
  30.     # Decode HEX values and spaces, if any
  31.     if ($raw_query !~ /[&=]/) {  # handle <ISINDEX> input
  32.         $isindex = $raw_query;
  33.         &decode_url($isindex);
  34.     } else {
  35.         %query = &decode_url(split(/[&=]/, $raw_query));
  36.     }
  37. }
  38.  
  39. #
  40. #    Decode a URL encoded string or array of strings 
  41. #        + -> space
  42. #        %xx -> character xx
  43. #
  44. sub decode_url {
  45.     foreach (@_) {
  46.         tr/+/ /;
  47.         s/%(..)/pack("c",hex($1))/ge;
  48.     }
  49.     @_;
  50. }
  51.  
  52. #
  53. # html_header sends an HTML header for the document to be returned
  54. #
  55. sub html_header {
  56.     local($title) = shift;
  57.  
  58.     print "Content-type: text/html\n\n";
  59.     print "<html><head>\n";
  60.     print "<title>$title</title>\n";
  61.     print "</head>\n";
  62.     print "<body>\n";
  63. }
  64.  
  65. #
  66. # html_trailer sends the HTML trailing material to STDOUT.
  67. #
  68. sub html_trailer {
  69.     local($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) =
  70.         localtime;
  71.     local(@days) = ('Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday',
  72.         'Friday', 'Saturday');
  73.     local(@months) = ('January', 'February', 'March', 'April', 'May', 'June',
  74.         'July', 'August', 'September', 'October', 'November', 'December');
  75.  
  76. #    print "<p>\nGenerated by the ";
  77. #    print "<a href=\"/\">Internet Multicasting Service</a>";
  78. #    print " at ", sprintf("%02d:%02d:%02d %s on %s %d, %d", $hour, $min, $sec,
  79. #        ($isdst>0 ? "EDT" : "EST"), $months[$mon], $mday, 1900+$year);
  80.  
  81.     print "<p>\n";
  82.     print "<ul>\n";
  83.     print "<li><a href=\"http://park.org/cgi-bin/form-mail\">Comments or suggestions to Fairmaster</a>\n";
  84.     print "<li><a href=\"http://park.org/\">Home Page\n";  
  85.     print "</ul>\n";
  86.  
  87.     print "<hr>\n";
  88.     print "</body></html>\n";
  89. }
  90.  
  91. # keep require happy
  92. 1;
  93.  
  94.