File:  [LON-CAPA] / loncom / auth / lonlogout.pm
Revision 1.25: download - view: text, annotated - select for diffs
Thu Mar 1 23:14:12 2007 UTC (17 years, 2 months ago) by albertel
Branches: MAIN
CVS tags: version_2_5_0, version_2_4_X, version_2_4_99_0, version_2_4_2, version_2_4_1, version_2_4_0, version_2_3_99_0, HEAD
- BUG#5212 unset the cookie when logging out.

    1: # The LearningOnline Network
    2: # Logout Handler
    3: #
    4: # $Id: lonlogout.pm,v 1.25 2007/03/01 23:14:12 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::lonlogout;
   30: 
   31: use strict;
   32: use Apache::Constants qw(:common);
   33: use Apache::File;
   34: use Apache::lonnet;
   35: use Apache::lonmenu;
   36: use CGI::Cookie();
   37: use Apache::lonlocal;
   38: 
   39: sub handler {
   40:     my $r = shift;
   41: 
   42:     #Check for cookie
   43:     my $requrl=$r->uri;
   44:     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
   45:     my $lonid=$cookies{'lonID'};
   46:     my $cookie;
   47:     if (!$lonid) {
   48: 	return FORBIDDEN;
   49:     }
   50: 
   51:     #check if cookie still valid
   52:     my $handle=&LONCAPA::clean_handle($lonid->value);
   53:     my $lonidsdir=$r->dir_config('lonIDsDir');
   54:     if ((!-e "$lonidsdir/$handle.id") || ($handle eq '')) {
   55: 	$r->log_reason("Cookie $handle not valid", $r->filename); 
   56: 	return FORBIDDEN;
   57:     }
   58: 
   59:     #we've got a valid user
   60:     my @profile;
   61:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   62:     unlink("$lonidsdir/$handle.id");
   63:     my %temp=('logout' => time);
   64:     &Apache::lonnet::put('email_status',\%temp);
   65:     &Apache::lonnet::log($env{'user.domain'},
   66: 			 $env{'user.name'},
   67: 			 $env{'user.home'},
   68: 			 "Logout $ENV{'REMOTE_ADDR'}");
   69: 
   70:     &Apache::loncommon::content_type($r,'text/html');
   71: 
   72:     #expire the cookie
   73:     my $c = new CGI::Cookie(-name    => 'lonID',
   74: 			    -value   => '',
   75: 			    -expires => '-10y',);
   76:     $r->header_out('Set-cookie' => $c);
   77: 
   78:     $r->send_http_header;
   79:     return OK if $r->header_only;
   80: # -------------------------------------------------------- Menu script and info
   81: 
   82:     my $windowinfo=&Apache::lonmenu::close();
   83:     $windowinfo.=&Apache::lonnavmaps::close();
   84: # ---------------------------------------------------------------- Get handover
   85:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['handover']);
   86:     my $switch='';
   87:     my $start_page='';
   88:     my $relogmessage='';
   89:     if ($env{'form.handover'}) {
   90: 	$switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.
   91: 	    $env{'form.handover'}.'">';
   92: 	$start_page=&Apache::loncommon::start_page('Switching Server ...',
   93: 						   $switch);
   94:     } else {
   95: 	$start_page=&Apache::loncommon::start_page('Logged Out',undef,
   96: 						   {'no_inline_link' => 1,});
   97: 	my %lt=&Apache::lonlocal::texthash('gb' => 'Goodbye',
   98: 					   'cw' => 'close this window',
   99: 					   'li' => 'log in again',
  100: 					   'pe' => 'Please either',
  101: 					   'or' => 'or');
  102:         my $relogin_server;
  103:         if ($env{'request.sso.reloginserver'}) {
  104:             $relogin_server = $env{'request.sso.reloginserver'};
  105:         }
  106: 	my $login_url = $relogin_server.'/adm/'.
  107:                         ($env{'request.sso.login'} ? 'roles': 'login');
  108:  
  109: 	$relogmessage=(<<ENDRELOG);
  110: 	<h1>$lt{'gb'}!</h1>
  111: 	    $lt{'pe'} <a href="javascript:self.close();">$lt{'cw'}</a> $lt{'or'}
  112: 	<a href="$login_url?domain=$env{'user.domain'}">$lt{'li'}</a>.
  113: ENDRELOG
  114: 
  115:         if ($env{'request.sso.login'}
  116: 	    && defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {
  117: 	    open(my $fh,$r->dir_config('lonSSOUserLogoutMessageFile'));
  118: 	    $relogmessage.= join('',<$fh>);
  119: 	}
  120: 
  121:     }
  122:     my $end_page=&Apache::loncommon::end_page();
  123: # --------------------------------------------------------------- Screen Output
  124:     $r->print(<<ENDDOCUMENT);
  125: $start_page
  126: $windowinfo
  127: $relogmessage
  128: $end_page
  129: ENDDOCUMENT
  130:     &Apache::lonnet::flushcourselogs();
  131:     return OK; 
  132: }
  133: 
  134: 1;
  135: __END__
  136: 
  137: 
  138: 
  139: 
  140: 
  141: 
  142: 
  143: 

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