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

1.1       www         1: # The LearningOnline Network
                      2: # Logout Handler
1.3       www         3: #
1.45.2.1! raeburn     4: # $Id: lonlogout.pm,v 1.45 2012/02/13 16:59:24 raeburn 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: 
1.36      jms        29: =head1 NAME
                     30: 
                     31: Apache::lonlogout
                     32: 
                     33: =head1 SYNOPSIS
                     34: 
                     35: 
                     36: This is part of the LearningOnline Network with CAPA project
                     37: described at http://www.lon-capa.org.
                     38: 
                     39: 
                     40: =cut
                     41: 
1.1       www        42: package Apache::lonlogout;
                     43: 
                     44: use strict;
                     45: use Apache::Constants qw(:common);
                     46: use Apache::File;
                     47: use Apache::lonnet;
1.2       www        48: use Apache::lonmenu;
1.1       www        49: use CGI::Cookie();
1.11      www        50: use Apache::lonlocal;
1.1       www        51: 
                     52: sub handler {
                     53:     my $r = shift;
                     54: 
1.17      albertel   55:     #Check for cookie
1.1       www        56:     my $requrl=$r->uri;
1.29      albertel   57:     my $handle = &Apache::lonnet::check_for_valid_session($r);
1.17      albertel   58:     #check if cookie still valid
1.29      albertel   59:     if ($handle eq '') {
1.17      albertel   60: 	$r->log_reason("Cookie $handle not valid", $r->filename); 
                     61: 	return FORBIDDEN;
                     62:     }
                     63: 
                     64:     #we've got a valid user
1.31      www        65:     #any locks in place?
                     66:     my $locknum=&Apache::lonnet::get_locks();
                     67:     if ($locknum) { return 409; }
                     68:     #nope, go ahead
1.17      albertel   69:     my @profile;
1.29      albertel   70:     my $lonidsdir=$r->dir_config('lonIDsDir');
1.21      albertel   71:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
1.17      albertel   72:     unlink("$lonidsdir/$handle.id");
                     73:     my %temp=('logout' => time);
                     74:     &Apache::lonnet::put('email_status',\%temp);
1.21      albertel   75:     &Apache::lonnet::log($env{'user.domain'},
                     76: 			 $env{'user.name'},
                     77: 			 $env{'user.home'},
1.17      albertel   78: 			 "Logout $ENV{'REMOTE_ADDR'}");
1.25      albertel   79: 
1.17      albertel   80:     &Apache::loncommon::content_type($r,'text/html');
1.25      albertel   81: 
                     82:     #expire the cookie
                     83:     my $c = new CGI::Cookie(-name    => 'lonID',
                     84: 			    -value   => '',
                     85: 			    -expires => '-10y',);
                     86:     $r->header_out('Set-cookie' => $c);
                     87: 
1.17      albertel   88:     $r->send_http_header;
                     89:     return OK if $r->header_only;
1.2       www        90: # -------------------------------------------------------- Menu script and info
                     91: 
1.45.2.1! raeburn    92:     my $windowinfo=&Apache::lonmenu::close();
1.6       www        93: # ---------------------------------------------------------------- Get handover
                     94:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['handover']);
                     95:     my $switch='';
