Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ASP

Problem with PDF files

 

 

ModPerl asp RSS feed   Index | Next | Previous | View Threaded


dixonjon at lycos

Apr 23, 2005, 6:59 PM

Post #1 of 5 (2956 views)
Permalink
Problem with PDF files

I am running a website where I want to control access to the various files. I have the directory setup in httpd.conf with:

<Files ~ (\.asp)>
SetHandler perl-script
PerlHandler Apache::ASP
PerlSetVar Global /storage/t212
PerlSetVar StateDir /tmp/asp
PerlSetVar RequestBinaryRead On
</Files>
<Files ~ (\.html)>
SetHandler perl-script
PerlHandler Apache::ASP
PerlSetVar Global /storage/t212
PerlSetVar StateDir /tmp/asp
PerlSetVar RequestBinaryRead On
</Files>
<Files ~ (\.doc)>
SetHandler perl-script
PerlHandler Apache::ASP
PerlSetVar Global /storage/t212
PerlSetVar StateDir /tmp/asp
PerlSetVar RequestBinaryRead On
</Files>
<Files ~ (\.pdf)>
SetHandler perl-script
PerlHandler Apache::ASP
PerlSetVar Global /storage/t212
PerlSetVar StateDir /tmp/asp
PerlSetVar RequestBinaryRead On
</Files>

and the global.asa file that includes:

sub Script_OnStart {
$Basename = basename($0);
$Basename = 'index.asp' unless $Basename;
$Logged = $Session->{"Logged"};

$Response->Redirect("Login.asp")
unless ($Logged or $Basename eq 'Login.asp');

if ($Request->Form('logout')) {
$Session->Abandon();
$Response->Redirect("Login.asp");
}

if ($Basename =~ /\.css$/) {
$Response->{ContentType} = 'text/css';
open(FILE, $Basename) or die "File not found";
my $temp = $/;
$/ = undef;
my $data = <FILE>;
$Response->Clear;
$Response->AddHeader('Content-Length', length $data);
$Response->Write($data);
$/ = $temp;
$Response->End;
}

if ($Basename =~ /\.doc$/) {
$Response->{ContentType} = 'application/msword';
open(FILE, $Basename) or die "File not found: $Basename";
binmode FILE;
my $temp = $/;
$/ = undef;
my $data = <FILE>;
$Response->Clear;
$Response->AddHeader('Content-Length', length $data);
$Response->BinaryWrite($data);
$/ = $temp;
$Response->End;
}
if ($Basename =~ /\.pdf$/i) {
$Response->{ContentType} = 'application/pdf';
open(FILE, $Basename) or die "File not found: $Basename";
binmode FILE;
my $temp = $/;
$/ = undef;
my $data = <FILE>;
$Response->Clear;
$Response->AddHeader('Content-Length', length $data);
$Response->BinaryWrite($data);
$/ = $temp;
$Response->End;
}
if ($Basename =~ /\.html$/) {
$Response->{ContentType} = 'text/html';
open(FILE, $Basename) or die "File not found";
my $data = <FILE>;
$Response->Clear;
$Response->AddHeader('Content-Length', length $data);
$Response->Write($data);
$Response->End;
}

$Title = "$Name " . $Titles{$Basename};
$Response->Include('header.inc');

if ($Logged) {
$Admin = $Session->{Admin};
$User = $Session->{User};
$UniqueID = $Session->{UID};
$Perm = $Session->{Perm};
my $Hash = $Session->{Hash};
my $junk = $UniqueID . $User . $Perm;
unless ($Hash == crypt($junk,$Hash)) {
$Session->{"Logged"} = 0;
$Response->Redirect("Login.asp");
}
}
}


This works well for the .doc, .css, .html, and .asp files, but the pdf files always crash with an error along the lines of:
[error] error compiling blah.pdf: Unrecognized character \\xF9 at (eval 37) line 265. <--> , /usr/lib/perl5/site_perl/5.8.3/Apache/ASP.pm line 1462

In fact, even if I change the global.asa script to die at the beginning of Script_OnStart, I still get the same error for PDF files (unlike the other file types, where I get the error from the die command). This indicates to me that the PDF file is getting processed somehow differently from the other file types.

What am I overlooking here? How do I get my site to follow the global.asa directives for the PDF file just the same as it does for the DOC files?

Thanks,

Jon Dixon
dixonjon [at] lycos
http://dixonjon.tripod.com/
--
_______________________________________________
NEW! Lycos Dating Search. The only place to search multiple dating sites at once.
http://datingsearch.lycos.com


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


