Technically, this is an Apache question, and not a Perl one. But if you must do it with Perl, here's something to get you started:

#!/usr/bin/perl -wT use CGI; use File::MimeInfo qw( mimetype ); use CGI::Carp qw( fatalsToBrowser ); #Of course, you'll want a more el +egant method # of error reporting than I use h +ere use constant FILES_DIR => "/path/to/files/"; my $cgi = new CGI; #Get the requested filename my $wanted_file = $cgi->param( "file" ); #my $wanted_file = $cgi->keywords; #Check if data is tainted - VERY IMPORTANT unless( $wanted_file =~ /\w{1}[\w-.]*\@[\w-.]+/ ) { #User tried to pass tainted data, e.g. "/etc/passwd" die( "Nice try, buddy." ); } #Check if that actually exists unless( -f FILES_DIR.$wanted_file" ) { die( "That file cannot be found." ); } #Check if the user is allowed to see that file #NOTE: Using cookies to store user id's is a bad idea. You # should use a session or a token of some sort. my $given_userid = $cgi->cookie( "user_id" ); my @allowed_people = get_an_array_of_allowed_people_from_somewhere(); unless( grep($given_userid, @allowed_userid) ) { die( "You are not allowed to see this file." ); } #Since we got here, we can give the user their file my $content_type = mimetype( FILES_DIR.$wanted_file ); open( FILE, "<", FILES_DIR.$wanted_file ) or die( "Cannot open file: $ +!" ); print $cgi->header( -type => $content_type ); print while <FILE>; close FILE;
~Thomas~
confess( "I offer no guarantees on my code." );

In reply to Re: Filter apache web get request using cgi-perl by thomas895
in thread Filter apache web get request using cgi-perl by cheekuperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.