--- loncom/auth/lonacc.pm 2011/11/18 22:41:02 1.130.6.1 +++ loncom/auth/lonacc.pm 2012/05/30 20:29:49 1.138 @@ -1,7 +1,7 @@ # The LearningOnline Network # Cookie Based Access Handler # -# $Id: lonacc.pm,v 1.130.6.1 2011/11/18 22:41:02 raeburn Exp $ +# $Id: lonacc.pm,v 1.138 2012/05/30 20:29:49 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -156,7 +156,7 @@ sub get_posted_cgi { for ($i=0;$i<=$#lines;$i++) { if ($lines[$i]=~/^--\Q$contentsep\E/) { if ($name) { - chomp($value); + $value=~s/[\r\n]+$//; if (ref($fields) eq 'ARRAY') { next if (!grep(/^\Q$name\E$/,@{$fields})); } @@ -290,12 +290,17 @@ sub sso_login { } } - my $domain = $r->dir_config('lonDefDomain'); + my $domain = $r->dir_config('lonSSOUserDomain'); + if ($domain eq '') { + $domain = $r->dir_config('lonDefDomain'); + } my $home=&Apache::lonnet::homeserver($user,$domain); if ($home !~ /(con_lost|no_host|no_such_host)/) { &Apache::lonnet::logthis(" SSO authorized user $user "); - if ($r->dir_config("lonBalancer") eq 'yes') { - # login but immeaditly go to switch server to find us a new + my ($is_balancer,$otherserver) = + &Apache::lonnet::check_loadbalancing($user,$domain); + if ($is_balancer) { + # login but immediately go to switch server to find us a new # machine &Apache::lonauth::success($r,$user,$domain,$home,'noredirect'); $env{'request.sso.login'} = 1; @@ -303,7 +308,11 @@ sub sso_login { $env{'request.sso.reloginserver'} = $r->dir_config('lonSSOReloginServer'); } - $r->internal_redirect('/adm/switchserver'); + my $redirecturl = '/adm/switchserver'; + if ($otherserver ne '') { + $redirecturl .= '?otherserver='.$otherserver; + } + $r->internal_redirect($redirecturl); $r->set_handlers('PerlHandler'=> undef); } else { # need to login them in, so generate the need data that @@ -380,11 +389,7 @@ sub handler { return $result; } - - if ($r->dir_config("lonBalancer") eq 'yes') { - $r->set_handlers('PerlResponseHandler'=> - [\&Apache::switchserver::handler]); - } + my ($is_balancer,$otherserver); if ($handle eq '') { $r->log_reason("Cookie $handle not valid", $r->filename); @@ -417,7 +422,7 @@ sub handler { my $preserved; foreach my $pair (split(/&/,$query)) { my ($name, $value) = split(/=/,$pair); - unless (($name eq 'symb') || ($name eq 'wrapperdisplay')) { + unless ($name eq 'symb') { $preserved .= $pair.'&'; } } @@ -431,6 +436,27 @@ sub handler { &Apache::lonacc::get_posted_cgi($r); +# ------------------------------------------------------ Check if load balancer + + my $checkexempt; + if ($env{'user.loadbalexempt'} eq $r->dir_config('lonHostID')) { + if ($env{'user.loadbalcheck.time'} + 600 > time) { + $checkexempt = 1; + } + } + unless ($checkexempt) { + ($is_balancer,$otherserver) = + &Apache::lonnet::check_loadbalancing($env{'user.name'}, + $env{'user.domain'}); + } + if ($is_balancer) { + $r->set_handlers('PerlResponseHandler'=> + [\&Apache::switchserver::handler]); + if ($otherserver ne '') { + $env{'form.otherserver'} = $otherserver; + } + } + # ---------------------------------------------------------------- Check access my $now = time; if ($requrl !~ m{^/(?:adm|public|prtspool)/} @@ -452,8 +478,16 @@ sub handler { if ($requrl =~ m{^/res/}) { $access = &Apache::lonnet::allowed('bro',$requrl); if ($access ne 'F') { - $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied"; - return HTTP_NOT_ACCEPTABLE; + if ($requrl eq '/res/lib/templates/simpleproblem.problem/smpedit') { + $access = &Apache::lonnet::allowed('bre','/res/lib/templates/simpleproblem.problem'); + if ($access ne 'F') { + $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied"; + return HTTP_NOT_ACCEPTABLE; + } + } else { + $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied"; + return HTTP_NOT_ACCEPTABLE; + } } } else { $env{'user.error.msg'}="$requrl:bre:1:1:Access Denied"; @@ -489,22 +523,17 @@ sub handler { } # ------------------------------------------------------------- This is allowed if ($env{'request.course.id'}) { - my $skiplogging; - if ((!&Apache::loncommon::needs_gci_custom()) && - ($env{'course.'.$env{'request.course.id'}.'.internal.courseowner'} ne $env{'user.name'}.':'.$env{'user.domain'})) { - $skiplogging = 1; - } - unless ($skiplogging) { - &Apache::lonnet::countacc($requrl); - } + &Apache::lonnet::countacc($requrl); $requrl=~/\.(\w+)$/; my $query=$r->args; if ((&Apache::loncommon::fileembstyle($1) eq 'ssi') || - ($requrl=~/^\/adm\/.*\/(aboutme|navmaps|smppg|bulletinboard)(\?|$ )/x) || + ($requrl=~/^\/adm\/.*\/(aboutme|smppg|bulletinboard)(\?|$ )/x) || ($requrl=~/^\/adm\/wrapper\//) || ($requrl=~m|^/adm/coursedocs/showdoc/|) || ($requrl=~m|\.problem/smpedit$|) || - ($requrl=~/^\/public\/.*\/syllabus$/)) { + ($requrl=~/^\/public\/.*\/syllabus$/) || + ($requrl=~/^\/adm\/(viewclasslist|navmaps)$/) || + ($requrl=~/^\/adm\/.*\/aboutme\/portfolio(\?|$)/)) { # ------------------------------------- This is serious stuff, get symb and log my $symb; if ($query) { @@ -519,7 +548,9 @@ sub handler { 'last_known' =>[$murl,$mid]); } elsif ((&Apache::lonnet::symbverify($symb,$requrl)) || (($requrl=~m|(.*)/smpedit$|) && - &Apache::lonnet::symbverify($symb,$1))) { + &Apache::lonnet::symbverify($symb,$1)) || + (($requrl=~m|(.*/aboutme)/portfolio$|) && + &Apache::lonnet::symbverify($symb,$1))) { my ($map,$mid,$murl)=&Apache::lonnet::decode_symb($symb); &Apache::lonnet::symblist($map,$murl => [$murl,$mid], 'last_known' =>[$murl,$mid]); @@ -531,6 +562,9 @@ sub handler { return HTTP_NOT_ACCEPTABLE; } } else { + if ($requrl=~m{^(/adm/.*/aboutme)/portfolio$}) { + $requrl = $1; + } $symb=&Apache::lonnet::symbread($requrl); if (&Apache::lonnet::is_on_map($requrl) && $symb && !&Apache::lonnet::symbverify($symb,$requrl)) { @@ -547,14 +581,10 @@ sub handler { } } $env{'request.symb'}=$symb; - unless ($skiplogging) { - &Apache::lonnet::courseacclog($symb); - } + &Apache::lonnet::courseacclog($symb); } else { # ------------------------------------------------------- This is other content - unless ($skiplogging) { - &Apache::lonnet::courseacclog($requrl); - } + &Apache::lonnet::courseacclog($requrl); } my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};; @@ -570,6 +600,17 @@ sub handler { } } return OK; + } else { + my $defdom=$r->dir_config('lonDefDomain'); + ($is_balancer,$otherserver) = + &Apache::lonnet::check_loadbalancing(undef,$defdom); + if ($is_balancer) { + $r->set_handlers('PerlResponseHandler'=> + [\&Apache::switchserver::handler]); + if ($otherserver ne '') { + $env{'form.otherserver'} = $otherserver; + } + } } # -------------------------------------------- See if this is a public resource if ($requrl=~m|^/+adm/+help/+|) {