--- loncom/auth/migrateuser.pm 2022/01/01 17:00:40 1.25.2.5.2.1 +++ loncom/auth/migrateuser.pm 2022/02/24 14:42:06 1.25.2.5.2.4 @@ -1,7 +1,7 @@ # The LearningOnline Network # Starts a user off based of an existing token. # -# $Id: migrateuser.pm,v 1.25.2.5.2.1 2022/01/01 17:00:40 raeburn Exp $ +# $Id: migrateuser.pm,v 1.25.2.5.2.4 2022/02/24 14:42:06 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,6 +35,7 @@ use Apache::lonauth; use Apache::lonnet; use Apache::lonlocal; use Apache::lonlogin(); +use CGI::Cookie; sub goto_login { my ($r,$domain) = @_; @@ -214,6 +215,73 @@ sub ip_changed { return OK; } +sub logout { + my ($r,$ip,$handle,$data,$lti_env) = @_; + my $lonidsdir=$r->dir_config('lonIDsDir'); + if (unlink("$lonidsdir/$handle.id")) { + if (($env{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) && + (-l "$lonidsdir/$env{'user.linkedenv'}.id") && + (readlink("$lonidsdir/$env{'user.linkedenv'}.id") eq "$lonidsdir/$handle.id")) { + unlink("$lonidsdir/$env{'user.linkedenv'}.id"); + } + } + my %temp=('logout' => time); + &Apache::lonnet::put('email_status',\%temp); + &Apache::lonnet::log($env{'user.domain'}, + $env{'user.name'}, + $env{'user.home'}, + "Logout $ip"); + + &Apache::loncommon::content_type($r,'text/html'); + + #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); + } + my (%info,%user_info,%lti_info); + if (ref($lti_env) eq 'HASH') { + foreach my $key (sort(keys(%{$lti_env}))) { + if ($key =~ /^request\.(.+)$/) { + $lti_info{$1} = $lti_env->{$key}; + } + } + } + my $lonhost = $r->dir_config('lonHostID'); + if (ref($data) eq 'HASH') { + %user_info=('ip' => $ip, + 'domain' => $data->{'domain'}, + 'username' => $data->{'username'}, + 'home' => $data->{'home'}, + 'role' => $data->{'role'}, + 'origurl' => $data->{'origurl'}, + 'symb' => $data->{'symb'}, + 'server' => $lonhost); + } + %info = (%user_info,%lti_info); + my $token = &Apache::lonnet::tmpput(\%info,$lonhost); + my $url = '/adm/migrateuser?token='.$token; + $r->send_http_header; + $r->print( + &Apache::loncommon::start_page('Updating Session ...',undef, + {'redirect' => [0.1,$url], + 'only_body' => 1,}). + &Apache::loncommon::end_page()); + if ($env{'request.balancercookie'}) { + my ($balancer,$cookie) = split(/:/,$env{'request.balancercookie'}); + if ((&Apache::lonnet::hostname($balancer)) && ($cookie =~ /^[a-f0-9]{32}$/)) { + $cookie = $env{'user.domain'}.'_'.$env{'user.name'}.'_'.$cookie; + &Apache::lonnet::delbalcookie($cookie,$balancer); + } + } + $r->register_cleanup(\&flush_course_logs); + return; +} + sub handler { my ($r) = @_; @@ -307,23 +375,28 @@ sub handler { $handle); my $checklaunch; if ($data{'origurl'} =~ m{^/tiny/$match_domain/\w+$}) { - if ($env{'request.linkprot'} ne '') { - unless ($env{'request.linkprot'} eq $data{'linkprot'}) { - $checklaunch = 1; - } - } - if ($env{'request.linkkey'} ne '') { - unless ($env{'request.linkkey'} eq $data{'linkkey'}) { - $checklaunch = 1; - } + unless ($env{'request.linkprot'} eq $data{'linkprot'}) { + $checklaunch = 1; } - if ($env{'request.deeplink.login'}) { - unless ($env{'request.deeplink.login'} eq $data{'deeplink.login'}) { - $checklaunch = 1; - } + unless ($env{'request.linkkey'} eq $data{'linkkey'}) { + $checklaunch = 1; + } + unless ($env{'request.deeplink.login'} eq $data{'deeplink.login'}) { + $checklaunch = 1; } } if ($data{'linkprot'} ne '') { + if (($env{'user.name'} ne $data{'username'}) || + ($env{'user.domain'} ne $data{'domain'})) { + my %linkprot_env; + foreach my $item ('linkprot','deeplink.login') { + if ($data{$item}) { + $linkprot_env{'request.'.$item} = $data{$item}; + } + } + &logout($r,$ip,$handle,\%data,\%linkprot_env); + return OK; + } &Apache::lonnet::appenv({'request.linkprot' => $data{'linkprot'}}); if ($env{'request.linkkey'}) { &Apache::lonnet::delenv('request.linkkey'); @@ -379,6 +452,9 @@ sub handler { } if ($data{'deeplink.login'}) { &Apache::lonnet::appenv({'request.deeplink.login' => $data{'deeplink.login'}}); + if ($env{'environment.remote'} eq 'on') { + &Apache::lonnet::appenv({'environment.remote' => 'off'}); + } } if ($data{'origurl'} ne '') { my $dest = $data{'origurl'};