--- loncom/interface/lonexttool.pm 2018/01/31 14:17:44 1.18
+++ loncom/interface/lonexttool.pm 2023/06/02 01:20:26 1.25
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Launch External Tool Provider (LTI)
#
-# $Id: lonexttool.pm,v 1.18 2018/01/31 14:17:44 raeburn Exp $
+# $Id: lonexttool.pm,v 1.25 2023/06/02 01:20:26 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -96,13 +96,20 @@ sub handler {
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
my $chome = $env{'course.'.$env{'request.course.id'}.'.home'};
- my ($idx,$is_tool,%toolhash,%toolsettings);
+ my ($idx,$crstool,$is_tool,%toolhash,%toolsettings);
if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") {
%toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum);
if ($toolsettings{'id'}) {
- $idx = $toolsettings{'id'};
- my %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
+ my %ltitools;
+ if ($toolsettings{'id'} =~ /^c(\d+)$/) {
+ $idx = $1;
+ $crstool = 1;
+ %ltitools = &Apache::lonnet::get_course_lti($cnum,$cdom,'consumer');
+ } else {
+ $idx = $toolsettings{'id'};
+ %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer');
+ }
if (ref($ltitools{$idx}) eq 'HASH') {
%toolhash = %{$ltitools{$idx}};
$toolhash{'display'} = {
@@ -110,7 +117,7 @@ sub handler {
width => $toolsettings{'width'},
height => $toolsettings{'height'},
};
- foreach my $item (qw(crslabel crstitle crsappend gradable incdom)) {
+ foreach my $item (qw(crslabel crstitle crsappend gradable)) {
$toolhash{$item} = $toolsettings{$item};
}
$is_tool = 1;
@@ -204,17 +211,19 @@ sub handler {
}
}
my $submittext = &mt('Launch [_1]',$toolhash{'title'});
- if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') &&
- ($toolhash{'url'} ne '') && ($launchok)) {
+ if (($toolhash{'url'} ne '') && ($launchok)) {
my %lti = <i_params($r,$cnum,$cdom,$idx,$submittext,\%toolhash);
my $url = $toolhash{'url'};
if ($toolhash{'crsappend'} ne '') {
$url .= $toolhash{'crsappend'};
}
- $r->print(&launch_html($url,$toolhash{'key'},$toolhash{'secret'},
- $toolhash{'sigmethod'},$submittext,\%lti));
+ my %info = (
+ method => $toolhash{'sigmethod'},
+ );
+ $r->print(&launch_html($cdom,$cnum,$crstool,$url,$idx,
+ $toolhash{'cipher'},$submittext,\%lti,\%info));
} else {
- $r->print('
'.&mt('External Tool Unavailable').'
');
+ $r->print(''.&mt('External Tool Unavailable').'
');
}
}
return OK;
@@ -259,10 +268,10 @@ sub lti_params {
$msgtype = 'basic-lti-launch-request';
}
if ($crslabel eq '') {
- $crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'},
+ $crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'};
}
if ($crstitle eq '') {
- $crstitle = $env{'course.'.$env{'request.course.id'}.'.description'},;
+ $crstitle = $env{'course.'.$env{'request.course.id'}.'.description'};
}
my $lonhost = $r->dir_config('lonHostID');
my $loncaparev = $r->dir_config('lonVersion');
@@ -275,7 +284,7 @@ sub lti_params {
$ltirole = 'Learner';
}
my @possdigest;
- my $digest_user = &Encode::decode_utf8($uname.':'.$udom);
+ my $digest_user = &Encode::decode('UTF-8',$uname.':'.$udom);
$digest_user = &Digest::SHA::sha1_hex($digest_user);
push(@possdigest,$digest_user);
if ($env{'course.'.$env{'request.course.id'}.'.languages'} ne '') {
@@ -298,7 +307,7 @@ sub lti_params {
my ($title,$digest_symb);
my ($symb) = &Apache::lonnet::whichuser();
if ($symb) {
- $digest_symb = &Encode::decode_utf8($symb);
+ $digest_symb = &Encode::decode('UTF-8',$symb);
$digest_symb = &Digest::SHA::sha1_hex($digest_symb);
push(@possdigest,$digest_symb);
my $navmap = Apache::lonnavmaps::navmap->new();
@@ -312,7 +321,7 @@ sub lti_params {
my $domdesc = &Apache::lonnet::domain($cdom);
my $primary_id = &Apache::lonnet::domain($cdom,'primary');
my $int_dom = &Apache::lonnet::internet_dom($primary_id);
- my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom);
+ my $portal_url = &Apache::lonnet::course_portal_url($cnum,$cdom,$r);
my %ltiparams = (
lti_version => $version,
@@ -322,7 +331,7 @@ sub lti_params {
tool_consumer_instance_guid => $lonhost,
tool_consumer_instance_description => $domdesc,
tool_consumer_info_product_family_code => 'loncapa',
- tool_consumer_instance_name => $int_dom,
+ tool_consumer_instance_name => $int_dom,
tool_consumer_instance_url => $portal_url,
tool_consumer_info_version => $loncaparev,
user_id => $digest_user,
@@ -351,7 +360,7 @@ sub lti_params {
$ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'};
if ($gradesecret) {
my $uniqid = $digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'};
- $ltiparams{'lis_result_sourcedid'} = &LONCAPA::ltiutils::get_service_id($gradesecret,$uniqid);
+ $ltiparams{'lis_result_sourcedid'} = &LONCAPA::ltiutils::get_service_id($gradesecret,$uniqid);
}
}
if ($roster) {
@@ -427,15 +436,20 @@ sub lti_params {
}
}
foreach my $key (keys(%ltiparams)) {
- $ltiparams{$key} = &Encode::decode_utf8($ltiparams{$key});
+ $ltiparams{$key} = &Encode::decode('UTF-8',$ltiparams{$key});
}
$ltiparams{'basiclti_submit'} = $submittext;
return %ltiparams;
}
sub launch_html {
- my ($url,$key,$secret,$sigmethod,$submittext,$paramsref) = @_;
- my $hashref = &LONCAPA::ltiutils::sign_params($url,$key,$secret,$sigmethod,$paramsref);
+ my ($cdom,$cnum,$crstool,$url,$idx,$keynum,$submittext,$paramsref,$inforef) = @_;
+ my ($status,$hashref) =
+ &Apache::lonnet::sign_lti($cdom,$cnum,$crstool,'tools','launch',$url,$idx,$keynum,
+ $paramsref,$inforef);
+ unless ($status eq 'ok') {
+ return ''.&mt('External Tool Unavailable').'
';
+ }
my $action = &HTML::Entities::encode($url,'<>&"');
my $form = <<"END";