File:  [LON-CAPA] / loncom / auth / lonlogout.pm
Revision 1.45.2.5: download - view: text, annotated - select for diffs
Tue Sep 11 14:23:21 2018 UTC (5 years, 7 months ago) by raeburn
Branches: version_2_11_X
- For 2.11
  Backport 1.53 (part) not included in rev. 1.45.2.4

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

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