Annotation of loncom/auth/lonlinkexit.pm, revision 1.2
1.1 raeburn 1: # The LearningOnline Network
2: # Re-launch guidance for deep linked access with username mismatch
3: #
1.2 ! raeburn 4: # $Id: lonlinkexit.pm,v 1.1 2022/06/30 21:04:13 raeburn Exp $
1.1 raeburn 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: package Apache::lonlinkexit;
30:
31: use strict;
32: use lib '/home/httpd/lib/perl/';
33: use Apache::Constants qw(:common);
34: use Apache::lonnet;
35: use Apache::loncommon;
1.2 ! raeburn 36: use Apache::lonnavmaps;
1.1 raeburn 37: use Apache::lonlocal;
38: use LONCAPA;
39: use CGI::Cookie();
40:
41: sub handler {
42: my $r = shift;
43:
44: my $handle = &Apache::lonnet::check_for_valid_session($r);
45: my ($exiturl,$deeplinktarget);
46: if ($handle ne '') {
47: my $lonidsdir=$r->dir_config('lonIDsDir');
48: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
49: if ($env{'request.deeplink.login'}) {
50: if ($env{'request.deeplink.target'} ne '') {
51: $deeplinktarget = $env{'request.deeplink.target'};
52: }
1.2 ! raeburn 53: if ($env{'request.course.id'}) {
! 54: my ($deeplink_symb,$deeplink);
! 55: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
! 56: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 57: if (($cnum ne '') && ($cdom ne '')) {
! 58: $deeplink_symb = &Apache::loncommon::deeplink_login_symb($cnum,$cdom);
! 59: if ($deeplink_symb) {
! 60: if ($deeplink_symb =~ /\.(page|sequence)$/) {
! 61: my $mapname = &Apache::lonnet::deversion((&Apache::lonnet::decode_symb($deeplink_symb))[2]);
! 62: my $navmap = Apache::lonnavmaps::navmap->new();
! 63: if (ref($navmap)) {
! 64: $deeplink = $navmap->get_mapparam(undef,$mapname,'0.deeplink');
! 65: }
! 66: } else {
! 67: $deeplink = &Apache::lonnet::EXT('resource.0.deeplink',$deeplink_symb);
! 68: }
! 69: if ($deeplink ne '') {
! 70: my ($state,$others,$listed,$scope,$protect,$display,$target,$exit) = split(/,/,$deeplink);
! 71: if ($exit) {
! 72: my ($show,$text) = split(/:/,$exit);
! 73: if ($show eq 'url') {
! 74: if ($env{'request.linkprotexit'} =~ m{^https?://}) {
! 75: $exiturl = $env{'request.linkprotexit'};
! 76: &js_escape(\$exiturl);
! 77: }
! 78: }
! 79: }
! 80: }
! 81: }
! 82: }
1.1 raeburn 83: }
84: }
85: if (unlink("$lonidsdir/$handle.id")) {
86: if (($env{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
87: (-l "$lonidsdir/$env{'user.linkedenv'}.id") &&
88: (readlink("$lonidsdir/$env{'user.linkedenv'}.id") eq "$lonidsdir/$handle.id")) {
89: unlink("$lonidsdir/$env{'user.linkedenv'}.id");
90: }
91: }
92: my %temp=('logout' => time);
93: my $ip = &Apache::lonnet::get_requestor_ip();
94: &Apache::lonnet::put('email_status',\%temp);
95: &Apache::lonnet::log($env{'user.domain'},
96: $env{'user.name'},
97: $env{'user.home'},
98: "Logout $ip");
99: #expire the cookies
100: my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
101: foreach my $name (keys(%cookies)) {
102: next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
103: my $c = new CGI::Cookie(-name => $name,
104: -value => '',
105: -expires => '-10y',);
106: $r->headers_out->add('Set-cookie' => $c);
107: }
108: }
109: if (!$Apache::lonlocal::lh) {
110: &Apache::lonlocal::get_language_handle($r);
111: }
112: &Apache::loncommon::content_type($r,'text/html');
113: $r->send_http_header;
114: return OK if $r->header_only;
115:
116: my ($msg,$js);
117: $msg = '<p>'.&mt('Expired any existing session').'</p>';
118: my $args = {'only_body' => 1};
119: if ($exiturl) {
120: $js = <<ENDJS;
121: <script type="text/javascript">
122: // <![CDATA[
123: \$(document).ready( function() {
124: setTimeout(function() {
125: if (window.self !== window.top) {
126: window.top.location.href = '$exiturl';
127: } else {
128: document.location.href = '$exiturl';
129: }
130: },100);
131: });
132: // ]]>
133: </script>
134: ENDJS
135: $msg .= '<p>'.&mt('Redirecting ...').'</p>';
136: }
137:
138: $r->print(&Apache::loncommon::start_page('Session removed',$js,{'only_body' => 1}));
139: $r->print($msg);
140: $r->print(&Apache::loncommon::end_page());
141: return OK;
142: }
143:
144: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>