File:  [LON-CAPA] / loncom / auth / publiccheck.pm
Revision 1.12: download - view: text, annotated - select for diffs
Mon Dec 11 14:06:04 2006 UTC (17 years, 5 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_3_1, version_2_3_0, version_2_2_99_1, version_2_2_99_0, HEAD
Add response code of 'B' to lonnet::allowed() to indicate access to a file is currently subject to a block, because the file owner is part of a course with active communications blocking, and file viewer does not have 'evb' privilege in the course to nullify the block.

Used to block access to portfolio files.  Response of 'B' triggers blockedaccess.pm which displays information about blocking conditions.

    1: # The LearningOnline Network
    2: # Cookie Based Access Handler
    3: #
    4: # $Id: publiccheck.pm,v 1.12 2006/12/11 14:06:04 raeburn Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: ###
   29: 
   30: package Apache::publiccheck;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common :http :methods);
   34: use Apache::lonnet;
   35: use Apache::loncommon();
   36: use Apache::lonlocal;
   37: use CGI::Cookie();
   38: use Fcntl qw(:flock);
   39: use Apache::lonacc();
   40: 
   41: sub handler {
   42:     my $r = shift;
   43: 
   44:     my $requrl=$r->uri;
   45:     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
   46:     my $lonid=$cookies{'lonID'};
   47:     if ($lonid) {
   48: 	my $handle=&LONCAPA::clean_handle($lonid->value);
   49:         my $lonidsdir=$r->dir_config('lonIDsDir');
   50:         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
   51: 	    &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   52: 	    if ($env{'user.name'} ne 'public'
   53: 		&& $env{'user.domain'} ne 'public') {
   54: 		return OK;
   55: 	    }
   56: 	}
   57:     }
   58:     if ($requrl=~m|^/public/|
   59: 	|| $requrl=~m|^/adm/help/.*\.hlp$|
   60: 	|| $requrl=~m|^/adm/[^/]+/[^/]+/aboutme/portfolio$|
   61: 	|| (&Apache::lonnet::metadata($requrl,'copyright') eq 'public')) {
   62:         &process_public($r,$requrl);
   63:         return OK;
   64:     } elsif (&Apache::lonnet::is_portfolio_url($requrl)) {
   65: 	my (undef,$udom,$unum,$file_name,$group) = 
   66: 	    &Apache::lonnet::parse_portfolio_url($requrl);
   67:         my $access = &process_portfolio($udom,$unum,$file_name,$group);
   68:         if ($access) {
   69:             &process_public($r,$requrl,$access);
   70:             return OK;
   71:         } 
   72:     } elsif ($requrl eq '/adm/restrictedaccess') {
   73:         &process_public($r,$requrl);
   74: 	return OK;
   75:     } elsif ($requrl eq '/adm/blockedaccess') {
   76:        &process_public($r,$requrl);
   77:        return OK;
   78:     } 
   79:     return DECLINED;
   80: }
   81: 
   82: sub process_public {
   83:     my ($r,$requrl,$access) = @_;
   84:     &Apache::lonnet::logthis('Granting public access: '.$requrl);
   85:     if ($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public') {
   86:         my $cookie=&Apache::lonauth::success($r,'public','public','public');
   87:         my $lonidsdir=$r->dir_config('lonIDsDir');
   88:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$cookie);
   89: 	$r->err_header_out('Set-cookie',"lonID=$cookie; path=/");
   90:     }
   91:     &Apache::lonacc::get_posted_cgi($r);
   92:     $env{'request.state'} = "published";
   93:     $env{'request.publicaccess'} = 1;
   94:     $env{'request.filename'} = $r->filename;
   95:     return;
   96: }
   97: 
   98: sub process_portfolio {
   99:     my ($udom,$unum,$file_name,$group) = @_;
  100:     my $current_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum);
  101:     my %access_controls = &Apache::lonnet::get_access_controls($current_perms,$group,$file_name);
  102:     my $access = '';
  103:     my $now = time;
  104:     foreach my $key (keys(%{$access_controls{$file_name}})) {
  105:         my ($num,$scope,$end,$start) = ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
  106:         if ($start > $now) {
  107:             next;
  108:         }
  109:         if ($end && $end<$now) {
  110:             next;
  111:         }
  112:         if ($scope eq 'public') {
  113:             $access = 'public';
  114:             last;
  115:         }
  116:         if ($scope eq 'guest') {
  117:             $access = 'guest';
  118:         }
  119:     }
  120:     return $access;
  121: }
  122: 
  123: 1;
  124: 
  125: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>