File:  [LON-CAPA] / loncom / auth / loncacc.pm
Revision 1.61: download - view: text, annotated - select for diffs
Tue Jun 4 23:12:13 2013 UTC (10 years, 11 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_12_X, version_2_11_X, version_2_11_4_uiuc, version_2_11_4_msu, version_2_11_4, version_2_11_3_uiuc, version_2_11_3_msu, version_2_11_3, version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1, version_2_11_0_RC3, version_2_11_0_RC2, version_2_11_0_RC1, version_2_11_0, HEAD
- Replace terms: "Construction Space" with "Authoring Space"
  and: "Construction space" with "Authoring space"
  for consistency with type of role used to access it, and action taken there.

    1: # The LearningOnline Network
    2: # Cookie Based Access Handler for Authoring Spaces
    3: # (lonacc: 5/21/99,5/22,5/29,5/31 Gerd Kortemeyer)
    4: #
    5: # $Id: loncacc.pm,v 1.61 2013/06/04 23:12:13 raeburn Exp $
    6: #
    7: # Copyright Michigan State University Board of Trustees
    8: #
    9: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
   10: #
   11: # LON-CAPA is free software; you can redistribute it and/or modify
   12: # it under the terms of the GNU General Public License as published by
   13: # the Free Software Foundation; either version 2 of the License, or
   14: # (at your option) any later version.
   15: #
   16: # LON-CAPA is distributed in the hope that it will be useful,
   17: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   18: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   19: # GNU General Public License for more details.
   20: #
   21: # You should have received a copy of the GNU General Public License
   22: # along with LON-CAPA; if not, write to the Free Software
   23: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   24: #
   25: # /home/httpd/html/adm/gpl.txt
   26: #
   27: # http://www.lon-capa.org/
   28: #
   29: 
   30: =pod
   31: 
   32: =head1 NAME
   33: 
   34: Apache::lonacc - Cookie Based Access Handler for Authoring Spaces 
   35: 
   36: =head1 SYNOPSIS
   37: 
   38: Invoked (for various locations) by /etc/httpd/conf/loncapa_apache.conf:
   39: 
   40:  PerlAccessHandler       Apache::loncacc
   41: 
   42: =head1 INTRODUCTION
   43: 
   44: This module enables cookie based authentication for construction area
   45: and is used to control access for the following two types of URI 
   46: (one for files, and one for directories):
   47: 
   48:  <LocationMatch "^/priv.*">
   49:  <LocationMatch "^/priv.*/$">
   50: 
   51: Whenever the client sends the cookie back to the server, 
   52: if the cookie is missing or invalid, the user is re-challenged
   53: for login information.
   54: 
   55: This is part of the LearningOnline Network with CAPA project
   56: described at http://www.lon-capa.org.
   57: 
   58: =head1 HANDLER SUBROUTINE
   59: 
   60: This routine is called by Apache and mod_perl.
   61: 
   62: =over 4
   63: 
   64: =item *
   65: 
   66: load POST parameters
   67: 
   68: =item *
   69: 
   70: store where they wanted to go (first url entered)
   71: 
   72: =back
   73: 
   74: =cut
   75: 
   76: 
   77: package Apache::loncacc;
   78: 
   79: use strict;
   80: use Apache::Constants qw(:common :http :methods REDIRECT);
   81: use Fcntl qw(:flock);
   82: use Apache::lonlocal;
   83: use Apache::lonnet;
   84: use Apache::lonacc;
   85: use LONCAPA qw(:DEFAULT :match);
   86: 
   87: sub handler {
   88:     my $r = shift;
   89:     my $requrl=$r->uri;
   90:     $env{'request.editurl'}=$requrl;
   91: 
   92:     my $handle =  &Apache::lonnet::check_for_valid_session($r);
   93:     if ($handle ne '') {
   94: 
   95: # ------------------------------------------------------ Initialize Environment
   96:         my $lonidsdir=$r->dir_config('lonIDsDir');
   97: 	&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   98: 
   99: # --------------------------------------------------------- Initialize Language
  100:  
  101: 	&Apache::lonlocal::get_language_handle($r);
  102: 
  103: # -------------------------------------------------------------- Resource State
  104: 
  105: 	$env{'request.state'}    = "construct";
  106: 	$env{'request.filename'} = $r->filename;
  107: 
  108: 	my $allowed;
  109: 	my ($ownername,$ownerdom,$ownerhome) = 
  110:             &Apache::lonnet::constructaccess($requrl,'setpriv');
  111:         if (($ownername ne '') && ($ownerdom ne '') && ($ownerhome ne '')) {
  112:             unless ($ownerhome eq 'no_host') {
  113:                 my @hosts = &Apache::lonnet::current_machine_ids();
  114:                 if (grep(/^\Q$ownerhome\E$/,@hosts)) {
  115:                     $allowed = 1;
  116:                 }
  117:             }
  118:         }
  119: 
  120:         unless ($allowed) {
  121: 	    $r->log_reason("Unauthorized $requrl", $r->filename); 
  122: 	    return HTTP_NOT_ACCEPTABLE;
  123: 	}
  124: 
  125: # -------------------------------------------------------- Load POST parameters
  126: 
  127: 	&Apache::lonacc::get_posted_cgi($r);
  128: 
  129: 	return OK; 
  130:     } else {
  131: 	$r->log_reason("Cookie $handle not valid", $r->filename) 
  132:     }
  133: 
  134: # ----------------------------------------------- Store where they wanted to go
  135: 
  136:     $env{'request.firsturl'}=$requrl;
  137:     return FORBIDDEN;
  138: }
  139: 
  140: 1;
  141: __END__
  142: 

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