Annotation of loncom/auth/lonacc.pm, revision 1.159.2.21.2.5
1.1 albertel 1: # The LearningOnline Network
2: # Cookie Based Access Handler
1.22 www 3: #
1.159.2.21.2. (raeburn 4:): # $Id: lonacc.pm,v 1.159.2.21.2.4 2023/01/23 00:32:03 raeburn Exp $
1.22 www 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.25 harris41 28: ###
1.1 albertel 29:
1.121 jms 30: =head1 NAME
31:
32: Apache::lonacc - Cookie Based Access Handler
33:
34: =head1 SYNOPSIS
35:
36: Invoked (for various locations) by /etc/httpd/conf/srm.conf:
37:
38: PerlAccessHandler Apache::lonacc
39:
40: =head1 INTRODUCTION
41:
42: This module enables cookie based authentication and is used
43: to control access for many different LON-CAPA URIs.
44:
45: Whenever the client sends the cookie back to the server,
46: this cookie is handled by either lonacc.pm or loncacc.pm
47: (see srm.conf for what is invoked when). If
48: the cookie is missing or invalid, the user is re-challenged
49: for login information.
50:
51: This is part of the LearningOnline Network with CAPA project
52: described at http://www.lon-capa.org.
53:
54: =head1 HANDLER SUBROUTINE
55:
56: This routine is called by Apache and mod_perl.
57:
58: =over 4
59:
60: =item *
61:
62: transfer profile into environment
63:
64: =item *
65:
66: load POST parameters
67:
68: =item *
69:
70: check access
71:
72: =item *
73:
74: if allowed, get symb, log, generate course statistics if applicable
75:
76: =item *
77:
78: otherwise return error
79:
80: =item *
81:
82: see if public resource
83:
84: =item *
85:
86: store attempted access
87:
88: =back
89:
90: =head1 NOTABLE SUBROUTINES
91:
92: =cut
93:
1.119 jms 94:
1.1 albertel 95: package Apache::lonacc;
96:
97: use strict;
1.8 www 98: use Apache::Constants qw(:common :http :methods);
1.2 www 99: use Apache::File;
1.6 www 100: use Apache::lonnet;
1.25 harris41 101: use Apache::loncommon();
1.47 www 102: use Apache::lonlocal;
1.86 albertel 103: use Apache::restrictedaccess();
1.148 raeburn 104: use Apache::blockedaccess();
1.159.2.21.2. (raeburn 105:): use Apache::lonprotected();
1.16 www 106: use Fcntl qw(:flock);
1.141 raeburn 107: use LONCAPA qw(:DEFAULT :match);
1.1 albertel 108:
1.75 albertel 109: sub cleanup {
110: my ($r)=@_;
111: if (! $r->is_initial_req()) { return DECLINED; }
112: &Apache::lonnet::save_cache();
113: return OK;
114: }
115:
116: sub goodbye {
117: my ($r)=@_;
118: &Apache::lonnet::goodbye();
119: return DONE;
120: }
121:
1.76 albertel 122: ###############################################
123:
124: sub get_posted_cgi {
1.114 raeburn 125: my ($r,$fields) = @_;
1.76 albertel 126:
127: my $buffer;
128: if ($r->header_in('Content-length')) {
129: $r->read($buffer,$r->header_in('Content-length'),0);
130: }
1.113 albertel 131: my $content_type = $r->header_in('Content-type');
132: if ($content_type !~ m{^multipart/form-data}) {
1.76 albertel 133: my @pairs=split(/&/,$buffer);
134: my $pair;
135: foreach $pair (@pairs) {
136: my ($name,$value) = split(/=/,$pair);
137: $value =~ tr/+/ /;
138: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
139: $name =~ tr/+/ /;
140: $name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.114 raeburn 141: if (ref($fields) eq 'ARRAY') {
142: next if (!grep(/^\Q$name\E$/,@{$fields}));
143: }
1.77 albertel 144: &Apache::loncommon::add_to_env("form.$name",$value);
1.76 albertel 145: }
146: } else {
1.113 albertel 147: my ($contentsep) = ($content_type =~ /boundary=\"?([^\";,]+)\"?/);
1.76 albertel 148: my @lines = split (/\n/,$buffer);
149: my $name='';
150: my $value='';
151: my $fname='';
152: my $fmime='';
153: my $i;
154: for ($i=0;$i<=$#lines;$i++) {
1.113 albertel 155: if ($lines[$i]=~/^--\Q$contentsep\E/) {
1.76 albertel 156: if ($name) {
1.139 raeburn 157: chomp($value);
158: if (($r->uri eq '/adm/portfolio') &&
159: ($name eq 'uploaddoc')) {
160: if (length($value) == 1) {
161: $value=~s/[\r\n]$//;
162: }
1.159.2.21 raeburn 163: }
164: if ($fname =~ /\.(xls|doc|ppt)(x|m)$/i) {
1.154 raeburn 165: $value=~s/[\r\n]$//;
1.139 raeburn 166: }
1.114 raeburn 167: if (ref($fields) eq 'ARRAY') {
168: next if (!grep(/^\Q$name\E$/,@{$fields}));
169: }
1.118 raeburn 170: if ($fname) {
171: if ($env{'form.symb'} ne '') {
172: my $size = (length($value))/(1024.0 * 1024.0);
173: if (&upload_size_allowed($name,$size,$fname) eq 'ok') {
174: $env{"form.$name.filename"}=$fname;
175: $env{"form.$name.mimetype"}=$fmime;
176: &Apache::loncommon::add_to_env("form.$name",$value);
177: }
178: } else {
179: $env{"form.$name.filename"}=$fname;
180: $env{"form.$name.mimetype"}=$fmime;
181: &Apache::loncommon::add_to_env("form.$name",$value);
182: }
183: } else {
184: $value=~s/\s+$//s;
185: &Apache::loncommon::add_to_env("form.$name",$value);
186: }
1.76 albertel 187: }
188: if ($i<$#lines) {
189: $i++;
190: $lines[$i]=~
191: /Content\-Disposition\:\s*form\-data\;\s*name\=\"([^\"]+)\"/i;
192: $name=$1;
193: $value='';
194: if ($lines[$i]=~/filename\=\"([^\"]+)\"/i) {
195: $fname=$1;
196: if
197: ($lines[$i+1]=~/Content\-Type\:\s*([\w\-\/]+)/i) {
198: $fmime=$1;
199: $i++;
200: } else {
201: $fmime='';
202: }
203: } else {
204: $fname='';
205: $fmime='';
206: }
207: $i++;
208: }
209: } else {
210: $value.=$lines[$i]."\n";
211: }
212: }
213: }
214: #
215: # Digested POSTed values
216: #
217: # Remember the way this was originally done (GET or POST)
218: #
219: $env{'request.method'}=$ENV{'REQUEST_METHOD'};
220: #
221: # There may also be stuff in the query string
222: # Tell subsequent handlers that this was GET, not POST, so they can access query string.
223: # Also, unset POSTed content length to cover all tracks.
224: #
225:
226: $r->method_number(M_GET);
227:
228: $r->method('GET');
229: $r->headers_in->unset('Content-length');
230: }
231:
1.121 jms 232: =pod
233:
1.146 raeburn 234: =over
235:
1.121 jms 236: =item upload_size_allowed()
237:
238: Perform size checks for file uploads to essayresponse items in course context.
239:
240: Add form.HWFILESIZE.$part_$id to %env with file size (MB)
241: If file exceeds maximum allowed size, add form.HWFILETOOBIG.$part_$id to %env.
242:
243: =cut
1.118 raeburn 244:
245: sub upload_size_allowed {
246: my ($name,$size,$fname) = @_;
247: if ($name =~ /^HWFILE(\w+)$/) {
248: my $ident = $1;
249: my $item = 'HWFILESIZE'.$ident;
1.122 raeburn 250: my $savesize = sprintf("%.6f",$size);
251: &Apache::loncommon::add_to_env("form.$item",$savesize);
1.118 raeburn 252: my $maxsize= &Apache::lonnet::EXT("resource.$ident.maxfilesize");
253: if (!$maxsize) {
1.123 raeburn 254: $maxsize = 10.0; # FIXME This should become a domain configuration.
1.118 raeburn 255: }
256: if ($size > $maxsize) {
257: my $warn = 'HWFILETOOBIG'.$ident;
258: &Apache::loncommon::add_to_env("form.$warn",$fname);
259: return;
260: }
261: }
262: return 'ok';
263: }
264:
1.121 jms 265: =pod
266:
267: =item sso_login()
268:
269: handle the case of the single sign on user, at this point $r->user
1.150 raeburn 270: will be set and valid; now need to find the loncapa user info, and possibly
1.149 raeburn 271: balance them. If $r->user() is set this means either it was either set by
1.150 raeburn 272: SSO or by checkauthen.pm, if a valid cookie was found. The latter case can
273: be identified by the third arg ($usename), except when lonacc is called in
274: an internal redirect to /adm/switchserver (e.g., load-balancing following
275: successful authentication) -- no cookie set yet. For that particular case
1.159.2.21.2. (raeburn 276:): simply skip the call to sso_login().
1.149 raeburn 277:
278: returns OK if it was SSO and user was handled.
279: returns undef if not SSO or no means to handle the user.
1.159.2.21.2. (raeburn 280:):
281:): In the case where the session was started from /adm/launch/tiny/$domain/$id,
282:): i.e., for a protected link, with launch from another CMS, and user information
283:): is accepted from the LTI payload, then, if the user has privileged roles,
284:): authentication will be required. If SSO authentication is with a username
285:): and/or domain that differ from the username in the LTI payload and domain
286:): in the launch URL, then $r->user() will be unset and /adm/relaunch will be
287:): called.
1.121 jms 288:
289: =cut
1.117 jms 290:
1.94 albertel 291: sub sso_login {
1.149 raeburn 292: my ($r,$handle,$username) = @_;
1.94 albertel 293:
1.156 raeburn 294: if (($r->user eq '') || ($username ne '') || ($r->user eq 'public:public') ||
1.143 raeburn 295: (defined($env{'user.name'}) && (defined($env{'user.domain'}))
296: && ($handle ne ''))) {
1.94 albertel 297: # not an SSO case or already logged in
298: return undef;
299: }
300:
1.159.2.1 raeburn 301: my ($user) = ($r->user =~ m/^($match_username)$/);
302: if ($user eq '') {
303: return undef;
304: }
1.97 albertel 305:
1.126 raeburn 306: my $query = $r->args;
307: my %form;
308: if ($query) {
1.159.2.21.2. (raeburn 309:): my @items = ('role','symb','iptoken','origurl','ttoken',
310:): 'ltoken','linkkey','logtoken','sso','lcssowin');
1.127 raeburn 311: &Apache::loncommon::get_unprocessed_cgi($query,\@items);
312: foreach my $item (@items) {
313: if (defined($env{'form.'.$item})) {
314: $form{$item} = $env{'form.'.$item};
1.126 raeburn 315: }
316: }
317: }
318:
1.145 raeburn 319: my %sessiondata;
320: if ($form{'iptoken'}) {
321: %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
1.158 raeburn 322: my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
323: unless ($sessiondata{'sessionserver'}) {
324: delete($form{'iptoken'});
325: }
1.145 raeburn 326: }
327:
1.159.2.21.2. (raeburn 328:): my ($linkprot,$linkprotuser,$linkprotexit,$linkkey,$deeplinkurl,
329:): $linkprotpbid,$linkprotpburl);
330:):
1.159.2.21 raeburn 331: #
332: # If Shibboleth auth is in use, and a dual SSO and non-SSO login page
333: # is in use, then the query string will contain the logtoken item with
334: # a value set to the name of a .tmp file in /home/httpd/perl/tmp
335: # containing the url to display after authentication, and also,
1.159.2.21.2. (raeburn 336:): # optionally, role and symb, or linkprot or linkkey (deep-link access).
337:): #
338:): # If Shibboleth auth is in use, but a dual log-in page is not in use,
339:): # and the originally requested URL was /tiny/$domain/$id (i.e.,
340:): # for deeplinking), then the query string will contain the sso item
341:): # with a value set to the name of a .tmp file in /home/httpd/perl/tmp
342:): # containing the url to display after authentication, and also,
343:): # optionally, linkprot or linkkey (deep-link access).
344:): #
345:): # Otherwise the query string may contain role and symb, or if the
346:): # originally requested URL was /tiny/$domain/$id (i.e. for deeplinking)
347:): # then the query string may contain a ttoken item with a value set
348:): # to the name of a .tmp file in /home/httpd/perl/tmp containing either
349:): # linkprot or linkkey (deep-link access).
1.159.2.21 raeburn 350: #
1.159.2.21.2. (raeburn 351:): # If deep-linked, i.e., the originally requested URL was /tiny/$domain/$id
352:): # the linkkey may have originally been sent in POSTed data, which will
353:): # have been processed in lontrans.pm
1.159.2.21 raeburn 354: #
355:
1.159.2.21.2. (raeburn 356:): if ($form{'ttoken'}) {
357:): my %info = &Apache::lonnet::tmpget($form{'ttoken'});
358:): &Apache::lonnet::tmpdel($form{'ttoken'});
359:): if ($info{'origurl'}) {
360:): $form{'origurl'} = $info{'origurl'};
361:): if ($form{'origurl'} =~ m{^/tiny/$match_domain/\w+$}) {
362:): $deeplinkurl = $form{'origurl'};
363:): }
364:): }
365:): if ($info{'linkprot'}) {
366:): $linkprot = $info{'linkprot'};
367:): $linkprotuser = $info{'linkprotuser'};
368:): $linkprotexit = $info{'linkprotexit'};
369:): $linkprotpbid = $info{'linkprotpbid'};
370:): $linkprotpburl = $info{'linkprotpburl'};
371:): } elsif ($info{'linkkey'} ne '') {
372:): $linkkey = $info{'linkkey'};
373:): }
374:): } elsif ($form{'logtoken'}) {
1.159.2.21 raeburn 375: my ($firsturl,@rest);
376: my $lonhost = $r->dir_config('lonHostID');
377: my $tmpinfo = &Apache::lonnet::reply('tmpget:'.$form{'logtoken'},$lonhost);
378: my $delete = &Apache::lonnet::tmpdel($form{'logtoken'});
379: unless (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||
380: ($tmpinfo eq 'no_such_host')) {
381: (undef,$firsturl,@rest) = split(/&/,$tmpinfo);
382: if ($firsturl ne '') {
383: $firsturl = &unescape($firsturl);
384: }
385: foreach my $item (@rest) {
386: my ($key,$value) = split(/=/,$item);
387: $form{$key} = &unescape($value);
388: }
1.159.2.21.2. (raeburn 389:): if ($firsturl =~ m{^/tiny/$match_domain/\w+$}) {
390:): $form{'origurl'} = $firsturl;
391:): $deeplinkurl = $firsturl;
392:): } elsif ($firsturl eq '/adm/email') {
393:): $form{'origurl'} = $firsturl;
394:): }
395:): if ($form{'linkprot'}) {
396:): $linkprot = $form{'linkprot'};
397:): $linkprotuser = $form{'linkprotuser'};
398:): $linkprotexit = $form{'linkprotexit'};
399:): $linkprotpbid = $form{'linkprotpbid'};
400:): $linkprotpburl = $form{'linkprotpburl'};
401:): } elsif ($form{'linkkey'} ne '') {
402:): $linkkey = $form{'linkkey'};
403:): }
1.159.2.21 raeburn 404: if ($form{'iptoken'}) {
405: %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
406: my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
407: }
408: }
1.159.2.21.2. (raeburn 409:): } elsif ($form{'sso'}) {
410:): my $lonhost = $r->dir_config('lonHostID');
411:): my $info = &Apache::lonnet::reply('tmpget:'.$form{'sso'},$lonhost);
412:): &Apache::lonnet::tmpdel($form{'sso'});
413:): unless (($info=~/^error/) || ($info eq 'con_lost') ||
414:): ($info eq 'no_such_host')) {
415:): my ($firsturl,@rest)=split(/\&/,$info);
416:): if ($firsturl ne '') {
417:): $form{'origurl'} = &unescape($firsturl);
418:): if ($form{'origurl'} =~ m{^/tiny/$match_domain/\w+$}) {
419:): $deeplinkurl = $form{'origurl'};
420:): }
421:): }
422:): foreach my $item (@rest) {
423:): my ($key,$value) = split(/=/,$item);
424:): $form{$key} = &unescape($value);
425:): }
426:): if ($form{'linkprot'}) {
427:): $linkprot = $form{'linkprot'};
428:): $linkprotuser = $form{'linkprotuser'};
429:): $linkprotexit = $form{'linkprotexit'};
430:): $linkprotpbid = $form{'linkprotpbid'};
431:): $linkprotpburl = $form{'linkprotpburl'};
432:): } elsif ($form{'linkkey'} ne '') {
433:): $linkkey = $form{'linkkey'};
434:): }
435:): }
436:): } elsif ($form{'ltoken'}) {
437:): my %link_info = &Apache::lonnet::tmpget($form{'ltoken'});
438:): $linkprot = $link_info{'linkprot'};
439:): if ($linkprot) {
440:): if ($link_info{'linkprotuser'} ne '') {
441:): $linkprotuser = $link_info{'linkprotuser'};
442:): }
443:): if ($link_info{'linkprotexit'} ne '') {
444:): $linkprotexit = $link_info{'linkprotexit'};
445:): }
446:): if ($link_info{'linkprotpbid'} ne '') {
447:): $linkprotpbid = $link_info{'linkprotpbid'};
448:): }
449:): if ($link_info{'linkprotpburl'} ne '') {
450:): $linkprotpburl = $link_info{'linkprotpburl'};
451:): }
452:): }
453:): my $delete = &Apache::lonnet::tmpdel($form{'ltoken'});
454:): delete($form{'ltoken'});
455:): if ($form{'origurl'} =~ m{^/tiny/$match_domain/\w+$}) {
456:): $deeplinkurl = $form{'origurl'};
457:): }
458:): } elsif ($form{'linkkey'} ne '') {
459:): $linkkey = $form{'linkkey'};
1.159.2.21 raeburn 460: }
461:
1.136 raeburn 462: my $domain = $r->dir_config('lonSSOUserDomain');
463: if ($domain eq '') {
464: $domain = $r->dir_config('lonDefDomain');
465: }
1.159.2.21.2. (raeburn 466:): if (($deeplinkurl) && ($linkprot) && ($linkprotuser ne '')) {
467:): unless ($linkprotuser eq $user.':'.$domain) {
468:): $r->user();
469:): my %data = (
470:): origurl => $deeplinkurl,
471:): linkprot => $linkprot,
472:): linkprotuser => $linkprotuser,
473:): linkprotexit => $linkprotexit,
474:): linkprotpbid => $linkprotpbid,
475:): linkprotpburl => $linkprotpburl,
476:): );
477:): if ($env{'form.lcssowin'}) {
478:): $data{'lcssowin'} = $env{'form.lcssowin'};
479:): }
480:): my $token = &Apache::lonnet::tmpput(\%data,$r->dir_config('lonHostID'),'link');
481:): unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
482:): ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
483:): $r->internal_redirect('/adm/relaunch?rtoken='.$token);
484:): $r->set_handlers('PerlHandler'=> undef);
485:): return OK;
486:): }
487:): }
488:): }
1.97 albertel 489: my $home=&Apache::lonnet::homeserver($user,$domain);
1.94 albertel 490: if ($home !~ /(con_lost|no_host|no_such_host)/) {
1.107 albertel 491: &Apache::lonnet::logthis(" SSO authorized user $user ");
1.145 raeburn 492: my ($is_balancer,$otherserver,$hosthere);
493: if ($form{'iptoken'}) {
1.158 raeburn 494: if (($sessiondata{'domain'} eq $domain) &&
495: ($sessiondata{'username'} eq $user)) {
1.145 raeburn 496: $hosthere = 1;
497: }
498: }
499: unless ($hosthere) {
500: ($is_balancer,$otherserver) =
1.159.2.5 raeburn 501: &Apache::lonnet::check_loadbalancing($user,$domain,'login');
502: if ($is_balancer) {
1.159.2.8 raeburn 503: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
504: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r);
505: if (($found_server) && ($balancer_cookie =~ /^\Q$domain\E_\Q$user\E_/)) {
506: $otherserver = $found_server;
507: } elsif ($otherserver eq '') {
1.159.2.5 raeburn 508: my $lowest_load;
509: ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($domain);
510: if ($lowest_load > 100) {
1.159.2.21 raeburn 511: $otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$domain);
1.159.2.5 raeburn 512: }
1.159.2.8 raeburn 513: if ($otherserver ne '') {
514: my @hosts = &Apache::lonnet::current_machine_ids();
515: if (grep(/^\Q$otherserver\E$/,@hosts)) {
516: $hosthere = $otherserver;
517: }
1.159.2.5 raeburn 518: }
519: }
520: }
1.145 raeburn 521: }
1.159.2.5 raeburn 522: if (($is_balancer) && (!$hosthere)) {
1.136 raeburn 523: # login but immediately go to switch server to find us a new
1.94 albertel 524: # machine
1.127 raeburn 525: &Apache::lonauth::success($r,$user,$domain,$home,'noredirect');
1.159.2.21 raeburn 526: foreach my $item (keys(%form)) {
527: $env{'form.'.$item} = $form{$item};
528: }
529: unless (($form{'symb'}) || ($form{'origurl'})) {
530: unless (($r->uri eq '/adm/roles') || ($r->uri eq '/adm/sso')) {
531: $env{'form.origurl'} = $r->uri;
532: }
533: }
1.159.2.21.2. (raeburn 534:): if (($r->uri eq '/adm/sso') && ($form{'origurl'} =~ m{^/+tiny/+$match_domain/+\w+$})) {
535:): $env{'request.deeplink.login'} = $form{'origurl'};
536:): } elsif ($r->uri =~ m{^/+tiny/+$match_domain/+\w+$}) {
537:): $env{'request.deeplink.login'} = $r->uri;
538:): }
539:): if ($env{'request.deeplink.login'}) {
540:): if ($linkprot) {
541:): $env{'request.linkprot'} = $linkprot;
542:): if ($linkprotuser ne '') {
543:): $env{'request.linkprotuser'} = $linkprotuser;
544:): }
545:): if ($linkprotexit ne '') {
546:): $env{'request.linkprotexit'} = $linkprotexit;
547:): }
548:): if ($linkprotpbid ne '') {
549:): $env{'request.linkprotpbid'} = $linkprotpbid;
550:): }
551:): if ($linkprotpburl ne '') {
552:): $env{'request.linkprotpburl'} = $linkprotpburl;
553:): }
554:): } elsif ($linkkey ne '') {
555:): $env{'request.linkkey'} = $linkkey;
556:): }
557:): }
558:): if (($r->uri eq '/adm/sso') && ($form{'origurl'} eq '/adm/email')) {
559:): if ($form{'display'} && ($env{'form.mailrecip'} eq $user.':'.$domain)) {
560:): $env{'request.display'} = $form{'display'};
561:): $env{'request.mailrecip'} = $env{'form.mailrecip'};
562:): }
563:): }
1.105 raeburn 564: $env{'request.sso.login'} = 1;
1.106 raeburn 565: if (defined($r->dir_config("lonSSOReloginServer"))) {
566: $env{'request.sso.reloginserver'} =
567: $r->dir_config('lonSSOReloginServer');
568: }
1.137 raeburn 569: my $redirecturl = '/adm/switchserver';
570: if ($otherserver ne '') {
571: $redirecturl .= '?otherserver='.$otherserver;
572: }
1.159.2.21.2. (raeburn 573:): if ($form{'lcssowin'}) {
574:): $redirecturl .= (($redirecturl=~/\?/)?'&':'?') . 'lcssowin=1';
575:): }
1.137 raeburn 576: $r->internal_redirect($redirecturl);
1.101 albertel 577: $r->set_handlers('PerlHandler'=> undef);
1.94 albertel 578: } else {
579: # need to login them in, so generate the need data that
580: # migrate expects to do login
1.159.2.18 raeburn 581: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.147 raeburn 582: my %info=('ip' => $ip,
1.94 albertel 583: 'domain' => $domain,
1.97 albertel 584: 'username' => $user,
1.94 albertel 585: 'server' => $r->dir_config('lonHostID'),
586: 'sso.login' => 1
587: );
1.159.2.21.2. (raeburn 588:): foreach my $item ('role','symb','iptoken','origurl','lcssowin') {
1.126 raeburn 589: if (exists($form{$item})) {
590: $info{$item} = $form{$item};
1.159.2.21 raeburn 591: } elsif ($sessiondata{$item} ne '') {
592: $info{$item} = $sessiondata{$item};
1.126 raeburn 593: }
594: }
1.159.2.21 raeburn 595: unless (($info{'symb'}) || ($info{'origurl'})) {
1.152 raeburn 596: unless (($r->uri eq '/adm/roles') || ($r->uri eq '/adm/sso')) {
1.151 raeburn 597: $info{'origurl'} = $r->uri;
598: }
599: }
1.159.2.21.2. (raeburn 600:): if (($r->uri eq '/adm/sso') && ($form{'origurl'} =~ m{^/+tiny/+$match_domain/+\w+$})) {
601:): $info{'deeplink.login'} = $form{'origurl'};
602:): } elsif ($r->uri =~ m{^/+tiny/+$match_domain/+\w+$}) {
603:): $info{'deeplink.login'} = $r->uri;
604:): }
605:): if ($info{'deeplink.login'}) {
606:): if ($linkprot) {
607:): $info{'linkprot'} = $linkprot;
608:): if ($linkprotuser ne '') {
609:): $info{'linkprotuser'} = $linkprotuser;
610:): }
611:): if ($linkprotexit ne '') {
612:): $info{'linkprotexit'} = $linkprotexit;
613:): }
614:): if ($linkprotpbid ne '') {
615:): $info{'linkprotpbid'} = $linkprotpbid;
616:): }
617:): if ($linkprotpburl ne '') {
618:): $info{'linkprotpburl'} = $linkprotpburl;
619:): }
620:): } elsif ($linkkey ne '') {
621:): $info{'linkkey'} = $linkkey;
622:): }
623:): }
624:): if (($r->uri eq '/adm/sso') && ($form{'origurl'} eq '/adm/email')) {
625:): if ($form{'display'} && ($form{'mailrecip'} eq $user.':'.$domain)) {
626:): $info{'display'} = &escape($form{'display'});
627:): $info{'mailrecip'} = &escape($form{'mailrecip'});
628:): }
629:): }
1.116 raeburn 630: if ($r->dir_config("ssodirecturl") == 1) {
631: $info{'origurl'} = $r->uri;
632: }
1.106 raeburn 633: if (defined($r->dir_config("lonSSOReloginServer"))) {
634: $info{'sso.reloginserver'} =
635: $r->dir_config('lonSSOReloginServer');
636: }
1.159.2.5 raeburn 637: if (($is_balancer) && ($hosthere)) {
638: $info{'noloadbalance'} = $hosthere;
639: }
1.159.2.21.2. (raeburn 640:): my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'sso');
1.94 albertel 641: $env{'form.token'} = $token;
642: $r->internal_redirect('/adm/migrateuser');
1.101 albertel 643: $r->set_handlers('PerlHandler'=> undef);
1.94 albertel 644: }
645: return OK;
1.155 raeburn 646: } else {
1.107 albertel 647: &Apache::lonnet::logthis(" SSO authorized unknown user $user ");
1.115 raeburn 648: my @cancreate;
649: my %domconfig =
650: &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
651: if (ref($domconfig{'usercreation'}) eq 'HASH') {
652: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
653: if (ref($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
654: @cancreate = @{$domconfig{'usercreation'}{'cancreate'}{'selfcreate'}};
655: } elsif (($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') &&
656: ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne '')) {
657: @cancreate = ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'});
658: }
659: }
660: }
1.155 raeburn 661: if ((grep(/^sso$/,@cancreate)) || (defined($r->dir_config('lonSSOUserUnknownRedirect')))) {
662: $r->subprocess_env->set('SSOUserUnknown' => $user);
663: $r->subprocess_env->set('SSOUserDomain' => $domain);
664: if (grep(/^sso$/,@cancreate)) {
1.159.2.21.2. (raeburn 665:): #FIXME - need to preserve origurl, role and symb, or linkprot or linkkey for use after account
666:): # creation. If lcssowin is 1, createaccount needs to close pop-up and display in main window.
1.155 raeburn 667: $r->set_handlers('PerlHandler'=> [\&Apache::createaccount::handler]);
668: $r->handler('perl-script');
669: } else {
670: $r->internal_redirect($r->dir_config('lonSSOUserUnknownRedirect'));
671: $r->set_handlers('PerlHandler'=> undef);
672: }
673: return OK;
1.115 raeburn 674: }
1.94 albertel 675: }
676: return undef;
677: }
678:
1.1 albertel 679: sub handler {
680: my $r = shift;
681: my $requrl=$r->uri;
1.149 raeburn 682:
683: if ($requrl =~ m{^/res/adm/pages/[^/]+\.(gif|png)$}) {
1.108 raeburn 684: return OK;
685: }
1.70 albertel 686:
1.149 raeburn 687: if (&Apache::lonnet::is_domainimage($requrl)) {
1.124 raeburn 688: return OK;
689: }
690:
1.149 raeburn 691: my %user;
692: my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user);
1.93 albertel 693:
1.150 raeburn 694: unless (($requrl eq '/adm/switchserver') && (!$r->is_initial_req())) {
695: my $result = &sso_login($r,$handle,$user{'name'});
696: if (defined($result)) {
697: return $result;
698: }
1.70 albertel 699: }
700:
1.137 raeburn 701: my ($is_balancer,$otherserver);
1.142 raeburn 702:
1.92 albertel 703: if ($handle eq '') {
1.159 raeburn 704: unless ((($requrl eq '/adm/switchserver') && (!$r->is_initial_req())) ||
705: ($requrl =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.159.2.21 raeburn 706: ($requrl =~ m{^/adm/help/}) || ($requrl eq '/adm/sso') ||
1.159 raeburn 707: ($requrl =~ m{^/res/$match_domain/$match_username/})) {
1.149 raeburn 708: $r->log_reason("Cookie not valid", $r->filename);
1.142 raeburn 709: }
1.111 albertel 710: } elsif ($handle ne '') {
1.6 www 711:
1.46 www 712: # ------------------------------------------------------ Initialize Environment
1.111 albertel 713: my $lonidsdir=$r->dir_config('lonIDsDir');
1.92 albertel 714: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
1.47 www 715:
716: # --------------------------------------------------------- Initialize Language
717:
1.92 albertel 718: &Apache::lonlocal::get_language_handle($r);
719:
720: }
1.46 www 721:
1.92 albertel 722: # -------------------------------------------------- Should be a valid user now
723: if ($env{'user.name'} ne '' && $env{'user.domain'} ne '') {
1.46 www 724: # -------------------------------------------------------------- Resource State
1.6 www 725:
1.141 raeburn 726: my ($cdom,$cnum);
727: if ($env{'request.course.id'}) {
728: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
729: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
730: }
1.92 albertel 731: if ($requrl=~/^\/+(res|uploaded)\//) {
732: $env{'request.state'} = "published";
733: } else {
734: $env{'request.state'} = 'unknown';
735: }
736: $env{'request.filename'} = $r->filename;
737: $env{'request.noversionuri'} = &Apache::lonnet::deversion($requrl);
1.157 raeburn 738: my ($suppext,$checkabsolute);
1.129 raeburn 739: if ($requrl =~ m{^/adm/wrapper/ext/}) {
740: my $query = $r->args;
741: if ($query) {
742: my $preserved;
743: foreach my $pair (split(/&/,$query)) {
744: my ($name, $value) = split(/=/,$pair);
1.159.2.7 raeburn 745: unless (($name eq 'symb') || ($name eq 'usehttp')) {
1.129 raeburn 746: $preserved .= $pair.'&';
747: }
1.141 raeburn 748: if (($env{'request.course.id'}) && ($name eq 'folderpath')) {
749: if ($value =~ /^supplemental/) {
750: $suppext = 1;
751: }
752: }
1.129 raeburn 753: }
754: $preserved =~ s/\&$//;
755: if ($preserved) {
756: $env{'request.external.querystring'} = $preserved;
757: }
758: }
1.157 raeburn 759: if ($env{'request.course.id'}) {
760: $checkabsolute = 1;
761: }
1.141 raeburn 762: } elsif ($env{'request.course.id'} &&
763: (($requrl =~ m{^/adm/$match_domain/$match_username/aboutme$}) ||
1.159.2.21.2. (raeburn 764:): ($requrl eq "/public/$cdom/$cnum/syllabus") ||
765:): ($requrl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}))) {
1.141 raeburn 766: my $query = $r->args;
767: if ($query) {
768: foreach my $pair (split(/&/,$query)) {
769: my ($name, $value) = split(/=/,$pair);
770: if ($name eq 'folderpath') {
771: if ($value =~ /^supplemental/) {
772: $suppext = 1;
773: }
1.159.2.12 raeburn 774: last;
1.141 raeburn 775: }
776: }
777: }
1.157 raeburn 778: if ($requrl =~ m{^/public/$cdom/$cnum/syllabus$}) {
779: $checkabsolute = 1;
780: }
781: }
782: if ($checkabsolute) {
783: my $hostname = $r->hostname();
784: my $lonhost = &Apache::lonnet::host_from_dns($hostname);
785: if ($lonhost) {
1.159.2.21 raeburn 786: my $actual = &Apache::lonnet::absolute_url($hostname,1,1);
1.157 raeburn 787: my $expected = $Apache::lonnet::protocol{$lonhost}.'://'.$hostname;
788: unless ($actual eq $expected) {
789: $env{'request.use_absolute'} = $expected;
790: }
791: }
1.129 raeburn 792: }
1.6 www 793: # -------------------------------------------------------- Load POST parameters
794:
1.92 albertel 795: &Apache::lonacc::get_posted_cgi($r);
1.6 www 796:
1.137 raeburn 797: # ------------------------------------------------------ Check if load balancer
798:
1.138 raeburn 799: my $checkexempt;
800: if ($env{'user.loadbalexempt'} eq $r->dir_config('lonHostID')) {
801: if ($env{'user.loadbalcheck.time'} + 600 > time) {
1.159.2.8 raeburn 802: $checkexempt = 1;
1.138 raeburn 803: }
804: }
1.145 raeburn 805: if ($env{'user.noloadbalance'} eq $r->dir_config('lonHostID')) {
806: $checkexempt = 1;
807: }
1.159.2.15 raeburn 808: unless (($checkexempt) || (($requrl eq '/adm/switchserver') && (!$r->is_initial_req()))) {
1.138 raeburn 809: ($is_balancer,$otherserver) =
810: &Apache::lonnet::check_loadbalancing($env{'user.name'},
811: $env{'user.domain'});
1.159.2.8 raeburn 812: if ($is_balancer) {
1.159.2.15 raeburn 813: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
814: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r);
815: if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) {
816: $otherserver = $found_server;
817: }
818: unless ($requrl eq '/adm/switchserver') {
819: $r->set_handlers('PerlResponseHandler'=>
820: [\&Apache::switchserver::handler]);
1.159.2.8 raeburn 821: }
822: if ($otherserver ne '') {
823: $env{'form.otherserver'} = $otherserver;
824: }
1.159.2.15 raeburn 825: unless (($env{'form.origurl'}) || ($r->uri eq '/adm/roles') ||
826: ($r->uri eq '/adm/switchserver') || ($r->uri eq '/adm/sso')) {
827: $env{'form.origurl'} = $r->uri;
828: }
1.152 raeburn 829: }
1.137 raeburn 830: }
1.159.2.21.2. (raeburn 831:): if ($requrl=~m{^/+tiny/+$match_domain/+\w+$}) {
832:): if ($r->args) {
833:): &Apache::loncommon::get_unprocessed_cgi($r->args,['ttoken']);
834:): if (defined($env{'form.ttoken'})) {
835:): my %info = &Apache::lonnet::tmpget($env{'form.ttoken'});
836:): if (($info{'origurl'} ne '') && ($info{'origurl'} eq $requrl)) {
837:): my %data;
838:): if (($info{'linkprotuser'} ne '') && ($info{'linkprot'}) &&
839:): ($info{'linkprotuser'} ne $env{'user.name'}.':'.$env{'user.domain'})) {
840:): %data = (
841:): origurl => $requrl,
842:): linkprot => $info{'linkprot'},
843:): linkprotuser => $info{'linkprotuser'},
844:): linkprotexit => $info{'linkprotexit'},
845:): linkprotpbid => $info{'linkprotpbid'},
846:): linkprotpburl => $info{'linkprotpburl'},
847:): );
848:): } elsif ($info{'ltoken'} ne '') {
849:): my %ltoken_info = &Apache::lonnet::tmpget($info{'ltoken'});
850:): if (($ltoken_info{'linkprotuser'} ne '') && ($ltoken_info{'linkprot'}) &&
851:): ($ltoken_info{'linkprotuser'} ne $env{'user.name'}.':'.$env{'user.domain'})) {
852:): %data = (
853:): origurl => $requrl,
854:): linkprot => $ltoken_info{'linkprot'},
855:): linkprotuser => $ltoken_info{'linkprotuser'},
856:): linkprotexit => $ltoken_info{'linkprotexit'},
857:): linkprotpbid => $ltoken_info{'linkprotpbid'},
858:): linkprotpburl => $ltoken_info{'linkprotpburl'},
859:): );
860:): }
861:): }
862:): if (keys(%data)) {
863:): my $delete = &Apache::lonnet::tmpdel($env{'form.ttoken'});
864:): if ($info{'ltoken'} ne '') {
865:): my $delete = &Apache::lonnet::tmpdel($info{'ltoken'});
866:): }
867:): my $token =
868:): &Apache::lonnet::tmpput(\%data,$r->dir_config('lonHostID'),'retry');
869:): unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
870:): ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
871:): $r->internal_redirect('/adm/relaunch?rtoken='.$token);
872:): $r->set_handlers('PerlHandler'=> undef);
873:): return OK;
874:): }
875:): }
876:): }
877:): }
878:): }
879:): if ($env{'user.name'} eq 'public' &&
880:): $env{'user.domain'} eq 'public') {
881:): $env{'request.firsturl'}=$requrl;
882:): return FORBIDDEN;
883:): }
884:): return OK;
885:): }
1.6 www 886: # ---------------------------------------------------------------- Check access
1.92 albertel 887: my $now = time;
1.159.2.17 raeburn 888: my ($check_symb,$check_access,$check_block,$access,$poss_symb);
1.159.2.10 raeburn 889: if ($requrl !~ m{^/(?:adm|public|(?:prt|zip)spool)/}
1.95 albertel 890: || $requrl =~ /^\/adm\/.*\/(smppg|bulletinboard)(\?|$ )/x) {
1.159.2.16 raeburn 891: $check_access = 1;
892: }
1.159.2.17 raeburn 893: if ((!$check_access) && ($env{'request.course.id'})) {
894: if (($requrl eq '/adm/viewclasslist') ||
895: ($requrl =~ m{^(/adm/wrapper|)\Q/uploaded/$cdom/$cnum/docs/\E}) ||
896: ($requrl =~ m{^/adm/.*/aboutme$}) ||
1.159.2.21.2. (raeburn 897:): ($requrl=~m{^/adm/coursedocs/showdoc/}) ||
898:): ($requrl=~m{^(/adm/wrapper|)/adm/$cdom/$cnum/\d+/ext\.tool$})) {
1.159.2.17 raeburn 899: $check_block = 1;
900: }
901: }
1.159.2.16 raeburn 902: if (($env{'request.course.id'}) && (!$suppext)) {
903: $requrl=~/\.(\w+)$/;
904: if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
905: ($requrl=~/^\/adm\/.*\/(aboutme|smppg|bulletinboard)(\?|$ )/x) ||
906: ($requrl=~/^\/adm\/wrapper\//) ||
907: ($requrl=~m|^/adm/coursedocs/showdoc/|) ||
908: ($requrl=~m|\.problem/smpedit$|) ||
909: ($requrl=~/^\/public\/.*\/syllabus$/) ||
910: ($requrl=~/^\/adm\/(viewclasslist|navmaps)$/) ||
1.159.2.21.2. (raeburn 911:): ($requrl=~/^\/adm\/.*\/aboutme\/portfolio(\?|$)/) ||
912:): ($requrl=~m{^/adm/$cdom/$cnum/\d+/ext\.tool$})) {
1.159.2.16 raeburn 913: $check_symb = 1;
1.159.2.12 raeburn 914: }
1.159.2.16 raeburn 915: }
1.159.2.17 raeburn 916: if (($check_access) || ($check_block)) {
1.159.2.12 raeburn 917: if ($check_symb) {
1.159.2.11 raeburn 918: if ($env{'form.symb'}) {
919: $poss_symb=&Apache::lonnet::symbclean($env{'form.symb'});
1.159.2.12 raeburn 920: } elsif (($env{'request.course.id'}) && ($r->args ne '')) {
921: my $query = $r->args;
922: foreach my $pair (split(/&/,$query)) {
923: my ($name, $value) = split(/=/,$pair);
1.159.2.13 raeburn 924: $name = &unescape($name);
925: $value =~ tr/+/ /;
926: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.159.2.12 raeburn 927: if ($name eq 'symb') {
928: $poss_symb = &Apache::lonnet::symbclean($value);
929: last;
930: }
931: }
1.159.2.11 raeburn 932: }
933: if ($poss_symb) {
934: my ($possmap,$resid,$url)=&Apache::lonnet::decode_symb($poss_symb);
935: $url = &Apache::lonnet::clutter($url);
1.159.2.17 raeburn 936: my $toplevelmap = $env{'course.'.$env{'request.course.id'}.'.url'};
937: unless (($url eq $requrl) && (($possmap eq $toplevelmap) ||
938: (&Apache::lonnet::is_on_map($possmap)))) {
1.159.2.11 raeburn 939: undef($poss_symb);
940: }
941: if ($poss_symb) {
942: if ((!$env{'request.role.adv'}) && ($env{'acc.randomout'}) &&
943: ($env{'acc.randomout'}=~/\&\Q$poss_symb\E\&/)) {
944: undef($poss_symb);
1.159.2.21.2. (raeburn 945:): } elsif ((!$env{'request.role.adv'}) && ($env{'acc.deeplinkout'}) &&
946:): ($env{'acc.deeplinkout'}=~/\&\Q$poss_symb\E\&/)) {
947:): undef($poss_symb);
1.159.2.11 raeburn 948: }
949: }
950: }
951: if ($poss_symb) {
952: $access=&Apache::lonnet::allowed('bre',$requrl,$poss_symb);
953: } else {
954: $access=&Apache::lonnet::allowed('bre',$requrl,'','','','',1);
955: }
956: } else {
1.159.2.21.2. (raeburn 957:): my $nodeeplinkcheck;
958:): if (($check_access) && ($requrl =~ /\.(sequence|page)$/)) {
959:): unless ($env{'form.navmap'}) {
960:): if ($r->args ne '') {
961:): &Apache::loncommon::get_unprocessed_cgi($r->args,['navmap']);
962:): unless ($env{'form.navmap'}) {
963:): $nodeeplinkcheck = 1;
964:): }
965:): }
966:): }
967:): }
1.159.2.21 raeburn 968: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1.159.2.21.2. (raeburn 969:): $access=&Apache::lonnet::allowed('bre',$requrl,'','',$clientip,'','',$nodeeplinkcheck);
1.159.2.11 raeburn 970: }
1.159.2.17 raeburn 971: }
972: if ($check_block) {
973: if ($access eq 'B') {
974: if ($poss_symb) {
975: if (&Apache::lonnet::symbverify($poss_symb,$requrl)) {
976: $env{'request.symb'} = $poss_symb;
977: }
978: }
979: &Apache::blockedaccess::setup_handler($r);
980: return OK;
981: }
1.159.2.21.2. (raeburn 982:): } elsif ($check_access) {
1.159 raeburn 983: if ($handle eq '') {
984: unless ($access eq 'F') {
985: if ($requrl =~ m{^/res/$match_domain/$match_username/}) {
986: $r->log_reason("Cookie not valid", $r->filename);
987: }
988: }
989: }
1.92 albertel 990: if ($access eq '1') {
991: $env{'user.error.msg'}="$requrl:bre:0:0:Choose Course";
992: return HTTP_NOT_ACCEPTABLE;
993: }
994: if ($access eq 'A') {
995: &Apache::restrictedaccess::setup_handler($r);
996: return OK;
997: }
1.103 raeburn 998: if ($access eq 'B') {
1.159.2.11 raeburn 999: if ($poss_symb) {
1000: if (&Apache::lonnet::symbverify($poss_symb,$requrl)) {
1001: $env{'request.symb'} = $poss_symb;
1002: }
1003: }
1.103 raeburn 1004: &Apache::blockedaccess::setup_handler($r);
1005: return OK;
1006: }
1.159.2.21.2. (raeburn 1007:): if ($access eq 'D') {
1008:): &Apache::lonprotected::setup_handler($r);
1009:): return OK;
1010:): }
1.92 albertel 1011: if (($access ne '2') && ($access ne 'F')) {
1.130 raeburn 1012: if ($requrl =~ m{^/res/}) {
1013: $access = &Apache::lonnet::allowed('bro',$requrl);
1014: if ($access ne 'F') {
1.132 raeburn 1015: if ($requrl eq '/res/lib/templates/simpleproblem.problem/smpedit') {
1016: $access = &Apache::lonnet::allowed('bre','/res/lib/templates/simpleproblem.problem');
1017: if ($access ne 'F') {
1018: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1019: return HTTP_NOT_ACCEPTABLE;
1020: }
1021: } else {
1022: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1023: return HTTP_NOT_ACCEPTABLE;
1024: }
1.130 raeburn 1025: }
1.159.2.3 raeburn 1026: } elsif (($handle =~ /^publicuser_\d+$/) && (&Apache::lonnet::is_portfolio_url($requrl))) {
1.159.2.18 raeburn 1027: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1.159.2.3 raeburn 1028: if (&Apache::lonnet::allowed('bre',$requrl,undef,undef,$clientip) ne 'F') {
1029: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1030: return HTTP_NOT_ACCEPTABLE;
1031: }
1.130 raeburn 1032: } else {
1033: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1034: return HTTP_NOT_ACCEPTABLE;
1035: }
1.37 albertel 1036: }
1.92 albertel 1037: }
1038: if ($requrl =~ m|^/prtspool/|) {
1039: my $start='/prtspool/'.$env{'user.name'}.'_'.
1040: $env{'user.domain'};
1041: if ($requrl !~ /^\Q$start\E/) {
1042: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1043: return HTTP_NOT_ACCEPTABLE;
1.67 albertel 1044: }
1.92 albertel 1045: }
1.109 banghart 1046: if ($requrl =~ m|^/zipspool/|) {
1.110 banghart 1047: my $start='/zipspool/zipout/'.$env{'user.name'}.":".
1.109 banghart 1048: $env{'user.domain'};
1049: if ($requrl !~ /^\Q$start\E/) {
1050: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1051: return HTTP_NOT_ACCEPTABLE;
1052: }
1053: }
1.92 albertel 1054: if ($env{'user.name'} eq 'public' &&
1055: $env{'user.domain'} eq 'public' &&
1056: $requrl !~ m{^/+(res|public|uploaded)/} &&
1057: $requrl !~ m{^/adm/[^/]+/[^/]+/aboutme/portfolio$ }x &&
1.159.2.12 raeburn 1058: $requrl !~ m{^/adm/blockingstatus/.*$} &&
1.92 albertel 1059: $requrl !~ m{^/+adm/(help|logout|restrictedaccess|randomlabel\.png)}) {
1060: $env{'request.querystring'}=$r->args;
1061: $env{'request.firsturl'}=$requrl;
1062: return FORBIDDEN;
1063: }
1.23 www 1064: # ------------------------------------------------------------- This is allowed
1.92 albertel 1065: if ($env{'request.course.id'}) {
1.24 www 1066: &Apache::lonnet::countacc($requrl);
1.125 raeburn 1067: my $query=$r->args;
1.159.2.12 raeburn 1068: if ($check_symb) {
1.23 www 1069: # ------------------------------------- This is serious stuff, get symb and log
1.92 albertel 1070: my $symb;
1071: if ($query) {
1.141 raeburn 1072: &Apache::loncommon::get_unprocessed_cgi($query,['symb','folderpath']);
1.92 albertel 1073: }
1074: if ($env{'form.symb'}) {
1.64 albertel 1075: $symb=&Apache::lonnet::symbclean($env{'form.symb'});
1.159.2.19 raeburn 1076: if (($requrl eq '/adm/navmaps') ||
1077: ($requrl =~ m{^/adm/wrapper/}) ||
1078: ($requrl =~ m{^/adm/coursedocs/showdoc/})) {
1079: unless (&Apache::lonnet::symbverify($symb,$requrl)) {
1080: if (&Apache::lonnet::is_on_map($requrl)) {
1081: $symb = &Apache::lonnet::symbread($requrl);
1082: unless (&Apache::lonnet::symbverify($symb,$requrl)) {
1083: undef($symb);
1084: }
1085: }
1086: }
1087: if ($symb) {
1088: if ($requrl eq '/adm/navmaps') {
1089: my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1090: &Apache::lonnet::symblist($map,$murl => [$murl,$mid]);
1091: } elsif (($requrl =~ m{^/adm/wrapper/}) ||
1092: ($requrl =~ m{^/adm/coursedocs/showdoc/})) {
1093: my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1094: if ($map =~ /\.page$/) {
1095: my $mapsymb = &Apache::lonnet::symbread($map);
1096: ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb);
1097: }
1098: &Apache::lonnet::symblist($map,$murl => [$murl,$mid],
1099: 'last_known' =>[$murl,$mid]);
1100: }
1.159.2.9 raeburn 1101: }
1.92 albertel 1102: } elsif ((&Apache::lonnet::symbverify($symb,$requrl)) ||
1.53 albertel 1103: (($requrl=~m|(.*)/smpedit$|) &&
1.134 raeburn 1104: &Apache::lonnet::symbverify($symb,$1)) ||
1105: (($requrl=~m|(.*/aboutme)/portfolio$|) &&
1106: &Apache::lonnet::symbverify($symb,$1))) {
1.92 albertel 1107: my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1.159.2.9 raeburn 1108: if (($map =~ /\.page$/) && ($requrl !~ /\.page$/)) {
1109: my $mapsymb = &Apache::lonnet::symbread($map);
1110: ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb);
1111: }
1.92 albertel 1112: &Apache::lonnet::symblist($map,$murl => [$murl,$mid],
1113: 'last_known' =>[$murl,$mid]);
1.31 www 1114: } else {
1115: $r->log_reason('Invalid symb for '.$requrl.': '.
1.92 albertel 1116: $symb);
1117: $env{'user.error.msg'}=
1118: "$requrl:bre:1:1:Invalid Access";
1119: return HTTP_NOT_ACCEPTABLE;
1120: }
1121: } else {
1.134 raeburn 1122: if ($requrl=~m{^(/adm/.*/aboutme)/portfolio$}) {
1123: $requrl = $1;
1124: }
1.159.2.12 raeburn 1125: $symb=&Apache::lonnet::symbread($requrl);
1126: if (&Apache::lonnet::is_on_map($requrl) && $symb) {
1127: my ($encstate,$invalidsymb);
1128: unless (&Apache::lonnet::symbverify($symb,$requrl,\$encstate)) {
1129: $invalidsymb = 1;
1130: #
1.159.2.14 raeburn 1131: # If $env{'request.enc'} inconsistent with encryption expected for $symb
1132: # retrieved by lonnet::symbread(), call again to check for an instance of
1133: # $requrl in the course for which expected encryption matches request.enc.
1134: # If symb for different instance passes lonnet::symbverify(), use that as
1135: # the symb for $requrl and call &Apache::lonnet::allowed() for that symb.
1136: # Report invalid symb if there is no other symb. Redirect to /adm/ambiguous
1137: # if multiple possible symbs consistent with request.enc available for $requrl.
1.159.2.12 raeburn 1138: #
1.159.2.14 raeburn 1139: if (($env{'request.enc'} && !$encstate) || (!$env{'request.enc'} && $encstate)) {
1.159.2.12 raeburn 1140: my %possibles;
1141: my $nocache = 1;
1.159.2.14 raeburn 1142: my $oldsymb = $symb;
1.159.2.12 raeburn 1143: $symb = &Apache::lonnet::symbread($requrl,'','','',\%possibles,$nocache);
1.159.2.14 raeburn 1144: if (($symb) && ($symb ne $oldsymb)) {
1.159.2.12 raeburn 1145: if (&Apache::lonnet::symbverify($symb,$requrl)) {
1.159.2.14 raeburn 1146: my $access=&Apache::lonnet::allowed('bre',$requrl,$symb);
1147: if ($access eq 'B') {
1148: $env{'request.symb'} = $symb;
1149: &Apache::blockedaccess::setup_handler($r);
1150: return OK;
1151: } elsif (($access eq '2') || ($access eq 'F')) {
1152: $invalidsymb = '';
1153: }
1.159.2.11 raeburn 1154: }
1.159.2.12 raeburn 1155: } elsif (keys(%possibles) > 1) {
1156: $r->internal_redirect('/adm/ambiguous');
1157: return OK;
1.159.2.11 raeburn 1158: }
1.159.2.12 raeburn 1159: }
1160: if ($invalidsymb) {
1.159.2.19 raeburn 1161: if ($requrl eq '/adm/navmaps') {
1.159.2.20 raeburn 1162: undef($symb);
1.159.2.19 raeburn 1163: } else {
1164: $r->log_reason('Invalid symb for '.$requrl.': '.$symb);
1165: $env{'user.error.msg'}=
1166: "$requrl:bre:1:1:Invalid Access";
1167: return HTTP_NOT_ACCEPTABLE;
1168: }
1.159.2.11 raeburn 1169: }
1170: }
1.159.2.12 raeburn 1171: }
1172: if ($symb) {
1173: my ($map,$mid,$murl)=
1174: &Apache::lonnet::decode_symb($symb);
1175: if ($requrl eq '/adm/navmaps') {
1176: &Apache::lonnet::symblist($map,$murl =>[$murl,$mid]);
1177: } else {
1178: if (($map =~ /\.page$/) && ($requrl !~ /\.page$/)) {
1179: my $mapsymb = &Apache::lonnet::symbread($map);
1180: ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb);
1.159.2.9 raeburn 1181: }
1.159.2.12 raeburn 1182: &Apache::lonnet::symblist($map,$murl =>[$murl,$mid],
1183: 'last_known' =>[$murl,$mid]);
1184: }
1.61 albertel 1185: }
1.92 albertel 1186: }
1187: $env{'request.symb'}=$symb;
1.159.2.11 raeburn 1188: if (($env{'request.symbread.cached.'}) && ($env{'request.symbread.cached.'} ne $symb)) {
1189: $env{'request.symbread.cached.'} = $symb;
1190: }
1.92 albertel 1191: &Apache::lonnet::courseacclog($symb);
1192: } else {
1.23 www 1193: # ------------------------------------------------------- This is other content
1.92 albertel 1194: &Apache::lonnet::courseacclog($requrl);
1195: }
1.140 raeburn 1196: if ($requrl =~ m{^/+uploaded/\Q$cdom\E/\Q$cnum\E/(docs|supplemental)/.+\.html?$}) {
1.125 raeburn 1197: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1198: if ($query) {
1199: &Apache::loncommon::get_unprocessed_cgi($query,['forceedit']);
1200: if ($env{'form.forceedit'}) {
1201: $env{'request.state'} = 'edit';
1202: }
1203: }
1204: }
1.144 raeburn 1205: } elsif ($requrl =~ m{^/+uploaded/\Q$cdom\E/\Q$cnum\E/portfolio/syllabus/.+\.html?$}) {
1206: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1207: if ($query) {
1208: &Apache::loncommon::get_unprocessed_cgi($query,['forceedit','editmode']);
1209: if (($env{'form.forceedit'}) || ($env{'form.editmode'})) {
1210: $env{'request.state'} = 'edit';
1211: }
1212: }
1213: }
1.125 raeburn 1214: }
1.88 albertel 1215: }
1.92 albertel 1216: return OK;
1.137 raeburn 1217: } else {
1218: my $defdom=$r->dir_config('lonDefDomain');
1219: ($is_balancer,$otherserver) =
1220: &Apache::lonnet::check_loadbalancing(undef,$defdom);
1221: if ($is_balancer) {
1222: $r->set_handlers('PerlResponseHandler'=>
1223: [\&Apache::switchserver::handler]);
1224: if ($otherserver ne '') {
1225: $env{'form.otherserver'} = $otherserver;
1226: }
1227: }
1.92 albertel 1228: }
1.21 www 1229: # -------------------------------------------- See if this is a public resource
1.68 albertel 1230: if ($requrl=~m|^/+adm/+help/+|) {
1.89 albertel 1231: return OK;
1.68 albertel 1232: }
1.90 albertel 1233: # ------------------------------------ See if this is a viewable portfolio file
1.89 albertel 1234: if (&Apache::lonnet::is_portfolio_url($requrl)) {
1.159.2.18 raeburn 1235: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1.159.2.3 raeburn 1236: my $access=&Apache::lonnet::allowed('bre',$requrl,undef,undef,$clientip);
1.90 albertel 1237: if ($access eq 'A') {
1238: &Apache::restrictedaccess::setup_handler($r);
1239: return OK;
1240: }
1241: if (($access ne '2') && ($access ne 'F')) {
1242: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1243: return HTTP_NOT_ACCEPTABLE;
1244: }
1.79 raeburn 1245: }
1.87 albertel 1246:
1.34 www 1247: # -------------------------------------------------------------- Not authorized
1248: $requrl=~/\.(\w+)$/;
1.62 albertel 1249: # if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
1250: # ($requrl=~/^\/adm\/(roles|logout|email|menu|remote)/) ||
1251: # ($requrl=~m|^/prtspool/|)) {
1.34 www 1252: # -------------------------- Store where they wanted to go and get login screen
1.64 albertel 1253: $env{'request.querystring'}=$r->args;
1254: $env{'request.firsturl'}=$requrl;
1.34 www 1255: return FORBIDDEN;
1.62 albertel 1256: # } else {
1.34 www 1257: # --------------------------------------------------------------------- Goodbye
1.62 albertel 1258: # return HTTP_BAD_REQUEST;
1259: # }
1.1 albertel 1260: }
1261:
1262: 1;
1263: __END__
1.120 jms 1264:
1.121 jms 1265: =pod
1.120 jms 1266:
1.121 jms 1267: =back
1.120 jms 1268:
1.121 jms 1269: =cut
1.120 jms 1270:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>