Annotation of loncom/auth/switchserver.pm, revision 1.1

1.1     ! albertel    1: # The LearningOnline Network
        !             2: # Switch Servers Handler
        !             3: #
        !             4: # $Id: lonlogout.pm,v 1.15 2005/09/20 07:33:54 albertel Exp $
        !             5: #
        !             6: # Copyright Michigan State University Board of Trustees
        !             7: #
        !             8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
        !             9: #
        !            10: # LON-CAPA is free software; you can redistribute it and/or modify
        !            11: # it under the terms of the GNU General Public License as published by
        !            12: # the Free Software Foundation; either version 2 of the License, or
        !            13: # (at your option) any later version.
        !            14: #
        !            15: # LON-CAPA is distributed in the hope that it will be useful,
        !            16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
        !            17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        !            18: # GNU General Public License for more details.
        !            19: #
        !            20: # You should have received a copy of the GNU General Public License
        !            21: # along with LON-CAPA; if not, write to the Free Software
        !            22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
        !            23: #
        !            24: # /home/httpd/html/adm/gpl.txt
        !            25: #
        !            26: # http://www.lon-capa.org/
        !            27: #
        !            28: 
        !            29: package Apache::switchserver;
        !            30: 
        !            31: use strict;
        !            32: use Apache::Constants qw(:common);
        !            33: use Apache::lonnet;
        !            34: use Apache::lonmenu;
        !            35: use CGI::Cookie();
        !            36: use Apache::lonlocal;
        !            37: 
        !            38: sub init_env {
        !            39:     my ($r) = @_;
        !            40:     my $requrl=$r->uri;
        !            41:     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
        !            42:     my $lonid=$cookies{'lonID'};
        !            43:     my $cookie;
        !            44:     if (!$lonid) { return undef; }
        !            45: 
        !            46:     my $handle=$lonid->value;
        !            47:     $handle=~s/\W//g;
        !            48:     my $lonidsdir=$r->dir_config('lonIDsDir');
        !            49:     if ((!-e "$lonidsdir/$handle.id") || ($handle eq '')) {
        !            50: 	$r->log_reason("Cookie $handle not valid", $r->filename); 
        !            51: 	return undef;
        !            52:     }
        !            53: 
        !            54:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
        !            55:     
        !            56:     return $handle;
        !            57: }
        !            58: 
        !            59: sub handler {
        !            60:     my $r = shift;
        !            61:     
        !            62:     
        !            63:     my $handle=&init_env($r);
        !            64:     if (!defined($handle)) { return FORBIDDEN; }
        !            65: 
        !            66:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
        !            67: 					    ['otherserver','role']);
        !            68:     my $switch_to=$Apache::lonnet::hostname{$env{'form.otherserver'}};
        !            69:     if (!defined($switch_to)) { return FORBIDDEN; }
        !            70:     if (!exists($env{'user.role.'.$env{'form.role'}})) { return FORBIDDEN; }
        !            71: 
        !            72:     #remove session env, and log event
        !            73:     unlink($r->dir_config('lonIDsDir')."/$handle.id");
        !            74:     my %temp=('switchserver' => time.':'.$env{'form.otherserver'},
        !            75: 	      $env{'form.role'});
        !            76:     &Apache::lonnet::put('email_status',\%temp);
        !            77:     &Apache::lonnet::log($env{'user.domain'},$env{'user.name'},
        !            78: 			 $env{'user.home'},
        !            79: 			 "Switch Server to $env{'form.otherserver'} with role $env{'form.role'} $ENV{'REMOTE_ADDR'}");
        !            80:     &Apache::lonnet::logthis(join(' -- ',$env{'user.domain'},$env{'user.name'},
        !            81: 			 $env{'user.home'},
        !            82: 			 "Switch Server to $env{'form.otherserver'} with role $env{'form.role'} $ENV{'REMOTE_ADDR'}"));
        !            83: 
        !            84:     &Apache::loncommon::content_type($r,'text/html');
        !            85:     $r->send_http_header;
        !            86:     return OK if $r->header_only;
        !            87: # -------------------------------------------------------- Menu script and info
        !            88: 	   
        !            89:     my $windowinfo=&Apache::lonmenu::close();
        !            90:     $windowinfo.=&Apache::lonnavmaps::close();
        !            91: # ---------------------------------------------------------------- Get handover
        !            92: 
        !            93:     my $token = &Apache::lonnet::reply('tmpput:'.join('&',$ENV{'REMOTE_ADDR'},$env{'user.domain'},$env{'user.name'},$env{'form.role'}),$env{'form.otherserver'});
        !            94:     &Apache::lonnet::logthis("token is $token $switch_to");
        !            95:     my $switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url=http://'.$switch_to.'/adm/migrateuser?token='.$token.'">';
        !            96:     my $bodytag=&Apache::loncommon::bodytag('Switching Server ...');
        !            97: # --------------------------------------------------------------- Screen Output
        !            98:     my $doc=(<<ENDDOCUMENT);
        !            99: 	   <html>
        !           100: 	       <head><title>The LearningOnline Network with CAPA Logout</title>
        !           101: 	       $switch
        !           102: 	       </head>
        !           103: 	       $bodytag
        !           104: 	       $windowinfo
        !           105: 	       </body>
        !           106: 	       </html>
        !           107: ENDDOCUMENT
        !           108: &Apache::lonnet::logthis($doc);
        !           109:     $r->print($doc);
        !           110:     &Apache::lonnet::flushcourselogs();
        !           111:     return OK;
        !           112: }
        !           113: 
        !           114: 1;
        !           115: __END__
        !           116: 
        !           117: 
        !           118: 
        !           119: 
        !           120: 
        !           121: 
        !           122: 
        !           123: 

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>