#!/usr/bin/perl # # @(#)pack200 0.1 2007-06-03 # # Copyright (c) 2007 by AnyWikiDraw.org and all its contributors. # All rights reserved. # # This software is the confidential and proprietary information of # AnyWikiDraw.org ("Confidential Information"). You shall not disclose # such Confidential Information and shall use it only in accordance # with the terms of the license agreement you entered into with # AnyWikiDraw.org. # # This script delivers a Java Applet that is compressed with pack200-gzip or # with gzip. # # This script expects that all Jar files of the Java Applet are supplied in # three files with the following extensions: # - .jar # - .jar.pack.gz # - .jar.gz # # This script is based on the pack200 deployment guide: # http://java.sun.com/j2se/1.5.0/docs/guide/deployment/deployment-guide/pack200.html # use CGI qw(:standard); use File::Basename; $acceptEncoding = $ENV{'HTTP_ACCEPT_ENCODING'}; $pathInfo = $ENV{'PATH_INFO'}; # For security reason, we only deliver files with the extension .jar if (substr($pathInfo, length($pathInf) -4) != '.jar') { print header(-status=>'404 Not Found'); exit; } # Strip all leading points, slashes, and backslashes from pathInfo $pathInfo =~ s/^[.\/\\\\]//go; # Strip all multi point sequences from pathInfo $pathInfo =~ s/\.\.//go; # $pathInfo = dirname(dirname($ENV{'SCRIPT_FILENAME'})).'/'.$pathInfo; @acceptEncodings = split(/,/, lc($acceptEncoding)); for (@acceptEncodings) { $isAcceptEncoding{$_} = 1; } if ($isAcceptEncoding{'pack200-gzip'} && -e($pathInfo.'.pack.gz')) { deliverFile($pathInfo.'.pack.gz', 'pack200-gzip'); } elsif ($isAcceptEncoding{'gzip'} && -e($pathInfo.'.gz')) { deliverFile($pathInfo.'.gz', 'gzip'); } else { deliverFile($pathInfo, null); } # # Deliver the file. # sub deliverFile { my( $file, $contentEncoding ) = @_; if (-e($file)) { if ($contentEncoding != null) { print header(-status=>'200 OK', -Content_Type=>'application/x-java-archive', -Content_Length=>(-s $file), -Content_Encoding=>$contentEncoding ); } else { print header(-status=>'200 OK', -Content_Type=>'application/x-java-archive', -Content_Length=>(-s $file) ); } open(filehandle, $file); binmode(filehandle); print ; close (filehandle); } else { print header(-status=>'404 Not Found'); #foreach $key (sort keys(%ENV)) { # print "$key = $ENV{$key}

"; #} print p($file); } exit; }