--- loncom/lonnet/perl/lonnet.pm 2023/04/05 18:09:52 1.1507 +++ loncom/lonnet/perl/lonnet.pm 2023/06/02 01:20:29 1.1511 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1507 2023/04/05 18:09:52 raeburn Exp $ +# $Id: lonnet.pm,v 1.1511 2023/06/02 01:20:29 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -415,6 +415,63 @@ sub remote_devalidate_cache { return $response; } +sub sign_lti { + my ($cdom,$cnum,$crsdef,$type,$context,$url,$ltinum,$keynum,$paramsref,$inforef) = @_; + my $chome; + if (&domain($cdom) ne '') { + if ($crsdef) { + $chome = &homeserver($cnum,$cdom); + } else { + $chome = &domain($cdom,'primary'); + } + } + if ($cdom && $chome && ($chome ne 'no_host')) { + if ((ref($paramsref) eq 'HASH') && + (ref($inforef) eq 'HASH')) { + my $rep; + if (grep { $_ eq $chome } ¤t_machine_ids()) { + # domain information is hosted on this machine + $rep = + &LONCAPA::Lond::sign_lti_payload($cdom,$cnum,$crsdef,$type, + $context,$url,$ltinum,$keynum, + $perlvar{'lonVersion'}, + $paramsref,$inforef); + if (ref($rep) eq 'HASH') { + return ('ok',$rep); + } + } else { + my ($escurl,$params,$info); + $escurl = &escape($url); + if (ref($paramsref) eq 'HASH') { + $params = &freeze_escape($paramsref); + } + if (ref($inforef) eq 'HASH') { + $info = &freeze_escape($inforef); + } + $rep=&reply("encrypt:signlti:$cdom:$cnum:$crsdef:$type:$context:$escurl:$ltinum:$keynum:$params:$info",$chome); + } + if (($rep eq '') || ($rep =~ /^con_lost|error|no_such_host|unknown_cmd/i)) { + return (); + } elsif (($inforef->{'respfmt'} eq 'to_post_body') || + ($inforef->{'respfmt'} eq 'to_authorization_header')) { + return ('ok',$rep); + } else { + my %returnhash; + foreach my $item (split(/\&/,$rep)) { + my ($name,$value)=split(/\=/,$item); + $returnhash{&unescape($name)}=&thaw_unescape($value); + } + return('ok',\%returnhash); + } + } else { + return (); + } + } else { + return (); + &logthis("sign_lti failed - no homeserver and/or domain ($cdom) ($chome)"); + } +} + # -------------------------------------------------- Non-critical communication sub subreply { my ($cmd,$server)=@_; @@ -2699,7 +2756,8 @@ sub get_domain_defaults { 'requestauthor','selfenrollment', 'coursecategories','ssl','autoenroll', 'trust','helpsettings','wafproxy', - 'ltisec','toolsec'],$domain); + 'ltisec','toolsec','domexttool', + 'exttool'],$domain); my @coursetypes = ('official','unofficial','community','textbook','placement'); if (ref($domconfig{'defaults'}) eq 'HASH') { $domdefaults{'lang_def'} = $domconfig{'defaults'}{'lang_def'}; @@ -2771,6 +2829,16 @@ sub get_domain_defaults { $domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$type}; } } + if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') { + $domdefaults{$type.'domexttool'} = $domconfig{'coursedefaults'}{'domexttool'}{$type}; + } else { + $domdefaults{$type.'domexttool'} = 1; + } + if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') { + $domdefaults{$type.'exttool'} = $domconfig{'coursedefaults'}{'exttool'}{$type}; + } else { + $domdefaults{$type.'exttool'} = 0; + } } if (ref($domconfig{'coursedefaults'}{'canclone'}) eq 'HASH') { if (ref($domconfig{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') { @@ -5145,7 +5213,7 @@ sub flushcourselogs { # Typo in rev. 1.458 (2003/12/09)?? # These should likely by $env{'course.'.$cid.'.domain'} and $env{'course.'.$cid.'.num'} # -# While these ramain as $env{'request.'.$cid.'.domain'} and $env{'request.'.$cid.'.num'} +# While these remain as $env{'request.'.$cid.'.domain'} and $env{'request.'.$cid.'.num'} # $dom and $name will always be null, so the &inc() call will default to storing this data # in a nohist_accesscount.db file for the user rather than the course. # @@ -12485,13 +12553,11 @@ sub get_domain_lti { } else { return %lti; } - if ($context eq 'linkprot') { $cachename = $context; } else { $cachename = $name; } - my ($result,$cached)=&is_cached_new($cachename,$cdom); if (defined($cached)) { if (ref($result) eq 'HASH') { @@ -12507,18 +12573,6 @@ sub get_domain_lti { } else { %lti = %{$domconfig{$name}}; } - if (($context eq 'consumer') && (keys(%lti))) { - my %encdomconfig = &get_dom('encconfig',[$name],$cdom,undef,1); - if (ref($encdomconfig{$name}) eq 'HASH') { - foreach my $id (keys(%lti)) { - if (ref($encdomconfig{$name}{$id}) eq 'HASH') { - foreach my $item ('key','secret') { - $lti{$id}{$item} = $encdomconfig{$name}{$id}{$item}; - } - } - } - } - } } my $cachetime = 24*60*60; &do_cache_new($cachename,$cdom,\%lti,$cachetime); @@ -12527,20 +12581,29 @@ sub get_domain_lti { } sub get_course_lti { - my ($cnum,$cdom) = @_; + my ($cnum,$cdom,$context) = @_; + my ($name,$cachename,%lti); + if ($context eq 'consumer') { + $name = 'ltitools'; + $cachename = 'courseltitools'; + } elsif ($context eq 'provider') { + $name = 'lti'; + $cachename = 'courselti'; + } else { + return %lti; + } my $hashid=$cdom.'_'.$cnum; - my %courselti; - my ($result,$cached)=&is_cached_new('courselti',$hashid); + my ($result,$cached)=&is_cached_new($cachename,$hashid); if (defined($cached)) { if (ref($result) eq 'HASH') { - %courselti = %{$result}; + %lti = %{$result}; } } else { - %courselti = &dump('lti',$cdom,$cnum,undef,undef,undef,1); + %lti = &dump($name,$cdom,$cnum,undef,undef,undef,1); my $cachetime = 24*60*60; - &do_cache_new('courselti',$hashid,\%courselti,$cachetime); + &do_cache_new($cachename,$hashid,\%lti,$cachetime); } - return %courselti; + return %lti; } sub courselti_itemid {