--- loncom/auth/lonacc.pm 2006/06/16 22:37:29 1.79 +++ loncom/auth/lonacc.pm 2006/07/21 18:52:32 1.89 @@ -1,7 +1,7 @@ # The LearningOnline Network # Cookie Based Access Handler # -# $Id: lonacc.pm,v 1.79 2006/06/16 22:37:29 raeburn Exp $ +# $Id: lonacc.pm,v 1.89 2006/07/21 18:52:32 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,8 +35,10 @@ use Apache::File; use Apache::lonnet; use Apache::loncommon(); use Apache::lonlocal; +use Apache::restrictedaccess(); use CGI::Cookie(); use Fcntl qw(:flock); +use LONCAPA; sub cleanup { my ($r)=@_; @@ -135,32 +137,20 @@ sub get_posted_cgi { $r->headers_in->unset('Content-length'); } -sub portfolio_access { - my ($udom,$unum,$file_name,$group) = @_; - my $current_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum); - my %access_controls = &Apache::lonnet::get_access_controls( - $current_perms,$group,$file_name); - my ($public); - my $now = time; - my $access_hash = $access_controls{$file_name}; - if (ref($access_hash) eq 'HASH') { - foreach my $key (keys(%{$access_hash})) { - my ($num,$scope,$end,$start) = ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/); - if ($start > $now) { - next; +sub passphrase_access_checker { + my ($r,$guestkey,$requrl) = @_; + my ($num,$scope,$end,$start) = ($guestkey =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/); + if ($scope eq 'guest') { + if (exists($env{'user.passphrase_access_'.$requrl})) { + if (($env{'user.passphrase_access_'.$requrl} == 0) || + ($env{'user.passphrase_access_'.$requrl} > time)) { + $env{'request.publicaccess'} = 1; + return 'ok'; } - if ($end && $end<$now) { - next; - } - if ($scope eq 'public') { - $public = $key; - last; - } - } - if ($public) { - return 'ok'; } } + $r->set_handlers('PerlHandler'=> \&Apache::restrictedaccess::handler); + $r->content_type('perl-script'); return; } @@ -226,17 +216,10 @@ sub handler { # ---------------------------------------------------------------- Check access my $now = time; - if ($requrl =~ m#/+uploaded/([^/]+)/([^/]+)/portfolio(/.+)$#) { - my $result = &portfolio_access($1,$2,$3); - if ($result eq 'ok') { - return OK; - } - } elsif ($requrl =~ m#/+uploaded/([^/]+)/([^/]+)/groups/([^/]+)/portfolio/(.+)$#) { - my $result = &portfolio_access($1,$2,$4.'/'.$3,$3); - if ($result eq 'ok') { - return OK; - } - } + if (&Apache::lonnet::is_portfolio_url($requrl)) { + my $result = &Apache::lonnet::portfolio_access($r,$requrl); + if ($result eq 'ok') { return OK; } + } if ($requrl!~/^\/adm|public|prtspool\//) { my $access=&Apache::lonnet::allowed('bre',$requrl); if ($access eq '1') { @@ -259,7 +242,7 @@ sub handler { if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public' && $requrl !~ m{^/+(res|public)/} && - $requrl !~ m{^/+adm/(help|logout|randomlabel\.png)}) { + $requrl !~ m{^/+adm/(help|logout|restrictedaccess|randomlabel\.png)}) { $env{'request.querystring'}=$r->args; $env{'request.firsturl'}=$requrl; return FORBIDDEN; @@ -327,7 +310,7 @@ sub handler { } else { $r->log_reason("Cookie $handle not valid", $r->filename); } - } + } # -------------------------------------------- See if this is a public resource if ($requrl=~m|^/public/| @@ -347,20 +330,14 @@ sub handler { return OK; } if ($requrl=~m|^/+adm/+help/+|) { - return OK; + return OK; } # ------------------------------------- See if this is a viewable portfolio file - if ($requrl =~ m#/+uploaded/([^/]+)/([^/]+)/portfolio(/.+)$#) { - my $result = &portfolio_access($1,$2,$3); - if ($result eq 'ok') { - return OK; - } - } elsif ($requrl =~ m#/+uploaded/([^/]+)/([^/]+)/groups/([^/]+)/portfolio/(.+)$#) { - my $result = &portfolio_access($1,$2,$4.'/'.$3,$3); - if ($result eq 'ok') { - return OK; - } + if (&Apache::lonnet::is_portfolio_url($requrl)) { + my $result = &Apache::lonnet::portfolio_access($r,$requrl); + if ($result eq 'ok' ) { return OK; } } + # -------------------------------------------------------------- Not authorized $requrl=~/\.(\w+)$/; # if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||