File:  [LON-CAPA] / loncom / auth / publiccheck.pm
Revision 1.3: download - view: text, annotated - select for diffs
Fri Jun 16 22:37:29 2006 UTC (18 years ago) by raeburn
Branches: MAIN
CVS tags: HEAD
Enable users to set access controls on portfolio files to permit public viewing. Third iteration of data structure in file_permissions.db for storage of access contol records. Now uses key = value for individual access control records and a key = anonymous hash for fast look-ups of all records for a single file.   Use of a temporary lock record to prevent others modifying access control records for a specific portfolio file while the record for the same file is being updated. Additional argument added to call to lonhtmlcommon::datesetter() to optionally suppress display of calendar link.

    1: # The LearningOnline Network
    2: # Cookie Based Access Handler
    3: #
    4: # $Id: publiccheck.pm,v 1.3 2006/06/16 22:37:29 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:     my $requrl=$r->uri;
   44:     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
   45:     my $lonid=$cookies{'lonID'};
   46:     if ($lonid) {
   47: 	my $handle=$lonid->value;
   48:         $handle=~s/\W//g;
   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: 	|| (&Apache::lonnet::metadata($requrl,'copyright') eq 'public')) {
   60:         &process_public($r,$requrl);
   61:         return OK;
   62:     } elsif ($requrl =~ m#/+uploaded/([^/]+)/([^/]+)/portfolio(/.+)$#) {
   63:         if (&process_portfolio($1,$2,$3)) {
   64:             &process_public($r,$requrl);
   65:             return OK;
   66:         } 
   67:     } elsif ($requrl =~ m#/+uploaded/([^/]+)/([^/]+)/groups/([^/]+)/portfolio/(.+)$#) {
   68:         if (&process_portfolio($1,$2,$3.'/'.$4,$3)) {
   69:             &process_public($r,$requrl);
   70:             return OK;
   71:         }
   72:     }
   73:     return DECLINED;
   74: }
   75: 
   76: sub process_public {
   77:     my ($r,$requrl) = @_;
   78:     &Apache::lonnet::logthis('Granting public access: '.$requrl);
   79:     if ($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public') {
   80:         my $cookie=&Apache::lonauth::success($r,'public','public','public');
   81:         my $lonidsdir=$r->dir_config('lonIDsDir');
   82:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$cookie);
   83:         $r->header_out('Set-cookie',"lonID=$cookie; path=/");
   84:     }
   85:     &Apache::lonacc::get_posted_cgi($r);
   86:     $env{'request.state'} = "published";
   87:     $env{'request.publicaccess'} = 1;
   88:     $env{'request.filename'} = $r->filename;
   89:     return;
   90: }
   91: 
   92: sub process_portfolio {
   93:     my ($udom,$unum,$file_name,$group) = @_;
   94:     my $current_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum);
   95:     my %access_controls = &Apache::lonnet::get_access_controls($current_perms,$group,$file_name);
   96:     my $public_access = 0;
   97:     my $now = time;
   98:     foreach my $key (keys(%{$access_controls{$file_name}})) {
   99:         my ($num,$scope,$end,$start) = ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
  100:         if ($start > $now) {
  101:             next;
  102:         }
  103:         if ($end && $end<$now) {
  104:             next;
  105:         }
  106:         if ($scope eq 'public') {
  107:             $public_access = 1;
  108:             last;
  109:         }
  110:     }
  111:     return $public_access;
  112: }
  113: 
  114: 1;
  115: 
  116: __END__

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