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