--- loncom/auth/switchserver.pm 2007/08/25 00:52:47 1.14 +++ loncom/auth/switchserver.pm 2010/03/10 21:25:29 1.23 @@ -1,7 +1,7 @@ # The LearningOnline Network # Switch Servers Handler # -# $Id: switchserver.pm,v 1.14 2007/08/25 00:52:47 albertel Exp $ +# $Id: switchserver.pm,v 1.23 2010/03/10 21:25:29 droeschl Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,18 +42,11 @@ sub init_env { return $env{'user.environment'}; } my $requrl=$r->uri; - my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); - my $lonid=$cookies{'lonID'}; - my $cookie; - if (!$lonid) { return undef; } - - my $handle=&LONCAPA::clean_handle($lonid->value); - my $lonidsdir=$r->dir_config('lonIDsDir'); - if ((!-e "$lonidsdir/$handle.id") || ($handle eq '')) { - $r->log_reason("Cookie $handle not valid", $r->filename); + my $handle= &Apache::lonnet::check_for_valid_session($r); + if ($handle ne '') { return undef; } - + my $lonidsdir=$r->dir_config('lonIDsDir'); &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); return $r->dir_config('lonIDsDir')."/$handle.id"; @@ -62,10 +55,10 @@ sub init_env { sub do_redirect { my ($r,$url,$only_body,$extra_text) = @_; $r->send_http_header; - my $switch=''; my $start_page = - &Apache::loncommon::start_page('Switching Server ...', $switch, - {'no_inline_link' => 1, + &Apache::loncommon::start_page('Switching Server ...',undef, + {'redirect' => [0.5,$url], + 'no_inline_link' => 1, 'only_body' => $only_body,}); my $end_page = &Apache::loncommon::end_page(); $r->print($start_page.$extra_text.$end_page); @@ -80,11 +73,18 @@ sub handler { if (!defined($handle)) { return FORBIDDEN; } &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, - ['otherserver','role']); + ['otherserver','role','origurl','symb']); my $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'}); - if (!$env{'form.otherserver'}) { - $env{'form.otherserver'}=&Apache::lonnet::spareserver(30000,undef,1); + if (! $env{'form.otherserver'}) { + $env{'form.otherserver'} = + &Apache::lonnet::find_existing_session($env{'user.domain'}, + $env{'user.name'}); + if (! $env{'form.otherserver'}) { + $env{'form.otherserver'} = + &Apache::lonnet::spareserver(30000,undef,1); + } + $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'}); } @@ -92,7 +92,7 @@ sub handler { if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { - my $url = 'http://'.$switch_to.'/'.$r->uri; + my $url = 'http://'.$switch_to.$r->uri; return &do_redirect($r,$url,1) } @@ -115,12 +115,14 @@ sub handler { -value => '', -expires => '-10y',); $r->header_out('Set-cookie' => $c); - $r->send_http_header; - return OK if $r->header_only; + + if ($r->header_only) { + $r->send_http_header; + return OK; + } # -------------------------------------------------------- Menu script and info my $windowinfo= - &Apache::lonmenu::close(). &Apache::lonnavmaps::close(); # ---------------------------------------------------------------- Get handover @@ -129,6 +131,12 @@ sub handler { 'username' => $env{'user.name'}, 'role' => $env{'form.role'}, 'server' => $r->dir_config('lonHostID')); + if ($env{'form.origurl'}) { + $info{'origurl'} = $env{'form.origurl'}; + } + if ($env{'form.symb'}) { + $info{'symb'} = $env{'form.symb'}; + } if ($env{'request.sso.login'}) { $info{'sso.login'} = $env{'request.sso.login'}; }