Annotation of loncom/auth/loncacc.pm, revision 1.61
1.1 albertel 1: # The LearningOnline Network
1.61 ! raeburn 2: # Cookie Based Access Handler for Authoring Spaces
1.1 albertel 3: # (lonacc: 5/21/99,5/22,5/29,5/31 Gerd Kortemeyer)
1.20 www 4: #
1.61 ! raeburn 5: # $Id: loncacc.pm,v 1.60 2012/10/29 17:39:06 raeburn Exp $
1.20 www 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: #
1.1 albertel 29:
1.47 jms 30: =pod
31:
32: =head1 NAME
33:
1.61 ! raeburn 34: Apache::lonacc - Cookie Based Access Handler for Authoring Spaces
1.47 jms 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
1.57 raeburn 45: and is used to control access for the following two types of URI
46: (one for files, and one for directories):
1.47 jms 47:
48: <LocationMatch "^/priv.*">
1.57 raeburn 49: <LocationMatch "^/priv.*/$">
1.47 jms 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:
1.1 albertel 77: package Apache::loncacc;
78:
79: use strict;
1.26 www 80: use Apache::Constants qw(:common :http :methods REDIRECT);
1.45 albertel 81: use Fcntl qw(:flock);
1.30 www 82: use Apache::lonlocal;
1.38 albertel 83: use Apache::lonnet;
1.45 albertel 84: use Apache::lonacc;
1.43 albertel 85: use LONCAPA qw(:DEFAULT :match);
1.1 albertel 86:
87: sub handler {
88: my $r = shift;
89: my $requrl=$r->uri;
1.38 albertel 90: $env{'request.editurl'}=$requrl;
1.46 albertel 91:
92: my $handle = &Apache::lonnet::check_for_valid_session($r);
93: if ($handle ne '') {
1.28 www 94:
95: # ------------------------------------------------------ Initialize Environment
1.46 albertel 96: my $lonidsdir=$r->dir_config('lonIDsDir');
97: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
1.30 www 98:
99: # --------------------------------------------------------- Initialize Language
100:
1.46 albertel 101: &Apache::lonlocal::get_language_handle($r);
1.28 www 102:
103: # -------------------------------------------------------------- Resource State
104:
1.46 albertel 105: $env{'request.state'} = "construct";
106: $env{'request.filename'} = $r->filename;
1.15 www 107:
1.58 raeburn 108: my $allowed;
1.60 raeburn 109: my ($ownername,$ownerdom,$ownerhome) =
110: &Apache::lonnet::constructaccess($requrl,'setpriv');
1.58 raeburn 111: if (($ownername ne '') && ($ownerdom ne '') && ($ownerhome ne '')) {
112: unless ($ownerhome eq 'no_host') {
1.59 raeburn 113: my @hosts = &Apache::lonnet::current_machine_ids();
1.58 raeburn 114: if (grep(/^\Q$ownerhome\E$/,@hosts)) {
115: $allowed = 1;
116: }
117: }
118: }
119:
120: unless ($allowed) {
1.46 albertel 121: $r->log_reason("Unauthorized $requrl", $r->filename);
122: return HTTP_NOT_ACCEPTABLE;
123: }
1.9 www 124:
125: # -------------------------------------------------------- Load POST parameters
126:
1.46 albertel 127: &Apache::lonacc::get_posted_cgi($r);
1.8 www 128:
1.46 albertel 129: return OK;
1.58 raeburn 130: } else {
1.46 albertel 131: $r->log_reason("Cookie $handle not valid", $r->filename)
1.1 albertel 132: }
1.6 www 133:
134: # ----------------------------------------------- Store where they wanted to go
135:
1.38 albertel 136: $env{'request.firsturl'}=$requrl;
1.1 albertel 137: return FORBIDDEN;
138: }
139:
140: 1;
141: __END__
142:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>