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

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

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