Annotation of loncom/auth/lonlogout.pm, revision 1.31
1.1 www 1: # The LearningOnline Network
2: # Logout Handler
1.3 www 3: #
1.31 ! www 4: # $Id: lonlogout.pm,v 1.30 2008/04/02 12:29:38 bisitz 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:
29: package Apache::lonlogout;
30:
31: use strict;
32: use Apache::Constants qw(:common);
33: use Apache::File;
34: use Apache::lonnet;
1.2 www 35: use Apache::lonmenu;
1.1 www 36: use CGI::Cookie();
1.11 www 37: use Apache::lonlocal;
1.1 www 38:
39: sub handler {
40: my $r = shift;
41:
1.17 albertel 42: #Check for cookie
1.1 www 43: my $requrl=$r->uri;
1.29 albertel 44: my $handle = &Apache::lonnet::check_for_valid_session($r);
1.17 albertel 45: #check if cookie still valid
1.29 albertel 46: if ($handle eq '') {
1.17 albertel 47: $r->log_reason("Cookie $handle not valid", $r->filename);
48: return FORBIDDEN;
49: }
50:
51: #we've got a valid user
1.31 ! www 52: #any locks in place?
! 53: my $locknum=&Apache::lonnet::get_locks();
! 54: if ($locknum) { return 409; }
! 55: #nope, go ahead
1.17 albertel 56: my @profile;
1.29 albertel 57: my $lonidsdir=$r->dir_config('lonIDsDir');
1.21 albertel 58: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
1.17 albertel 59: unlink("$lonidsdir/$handle.id");
60: my %temp=('logout' => time);
61: &Apache::lonnet::put('email_status',\%temp);
1.21 albertel 62: &Apache::lonnet::log($env{'user.domain'},
63: $env{'user.name'},
64: $env{'user.home'},
1.17 albertel 65: "Logout $ENV{'REMOTE_ADDR'}");
1.25 albertel 66:
1.17 albertel 67: &Apache::loncommon::content_type($r,'text/html');
1.25 albertel 68:
69: #expire the cookie
70: my $c = new CGI::Cookie(-name => 'lonID',
71: -value => '',
72: -expires => '-10y',);
73: $r->header_out('Set-cookie' => $c);
74:
1.17 albertel 75: $r->send_http_header;
76: return OK if $r->header_only;
1.2 www 77: # -------------------------------------------------------- Menu script and info
78:
79: my $windowinfo=&Apache::lonmenu::close();
1.13 albertel 80: $windowinfo.=&Apache::lonnavmaps::close();
1.6 www 81: # ---------------------------------------------------------------- Get handover
82: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['handover']);
83: my $switch='';
1.18 albertel 84: my $start_page='';
1.7 www 85: my $relogmessage='';
1.14 albertel 86: if ($env{'form.handover'}) {
1.17 albertel 87: $switch='<meta HTTP-EQUIV="Refresh" CONTENT="0.5; url='.
88: $env{'form.handover'}.'">';
89: $start_page=&Apache::loncommon::start_page('Switching Server ...',
90: $switch);
91: } else {
1.19 albertel 92: $start_page=&Apache::loncommon::start_page('Logged Out',undef,
93: {'no_inline_link' => 1,});
1.26 albertel 94:
1.30 bisitz 95: $relogmessage.='<h1>'.&mt('Goodbye').'</h1>';
1.26 albertel 96:
97: if (!$env{'request.sso.norelogin'}) {
98: my $relogin_server;
99: if ($env{'request.sso.reloginserver'}) {
100: $relogin_server = $env{'request.sso.reloginserver'};
101: }
102: my $login_url = $relogin_server.'/adm/'.
103: ($env{'request.sso.login'} ? 'roles': 'login');
104:
1.30 bisitz 105: $relogmessage.=&mt('Please either [_1]close this window[_2] or [_3]log in again[_4].'
106: ,'<a href="javascript:self.close();">','</a>'
107: ,'<a href="'.$login_url.'?domain='.$env{'user.domain'}.'">','</a>');
1.26 albertel 108: }
109: my $domain = $env{'user.domain'};
1.20 albertel 110: if ($env{'request.sso.login'}
1.26 albertel 111: && defined($r->dir_config("lonSSOUserLogoutMessageFile_$domain"))) {
112: open(my $fh,$r->dir_config("lonSSOUserLogoutMessageFile_$domain"));
113: $relogmessage.= join('',<$fh>);
114: }
115: if ($env{'request.sso.login'}
1.27 albertel 116: && defined($r->dir_config('lonSSOUserLogoutMessageFile'))) {
1.20 albertel 117: open(my $fh,$r->dir_config('lonSSOUserLogoutMessageFile'));
118: $relogmessage.= join('',<$fh>);
119: }
120:
1.17 albertel 121: }
1.18 albertel 122: my $end_page=&Apache::loncommon::end_page();
1.2 www 123: # --------------------------------------------------------------- Screen Output
1.17 albertel 124: $r->print(<<ENDDOCUMENT);
1.16 albertel 125: $start_page
1.2 www 126: $windowinfo
1.7 www 127: $relogmessage
1.16 albertel 128: $end_page
1.1 www 129: ENDDOCUMENT
1.28 albertel 130: $r->register_cleanup(\&flush_course_logs);
131: return OK;
132: }
133:
134: sub flush_course_logs {
1.17 albertel 135: &Apache::lonnet::flushcourselogs();
1.28 albertel 136: return OK;
1.1 www 137: }
138:
139: 1;
140: __END__
141:
142:
143:
144:
145:
146:
147:
148:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>