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