On Sat, 2004-07-10 at 19:39, David Arnold wrote:

> I have a sequence of files (maybe 40) that I want to serve. Each file must
> be served no earlier than a certain time and no later than a certain time.
> Each of these time-day restrictions will be unique for each file.

> I am curious if the members of this group could suggest an authorization
> strategy in mod perl? I'm not looking for complete code, just general
> suggestions.

You're actually looking for access control, not authorization here (to
understand the difference read httpd.apache.org/docs/howto/auth.html).

 This exact problem is addressed in "Writing Apache Modules with C and
Perl" by Lincoln Stein and Doug MacEachern, the following example (6.2)
is copyright O'Reilly.

    package Apache::DayLimit;
    
    use strict;
    use Apache::Constants qw(:common);
    use Time::localtime;
    
    sub handler {
        my $r = shift;
    
        my @wday = qw(sunday monday tuesday wednesday 
                      thursday friday saturday);

    sub handler {
        my $r = shift;
        my $requires = $r->dir_config("ReqDay");
        return DECLINED unless $requires;

        my $day = $wday[localtime->wday];
        return OK if $requires =~ /day([,\s]+|$)/i;

        $r->log_reason( qq{Access forbidden on weekday "$day"},
                        $r->uri);
        return FORBIDDEN;
    }

    1;

  A <Location> section to go with Apache::DayLimit.

    <Location /weekends_only>
        PerlSetVar ReqDay saturday,sunday
        PerlAccessHandler Apche::DayLimit
    </Location>


That should give you a really good idea of how to use an Access Handler
(and the value of O'Reilly books on your bookshelf ;). The only caveat
here is that your mod_perl has to be compiled with the proper API hooks
in it.

As per your specific situation, adapting this to be clock time based
instead of day based should be trivial. If you don't want to have a
<File> or <Location> tag for each file (either in the main conf or
.htaccess) you might consider authenticating against a database. For
only 40 files though generating a .htacces skeleton with readir() might
be easiest.



-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Reply via email to