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