File:  [LON-CAPA] / loncom / auth / lonlogout.pm
Revision 1.45.2.3: download - view: text, annotated - select for diffs
Thu Mar 12 00:50:46 2015 UTC (9 years, 1 month ago) by raeburn
Branches: version_2_11_X
CVS tags: version_2_11_2_uiuc, version_2_11_2_msu, version_2_11_2_educog, version_2_11_2, version_2_11_1
- For 2.11
  Backport 1.47. 1.48, 1.49

    1: # The LearningOnline Network
    2: # Logout Handler
    3: #
    4: # $Id: lonlogout.pm,v 1.45.2.3 2015/03/12 00:50:46 raeburn 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: =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: 
   42: package Apache::lonlogout;
   43: 
   44: use strict;
   45: use Apache::Constants qw(:common);
   46: use Apache::File;
   47: use Apache::lonnet;
   48: use Apache::lonmenu;
   49: use CGI::Cookie();
   50: use Apache::lonlocal;
   51: 
   52: sub handler {
   53:     my $r = shift;
   54: 
   55:     #Check for cookie
   56:     my $requrl=$r->uri;
   57:     my $handle = &Apache::lonnet::check_for_valid_session($r);
   58:     #check if cookie still valid
   59:     if ($handle eq '') {
   60: 	$r->log_reason("Cookie $handle not valid", $r->filename); 
   61: 	return FORBIDDEN;
   62:     }
   63: 
   64:     #we've got a valid user
   65:     #any locks in place?
   66:     my $locknum=&Apache::lonnet::get_locks();
   67:     if ($locknum) { return 409; }
   68:     #nope, go ahead
   69:     my @profile;
   70:     my $lonidsdir=$r->dir_config('lonIDsDir');
   71:     &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
   72:     unlink("$lonidsdir/$handle.id");
   73:     if (!$Apache::lonlocal::lh) {
   74:         &Apache::lonlocal::get_language_handle($r);
   75:     }
   76:     my %temp=('logout' => time);
   77:     &Apache::lonnet::put('email_status',\%temp);
   78:     &Apache::lonnet::log($env{'user.domain'},
   79: 			 $env{'user.name'},
   80: 			 $env{'user.home'},
   81: 			 "Logout $ENV{'REMOTE_ADDR'}");
   82: 
   83:     &Apache::loncommon::content_type($r,'text/html');
   84: 
   85:     #expire the cookie
   86:     my $c = new CGI::Cookie(-name    => 'lonID',
   87: 			    -value   => '',
   88: 			    -expires => '-10y',);
   89:     $r->header_out('Set-cookie' => $c);
   90: 
   91:     $r->send_http_header;
   92:     return OK if $r->header_only;
   93: # -------------------------------------------------------- Menu script and info
   94: 
   95:     my $windowinfo=&Apache::lonmenu::close();
   96: # ---------------------------------------------------------------- Get handover
   97:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['handover']);
   98:     my $switch='';
   99:     my $start_page='';
  100:     my $relogmessage='';
  101:     if ($env{'form.handover'}) {
  102: 	$switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.
  103: 	    $env{'form.handover'}.'" />';
  104: 	$start_page=&Apache::loncommon::start_page('Switching Server ...',
  105: 						   $switch);
  106:     } else {
  107:         my $domain = $env{'user.domain'};
  108:         my $headextra;
  109:         if ($env{'request.sso.login'}
  110:             && defined($r->dir_config("lonSSOUserLogoutHeadFile_$domain"))) {
  111:             if (open(my $fh,$r->dir_config("lonSSOUserLogoutHeadFile_$domain"))) {
  112:                 $headextra = join('',<$fh>);
  113:                 close($fh);
  114:             }
  115:         }
  116:         if ($env{'request.sso.login'}
  117:             && defined($r->dir_config('lonSSOUserLogoutHeadFile'))) {
  118:             if (open(my $fh,$r->dir_config('lonSSOUserLogoutHeadFile'))) {
  119:                 $headextra.= join('',<$fh>);
  120:                 close($fh);
  121:             }
  122:         }
  123: 	$start_page=&Apache::loncommon::start_page('Logged Out',$headextra,
  124:                            {'no_inline_link' => 1,
  125:                             'no_nav_bar'     => 1,});
  126: 	
  127:         $relogmessage.='<h1>'.&mt('Goodbye').'</h1>'
  128:                       .'<p>'.&mt('Thank you for using LON-CAPA.').'</p>';
  129: 
  130: 	if (!$env{'request.sso.norelogin'}) {
  131: 	    my ($relogin_server,$login_url);
  132: 	    if ($env{'request.sso.reloginserver'}) {
  133: 		$relogin_server = $env{'request.sso.reloginserver'};
  134: 	    } else {
  135:                  my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
  136:                  if ($domdefaults{'portal_def'}) {
  137:                      $login_url = $domdefaults{'portal_def'};
  138:                  } else {
  139:                      my $checkloginvia = 1;
  140:                      my ($lonhost,$server,$path,$isredirect) = 
  141:                          &Apache::lonnet::choose_server($domain,$checkloginvia);
  142:                      if ($server && $lonhost) {
  143:                          $login_url = $Apache::lonnet::protocol{$lonhost}.
  144:                                       '://'.$server.$path;
  145:                          if (($path eq '') && (!$isredirect)) {
  146:                              my $serverhomeID =
  147:                                  &Apache::lonnet::get_server_homeID($server);
  148:                              my $serverhomedom =
  149:                                  &Apache::lonnet::host_domain($serverhomeID);
  150:                              if ($serverhomedom ne $domain) {
  151:                                  $path = '/adm/login';
  152:                                  $login_url .= $path;
  153:                              }
  154:                          }
  155:                          if ($path eq '/adm/login' && $domain ne '') {
  156:                              $login_url .= '?domain='.$domain;
  157:                          }
  158:                      }
  159:                  }
  160:             }
  161:             if ($login_url eq '') {
  162: 	        $login_url = $relogin_server.'/adm/'.
  163: 		    ($env{'request.sso.login'} ? 'roles': 'login?domain='.$domain);
  164:             }
  165:             $relogmessage.='<p>'.&mt('You have been successfully logged out.').' '
  166:                           .&mt('You can [_1]close this window[_2] now.'
  167:                               ,'','') # ,'<a href="javascript:self.close();">','</a>')
  168:                           .'</p>';
  169: =pod
  170: 
  171: =head1 NOTES:
  172: 
  173: '<a href="javascript:self.close();">','</a>'
  174: 
  175: Due to security reasons in new web browsers a window could only be closed with javascript, if this window has also been opened 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)
  176: 
  177: =cut
  178:             $relogmessage.='<p>'.&mt('[_1]Log in again[_2]'
  179:                               ,'<a href="'.$login_url.'">','</a>')
  180:                           .'</p>';
  181:         }
  182:         if ($env{'request.sso.login'}
  183: 	    && defined($r->dir_config("lonSSOUserLogoutMessageFile_$domain"))) {
  184: 	    if (open(my $fh,$r->dir_config("lonSSOUserLogoutMessageFile_$domain"))) {
  185: 	        $relogmessage.= join('',<$fh>);
  186:                 close($fh);
  187:             }
  188: 	}
  189: 	if ($env{'request.sso.login'}
  190: 	    && defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {
  191: 	    if (open(my $fh,$r->dir_config('lonSSOUserLogoutMessageFile'))) {
  192: 	        $relogmessage.= join('',<$fh>);
  193:                 close($fh);
  194:             }
  195: 	}
  196:     }
  197:     my $end_page=&Apache::loncommon::end_page();
  198: # --------------------------------------------------------------- Screen Output
  199:     $r->print(<<ENDDOCUMENT);
  200: $start_page
  201: $windowinfo
  202: $relogmessage
  203: $end_page
  204: ENDDOCUMENT
  205:     $r->register_cleanup(\&flush_course_logs);
  206:     return OK; 
  207: }
  208: 
  209: sub flush_course_logs {
  210:     &Apache::lonnet::flushcourselogs();
  211:     return OK;
  212: }
  213: 
  214: 1;
  215: __END__
  216: 
  217: 
  218: 
  219: 
  220: 
  221: 
  222: 

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