--- loncom/auth/switchserver.pm 2019/08/01 15:20:06 1.35.2.1 +++ loncom/auth/switchserver.pm 2019/06/15 02:50:04 1.49 @@ -1,7 +1,7 @@ # The LearningOnline Network # Switch Servers Handler # -# $Id: switchserver.pm,v 1.35.2.1 2019/08/01 15:20:06 raeburn Exp $ +# $Id: switchserver.pm,v 1.49 2019/06/15 02:50:04 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -128,6 +128,12 @@ sub handler { if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { my $url = $protocol.'://'.$switch_to.$r->uri; + unlink($handle); + #expire the cookie + my $c = new CGI::Cookie(-name => 'lonPubID', + -value => '', + -expires => '-10y',); + $r->header_out('Set-cookie' => $c); return &do_redirect($r,$url,1) } @@ -145,8 +151,12 @@ sub handler { $skip_canhost_check = 1; } } elsif ($env{'form.role'} =~ m{^[ac]a\./($match_domain)/($match_username)$}) { - if (&Apache::lonnet::homeserver($2,$1) eq $env{'form.otherserver'}) { - $skip_canhost_check = 1; + my ($audom,$auname) = ($1,$2); + if (&Apache::lonnet::homeserver($auname,$audom) eq $env{'form.otherserver'}) { + if ((&Apache::lonnet::will_trust('othcoau',$env{'user.domain'},$audom)) && + (&Apache::lonnet::will_trust('coaurem',$audom,$env{'user.domain'}))) { + $skip_canhost_check = 1; + } } } } @@ -178,13 +188,26 @@ sub handler { } #remove session env, and log event - unlink($handle); + if (unlink($handle)) { + if ($env{'user.linkedenv'} ne '') { + my $lonidsdir=$r->dir_config('lonIDsDir'); + if (($env{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) && + (-l "$lonidsdir/$env{'user.linkedenv'}.id") && + (readlink("$lonidsdir/$env{'user.linkedenv'}.id") eq $handle)) { + unlink("$lonidsdir/$env{'user.linkedenv'}.id"); + } + } + } my %temp=('switchserver' => $now.':'.$env{'form.otherserver'}, $env{'form.role'}); &Apache::lonnet::put('email_status',\%temp); my $logmsg = "Switch Server to $env{'form.otherserver'}"; if ($env{'form.role'}) { $logmsg .= " with role: $env{'form.role'}"; + } elsif (($env{'form.lti.reqcrs'}) && ($env{'form.lti.reqrole'} eq 'cc')) { + $logmsg .= " to create new LTI course"; + } elsif ($env{'form.lti.selfenrollrole'}) { + $logmsg .= " to selfenroll with role: $env{'form.lti.selfenrollrole'}"; } else { $logmsg .= " (no role)"; } @@ -194,12 +217,15 @@ sub handler { &Apache::loncommon::content_type($r,'text/html'); - #expire the cookie - my $c = new CGI::Cookie(-name => 'lonID', - -value => '', - -expires => '-10y',); - $r->header_out('Set-cookie' => $c); - + #expire the cookies + my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); + foreach my $name (keys(%cookies)) { + next unless ($name =~ /^lon(|S|Link|Pub)ID$/); + my $c = new CGI::Cookie(-name => $name, + -value => '', + -expires => '-10y',); + $r->headers_out->add('Set-cookie' => $c); + } if ($r->header_only) { $r->send_http_header; return OK; @@ -210,9 +236,10 @@ sub handler { my $newcookieid; my $only_body = 0; - my ($is_balancer,$posshost,$setcookie) = + my ($is_balancer,$posshost,$setcookie,$offloadto,$dom_balancers) = &Apache::lonnet::check_loadbalancing($env{'user.name'},$env{'user.domain'}); if ($is_balancer && $setcookie && $env{'form.otherserver'}) { + # Set a balancer cookie unless browser already sent LON-CAPA load balancer # cookie which points at the target server my ($found_server,$balancer_cookie) = &Apache::lonnet::check_for_balancer_cookie($r,1); @@ -226,12 +253,25 @@ sub handler { } } - my %info=('ip' => $ENV{'REMOTE_ADDR'}, - 'domain' => $env{'user.domain'}, - 'username' => $env{'user.name'}, - 'role' => $env{'form.role'}, - 'server' => $r->dir_config('lonHostID'), - 'balancer' => $is_balancer); + my %info=('ip' => $ENV{'REMOTE_ADDR'}, + 'domain' => $env{'user.domain'}, + 'username' => $env{'user.name'}, + 'home' => $env{'user.home'}, + 'role' => $env{'form.role'}, + 'server' => $r->dir_config('lonHostID'), + 'balancer' => $is_balancer, + 'dom_balancers' => $dom_balancers, + 'offloadto' => ''); + if (ref($offloadto) eq 'HASH') { + foreach my $key (keys(%{$offloadto})) { + if (ref($offloadto->{$key}) eq 'ARRAY') { + $info{'offloadto'} .= $key.'='.join(',',@{$offloadto->{$key}}).'&'; + } + } + $info{'offloadto'} =~ s/\&$//; + } elsif (ref($offloadto) eq 'ARRAY') { + $info{'offloadto'} = join(',',@{$offloadto}); + } if ($newcookieid) { $info{'balcookie'} = $newcookieid; } @@ -247,6 +287,48 @@ sub handler { if ($env{'request.sso.reloginserver'}) { $info{'sso.reloginserver'} = $env{'request.sso.reloginserver'}; } + if ($env{'request.linkprot'}) { + $info{'linkprot'} = $env{'request.linkprot'}; + } + if ($env{'request.deeplink.login'}) { + $info{'deeplink.login'} = $env{'request.deeplink.login'}; + if ($env{'request.linkkey'}) { + $info{'linkkey'} = $env{'request.linkkey'}; + } + } + if ($env{'request.lti.login'}) { + $info{'lti.login'} = $env{'request.lti.login'}; + } + if ($env{'request.lti.uri'}) { + $info{'lti.uri'} = $env{'request.lti.uri'}; + } + if ($env{'request.lti.reqcrs'}) { + $info{'lti.reqcrs'} = $env{'request.lti.reqcrs'}; + } + if ($env{'request.lti.reqrole'}) { + $info{'lti.reqrole'} = $env{'request.lti.reqrole'}; + } + if ($env{'request.lti.selfenrollrole'}) { + $info{'lti.selfenrollrole'} = $env{'request.lti.selfenrollrole'}; + } + if ($env{'request.lti.sourcecrs'}) { + $info{'lti.sourcecrs'} = $env{'request.lti.sourcecrs'}; + } + if ($env{'request.lti.passbackid'}) { + $info{'lti.passbackid'} = $env{'request.lti.passbackid'}; + } + if ($env{'request.lti.passbackurl'}) { + $info{'lti.passbackurl'} = $env{'request.lti.passbackurl'}; + } + if ($env{'request.lti.rosterid'}) { + $info{'lti.rosterid'} = $env{'request.lti.rosterid'}; + } + if ($env{'request.lti.rosterurl'}) { + $info{'lti.rosterurl'} = $env{'request.lti.rosterurl'}; + } + if ($env{'request.lti.target'}) { + $info{'lti.target'} = $env{'request.lti.target'}; + } my $token = &Apache::lonnet::tmpput(\%info,$env{'form.otherserver'}); my $url =$protocol.'://'.$switch_to.'/adm/login?'. 'domain='.$env{'user.domain'}.