#!/usr/bin/perl # # This perl CGI script enables document distribution using SwiftView(R) # SwiftView, Inc. # # It works around IE POST bugs by responding to a POST with an HTML page that # contains an EMBED that in turn fetches the actual file with a GET query. # # flush stdout buffer $| = 1; # # Debugging: open(perllog, ">>/tmp/perllog"); while (($key,$value) = each %ENV) { print perllog "\t$key=$value\n"; } if ($ENV{'HTTP_USER_AGENT'} eq 'contype') { # IE POST workaround: IE sends three requests, 1/2 need only return # mime, second needs only content type, sends content type = "contype", # and has a 10 second timeout. # IE5.5, 4.6.00: POST now is sometimes followed by two GETS, the first one # is "contype". print "Content-type: text/html\n\n"; print perllog "got contype, return just Content-type\n"; exit 0; } # check for the POST method - used for forms if ($ENV{'REQUEST_METHOD'} eq 'POST') { # How many bytes are we supposed to receive? read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); # make a list of keyword/value pairs @pairs = split(/&/, $buffer); # cycle through each pair and decipher the values foreach $pair (@pairs) { # get the name/value pair strings ($name, $value) = split(/=/, $pair); # translate "+" to a space $value =~ tr/+/ /; # decipher ASCII hexidecimal escaped characters, if any $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; # add the pair to a list keyed on the name of the variable $contents{$name} = $value; print perllog "$name=$value "; } } # check for the GET method - used for links # Could optmize here, and return the document directly, byassing the IE/POST # workaround. if ($ENV{REQUEST_METHOD} eq 'GET' && $ENV{QUERY_STRING} ne '') { # split the query string into an array of keywords foreach $widget (split("&", $ENV{QUERY_STRING})) { # get the keyword and value pair from the widget string if ($widget =~ /(.*)=(.*)/) { ($key, $value) = ($1, $2); $value =~ s/\+/ /g ; # replace "+" with " " # unescape ASCII hexadecimal characters $value =~ s/%(..)/pack('c',hex($1))/eg; $contents{$key} = $value; # add keyword/value pair to a list } } } print perllog "\n"; # The server-side filename is now in the name variable. # no-file error handled by GET for EMBED. # A real database application has more to do here: the POST query must be done # in this script, and the data saved in a file that will be deleted by the # second script when it completes returning the data. print "Content-type: text/html\n\n"; print ""; print ""; print "
"; print ""; print "