warren at etr-usa

Apr 25, 2005, 5:04 AM

Post #2 of 5 (2769 views)
Permalink
Re: Problem with PDF files [In reply to]

Jonathan Dixon wrote:

> <Files ~ (\.pdf)>
> SetHandler perl-script
> PerlHandler Apache::ASP
> PerlSetVar Global /storage/t212
> PerlSetVar StateDir /tmp/asp
> PerlSetVar RequestBinaryRead On
> </Files>

This declares *.pdf files as being ASP files. Apache::ASP is trying to
interpret them directly!

What you want to do cannot be accomplished with this mechanism. Try
looking at the various Apache modules.

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


dixonjon at lycos

Apr 25, 2005, 11:12 AM

Post #3 of 5 (2767 views)
Permalink
Re: Problem with PDF files [In reply to]

> This declares *.pdf files as being ASP files. Apache::ASP is trying to
> interpret them directly!
>
> What you want to do cannot be accomplished with this mechanism. Try looking
> at the various Apache modules.

I understand that this forces the PDF files to be handled through Apache::ASP. But shouldn't the Script_OnStart section in the global.asa file short-circuit the processing of the file itself and send it out as a straight binary file? This is what seems to happen for the Word files in the directory that are treated the same way.

Do you (or anyone else) have suggestions for modules to look at that can check for a valid ASP session before allowing access to files on the server?

Thanks,

Jon Dixon
dixonjon [at] lycos
http://dixonjon.tripod.com/


--
_______________________________________________
NEW! Lycos Dating Search. The only place to search multiple dating sites at once.
http://datingsearch.lycos.com


---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


mfr at bmx-chemnitz

Apr 26, 2005, 12:48 AM

Post #4 of 5 (2752 views)
Permalink
Re: Problem with PDF files [In reply to]

Jonathan Dixon wrote:

>> This declares *.pdf files as being ASP files. Apache::ASP is
>> trying to interpret them directly!
>>
>> What you want to do cannot be accomplished with this mechanism.
>> Try looking at the various Apache modules.
>
> I understand that this forces the PDF files to be handled through
> Apache::ASP. But shouldn't the Script_OnStart section in the
> global.asa file short-circuit the processing of the file itself and
> send it out as a straight binary file? This is what seems to happen
> for the Word files in the directory that are treated the same way.
>
> Do you (or anyone else) have suggestions for modules to look at that
> can check for a valid ASP session before allowing access to files on
> the server?

I would attempt this a bit differently. Instead of referencing the file
directly and inject the code voodoo-like, how about you use a dedicated
download script, hide it behind a plain name of download with the
handler settings and then use $PATHINFO to get to the requested file,
which can then be located elsewhere, too.

This is how this would look for the user:
http://foo.bar/download/file.ext

where download is the name for your download script which then gets
"file.ext" (or "/file.ext", I am unsure right now) as $PATHINFO which
you can then use to retrieve the file from the real location to which
you can apply more restrictive access rights, too, as additional benefit.

regards,
Marko

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl


josh at chamas

May 23, 2005, 11:04 PM

Post #5 of 5 (2729 views)
Permalink
Re: Problem with PDF files [In reply to]

Jonathan Dixon wrote:
> I am running a website where I want to control access to the various files. I have the directory setup in httpd.conf with:
...
>
> This works well for the .doc, .css, .html, and .asp files, but the pdf files always crash with an error along the lines of:
> [error] error compiling blah.pdf: Unrecognized character \\xF9 at (eval 37) line 265. <--> , /usr/lib/perl5/site_perl/5.8.3/Apache/ASP.pm line 1462
>
> In fact, even if I change the global.asa script to die at the beginning of Script_OnStart, I still get the same error for PDF files (unlike the other file types, where I get the error from the die command). This indicates to me that the PDF file is getting processed somehow differently from the other file types.
>
> What am I overlooking here? How do I get my site to follow the global.asa directives for the PDF file just the same as it does for the DOC files?
>

The others gave you great work arounds. If you really had to make this work, you might
try using the Script_OnParse event instead of Script_OnStart. Script_OnStart occurs
after the script has been compiled, but just before execution. With Script_OnParse,
you might rewrite the script to do something like a read/binary write of the file
you are dealing with.

Regards,

Josh

---------------------------------------------------------------------
To unsubscribe, e-mail: asp-unsubscribe [at] perl
For additional commands, e-mail: asp-help [at] perl

ModPerl asp RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.