File:  [LON-CAPA] / loncom / auth / lonlogout.pm
Revision 1.51: download - view: text, annotated - select for diffs
Fri Aug 18 18:13:33 2017 UTC (6 years, 8 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Sanity checking

    1: # The LearningOnline Network
    2: # Logout Handler
    3: #
    4: # $Id: lonlogout.pm,v 1.51 2017/08/18 18:13:33 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 ($env{'user.linkedenv'} ne '') {
   76:         my $lonhost = $r->dir_config('lonHostID');
   77:         if ((-l $env{'user.linkedenv'}) && 
   78:             (readlink($env{'user.linkedenv'}) eq "$lonidsdir/$handle.id")) {
   79:             unlink($env{'user.linkedenv'});
   80:         }
   81:     }
   82:     if (!$Apache::lonlocal::lh) {
   83:         &Apache::lonlocal::get_language_handle($r);
   84:     }
   85:     my %temp=('logout' => time);
   86:     &Apache::lonnet::put('email_status',\%temp);
   87:     &Apache::lonnet::log($env{'user.domain'},
   88: 			 $env{'user.name'},
   89: 			 $env{'user.home'},
   90: 			 "Logout $ENV{'REMOTE_ADDR'}");
   91: 
   92:     &Apache::loncommon::content_type($r,'text/html');
   93: 
   94:     #expire the cookie
   95:     my $name = 'lonID';
   96:     if (($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')) {
   97:         $name = 'lonPubID';
   98:     }
   99:     my $c = new CGI::Cookie(-name    => $name,
  100: 			    -value   => '',
  101: 			    -expires => '-10y',);
  102:     $r->headers_out->add('Set-cookie' => $c);
  103:     if (($name eq 'lonID') && ($env{'user.linkeenv'})) {
  104:         my $other = new CGI::Cookie(-name    => 'lonLinkID',
  105:                                     -value   => '',
  106:                                     -expires => '-10y',);
  107:         $r->headers_out->add('Set-cookie' => $other);
  108:     }
  109:     $r->send_http_header;
  110:     return OK if $r->header_only;
  111: # -------------------------------------------------------- Menu script and info
  112: 
  113: # ---------------------------------------------------------------- Get handover
  114:     &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['handover']);
  115:     my $switch='';
  116:     my $start_page='';
  117:     my $relogmessage='';
  118:     if ($env{'form.handover'}) {
  119: 	$switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.
  120: 	    $env{'form.handover'}.'" />';
  121: 	$start_page=&Apache::loncommon::start_page('Switching Server ...',
  122: 						   $switch);
  123:     } else {
  124:         my $domain = $env{'user.domain'};
  125:         my ($headextra,$ssofile);
  126:         if ($env{'request.sso.login'}) {
  127:             my $londocroot = $r->dir_config('lonDocRoot');
  128:             if ($domain =~ /^$match_domain$/) {
  129:                 if (defined($r->dir_config("lonSSOUserLogoutHeadFile_$domain"))) {
  130:                     $ssofile = '/'.&Apache::loncommon::clean_path($r->dir_config("lonSSOUserLogoutHeadFile_$domain"));
  131:                     if ($ssofile eq $r->dir_config("lonSSOUserLogoutHeadFile_$domain")) {
  132:                         if ($ssofile =~ /^\Q$londocroot\E/) {
  133:                             if (open(my $fh,"<$ssofile")) {
  134:                                 $headextra = join('',<$fh>);
  135:                                 close($fh);
  136:                             }
  137:                         }
  138:                     }
  139:                 }
  140:             }
  141:             if (defined($r->dir_config('lonSSOUserLogoutHeadFile'))) {
  142:                 $ssofile = '/'.&Apache::loncommon::clean_path($r->dir_config('lonSSOUserLogoutHeadFile'));
  143:                 if ($ssofile eq $r->dir_config('lonSSOUserLogoutHeadFile')) {
  144:                     if ($ssofile =~ /^\Q$londocroot\E/) {
  145:                         if (open(my $fh,"<$ssofile")) {
  146:                             $headextra.= join('',<$fh>);
  147:                             close($fh);
  148:                         }
  149:                     }
  150:                 }
  151:             }
  152:         }
  153: 	$start_page=&Apache::loncommon::start_page('Logged Out',$headextra,
  154:                            {'no_nav_bar'     => 1,});
  155: 	
  156:         $relogmessage.='<h1>'.&mt('Goodbye').'</h1>'
  157:                       .'<p>'.&mt('Thank you for using LON-CAPA.').'</p>';
  158: 
  159: 	if (!$env{'request.sso.norelogin'}) {
  160: 	    my ($relogin_server,$login_url);
  161: 	    if ($env{'request.sso.reloginserver'}) {
  162: 		$relogin_server = $env{'request.sso.reloginserver'};
  163: 	    } else {
  164:                  my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
  165:                  if ($domdefaults{'portal_def'}) {
  166:                      $login_url = $domdefaults{'portal_def'};
  167:                  } else {
  168:                      my $checkloginvia = 1;
  169:                      my ($lonhost,$server,$path,$isredirect) = 
  170:                          &Apache::lonnet::choose_server($domain,$checkloginvia);
  171:                      if ($server && $lonhost) {
  172:                          $login_url = $Apache::lonnet::protocol{$lonhost}.
  173:                                       '://'.$server.$path;
  174:                          if (($path eq '') && (!$isredirect)) {
  175:                              my $serverhomeID =
  176:                                  &Apache::lonnet::get_server_homeID($server);
  177:                              my $serverhomedom =
  178:                                  &Apache::lonnet::host_domain($serverhomeID);
  179:                              if ($serverhomedom ne $domain) {
  180:                                  $path = '/adm/login';
  181:                                  $login_url .= $path;
  182:                              }
  183:                          }
  184:                          if ($path eq '/adm/login' && $domain ne '') {
  185:                              $login_url .= '?domain='.$domain;
  186:                          }
  187:                      }
  188:                  }
  189:             }
  190:             if ($login_url eq '') {
  191: 	        $login_url = $relogin_server.'/adm/'.
  192: 		    ($env{'request.sso.login'} ? 'roles': 'login?domain='.$domain);
  193:             }
  194:             $relogmessage.='<p>'.&mt('You have been successfully logged out.').' '
  195:                           .&mt('You can [_1]close this window[_2] now.'
  196:                               ,'','') # ,'<a href="javascript:self.close();">','</a>')
  197:                           .'</p>';
  198: =pod
  199: 
  200: =head1 NOTES:
  201: 
  202: '<a href="javascript:self.close();">','</a>'
  203: 
  204: 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)
  205: 
  206: =cut
  207:             $relogmessage.='<p>'.&mt('[_1]Log in again[_2]'
  208:                               ,'<a href="'.$login_url.'">','</a>')
  209:                           .'</p>';
  210:         }
  211:         if ($env{'request.sso.login'}
  212: 	    && defined($r->dir_config("lonSSOUserLogoutMessageFile_$domain"))) {
  213: 	    if (open(my $fh,$r->dir_config("lonSSOUserLogoutMessageFile_$domain"))) {
  214: 	        $relogmessage.= join('',<$fh>);
  215:                 close($fh);
  216:             }
  217: 	}
  218: 	if ($env{'request.sso.login'}
  219: 	    && defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {
  220: 	    if (open(my $fh,$r->dir_config('lonSSOUserLogoutMessageFile'))) {
  221: 	        $relogmessage.= join('',<$fh>);
  222:                 close($fh);
  223:             }
  224: 	}
  225:     }
  226:     my $end_page=&Apache::loncommon::end_page();
  227: # --------------------------------------------------------------- Screen Output
  228:     $r->print(<<ENDDOCUMENT);
  229: $start_page
  230: $relogmessage
  231: $end_page
  232: ENDDOCUMENT
  233:     $r->register_cleanup(\&flush_course_logs);
  234:     return OK; 
  235: }
  236: 
  237: sub flush_course_logs {
  238:     &Apache::lonnet::flushcourselogs();
  239:     return OK;
  240: }
  241: 
  242: 1;
  243: __END__
  244: 
  245: 
  246: 
  247: 
  248: 
  249: 
  250: 

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