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