#!/usr/bin/perl # # This perl CGI script enables document distribution using SwiftView(R) # SwiftView, Inc. # # flush stdout buffer $| = 1; # # MIME type = any type defined for SwiftView(R) Plug-in so that # browsers starts it. SwiftView looks in the file itself so # this can be one MIME type for all returned files. # Don't send type until we know if we need to send status - we must # send status, else SwiftView will count http://foo.001 files forever. # # Debugging: $Debug = 1; if ($Debug) { 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: application/vnd.SwiftView-ICS\n\n"; if ($Debug) { 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; if ($Debug) { print perllog "$Name=$Value "; } } } # check for the GET method - used for links 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 } } } if ($Debug) { print perllog "\n"; } # The server-side filename is now in the name variable # Require all paths be relative to DOCUMENT_ROOT $DOCUMENT_ROOT = $ENV{'DOCUMENT_ROOT'}; if ($DOCUMENT_ROOT eq '') { # fallback for most servers, many do not have DOCUEMENT_ROOT. $DOCUMENT_ROOT = $ENV{'PATH_TRANSLATED'}; } if (!open(datafile, "$DOCUMENT_ROOT/$Contents{'name'}")) { # print "HTTP/1.0 404 Not Found\n"; print "Content-type: application/vnd.SwiftView-ICS\n\n"; print "Could not open file \"", $Contents{'name'}, "\"\n"; print "QUERY_STRING = \"", $ENV{'QUERY_STRING'}, "\"\n"; print "CONTENT_LENGTH = \"", $ENV{'CONTENT_LENGTH'}, "\"\n"; print "content = \"", $Buffer, "\"\n"; exit 1; } print "Content-type: application/vnd.SwiftView-ICS\n\n"; while() { print; }