1.18      albertel   96:     my $start_page='';
1.7       www        97:     my $relogmessage='';
1.14      albertel   98:     if ($env{'form.handover'}) {
1.17      albertel   99: 	$switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.
1.37      bisitz    100: 	    $env{'form.handover'}.'" />';
1.17      albertel  101: 	$start_page=&Apache::loncommon::start_page('Switching Server ...',
                    102: 						   $switch);
                    103:     } else {
1.19      albertel  104: 	$start_page=&Apache::loncommon::start_page('Logged Out',undef,
1.45.2.1! raeburn   105:                            {'no_inline_link' => 1,
        !           106:                             'no_nav_bar'     => 1,});
1.26      albertel  107: 	
1.32      bisitz    108:         $relogmessage.='<h1>'.&mt('Goodbye').'</h1>'
                    109:                       .'<p>'.&mt('Thank you for using LON-CAPA.').'</p>';
1.26      albertel  110: 
1.42      raeburn   111:         my $domain = $env{'user.domain'};
1.26      albertel  112: 	if (!$env{'request.sso.norelogin'}) {
1.42      raeburn   113: 	    my ($relogin_server,$login_url);
1.26      albertel  114: 	    if ($env{'request.sso.reloginserver'}) {
                    115: 		$relogin_server = $env{'request.sso.reloginserver'};
1.42      raeburn   116: 	    } else {
                    117:                  my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
                    118:                  if ($domdefaults{'portal_def'}) {
                    119:                      $login_url = $domdefaults{'portal_def'};
                    120:                  } else {
                    121:                      my $checkloginvia = 1;
1.44      raeburn   122:                      my ($lonhost,$server,$path,$isredirect) = 
1.42      raeburn   123:                          &Apache::lonnet::choose_server($domain,$checkloginvia);
                    124:                      if ($server && $lonhost) {
                    125:                          $login_url = $Apache::lonnet::protocol{$lonhost}.
                    126:                                       '://'.$server.$path;
1.44      raeburn   127:                          if (($path eq '') && (!$isredirect)) {
                    128:                              my $serverhomeID =
1.45      raeburn   129:                                  &Apache::lonnet::get_server_homeID($server);
1.44      raeburn   130:                              my $serverhomedom =
                    131:                                  &Apache::lonnet::host_domain($serverhomeID);
                    132:                              if ($serverhomedom ne $domain) {
                    133:                                  $path = '/adm/login';
                    134:                                  $login_url .= $path;
                    135:                              }
                    136:                          }
1.43      raeburn   137:                          if ($path eq '/adm/login' && $domain ne '') {
                    138:                              $login_url .= '?domain='.$domain;
                    139:                          }
1.42      raeburn   140:                      }
                    141:                  }
                    142:             }
                    143:             if ($login_url eq '') {
                    144: 	        $login_url = $relogin_server.'/adm/'.
                    145: 		    ($env{'request.sso.login'} ? 'roles': 'login?domain='.$domain);
                    146:             }
1.32      bisitz    147:             $relogmessage.='<p>'.&mt('You have been successfully logged out.').' '
                    148:                           .&mt('You can [_1]close this window[_2] now.'
1.34      bisitz    149:                               ,'','') # ,'<a href="javascript:self.close();">','</a>')
                    150:                           .'</p>';
1.33      jms       151: =pod
                    152: 
                    153: =head1 NOTES:
                    154: 
1.34      bisitz    155: '<a href="javascript:self.close();">','</a>'
1.33      jms       156: 
                    157: 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)
                    158: 
                    159: =cut
1.34      bisitz    160:             $relogmessage.='<p>'.&mt('[_1]Log in again[_2]'
1.42      raeburn   161:                               ,'<a href="'.$login_url.'">','</a>')
1.32      bisitz    162:                           .'</p>';
1.26      albertel  163:         }
1.20      albertel  164:         if ($env{'request.sso.login'}
1.26      albertel  165: 	    && defined($r->dir_config("lonSSOUserLogoutMessageFile_$domain"))) {
                    166: 	    open(my $fh,$r->dir_config("lonSSOUserLogoutMessageFile_$domain"));
                    167: 	    $relogmessage.= join('',<$fh>);
                    168: 	}
                    169: 	if ($env{'request.sso.login'}
1.27      albertel  170: 	    && defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {
1.20      albertel  171: 	    open(my $fh,$r->dir_config('lonSSOUserLogoutMessageFile'));
                    172: 	    $relogmessage.= join('',<$fh>);
                    173: 	}
                    174: 
1.17      albertel  175:     }
1.18      albertel  176:     my $end_page=&Apache::loncommon::end_page();
1.2       www       177: # --------------------------------------------------------------- Screen Output
1.17      albertel  178:     $r->print(<<ENDDOCUMENT);
1.16      albertel  179: $start_page
1.45.2.1! raeburn   180: $windowinfo
1.7       www       181: $relogmessage
1.16      albertel  182: $end_page
1.1       www       183: ENDDOCUMENT
1.28      albertel  184:     $r->register_cleanup(\&flush_course_logs);
                    185:     return OK; 
                    186: }
                    187: 
                    188: sub flush_course_logs {
1.17      albertel  189:     &Apache::lonnet::flushcourselogs();
1.28      albertel  190:     return OK;
1.1       www       191: }
                    192: 
                    193: 1;
                    194: __END__
                    195: 
                    196: 
                    197: 
                    198: 
                    199: 
                    200: 
                    201: 

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