--- loncom/auth/switchserver.pm 2010/09/06 15:44:05 1.30 +++ loncom/auth/switchserver.pm 2015/01/22 22:45:06 1.34 @@ -1,7 +1,7 @@ # The LearningOnline Network # Switch Servers Handler # -# $Id: switchserver.pm,v 1.30 2010/09/06 15:44:05 raeburn Exp $ +# $Id: switchserver.pm,v 1.34 2015/01/22 22:45:06 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -96,9 +96,16 @@ sub handler { if (!defined($switch_to)) { return FORBIDDEN; } + my $protocol = 'http'; + if ($env{'form.otherserver'}) { + if ($Apache::lonnet::protocol{$env{'form.otherserver'}} eq 'https') { + $protocol = $Apache::lonnet::protocol{$env{'form.otherserver'}}; + } + } + if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { - my $url = 'http://'.$switch_to.$r->uri; + my $url = $protocol.'://'.$switch_to.$r->uri; return &do_redirect($r,$url,1) } @@ -115,7 +122,7 @@ sub handler { if (&Apache::lonnet::homeserver($env{'user.name'},$env{'user.domain'}) eq $env{'form.otherserver'}) { $skip_canhost_check = 1; } - } elsif ($env{'form.role'} =~ m{^[ac]a\./($match_domain)/($match_username)/$}) { + } 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; } @@ -153,9 +160,15 @@ sub handler { my %temp=('switchserver' => time.':'.$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'}"; + } else { + $logmsg .= " (no role)"; + } + $logmsg .= ' '.$ENV{'REMOTE_ADDR'}; &Apache::lonnet::log($env{'user.domain'},$env{'user.name'}, - $env{'user.home'}, - "Switch Server to $env{'form.otherserver'} with role $env{'form.role'} $ENV{'REMOTE_ADDR'}"); + $env{'user.home'},$logmsg); &Apache::loncommon::content_type($r,'text/html'); @@ -173,11 +186,13 @@ sub handler { # ---------------------------------------------------------------- Get handover + my ($is_balancer) = &Apache::lonnet::check_loadbalancing($env{'user.name'},$env{'user.domain'}); my %info=('ip' => $ENV{'REMOTE_ADDR'}, 'domain' => $env{'user.domain'}, 'username' => $env{'user.name'}, 'role' => $env{'form.role'}, - 'server' => $r->dir_config('lonHostID')); + 'server' => $r->dir_config('lonHostID'), + 'balancer' => $is_balancer); if ($env{'form.origurl'}) { $info{'origurl'} = $env{'form.origurl'}; } @@ -191,7 +206,7 @@ sub handler { $info{'sso.reloginserver'} = $env{'request.sso.reloginserver'}; } my $token = &Apache::lonnet::tmpput(\%info,$env{'form.otherserver'}); - my $url ='http://'.$switch_to.'/adm/login?'. + my $url =$protocol.'://'.$switch_to.'/adm/login?'. 'domain='.$env{'user.domain'}. '&username='.$env{'user.name'}. '&token='.$token;