File:  [LON-CAPA] / loncom / auth / lonacc.pm
Revision 1.150: download - view: text, annotated - select for diffs
Thu Dec 19 22:50:16 2013 UTC (10 years, 4 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Call to &sso_login() not needed when lonacc::handler() is called in the
  context of an internal redirect to /adm/switchserver.
- Avoid ISE on loadbalancer server following change in checkauthen.pm rev
  1.14

    1: # The LearningOnline Network
    2: # Cookie Based Access Handler
    3: #
    4: # $Id: lonacc.pm,v 1.150 2013/12/19 22:50:16 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: =head1 NAME
   31: 
   32: Apache::lonacc - Cookie Based Access Handler
   33: 
   34: =head1 SYNOPSIS
   35: 
   36: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
   37: 
   38:  PerlAccessHandler       Apache::lonacc
   39: 
   40: =head1 INTRODUCTION
   41: 
   42: This module enables cookie based authentication and is used
   43: to control access for many different LON-CAPA URIs.
   44: 
   45: Whenever the client sends the cookie back to the server, 
   46: this cookie is handled by either lonacc.pm or loncacc.pm
   47: (see srm.conf for what is invoked when).  If
   48: the cookie is missing or invalid, the user is re-challenged
   49: for login information.
   50: 
   51: This is part of the LearningOnline Network with CAPA project
   52: described at http://www.lon-capa.org.
   53: 
   54: =head1 HANDLER SUBROUTINE
   55: 
   56: This routine is called by Apache and mod_perl.
   57: 
   58: =over 4
   59: 
   60: =item *
   61: 
   62: transfer profile into environment
   63: 
   64: =item *
   65: 
   66: load POST parameters
   67: 
   68: =item *
   69: 
   70: check access
   71: 
   72: =item *
   73: 
   74: if allowed, get symb, log, generate course statistics if applicable
   75: 
   76: =item *
   77: 
   78: otherwise return error
   79: 
   80: =item *
   81: 
   82: see if public resource
   83: 
   84: =item *
   85: 
   86: store attempted access
   87: 
   88: =back
   89: 
   90: =head1 NOTABLE SUBROUTINES
   91: 
   92: =cut
   93: 
   94: 
   95: package Apache::lonacc;
   96: 
   97: use strict;
   98: use Apache::Constants qw(:common :http :methods);
   99: use Apache::File;
  100: use Apache::lonnet;
  101: use Apache::loncommon();
  102: use Apache::lonlocal;
  103: use Apache::restrictedaccess();
  104: use Apache::blockedaccess();
  105: use Fcntl qw(:flock);
  106: use LONCAPA qw(:DEFAULT :match);
  107: 
  108: sub cleanup {
  109:     my ($r)=@_;
  110:     if (! $r->is_initial_req()) { return DECLINED; }
  111:     &Apache::lonnet::save_cache();
  112:     &Apache::lontexconvert::jsMath_reset();
  113:     return OK;
  114: }
  115: 
  116: sub goodbye {
  117:     my ($r)=@_;
  118:     &Apache::lonnet::goodbye();
  119:     return DONE;
  120: }
  121: 
  122: ###############################################
  123: 
  124: sub get_posted_cgi {
  125:     my ($r,$fields) = @_;
  126: 
  127:     my $buffer;
  128:     if ($r->header_in('Content-length')) {
  129: 	$r->read($buffer,$r->header_in('Content-length'),0);
  130:     }
  131:     my $content_type = $r->header_in('Content-type');
  132:     if ($content_type !~ m{^multipart/form-data}) {
  133: 	my @pairs=split(/&/,$buffer);
  134: 	my $pair;
  135: 	foreach $pair (@pairs) {
  136: 	    my ($name,$value) = split(/=/,$pair);
  137: 	    $value =~ tr/+/ /;
  138: 	    $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
  139: 	    $name  =~ tr/+/ /;
  140: 	    $name  =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
  141:             if (ref($fields) eq 'ARRAY') {
  142:                 next if (!grep(/^\Q$name\E$/,@{$fields}));
  143:             }
  144: 	    &Apache::loncommon::add_to_env("form.$name",$value);
  145: 	}
  146:     } else {
  147: 	my ($contentsep) = ($content_type =~ /boundary=\"?([^\";,]+)\"?/);
  148: 	my @lines = split (/\n/,$buffer);
  149: 	my $name='';
  150: 	my $value='';
  151: 	my $fname='';
  152: 	my $fmime='';
  153: 	my $i;
  154: 	for ($i=0;$i<=$#lines;$i++) {
  155: 	    if ($lines[$i]=~/^--\Q$contentsep\E/) {
  156: 		if ($name) {
  157:                     chomp($value);
  158:                     if (($r->uri eq '/adm/portfolio') && 
  159:                         ($name eq 'uploaddoc')) {
  160:                         if (length($value) == 1) {
  161:                             $value=~s/[\r\n]$//;
  162:                         }
  163:                     }
  164:                     if (ref($fields) eq 'ARRAY') {
  165:                         next if (!grep(/^\Q$name\E$/,@{$fields}));
  166:                     }
  167:                     if ($fname) {
  168:                         if ($env{'form.symb'} ne '') {
  169:                             my $size = (length($value))/(1024.0 * 1024.0);
  170:                             if (&upload_size_allowed($name,$size,$fname) eq 'ok') {
  171:                                 $env{"form.$name.filename"}=$fname;
  172:                                 $env{"form.$name.mimetype"}=$fmime;
  173:                                 &Apache::loncommon::add_to_env("form.$name",$value);
  174:                             }
  175:                         } else {
  176:                             $env{"form.$name.filename"}=$fname;
  177:                             $env{"form.$name.mimetype"}=$fmime;
  178:                             &Apache::loncommon::add_to_env("form.$name",$value);
  179:                         }
  180:                     } else {
  181:                         $value=~s/\s+$//s;
  182:                         &Apache::loncommon::add_to_env("form.$name",$value);
  183:                     }
  184: 		}
  185: 		if ($i<$#lines) {
  186: 		    $i++;
  187: 		    $lines[$i]=~
  188: 		/Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
  189: 		    $name=$1;
  190: 		    $value='';
  191: 		    if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
  192: 			$fname=$1;
  193: 			if 
  194:                             ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {
  195: 				$fmime=$1;
  196: 				$i++;
  197: 			    } else {
  198: 				$fmime='';
  199: 			    }
  200: 		    } else {
  201: 			$fname='';
  202: 			$fmime='';
  203: 		    }
  204: 		    $i++;
  205: 		}
  206: 	    } else {
  207: 		$value.=$lines[$i]."\n";
  208: 	    }
  209: 	}
  210:     }
  211: #
  212: # Digested POSTed values
  213: #
  214: # Remember the way this was originally done (GET or POST)
  215: #
  216:     $env{'request.method'}=$ENV{'REQUEST_METHOD'};
  217: #
  218: # There may also be stuff in the query string
  219: # Tell subsequent handlers that this was GET, not POST, so they can access query string.
  220: # Also, unset POSTed content length to cover all tracks.
  221: #
  222: 
  223:     $r->method_number(M_GET);
  224: 
  225:     $r->method('GET');
  226:     $r->headers_in->unset('Content-length');
  227: }
  228: 
  229: =pod
  230: 
  231: =over
  232: 
  233: =item upload_size_allowed()
  234: 
  235: 	Perform size checks for file uploads to essayresponse items in course context.
  236: 	
  237: 	Add form.HWFILESIZE.$part_$id to %env with file size (MB)
  238: 	If file exceeds maximum allowed size, add form.HWFILETOOBIG.$part_$id to %env.
  239: 
  240: =cut
  241:  
  242: sub upload_size_allowed {
  243:     my ($name,$size,$fname) = @_;
  244:     if ($name =~ /^HWFILE(\w+)$/) {
  245:         my $ident = $1;
  246:         my $item = 'HWFILESIZE'.$ident;
  247:         my $savesize = sprintf("%.6f",$size);
  248:         &Apache::loncommon::add_to_env("form.$item",$savesize);
  249:         my $maxsize= &Apache::lonnet::EXT("resource.$ident.maxfilesize");
  250:         if (!$maxsize) {
  251:             $maxsize = 10.0; # FIXME This should become a domain configuration.
  252:         }
  253:         if ($size > $maxsize) {
  254:             my $warn = 'HWFILETOOBIG'.$ident;
  255:             &Apache::loncommon::add_to_env("form.$warn",$fname);
  256:             return;
  257:         }
  258:     }
  259:     return 'ok';
  260: }
  261: 
  262: =pod
  263: 
  264: =item sso_login()
  265: 
  266: 	handle the case of the single sign on user, at this point $r->user 
  267: 	will be set and valid; now need to find the loncapa user info, and possibly
  268: 	balance them. If $r->user() is set this means either it was either set by
  269:         SSO or by checkauthen.pm, if a valid cookie was found. The latter case can
  270:         be identified by the third arg ($usename), except when lonacc is called in 
  271:         an internal redirect to /adm/switchserver (e.g., load-balancing following
  272:         successful authentication) -- no cookie set yet.  For that particular case
  273:         simply skip the call to sso_login(). 
  274: 
  275: 	returns OK if it was SSO and user was handled.
  276:         returns undef if not SSO or no means to handle the user.
  277:         
  278: =cut
  279: 
  280: sub sso_login {
  281:     my ($r,$handle,$username) = @_;
  282: 
  283:     my $lonidsdir=$r->dir_config('lonIDsDir');
  284:     if (($r->user eq '') || ($username ne '') ||
  285:         (defined($env{'user.name'}) && (defined($env{'user.domain'}))
  286: 	  && ($handle ne ''))) {
  287: 	# not an SSO case or already logged in
  288: 	return undef;
  289:     }
  290: 
  291:     my ($user) = ($r->user =~ m/([a-zA-Z0-9_\-@.]*)/);
  292: 
  293:     my $query = $r->args;
  294:     my %form;
  295:     if ($query) {
  296:         my @items = ('role','symb','iptoken');
  297:         &Apache::loncommon::get_unprocessed_cgi($query,\@items);
  298:         foreach my $item (@items) {
  299:             if (defined($env{'form.'.$item})) {
  300:                 $form{$item} = $env{'form.'.$item};
  301:             }
  302:         }
  303:     }
  304: 
  305:     my %sessiondata;
  306:     if ($form{'iptoken'}) {
  307:         %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
  308:         my $delete = &Apache::lonnet::tmpdel($form{'token'});
  309:     }
  310: 
  311:     my $domain = $r->dir_config('lonSSOUserDomain');
  312:     if ($domain eq '') {
  313:         $domain = $r->dir_config('lonDefDomain');
  314:     }
  315:     my $home=&Apache::lonnet::homeserver($user,$domain);
  316:     if ($home !~ /(con_lost|no_host|no_such_host)/) {
  317: 	&Apache::lonnet::logthis(" SSO authorized user $user ");
  318:         my ($is_balancer,$otherserver,$hosthere);
  319:         if ($form{'iptoken'}) {
  320:             if (($sessiondata{'domain'} eq $form{'udom'}) &&
  321:                 ($sessiondata{'username'} eq $form{'uname'})) {
  322:                 $hosthere = 1;
  323:             }
  324:         }
  325:         unless ($hosthere) {
  326:             ($is_balancer,$otherserver) =
  327:                 &Apache::lonnet::check_loadbalancing($user,$domain);
  328:         }
  329: 
  330: 	if ($is_balancer) {
  331: 	    # login but immediately go to switch server to find us a new 
  332: 	    # machine
  333: 	    &Apache::lonauth::success($r,$user,$domain,$home,'noredirect');
  334:             $env{'request.sso.login'} = 1;
  335:             if (defined($r->dir_config("lonSSOReloginServer"))) {
  336:                 $env{'request.sso.reloginserver'} =
  337:                     $r->dir_config('lonSSOReloginServer');
  338:             }
  339:             my $redirecturl = '/adm/switchserver';
  340:             if ($otherserver ne '') {
  341:                 $redirecturl .= '?otherserver='.$otherserver;
  342:             }
  343: 	    $r->internal_redirect($redirecturl);
  344: 	    $r->set_handlers('PerlHandler'=> undef);
  345: 	} else {
  346: 	    # need to login them in, so generate the need data that
  347: 	    # migrate expects to do login
  348: 	    my $ip;
  349: 	    my $c = $r->connection;
  350: 	    eval {
  351: 	        $ip = $c->remote_ip();
  352: 	    };
  353: 	    if ($@) {
  354: 	        $ip = $c->client_ip();
  355: 	    }
  356: 	    my %info=('ip'        => $ip,
  357: 		      'domain'    => $domain,
  358: 		      'username'  => $user,
  359: 		      'server'    => $r->dir_config('lonHostID'),
  360: 		      'sso.login' => 1
  361: 		      );
  362:             foreach my $item ('role','symb') {
  363:                 if (exists($form{$item})) {
  364:                     $info{$item} = $form{$item};
  365:                 }
  366:             }
  367:             if ($r->dir_config("ssodirecturl") == 1) {
  368:                 $info{'origurl'} = $r->uri;
  369:             }
  370:             if (defined($r->dir_config("lonSSOReloginServer"))) {
  371:                 $info{'sso.reloginserver'} = 
  372:                     $r->dir_config('lonSSOReloginServer'); 
  373:             }
  374: 	    my $token = 
  375: 		&Apache::lonnet::tmpput(\%info,
  376: 					$r->dir_config('lonHostID'));
  377: 	    $env{'form.token'} = $token;
  378: 	    $r->internal_redirect('/adm/migrateuser');
  379: 	    $r->set_handlers('PerlHandler'=> undef);
  380: 	}
  381: 	return OK;
  382:     } elsif (defined($r->dir_config('lonSSOUserUnknownRedirect'))) {
  383: 	&Apache::lonnet::logthis(" SSO authorized unknown user $user ");
  384:         $r->subprocess_env->set('SSOUserUnknown' => $user);
  385:         $r->subprocess_env->set('SSOUserDomain' => $domain);
  386:         my @cancreate;
  387:         my %domconfig =
  388:             &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
  389:         if (ref($domconfig{'usercreation'}) eq 'HASH') {
  390:             if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
  391:                 if (ref($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
  392:                     @cancreate = @{$domconfig{'usercreation'}{'cancreate'}{'selfcreate'}};
  393:                 } elsif (($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') && 
  394:                          ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne '')) {
  395:                     @cancreate = ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'});
  396:                 }
  397:             }
  398:         }
  399:         if (grep(/^sso$/,@cancreate)) {
  400:             $r->internal_redirect('/adm/createaccount');
  401:         } else {
  402: 	    $r->internal_redirect($r->dir_config('lonSSOUserUnknownRedirect'));
  403:         }
  404: 	$r->set_handlers('PerlHandler'=> undef);
  405: 	return OK;
  406:     }
  407:     return undef;
  408: }
  409: 
  410: sub handler {
  411:     my $r = shift;
  412:     my $requrl=$r->uri;
  413: 
  414:     if ($requrl =~ m{^/res/adm/pages/[^/]+\.(gif|png)$}) {
  415:         return OK;
  416:     }
  417: 
  418:     if (&Apache::lonnet::is_domainimage($requrl)) {
  419:         return OK;
  420:     }
  421: 
  422:     my %user;
  423:     my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user);
  424: 
  425:     unless (($requrl eq '/adm/switchserver') && (!$r->is_initial_req())) {
  426:         my $result = &sso_login($r,$handle,$user{'name'});
  427:         if (defined($result)) {
  428: 	    return $result;
  429:         }
  430:     }
  431: 
  432:     my ($is_balancer,$otherserver);
  433: 
  434:     if ($handle eq '') {
  435:         unless (($requrl eq '/adm/switchserver') && (!$r->is_initial_req())) {
  436: 	    $r->log_reason("Cookie not valid", $r->filename);
  437:         }
  438:     } elsif ($handle ne '') {
  439: 
  440: # ------------------------------------------------------ Initialize Environment
  441: 	my $lonidsdir=$r->dir_config('lonIDsDir');
  442: 	&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
  443: 
  444: # --------------------------------------------------------- Initialize Language
  445: 
  446: 	&Apache::lonlocal::get_language_handle($r);
  447: 
  448:     }
  449: 
  450: # -------------------------------------------------- Should be a valid user now
  451:     if ($env{'user.name'} ne '' && $env{'user.domain'} ne '') {
  452: # -------------------------------------------------------------- Resource State
  453: 
  454:         my ($cdom,$cnum);
  455:         if ($env{'request.course.id'}) {
  456:             $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
  457:             $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
  458:         }
  459: 	if ($requrl=~/^\/+(res|uploaded)\//) {
  460: 	    $env{'request.state'} = "published";
  461: 	} else {
  462: 	    $env{'request.state'} = 'unknown';
  463: 	}
  464: 	$env{'request.filename'} = $r->filename;
  465: 	$env{'request.noversionuri'} = &Apache::lonnet::deversion($requrl);
  466:         my $suppext;
  467:         if ($requrl =~ m{^/adm/wrapper/ext/}) {
  468:             my $query = $r->args;
  469:             if ($query) {
  470:                 my $preserved;
  471:                 foreach my $pair (split(/&/,$query)) {
  472:                     my ($name, $value) = split(/=/,$pair);
  473:                     unless ($name eq 'symb') {
  474:                         $preserved .= $pair.'&';
  475:                     }
  476:                     if (($env{'request.course.id'}) && ($name eq 'folderpath')) {
  477:                         if ($value =~ /^supplemental/) {
  478:                             $suppext = 1;
  479:                         }
  480:                     }
  481:                 }
  482:                 $preserved =~ s/\&$//;
  483:                 if ($preserved) {
  484:                     $env{'request.external.querystring'} = $preserved;
  485:                 }
  486:             }
  487:         } elsif ($env{'request.course.id'} &&
  488:                  (($requrl =~ m{^/adm/$match_domain/$match_username/aboutme$}) ||
  489:                   ($requrl =~ m{^/public/$cdom/$cnum/syllabus$}))) {
  490:             my $query = $r->args;
  491:             if ($query) {
  492:                 foreach my $pair (split(/&/,$query)) {
  493:                     my ($name, $value) = split(/=/,$pair);
  494:                     if ($name eq 'folderpath') {
  495:                         if ($value =~ /^supplemental/) {
  496:                             $suppext = 1;
  497:                         }
  498:                     }
  499:                 }
  500:             }
  501:         }
  502: # -------------------------------------------------------- Load POST parameters
  503: 
  504: 	&Apache::lonacc::get_posted_cgi($r);
  505: 
  506: # ------------------------------------------------------ Check if load balancer 
  507: 
  508:         my $checkexempt;
  509:         if ($env{'user.loadbalexempt'} eq $r->dir_config('lonHostID')) {
  510:             if ($env{'user.loadbalcheck.time'} + 600 > time) {
  511:                 $checkexempt = 1;    
  512:             }
  513:         }
  514:         if ($env{'user.noloadbalance'} eq $r->dir_config('lonHostID')) {
  515:             $checkexempt = 1;
  516:         }
  517:         unless ($checkexempt) {
  518:             ($is_balancer,$otherserver) =
  519:                 &Apache::lonnet::check_loadbalancing($env{'user.name'},
  520:                                                      $env{'user.domain'});
  521:         }
  522:         if ($is_balancer) {
  523:             $r->set_handlers('PerlResponseHandler'=>
  524:                              [\&Apache::switchserver::handler]);
  525:             if ($otherserver ne '') {
  526:                 $env{'form.otherserver'} = $otherserver;
  527:             }
  528:         }
  529: 
  530: # ---------------------------------------------------------------- Check access
  531: 	my $now = time;
  532: 	if ($requrl !~ m{^/(?:adm|public|prtspool)/}
  533: 	    || $requrl =~ /^\/adm\/.*\/(smppg|bulletinboard)(\?|$ )/x) {
  534: 	    my $access=&Apache::lonnet::allowed('bre',$requrl);
  535: 	    if ($access eq '1') {
  536: 		$env{'user.error.msg'}="$requrl:bre:0:0:Choose Course";
  537: 		return HTTP_NOT_ACCEPTABLE; 
  538: 	    }
  539: 	    if ($access eq 'A') {
  540: 		&Apache::restrictedaccess::setup_handler($r);
  541: 		return OK;
  542: 	    }
  543:             if ($access eq 'B') {
  544:                 &Apache::blockedaccess::setup_handler($r);
  545:                 return OK;
  546:             }
  547: 	    if (($access ne '2') && ($access ne 'F')) {
  548:                 if ($requrl =~ m{^/res/}) {
  549:                     $access = &Apache::lonnet::allowed('bro',$requrl);
  550:                     if ($access ne 'F') {
  551:                         if ($requrl eq '/res/lib/templates/simpleproblem.problem/smpedit') {
  552:                             $access = &Apache::lonnet::allowed('bre','/res/lib/templates/simpleproblem.problem');
  553:                             if ($access ne 'F') {
  554:                                 $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
  555:                                 return HTTP_NOT_ACCEPTABLE;
  556:                             }
  557:                         } else {
  558:                             $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
  559:                             return HTTP_NOT_ACCEPTABLE;
  560:                         }
  561:                     }
  562:                 } else {
  563: 		    $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
  564: 		    return HTTP_NOT_ACCEPTABLE;
  565:                 }
  566: 	    }
  567: 	}
  568: 	if ($requrl =~ m|^/prtspool/|) {
  569: 	    my $start='/prtspool/'.$env{'user.name'}.'_'.
  570: 		$env{'user.domain'};
  571: 	    if ($requrl !~ /^\Q$start\E/) {
  572: 		$env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
  573: 		return HTTP_NOT_ACCEPTABLE;
  574: 	    }
  575: 	}
  576: 	if ($requrl =~ m|^/zipspool/|) {
  577: 	    my $start='/zipspool/zipout/'.$env{'user.name'}.":".
  578: 		$env{'user.domain'};
  579: 	    if ($requrl !~ /^\Q$start\E/) {
  580: 		$env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
  581: 		return HTTP_NOT_ACCEPTABLE;
  582: 	    }
  583: 	}
  584: 	if ($env{'user.name'} eq 'public' && 
  585: 	    $env{'user.domain'} eq 'public' &&
  586: 	    $requrl !~ m{^/+(res|public|uploaded)/} &&
  587: 	    $requrl !~ m{^/adm/[^/]+/[^/]+/aboutme/portfolio$ }x &&
  588:         $requrl !~ m{^/adm/blockingstatus/.*$} &&
  589: 	    $requrl !~ m{^/+adm/(help|logout|restrictedaccess|randomlabel\.png)}) {
  590: 	    $env{'request.querystring'}=$r->args;
  591: 	    $env{'request.firsturl'}=$requrl;
  592: 	    return FORBIDDEN;
  593: 	}
  594: # ------------------------------------------------------------- This is allowed
  595: 	if ($env{'request.course.id'}) {
  596: 	    &Apache::lonnet::countacc($requrl);
  597: 	    $requrl=~/\.(\w+)$/;
  598:             my $query=$r->args;
  599: 	    if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
  600: 		($requrl=~/^\/adm\/.*\/(aboutme|smppg|bulletinboard)(\?|$ )/x) ||
  601: 		($requrl=~/^\/adm\/wrapper\//) ||
  602: 		($requrl=~m|^/adm/coursedocs/showdoc/|) ||
  603: 		($requrl=~m|\.problem/smpedit$|) ||
  604: 		($requrl=~/^\/public\/.*\/syllabus$/) ||
  605:                 ($requrl=~/^\/adm\/(viewclasslist|navmaps)$/) ||
  606:                 ($requrl=~/^\/adm\/.*\/aboutme\/portfolio(\?|$)/)) {
  607: # ------------------------------------- This is serious stuff, get symb and log
  608: 		my $symb;
  609: 		if ($query) {
  610: 		    &Apache::loncommon::get_unprocessed_cgi($query,['symb','folderpath']);
  611: 		}
  612: 		if ($env{'form.symb'}) {
  613: 		    $symb=&Apache::lonnet::symbclean($env{'form.symb'});
  614: 		    if ($requrl =~ m|^/adm/wrapper/|
  615: 			|| $requrl =~ m|^/adm/coursedocs/showdoc/|) {
  616: 			my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
  617: 			&Apache::lonnet::symblist($map,$murl => [$murl,$mid],
  618: 						  'last_known' =>[$murl,$mid]);
  619: 		    } elsif ((&Apache::lonnet::symbverify($symb,$requrl)) ||
  620: 			     (($requrl=~m|(.*)/smpedit$|) &&
  621: 			      &Apache::lonnet::symbverify($symb,$1)) ||
  622:                              (($requrl=~m|(.*/aboutme)/portfolio$|) &&
  623:                               &Apache::lonnet::symbverify($symb,$1))) {
  624: 			my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
  625: 			&Apache::lonnet::symblist($map,$murl => [$murl,$mid],
  626: 						  'last_known' =>[$murl,$mid]);
  627: 		    } else {
  628: 			$r->log_reason('Invalid symb for '.$requrl.': '.
  629: 				       $symb);
  630: 			$env{'user.error.msg'}=
  631: 			    "$requrl:bre:1:1:Invalid Access";
  632: 			return HTTP_NOT_ACCEPTABLE; 
  633: 		    }
  634: 		} else {
  635:                     if ($requrl=~m{^(/adm/.*/aboutme)/portfolio$}) {
  636:                         $requrl = $1;
  637:                     }
  638:                     unless ($suppext) {
  639: 		        $symb=&Apache::lonnet::symbread($requrl);
  640: 		        if (&Apache::lonnet::is_on_map($requrl) && $symb &&
  641: 			    !&Apache::lonnet::symbverify($symb,$requrl)) {
  642: 			    $r->log_reason('Invalid symb for '.$requrl.': '.$symb);
  643: 			    $env{'user.error.msg'}=
  644: 			        "$requrl:bre:1:1:Invalid Access";
  645: 			    return HTTP_NOT_ACCEPTABLE; 
  646: 		        }
  647: 		        if ($symb) {
  648: 			    my ($map,$mid,$murl)=
  649: 			        &Apache::lonnet::decode_symb($symb);
  650: 			    &Apache::lonnet::symblist($map,$murl =>[$murl,$mid],
  651: 						      'last_known' =>[$murl,$mid]);
  652: 		        }
  653: 		    }
  654: 		}
  655: 		$env{'request.symb'}=$symb;
  656: 		&Apache::lonnet::courseacclog($symb);
  657: 	    } else {
  658: # ------------------------------------------------------- This is other content
  659: 		&Apache::lonnet::courseacclog($requrl);    
  660: 	    }
  661:             if ($requrl =~ m{^/+uploaded/\Q$cdom\E/\Q$cnum\E/(docs|supplemental)/.+\.html?$}) {
  662:                 if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  663:                     if ($query) {
  664:                         &Apache::loncommon::get_unprocessed_cgi($query,['forceedit']);
  665:                         if ($env{'form.forceedit'}) {
  666:                             $env{'request.state'} = 'edit';
  667:                         }
  668:                     }
  669:                 }
  670:             } elsif ($requrl =~ m{^/+uploaded/\Q$cdom\E/\Q$cnum\E/portfolio/syllabus/.+\.html?$}) {
  671:                 if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
  672:                     if ($query) {
  673:                         &Apache::loncommon::get_unprocessed_cgi($query,['forceedit','editmode']);
  674:                         if (($env{'form.forceedit'}) || ($env{'form.editmode'})) {
  675:                             $env{'request.state'} = 'edit';
  676:                         }
  677:                     }
  678:                 }
  679:             }
  680: 	}
  681: 	return OK;
  682:     } else {
  683:         my $defdom=$r->dir_config('lonDefDomain');
  684:         ($is_balancer,$otherserver) =
  685:             &Apache::lonnet::check_loadbalancing(undef,$defdom);
  686:         if ($is_balancer) {
  687:             $r->set_handlers('PerlResponseHandler'=>
  688:                              [\&Apache::switchserver::handler]);
  689:             if ($otherserver ne '') {
  690:                 $env{'form.otherserver'} = $otherserver;
  691:             }
  692:         }
  693:     }
  694: # -------------------------------------------- See if this is a public resource
  695:     if ($requrl=~m|^/+adm/+help/+|) {
  696:  	return OK;
  697:     }
  698: # ------------------------------------ See if this is a viewable portfolio file
  699:     if (&Apache::lonnet::is_portfolio_url($requrl)) {
  700: 	my $access=&Apache::lonnet::allowed('bre',$requrl);
  701: 	if ($access eq 'A') {
  702: 	    &Apache::restrictedaccess::setup_handler($r);
  703: 	    return OK;
  704: 	}
  705: 	if (($access ne '2') && ($access ne 'F')) {
  706: 	    $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
  707: 	    return HTTP_NOT_ACCEPTABLE;
  708: 	}
  709:     }
  710: 
  711: # -------------------------------------------------------------- Not authorized
  712:     $requrl=~/\.(\w+)$/;
  713: #    if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
  714: #        ($requrl=~/^\/adm\/(roles|logout|email|menu|remote)/) ||
  715: #        ($requrl=~m|^/prtspool/|)) {
  716: # -------------------------- Store where they wanted to go and get login screen
  717: 	$env{'request.querystring'}=$r->args;
  718: 	$env{'request.firsturl'}=$requrl;
  719:        return FORBIDDEN;
  720: #   } else {
  721: # --------------------------------------------------------------------- Goodbye
  722: #       return HTTP_BAD_REQUEST;
  723: #   }
  724: }
  725: 
  726: 1;
  727: __END__
  728: 
  729: =pod
  730: 
  731: =back
  732: 
  733: =cut
  734: 

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