File:  [LON-CAPA] / loncom / auth / lonlogout.pm
Revision 1.33: download - view: text, annotated - select for diffs
Wed Nov 12 20:01:09 2008 UTC (15 years, 6 months ago) by jms
Branches: MAIN
CVS tags: HEAD
Added/modified POD documentation

    1: # The LearningOnline Network
    2: # Logout Handler
    3: #
    4: # $Id: lonlogout.pm,v 1.33 2008/11/12 20:01:09 jms 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 $handle = &Apache::lonnet::check_for_valid_session($r);
   45:     #check if cookie still valid
   46:     if ($handle eq '') {
   47: 	$r->log_reason("Cookie $handle not valid", $r->filename); 
   48: 	return FORBIDDEN;
   49:     }
   50: 
   51:     #we've got a valid user
   52:     #any locks in place?
   53:     my $locknum=&Apache::lonnet::get_locks();
   54:     if ($locknum) { return 409; }
   55:     #nope, go ahead
   56:     my @profile;
   57:     my $lonidsdir=$r->dir_config('lonIDsDir');
   58:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   59:     unlink("$lonidsdir/$handle.id");
   60:     my %temp=('logout' => time);
   61:     &Apache::lonnet::put('email_status',\%temp);
   62:     &Apache::lonnet::log($env{'user.domain'},
   63: 			 $env{'user.name'},
   64: 			 $env{'user.home'},
   65: 			 "Logout $ENV{'REMOTE_ADDR'}");
   66: 
   67:     &Apache::loncommon::content_type($r,'text/html');
   68: 
   69:     #expire the cookie
   70:     my $c = new CGI::Cookie(-name    => 'lonID',
   71: 			    -value   => '',
   72: 			    -expires => '-10y',);
   73:     $r->header_out('Set-cookie' => $c);
   74: 
   75:     $r->send_http_header;
   76:     return OK if $r->header_only;
   77: # -------------------------------------------------------- Menu script and info
   78: 
   79:     my $windowinfo=&Apache::lonmenu::close();
   80:     $windowinfo.=&Apache::lonnavmaps::close();
   81: # ---------------------------------------------------------------- Get handover
   82:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['handover']);
   83:     my $switch='';
   84:     my $start_page='';
   85:     my $relogmessage='';
   86:     if ($env{'form.handover'}) {
   87: 	$switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.
   88: 	    $env{'form.handover'}.'">';
   89: 	$start_page=&Apache::loncommon::start_page('Switching Server ...',
   90: 						   $switch);
   91:     } else {
   92: 	$start_page=&Apache::loncommon::start_page('Logged Out',undef,
   93: 						   {'no_inline_link' => 1,});
   94: 	
   95:         $relogmessage.='<h1>'.&mt('Goodbye').'</h1>'
   96:                       .'<p>'.&mt('Thank you for using LON-CAPA.').'</p>';
   97: 
   98: 	if (!$env{'request.sso.norelogin'}) {
   99: 	    my $relogin_server;
  100: 	    if ($env{'request.sso.reloginserver'}) {
  101: 		$relogin_server = $env{'request.sso.reloginserver'};
  102: 	    }
  103: 	    my $login_url = $relogin_server.'/adm/'.
  104: 		($env{'request.sso.login'} ? 'roles': 'login');
  105: 
  106:             $relogmessage.='<p>'.&mt('You have been successfully logged out.').' '
  107:                           .&mt('You can [_1]close this window[_2] now.'
  108:                               ,'','')
  109: #                              ,'<a href="javascript:self.close();">','</a>');
  110: =pod
  111: 
  112: =head1 NOTES:
  113: 
  114: '<a href="javascript:self.close();">','</a>');
  115: 
  116: Due to security reasons in new web browsers a window could only be closed with java script, if this window has also been opend with javascript. This is not done here which means that in most cases the close link will not work. Unless we find another solution, this link should not be offered. (Stefan Bisitz, 2008-08-01)
  117: 
  118: =cut
  119:                           .'</p>'
  120:                           .'<p>'.&mt('[_1]Log in again[_2]'
  121:                               ,'<a href="'.$login_url.'?domain='.$env{'user.domain'}.'">','</a>')
  122:                           .'</p>';
  123:         }
  124: 	my $domain = $env{'user.domain'};
  125:         if ($env{'request.sso.login'}
  126: 	    && defined($r->dir_config("lonSSOUserLogoutMessageFile_$domain"))) {
  127: 	    open(my $fh,$r->dir_config("lonSSOUserLogoutMessageFile_$domain"));
  128: 	    $relogmessage.= join('',<$fh>);
  129: 	}
  130: 	if ($env{'request.sso.login'}
  131: 	    && defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {
  132: 	    open(my $fh,$r->dir_config('lonSSOUserLogoutMessageFile'));
  133: 	    $relogmessage.= join('',<$fh>);
  134: 	}
  135: 
  136:     }
  137:     my $end_page=&Apache::loncommon::end_page();
  138: # --------------------------------------------------------------- Screen Output
  139:     $r->print(<<ENDDOCUMENT);
  140: $start_page
  141: $windowinfo
  142: $relogmessage
  143: $end_page
  144: ENDDOCUMENT
  145:     $r->register_cleanup(\&flush_course_logs);
  146:     return OK; 
  147: }
  148: 
  149: sub flush_course_logs {
  150:     &Apache::lonnet::flushcourselogs();
  151:     return OK;
  152: }
  153: 
  154: 1;
  155: __END__
  156: 
  157: 
  158: 
  159: 
  160: 
  161: 
  162: 
  163: 

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