Annotation of loncom/auth/lonrelaunch.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: lonrelaunch.pm,v 1.1 2022/06/18 02:10:18 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::lonrelaunch;
                     30: 
                     31: use strict;
                     32: use lib '/home/httpd/lib/perl/';
                     33: use Apache::Constants qw(:common :http REDIRECT);
                     34: use Apache::lonnet;
                     35: use Apache::loncommon();
                     36: use Apache::lonlocal;
                     37: use LONCAPA qw(:DEFAULT :match);
                     38: use CGI::Cookie();
                     39: 
                     40: sub handler {
                     41:     my $r = shift;
                     42: 
                     43:     my %data;
                     44:     if ($r->args) {
                     45:         &Apache::loncommon::get_unprocessed_cgi($r->args,['rtoken']);
                     46:         if (exists($env{'form.rtoken'})) {
                     47:             %data = &Apache::lonnet::tmpget($env{'form.rtoken'});
                     48:         }
                     49:     }
                     50:     my $handle = &Apache::lonnet::check_for_valid_session($r);
                     51:     if ($handle ne '') {
                     52:         my $lonidsdir=$r->dir_config('lonIDsDir');
                     53:         &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
                     54:         if (unlink("$lonidsdir/$handle.id")) {
                     55:             if (($env{'user.linkedenv'} =~ /^[a-f0-9]+_linked$/) &&
                     56:                 (-l "$lonidsdir/$env{'user.linkedenv'}.id") &&
                     57:                 (readlink("$lonidsdir/$env{'user.linkedenv'}.id") eq "$lonidsdir/$handle.id")) {
                     58:                 unlink("$lonidsdir/$env{'user.linkedenv'}.id");
                     59:             }
                     60:         }
                     61:         my %temp=('logout' => time);
                     62:         my $ip = &Apache::lonnet::get_requestor_ip();
                     63:         &Apache::lonnet::put('email_status',\%temp);
                     64:         &Apache::lonnet::log($env{'user.domain'},
                     65:                              $env{'user.name'},
                     66:                              $env{'user.home'},
                     67:                              "Logout $ip");
                     68:         #expire the cookies
                     69:         my %cookies=CGI::Cookie->parse($r->header_in('Cookie'));
                     70:         foreach my $name (keys(%cookies)) {
                     71:             next unless ($name =~ /^lon(|S|Link|Pub)ID$/);
                     72:             my $c = new CGI::Cookie(-name    => $name,
                     73:                                     -value   => '',
                     74:                                     -expires => '-10y',);
                     75:             $r->headers_out->add('Set-cookie' => $c);
                     76:         }
                     77:     }
                     78:     if (!$Apache::lonlocal::lh) {
                     79:         &Apache::lonlocal::get_language_handle($r);
                     80:     }
                     81:     &Apache::loncommon::content_type($r,'text/html');
                     82:     $r->send_http_header;
                     83:     return OK if $r->header_only;
                     84: 
                     85:     if ((keys(%data)) && ($data{'origurl'} =~ m{^/tiny/$match_domain/\w+$})) {
                     86:         my $url = $data{'origurl'};
1.2     ! raeburn    87:         if ($data{'linkprot'} =~ m{^\w+(c|d):\Q$url\E$}) {
        !            88:             if ((!exists($data{'linkprotuser'})) ||
        !            89:                 (($data{'linkprotuser'}) &&
        !            90:                  ($data{'linkprotuser'} =~ m{^($match_username):($match_domain)$}))) {
        !            91:                 $url .= '?ltoken='.$env{'form.rtoken'};
        !            92:                 $r->print(&Apache::loncommon::start_page('Updating session',undef,
        !            93:                                                          {'only_body'    => 1,
        !            94:                                                           'redirect'     => [1,$url]}).
        !            95:                           '<p>'.&mt('Updating old session information').'</p>'.
        !            96:                           &Apache::loncommon::end_page());
1.1       raeburn    97:             return OK;
                     98:         }
                     99:     }
1.2     ! raeburn   100:     if ($data{'linkprot'}) {
        !           101:         $r->print(&Apache::loncommon::start_page('Updating session',undef,{'only_body' => 1}));
        !           102:         if ($data{'linkprotuser'} ne '') {
        !           103:             $r->print(&mt('Although your credentials were authenticated, the username you entered did not match what was expected [_1] from the link you followed',"($data{'linkprotuser'})"));
        !           104:         } else {
        !           105:             $r->print(&mt('Expired any existing session'));
        !           106:         }
        !           107:     } else {
        !           108:         $r->print(&Apache::loncommon::start_page('Session removed',undef,{'only_body' => 1}));
        !           109:         $r->print(&mt('Expired any existing session'));
        !           110:     }
1.1       raeburn   111:     $r->print(&Apache::loncommon::end_page());
1.2     ! raeburn   112:     if (exists($env{'form.rtoken'})) {
        !           113:         &Apache::lonnet::tmpdel($env{'form.rtoken'});       
        !           114:     }
1.1       raeburn   115:     return OK;
                    116: }
                    117: 
                    118: 1;

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