File:  [LON-CAPA] / loncom / auth / loncacc.pm
Revision 1.46: download - view: text, annotated - select for diffs
Tue Oct 2 01:09:59 2007 UTC (16 years, 7 months ago) by albertel
Branches: MAIN
CVS tags: version_2_8_X, version_2_8_2, version_2_8_1, version_2_8_0, version_2_7_X, version_2_7_99_1, version_2_7_99_0, version_2_7_1, version_2_7_0, version_2_6_X, version_2_6_99_1, version_2_6_99_0, version_2_6_3, version_2_6_2, version_2_6_1, version_2_6_0, version_2_5_99_1, version_2_5_99_0, HEAD, GCI_1
- convert exisiting cookie reads/validations to use
   lonnet::check_for_valid_session

    1: # The LearningOnline Network
    2: # Cookie Based Access Handler for Construction Area
    3: # (lonacc: 5/21/99,5/22,5/29,5/31 Gerd Kortemeyer)
    4: #
    5: # $Id: loncacc.pm,v 1.46 2007/10/02 01:09:59 albertel 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: package Apache::loncacc;
   31: 
   32: use strict;
   33: use Apache::Constants qw(:common :http :methods REDIRECT);
   34: use Fcntl qw(:flock);
   35: use Apache::lonlocal;
   36: use Apache::lonnet;
   37: use Apache::lonacc;
   38: use LONCAPA qw(:DEFAULT :match);
   39: 
   40: sub constructaccess {
   41:     my ($url,$ownerdomain)=@_;
   42:     my ($ownername)=($url=~/\/(?:\~|priv\/|home\/)($match_username)\//);
   43:     unless (($ownername) && ($ownerdomain)) { return ''; }
   44:     # We do not allow editing of previous versions of files.
   45:     if ($url=~/\.(\d+)\.(\w+)$/) { return ''; }
   46:     my @possibledomains = &Apache::lonnet::current_machine_domains();
   47:     if ($ownername eq $env{'user.name'}) {
   48: 	foreach my $domain (@possibledomains) {
   49: 	    if ($domain eq $env{'user.domain'}) {
   50: 		return ($ownername,$domain);
   51: 	    }
   52: 	}
   53:     }
   54:     
   55:     foreach my $domain (@possibledomains) {
   56: 	if (exists($env{'user.priv.ca./'.$domain.'/'.$ownername.'./'}) ||
   57: 	    exists($env{'user.priv.aa./'.$domain.'/'.$ownername.'./'}) ) {
   58: 	    return ($ownername,$domain);
   59: 	}
   60:     }
   61:     return '';
   62: }
   63: 
   64: sub handler {
   65:     my $r = shift;
   66:     my $requrl=$r->uri;
   67:     $env{'request.editurl'}=$requrl;
   68: 
   69:     my $handle =  &Apache::lonnet::check_for_valid_session($r);
   70:     if ($handle ne '') {
   71: 
   72: # ------------------------------------------------------ Initialize Environment
   73:         my $lonidsdir=$r->dir_config('lonIDsDir');
   74: 	&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   75: 
   76: # --------------------------------------------------------- Initialize Language
   77:  
   78: 	&Apache::lonlocal::get_language_handle($r);
   79: 
   80: # -------------------------------------------------------------- Resource State
   81: 
   82: 	$env{'request.state'}    = "construct";
   83: 	$env{'request.filename'} = $r->filename;
   84: 
   85: 	unless (&constructaccess($requrl,$r->dir_config('lonDefDomain'))) {
   86: 	    $r->log_reason("Unauthorized $requrl", $r->filename); 
   87: 	    return HTTP_NOT_ACCEPTABLE;
   88: 	}
   89: 
   90: # -------------------------------------------------------- Load POST parameters
   91: 
   92: 	&Apache::lonacc::get_posted_cgi($r);
   93: 
   94: 	return OK; 
   95:     } else { 
   96: 	$r->log_reason("Cookie $handle not valid", $r->filename) 
   97:     }
   98: 
   99: # ----------------------------------------------- Store where they wanted to go
  100: 
  101:     $env{'request.firsturl'}=$requrl;
  102:     return FORBIDDEN;
  103: }
  104: 
  105: 1;
  106: __END__
  107: 
  108: =head1 NAME
  109: 
  110: Apache::lonacc - Cookie Based Access Handler for Construction Area
  111: 
  112: =head1 SYNOPSIS
  113: 
  114: Invoked (for various locations) by /etc/httpd/conf/loncapa_apache.conf:
  115: 
  116:  PerlAccessHandler       Apache::loncacc
  117: 
  118: =head1 INTRODUCTION
  119: 
  120: This module enables cookie based authentication for construction area
  121: and is used to control access for three (essentially equivalent) URIs.
  122: 
  123:  <LocationMatch "^/priv.*">
  124:  <LocationMatch "^/\~.*">
  125:  <LocationMatch "^/\~.*/$">
  126: 
  127: Whenever the client sends the cookie back to the server, 
  128: if the cookie is missing or invalid, the user is re-challenged
  129: for login information.
  130: 
  131: This is part of the LearningOnline Network with CAPA project
  132: described at http://www.lon-capa.org.
  133: 
  134: =head1 HANDLER SUBROUTINE
  135: 
  136: This routine is called by Apache and mod_perl.
  137: 
  138: =over 4
  139: 
  140: =item *
  141: 
  142: load POST parameters
  143: 
  144: =item *
  145: 
  146: store where they wanted to go (first url entered)
  147: 
  148: =back
  149: 
  150: =head1 OTHERSUBROUTINES
  151: 
  152: =over 4
  153: 
  154: =item *
  155: 
  156: constructaccess($url,$ownerdomain) : See if the owner domain and name
  157: in the URL match those in the expected environment.  If so, return 
  158: two element list ($ownername,$ownerdomain).  Else, return null string.
  159: 
  160: =back
  161: 
  162: =cut
  163: 
  164: 
  165: 
  166: 
  167: 
  168: 
  169: 

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