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