Annotation of loncom/auth/lonlogout.pm, revision 1.28

1.1       www         1: # The LearningOnline Network
                      2: # Logout Handler
1.3       www         3: #
1.28    ! albertel    4: # $Id: lonlogout.pm,v 1.27 2007/08/25 00:51:24 albertel Exp $
1.3       www         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: #
1.1       www        28: 
                     29: package Apache::lonlogout;
                     30: 
                     31: use strict;
                     32: use Apache::Constants qw(:common);
                     33: use Apache::File;
                     34: use Apache::lonnet;
1.2       www        35: use Apache::lonmenu;
1.1       www        36: use CGI::Cookie();
1.11      www        37: use Apache::lonlocal;
1.1       www        38: 
                     39: sub handler {
                     40:     my $r = shift;
                     41: 
1.17      albertel   42:     #Check for cookie
1.1       www        43:     my $requrl=$r->uri;
                     44:     my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
                     45:     my $lonid=$cookies{'lonID'};
                     46:     my $cookie;
1.17      albertel   47:     if (!$lonid) {
                     48: 	return FORBIDDEN;
                     49:     }
                     50: 
                     51:     #check if cookie still valid
1.22      albertel   52:     my $handle=&LONCAPA::clean_handle($lonid->value);
1.17      albertel   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;
1.21      albertel   61:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
1.17      albertel   62:     unlink("$lonidsdir/$handle.id");
                     63:     my %temp=('logout' => time);
                     64:     &Apache::lonnet::put('email_status',\%temp);
1.21      albertel   65:     &Apache::lonnet::log($env{'user.domain'},
                     66: 			 $env{'user.name'},
                     67: 			 $env{'user.home'},
1.17      albertel   68: 			 "Logout $ENV{'REMOTE_ADDR'}");
1.25      albertel   69: 
1.17      albertel   70:     &Apache::loncommon::content_type($r,'text/html');
1.25      albertel   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: 
1.17      albertel   78:     $r->send_http_header;
                     79:     return OK if $r->header_only;
1.2       www        80: # -------------------------------------------------------- Menu script and info
                     81: 
                     82:     my $windowinfo=&Apache::lonmenu::close();
1.13      albertel   83:     $windowinfo.=&Apache::lonnavmaps::close();
1.6       www        84: # ---------------------------------------------------------------- Get handover
                     85:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['handover']);
                     86:     my $switch='';
1.18      albertel   87:     my $start_page='';
1.7       www        88:     my $relogmessage='';
1.14      albertel   89:     if ($env{'form.handover'}) {
1.17      albertel   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 {
1.19      albertel   95: 	$start_page=&Apache::loncommon::start_page('Logged Out',undef,
                     96: 						   {'no_inline_link' => 1,});
1.17      albertel   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');
1.26      albertel  102: 	
                    103: 	$relogmessage.=(<<ENDRELOG);
1.17      albertel  104: 	<h1>$lt{'gb'}!</h1>
1.26      albertel  105: ENDRELOG
                    106: 
                    107: 	if (!$env{'request.sso.norelogin'}) {
                    108: 	    my $relogin_server;
                    109: 	    if ($env{'request.sso.reloginserver'}) {
                    110: 		$relogin_server = $env{'request.sso.reloginserver'};
                    111: 	    }
                    112: 	    my $login_url = $relogin_server.'/adm/'.
                    113: 		($env{'request.sso.login'} ? 'roles': 'login');
                    114: 
                    115: 	    $relogmessage.=(<<ENDRELOG);
1.17      albertel  116: 	    $lt{'pe'} <a href="javascript:self.close();">$lt{'cw'}</a> $lt{'or'}
1.21      albertel  117: 	<a href="$login_url?domain=$env{'user.domain'}">$lt{'li'}</a>.
1.7       www       118: ENDRELOG
1.20      albertel  119: 
1.26      albertel  120:         }
                    121: 	my $domain = $env{'user.domain'};
1.20      albertel  122:         if ($env{'request.sso.login'}
1.26      albertel  123: 	    && defined($r->dir_config("lonSSOUserLogoutMessageFile_$domain"))) {
                    124: 	    open(my $fh,$r->dir_config("lonSSOUserLogoutMessageFile_$domain"));
                    125: 	    $relogmessage.= join('',<$fh>);
                    126: 	}
                    127: 	if ($env{'request.sso.login'}
1.27      albertel  128: 	    && defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {
1.20      albertel  129: 	    open(my $fh,$r->dir_config('lonSSOUserLogoutMessageFile'));
                    130: 	    $relogmessage.= join('',<$fh>);
                    131: 	}
                    132: 
1.17      albertel  133:     }
1.18      albertel  134:     my $end_page=&Apache::loncommon::end_page();
1.2       www       135: # --------------------------------------------------------------- Screen Output
1.17      albertel  136:     $r->print(<<ENDDOCUMENT);
1.16      albertel  137: $start_page
1.2       www       138: $windowinfo
1.7       www       139: $relogmessage
1.16      albertel  140: $end_page
1.1       www       141: ENDDOCUMENT
1.28    ! albertel  142:     $r->register_cleanup(\&flush_course_logs);
        !           143:     return OK; 
        !           144: }
        !           145: 
        !           146: sub flush_course_logs {
1.17      albertel  147:     &Apache::lonnet::flushcourselogs();
1.28    ! albertel  148:     return OK;
1.1       www       149: }
                    150: 
                    151: 1;
                    152: __END__
                    153: 
                    154: 
                    155: 
                    156: 
                    157: 
                    158: 
                    159: 
                    160: 

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