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