Annotation of loncom/auth/lonacc.pm, revision 1.159.2.21.2.4
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.3 2022/08/30 11:58:44 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:):
310:): my @items = ('role','symb','iptoken','origurl','ttoken',
311:): 'ltoken','linkkey','logtoken','sso','lcssowin');
1.127 raeburn 312: &Apache::loncommon::get_unprocessed_cgi($query,\@items);
313: foreach my $item (@items) {
314: if (defined($env{'form.'.$item})) {
315: $form{$item} = $env{'form.'.$item};
1.126 raeburn 316: }
317: }
318: }
319:
1.145 raeburn 320: my %sessiondata;
321: if ($form{'iptoken'}) {
322: %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
1.158 raeburn 323: my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
324: unless ($sessiondata{'sessionserver'}) {
325: delete($form{'iptoken'});
326: }
1.145 raeburn 327: }
328:
1.159.2.21.2. (raeburn 329:): my ($linkprot,$linkprotuser,$linkprotexit,$linkkey,$deeplinkurl);
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:): } elsif ($info{'linkkey'} ne '') {
370:): $linkkey = $info{'linkkey'};
371:): }
372:): } elsif ($form{'logtoken'}) {
1.159.2.21 raeburn 373: my ($firsturl,@rest);
374: my $lonhost = $r->dir_config('lonHostID');
375: my $tmpinfo = &Apache::lonnet::reply('tmpget:'.$form{'logtoken'},$lonhost);
376: my $delete = &Apache::lonnet::tmpdel($form{'logtoken'});
377: unless (($tmpinfo=~/^error/) || ($tmpinfo eq 'con_lost') ||
378: ($tmpinfo eq 'no_such_host')) {
379: (undef,$firsturl,@rest) = split(/&/,$tmpinfo);
380: if ($firsturl ne '') {
381: $firsturl = &unescape($firsturl);
382: }
383: foreach my $item (@rest) {
384: my ($key,$value) = split(/=/,$item);
385: $form{$key} = &unescape($value);
386: }
1.159.2.21.2. (raeburn 387:): if ($firsturl =~ m{^/tiny/$match_domain/\w+$}) {
388:): $form{'origurl'} = $firsturl;
389:): $deeplinkurl = $firsturl;
390:): } elsif ($firsturl eq '/adm/email') {
391:): $form{'origurl'} = $firsturl;
392:): }
393:): if ($form{'linkprot'}) {
394:): $linkprot = $form{'linkprot'};
395:): $linkprotuser = $form{'linkprotuser'};
396:): $linkprotexit = $form{'linkprotexit'};
397:): } elsif ($form{'linkkey'} ne '') {
398:): $linkkey = $form{'linkkey'};
399:): }
1.159.2.21 raeburn 400: if ($form{'iptoken'}) {
401: %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
402: my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
403: }
404: }
1.159.2.21.2. (raeburn 405:): } elsif ($form{'sso'}) {
406:): my $lonhost = $r->dir_config('lonHostID');
407:): my $info = &Apache::lonnet::reply('tmpget:'.$form{'sso'},$lonhost);
408:): &Apache::lonnet::tmpdel($form{'sso'});
409:): unless (($info=~/^error/) || ($info eq 'con_lost') ||
410:): ($info eq 'no_such_host')) {
411:): my ($firsturl,@rest)=split(/\&/,$info);
412:): if ($firsturl ne '') {
413:): $form{'origurl'} = &unescape($firsturl);
414:): if ($form{'origurl'} =~ m{^/tiny/$match_domain/\w+$}) {
415:): $deeplinkurl = $form{'origurl'};
416:): }
417:): }
418:): foreach my $item (@rest) {
419:): my ($key,$value) = split(/=/,$item);
420:): $form{$key} = &unescape($value);
421:): }
422:): if ($form{'linkprot'}) {
423:): $linkprot = $form{'linkprot'};
424:): $linkprotuser = $form{'linkprotuser'};
425:): $linkprotexit = $form{'linkprotexit'};
426:): } elsif ($form{'linkkey'} ne '') {
427:): $linkkey = $form{'linkkey'};
428:): }
429:): }
430:): } elsif ($form{'ltoken'}) {
431:): my %link_info = &Apache::lonnet::tmpget($form{'ltoken'});
432:): $linkprot = $link_info{'linkprot'};
433:): if ($linkprot) {
434:): if ($link_info{'linkprotuser'} ne '') {
435:): $linkprotuser = $link_info{'linkprotuser'};
436:): }
437:): if ($link_info{'linkprotexit'} ne '') {
438:): $linkprotexit = $link_info{'linkprotexit'};
439:): }
440:): }
441:): my $delete = &Apache::lonnet::tmpdel($form{'ltoken'});
442:): delete($form{'ltoken'});
443:): if ($form{'origurl'} =~ m{^/tiny/$match_domain/\w+$}) {
444:): $deeplinkurl = $form{'origurl'};
445:): }
446:): } elsif ($form{'linkkey'} ne '') {
447:): $linkkey = $form{'linkkey'};
1.159.2.21 raeburn 448: }
449:
1.136 raeburn 450: my $domain = $r->dir_config('lonSSOUserDomain');
451: if ($domain eq '') {
452: $domain = $r->dir_config('lonDefDomain');
453: }
1.159.2.21.2. (raeburn 454:): if (($deeplinkurl) && ($linkprot) && ($linkprotuser ne '')) {
455:): unless ($linkprotuser eq $user.':'.$domain) {
456:): $r->user();
457:): my %data = (
458:): origurl => $deeplinkurl,
459:): linkprot => $linkprot,
460:): linkprotuser => $linkprotuser,
461:): linkprotexit => $linkprotexit,
462:): );
463:): if ($env{'form.lcssowin'}) {
464:): $data{'lcssowin'} = $env{'form.lcssowin'};
465:): }
466:): my $token = &Apache::lonnet::tmpput(\%data,$r->dir_config('lonHostID'),'link');
467:): unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
468:): ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
469:): $r->internal_redirect('/adm/relaunch?rtoken='.$token);
470:): $r->set_handlers('PerlHandler'=> undef);
471:): return OK;
472:): }
473:): }
474:): }
1.97 albertel 475: my $home=&Apache::lonnet::homeserver($user,$domain);
1.94 albertel 476: if ($home !~ /(con_lost|no_host|no_such_host)/) {
1.107 albertel 477: &Apache::lonnet::logthis(" SSO authorized user $user ");
1.145 raeburn 478: my ($is_balancer,$otherserver,$hosthere);
479: if ($form{'iptoken'}) {
1.158 raeburn 480: if (($sessiondata{'domain'} eq $domain) &&
481: ($sessiondata{'username'} eq $user)) {
1.145 raeburn 482: $hosthere = 1;
483: }
484: }
485: unless ($hosthere) {
486: ($is_balancer,$otherserver) =
1.159.2.5 raeburn 487: &Apache::lonnet::check_loadbalancing($user,$domain,'login');
488: if ($is_balancer) {
1.159.2.8 raeburn 489: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
490: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r);
491: if (($found_server) && ($balancer_cookie =~ /^\Q$domain\E_\Q$user\E_/)) {
492: $otherserver = $found_server;
493: } elsif ($otherserver eq '') {
1.159.2.5 raeburn 494: my $lowest_load;
495: ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($domain);
496: if ($lowest_load > 100) {
1.159.2.21 raeburn 497: $otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$domain);
1.159.2.5 raeburn 498: }
1.159.2.8 raeburn 499: if ($otherserver ne '') {
500: my @hosts = &Apache::lonnet::current_machine_ids();
501: if (grep(/^\Q$otherserver\E$/,@hosts)) {
502: $hosthere = $otherserver;
503: }
1.159.2.5 raeburn 504: }
505: }
506: }
1.145 raeburn 507: }
1.159.2.5 raeburn 508: if (($is_balancer) && (!$hosthere)) {
1.136 raeburn 509: # login but immediately go to switch server to find us a new
1.94 albertel 510: # machine
1.127 raeburn 511: &Apache::lonauth::success($r,$user,$domain,$home,'noredirect');
1.159.2.21 raeburn 512: foreach my $item (keys(%form)) {
513: $env{'form.'.$item} = $form{$item};
514: }
515: unless (($form{'symb'}) || ($form{'origurl'})) {
516: unless (($r->uri eq '/adm/roles') || ($r->uri eq '/adm/sso')) {
517: $env{'form.origurl'} = $r->uri;
518: }
519: }
1.159.2.21.2. (raeburn 520:): if (($r->uri eq '/adm/sso') && ($form{'origurl'} =~ m{^/+tiny/+$match_domain/+\w+$})) {
521:): $env{'request.deeplink.login'} = $form{'origurl'};
522:): } elsif ($r->uri =~ m{^/+tiny/+$match_domain/+\w+$}) {
523:): $env{'request.deeplink.login'} = $r->uri;
524:): }
525:): if ($env{'request.deeplink.login'}) {
526:): if ($linkprot) {
527:): $env{'request.linkprot'} = $linkprot;
528:): if ($linkprotuser ne '') {
529:): $env{'request.linkprotuser'} = $linkprotuser;
530:): }
531:): if ($linkprotexit ne '') {
532:): $env{'request.linkprotexit'} = $linkprotexit;
533:): }
534:): } elsif ($linkkey ne '') {
535:): $env{'request.linkkey'} = $linkkey;
536:): }
537:): }
538:): if (($r->uri eq '/adm/sso') && ($form{'origurl'} eq '/adm/email')) {
539:): if ($form{'display'} && ($env{'form.mailrecip'} eq $user.':'.$domain)) {
540:): $env{'request.display'} = $form{'display'};
541:): $env{'request.mailrecip'} = $env{'form.mailrecip'};
542:): }
543:): }
1.105 raeburn 544: $env{'request.sso.login'} = 1;
1.106 raeburn 545: if (defined($r->dir_config("lonSSOReloginServer"))) {
546: $env{'request.sso.reloginserver'} =
547: $r->dir_config('lonSSOReloginServer');
548: }
1.137 raeburn 549: my $redirecturl = '/adm/switchserver';
550: if ($otherserver ne '') {
551: $redirecturl .= '?otherserver='.$otherserver;
552: }
1.159.2.21.2. (raeburn 553:): if ($form{'lcssowin'}) {
554:): $redirecturl .= (($redirecturl=~/\?/)?'&':'?') . 'lcssowin=1';
555:): }
1.137 raeburn 556: $r->internal_redirect($redirecturl);
1.101 albertel 557: $r->set_handlers('PerlHandler'=> undef);
1.94 albertel 558: } else {
559: # need to login them in, so generate the need data that
560: # migrate expects to do login
1.159.2.18 raeburn 561: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.147 raeburn 562: my %info=('ip' => $ip,
1.94 albertel 563: 'domain' => $domain,
1.97 albertel 564: 'username' => $user,
1.94 albertel 565: 'server' => $r->dir_config('lonHostID'),
566: 'sso.login' => 1
567: );
1.159.2.21.2. (raeburn 568:): foreach my $item ('role','symb','iptoken','origurl','lcssowin') {
1.126 raeburn 569: if (exists($form{$item})) {
570: $info{$item} = $form{$item};
1.159.2.21 raeburn 571: } elsif ($sessiondata{$item} ne '') {
572: $info{$item} = $sessiondata{$item};
1.126 raeburn 573: }
574: }
1.159.2.21 raeburn 575: unless (($info{'symb'}) || ($info{'origurl'})) {
1.152 raeburn 576: unless (($r->uri eq '/adm/roles') || ($r->uri eq '/adm/sso')) {
1.151 raeburn 577: $info{'origurl'} = $r->uri;
578: }
579: }
1.159.2.21.2. (raeburn 580:): if (($r->uri eq '/adm/sso') && ($form{'origurl'} =~ m{^/+tiny/+$match_domain/+\w+$})) {
581:): $info{'deeplink.login'} = $form{'origurl'};
582:): } elsif ($r->uri =~ m{^/+tiny/+$match_domain/+\w+$}) {
583:): $info{'deeplink.login'} = $r->uri;
584:): }
585:): if ($info{'deeplink.login'}) {
586:): if ($linkprot) {
587:): $info{'linkprot'} = $linkprot;
588:): if ($linkprotuser ne '') {
589:): $info{'linkprotuser'} = $linkprotuser;
590:): }
591:): if ($linkprotexit ne '') {
592:): $info{'linkprotexit'} = $linkprotexit;
593:): }
594:): } elsif ($linkkey ne '') {
595:): $info{'linkkey'} = $linkkey;
596:): }
597:): }
598:): if (($r->uri eq '/adm/sso') && ($form{'origurl'} eq '/adm/email')) {
599:): if ($form{'display'} && ($form{'mailrecip'} eq $user.':'.$domain)) {
600:): $info{'display'} = &escape($form{'display'});
601:): $info{'mailrecip'} = &escape($form{'mailrecip'});
602:): }
603:): }
1.116 raeburn 604: if ($r->dir_config("ssodirecturl") == 1) {
605: $info{'origurl'} = $r->uri;
606: }
1.106 raeburn 607: if (defined($r->dir_config("lonSSOReloginServer"))) {
608: $info{'sso.reloginserver'} =
609: $r->dir_config('lonSSOReloginServer');
610: }
1.159.2.5 raeburn 611: if (($is_balancer) && ($hosthere)) {
612: $info{'noloadbalance'} = $hosthere;
613: }
1.159.2.21.2. (raeburn 614:): my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'sso');
1.94 albertel 615: $env{'form.token'} = $token;
616: $r->internal_redirect('/adm/migrateuser');
1.101 albertel 617: $r->set_handlers('PerlHandler'=> undef);
1.94 albertel 618: }
619: return OK;
1.155 raeburn 620: } else {
1.107 albertel 621: &Apache::lonnet::logthis(" SSO authorized unknown user $user ");
1.115 raeburn 622: my @cancreate;
623: my %domconfig =
624: &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
625: if (ref($domconfig{'usercreation'}) eq 'HASH') {
626: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
627: if (ref($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
628: @cancreate = @{$domconfig{'usercreation'}{'cancreate'}{'selfcreate'}};
629: } elsif (($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') &&
630: ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne '')) {
631: @cancreate = ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'});
632: }
633: }
634: }
1.155 raeburn 635: if ((grep(/^sso$/,@cancreate)) || (defined($r->dir_config('lonSSOUserUnknownRedirect')))) {
636: $r->subprocess_env->set('SSOUserUnknown' => $user);
637: $r->subprocess_env->set('SSOUserDomain' => $domain);
638: if (grep(/^sso$/,@cancreate)) {
1.159.2.21.2. (raeburn 639:): #FIXME - need to preserve origurl, role and symb, or linkprot or linkkey for use after account
640:): # creation. If lcssowin is 1, createaccount needs to close pop-up and display in main window.
1.155 raeburn 641: $r->set_handlers('PerlHandler'=> [\&Apache::createaccount::handler]);
642: $r->handler('perl-script');
643: } else {
644: $r->internal_redirect($r->dir_config('lonSSOUserUnknownRedirect'));
645: $r->set_handlers('PerlHandler'=> undef);
646: }
647: return OK;
1.115 raeburn 648: }
1.94 albertel 649: }
650: return undef;
651: }
652:
1.1 albertel 653: sub handler {
654: my $r = shift;
655: my $requrl=$r->uri;
1.149 raeburn 656:
657: if ($requrl =~ m{^/res/adm/pages/[^/]+\.(gif|png)$}) {
1.108 raeburn 658: return OK;
659: }
1.70 albertel 660:
1.149 raeburn 661: if (&Apache::lonnet::is_domainimage($requrl)) {
1.124 raeburn 662: return OK;
663: }
664:
1.149 raeburn 665: my %user;
666: my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user);
1.93 albertel 667:
1.150 raeburn 668: unless (($requrl eq '/adm/switchserver') && (!$r->is_initial_req())) {
669: my $result = &sso_login($r,$handle,$user{'name'});
670: if (defined($result)) {
671: return $result;
672: }
1.70 albertel 673: }
674:
1.137 raeburn 675: my ($is_balancer,$otherserver);
1.142 raeburn 676:
1.92 albertel 677: if ($handle eq '') {
1.159 raeburn 678: unless ((($requrl eq '/adm/switchserver') && (!$r->is_initial_req())) ||
679: ($requrl =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
1.159.2.21 raeburn 680: ($requrl =~ m{^/adm/help/}) || ($requrl eq '/adm/sso') ||
1.159 raeburn 681: ($requrl =~ m{^/res/$match_domain/$match_username/})) {
1.149 raeburn 682: $r->log_reason("Cookie not valid", $r->filename);
1.142 raeburn 683: }
1.111 albertel 684: } elsif ($handle ne '') {
1.6 www 685:
1.46 www 686: # ------------------------------------------------------ Initialize Environment
1.111 albertel 687: my $lonidsdir=$r->dir_config('lonIDsDir');
1.92 albertel 688: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
1.47 www 689:
690: # --------------------------------------------------------- Initialize Language
691:
1.92 albertel 692: &Apache::lonlocal::get_language_handle($r);
693:
694: }
1.46 www 695:
1.92 albertel 696: # -------------------------------------------------- Should be a valid user now
697: if ($env{'user.name'} ne '' && $env{'user.domain'} ne '') {
1.46 www 698: # -------------------------------------------------------------- Resource State
1.6 www 699:
1.141 raeburn 700: my ($cdom,$cnum);
701: if ($env{'request.course.id'}) {
702: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
703: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
704: }
1.92 albertel 705: if ($requrl=~/^\/+(res|uploaded)\//) {
706: $env{'request.state'} = "published";
707: } else {
708: $env{'request.state'} = 'unknown';
709: }
710: $env{'request.filename'} = $r->filename;
711: $env{'request.noversionuri'} = &Apache::lonnet::deversion($requrl);
1.157 raeburn 712: my ($suppext,$checkabsolute);
1.129 raeburn 713: if ($requrl =~ m{^/adm/wrapper/ext/}) {
714: my $query = $r->args;
715: if ($query) {
716: my $preserved;
717: foreach my $pair (split(/&/,$query)) {
718: my ($name, $value) = split(/=/,$pair);
1.159.2.7 raeburn 719: unless (($name eq 'symb') || ($name eq 'usehttp')) {
1.129 raeburn 720: $preserved .= $pair.'&';
721: }
1.141 raeburn 722: if (($env{'request.course.id'}) && ($name eq 'folderpath')) {
723: if ($value =~ /^supplemental/) {
724: $suppext = 1;
725: }
726: }
1.129 raeburn 727: }
728: $preserved =~ s/\&$//;
729: if ($preserved) {
730: $env{'request.external.querystring'} = $preserved;
731: }
732: }
1.157 raeburn 733: if ($env{'request.course.id'}) {
734: $checkabsolute = 1;
735: }
1.141 raeburn 736: } elsif ($env{'request.course.id'} &&
737: (($requrl =~ m{^/adm/$match_domain/$match_username/aboutme$}) ||
738: ($requrl =~ m{^/public/$cdom/$cnum/syllabus$}))) {
739: my $query = $r->args;
740: if ($query) {
741: foreach my $pair (split(/&/,$query)) {
742: my ($name, $value) = split(/=/,$pair);
743: if ($name eq 'folderpath') {
744: if ($value =~ /^supplemental/) {
745: $suppext = 1;
746: }
1.159.2.12 raeburn 747: last;
1.141 raeburn 748: }
749: }
750: }
1.157 raeburn 751: if ($requrl =~ m{^/public/$cdom/$cnum/syllabus$}) {
752: $checkabsolute = 1;
753: }
754: }
755: if ($checkabsolute) {
756: my $hostname = $r->hostname();
757: my $lonhost = &Apache::lonnet::host_from_dns($hostname);
758: if ($lonhost) {
1.159.2.21 raeburn 759: my $actual = &Apache::lonnet::absolute_url($hostname,1,1);
1.157 raeburn 760: my $expected = $Apache::lonnet::protocol{$lonhost}.'://'.$hostname;
761: unless ($actual eq $expected) {
762: $env{'request.use_absolute'} = $expected;
763: }
764: }
1.129 raeburn 765: }
1.6 www 766: # -------------------------------------------------------- Load POST parameters
767:
1.92 albertel 768: &Apache::lonacc::get_posted_cgi($r);
1.6 www 769:
1.137 raeburn 770: # ------------------------------------------------------ Check if load balancer
771:
1.138 raeburn 772: my $checkexempt;
773: if ($env{'user.loadbalexempt'} eq $r->dir_config('lonHostID')) {
774: if ($env{'user.loadbalcheck.time'} + 600 > time) {
1.159.2.8 raeburn 775: $checkexempt = 1;
1.138 raeburn 776: }
777: }
1.145 raeburn 778: if ($env{'user.noloadbalance'} eq $r->dir_config('lonHostID')) {
779: $checkexempt = 1;
780: }
1.159.2.15 raeburn 781: unless (($checkexempt) || (($requrl eq '/adm/switchserver') && (!$r->is_initial_req()))) {
1.138 raeburn 782: ($is_balancer,$otherserver) =
783: &Apache::lonnet::check_loadbalancing($env{'user.name'},
784: $env{'user.domain'});
1.159.2.8 raeburn 785: if ($is_balancer) {
1.159.2.15 raeburn 786: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
787: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r);
788: if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) {
789: $otherserver = $found_server;
790: }
791: unless ($requrl eq '/adm/switchserver') {
792: $r->set_handlers('PerlResponseHandler'=>
793: [\&Apache::switchserver::handler]);
1.159.2.8 raeburn 794: }
795: if ($otherserver ne '') {
796: $env{'form.otherserver'} = $otherserver;
797: }
1.159.2.15 raeburn 798: unless (($env{'form.origurl'}) || ($r->uri eq '/adm/roles') ||
799: ($r->uri eq '/adm/switchserver') || ($r->uri eq '/adm/sso')) {
800: $env{'form.origurl'} = $r->uri;
801: }
1.152 raeburn 802: }
1.137 raeburn 803: }
1.159.2.21.2. (raeburn 804:): if ($requrl=~m{^/+tiny/+$match_domain/+\w+$}) {
805:): if ($r->args) {
806:): &Apache::loncommon::get_unprocessed_cgi($r->args,['ttoken']);
807:): if (defined($env{'form.ttoken'})) {
808:): my %info = &Apache::lonnet::tmpget($env{'form.ttoken'});
809:): if (($info{'origurl'} ne '') && ($info{'origurl'} eq $requrl)) {
810:): my %data;
811:): if (($info{'linkprotuser'} ne '') && ($info{'linkprot'}) &&
812:): ($info{'linkprotuser'} ne $env{'user.name'}.':'.$env{'user.domain'})) {
813:): %data = (
814:): origurl => $requrl,
815:): linkprot => $info{'linkprot'},
816:): linkprotuser => $info{'linkprotuser'},
817:): linkprotexit => $info{'linkprotexit'},
818:): );
819:): } elsif ($info{'ltoken'} ne '') {
820:): my %ltoken_info = &Apache::lonnet::tmpget($info{'ltoken'});
821:): if (($ltoken_info{'linkprotuser'} ne '') && ($ltoken_info{'linkprot'}) &&
822:): ($ltoken_info{'linkprotuser'} ne $env{'user.name'}.':'.$env{'user.domain'})) {
823:): %data = (
824:): origurl => $requrl,
825:): linkprot => $ltoken_info{'linkprot'},
826:): linkprotuser => $ltoken_info{'linkprotuser'},
827:): linkprotexit => $ltoken_info{'linkprotexit'},
828:): );
829:): }
830:): }
831:): if (keys(%data)) {
832:): my $delete = &Apache::lonnet::tmpdel($env{'form.ttoken'});
833:): if ($info{'ltoken'} ne '') {
834:): my $delete = &Apache::lonnet::tmpdel($info{'ltoken'});
835:): }
836:): my $token =
837:): &Apache::lonnet::tmpput(\%data,$r->dir_config('lonHostID'),'retry');
838:): unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
839:): ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
840:): $r->internal_redirect('/adm/relaunch?rtoken='.$token);
841:): $r->set_handlers('PerlHandler'=> undef);
842:): return OK;
843:): }
844:): }
845:): }
846:): }
847:): }
848:): if ($env{'user.name'} eq 'public' &&
849:): $env{'user.domain'} eq 'public') {
850:): $env{'request.firsturl'}=$requrl;
851:): return FORBIDDEN;
852:): }
853:): return OK;
854:): }
1.6 www 855: # ---------------------------------------------------------------- Check access
1.92 albertel 856: my $now = time;
1.159.2.17 raeburn 857: my ($check_symb,$check_access,$check_block,$access,$poss_symb);
1.159.2.10 raeburn 858: if ($requrl !~ m{^/(?:adm|public|(?:prt|zip)spool)/}
1.95 albertel 859: || $requrl =~ /^\/adm\/.*\/(smppg|bulletinboard)(\?|$ )/x) {
1.159.2.16 raeburn 860: $check_access = 1;
861: }
1.159.2.17 raeburn 862: if ((!$check_access) && ($env{'request.course.id'})) {
863: if (($requrl eq '/adm/viewclasslist') ||
864: ($requrl =~ m{^(/adm/wrapper|)\Q/uploaded/$cdom/$cnum/docs/\E}) ||
865: ($requrl =~ m{^/adm/.*/aboutme$}) ||
1.159.2.21.2. (raeburn 866:): ($requrl=~m{^/adm/coursedocs/showdoc/}) ||
867:): ($requrl=~m{^(/adm/wrapper|)/adm/$cdom/$cnum/\d+/ext\.tool$})) {
1.159.2.17 raeburn 868: $check_block = 1;
869: }
870: }
1.159.2.16 raeburn 871: if (($env{'request.course.id'}) && (!$suppext)) {
872: $requrl=~/\.(\w+)$/;
873: if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
874: ($requrl=~/^\/adm\/.*\/(aboutme|smppg|bulletinboard)(\?|$ )/x) ||
875: ($requrl=~/^\/adm\/wrapper\//) ||
876: ($requrl=~m|^/adm/coursedocs/showdoc/|) ||
877: ($requrl=~m|\.problem/smpedit$|) ||
878: ($requrl=~/^\/public\/.*\/syllabus$/) ||
879: ($requrl=~/^\/adm\/(viewclasslist|navmaps)$/) ||
1.159.2.21.2. (raeburn 880:): ($requrl=~/^\/adm\/.*\/aboutme\/portfolio(\?|$)/) ||
881:): ($requrl=~m{^/adm/$cdom/$cnum/\d+/ext\.tool$})) {
1.159.2.16 raeburn 882: $check_symb = 1;
1.159.2.12 raeburn 883: }
1.159.2.16 raeburn 884: }
1.159.2.17 raeburn 885: if (($check_access) || ($check_block)) {
1.159.2.12 raeburn 886: if ($check_symb) {
1.159.2.11 raeburn 887: if ($env{'form.symb'}) {
888: $poss_symb=&Apache::lonnet::symbclean($env{'form.symb'});
1.159.2.12 raeburn 889: } elsif (($env{'request.course.id'}) && ($r->args ne '')) {
890: my $query = $r->args;
891: foreach my $pair (split(/&/,$query)) {
892: my ($name, $value) = split(/=/,$pair);
1.159.2.13 raeburn 893: $name = &unescape($name);
894: $value =~ tr/+/ /;
895: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.159.2.12 raeburn 896: if ($name eq 'symb') {
897: $poss_symb = &Apache::lonnet::symbclean($value);
898: last;
899: }
900: }
1.159.2.11 raeburn 901: }
902: if ($poss_symb) {
903: my ($possmap,$resid,$url)=&Apache::lonnet::decode_symb($poss_symb);
904: $url = &Apache::lonnet::clutter($url);
1.159.2.17 raeburn 905: my $toplevelmap = $env{'course.'.$env{'request.course.id'}.'.url'};
906: unless (($url eq $requrl) && (($possmap eq $toplevelmap) ||
907: (&Apache::lonnet::is_on_map($possmap)))) {
1.159.2.11 raeburn 908: undef($poss_symb);
909: }
910: if ($poss_symb) {
911: if ((!$env{'request.role.adv'}) && ($env{'acc.randomout'}) &&
912: ($env{'acc.randomout'}=~/\&\Q$poss_symb\E\&/)) {
913: undef($poss_symb);
1.159.2.21.2. (raeburn 914:): } elsif ((!$env{'request.role.adv'}) && ($env{'acc.deeplinkout'}) &&
915:): ($env{'acc.deeplinkout'}=~/\&\Q$poss_symb\E\&/)) {
916:): undef($poss_symb);
1.159.2.11 raeburn 917: }
918: }
919: }
920: if ($poss_symb) {
921: $access=&Apache::lonnet::allowed('bre',$requrl,$poss_symb);
922: } else {
923: $access=&Apache::lonnet::allowed('bre',$requrl,'','','','',1);
924: }
925: } else {
1.159.2.21.2. (raeburn 926:): my $nodeeplinkcheck;
927:): if (($check_access) && ($requrl =~ /\.(sequence|page)$/)) {
928:): unless ($env{'form.navmap'}) {
929:): if ($r->args ne '') {
930:): &Apache::loncommon::get_unprocessed_cgi($r->args,['navmap']);
931:): unless ($env{'form.navmap'}) {
932:): $nodeeplinkcheck = 1;
933:): }
934:): }
935:): }
936:): }
1.159.2.21 raeburn 937: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1.159.2.21.2. (raeburn 938:): $access=&Apache::lonnet::allowed('bre',$requrl,'','',$clientip,'','',$nodeeplinkcheck);
1.159.2.11 raeburn 939: }
1.159.2.17 raeburn 940: }
941: if ($check_block) {
942: if ($access eq 'B') {
943: if ($poss_symb) {
944: if (&Apache::lonnet::symbverify($poss_symb,$requrl)) {
945: $env{'request.symb'} = $poss_symb;
946: }
947: }
948: &Apache::blockedaccess::setup_handler($r);
949: return OK;
950: }
951: } elsif ($check_access) {
1.159 raeburn 952: if ($handle eq '') {
953: unless ($access eq 'F') {
954: if ($requrl =~ m{^/res/$match_domain/$match_username/}) {
955: $r->log_reason("Cookie not valid", $r->filename);
956: }
957: }
958: }
1.92 albertel 959: if ($access eq '1') {
960: $env{'user.error.msg'}="$requrl:bre:0:0:Choose Course";
961: return HTTP_NOT_ACCEPTABLE;
962: }
963: if ($access eq 'A') {
964: &Apache::restrictedaccess::setup_handler($r);
965: return OK;
966: }
1.103 raeburn 967: if ($access eq 'B') {
1.159.2.11 raeburn 968: if ($poss_symb) {
969: if (&Apache::lonnet::symbverify($poss_symb,$requrl)) {
970: $env{'request.symb'} = $poss_symb;
971: }
972: }
1.103 raeburn 973: &Apache::blockedaccess::setup_handler($r);
974: return OK;
975: }
1.159.2.21.2. (raeburn 976:): if ($access eq 'D') {
977:): &Apache::lonprotected::setup_handler($r);
978:): return OK;
979:): }
1.92 albertel 980: if (($access ne '2') && ($access ne 'F')) {
1.130 raeburn 981: if ($requrl =~ m{^/res/}) {
982: $access = &Apache::lonnet::allowed('bro',$requrl);
983: if ($access ne 'F') {
1.132 raeburn 984: if ($requrl eq '/res/lib/templates/simpleproblem.problem/smpedit') {
985: $access = &Apache::lonnet::allowed('bre','/res/lib/templates/simpleproblem.problem');
986: if ($access ne 'F') {
987: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
988: return HTTP_NOT_ACCEPTABLE;
989: }
990: } else {
991: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
992: return HTTP_NOT_ACCEPTABLE;
993: }
1.130 raeburn 994: }
1.159.2.3 raeburn 995: } elsif (($handle =~ /^publicuser_\d+$/) && (&Apache::lonnet::is_portfolio_url($requrl))) {
1.159.2.18 raeburn 996: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1.159.2.3 raeburn 997: if (&Apache::lonnet::allowed('bre',$requrl,undef,undef,$clientip) ne 'F') {
998: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
999: return HTTP_NOT_ACCEPTABLE;
1000: }
1.130 raeburn 1001: } else {
1002: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1003: return HTTP_NOT_ACCEPTABLE;
1004: }
1.37 albertel 1005: }
1.92 albertel 1006: }
1007: if ($requrl =~ m|^/prtspool/|) {
1008: my $start='/prtspool/'.$env{'user.name'}.'_'.
1009: $env{'user.domain'};
1010: if ($requrl !~ /^\Q$start\E/) {
1011: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1012: return HTTP_NOT_ACCEPTABLE;
1.67 albertel 1013: }
1.92 albertel 1014: }
1.109 banghart 1015: if ($requrl =~ m|^/zipspool/|) {
1.110 banghart 1016: my $start='/zipspool/zipout/'.$env{'user.name'}.":".
1.109 banghart 1017: $env{'user.domain'};
1018: if ($requrl !~ /^\Q$start\E/) {
1019: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1020: return HTTP_NOT_ACCEPTABLE;
1021: }
1022: }
1.92 albertel 1023: if ($env{'user.name'} eq 'public' &&
1024: $env{'user.domain'} eq 'public' &&
1025: $requrl !~ m{^/+(res|public|uploaded)/} &&
1026: $requrl !~ m{^/adm/[^/]+/[^/]+/aboutme/portfolio$ }x &&
1.159.2.12 raeburn 1027: $requrl !~ m{^/adm/blockingstatus/.*$} &&
1.92 albertel 1028: $requrl !~ m{^/+adm/(help|logout|restrictedaccess|randomlabel\.png)}) {
1029: $env{'request.querystring'}=$r->args;
1030: $env{'request.firsturl'}=$requrl;
1031: return FORBIDDEN;
1032: }
1.23 www 1033: # ------------------------------------------------------------- This is allowed
1.92 albertel 1034: if ($env{'request.course.id'}) {
1.24 www 1035: &Apache::lonnet::countacc($requrl);
1.125 raeburn 1036: my $query=$r->args;
1.159.2.12 raeburn 1037: if ($check_symb) {
1.23 www 1038: # ------------------------------------- This is serious stuff, get symb and log
1.92 albertel 1039: my $symb;
1040: if ($query) {
1.141 raeburn 1041: &Apache::loncommon::get_unprocessed_cgi($query,['symb','folderpath']);
1.92 albertel 1042: }
1043: if ($env{'form.symb'}) {
1.64 albertel 1044: $symb=&Apache::lonnet::symbclean($env{'form.symb'});
1.159.2.19 raeburn 1045: if (($requrl eq '/adm/navmaps') ||
1046: ($requrl =~ m{^/adm/wrapper/}) ||
1047: ($requrl =~ m{^/adm/coursedocs/showdoc/})) {
1048: unless (&Apache::lonnet::symbverify($symb,$requrl)) {
1049: if (&Apache::lonnet::is_on_map($requrl)) {
1050: $symb = &Apache::lonnet::symbread($requrl);
1051: unless (&Apache::lonnet::symbverify($symb,$requrl)) {
1052: undef($symb);
1053: }
1054: }
1055: }
1056: if ($symb) {
1057: if ($requrl eq '/adm/navmaps') {
1058: my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1059: &Apache::lonnet::symblist($map,$murl => [$murl,$mid]);
1060: } elsif (($requrl =~ m{^/adm/wrapper/}) ||
1061: ($requrl =~ m{^/adm/coursedocs/showdoc/})) {
1062: my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1063: if ($map =~ /\.page$/) {
1064: my $mapsymb = &Apache::lonnet::symbread($map);
1065: ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb);
1066: }
1067: &Apache::lonnet::symblist($map,$murl => [$murl,$mid],
1068: 'last_known' =>[$murl,$mid]);
1069: }
1.159.2.9 raeburn 1070: }
1.92 albertel 1071: } elsif ((&Apache::lonnet::symbverify($symb,$requrl)) ||
1.53 albertel 1072: (($requrl=~m|(.*)/smpedit$|) &&
1.134 raeburn 1073: &Apache::lonnet::symbverify($symb,$1)) ||
1074: (($requrl=~m|(.*/aboutme)/portfolio$|) &&
1075: &Apache::lonnet::symbverify($symb,$1))) {
1.92 albertel 1076: my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1.159.2.9 raeburn 1077: if (($map =~ /\.page$/) && ($requrl !~ /\.page$/)) {
1078: my $mapsymb = &Apache::lonnet::symbread($map);
1079: ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb);
1080: }
1.92 albertel 1081: &Apache::lonnet::symblist($map,$murl => [$murl,$mid],
1082: 'last_known' =>[$murl,$mid]);
1.31 www 1083: } else {
1084: $r->log_reason('Invalid symb for '.$requrl.': '.
1.92 albertel 1085: $symb);
1086: $env{'user.error.msg'}=
1087: "$requrl:bre:1:1:Invalid Access";
1088: return HTTP_NOT_ACCEPTABLE;
1089: }
1090: } else {
1.134 raeburn 1091: if ($requrl=~m{^(/adm/.*/aboutme)/portfolio$}) {
1092: $requrl = $1;
1093: }
1.159.2.12 raeburn 1094: $symb=&Apache::lonnet::symbread($requrl);
1095: if (&Apache::lonnet::is_on_map($requrl) && $symb) {
1096: my ($encstate,$invalidsymb);
1097: unless (&Apache::lonnet::symbverify($symb,$requrl,\$encstate)) {
1098: $invalidsymb = 1;
1099: #
1.159.2.14 raeburn 1100: # If $env{'request.enc'} inconsistent with encryption expected for $symb
1101: # retrieved by lonnet::symbread(), call again to check for an instance of
1102: # $requrl in the course for which expected encryption matches request.enc.
1103: # If symb for different instance passes lonnet::symbverify(), use that as
1104: # the symb for $requrl and call &Apache::lonnet::allowed() for that symb.
1105: # Report invalid symb if there is no other symb. Redirect to /adm/ambiguous
1106: # if multiple possible symbs consistent with request.enc available for $requrl.
1.159.2.12 raeburn 1107: #
1.159.2.14 raeburn 1108: if (($env{'request.enc'} && !$encstate) || (!$env{'request.enc'} && $encstate)) {
1.159.2.12 raeburn 1109: my %possibles;
1110: my $nocache = 1;
1.159.2.14 raeburn 1111: my $oldsymb = $symb;
1.159.2.12 raeburn 1112: $symb = &Apache::lonnet::symbread($requrl,'','','',\%possibles,$nocache);
1.159.2.14 raeburn 1113: if (($symb) && ($symb ne $oldsymb)) {
1.159.2.12 raeburn 1114: if (&Apache::lonnet::symbverify($symb,$requrl)) {
1.159.2.14 raeburn 1115: my $access=&Apache::lonnet::allowed('bre',$requrl,$symb);
1116: if ($access eq 'B') {
1117: $env{'request.symb'} = $symb;
1118: &Apache::blockedaccess::setup_handler($r);
1119: return OK;
1120: } elsif (($access eq '2') || ($access eq 'F')) {
1121: $invalidsymb = '';
1122: }
1.159.2.11 raeburn 1123: }
1.159.2.12 raeburn 1124: } elsif (keys(%possibles) > 1) {
1125: $r->internal_redirect('/adm/ambiguous');
1126: return OK;
1.159.2.11 raeburn 1127: }
1.159.2.12 raeburn 1128: }
1129: if ($invalidsymb) {
1.159.2.19 raeburn 1130: if ($requrl eq '/adm/navmaps') {
1.159.2.20 raeburn 1131: undef($symb);
1.159.2.19 raeburn 1132: } else {
1133: $r->log_reason('Invalid symb for '.$requrl.': '.$symb);
1134: $env{'user.error.msg'}=
1135: "$requrl:bre:1:1:Invalid Access";
1136: return HTTP_NOT_ACCEPTABLE;
1137: }
1.159.2.11 raeburn 1138: }
1139: }
1.159.2.12 raeburn 1140: }
1141: if ($symb) {
1142: my ($map,$mid,$murl)=
1143: &Apache::lonnet::decode_symb($symb);
1144: if ($requrl eq '/adm/navmaps') {
1145: &Apache::lonnet::symblist($map,$murl =>[$murl,$mid]);
1146: } else {
1147: if (($map =~ /\.page$/) && ($requrl !~ /\.page$/)) {
1148: my $mapsymb = &Apache::lonnet::symbread($map);
1149: ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb);
1.159.2.9 raeburn 1150: }
1.159.2.12 raeburn 1151: &Apache::lonnet::symblist($map,$murl =>[$murl,$mid],
1152: 'last_known' =>[$murl,$mid]);
1153: }
1.61 albertel 1154: }
1.92 albertel 1155: }
1156: $env{'request.symb'}=$symb;
1.159.2.11 raeburn 1157: if (($env{'request.symbread.cached.'}) && ($env{'request.symbread.cached.'} ne $symb)) {
1158: $env{'request.symbread.cached.'} = $symb;
1159: }
1.92 albertel 1160: &Apache::lonnet::courseacclog($symb);
1161: } else {
1.23 www 1162: # ------------------------------------------------------- This is other content
1.92 albertel 1163: &Apache::lonnet::courseacclog($requrl);
1164: }
1.140 raeburn 1165: if ($requrl =~ m{^/+uploaded/\Q$cdom\E/\Q$cnum\E/(docs|supplemental)/.+\.html?$}) {
1.125 raeburn 1166: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1167: if ($query) {
1168: &Apache::loncommon::get_unprocessed_cgi($query,['forceedit']);
1169: if ($env{'form.forceedit'}) {
1170: $env{'request.state'} = 'edit';
1171: }
1172: }
1173: }
1.144 raeburn 1174: } elsif ($requrl =~ m{^/+uploaded/\Q$cdom\E/\Q$cnum\E/portfolio/syllabus/.+\.html?$}) {
1175: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1176: if ($query) {
1177: &Apache::loncommon::get_unprocessed_cgi($query,['forceedit','editmode']);
1178: if (($env{'form.forceedit'}) || ($env{'form.editmode'})) {
1179: $env{'request.state'} = 'edit';
1180: }
1181: }
1182: }
1.125 raeburn 1183: }
1.88 albertel 1184: }
1.92 albertel 1185: return OK;
1.137 raeburn 1186: } else {
1187: my $defdom=$r->dir_config('lonDefDomain');
1188: ($is_balancer,$otherserver) =
1189: &Apache::lonnet::check_loadbalancing(undef,$defdom);
1190: if ($is_balancer) {
1191: $r->set_handlers('PerlResponseHandler'=>
1192: [\&Apache::switchserver::handler]);
1193: if ($otherserver ne '') {
1194: $env{'form.otherserver'} = $otherserver;
1195: }
1196: }
1.92 albertel 1197: }
1.21 www 1198: # -------------------------------------------- See if this is a public resource
1.68 albertel 1199: if ($requrl=~m|^/+adm/+help/+|) {
1.89 albertel 1200: return OK;
1.68 albertel 1201: }
1.90 albertel 1202: # ------------------------------------ See if this is a viewable portfolio file
1.89 albertel 1203: if (&Apache::lonnet::is_portfolio_url($requrl)) {
1.159.2.18 raeburn 1204: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1.159.2.3 raeburn 1205: my $access=&Apache::lonnet::allowed('bre',$requrl,undef,undef,$clientip);
1.90 albertel 1206: if ($access eq 'A') {
1207: &Apache::restrictedaccess::setup_handler($r);
1208: return OK;
1209: }
1210: if (($access ne '2') && ($access ne 'F')) {
1211: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1212: return HTTP_NOT_ACCEPTABLE;
1213: }
1.79 raeburn 1214: }
1.87 albertel 1215:
1.34 www 1216: # -------------------------------------------------------------- Not authorized
1217: $requrl=~/\.(\w+)$/;
1.62 albertel 1218: # if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
1219: # ($requrl=~/^\/adm\/(roles|logout|email|menu|remote)/) ||
1220: # ($requrl=~m|^/prtspool/|)) {
1.34 www 1221: # -------------------------- Store where they wanted to go and get login screen
1.64 albertel 1222: $env{'request.querystring'}=$r->args;
1223: $env{'request.firsturl'}=$requrl;
1.34 www 1224: return FORBIDDEN;
1.62 albertel 1225: # } else {
1.34 www 1226: # --------------------------------------------------------------------- Goodbye
1.62 albertel 1227: # return HTTP_BAD_REQUEST;
1228: # }
1.1 albertel 1229: }
1230:
1231: 1;
1232: __END__
1.120 jms 1233:
1.121 jms 1234: =pod
1.120 jms 1235:
1.121 jms 1236: =back
1.120 jms 1237:
1.121 jms 1238: =cut
1.120 jms 1239:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>