--- loncom/auth/lonacc.pm 2006/06/16 22:37:29 1.79 +++ loncom/auth/lonacc.pm 2006/07/21 19:42:12 1.90 @@ -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.90 2006/07/21 19:42:12 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,35 +137,6 @@ 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; - } - if ($end && $end<$now) { - next; - } - if ($scope eq 'public') { - $public = $key; - last; - } - } - if ($public) { - return 'ok'; - } - } - return; -} - sub handler { my $r = shift; my $requrl=$r->uri; @@ -226,23 +199,16 @@ 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 ($requrl!~/^\/adm|public|prtspool\//) { my $access=&Apache::lonnet::allowed('bre',$requrl); if ($access eq '1') { $env{'user.error.msg'}="$requrl:bre:0:0:Choose Course"; return HTTP_NOT_ACCEPTABLE; } + if ($access eq 'A') { + &Apache::restrictedaccess::setup_handler($r); + return OK; + } if (($access ne '2') && ($access ne 'F')) { $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied"; return HTTP_NOT_ACCEPTABLE; @@ -258,8 +224,8 @@ 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{^/+(res|public|uploaded)/} && + $requrl !~ m{^/+adm/(help|logout|restrictedaccess|randomlabel\.png)}) { $env{'request.querystring'}=$r->args; $env{'request.firsturl'}=$requrl; return FORBIDDEN; @@ -327,7 +293,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 +313,21 @@ 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; - } +# ------------------------------------ See if this is a viewable portfolio file + if (&Apache::lonnet::is_portfolio_url($requrl)) { + my $access=&Apache::lonnet::allowed('bre',$requrl); + if ($access eq 'A') { + &Apache::restrictedaccess::setup_handler($r); + return OK; + } + if (($access ne '2') && ($access ne 'F')) { + $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied"; + return HTTP_NOT_ACCEPTABLE; + } } + # -------------------------------------------------------------- Not authorized $requrl=~/\.(\w+)$/; # if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||