File:  [LON-CAPA] / loncom / auth / loncacc.pm
Revision 1.29: download - view: text, annotated - select for diffs
Wed Jun 11 00:39:46 2003 UTC (20 years, 11 months ago) by www
Branches: MAIN
CVS tags: version_1_0_3, version_1_0_2, version_1_0_1, version_1_0_0, version_0_99_5, version_0_99_4, version_0_99_3, version_0_99_2, HEAD
Bug #1636: co-author access had been denied.

    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.29 2003/06/11 00:39:46 www 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: # YEAR=2000
   30: # 6/15,16/11,22/11,
   31: # YEAR=2001
   32: # 01/06,01/11,6/1,9/25,9/28,11/22,12/25,12/26,
   33: # 01/06/01,05/04,05/05,05/09 Gerd Kortemeyer
   34: # YEAR=2002
   35: # 1/4 Gerd Kortemeyer
   36: ###
   37: 
   38: package Apache::loncacc;
   39: 
   40: use strict;
   41: use Apache::Constants qw(:common :http :methods REDIRECT);
   42: use Apache::File;
   43: use CGI::Cookie();
   44: use Fcntl qw(:flock);
   45: 
   46: sub constructaccess {
   47:     my ($url,$ownerdomain)=@_;
   48:     my ($ownername)=($url=~/\/(?:\~|priv\/|home\/)(\w+)/);
   49:     unless (($ownername) && ($ownerdomain)) { return ''; }
   50:     # We do not allow editing of previous versions of files.
   51:     if ($url=~/\.(\d+)\.(\w+)$/) { return ''; }
   52:     if (($ownername eq $ENV{'user.name'}) &&
   53:         ($ownerdomain eq $ENV{'user.domain'})) {
   54: 	return ($ownername,$ownerdomain);
   55:     }
   56: 
   57:     my $capriv='user.priv.ca./'.
   58:                $ownerdomain.'/'.$ownername.'./';
   59:     foreach (keys %ENV) {
   60:         if ($_ eq $capriv) {
   61:            return ($ownername,$ownerdomain);
   62:         }
   63:     }
   64:     return '';
   65: }
   66: 
   67: sub handler {
   68:     my $r = shift;
   69:     my $requrl=$r->uri;
   70:     $ENV{'request.editurl'}=$requrl;
   71:     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
   72:     my $lonid=$cookies{'lonID'};
   73:     my $cookie;
   74:     if ($lonid) {
   75: 	my $handle=$lonid->value;
   76:         $handle=~s/\W//g;
   77:         my $lonidsdir=$r->dir_config('lonIDsDir');
   78:         if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
   79: 
   80: # ------------------------------------------------------ Initialize Environment
   81: 
   82:             &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   83: 
   84: # -------------------------------------------------------------- Resource State
   85: 
   86:             $ENV{'request.state'}    = "construct";
   87:             $ENV{'request.filename'} = $r->filename;
   88: 
   89:             unless (&constructaccess($requrl,$r->dir_config('lonDefDomain'))) {
   90:                 $r->log_reason("Unauthorized $requrl", $r->filename); 
   91: 	        return HTTP_NOT_ACCEPTABLE;
   92:             }
   93: # Construction space needs Remote to work
   94:             if ($ENV{'environment.remote'} eq 'off') {
   95: 	        $r->content_type('text/html');
   96:                 $r->header_out(Location => 
   97:                     'http://'.$r->server->server_hostname.
   98:                     '/adm/remote?action=launch&url='.
   99:                     &Apache::lonnet::escape($requrl));
  100:                 return REDIRECT;
  101:             }
  102: 
  103: # -------------------------------------------------------- Load POST parameters
  104: 
  105: 	    &Apache::loncommon::get_posted_cgi($r);
  106: 
  107:             return OK; 
  108:         } else { 
  109:             $r->log_reason("Cookie $handle not valid", $r->filename) 
  110:         };
  111:     }
  112: 
  113: # ----------------------------------------------- Store where they wanted to go
  114: 
  115:     $ENV{'request.firsturl'}=$requrl;
  116:     return FORBIDDEN;
  117: }
  118: 
  119: 1;
  120: __END__
  121: 
  122: =head1 NAME
  123: 
  124: Apache::lonacc - Cookie Based Access Handler for Construction Area
  125: 
  126: =head1 SYNOPSIS
  127: 
  128: Invoked (for various locations) by /etc/httpd/conf/loncapa_apache.conf:
  129: 
  130:  PerlAccessHandler       Apache::loncacc
  131: 
  132: =head1 INTRODUCTION
  133: 
  134: This module enables cookie based authentication for construction area
  135: and is used to control access for three (essentially equivalent) URIs.
  136: 
  137:  <LocationMatch "^/priv.*">
  138:  <LocationMatch "^/\~.*">
  139:  <LocationMatch "^/\~.*/$">
  140: 
  141: Whenever the client sends the cookie back to the server, 
  142: if the cookie is missing or invalid, the user is re-challenged
  143: for login information.
  144: 
  145: This is part of the LearningOnline Network with CAPA project
  146: described at http://www.lon-capa.org.
  147: 
  148: =head1 HANDLER SUBROUTINE
  149: 
  150: This routine is called by Apache and mod_perl.
  151: 
  152: =over 4
  153: 
  154: =item *
  155: 
  156: load POST parameters
  157: 
  158: =item *
  159: 
  160: store where they wanted to go (first url entered)
  161: 
  162: =back
  163: 
  164: =head1 OTHERSUBROUTINES
  165: 
  166: =over 4
  167: 
  168: =item *
  169: 
  170: constructaccess($url,$ownerdomain) : See if the owner domain and name
  171: in the URL match those in the expected environment.  If so, return 
  172: two element list ($ownername,$ownerdomain).  Else, return null string.
  173: 
  174: =back
  175: 
  176: =cut
  177: 
  178: 
  179: 
  180: 
  181: 
  182: 
  183: 

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