File:
[LON-CAPA] /
loncom /
auth /
loncacc.pm
Revision
1.40:
download - view:
text,
annotated -
select for diffs
Tue Jul 12 07:00:28 2005 UTC (19 years, 2 months ago) by
albertel
Branches:
MAIN
CVS tags:
version_2_1_X,
version_2_1_3,
version_2_1_2,
version_2_1_1,
version_2_1_0,
version_2_0_X,
version_2_0_99_1,
version_2_0_2,
version_2_0_1,
version_2_0_0,
version_1_99_3,
version_1_99_2,
HEAD
- speeding up cstr access (this was cycling through everthing in %env twice per each domain on the machine)
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.40 2005/07/12 07:00:28 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 Apache::File;
35: use CGI::Cookie();
36: use Fcntl qw(:flock);
37: use Apache::lonlocal;
38: use Apache::lonnet;
39:
40:
41: sub constructaccess {
42: my ($url,$ownerdomain)=@_;
43: my ($ownername)=($url=~/\/(?:\~|priv\/|home\/)(\w+)\//);
44: unless (($ownername) && ($ownerdomain)) { return ''; }
45: # We do not allow editing of previous versions of files.
46: if ($url=~/\.(\d+)\.(\w+)$/) { return ''; }
47: my @possibledomains = &Apache::lonnet::current_machine_domains();
48: if ($ownername eq $env{'user.name'}) {
49: foreach my $domain (@possibledomains) {
50: if ($domain eq $env{'user.domain'}) {
51: return ($ownername,$domain);
52: }
53: }
54: }
55:
56: foreach my $domain (@possibledomains) {
57: if (exists($env{'user.priv.ca./'.$domain.'/'.$ownername.'./'}) ||
58: exists($env{'user.priv.aa./'.$domain.'/'.$ownername.'./'}) ) {
59: return ($ownername,$domain);
60: }
61: }
62: return '';
63: }
64:
65: sub handler {
66: my $r = shift;
67: my $requrl=$r->uri;
68: $env{'request.editurl'}=$requrl;
69: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
70: my $lonid=$cookies{'lonID'};
71: my $cookie;
72: if ($lonid) {
73: my $handle=$lonid->value;
74: $handle=~s/\W//g;
75: my $lonidsdir=$r->dir_config('lonIDsDir');
76: if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) {
77:
78: # ------------------------------------------------------ Initialize Environment
79:
80: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
81:
82: # --------------------------------------------------------- Initialize Language
83:
84: &Apache::lonlocal::get_language_handle($r);
85:
86: # -------------------------------------------------------------- Resource State
87:
88: $env{'request.state'} = "construct";
89: $env{'request.filename'} = $r->filename;
90:
91: unless (&constructaccess($requrl,$r->dir_config('lonDefDomain'))) {
92: $r->log_reason("Unauthorized $requrl", $r->filename);
93: return HTTP_NOT_ACCEPTABLE;
94: }
95:
96: # -------------------------------------------------------- Load POST parameters
97:
98: &Apache::loncommon::get_posted_cgi($r);
99:
100: return OK;
101: } else {
102: $r->log_reason("Cookie $handle not valid", $r->filename)
103: };
104: }
105:
106: # ----------------------------------------------- Store where they wanted to go
107:
108: $env{'request.firsturl'}=$requrl;
109: return FORBIDDEN;
110: }
111:
112: 1;
113: __END__
114:
115: =head1 NAME
116:
117: Apache::lonacc - Cookie Based Access Handler for Construction Area
118:
119: =head1 SYNOPSIS
120:
121: Invoked (for various locations) by /etc/httpd/conf/loncapa_apache.conf:
122:
123: PerlAccessHandler Apache::loncacc
124:
125: =head1 INTRODUCTION
126:
127: This module enables cookie based authentication for construction area
128: and is used to control access for three (essentially equivalent) URIs.
129:
130: <LocationMatch "^/priv.*">
131: <LocationMatch "^/\~.*">
132: <LocationMatch "^/\~.*/$">
133:
134: Whenever the client sends the cookie back to the server,
135: if the cookie is missing or invalid, the user is re-challenged
136: for login information.
137:
138: This is part of the LearningOnline Network with CAPA project
139: described at http://www.lon-capa.org.
140:
141: =head1 HANDLER SUBROUTINE
142:
143: This routine is called by Apache and mod_perl.
144:
145: =over 4
146:
147: =item *
148:
149: load POST parameters
150:
151: =item *
152:
153: store where they wanted to go (first url entered)
154:
155: =back
156:
157: =head1 OTHERSUBROUTINES
158:
159: =over 4
160:
161: =item *
162:
163: constructaccess($url,$ownerdomain) : See if the owner domain and name
164: in the URL match those in the expected environment. If so, return
165: two element list ($ownername,$ownerdomain). Else, return null string.
166:
167: =back
168:
169: =cut
170:
171:
172:
173:
174:
175:
176:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>