#!/usr/bin/perl # ODP::Passport - passport-static - A wrapper for Apache for protecting static files/pages (Version 0.01) # Copyright (C)2002 Richard P. Fuller # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # Values you should change as necessary: my $global_secret = 'your secret'; my $global_toolcollection = 'your tool collection'; my $global_mimetypespath = '/etc/apache/mime.types'; my $global_godirect = 1; my $ppconfig = ''; # Leave everything below here well alone if you don't know what you're doing use CGI qw(:standard); use ODP::Passport; use URI::Escape; if (!$ENV{'PATH_INFO'}) { $ENV{'PATH_INFO'} = 'this file'; &permission_denied(); } my $client = new ODP::Passport; $client -> checklogin($global_secret,$global_toolcollection,"ppstatic:".uri_escape($ENV{'PATH_INFO'}),$global_godirect,$ppconfig); if (!-e $ENV{'PATH_TRANSLATED'}){&filenotfound()} open (IN,$ENV{'PATH_TRANSLATED'}) || &permission_denied(); my $extension; if ($ENV{'PATH_INFO'} =~ /\.([^\.]+)$/) { $extension = $1; } my $type = &gettype($extension); print "Content-Type: $type\n\n"; while() { print; } close IN; sub permission_denied() { print < 403 Forbidden

Forbidden

You don't have permission to access $ENV{'PATH_INFO'} on this server.


$ENV{'SERVER_SIGNATURE'} END_HTML exit; } sub filenotfound() { print < 404 Not Found

Not Found

The requested URL $ENV{'PATH_INFO'} was not found on this server.


$ENV{'SERVER_SIGNATURE'} END_HTML exit; } sub gettype($) { my $ourtype = $_[0]; my %extensions; open(M,$global_mimetypespath); while () { chomp; my ($type, $extensions)=split(/\t/); foreach my $ext (split(/ /, $extensions)) { $extensions{$ext} = $type; } } return $extensions{$ourtype}; }