[LON-CAPA-cvs] cvs: loncom / loncapa_apache.conf /auth lonauth.pm lonroles.pm migrateuser.pm switchserver.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Mon, 24 Oct 2005 21:32:43 -0000
This is a MIME encoded message
--albertel1130189563
Content-Type: text/plain
albertel Mon Oct 24 17:32:43 2005 EDT
Added files:
/loncom/auth migrateuser.pm switchserver.pm
Modified files:
/loncom loncapa_apache.conf
/loncom/auth lonauth.pm lonroles.pm
Log:
- 'switch server' now really does
--albertel1130189563
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20051024173243.txt"
Index: loncom/loncapa_apache.conf
diff -u loncom/loncapa_apache.conf:1.116 loncom/loncapa_apache.conf:1.117
--- loncom/loncapa_apache.conf:1.116 Mon Oct 10 11:38:18 2005
+++ loncom/loncapa_apache.conf Mon Oct 24 17:32:35 2005
@@ -1,7 +1,7 @@
##
## loncapa_apache.conf -- Apache HTTP LON-CAPA configuration file
##
-## $Id: loncapa_apache.conf,v 1.116 2005/10/10 15:38:18 raeburn Exp $
+## $Id: loncapa_apache.conf,v 1.117 2005/10/24 21:32:35 albertel Exp $
##
#
@@ -399,11 +399,23 @@
ErrorDocument 403 /adm/login
</Location>
+<Location /adm/switchserver>
+PerlAccessHandler Apache::lonacc
+SetHandler perl-script
+PerlHandler Apache::switchserver
+ErrorDocument 403 /adm/login
+</Location>
+
<Location /adm/authenticate>
SetHandler perl-script
PerlHandler Apache::lonauth
</Location>
+<Location /adm/migrateuser>
+SetHandler perl-script
+PerlHandler Apache::migrateuser
+</Location>
+
<Location /adm/annotations>
PerlAccessHandler Apache::lonacc
SetHandler perl-script
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.69 loncom/auth/lonauth.pm:1.70
--- loncom/auth/lonauth.pm:1.69 Thu Jul 7 02:18:37 2005
+++ loncom/auth/lonauth.pm Mon Oct 24 17:32:42 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network
# User Authentication Module
#
-# $Id: lonauth.pm,v 1.69 2005/07/07 06:18:37 albertel Exp $
+# $Id: lonauth.pm,v 1.70 2005/10/24 21:32:42 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -195,7 +195,8 @@
# ------------------------------------------------------------ Get cookie ready
- if ($public) { return $cookie; }
+ if ($public or $lowerurl eq 'noredirect') { return $cookie; }
+
$cookie="lonID=$cookie; path=/";
# -------------------------------------------------------- Menu script and info
my $windowinfo=&Apache::lonmenu::open($clientos);
Index: loncom/auth/lonroles.pm
diff -u loncom/auth/lonroles.pm:1.129 loncom/auth/lonroles.pm:1.130
--- loncom/auth/lonroles.pm:1.129 Fri Sep 16 15:47:42 2005
+++ loncom/auth/lonroles.pm Mon Oct 24 17:32:42 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# User Roles Screen
#
-# $Id: lonroles.pm,v 1.129 2005/09/16 19:47:42 albertel Exp $
+# $Id: lonroles.pm,v 1.130 2005/10/24 21:32:42 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -479,11 +479,7 @@
foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
if (!$allowed) {
$button=0;
- $switchserver=&Apache::lonnet::escape('http://'.
- $Apache::lonnet::hostname{$home}.
- '/adm/login?domain='.$env{'user.domain'}.
- '&username='.$env{'user.name'}.
- '&firsturl=/priv/'.$trest.'/');
+ $switchserver='otherserver='.$home.'&role='.$trolecode;
}
#next if ($home eq 'no_host');
$home = $Apache::lonnet::hostname{$home};
@@ -772,7 +768,7 @@
unless ($nochoose) {
if (!$button) {
if ($switchserver) {
- $roletext.='<td><a href="/adm/logout?handover='.
+ $roletext.='<td><a href="/adm/switchserver?'.
$switchserver.'">'.&mt('Switch Server').'</a></td>';
} else {
$roletext.=('<td> </td>');
Index: loncom/auth/migrateuser.pm
+++ loncom/auth/migrateuser.pm
# The LearningOnline Network
# Starts a user off based of an existing token.
#
# $Id: migrateuser.pm,v 1.1 2005/10/24 21:32:42 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::startuser;
use strict;
use Apache::Constants qw(:common :http :methods);
use Apache::lonauth;
use Apache::lonnet;
sub goto_login {
my ($r) = @_;
&Apache::loncommon::content_type($r,'text/html');
$r->send_http_header;
$r->print(<<TOLOGIN);
<html>
<head>
<meta http-equiv="refresh" content="10;url=/adm/login" />
<title>Going to login</title>
</head>
<body>
<h1>One moment please...</h1>
<p>
Transferring to login page.
<a href="/adm/login">Continue</a>
</p>
</body>
</html>
TOLOGIN
return '';
}
sub handler {
my ($r) = @_;
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['token']);
my $data = &Apache::lonnet::reply('tmpget:'.$env{'form.token'},
$Apache::lonnet::perlvar{'lonHostID'});
my ($ip,$udom,$uname,$role) = split('&',$data);
if ($ip ne $ENV{'REMOTE_ADDR'} && $ip ne '127.0.0.1') {
#error or invalid token
&goto_login($r);
return OK;
}
&Apache::lonnet::logthis("Allowing access for $uname\@$udom to $role");
my $home=&Apache::lonnet::homeserver($uname,$udom);
my $cookie=&Apache::lonauth::success($r,$uname,$udom,$home,'noredirect');
$r->header_out('Set-cookie',"lonID=$cookie; path=/");
&Apache::lonnet::transfer_profile_to_env($r->dir_config('lonIDsDir'),
$cookie);
$env{'form.selectrole'}='1';
$env{'form.'.$role}='1';
return &Apache::lonroles::handler($r);
}
1;
__END__
Index: loncom/auth/switchserver.pm
+++ loncom/auth/switchserver.pm
# The LearningOnline Network
# Switch Servers Handler
#
# $Id: switchserver.pm,v 1.1 2005/10/24 21:32:43 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
package Apache::switchserver;
use strict;
use Apache::Constants qw(:common);
use Apache::lonnet;
use Apache::lonmenu;
use CGI::Cookie();
use Apache::lonlocal;
sub init_env {
my ($r) = @_;
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 $lonidsdir=$r->dir_config('lonIDsDir');
if ((!-e "$lonidsdir/$handle.id") || ($handle eq '')) {
$r->log_reason("Cookie $handle not valid", $r->filename);
return undef;
}
&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
return $handle;
}
sub handler {
my $r = shift;
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 (!defined($switch_to)) { return FORBIDDEN; }
if (!exists($env{'user.role.'.$env{'form.role'}})) { return FORBIDDEN; }
#remove session env, and log event
unlink($r->dir_config('lonIDsDir')."/$handle.id");
my %temp=('switchserver' => time.':'.$env{'form.otherserver'},
$env{'form.role'});
&Apache::lonnet::put('email_status',\%temp);
&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'}");
&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');
$r->send_http_header;
return OK if $r->header_only;
# -------------------------------------------------------- Menu script and info
my $windowinfo=&Apache::lonmenu::close();
$windowinfo.=&Apache::lonnavmaps::close();
# ---------------------------------------------------------------- Get handover
my $token = &Apache::lonnet::reply('tmpput:'.join('&',$ENV{'REMOTE_ADDR'},$env{'user.domain'},$env{'user.name'},$env{'form.role'}),$env{'form.otherserver'});
&Apache::lonnet::logthis("token is $token $switch_to");
my $switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url=http://'.$switch_to.'/adm/migrateuser?token='.$token.'">';
my $bodytag=&Apache::loncommon::bodytag('Switching Server ...');
# --------------------------------------------------------------- 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();
return OK;
}
1;
__END__
--albertel1130189563--