--- loncom/auth/switchserver.pm 2005/10/25 19:14:32 1.3
+++ loncom/auth/switchserver.pm 2006/11/23 01:49:41 1.10
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Switch Servers Handler
#
-# $Id: switchserver.pm,v 1.3 2005/10/25 19:14:32 albertel Exp $
+# $Id: switchserver.pm,v 1.10 2006/11/23 01:49:41 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,14 +37,17 @@ use Apache::lonlocal;
sub init_env {
my ($r) = @_;
+
+ if (-e $env{'user.environment'}) {
+ 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=$lonid->value;
- $handle=~s/\W//g;
+ 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);
@@ -53,24 +56,31 @@ sub init_env {
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
- return $handle;
+ return $r->dir_config('lonIDsDir')."/$handle.id";
}
sub handler {
- my $r = shift;
-
+ my ($r) = @_;
my $handle=&init_env($r);
if (!defined($handle)) { return FORBIDDEN; }
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
['otherserver','role']);
+
my $switch_to=$Apache::lonnet::hostname{$env{'form.otherserver'}};
+ 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 (!exists($env{'user.role.'.$env{'form.role'}})) { return FORBIDDEN; }
+
+ if ($env{'form.role'} &&
+ !exists($env{'user.role.'.$env{'form.role'}})) { return FORBIDDEN; }
#remove session env, and log event
- unlink($r->dir_config('lonIDsDir')."/$handle.id");
+ unlink($handle);
my %temp=('switchserver' => time.':'.$env{'form.otherserver'},
$env{'form.role'});
&Apache::lonnet::put('email_status',\%temp);
@@ -92,20 +102,17 @@ sub handler {
'username' => $env{'user.name'},
'role' => $env{'form.role'},
'server' => $r->dir_config('lonHostID'));
+ if ($env{'request.sso.login'}) {
+ $info{'sso.login'} = $env{'request.sso.login'};
+ }
my $token = &Apache::lonnet::tmpput(\%info,$env{'form.otherserver'});
- my $switch='';
- my $bodytag=&Apache::loncommon::bodytag('Switching Server ...');
+ my $switch='';
+ my $start_page = &Apache::loncommon::start_page('Switching Server ...',
+ $switch,
+ {'no_inline_link' => 1,});
+ my $end_page = &Apache::loncommon::end_page();
# --------------------------------------------------------------- Screen Output
- $r->print(<
- The LearningOnline Network with CAPA Logout
- $switch
-
- $bodytag
- $windowinfo
-