--- loncom/auth/lonacc.pm 2021/01/04 03:47:01 1.159.2.18 +++ loncom/auth/lonacc.pm 2021/01/02 19:31:11 1.186 @@ -1,7 +1,7 @@ # The LearningOnline Network # Cookie Based Access Handler # -# $Id: lonacc.pm,v 1.159.2.18 2021/01/04 03:47:01 raeburn Exp $ +# $Id: lonacc.pm,v 1.186 2021/01/02 19:31:11 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -102,6 +102,7 @@ use Apache::loncommon(); use Apache::lonlocal; use Apache::restrictedaccess(); use Apache::blockedaccess(); +use Apache::lonprotected(); use Fcntl qw(:flock); use LONCAPA qw(:DEFAULT :match); @@ -202,6 +203,14 @@ sub get_posted_cgi { $fname=''; $fmime=''; } + if ($i<$#lines && $lines[$i+1]=~/^Content\-Type\:\s*([\w\-\/]+)/i) { + # TODO: something with $1 ! + $i++; + } + if ($i<$#lines && $lines[$i+1]=~/^Content\-transfer\-encoding\:\s*([\w\-\/]+)/i) { + # TODO: something with $1 ! + $i++; + } $i++; } } else { @@ -355,6 +364,14 @@ sub sso_login { # login but immediately go to switch server to find us a new # machine &Apache::lonauth::success($r,$user,$domain,$home,'noredirect'); + foreach my $item (keys(%form)) { + $env{'form.'.$item} = $form{$item}; + } + unless ($form{'symb'}) { + unless (($r->uri eq '/adm/roles') || ($r->uri eq '/adm/sso')) { + $env{'form.origurl'} = $r->uri; + } + } $env{'request.sso.login'} = 1; if (defined($r->dir_config("lonSSOReloginServer"))) { $env{'request.sso.reloginserver'} = @@ -369,7 +386,7 @@ sub sso_login { } else { # need to login them in, so generate the need data that # migrate expects to do login - my $ip = &Apache::lonnet::get_requestor_ip($r); + my $ip = &Apache::lonnet::get_requestor_ip($r); my %info=('ip' => $ip, 'domain' => $domain, 'username' => $user, @@ -520,7 +537,8 @@ sub handler { } } elsif ($env{'request.course.id'} && (($requrl =~ m{^/adm/$match_domain/$match_username/aboutme$}) || - ($requrl =~ m{^/public/$cdom/$cnum/syllabus$}))) { + ($requrl eq "/public/$cdom/$cnum/syllabus") || + ($requrl =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}))) { my $query = $r->args; if ($query) { foreach my $pair (split(/&/,$query)) { @@ -542,6 +560,7 @@ sub handler { my $lonhost = &Apache::lonnet::host_from_dns($hostname); if ($lonhost) { my $actual = &Apache::lonnet::absolute_url($hostname); + my $exphostname = &Apache::lonnet::hostname($lonhost); my $expected = $Apache::lonnet::protocol{$lonhost}.'://'.$hostname; unless ($actual eq $expected) { $env{'request.use_absolute'} = $expected; @@ -573,7 +592,7 @@ sub handler { if (($found_server) && ($balancer_cookie =~ /^\Q$env{'user.domain'}\E_\Q$env{'user.name'}\E_/)) { $otherserver = $found_server; } - unless ($requrl eq '/adm/switchserver') { + unless ($requrl eq '/adm/switchserver') { $r->set_handlers('PerlResponseHandler'=> [\&Apache::switchserver::handler]); } @@ -586,7 +605,15 @@ sub handler { } } } - + if ($requrl=~m{^/+tiny/+$match_domain/+\w+$}) { + if ($env{'user.name'} eq 'public' && + $env{'user.domain'} eq 'public') { + $env{'request.firsturl'}=$requrl; + return FORBIDDEN; + } else { + return OK; + } + } # ---------------------------------------------------------------- Check access my $now = time; my ($check_symb,$check_access,$check_block,$access,$poss_symb); @@ -598,7 +625,8 @@ sub handler { if (($requrl eq '/adm/viewclasslist') || ($requrl =~ m{^(/adm/wrapper|)\Q/uploaded/$cdom/$cnum/docs/\E}) || ($requrl =~ m{^/adm/.*/aboutme$}) || - ($requrl=~m{^/adm/coursedocs/showdoc/})) { + ($requrl=~m{^/adm/coursedocs/showdoc/}) || + ($requrl=~m{^(/adm/wrapper|)/adm/$cdom/$cnum/\d+/ext\.tool$})) { $check_block = 1; } } @@ -611,7 +639,8 @@ sub handler { ($requrl=~m|\.problem/smpedit$|) || ($requrl=~/^\/public\/.*\/syllabus$/) || ($requrl=~/^\/adm\/(viewclasslist|navmaps)$/) || - ($requrl=~/^\/adm\/.*\/aboutme\/portfolio(\?|$)/)) { + ($requrl=~/^\/adm\/.*\/aboutme\/portfolio(\?|$)/) || + ($requrl=~m{^/adm/$cdom/$cnum/\d+/ext\.tool$})) { $check_symb = 1; } } @@ -666,7 +695,7 @@ sub handler { &Apache::blockedaccess::setup_handler($r); return OK; } - } elsif ($check_access) { + } elsif ($check_access) { if ($handle eq '') { unless ($access eq 'F') { if ($requrl =~ m{^/res/$match_domain/$match_username/}) { @@ -691,6 +720,10 @@ sub handler { &Apache::blockedaccess::setup_handler($r); return OK; } + if ($access eq 'D') { + &Apache::lonprotected::setup_handler($r); + return OK; + } if (($access ne '2') && ($access ne 'F')) { if ($requrl =~ m{^/res/}) { $access = &Apache::lonnet::allowed('bro',$requrl); @@ -707,7 +740,7 @@ sub handler { } } } elsif (($handle =~ /^publicuser_\d+$/) && (&Apache::lonnet::is_portfolio_url($requrl))) { - my $clientip = &Apache::lonnet::get_requestor_ip($r); + my $clientip = &Apache::lonnet::get_requestor_ip($r); if (&Apache::lonnet::allowed('bre',$requrl,undef,undef,$clientip) ne 'F') { $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied"; return HTTP_NOT_ACCEPTABLE; @@ -756,15 +789,15 @@ sub handler { } if ($env{'form.symb'}) { $symb=&Apache::lonnet::symbclean($env{'form.symb'}); - if ($requrl eq '/adm/navmaps') { + if ($requrl eq '/adm/navmaps') { my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb); &Apache::lonnet::symblist($map,$murl => [$murl,$mid]); - } elsif ($requrl =~ m|^/adm/wrapper/| + } elsif ($requrl =~ m|^/adm/wrapper/| || $requrl =~ m|^/adm/coursedocs/showdoc/|) { my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb); if ($map =~ /\.page$/) { my $mapsymb = &Apache::lonnet::symbread($map); - ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb); + ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb); } &Apache::lonnet::symblist($map,$murl => [$murl,$mid], 'last_known' =>[$murl,$mid]); @@ -844,8 +877,8 @@ sub handler { my $mapsymb = &Apache::lonnet::symbread($map); ($map,$mid,$murl)=&Apache::lonnet::decode_symb($mapsymb); } - &Apache::lonnet::symblist($map,$murl =>[$murl,$mid], - 'last_known' =>[$murl,$mid]); + &Apache::lonnet::symblist($map,$murl =>[$murl,$mid], + 'last_known' =>[$murl,$mid]); } } } @@ -898,7 +931,7 @@ sub handler { # ------------------------------------ See if this is a viewable portfolio file if (&Apache::lonnet::is_portfolio_url($requrl)) { my $clientip = &Apache::lonnet::get_requestor_ip($r); - my $access=&Apache::lonnet::allowed('bre',$requrl,undef,undef,$clientip); + my $access=&Apache::lonnet::allowed('bre',$requrl,undef,undef,$clientip); if ($access eq 'A') { &Apache::restrictedaccess::setup_handler($r); return OK;