File:  [LON-CAPA] / loncom / auth / publiccheck.pm
Revision 1.19: download - view: text, annotated - select for diffs
Wed Mar 17 19:41:11 2010 UTC (14 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: version_2_10_X, version_2_10_1, version_2_10_0_RC2, version_2_10_0_RC1, version_2_10_0, loncapaMITrelate_1, language_hyphenation_merge, language_hyphenation, PRINT_INCOMPLETE_base, PRINT_INCOMPLETE, HEAD, GCI_3, BZ4492-merge, BZ4492-feature_horizontal_radioresponse, BZ4492-feature_Support_horizontal_radioresponse, BZ4492-Support_horizontal_radioresponse
- Reverse publiccheck.pm,v 1.18, loncapa_apache.conf,v 1.189.
  - No need to assign a public user session for coursecatalog just to
    change inline menu (lonmenu.pm v 1.319 provides a general solution).

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

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