version 1.1, 2005/10/24 21:32:43
|
version 1.17, 2007/09/29 04:03:46
|
Line 37 use Apache::lonlocal;
|
Line 37 use Apache::lonlocal;
|
|
|
sub init_env { |
sub init_env { |
my ($r) = @_; |
my ($r) = @_; |
|
|
|
if (-e $env{'user.environment'}) { |
|
return $env{'user.environment'}; |
|
} |
my $requrl=$r->uri; |
my $requrl=$r->uri; |
my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); |
my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); |
my $lonid=$cookies{'lonID'}; |
my $lonid=$cookies{'lonID'}; |
my $cookie; |
my $cookie; |
if (!$lonid) { return undef; } |
if (!$lonid) { return undef; } |
|
|
my $handle=$lonid->value; |
my $handle=&LONCAPA::clean_handle($lonid->value); |
$handle=~s/\W//g; |
|
my $lonidsdir=$r->dir_config('lonIDsDir'); |
my $lonidsdir=$r->dir_config('lonIDsDir'); |
if ((!-e "$lonidsdir/$handle.id") || ($handle eq '')) { |
if ((!-e "$lonidsdir/$handle.id") || ($handle eq '')) { |
$r->log_reason("Cookie $handle not valid", $r->filename); |
$r->log_reason("Cookie $handle not valid", $r->filename); |
Line 53 sub init_env {
|
Line 56 sub init_env {
|
|
|
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); |
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); |
|
|
return $handle; |
return $r->dir_config('lonIDsDir')."/$handle.id"; |
|
} |
|
|
|
sub do_redirect { |
|
my ($r,$url,$only_body,$extra_text) = @_; |
|
$r->send_http_header; |
|
my $start_page = |
|
&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); |
|
return OK; |
|
|
} |
} |
|
|
sub handler { |
sub handler { |
my $r = shift; |
my ($r) = @_; |
|
|
|
|
my $handle=&init_env($r); |
my $handle=&init_env($r); |
if (!defined($handle)) { return FORBIDDEN; } |
if (!defined($handle)) { return FORBIDDEN; } |
|
|
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'}, |
['otherserver','role']); |
['otherserver','role']); |
my $switch_to=$Apache::lonnet::hostname{$env{'form.otherserver'}}; |
|
|
my $switch_to=&Apache::lonnet::hostname($env{'form.otherserver'}); |
|
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'}); |
|
} |
|
|
if (!defined($switch_to)) { return FORBIDDEN; } |
if (!defined($switch_to)) { return FORBIDDEN; } |
if (!exists($env{'user.role.'.$env{'form.role'}})) { return FORBIDDEN; } |
|
|
if ($env{'user.name'} eq 'public' |
|
&& $env{'user.domain'} eq 'public') { |
|
my $url = 'http://'.$switch_to.'/'.$r->uri; |
|
return &do_redirect($r,$url,1) |
|
} |
|
|
|
if ($env{'form.role'} && |
|
!exists($env{'user.role.'.$env{'form.role'}})) { return FORBIDDEN; } |
|
|
#remove session env, and log event |
#remove session env, and log event |
unlink($r->dir_config('lonIDsDir')."/$handle.id"); |
unlink($handle); |
my %temp=('switchserver' => time.':'.$env{'form.otherserver'}, |
my %temp=('switchserver' => time.':'.$env{'form.otherserver'}, |
$env{'form.role'}); |
$env{'form.role'}); |
&Apache::lonnet::put('email_status',\%temp); |
&Apache::lonnet::put('email_status',\%temp); |
&Apache::lonnet::log($env{'user.domain'},$env{'user.name'}, |
&Apache::lonnet::log($env{'user.domain'},$env{'user.name'}, |
$env{'user.home'}, |
$env{'user.home'}, |
"Switch Server to $env{'form.otherserver'} with role $env{'form.role'} $ENV{'REMOTE_ADDR'}"); |
"Switch Server to $env{'form.otherserver'} with role $env{'form.role'} $ENV{'REMOTE_ADDR'}"); |
&Apache::lonnet::logthis(join(' -- ',$env{'user.domain'},$env{'user.name'}, |
|
$env{'user.home'}, |
|
"Switch Server to $env{'form.otherserver'} with role $env{'form.role'} $ENV{'REMOTE_ADDR'}")); |
|
|
|
&Apache::loncommon::content_type($r,'text/html'); |
&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); |
$r->send_http_header; |
$r->send_http_header; |
return OK if $r->header_only; |
return OK if $r->header_only; |
# -------------------------------------------------------- Menu script and info |
# -------------------------------------------------------- Menu script and info |
|
|
my $windowinfo=&Apache::lonmenu::close(); |
my $windowinfo= |
$windowinfo.=&Apache::lonnavmaps::close(); |
&Apache::lonmenu::close(). |
|
&Apache::lonnavmaps::close(); |
# ---------------------------------------------------------------- Get handover |
# ---------------------------------------------------------------- Get handover |
|
|
my $token = &Apache::lonnet::reply('tmpput:'.join('&',$ENV{'REMOTE_ADDR'},$env{'user.domain'},$env{'user.name'},$env{'form.role'}),$env{'form.otherserver'}); |
my %info=('ip' => $ENV{'REMOTE_ADDR'}, |
&Apache::lonnet::logthis("token is $token $switch_to"); |
'domain' => $env{'user.domain'}, |
my $switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url=http://'.$switch_to.'/adm/migrateuser?token='.$token.'">'; |
'username' => $env{'user.name'}, |
my $bodytag=&Apache::loncommon::bodytag('Switching Server ...'); |
'role' => $env{'form.role'}, |
|
'server' => $r->dir_config('lonHostID')); |
|
if ($env{'request.sso.login'}) { |
|
$info{'sso.login'} = $env{'request.sso.login'}; |
|
} |
|
if ($env{'request.sso.reloginserver'}) { |
|
$info{'sso.reloginserver'} = $env{'request.sso.reloginserver'}; |
|
} |
|
my $token = &Apache::lonnet::tmpput(\%info,$env{'form.otherserver'}); |
|
my $url ='http://'.$switch_to.'/adm/login?'. |
|
'domain='.$env{'user.domain'}. |
|
'&username='.$env{'user.name'}. |
|
'&token='.$token; |
# --------------------------------------------------------------- Screen Output |
# --------------------------------------------------------------- Screen Output |
my $doc=(<<ENDDOCUMENT); |
|
<html> |
|
<head><title>The LearningOnline Network with CAPA Logout</title> |
|
$switch |
|
</head> |
|
$bodytag |
|
$windowinfo |
|
</body> |
|
</html> |
|
ENDDOCUMENT |
|
&Apache::lonnet::logthis($doc); |
|
$r->print($doc); |
|
&Apache::lonnet::flushcourselogs(); |
&Apache::lonnet::flushcourselogs(); |
return OK; |
return &do_redirect($r,$url,0,$windowinfo); |
} |
} |
|
|
1; |
1; |