version 1.19, 2018/05/23 16:36:14
|
version 1.29, 2025/06/14 02:50:25
|
Line 96 sub handler {
|
Line 96 sub handler {
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
my $chome = $env{'course.'.$env{'request.course.id'}.'.home'}; |
my $chome = $env{'course.'.$env{'request.course.id'}.'.home'}; |
my ($idx,$is_tool,%toolhash,%toolsettings); |
my ($idx,$crstool,$is_tool,%toolhash,%toolsettings,$desturl,$delay); |
|
|
if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") { |
if ($r->uri eq "/adm/$cdom/$cnum/$marker/$exttool") { |
%toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); |
%toolsettings=&Apache::lonnet::dump('exttool_'.$marker,$cdom,$cnum); |
if ($toolsettings{'id'}) { |
if ($toolsettings{'id'}) { |
$idx = $toolsettings{'id'}; |
my %ltitools; |
my %ltitools = &Apache::lonnet::get_domain_lti($cdom,'consumer'); |
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') { |
if (ref($ltitools{$idx}) eq 'HASH') { |
%toolhash = %{$ltitools{$idx}}; |
%toolhash = %{$ltitools{$idx}}; |
$toolhash{'display'} = { |
$toolhash{'display'} = { |
Line 113 sub handler {
|
Line 120 sub handler {
|
foreach my $item (qw(crslabel crstitle crsappend gradable)) { |
foreach my $item (qw(crslabel crstitle crsappend gradable)) { |
$toolhash{$item} = $toolsettings{$item}; |
$toolhash{$item} = $toolsettings{$item}; |
} |
} |
|
if ($toolhash{'returnurl'}) { |
|
my $gotreturnurl; |
|
if (ref($toolhash{'crsconf'}) eq 'HASH') { |
|
if ($toolhash{'crsconf'}{'returnurl'}) { |
|
foreach my $item (qw(returnurl backtourl)) { |
|
$toolhash{$item} = $toolsettings{$item}; |
|
} |
|
$gotreturnurl = 1; |
|
} |
|
} |
|
unless ($gotreturnurl) { |
|
$toolhash{'returnurl'} = 'default'; |
|
} |
|
} else { |
|
$toolhash{'returnurl'} = 'none'; |
|
} |
|
if ($toolhash{'desturl'}) { |
|
if ((ref($toolhash{'crsconf'}) eq 'HASH')) { |
|
if ($toolhash{'crsconf'}{'desturl'}) { |
|
if ((exists($toolsettings{'desturl'})) && |
|
($toolsettings{'desturl'} =~ m{^(https?\://|/)})) { |
|
$desturl = $toolsettings{'desturl'}; |
|
if ((exists($toolsettings{'delay'})) && |
|
($toolsettings{'delay'} =~ /^\d+\.?\d*$/)) { |
|
$delay = $toolsettings{'delay'}; |
|
} |
|
} |
|
} elsif ($toolhash{'defdest'} =~ m{^(https?\://|/)}) { |
|
$desturl = $toolhash{'defdest'}; |
|
if ($toolhash{'defdelay'} =~ /^\d+\.?\d*$/) { |
|
$delay = $toolhash{'defdelay'}; |
|
} |
|
} |
|
} |
|
} |
$is_tool = 1; |
$is_tool = 1; |
} |
} |
} |
} |
Line 204 sub handler {
|
Line 246 sub handler {
|
} |
} |
} |
} |
my $submittext = &mt('Launch [_1]',$toolhash{'title'}); |
my $submittext = &mt('Launch [_1]',$toolhash{'title'}); |
if (($toolhash{'key'} ne '') && ($toolhash{'secret'} ne '') && |
if (($toolhash{'url'} ne '') && ($launchok)) { |
($toolhash{'url'} ne '') && ($launchok)) { |
my %lti = <i_params($r,$cnum,$cdom,$marker,$exttool,$idx,$submittext,\%toolhash); |
my %lti = <i_params($r,$cnum,$cdom,$idx,$submittext,\%toolhash); |
|
my $url = $toolhash{'url'}; |
my $url = $toolhash{'url'}; |
if ($toolhash{'crsappend'} ne '') { |
if ($toolhash{'crsappend'} ne '') { |
$url .= $toolhash{'crsappend'}; |
$url .= $toolhash{'crsappend'}; |
} |
} |
$r->print(&launch_html($url,$toolhash{'key'},$toolhash{'secret'}, |
if ($desturl ne '') { |
$toolhash{'sigmethod'},$submittext,\%lti)); |
my ($scheme,$provider,$path); |
|
if ($url =~ m{^https?\://}) { |
|
($scheme,$provider,$path) = ($url =~ m{^(https?\://)([^/]+)(|/.+)$}); |
|
if ($desturl =~ m{^/}) { |
|
if ($path eq $desturl) { |
|
undef($desturl); |
|
} else { |
|
$desturl = $scheme.$provider.$desturl; |
|
} |
|
} elsif ($desturl =~ m{^https?\://}) { |
|
if ($url eq $desturl) { |
|
undef($desturl); |
|
} |
|
} |
|
} elsif ($url eq $desturl) { |
|
undef($desturl); |
|
} |
|
} |
|
my %info = ( |
|
method => $toolhash{'sigmethod'}, |
|
); |
|
$r->print(&launch_html($cdom,$cnum,$crstool,$url,$idx, |
|
$toolhash{'cipher'},$submittext, |
|
\%lti,\%info,$desturl,$delay)); |
} else { |
} else { |
$r->print('<div>'.&mt('External Tool Unavailable').'</div>'); |
$r->print('<div class="LC_warning">'.&mt('External Tool Unavailable').'</div>'); |
} |
} |
} |
} |
return OK; |
return OK; |
} |
} |
|
|
sub lti_params { |
sub lti_params { |
my ($r,$cnum,$cdom,$idx,$submittext,$toolsref) = @_; |
my ($r,$cnum,$cdom,$marker,$exttool,$idx,$submittext,$toolsref) = @_; |
my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale, |
my ($version,$context_type,$msgtype,$toolname,$passback,$roster,$locale, |
$crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap, |
$crslabel,$crstitle,$gradesecret,$rostersecret,%fields,%rolesmap, |
%display,%custom,@userlangs,$incdom); |
%display,%custom,@userlangs,$incdom,$returnurl,$backtourl); |
if (ref($toolsref) eq 'HASH') { |
if (ref($toolsref) eq 'HASH') { |
$version = $toolsref->{'version'}; |
$version = $toolsref->{'version'}; |
$toolname = $toolsref->{'title'}; |
$toolname = $toolsref->{'title'}; |
Line 248 sub lti_params {
|
Line 312 sub lti_params {
|
} |
} |
$crslabel = $toolsref->{'crslabel'}; |
$crslabel = $toolsref->{'crslabel'}; |
$crstitle = $toolsref->{'crstitle'}; |
$crstitle = $toolsref->{'crstitle'}; |
|
$returnurl = $toolsref->{'returnurl'}; |
|
$backtourl = $toolsref->{'backtourl'}; |
} |
} |
if ($version eq '') { |
if ($version eq '') { |
$version = 'LTI-1p0'; |
$version = 'LTI-1p0'; |
Line 259 sub lti_params {
|
Line 325 sub lti_params {
|
$msgtype = 'basic-lti-launch-request'; |
$msgtype = 'basic-lti-launch-request'; |
} |
} |
if ($crslabel eq '') { |
if ($crslabel eq '') { |
$crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}, |
$crslabel = $env{'course.'.$env{'request.course.id'}.'.internal.coursecode'}; |
} |
} |
if ($crstitle eq '') { |
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 $lonhost = $r->dir_config('lonHostID'); |
my $loncaparev = $r->dir_config('lonVersion'); |
my $loncaparev = $r->dir_config('lonVersion'); |
Line 275 sub lti_params {
|
Line 341 sub lti_params {
|
$ltirole = 'Learner'; |
$ltirole = 'Learner'; |
} |
} |
my @possdigest; |
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); |
$digest_user = &Digest::SHA::sha1_hex($digest_user); |
push(@possdigest,$digest_user); |
push(@possdigest,$digest_user); |
if ($env{'course.'.$env{'request.course.id'}.'.languages'} ne '') { |
if ($env{'course.'.$env{'request.course.id'}.'.languages'} ne '') { |
Line 295 sub lti_params {
|
Line 361 sub lti_params {
|
if (scalar(@userlangs) == 1) { |
if (scalar(@userlangs) == 1) { |
$locale = $userlangs[0]; |
$locale = $userlangs[0]; |
} |
} |
my ($title,$digest_symb); |
my ($title,$digest_symb,$resource_link_id); |
my ($symb) = &Apache::lonnet::whichuser(); |
my $ignorecachednull = 1; |
|
my ($symb) = &Apache::lonnet::whichuser('',$ignorecachednull); |
|
my $uri = "/adm/$cdom/$cnum/$marker/$exttool"; |
if ($symb) { |
if ($symb) { |
$digest_symb = &Encode::decode_utf8($symb); |
$digest_symb = &Encode::decode('UTF-8',$symb); |
$digest_symb = &Digest::SHA::sha1_hex($digest_symb); |
$digest_symb = &Digest::SHA::sha1_hex($digest_symb); |
|
$resource_link_id = $digest_symb; |
push(@possdigest,$digest_symb); |
push(@possdigest,$digest_symb); |
my $navmap = Apache::lonnavmaps::navmap->new(); |
my $navmap = Apache::lonnavmaps::navmap->new(); |
if (ref($navmap)) { |
if (ref($navmap)) { |
Line 308 sub lti_params {
|
Line 377 sub lti_params {
|
$title = $res->compTitle(); |
$title = $res->compTitle(); |
} |
} |
} |
} |
|
} elsif ($env{'httpref.'.$uri} eq '/adm/coursedoc') { |
|
my $digest_suppurl = &Encode::decode('UTF-8',$uri); |
|
$digest_suppurl = &Digest::SHA::sha1_hex($digest_suppurl); |
|
$resource_link_id = $digest_suppurl; |
|
$title = &mt('Supplemental Content').': '.$marker.'_'.$exttool; |
|
} else { |
|
my $digest_url = &Encode::decode('UTF-8',$uri); |
|
$digest_url = &Digest::SHA::sha1_hex($digest_url); |
|
$resource_link_id = $digest_url; |
|
$title = &mt('External Tool').': '.$marker.'_'.$exttool; |
} |
} |
my $domdesc = &Apache::lonnet::domain($cdom); |
my $domdesc = &Apache::lonnet::domain($cdom); |
my $primary_id = &Apache::lonnet::domain($cdom,'primary'); |
my $primary_id = &Apache::lonnet::domain($cdom,'primary'); |
my $int_dom = &Apache::lonnet::internet_dom($primary_id); |
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 = ( |
my %ltiparams = ( |
lti_version => $version, |
lti_version => $version, |
lti_message_type => $msgtype, |
lti_message_type => $msgtype, |
resource_link_title => $title, |
resource_link_title => $title, |
resource_link_id => $digest_symb, |
resource_link_id => $resource_link_id, |
tool_consumer_instance_guid => $lonhost, |
tool_consumer_instance_guid => $lonhost, |
tool_consumer_instance_description => $domdesc, |
tool_consumer_instance_description => $domdesc, |
tool_consumer_info_product_family_code => 'loncapa', |
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_instance_url => $portal_url, |
tool_consumer_info_version => $loncaparev, |
tool_consumer_info_version => $loncaparev, |
user_id => $digest_user, |
user_id => $digest_user, |
Line 351 sub lti_params {
|
Line 430 sub lti_params {
|
$ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'}; |
$ltiparams{'ext_ims_lis_basic_outcome_url'} = $ltiparams{'lis_outcome_service_url'}; |
if ($gradesecret) { |
if ($gradesecret) { |
my $uniqid = $digest_symb.':::'.$digest_user.':::'.$env{'request.course.id'}; |
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) { |
if ($roster) { |
Line 427 sub lti_params {
|
Line 506 sub lti_params {
|
} |
} |
} |
} |
foreach my $key (keys(%ltiparams)) { |
foreach my $key (keys(%ltiparams)) { |
$ltiparams{$key} = &Encode::decode_utf8($ltiparams{$key}); |
$ltiparams{$key} = &Encode::decode('UTF-8',$ltiparams{$key}); |
} |
} |
$ltiparams{'basiclti_submit'} = $submittext; |
$ltiparams{'basiclti_submit'} = $submittext; |
|
if ($returnurl eq 'default') { |
|
my $hostname = &Apache::lonnet::hostname($r->dir_config('lonHostID')); |
|
my $protocol = 'http'; |
|
my $port = $r->get_server_port(); |
|
if ($port eq '443') { |
|
$protocol = 'https'; |
|
} |
|
if (&Apache::lonnet::get_proxy_alias()) { |
|
my $hdrhost = $r->headers_in->get('Host'); |
|
if ($hdrhost ne '') { |
|
$hostname = $r->headers_in->get('Host'); |
|
} |
|
} |
|
my $location = $protocol.'://'.$hostname; |
|
if ($display{'target'} eq 'iframe') { |
|
my $return_url; |
|
if ($symb) { |
|
my ($map,$id,$url)=&Apache::lonnet::decode_symb($symb); |
|
my $mapurl = &Apache::lonnet::clutter($map); |
|
my $mapsymb = &Apache::lonnet::symbread($map); |
|
if ((&Apache::lonnet::EXT('resource.0.encrypturl',$mapsymb) =~ /^yes$/i) && |
|
(!$env{'request.role.adv'})) { |
|
$return_url = &Apache::lonenc::encrypted($mapurl); |
|
} else { |
|
$return_url = $mapurl; |
|
} |
|
$return_url .= '?navmap=1'; |
|
} elsif ($env{'httpref.'.$uri} eq '/adm/coursedoc') { |
|
$return_url = '/adm/supplemental'; |
|
} else { |
|
$return_url = '/adm/navmaps'; |
|
} |
|
$ltiparams{'launch_presentation_return_url'} = $location.$return_url; |
|
} else { |
|
$uri = '/adm/wrapper'.$uri; |
|
if ($env{'request.enc'}) { |
|
$uri = &Apache::lonenc::encrypted($uri); |
|
} |
|
$ltiparams{'launch_presentation_return_url'} = $location.$uri; |
|
} |
|
} elsif ($returnurl eq 'custom') { |
|
if ($backtourl ne '') { |
|
$ltiparams{'launch_presentation_return_url'} = $backtourl; |
|
} |
|
} |
return %ltiparams; |
return %ltiparams; |
} |
} |
|
|
sub launch_html { |
sub launch_html { |
my ($url,$key,$secret,$sigmethod,$submittext,$paramsref) = @_; |
my ($cdom,$cnum,$crstool,$url,$idx,$keynum,$submittext,$paramsref, |
my $hashref = &LONCAPA::ltiutils::sign_params($url,$key,$secret,$sigmethod,$paramsref); |
$inforef,$desturl,$delay) = @_; |
my $action = &HTML::Entities::encode($url,'<>&"'); |
my ($status,$hashref) = |
my $form = <<"END"; |
&Apache::lonnet::sign_lti($cdom,$cnum,$crstool,'tools','launch',$url,$idx,$keynum, |
|
$paramsref,$inforef); |
|
unless ($status eq 'ok') { |
|
return '<div class="LC_warning">'.&mt('External Tool Unavailable').'</div>'; |
|
} |
|
my ($action,$js_html,$header,$title,$bodytag,$form,$divsty,$delay_in_ms); |
|
if ($delay ne '') { |
|
$delay_in_ms = int(1000 * $delay); |
|
} |
|
$action = &HTML::Entities::encode($url,'<>&"'); |
|
$title = &mt('Launcher'); |
|
$header = <<"END"; |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> |
|
END |
|
if ($desturl) { |
|
$divsty = 'none'; |
|
if ($delay_in_ms eq '') { |
|
$delay_in_ms = 1000; |
|
} |
|
$bodytag = <<"END"; |
|
<body onload="setTimeout(document.LCltiLaunchForm.submit(),$delay_in_ms);"> |
|
END |
|
} else { |
|
$divsty = 'block'; |
|
$bodytag = <<"END"; |
<body> |
<body> |
<div id="LCltiLaunch"> |
END |
|
} |
|
$form = <<"END"; |
|
<div id="LCltiLaunch" style="display:$divsty;"> |
<form name="LCltiLaunchForm" id="LCltiLaunchFormId" action="$action" method="post" encType="application/x-www-form-urlencoded"> |
<form name="LCltiLaunchForm" id="LCltiLaunchFormId" action="$action" method="post" encType="application/x-www-form-urlencoded"> |
END |
END |
if (ref($hashref) eq 'HASH') { |
if (ref($hashref) eq 'HASH') { |
foreach my $item (keys(%{$hashref})) { |
foreach my $item (keys(%{$hashref})) { |
my $type = 'hidden'; |
my $type = 'hidden'; |
if ($item eq 'basiclti_submit') { |
if ($item eq 'basiclti_submit') { |
$type = 'submit'; |
unless ($desturl) { |
|
$type = 'submit'; |
|
} |
} |
} |
$form .= '<input type="'.$type.'" name="'.$item.'" value="'.$hashref->{$item}.'" id="id_'.$item.'" />'."\n"; |
$form .= '<input type="'.$type.'" name="'.$item.'" value="'.$hashref->{$item}.'" id="id_'.$item.'" />'."\n"; |
} |
} |
} |
} |
$form .= "</form></div>\n"; |
$form .= "</form></div>\n"; |
$form .= <<"ENDJS"; |
my $footer = <<"END"; |
|
</body> |
|
</html> |
|
END |
|
if ($desturl) { |
|
$js_html = $header.$bodytag.$form.$footer; |
|
&js_escape(\$js_html); |
|
&js_escape(\$desturl); |
|
return <<"END"; |
|
$header |
|
<head> |
|
<title>$title</title> |
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> |
|
<meta name="google" content="notranslate" /> |
|
</head> |
|
<body onload="javascript:addcontent();"> |
|
<iframe id="LC_launcher_iframe" style="position: absolute; width:0; height:0; border:0;"> |
|
</iframe> |
|
<script type="text/javascript"> |
|
// <![CDATA[ |
|
function addcontent() { |
|
if (document.getElementById('LC_launcher_iframe')) { |
|
document.getElementById('LC_launcher_iframe').src = "data:text/html;charset=utf-8," + escape("$js_html"); |
|
} |
|
setTimeout(() => { |
|
document.location.href="$desturl"; |
|
}, $delay_in_ms); |
|
} |
|
// ]]> |
|
</script> |
|
$footer |
|
END |
|
} else { |
|
return <<"END"; |
|
$header |
|
$bodytag |
|
$form |
<script type="text/javascript"> |
<script type="text/javascript"> |
|
// <![CDATA[ |
document.getElementById("LCltiLaunch").style.display = "none"; |
document.getElementById("LCltiLaunch").style.display = "none"; |
nei = document.createElement('input'); |
nei = document.createElement('input'); |
nei.setAttribute('type','hidden'); |
nei.setAttribute('type','hidden'); |
Line 463 END
|
Line 652 END
|
nei.setAttribute('value','$submittext'); |
nei.setAttribute('value','$submittext'); |
document.getElementById("LCltiLaunchFormId").appendChild(nei); |
document.getElementById("LCltiLaunchFormId").appendChild(nei); |
document.LCltiLaunchForm.submit(); |
document.LCltiLaunchForm.submit(); |
</script> |
// ]]> |
ENDJS |
</script> |
$form .= "</body></html>\n"; |
$footer |
return $form; |
END |
|
} |
} |
} |
|
|
sub gradabletool_access_check { |
sub gradabletool_access_check { |