[LON-CAPA-cvs] cvs: loncom /auth switchserver.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Tue, 29 Nov 2005 20:59:37 -0000
albertel Tue Nov 29 15:59:37 2005 EDT
Modified files:
/loncom/auth switchserver.pm
Log:
-making switchserver work when something has already loaded the env
Index: loncom/auth/switchserver.pm
diff -u loncom/auth/switchserver.pm:1.4 loncom/auth/switchserver.pm:1.5
--- loncom/auth/switchserver.pm:1.4 Fri Oct 28 17:51:43 2005
+++ loncom/auth/switchserver.pm Tue Nov 29 15:59:37 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network
# Switch Servers Handler
#
-# $Id: switchserver.pm,v 1.4 2005/10/28 21:51:43 albertel Exp $
+# $Id: switchserver.pm,v 1.5 2005/11/29 20:59:37 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -37,6 +37,10 @@
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'};
@@ -53,31 +57,31 @@
&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 ($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);