1: # The LearningOnline Network
2: # Cookie Based Access Handler
3: #
4: # $Id: lonacc.pm,v 1.159.2.21.2.2 2022/07/08 15:36:32 raeburn Exp $
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: #
28: ###
29:
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:
94:
95: package Apache::lonacc;
96:
97: use strict;
98: use Apache::Constants qw(:common :http :methods);
99: use Apache::File;
100: use Apache::lonnet;
101: use Apache::loncommon();
102: use Apache::lonlocal;
103: use Apache::restrictedaccess();
104: use Apache::blockedaccess();
105: use Apache::lonprotected();
106: use Fcntl qw(:flock);
107: use LONCAPA qw(:DEFAULT :match);
108:
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:
122: ###############################################
123:
124: sub get_posted_cgi {
125: my ($r,$fields) = @_;
126:
127: my $buffer;
128: if ($r->header_in('Content-length')) {
129: $r->read($buffer,$r->header_in('Content-length'),0);
130: }
131: my $content_type = $r->header_in('Content-type');
132: if ($content_type !~ m{^multipart/form-data}) {
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;
141: if (ref($fields) eq 'ARRAY') {
142: next if (!grep(/^\Q$name\E$/,@{$fields}));
143: }
144: &Apache::loncommon::add_to_env("form.$name",$value);
145: }
146: } else {
147: my ($contentsep) = ($content_type =~ /boundary=\"?([^\";,]+)\"?/);
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++) {
155: if ($lines[$i]=~/^--\Q$contentsep\E/) {
156: if ($name) {
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: }
163: }
164: if ($fname =~ /\.(xls|doc|ppt)(x|m)$/i) {
165: $value=~s/[\r\n]$//;
166: }
167: if (ref($fields) eq 'ARRAY') {
168: next if (!grep(/^\Q$name\E$/,@{$fields}));
169: }
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: }
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:
232: =pod
233:
234: =over
235:
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
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;
250: my $savesize = sprintf("%.6f",$size);
251: &Apache::loncommon::add_to_env("form.$item",$savesize);
252: my $maxsize= &Apache::lonnet::EXT("resource.$ident.maxfilesize");
253: if (!$maxsize) {
254: $maxsize = 10.0; # FIXME This should become a domain configuration.
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:
265: =pod
266:
267: =item sso_login()
268:
269: handle the case of the single sign on user, at this point $r->user
270: will be set and valid; now need to find the loncapa user info, and possibly
271: balance them. If $r->user() is set this means either it was either set by
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().
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.
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.
288:
289: =cut
290:
291: sub sso_login {
292: my ($r,$handle,$username) = @_;
293:
294: if (($r->user eq '') || ($username ne '') || ($r->user eq 'public:public') ||
295: (defined($env{'user.name'}) && (defined($env{'user.domain'}))
296: && ($handle ne ''))) {
297: # not an SSO case or already logged in
298: return undef;
299: }
300:
301: my ($user) = ($r->user =~ m/^($match_username)$/);
302: if ($user eq '') {
303: return undef;
304: }
305:
306: my $query = $r->args;
307: my %form;
308: if ($query) {
309:
310: my @items = ('role','symb','iptoken','origurl','ttoken',
311: 'ltoken','linkkey','logtoken','sso');
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};
316: }
317: }
318: }
319:
320: my %sessiondata;
321: if ($form{'iptoken'}) {
322: %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
323: my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
324: unless ($sessiondata{'sessionserver'}) {
325: delete($form{'iptoken'});
326: }
327: }
328:
329: my ($linkprot,$linkprotuser,$linkprotexit,$linkkey,$deeplinkurl);
330:
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,
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).
350: #
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
354: #
355:
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'}) {
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: }
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: }
398: if ($form{'iptoken'}) {
399: %sessiondata = &Apache::lonnet::tmpget($form{'iptoken'});
400: my $delete = &Apache::lonnet::tmpdel($form{'iptoken'});
401: }
402: }
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'};
446: }
447:
448: my $domain = $r->dir_config('lonSSOUserDomain');
449: if ($domain eq '') {
450: $domain = $r->dir_config('lonDefDomain');
451: }
452: if (($deeplinkurl) && ($linkprot) && ($linkprotuser ne '')) {
453: unless ($linkprotuser eq $user.':'.$domain) {
454: $r->user();
455: my %data = (
456: origurl => $deeplinkurl,
457: linkprot => $linkprot,
458: linkprotuser => $linkprotuser,
459: linkprotexit => $linkprotexit,
460: );
461: my $token = &Apache::lonnet::tmpput(\%data,$r->dir_config('lonHostID'),'link');
462: unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
463: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
464: $r->internal_redirect('/adm/relaunch?rtoken='.$token);
465: $r->set_handlers('PerlHandler'=> undef);
466: return OK;
467: }
468: }
469: }
470: my $home=&Apache::lonnet::homeserver($user,$domain);
471: if ($home !~ /(con_lost|no_host|no_such_host)/) {
472: &Apache::lonnet::logthis(" SSO authorized user $user ");
473: my ($is_balancer,$otherserver,$hosthere);
474: if ($form{'iptoken'}) {
475: if (($sessiondata{'domain'} eq $domain) &&
476: ($sessiondata{'username'} eq $user)) {
477: $hosthere = 1;
478: }
479: }
480: unless ($hosthere) {
481: ($is_balancer,$otherserver) =
482: &Apache::lonnet::check_loadbalancing($user,$domain,'login');
483: if ($is_balancer) {
484: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
485: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r);
486: if (($found_server) && ($balancer_cookie =~ /^\Q$domain\E_\Q$user\E_/)) {
487: $otherserver = $found_server;
488: } elsif ($otherserver eq '') {
489: my $lowest_load;
490: ($otherserver,undef,undef,undef,$lowest_load) = &Apache::lonnet::choose_server($domain);
491: if ($lowest_load > 100) {
492: $otherserver = &Apache::lonnet::spareserver($r,$lowest_load,$lowest_load,1,$domain);
493: }
494: if ($otherserver ne '') {
495: my @hosts = &Apache::lonnet::current_machine_ids();
496: if (grep(/^\Q$otherserver\E$/,@hosts)) {
497: $hosthere = $otherserver;
498: }
499: }
500: }
501: }
502: }
503: if (($is_balancer) && (!$hosthere)) {
504: # login but immediately go to switch server to find us a new
505: # machine
506: &Apache::lonauth::success($r,$user,$domain,$home,'noredirect');
507: foreach my $item (keys(%form)) {
508: $env{'form.'.$item} = $form{$item};
509: }
510: unless (($form{'symb'}) || ($form{'origurl'})) {
511: unless (($r->uri eq '/adm/roles') || ($r->uri eq '/adm/sso')) {
512: $env{'form.origurl'} = $r->uri;
513: }
514: }
515: if (($r->uri eq '/adm/sso') && ($form{'origurl'} =~ m{^/+tiny/+$match_domain/+\w+$})) {
516: $env{'request.deeplink.login'} = $form{'origurl'};
517: } elsif ($r->uri =~ m{^/+tiny/+$match_domain/+\w+$}) {
518: $env{'request.deeplink.login'} = $r->uri;
519: }
520: if ($env{'request.deeplink.login'}) {
521: if ($linkprot) {
522: $env{'request.linkprot'} = $linkprot;
523: if ($linkprotuser ne '') {
524: $env{'request.linkprotuser'} = $linkprotuser;
525: }
526: if ($linkprotexit ne '') {
527: $env{'request.linkprotexit'} = $linkprotexit;
528: }
529: } elsif ($linkkey ne '') {
530: $env{'request.linkkey'} = $linkkey;
531: }
532: }
533: $env{'request.sso.login'} = 1;
534: if (defined($r->dir_config("lonSSOReloginServer"))) {
535: $env{'request.sso.reloginserver'} =
536: $r->dir_config('lonSSOReloginServer');
537: }
538: my $redirecturl = '/adm/switchserver';
539: if ($otherserver ne '') {
540: $redirecturl .= '?otherserver='.$otherserver;
541: }
542: $r->internal_redirect($redirecturl);
543: $r->set_handlers('PerlHandler'=> undef);
544: } else {
545: # need to login them in, so generate the need data that
546: # migrate expects to do login
547: my $ip = &Apache::lonnet::get_requestor_ip($r);
548: my %info=('ip' => $ip,
549: 'domain' => $domain,
550: 'username' => $user,
551: 'server' => $r->dir_config('lonHostID'),
552: 'sso.login' => 1
553: );
554: foreach my $item ('role','symb','iptoken','origurl') {
555: if (exists($form{$item})) {
556: $info{$item} = $form{$item};
557: } elsif ($sessiondata{$item} ne '') {
558: $info{$item} = $sessiondata{$item};
559: }
560: }
561: unless (($info{'symb'}) || ($info{'origurl'})) {
562: unless (($r->uri eq '/adm/roles') || ($r->uri eq '/adm/sso')) {
563: $info{'origurl'} = $r->uri;
564: }
565: }
566: if (($r->uri eq '/adm/sso') && ($form{'origurl'} =~ m{^/+tiny/+$match_domain/+\w+$})) {
567: $info{'deeplink.login'} = $form{'origurl'};
568: } elsif ($r->uri =~ m{^/+tiny/+$match_domain/+\w+$}) {
569: $info{'deeplink.login'} = $r->uri;
570: }
571: if ($info{'deeplink.login'}) {
572: if ($linkprot) {
573: $info{'linkprot'} = $linkprot;
574: if ($linkprotuser ne '') {
575: $info{'linkprotuser'} = $linkprotuser;
576: }
577: if ($linkprotexit ne '') {
578: $info{'linkprotexit'} = $linkprotexit;
579: }
580: } elsif ($linkkey ne '') {
581: $info{'linkkey'} = $linkkey;
582: }
583: }
584: if ($r->dir_config("ssodirecturl") == 1) {
585: $info{'origurl'} = $r->uri;
586: }
587: if (defined($r->dir_config("lonSSOReloginServer"))) {
588: $info{'sso.reloginserver'} =
589: $r->dir_config('lonSSOReloginServer');
590: }
591: if (($is_balancer) && ($hosthere)) {
592: $info{'noloadbalance'} = $hosthere;
593: }
594: my $token = &Apache::lonnet::tmpput(\%info,$r->dir_config('lonHostID'),'sso');
595: $env{'form.token'} = $token;
596: $r->internal_redirect('/adm/migrateuser');
597: $r->set_handlers('PerlHandler'=> undef);
598: }
599: return OK;
600: } else {
601: &Apache::lonnet::logthis(" SSO authorized unknown user $user ");
602: my @cancreate;
603: my %domconfig =
604: &Apache::lonnet::get_dom('configuration',['usercreation'],$domain);
605: if (ref($domconfig{'usercreation'}) eq 'HASH') {
606: if (ref($domconfig{'usercreation'}{'cancreate'}) eq 'HASH') {
607: if (ref($domconfig{'usercreation'}{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
608: @cancreate = @{$domconfig{'usercreation'}{'cancreate'}{'selfcreate'}};
609: } elsif (($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne 'none') &&
610: ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'} ne '')) {
611: @cancreate = ($domconfig{'usercreation'}{'cancreate'}{'selfcreate'});
612: }
613: }
614: }
615: if ((grep(/^sso$/,@cancreate)) || (defined($r->dir_config('lonSSOUserUnknownRedirect')))) {
616: $r->subprocess_env->set('SSOUserUnknown' => $user);
617: $r->subprocess_env->set('SSOUserDomain' => $domain);
618: if (grep(/^sso$/,@cancreate)) {
619: #FIXME - need to preserve origurl, role and symb, or linkprot or linkkey for use after account
620: # creation
621: $r->set_handlers('PerlHandler'=> [\&Apache::createaccount::handler]);
622: $r->handler('perl-script');
623: } else {
624: $r->internal_redirect($r->dir_config('lonSSOUserUnknownRedirect'));
625: $r->set_handlers('PerlHandler'=> undef);
626: }
627: return OK;
628: }
629: }
630: return undef;
631: }
632:
633: sub handler {
634: my $r = shift;
635: my $requrl=$r->uri;
636:
637: if ($requrl =~ m{^/res/adm/pages/[^/]+\.(gif|png)$}) {
638: return OK;
639: }
640:
641: if (&Apache::lonnet::is_domainimage($requrl)) {
642: return OK;
643: }
644:
645: my %user;
646: my $handle = &Apache::lonnet::check_for_valid_session($r,undef,\%user);
647:
648: unless (($requrl eq '/adm/switchserver') && (!$r->is_initial_req())) {
649: my $result = &sso_login($r,$handle,$user{'name'});
650: if (defined($result)) {
651: return $result;
652: }
653: }
654:
655: my ($is_balancer,$otherserver);
656:
657: if ($handle eq '') {
658: unless ((($requrl eq '/adm/switchserver') && (!$r->is_initial_req())) ||
659: ($requrl =~ m{^/public/$match_domain/$match_courseid/syllabus}) ||
660: ($requrl =~ m{^/adm/help/}) || ($requrl eq '/adm/sso') ||
661: ($requrl =~ m{^/res/$match_domain/$match_username/})) {
662: $r->log_reason("Cookie not valid", $r->filename);
663: }
664: } elsif ($handle ne '') {
665:
666: # ------------------------------------------------------ Initialize Environment
667: my $lonidsdir=$r->dir_config('lonIDsDir');
668: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
669:
670: # --------------------------------------------------------- Initialize Language
671:
672: &Apache::lonlocal::get_language_handle($r);
673:
674: }
675:
676: # -------------------------------------------------- Should be a valid user now
677: if ($env{'user.name'} ne '' && $env{'user.domain'} ne '') {
678: # -------------------------------------------------------------- Resource State
679:
680: my ($cdom,$cnum);
681: if ($env{'request.course.id'}) {
682: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
683: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
684: }
685: if ($requrl=~/^\/+(res|uploaded)\//) {
686: $env{'request.state'} = "published";
687: } else {
688: $env{'request.state'} = 'unknown';
689: }
690: $env{'request.filename'} = $r->filename;
691: $env{'request.noversionuri'} = &Apache::lonnet::deversion($requrl);
692: my ($suppext,$checkabsolute);
693: if ($requrl =~ m{^/adm/wrapper/ext/}) {
694: my $query = $r->args;
695: if ($query) {
696: my $preserved;
697: foreach my $pair (split(/&/,$query)) {
698: my ($name, $value) = split(/=/,$pair);
699: unless (($name eq 'symb') || ($name eq 'usehttp')) {
700: $preserved .= $pair.'&';
701: }
702: if (($env{'request.course.id'}) && ($name eq 'folderpath')) {
703: if ($value =~ /^supplemental/) {
704: $suppext = 1;
705: }
706: }
707: }
708: $preserved =~ s/\&$//;
709: if ($preserved) {
710: $env{'request.external.querystring'} = $preserved;
711: }
712: }
713: if ($env{'request.course.id'}) {
714: $checkabsolute = 1;
715: }
716: } elsif ($env{'request.course.id'} &&
717: (($requrl =~ m{^/adm/$match_domain/$match_username/aboutme$}) ||
718: ($requrl =~ m{^/public/$cdom/$cnum/syllabus$}))) {
719: my $query = $r->args;
720: if ($query) {
721: foreach my $pair (split(/&/,$query)) {
722: my ($name, $value) = split(/=/,$pair);
723: if ($name eq 'folderpath') {
724: if ($value =~ /^supplemental/) {
725: $suppext = 1;
726: }
727: last;
728: }
729: }
730: }
731: if ($requrl =~ m{^/public/$cdom/$cnum/syllabus$}) {
732: $checkabsolute = 1;
733: }
734: }
735: if ($checkabsolute) {
736: my $hostname = $r->hostname();
737: my $lonhost = &Apache::lonnet::host_from_dns($hostname);
738: if ($lonhost) {
739: my $actual = &Apache::lonnet::absolute_url($hostname,1,1);
740: my $expected = $Apache::lonnet::protocol{$lonhost}.'://'.$hostname;
741: unless ($actual eq $expected) {
742: $env{'request.use_absolute'} = $expected;
743: }
744: }
745: }
746: # -------------------------------------------------------- Load POST parameters
747:
748: &Apache::lonacc::get_posted_cgi($r);
749:
750: # ------------------------------------------------------ Check if load balancer
751:
752: my $checkexempt;
753: if ($env{'user.loadbalexempt'} eq $r->dir_config('lonHostID')) {
754: if ($env{'user.loadbalcheck.time'} + 600 > time) {
755: $checkexempt = 1;
756: }
757: }
758: if ($env{'user.noloadbalance'} eq $r->dir_config('lonHostID')) {
759: $checkexempt = 1;
760: }
761: unless (($checkexempt) || (($requrl eq '/adm/switchserver') && (!$r->is_initial_req()))) {
762: ($is_balancer,$otherserver) =
763: &Apache::lonnet::check_loadbalancing($env{'user.name'},
764: $env{'user.domain'});
765: if ($is_balancer) {
766: # Check if browser sent a LON-CAPA load balancer cookie (and this is a balancer)
767: my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r);
768: if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) {
769: $otherserver = $found_server;
770: }
771: unless ($requrl eq '/adm/switchserver') {
772: $r->set_handlers('PerlResponseHandler'=>
773: [\&Apache::switchserver::handler]);
774: }
775: if ($otherserver ne '') {
776: $env{'form.otherserver'} = $otherserver;
777: }
778: unless (($env{'form.origurl'}) || ($r->uri eq '/adm/roles') ||
779: ($r->uri eq '/adm/switchserver') || ($r->uri eq '/adm/sso')) {
780: $env{'form.origurl'} = $r->uri;
781: }
782: }
783: }
784: if ($requrl=~m{^/+tiny/+$match_domain/+\w+$}) {
785: if ($r->args) {
786: &Apache::loncommon::get_unprocessed_cgi($r->args,['ttoken']);
787: if (defined($env{'form.ttoken'})) {
788: my %info = &Apache::lonnet::tmpget($env{'form.ttoken'});
789: if (($info{'origurl'} ne '') && ($info{'origurl'} eq $requrl)) {
790: my %data;
791: if (($info{'linkprotuser'} ne '') && ($info{'linkprot'}) &&
792: ($info{'linkprotuser'} ne $env{'user.name'}.':'.$env{'user.domain'})) {
793: %data = (
794: origurl => $requrl,
795: linkprot => $info{'linkprot'},
796: linkprotuser => $info{'linkprotuser'},
797: linkprotexit => $info{'linkprotexit'},
798: );
799: } elsif ($info{'ltoken'} ne '') {
800: my %ltoken_info = &Apache::lonnet::tmpget($info{'ltoken'});
801: if (($ltoken_info{'linkprotuser'} ne '') && ($ltoken_info{'linkprot'}) &&
802: ($ltoken_info{'linkprotuser'} ne $env{'user.name'}.':'.$env{'user.domain'})) {
803: %data = (
804: origurl => $requrl,
805: linkprot => $ltoken_info{'linkprot'},
806: linkprotuser => $ltoken_info{'linkprotuser'},
807: linkprotexit => $ltoken_info{'linkprotexit'},
808: );
809: }
810: }
811: if (keys(%data)) {
812: my $delete = &Apache::lonnet::tmpdel($env{'form.ttoken'});
813: if ($info{'ltoken'} ne '') {
814: my $delete = &Apache::lonnet::tmpdel($info{'ltoken'});
815: }
816: my $token =
817: &Apache::lonnet::tmpput(\%data,$r->dir_config('lonHostID'),'retry');
818: unless (($token eq 'con_lost') || ($token eq 'refused') || ($token =~ /^error:/) ||
819: ($token eq 'unknown_cmd') || ($token eq 'no_such_host')) {
820: $r->internal_redirect('/adm/relaunch?rtoken='.$token);
821: $r->set_handlers('PerlHandler'=> undef);
822: return OK;
823: }
824: }
825: }
826: }
827: }
828: if ($env{'user.name'} eq 'public' &&
829: $env{'user.domain'} eq 'public') {
830: $env{'request.firsturl'}=$requrl;
831: return FORBIDDEN;
832: }
833: return OK;
834: }
835: # ---------------------------------------------------------------- Check access
836: my $now = time;
837: my ($check_symb,$check_access,$check_block,$access,$poss_symb);
838: if ($requrl !~ m{^/(?:adm|public|(?:prt|zip)spool)/}
839: || $requrl =~ /^\/adm\/.*\/(smppg|bulletinboard)(\?|$ )/x) {
840: $check_access = 1;
841: }
842: if ((!$check_access) && ($env{'request.course.id'})) {
843: if (($requrl eq '/adm/viewclasslist') ||
844: ($requrl =~ m{^(/adm/wrapper|)\Q/uploaded/$cdom/$cnum/docs/\E}) ||
845: ($requrl =~ m{^/adm/.*/aboutme$}) ||
846: ($requrl=~m{^/adm/coursedocs/showdoc/}) ||
847: ($requrl=~m{^(/adm/wrapper|)/adm/$cdom/$cnum/\d+/ext\.tool$})) {
848: $check_block = 1;
849: }
850: }
851: if (($env{'request.course.id'}) && (!$suppext)) {
852: $requrl=~/\.(\w+)$/;
853: if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
854: ($requrl=~/^\/adm\/.*\/(aboutme|smppg|bulletinboard)(\?|$ )/x) ||
855: ($requrl=~/^\/adm\/wrapper\//) ||
856: ($requrl=~m|^/adm/coursedocs/showdoc/|) ||
857: ($requrl=~m|\.problem/smpedit$|) ||
858: ($requrl=~/^\/public\/.*\/syllabus$/) ||
859: ($requrl=~/^\/adm\/(viewclasslist|navmaps)$/) ||
860: ($requrl=~/^\/adm\/.*\/aboutme\/portfolio(\?|$)/) ||
861: ($requrl=~m{^/adm/$cdom/$cnum/\d+/ext\.tool$})) {
862: $check_symb = 1;
863: }
864: }
865: if (($check_access) || ($check_block)) {
866: if ($check_symb) {
867: if ($env{'form.symb'}) {
868: $poss_symb=&Apache::lonnet::symbclean($env{'form.symb'});
869: } elsif (($env{'request.course.id'}) && ($r->args ne '')) {
870: my $query = $r->args;
871: foreach my $pair (split(/&/,$query)) {
872: my ($name, $value) = split(/=/,$pair);
873: $name = &unescape($name);
874: $value =~ tr/+/ /;
875: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
876: if ($name eq 'symb') {
877: $poss_symb = &Apache::lonnet::symbclean($value);
878: last;
879: }
880: }
881: }
882: if ($poss_symb) {
883: my ($possmap,$resid,$url)=&Apache::lonnet::decode_symb($poss_symb);
884: $url = &Apache::lonnet::clutter($url);
885: my $toplevelmap = $env{'course.'.$env{'request.course.id'}.'.url'};
886: unless (($url eq $requrl) && (($possmap eq $toplevelmap) ||
887: (&Apache::lonnet::is_on_map($possmap)))) {
888: undef($poss_symb);
889: }
890: if ($poss_symb) {
891: if ((!$env{'request.role.adv'}) && ($env{'acc.randomout'}) &&
892: ($env{'acc.randomout'}=~/\&\Q$poss_symb\E\&/)) {
893: undef($poss_symb);
894: } elsif ((!$env{'request.role.adv'}) && ($env{'acc.deeplinkout'}) &&
895: ($env{'acc.deeplinkout'}=~/\&\Q$poss_symb\E\&/)) {
896: undef($poss_symb);
897: }
898: }
899: }
900: if ($poss_symb) {
901: $access=&Apache::lonnet::allowed('bre',$requrl,$poss_symb);
902: } else {
903: $access=&Apache::lonnet::allowed('bre',$requrl,'','','','',1);
904: }
905: } else {
906: my $nodeeplinkcheck;
907: if (($check_access) && ($requrl =~ /\.(sequence|page)$/)) {
908: unless ($env{'form.navmap'}) {
909: if ($r->args ne '') {
910: &Apache::loncommon::get_unprocessed_cgi($r->args,['navmap']);
911: unless ($env{'form.navmap'}) {
912: $nodeeplinkcheck = 1;
913: }
914: }
915: }
916: }
917: my $clientip = &Apache::lonnet::get_requestor_ip($r);
918: $access=&Apache::lonnet::allowed('bre',$requrl,'','',$clientip,'','',$nodeeplinkcheck);
919: }
920: }
921: if ($check_block) {
922: if ($access eq 'B') {
923: if ($poss_symb) {
924: if (&Apache::lonnet::symbverify($poss_symb,$requrl)) {
925: $env{'request.symb'} = $poss_symb;
926: }
927: }
928: &Apache::blockedaccess::setup_handler($r);
929: return OK;
930: }
931: } elsif ($check_access) {
932: if ($handle eq '') {
933: unless ($access eq 'F') {
934: if ($requrl =~ m{^/res/$match_domain/$match_username/}) {
935: $r->log_reason("Cookie not valid", $r->filename);
936: }
937: }
938: }
939: if ($access eq '1') {
940: $env{'user.error.msg'}="$requrl:bre:0:0:Choose Course";
941: return HTTP_NOT_ACCEPTABLE;
942: }
943: if ($access eq 'A') {
944: &Apache::restrictedaccess::setup_handler($r);
945: return OK;
946: }
947: if ($access eq 'B') {
948: if ($poss_symb) {
949: if (&Apache::lonnet::symbverify($poss_symb,$requrl)) {
950: $env{'request.symb'} = $poss_symb;
951: }
952: }
953: &Apache::blockedaccess::setup_handler($r);
954: return OK;
955: }
956: if ($access eq 'D') {
957: &Apache::lonprotected::setup_handler($r);
958: return OK;
959: }
960: if (($access ne '2') && ($access ne 'F')) {
961: if ($requrl =~ m{^/res/}) {
962: $access = &Apache::lonnet::allowed('bro',$requrl);
963: if ($access ne 'F') {
964: if ($requrl eq '/res/lib/templates/simpleproblem.problem/smpedit') {
965: $access = &Apache::lonnet::allowed('bre','/res/lib/templates/simpleproblem.problem');
966: if ($access ne 'F') {
967: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
968: return HTTP_NOT_ACCEPTABLE;
969: }
970: } else {
971: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
972: return HTTP_NOT_ACCEPTABLE;
973: }
974: }
975: } elsif (($handle =~ /^publicuser_\d+$/) && (&Apache::lonnet::is_portfolio_url($requrl))) {
976: my $clientip = &Apache::lonnet::get_requestor_ip($r);
977: if (&Apache::lonnet::allowed('bre',$requrl,undef,undef,$clientip) ne 'F') {
978: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
979: return HTTP_NOT_ACCEPTABLE;
980: }
981: } else {
982: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
983: return HTTP_NOT_ACCEPTABLE;
984: }
985: }
986: }
987: if ($requrl =~ m|^/prtspool/|) {
988: my $start='/prtspool/'.$env{'user.name'}.'_'.
989: $env{'user.domain'};
990: if ($requrl !~ /^\Q$start\E/) {
991: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
992: return HTTP_NOT_ACCEPTABLE;
993: }
994: }
995: if ($requrl =~ m|^/zipspool/|) {
996: my $start='/zipspool/zipout/'.$env{'user.name'}.":".
997: $env{'user.domain'};
998: if ($requrl !~ /^\Q$start\E/) {
999: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1000: return HTTP_NOT_ACCEPTABLE;
1001: }
1002: }
1003: if ($env{'user.name'} eq 'public' &&
1004: $env{'user.domain'} eq 'public' &&
1005: $requrl !~ m{^/+(res|public|uploaded)/} &&
1006: $requrl !~ m{^/adm/[^/]+/[^/]+/aboutme/portfolio$ }x &&
1007: $requrl !~ m{^/adm/blockingstatus/.*$} &&
1008: $requrl !~ m{^/+adm/(help|logout|restrictedaccess|randomlabel\.png)}) {
1009: $env{'request.querystring'}=$r->args;
1010: $env{'request.firsturl'}=$requrl;
1011: return FORBIDDEN;
1012: }
1013: # ------------------------------------------------------------- This is allowed
1014: if ($env{'request.course.id'}) {
1015: &Apache::lonnet::countacc($requrl);
1016: my $query=$r->args;
1017: if ($check_symb) {
1018: # ------------------------------------- This is serious stuff, get symb and log
1019: my $symb;
1020: if ($query) {
1021: &Apache::loncommon::get_unprocessed_cgi($query,['symb','folderpath']);
1022: }
1023: if ($env{'form.symb'}) {
1024: $symb=&Apache::lonnet::symbclean($env{'form.symb'});
1025: if (($requrl eq '/adm/navmaps') ||
1026: ($requrl =~ m{^/adm/wrapper/}) ||
1027: ($requrl =~ m{^/adm/coursedocs/showdoc/})) {
1028: unless (&Apache::lonnet::symbverify($symb,$requrl)) {
1029: if (&Apache::lonnet::is_on_map($requrl)) {
1030: $symb = &Apache::lonnet::symbread($requrl);
1031: unless (&Apache::lonnet::symbverify($symb,$requrl)) {
1032: undef($symb);
1033: }
1034: }
1035: }
1036: if ($symb) {
1037: if ($requrl eq '/adm/navmaps') {
1038: my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1039: &Apache::lonnet::symblist($map,$murl => [$murl,$mid]);
1040: } elsif (($requrl =~ m{^/adm/wrapper/}) ||
1041: ($requrl =~ m{^/adm/coursedocs/showdoc/})) {
1042: my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1043: if ($map =~ /\.page$/) {
1044: my $mapsymb = &Apache::lonnet::symbread($map);
1045: ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb);
1046: }
1047: &Apache::lonnet::symblist($map,$murl => [$murl,$mid],
1048: 'last_known' =>[$murl,$mid]);
1049: }
1050: }
1051: } elsif ((&Apache::lonnet::symbverify($symb,$requrl)) ||
1052: (($requrl=~m|(.*)/smpedit$|) &&
1053: &Apache::lonnet::symbverify($symb,$1)) ||
1054: (($requrl=~m|(.*/aboutme)/portfolio$|) &&
1055: &Apache::lonnet::symbverify($symb,$1))) {
1056: my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb);
1057: if (($map =~ /\.page$/) && ($requrl !~ /\.page$/)) {
1058: my $mapsymb = &Apache::lonnet::symbread($map);
1059: ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb);
1060: }
1061: &Apache::lonnet::symblist($map,$murl => [$murl,$mid],
1062: 'last_known' =>[$murl,$mid]);
1063: } else {
1064: $r->log_reason('Invalid symb for '.$requrl.': '.
1065: $symb);
1066: $env{'user.error.msg'}=
1067: "$requrl:bre:1:1:Invalid Access";
1068: return HTTP_NOT_ACCEPTABLE;
1069: }
1070: } else {
1071: if ($requrl=~m{^(/adm/.*/aboutme)/portfolio$}) {
1072: $requrl = $1;
1073: }
1074: $symb=&Apache::lonnet::symbread($requrl);
1075: if (&Apache::lonnet::is_on_map($requrl) && $symb) {
1076: my ($encstate,$invalidsymb);
1077: unless (&Apache::lonnet::symbverify($symb,$requrl,\$encstate)) {
1078: $invalidsymb = 1;
1079: #
1080: # If $env{'request.enc'} inconsistent with encryption expected for $symb
1081: # retrieved by lonnet::symbread(), call again to check for an instance of
1082: # $requrl in the course for which expected encryption matches request.enc.
1083: # If symb for different instance passes lonnet::symbverify(), use that as
1084: # the symb for $requrl and call &Apache::lonnet::allowed() for that symb.
1085: # Report invalid symb if there is no other symb. Redirect to /adm/ambiguous
1086: # if multiple possible symbs consistent with request.enc available for $requrl.
1087: #
1088: if (($env{'request.enc'} && !$encstate) || (!$env{'request.enc'} && $encstate)) {
1089: my %possibles;
1090: my $nocache = 1;
1091: my $oldsymb = $symb;
1092: $symb = &Apache::lonnet::symbread($requrl,'','','',\%possibles,$nocache);
1093: if (($symb) && ($symb ne $oldsymb)) {
1094: if (&Apache::lonnet::symbverify($symb,$requrl)) {
1095: my $access=&Apache::lonnet::allowed('bre',$requrl,$symb);
1096: if ($access eq 'B') {
1097: $env{'request.symb'} = $symb;
1098: &Apache::blockedaccess::setup_handler($r);
1099: return OK;
1100: } elsif (($access eq '2') || ($access eq 'F')) {
1101: $invalidsymb = '';
1102: }
1103: }
1104: } elsif (keys(%possibles) > 1) {
1105: $r->internal_redirect('/adm/ambiguous');
1106: return OK;
1107: }
1108: }
1109: if ($invalidsymb) {
1110: if ($requrl eq '/adm/navmaps') {
1111: undef($symb);
1112: } else {
1113: $r->log_reason('Invalid symb for '.$requrl.': '.$symb);
1114: $env{'user.error.msg'}=
1115: "$requrl:bre:1:1:Invalid Access";
1116: return HTTP_NOT_ACCEPTABLE;
1117: }
1118: }
1119: }
1120: }
1121: if ($symb) {
1122: my ($map,$mid,$murl)=
1123: &Apache::lonnet::decode_symb($symb);
1124: if ($requrl eq '/adm/navmaps') {
1125: &Apache::lonnet::symblist($map,$murl =>[$murl,$mid]);
1126: } else {
1127: if (($map =~ /\.page$/) && ($requrl !~ /\.page$/)) {
1128: my $mapsymb = &Apache::lonnet::symbread($map);
1129: ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb);
1130: }
1131: &Apache::lonnet::symblist($map,$murl =>[$murl,$mid],
1132: 'last_known' =>[$murl,$mid]);
1133: }
1134: }
1135: }
1136: $env{'request.symb'}=$symb;
1137: if (($env{'request.symbread.cached.'}) && ($env{'request.symbread.cached.'} ne $symb)) {
1138: $env{'request.symbread.cached.'} = $symb;
1139: }
1140: &Apache::lonnet::courseacclog($symb);
1141: } else {
1142: # ------------------------------------------------------- This is other content
1143: &Apache::lonnet::courseacclog($requrl);
1144: }
1145: if ($requrl =~ m{^/+uploaded/\Q$cdom\E/\Q$cnum\E/(docs|supplemental)/.+\.html?$}) {
1146: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1147: if ($query) {
1148: &Apache::loncommon::get_unprocessed_cgi($query,['forceedit']);
1149: if ($env{'form.forceedit'}) {
1150: $env{'request.state'} = 'edit';
1151: }
1152: }
1153: }
1154: } elsif ($requrl =~ m{^/+uploaded/\Q$cdom\E/\Q$cnum\E/portfolio/syllabus/.+\.html?$}) {
1155: if (&Apache::lonnet::allowed('mdc',$env{'request.course.id'})) {
1156: if ($query) {
1157: &Apache::loncommon::get_unprocessed_cgi($query,['forceedit','editmode']);
1158: if (($env{'form.forceedit'}) || ($env{'form.editmode'})) {
1159: $env{'request.state'} = 'edit';
1160: }
1161: }
1162: }
1163: }
1164: }
1165: return OK;
1166: } else {
1167: my $defdom=$r->dir_config('lonDefDomain');
1168: ($is_balancer,$otherserver) =
1169: &Apache::lonnet::check_loadbalancing(undef,$defdom);
1170: if ($is_balancer) {
1171: $r->set_handlers('PerlResponseHandler'=>
1172: [\&Apache::switchserver::handler]);
1173: if ($otherserver ne '') {
1174: $env{'form.otherserver'} = $otherserver;
1175: }
1176: }
1177: }
1178: # -------------------------------------------- See if this is a public resource
1179: if ($requrl=~m|^/+adm/+help/+|) {
1180: return OK;
1181: }
1182: # ------------------------------------ See if this is a viewable portfolio file
1183: if (&Apache::lonnet::is_portfolio_url($requrl)) {
1184: my $clientip = &Apache::lonnet::get_requestor_ip($r);
1185: my $access=&Apache::lonnet::allowed('bre',$requrl,undef,undef,$clientip);
1186: if ($access eq 'A') {
1187: &Apache::restrictedaccess::setup_handler($r);
1188: return OK;
1189: }
1190: if (($access ne '2') && ($access ne 'F')) {
1191: $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied";
1192: return HTTP_NOT_ACCEPTABLE;
1193: }
1194: }
1195:
1196: # -------------------------------------------------------------- Not authorized
1197: $requrl=~/\.(\w+)$/;
1198: # if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') ||
1199: # ($requrl=~/^\/adm\/(roles|logout|email|menu|remote)/) ||
1200: # ($requrl=~m|^/prtspool/|)) {
1201: # -------------------------- Store where they wanted to go and get login screen
1202: $env{'request.querystring'}=$r->args;
1203: $env{'request.firsturl'}=$requrl;
1204: return FORBIDDEN;
1205: # } else {
1206: # --------------------------------------------------------------------- Goodbye
1207: # return HTTP_BAD_REQUEST;
1208: # }
1209: }
1210:
1211: 1;
1212: __END__
1213:
1214: =pod
1215:
1216: =back
1217:
1218: =cut
1219:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>