Diff for /loncom/lti/ltiauth.pm between versions 1.34 and 1.37

version 1.34, 2022/02/17 22:35:51 version 1.37, 2022/06/18 02:10:19
Line 30  package Apache::ltiauth; Line 30  package Apache::ltiauth;
   
 use strict;  use strict;
 use LONCAPA qw(:DEFAULT :match);  use LONCAPA qw(:DEFAULT :match);
 use Apache::Constants qw(:common :http);  use Encode;
   use Apache::Constants qw(:common :http :remotehost);
 use Apache::lonlocal;  use Apache::lonlocal;
 use Apache::lonnet;  use Apache::lonnet;
 use Apache::loncommon;  use Apache::loncommon;
Line 63  sub handler { Line 64  sub handler {
     my $params = {};      my $params = {};
     foreach my $key (sort(keys(%env))) {      foreach my $key (sort(keys(%env))) {
         if ($key =~ /^form\.(.+)$/) {          if ($key =~ /^form\.(.+)$/) {
             $params->{$1} = $env{$key};              $params->{$1} = &Encode::decode('UTF-8',$env{$key});
         }          }
     }      }
 #  #
Line 116  sub handler { Line 117  sub handler {
 #  #
     if ($requri =~ m{^/adm/launch(|/.*)$}) {      if ($requri =~ m{^/adm/launch(|/.*)$}) {
         my $tail = $1;          my $tail = $1;
         if ($tail =~ m{^/tiny/($match_domain)/(\w+)$}) {          if ($tail =~ m{^/tiny/$match_domain/\w+$}) {
             my ($urlcdom,$urlcnum) = &course_from_tinyurl($tail);              my ($urlcdom,$urlcnum) = &course_from_tinyurl($tail);
             if (($urlcdom ne '') && ($urlcnum ne '')) {              if (($urlcdom ne '') && ($urlcnum ne '')) {
                 $cdom = $urlcdom;                  $cdom = $urlcdom;
Line 142  sub handler { Line 143  sub handler {
 # where url was /adm/launch/tiny/$cdom/$uniqueid  # where url was /adm/launch/tiny/$cdom/$uniqueid
 #  #
   
                         my ($itemid,$ltitype,%crslti,%lti_in_use);                          my ($itemid,$ltitype,%crslti,%lti_in_use,$ltiuser);
                         $itemid = &get_lti_itemid($requri,$hostname,$params,$cdom,$cnum,'linkprot');                          $itemid = &get_lti_itemid($requri,$hostname,$params,$cdom,$cnum,'linkprot');
                         if ($itemid) {                          if ($itemid) {
                             %crslti = &Apache::lonnet::get_course_lti($cnum,$cdom);                              %crslti = &Apache::lonnet::get_course_lti($cnum,$cdom);
Line 228  sub handler { Line 229  sub handler {
                                                 return OK;                                                  return OK;
                                             }                                              }
                                         }                                          }
                                           $ltiuser = $uname.':'.$cdom;
                                     }                                      }
                                 }                                  }
                                 if ($lti_in_use{'notstudent'} eq 'reject') {                                  if ($lti_in_use{'notstudent'} eq 'reject') {
                                     &invalid_request($r,'Information for valid user missing from launch request');                                      &invalid_request($r,'Information for valid user missing from launch request');
                                       return OK;
                                 }                                  }
                             }                              }
                         }                          }
Line 239  sub handler { Line 242  sub handler {
                             foreach my $key (%{$params}) {                              foreach my $key (%{$params}) {
                                 delete($env{'form.'.$key});                                  delete($env{'form.'.$key});
                             }                              }
                             my $ltoken = &Apache::lonnet::tmpput({'linkprot' => $itemid.$ltitype.':'.$tail},                              my %info = (
                                                                  $lonhost,'link');                                            'linkprot' => $itemid.$ltitype.':'.$tail,
                             if ($ltoken) {                                         );
                               if ($ltiuser ne '') {
                                   $info{'linkprotuser'} = $ltiuser;
                               }
                               my $ltoken = &Apache::lonnet::tmpput(\%info,$lonhost,'link');
                               if (($ltoken eq 'con_lost') || ($ltoken eq 'refused') || ($ltoken =~ /^error:/) ||
                                   ($ltoken eq 'unknown_cmd') || ($ltoken eq 'no_such_host') ||
                                   ($ltoken eq '')) {
                                   &invalid_request($r,'Failed to store information from launch request');
                               } else {
                                 $r->internal_redirect($tail.'?ltoken='.$ltoken);                                  $r->internal_redirect($tail.'?ltoken='.$ltoken);
                                 $r->set_handlers('PerlHandler'=> undef);                                  $r->set_handlers('PerlHandler'=> undef);
                             } else {  
                                 &invalid_request($r,'Failed to store information from launch request');  
                             }                              }
                         } else {                          } else {
                             &invalid_request($r,'Launch request could not be validated');                              &invalid_request($r,'Launch request could not be validated');
Line 984  sub lti_session { Line 994  sub lti_session {
                                                       $r->dir_config('ltiIDsDir'),                                                        $r->dir_config('ltiIDsDir'),
                                                       $protocol,$r->hostname);                                                        $protocol,$r->hostname);
         }          }
         my $ip = $r->get_remote_host();          my $ip = &Apache::lonnet::get_requestor_ip($r,REMOTE_NOLOOKUP);
         my %info=('ip'        => $ip,          my %info=('ip'        => $ip,
                   'domain'    => $udom,                    'domain'    => $udom,
                   'username'  => $uname,                    'username'  => $uname,
Line 1073  sub linkprot_session { Line 1083  sub linkprot_session {
         $r->set_handlers('PerlHandler'=> undef);          $r->set_handlers('PerlHandler'=> undef);
     } else {      } else {
         # need to login them in, so generate the data migrate expects to do login          # need to login them in, so generate the data migrate expects to do login
         my $ip = $r->get_remote_host();          my $ip = &Apache::lonnet::get_requestor_ip($r,REMOTE_NOLOOKUP);
         my %info=('ip'             => $ip,          my %info=('ip'             => $ip,
                   'domain'         => $cdom,                    'domain'         => $cdom,
                   'username'       => $uname,                    'username'       => $uname,
Line 1127  sub invalid_request { Line 1137  sub invalid_request {
         '<h3>'.&mt('Invalid LTI launch request').'</h3>'.          '<h3>'.&mt('Invalid LTI launch request').'</h3>'.
         '<p class="LC_warning">'.          '<p class="LC_warning">'.
         &mt('Launch of LON-CAPA is unavailable from the "external tool" link you had followed in another web application.').          &mt('Launch of LON-CAPA is unavailable from the "external tool" link you had followed in another web application.').
         &mt('Launch failed for the following reason:').          ' '.&mt('Launch failed for the following reason:').
         '</p>'.          '</p>'.
         '<p class="LC_error">'.$msg.'</p>'.          '<p class="LC_error">'.$msg.'</p>'.
         &Apache::loncommon::end_page());          &Apache::loncommon::end_page());

Removed from v.1.34  
changed lines
  Added in v.1.37


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