--- loncom/auth/switchserver.pm 2020/10/25 02:25:27 1.35.2.4 +++ loncom/auth/switchserver.pm 2022/01/01 16:33:13 1.35.2.6.2.1 @@ -1,7 +1,7 @@ # The LearningOnline Network # Switch Servers Handler # -# $Id: switchserver.pm,v 1.35.2.4 2020/10/25 02:25:27 raeburn Exp $ +# $Id: switchserver.pm,v 1.35.2.6.2.1 2022/01/01 16:33:13 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -29,7 +29,7 @@ package Apache::switchserver; use strict; -use Apache::Constants qw(:common); +use Apache::Constants qw(:common :remotehost); use Apache::lonnet; use Digest::MD5 qw(md5_hex); use CGI::Cookie(); @@ -57,7 +57,7 @@ sub do_redirect { my ($r,$url,$only_body,$extra_text) = @_; $r->send_http_header; my $delay = 0.5; - if ($only_body) { + if ($only_body && !$extra_text) { $delay = 0; } my $start_page = @@ -111,7 +111,7 @@ sub handler { $env{'user.name'}); if (! $env{'form.otherserver'}) { $env{'form.otherserver'} = - &Apache::lonnet::spareserver(30000,undef,1); + &Apache::lonnet::spareserver($r,30000,undef,1); } $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'}); } @@ -123,6 +123,10 @@ sub handler { if ($Apache::lonnet::protocol{$env{'form.otherserver'}} eq 'https') { $protocol = $Apache::lonnet::protocol{$env{'form.otherserver'}}; } + unless ($env{'form.otherserver'} eq $r->dir_config('lonHostID')) { + my $alias = &Apache::lonnet::use_proxy_alias($r,$env{'form.otherserver'}); + $switch_to = $alias if ($alias ne ''); + } } if ($env{'user.name'} eq 'public' @@ -203,7 +207,8 @@ sub handler { } else { $logmsg .= " (no role)"; } - $logmsg .= ' '.$ENV{'REMOTE_ADDR'}; + my $ip = &Apache::lonnet::get_requestor_ip($r,REMOTE_NOLOOKUP); + $logmsg .= ' '.$ip; &Apache::lonnet::log($env{'user.domain'},$env{'user.name'}, $env{'user.home'},$logmsg); @@ -248,7 +253,7 @@ sub handler { $otherbalcookie = $env{'request.balancercookie'}; } - my %info=('ip' => $ENV{'REMOTE_ADDR'}, + my %info=('ip' => $ip, 'domain' => $env{'user.domain'}, 'username' => $env{'user.name'}, 'role' => $env{'form.role'}, @@ -265,19 +270,40 @@ sub handler { if ($env{'form.symb'}) { $info{'symb'} = $env{'form.symb'}; } + my $ssologoutscript = ''; if ($env{'request.sso.login'}) { $info{'sso.login'} = $env{'request.sso.login'}; + if (defined($r->dir_config("lonSSOUserLogoutScriptFile_$info{domain}"))) { + if (open(my $fh,'<',$r->dir_config("lonSSOUserLogoutScriptFile_$info{domain}"))) { + $ssologoutscript .= join('',<$fh>); + close($fh); + } + } + if (defined($r->dir_config('lonSSOUserLogoutScriptFile'))) { + if (open(my $fh,'<',$r->dir_config('lonSSOUserLogoutScriptFile'))) { + $ssologoutscript .= join('',<$fh>); + close($fh); + } + } } if ($env{'request.sso.reloginserver'}) { $info{'sso.reloginserver'} = $env{'request.sso.reloginserver'}; } + if ($env{'request.linkprot'}) { + $info{'linkprot'} = $env{'request.linkprot'}; + } elsif ($env{'request.linkkey'} ne '') { + $info{'linkkey'} = $env{'request.linkkey'}; + } + if ($env{'request.deeplink.login'}) { + $info{'deeplink.login'} = $env{'request.deeplink.login'}; + } my $token = &Apache::lonnet::tmpput(\%info,$env{'form.otherserver'}); my $url =$protocol.'://'.$switch_to.'/adm/login?'. 'domain='.$env{'user.domain'}. '&username='.$env{'user.name'}. '&token='.$token; # --------------------------------------------------------------- Screen Output - return &do_redirect($r, $url, $only_body); + return &do_redirect($r, $url, $only_body, $ssologoutscript); } 1;