File:  [LON-CAPA] / loncom / auth / lonrelaunch.pm
Revision 1.2: download - view: text, annotated - select for diffs
Sun Jun 26 04:03:47 2022 UTC (23 months ago) by raeburn
Branches: MAIN
CVS tags: HEAD
- Bug 6907
  - Set request.linkprotuser in %env for students accessing deep-linked items
    with LTI link protection which includes username from other LMS.
  - Set "only_body" for intermediate pages shown while session is being set up
    for LTI link-protected access.
  - Provide appropriate feedback when a deep link is followed but the user
    only has a future and/or expired role in the target course.

    1: # The LearningOnline Network
    2: # Re-launch guidance for deep linked access with username mismatch
    3: #
    4: # $Id: lonrelaunch.pm,v 1.2 2022/06/26 04:03: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: 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'};
   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());
   97:             return OK;
   98:         }
   99:     }
  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:     }
  111:     $r->print(&Apache::loncommon::end_page());
  112:     if (exists($env{'form.rtoken'})) {
  113:         &Apache::lonnet::tmpdel($env{'form.rtoken'});       
  114:     }
  115:     return OK;
  116: }
  117: 
  118: 1;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>
500 Internal Server Error

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at root@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.