File:  [LON-CAPA] / loncom / auth / publiccheck.pm
Revision 1.21: download - view: text, annotated - select for diffs
Fri Feb 8 16:23:56 2013 UTC (11 years, 3 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_11_0_RC1, HEAD
- Setting of $r->user() not required prior to Apache 2.4.

    1: # The LearningOnline Network
    2: # Cookie Based Access Handler
    3: #
    4: # $Id: publiccheck.pm,v 1.21 2013/02/08 16:23:56 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 Fcntl qw(:flock);
   38: use Apache::lonacc();
   39: use LONCAPA();
   40: 
   41: sub handler {
   42:     my $r = shift;
   43: 
   44:     my $requrl=$r->uri;
   45: 
   46:     if (&Apache::lonnet::is_domainimage($requrl)) {
   47:         if (($r->user() eq '') && ($Apache::lonnet::apache >= 2.4)) {
   48:             $r->user('public');
   49:         }
   50:         return OK;
   51:     }
   52: 
   53:     if ($requrl =~ m{^/res/adm/pages/[^/]+\.(gif|png)$}) {
   54:         if (($r->user() eq '') && ($Apache::lonnet::apache >= 2.4)) {
   55:             $r->user('public');
   56:         }
   57:         return OK;
   58:     }
   59: 
   60:     my $handle = &Apache::lonnet::check_for_valid_session($r);
   61:     if ($handle ne '') {
   62:         my $lonidsdir=$r->dir_config('lonIDsDir');
   63: 	&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   64: 	if ($env{'user.name'} ne 'public'
   65: 	    && $env{'user.domain'} ne 'public') {
   66: 	    return OK;
   67: 	}
   68:     }
   69:     if ($requrl=~m|^/public/|
   70: 	|| $requrl=~m|^/adm/help/.*\.hlp$|
   71: 	|| $requrl=~m|^/adm/[^/]+/[^/]+/aboutme/portfolio$|
   72: 	|| (&Apache::lonnet::metadata($requrl,'copyright') eq 'public') 
   73:     || $requrl=~m|^/adm/blockingstatus/.*$|) { 
   74:         &process_public($r,$requrl);
   75:         return OK;
   76:     } elsif (&Apache::lonnet::is_portfolio_url($requrl)) {
   77: 	my (undef,$udom,$unum,$file_name,$group) = 
   78: 	    &Apache::lonnet::parse_portfolio_url($requrl);
   79:         my $access = &process_portfolio($udom,$unum,$file_name,$group);
   80:         if ($access) {
   81:             &process_public($r,$requrl,$access);
   82:             return OK;
   83:         } 
   84:     } elsif ($requrl eq '/adm/restrictedaccess') {
   85:         &process_public($r,$requrl);
   86: 	return OK;
   87:     } elsif ($requrl eq '/adm/blockedaccess') {
   88:        &process_public($r,$requrl);
   89:        return OK;
   90:     }
   91:     return DECLINED;
   92: }
   93: 
   94: sub process_public {
   95:     my ($r,$requrl,$access) = @_;
   96:     &Apache::lonnet::logthis('Granting public access: '.$requrl);
   97:     if ($env{'user.name'} ne 'public' && $env{'user.domain'} ne 'public') {
   98:         my $cookie=&Apache::lonauth::success($r,'public','public','public');
   99:         my $lonidsdir=$r->dir_config('lonIDsDir');
  100:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$cookie);
  101: 	$r->err_header_out('Set-cookie',"lonID=$cookie; path=/");
  102:     }
  103:     &Apache::lonacc::get_posted_cgi($r);
  104:     $env{'request.state'} = "published";
  105:     $env{'request.publicaccess'} = 1;
  106:     $env{'request.filename'} = $r->filename;
  107:     return;
  108: }
  109: 
  110: sub process_portfolio {
  111:     my ($udom,$unum,$file_name,$group) = @_;
  112:     my $current_perms = &Apache::lonnet::get_portfile_permissions($udom,$unum);
  113:     my %access_controls = &Apache::lonnet::get_access_controls($current_perms,$group,$file_name);
  114:     my $access = '';
  115:     my $now = time;
  116:     foreach my $key (keys(%{$access_controls{$file_name}})) {
  117:         my ($num,$scope,$end,$start) = ($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/);
  118:         if ($start > $now) {
  119:             next;
  120:         }
  121:         if ($end && $end<$now) {
  122:             next;
  123:         }
  124:         if ($scope eq 'public') {
  125:             $access = 'public';
  126:             last;
  127:         }
  128:         if ($scope eq 'guest') {
  129:             $access = 'guest';
  130:         }
  131:     }
  132:     return $access;
  133: }
  134: 
  135: 1;
  136: 
  137: __END__

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