File:  [LON-CAPA] / loncom / auth / publiccheck.pm
Revision 1.14: download - view: text, annotated - select for diffs
Wed Apr 11 21:36:58 2007 UTC (17 years, 1 month ago) by raeburn
Branches: MAIN
CVS tags: version_2_5_X, version_2_5_2, version_2_5_1, version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_99_0, HEAD
Put reg exp check for domain logo in lonnet  - &is_domainimage()
checkauthen, publiccheck and lonacc all need this to serve images for log-in page if port 8080 is not in use.
Other possibilities - (1) call once in checkauthen and pass along to publiccheck and lonacc in Apache notes, or (2) modify loncapa_apach.conf.
lonhttpd to use a call to the same routine.

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

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