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