Annotation of loncom/auth/lonlinkexit.pm, revision 1.1

1.1     ! raeburn     1: # The LearningOnline Network
        !             2: # Re-launch guidance for deep linked access with username mismatch
        !             3: #
        !             4: # $Id: lonlinkexit.pm,v 1.1 2022/06/29 22:40:00 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: 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;
        !            36: use Apache::lonlocal;
        !            37: use LONCAPA;
        !            38: use CGI::Cookie();
        !            39: 
        !            40: sub handler {
        !            41:     my $r = shift;
        !            42: 
        !            43:     my $handle = &Apache::lonnet::check_for_valid_session($r);
        !            44:     my ($exiturl,$deeplinktarget);
        !            45:     if ($handle ne '') {
        !            46:         my $lonidsdir=$r->dir_config('lonIDsDir');
        !            47:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
        !            48:         if ($env{'request.deeplink.login'}) {
        !            49:             if ($env{'request.deeplink.target'} ne '') {
        !            50:                 $deeplinktarget = $env{'request.deeplink.target'};
        !            51:             }
        !            52:             if ($env{'request.linkprotexit'} =~ m{^https?://}) {
        !            53:                 $exiturl = $env{'request.linkprotexit'};
        !            54:                 &js_escape(\$exiturl);
        !            55:             }
        !            56:         }
        !            57:         if (unlink("$lonidsdir/$handle.id")) {
        !            58:             if (($env{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
        !            59:                 (-l "$lonidsdir/$env{'user.linkedenv'}.id") &&
        !            60:                 (readlink("$lonidsdir/$env{'user.linkedenv'}.id") eq "$lonidsdir/$handle.id")) {
        !            61:                 unlink("$lonidsdir/$env{'user.linkedenv'}.id");
        !            62:             }
        !            63:         }
        !            64:         my %temp=('logout' => time);
        !            65:         my $ip = &Apache::lonnet::get_requestor_ip();
        !            66:         &Apache::lonnet::put('email_status',\%temp);
        !            67:         &Apache::lonnet::log($env{'user.domain'},
        !            68:                              $env{'user.name'},
        !            69:                              $env{'user.home'},
        !            70:                              "Logout $ip");
        !            71:         #expire the cookies
        !            72:         my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
        !            73:         foreach my $name (keys(%cookies)) {
        !            74:             next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
        !            75:             my $c = new CGI::Cookie(-name    => $name,
        !            76:                                     -value   => '',
        !            77:                                     -expires => '-10y',);
        !            78:             $r->headers_out->add('Set-cookie' => $c);
        !            79:         }
        !            80:     }
        !            81:     if (!$Apache::lonlocal::lh) {
        !            82:         &Apache::lonlocal::get_language_handle($r);
        !            83:     }
        !            84:     &Apache::loncommon::content_type($r,'text/html');
        !            85:     $r->send_http_header;
        !            86:     return OK if $r->header_only;
        !            87: 
        !            88:     my ($msg,$js);
        !            89:     $msg = '<p>'.&mt('Expired any existing session').'</p>';
        !            90:     my $args = {'only_body' => 1};
        !            91:     if ($exiturl) {
        !            92:         $js = <<ENDJS;
        !            93: <script type="text/javascript">
        !            94: // <![CDATA[
        !            95: \$(document).ready( function() {
        !            96:     setTimeout(function() {
        !            97:         if (window.self !== window.top) {
        !            98:             window.top.location.href = '$exiturl';
        !            99:         } else {
        !           100:             document.location.href = '$exiturl';
        !           101:         }
        !           102:     },100);
        !           103: });
        !           104: // ]]>
        !           105: </script>
        !           106: ENDJS
        !           107:         $msg .= '<p>'.&mt('Redirecting ...').'</p>';
        !           108:     }
        !           109: 
        !           110:     $r->print(&Apache::loncommon::start_page('Session removed',$js,{'only_body' => 1}));
        !           111:     $r->print($msg);
        !           112:     $r->print(&Apache::loncommon::end_page());
        !           113:     return OK;
        !           114: }
        !           115: 
        !           116: 1;

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