--- loncom/lonnet/perl/lonnet.pm 2022/02/27 02:19:13 1.1172.2.147 +++ loncom/lonnet/perl/lonnet.pm 2023/05/22 21:10:55 1.1510 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1172.2.147 2022/02/27 02:19:13 raeburn Exp $ +# $Id: lonnet.pm,v 1.1510 2023/05/22 21:10:55 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -71,11 +71,12 @@ delayed. package Apache::lonnet; use strict; -use LWP::UserAgent(); use HTTP::Date; use Image::Magick; use CGI::Cookie; +use Encode; + use vars qw(%perlvar %spareid %pr %prp $memcache %packagetab $tmpdir $deftex $_64bit %env %protocol %loncaparevs %serverhomeIDs %needsrelease %managerstab $passwdmin); @@ -101,6 +102,7 @@ use LONCAPA qw(:DEFAULT :match); use LONCAPA::Configuration; use LONCAPA::lonmetadata; use LONCAPA::Lond; +use LONCAPA::LWPReq; use LONCAPA::transliterate; use File::Copy; @@ -113,6 +115,7 @@ require Exporter; our @ISA = qw (Exporter); our @EXPORT = qw(%env); + # ------------------------------------ Logging (parameters, docs, slots, roles) { my $logid; @@ -127,20 +130,20 @@ our @EXPORT = qw(%env); $logid ++; my $now = time(); my $id=$now.'00000'.$$.'00000'.$logid; - my $ip = &get_requestor_ip(); - my $logentry = { - $id => { - 'exe_uname' => $env{'user.name'}, - 'exe_udom' => $env{'user.domain'}, - 'exe_time' => $now, - 'exe_ip' => $ip, - 'delflag' => $delflag, - 'logentry' => $storehash, - 'uname' => $uname, - 'udom' => $udom, - } + my $ip = &get_requestor_ip(); + my $logentry = { + $id => { + 'exe_uname' => $env{'user.name'}, + 'exe_udom' => $env{'user.domain'}, + 'exe_time' => $now, + 'exe_ip' => $ip, + 'delflag' => $delflag, + 'logentry' => $storehash, + 'uname' => $uname, + 'udom' => $udom, + } }; - return &put('nohist_'.$hash_name,$logentry,$cdom,$cnum); + return &put('nohist_'.$hash_name,$logentry,$cdom,$cnum); } } @@ -185,7 +188,7 @@ sub create_connection { Type => SOCK_STREAM, Timeout => 10); return 0 if (!$client); - print $client (join(':',$hostname,$lonid,&machine_ids($hostname))."\n"); + print $client (join(':',$hostname,$lonid,&machine_ids($hostname),$loncaparevs{$lonid})."\n"); my $result = <$client>; chomp($result); return 1 if ($result eq 'done'); @@ -230,6 +233,54 @@ sub get_server_distarch { return; } +sub get_servercerts_info { + my ($lonhost,$hostname,$context) = @_; + return if ($lonhost eq ''); + if ($hostname eq '') { + $hostname = &hostname($lonhost); + } + return if ($hostname eq ''); + my ($rep,$uselocal); + if ($context eq 'install') { + $uselocal = 1; + } elsif (grep { $_ eq $lonhost } ¤t_machine_ids()) { + $uselocal = 1; + } + if (($context ne 'cgi') && ($context ne 'install') && ($uselocal)) { + my $distro = (split(/\:/,&get_server_distarch($lonhost)))[0]; + if ($distro eq '') { + $uselocal = 0; + } elsif ($distro =~ /^(?:centos|redhat|scientific)(\d+)$/) { + if ($1 < 6) { + $uselocal = 0; + } + } elsif ($distro =~ /^(?:sles)(\d+)$/) { + if ($1 < 12) { + $uselocal = 0; + } + } + } + if ($uselocal) { + $rep = LONCAPA::Lond::server_certs(\%perlvar,$lonhost,$hostname); + } else { + $rep=&reply('servercerts',$lonhost); + } + my ($result,%returnhash); + if (($rep=~/^(refused|rejected|error)/) || ($rep eq 'con_lost') || + ($rep eq 'unknown_cmd')) { + $result = $rep; + } else { + $result = 'ok'; + my @pairs=split(/\&/,$rep); + foreach my $item (@pairs) { + my ($key,$value)=split(/=/,$item,2); + my $what = &unescape($key); + $returnhash{$what}=&thaw_unescape($value); + } + } + return ($result,\%returnhash); +} + sub get_server_loncaparev { my ($dom,$lonhost,$ignore_cache,$caller) = @_; if (defined($lonhost)) { @@ -264,14 +315,12 @@ sub get_server_loncaparev { $answer = &reply('serverloncaparev',$lonhost); if (($answer eq 'unknown_cmd') || ($answer eq 'con_lost')) { if ($caller eq 'loncron') { - my $ua=new LWP::UserAgent; - $ua->timeout(4); my $hostname = &hostname($lonhost); my $protocol = $protocol{$lonhost}; $protocol = 'http' if ($protocol ne 'https'); my $url = $protocol.'://'.$hostname.'/adm/about.html'; my $request=new HTTP::Request('GET',$url); - my $response=$ua->request($request); + my $response=&LONCAPA::LWPReq::makerequest($lonhost,$request,'',\%perlvar,4,1); unless ($response->is_error()) { my $content = $response->content; if ($content =~ /
VERSION\:\s*([\w.\-]+)<\/p>/) {
@@ -362,7 +411,62 @@ sub remote_devalidate_cache {
my $items;
return unless (ref($cachekeys) eq 'ARRAY');
my $cachestr = join('&',@{$cachekeys});
- return &reply('devalidatecache:'.&escape($cachestr),$lonhost);
+ my $response = &reply('devalidatecache:'.&escape($cachestr),$lonhost);
+ return $response;
+}
+
+sub sign_lti {
+ my ($cdom,$cnum,$crstool,$url,$idx,$keynum,$post,$paramsref,$inforef) = @_;
+ my $chome;
+ if (&domain($cdom) ne '') {
+ if ($crstool) {
+ $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_params($cdom,$cnum,$crstool,$url,
+ $idx,$keynum,$post,
+ $perlvar{'lonVersion'},
+ $paramsref,$inforef);
+ if ($rep ne '') {
+ 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:$crstool:$escurl:$idx:$keynum:$post:$params:$info",$chome);
+ }
+ if (($rep eq '') || ($rep =~ /^con_lost|error|no_such_host|unknown_cmd/i)) {
+ return ();
+ } 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
@@ -394,7 +498,7 @@ sub subreply {
} else {
&create_connection(&hostname($server),$server);
}
- sleep(0.1); # Try again later if failed connection.
+ sleep(0.1); # Try again later if failed connection.
}
my $answer;
if ($client) {
@@ -418,14 +522,15 @@ sub reply {
my $subcmd = $1;
if (($subcmd eq 'auth') || ($subcmd eq 'passwd') ||
($subcmd eq 'changeuserauth') || ($subcmd eq 'makeuser') ||
- ($subcmd eq 'putdom') || ($subcmd eq 'autoexportgrades')) {
+ ($subcmd eq 'putdom') || ($subcmd eq 'autoexportgrades') ||
+ ($subcmd eq 'put')) {
(undef,undef,my @rest) = split(/:/,$cmd);
if (($subcmd eq 'auth') || ($subcmd eq 'putdom')) {
splice(@rest,2,1,'Hidden');
} elsif ($subcmd eq 'passwd') {
splice(@rest,2,2,('Hidden','Hidden'));
} elsif (($subcmd eq 'changeuserauth') || ($subcmd eq 'makeuser') ||
- ($subcmd eq 'autoexportgrades')) {
+ ($subcmd eq 'autoexportgrades') || ($subcmd eq 'put')) {
splice(@rest,3,1,'Hidden');
}
$logged = join(':',('encrypt:'.$subcmd,@rest));
@@ -467,7 +572,7 @@ sub reconlonc {
&logthis("lonc at pid $loncpid responding, sending USR1");
kill USR1 => $loncpid;
sleep 1;
- } else {
+ } else {
&logthis(
"WARNING:".
" lonc at pid $loncpid not responding, giving up");
@@ -662,7 +767,7 @@ sub check_for_valid_session {
}
}
if (!-e "$lonidsdir/$handle.id") {
- if ((ref($domref)) && ($name eq 'lonID') &&
+ if ((ref($domref)) && ($name eq 'lonID') &&
($handle =~ /^($match_username)\_\d+\_($match_domain)\_(.+)$/)) {
my ($possuname,$possudom,$possuhome) = ($1,$2,$3);
if ((&domain($possudom) ne '') && (&homeserver($possuname,$possudom) eq $possuhome)) {
@@ -694,6 +799,11 @@ sub check_for_valid_session {
if ($disk_env{'request.role'}) {
$userhashref->{'role'} = $disk_env{'request.role'};
}
+ $userhashref->{'lti'} = $disk_env{'request.lti.login'};
+ if ($userhashref->{'lti'}) {
+ $userhashref->{'ltitarget'} = $disk_env{'request.lti.target'};
+ $userhashref->{'ltiuri'} = $disk_env{'request.lti.uri'};
+ }
}
untie(%disk_env);
@@ -929,9 +1039,9 @@ sub spareserver {
: $userloadpercent;
my ($uint_dom,$remotesessions);
if (($udom ne '') && (&domain($udom) ne '')) {
- my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
- $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
- my %udomdefaults = &Apache::lonnet::get_domain_defaults($udom);
+ my $uprimary_id = &domain($udom,'primary');
+ $uint_dom = &internet_dom($uprimary_id);
+ my %udomdefaults = &get_domain_defaults($udom);
$remotesessions = $udomdefaults{'remotesessions'};
}
my $spareshash = &this_host_spares($udom);
@@ -967,7 +1077,7 @@ sub spareserver {
if ($protocol{$spare_server} eq 'https') {
$protocol = $protocol{$spare_server};
}
- my $alias = &Apache::lonnet::use_proxy_alias($r,$spare_server);
+ my $alias = &use_proxy_alias($r,$spare_server);
$hostname = $alias if ($alias ne '');
$spare_server = $protocol.'://'.$hostname;
}
@@ -1035,6 +1145,19 @@ sub find_existing_session {
return;
}
+sub delusersession {
+ my ($lonid,$udom,$uname) = @_;
+ my $uprimary_id = &domain($udom,'primary');
+ my $uintdom = &internet_dom($uprimary_id);
+ my $intdom = &internet_dom($lonid);
+ my $serverhomedom = &host_domain($lonid);
+ if (($uintdom ne '') && ($uintdom eq $intdom)) {
+ return &reply(join(':','delusersession',
+ map {&escape($_)} ($udom,$uname)),$lonid);
+ }
+ return;
+}
+
# check if user's browser sent load balancer cookie and server still has session
# and is not overloaded.
sub check_for_balancer_cookie {
@@ -1142,7 +1265,7 @@ sub choose_server {
unless (defined($cached)) {
my $cachetime = 60*60*24;
my %domconfig =
- &Apache::lonnet::get_dom('configuration',['loadbalancing'],$udom);
+ &get_dom('configuration',['loadbalancing'],$udom);
if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
$balancers = &do_cache_new('loadbalancing',$udom,$domconfig{'loadbalancing'},
$cachetime);
@@ -1150,12 +1273,12 @@ sub choose_server {
}
}
foreach my $lonhost (keys(%servers)) {
- my $loginvia;
if ($skiploadbal) {
if (ref($balancers) eq 'HASH') {
next if (exists($balancers->{$lonhost}));
}
}
+ my $loginvia;
if ($checkloginvia) {
$loginvia = $domconfhash{$udom.'.login.loginvia_'.$lonhost};
if ($loginvia) {
@@ -1309,10 +1432,33 @@ sub authenticate {
return 'no_host';
}
+sub can_switchserver {
+ my ($udom,$home) = @_;
+ my ($canswitch,@intdoms);
+ my $internet_names = &get_internet_names($home);
+ if (ref($internet_names) eq 'ARRAY') {
+ @intdoms = @{$internet_names};
+ }
+ my $uint_dom = &internet_dom(&domain($udom,'primary'));
+ if ($uint_dom ne '' && grep(/^\Q$uint_dom\E$/,@intdoms)) {
+ $canswitch = 1;
+ } else {
+ my $serverhomeID = &get_server_homeID(&hostname($home));
+ my $serverhomedom = &host_domain($serverhomeID);
+ my %defdomdefaults = &get_domain_defaults($serverhomedom);
+ my %udomdefaults = &get_domain_defaults($udom);
+ my $remoterev = &get_server_loncaparev('',$home);
+ $canswitch = &can_host_session($udom,$home,$remoterev,
+ $udomdefaults{'remotesessions'},
+ $defdomdefaults{'hostedsessions'});
+ }
+ return $canswitch;
+}
+
sub can_host_session {
my ($udom,$lonhost,$remoterev,$remotesessions,$hostedsessions) = @_;
my $canhost = 1;
- my $host_idn = &Apache::lonnet::internet_dom($lonhost);
+ my $host_idn = &internet_dom($lonhost);
if (ref($remotesessions) eq 'HASH') {
if (ref($remotesessions->{'excludedomain'}) eq 'ARRAY') {
if (grep(/^\Q$host_idn\E$/,@{$remotesessions->{'excludedomain'}})) {
@@ -1348,8 +1494,8 @@ sub can_host_session {
}
if ($canhost) {
if (ref($hostedsessions) eq 'HASH') {
- my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
- my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
+ my $uprimary_id = &domain($udom,'primary');
+ my $uint_dom = &internet_dom($uprimary_id);
if (ref($hostedsessions->{'excludedomain'}) eq 'ARRAY') {
if (($uint_dom ne '') &&
(grep(/^\Q$uint_dom\E$/,@{$hostedsessions->{'excludedomain'}}))) {
@@ -1441,7 +1587,7 @@ sub spares_for_offload {
} else {
my $cachetime = 60*60*24;
my %domconfig =
- &Apache::lonnet::get_dom('configuration',['usersessions'],$dom_in_use);
+ &get_dom('configuration',['usersessions'],$dom_in_use);
if (ref($domconfig{'usersessions'}) eq 'HASH') {
if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
if (ref($domconfig{'usersessions'}{'spares'}{$lonhost_in_use}) eq 'HASH') {
@@ -1490,14 +1636,14 @@ sub get_lonbalancer_config {
sub check_loadbalancing {
my ($uname,$udom,$caller) = @_;
my ($is_balancer,$currtargets,$currrules,$dom_in_use,$homeintdom,
- $rule_in_effect,$offloadto,$otherserver,$setcookie);
+ $rule_in_effect,$offloadto,$otherserver,$setcookie,$dom_balancers);
my $lonhost = $perlvar{'lonHostID'};
my @hosts = ¤t_machine_ids();
- my $uprimary_id = &Apache::lonnet::domain($udom,'primary');
- my $uintdom = &Apache::lonnet::internet_dom($uprimary_id);
- my $intdom = &Apache::lonnet::internet_dom($lonhost);
+ my $uprimary_id = &domain($udom,'primary');
+ my $uintdom = &internet_dom($uprimary_id);
+ my $intdom = &internet_dom($lonhost);
my $serverhomedom = &host_domain($lonhost);
- my $domneedscache;
+ my $domneedscache;
my $cachetime = 60*60*24;
if (($uintdom ne '') && ($uintdom eq $intdom)) {
@@ -1509,7 +1655,7 @@ sub check_loadbalancing {
my ($result,$cached)=&is_cached_new('loadbalancing',$dom_in_use);
unless (defined($cached)) {
my %domconfig =
- &Apache::lonnet::get_dom('configuration',['loadbalancing'],$dom_in_use);
+ &get_dom('configuration',['loadbalancing'],$dom_in_use);
if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
$result = &do_cache_new('loadbalancing',$dom_in_use,$domconfig{'loadbalancing'},$cachetime);
} else {
@@ -1517,7 +1663,7 @@ sub check_loadbalancing {
}
}
if (ref($result) eq 'HASH') {
- ($is_balancer,$currtargets,$currrules,$setcookie) =
+ ($is_balancer,$currtargets,$currrules,$setcookie,$dom_balancers) =
&check_balancer_result($result,@hosts);
if ($is_balancer) {
if (ref($currrules) eq 'HASH') {
@@ -1570,7 +1716,7 @@ sub check_loadbalancing {
($result,$cached)=&is_cached_new('loadbalancing',$serverhomedom);
unless (defined($cached)) {
my %domconfig =
- &Apache::lonnet::get_dom('configuration',['loadbalancing'],$serverhomedom);
+ &get_dom('configuration',['loadbalancing'],$serverhomedom);
if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
$result = &do_cache_new('loadbalancing',$serverhomedom,$domconfig{'loadbalancing'},$cachetime);
} else {
@@ -1578,7 +1724,7 @@ sub check_loadbalancing {
}
}
if (ref($result) eq 'HASH') {
- ($is_balancer,$currtargets,$currrules,$setcookie) =
+ ($is_balancer,$currtargets,$currrules,$setcookie,$dom_balancers) =
&check_balancer_result($result,@hosts);
if ($is_balancer) {
if (ref($currrules) eq 'HASH') {
@@ -1654,12 +1800,12 @@ sub check_loadbalancing {
if (($is_balancer) && (!$homeintdom)) {
undef($setcookie);
}
- return ($is_balancer,$otherserver,$setcookie);
+ return ($is_balancer,$otherserver,$setcookie,$offloadto,$dom_balancers);
}
sub check_balancer_result {
my ($result,@hosts) = @_;
- my ($is_balancer,$currtargets,$currrules,$setcookie);
+ my ($is_balancer,$currtargets,$currrules,$setcookie,$dom_balancers);
if (ref($result) eq 'HASH') {
if ($result->{'lonhost'} ne '') {
my $currbalancer = $result->{'lonhost'};
@@ -1668,20 +1814,24 @@ sub check_balancer_result {
$currtargets = $result->{'targets'};
$currrules = $result->{'rules'};
}
+ $dom_balancers = $currbalancer;
} else {
- foreach my $key (keys(%{$result})) {
- if (($key ne '') && (grep(/^\Q$key\E$/,@hosts)) &&
- (ref($result->{$key}) eq 'HASH')) {
- $is_balancer = 1;
- $currrules = $result->{$key}{'rules'};
- $currtargets = $result->{$key}{'targets'};
- $setcookie = $result->{$key}{'cookie'};
- last;
+ if (keys(%{$result})) {
+ foreach my $key (keys(%{$result})) {
+ if (($key ne '') && (grep(/^\Q$key\E$/,@hosts)) &&
+ (ref($result->{$key}) eq 'HASH')) {
+ $is_balancer = 1;
+ $currrules = $result->{$key}{'rules'};
+ $currtargets = $result->{$key}{'targets'};
+ $setcookie = $result->{$key}{'cookie'};
+ last;
+ }
}
+ $dom_balancers = join(',',sort(keys(%{$result})));
}
}
}
- return ($is_balancer,$currtargets,$currrules,$setcookie);
+ return ($is_balancer,$currtargets,$currrules,$setcookie,$dom_balancers);
}
sub get_loadbalancer_targets {
@@ -1699,7 +1849,7 @@ sub get_loadbalancer_targets {
}
} elsif ($rule_in_effect eq 'externalbalancer') {
my %domconfig =
- &Apache::lonnet::get_dom('configuration',['loadbalancing'],$udom);
+ &get_dom('configuration',['loadbalancing'],$udom);
if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
if ($domconfig{'loadbalancing'}{'lonhost'} ne '') {
if (&hostname($domconfig{'loadbalancing'}{'lonhost'}) ne '') {
@@ -1753,6 +1903,101 @@ sub internet_dom_servers {
return %uniqservers;
}
+sub trusted_domains {
+ my ($cmdtype,$calldom) = @_;
+ my ($trusted,$untrusted);
+ if (&domain($calldom) eq '') {
+ return ($trusted,$untrusted);
+ }
+ unless ($cmdtype =~ /^(content|shared|enroll|coaurem|othcoau|domroles|catalog|reqcrs|msg)$/) {
+ return ($trusted,$untrusted);
+ }
+ my $callprimary = &domain($calldom,'primary');
+ my $intcalldom = &internet_dom($callprimary);
+ if ($intcalldom eq '') {
+ return ($trusted,$untrusted);
+ }
+
+ my ($trustconfig,$cached)=&is_cached_new('trust',$calldom);
+ unless (defined($cached)) {
+ my %domconfig = &get_dom('configuration',['trust'],$calldom);
+ &do_cache_new('trust',$calldom,$domconfig{'trust'},3600);
+ $trustconfig = $domconfig{'trust'};
+ }
+ if (ref($trustconfig)) {
+ my (%possexc,%possinc,@allexc,@allinc);
+ if (ref($trustconfig->{$cmdtype}) eq 'HASH') {
+ if (ref($trustconfig->{$cmdtype}->{'exc'}) eq 'ARRAY') {
+ map { $possexc{$_} = 1; } @{$trustconfig->{$cmdtype}->{'exc'}};
+ }
+ if (ref($trustconfig->{$cmdtype}->{'inc'}) eq 'ARRAY') {
+ $possinc{$intcalldom} = 1;
+ map { $possinc{$_} = 1; } @{$trustconfig->{$cmdtype}->{'inc'}};
+ }
+ }
+ if (keys(%possexc)) {
+ if (keys(%possinc)) {
+ foreach my $key (sort(keys(%possexc))) {
+ next if ($key eq $intcalldom);
+ unless ($possinc{$key}) {
+ push(@allexc,$key);
+ }
+ }
+ } else {
+ @allexc = sort(keys(%possexc));
+ }
+ }
+ if (keys(%possinc)) {
+ $possinc{$intcalldom} = 1;
+ @allinc = sort(keys(%possinc));
+ }
+ if ((@allexc > 0) || (@allinc > 0)) {
+ my %doms_by_intdom;
+ my %allintdoms = &all_host_intdom();
+ my %alldoms = &all_host_domain();
+ foreach my $key (%allintdoms) {
+ if (ref($doms_by_intdom{$allintdoms{$key}}) eq 'ARRAY') {
+ unless (grep(/^\Q$alldoms{$key}\E$/,@{$doms_by_intdom{$allintdoms{$key}}})) {
+ push(@{$doms_by_intdom{$allintdoms{$key}}},$alldoms{$key});
+ }
+ } else {
+ $doms_by_intdom{$allintdoms{$key}} = [$alldoms{$key}];
+ }
+ }
+ foreach my $exc (@allexc) {
+ if (ref($doms_by_intdom{$exc}) eq 'ARRAY') {
+ push(@{$untrusted},@{$doms_by_intdom{$exc}});
+ }
+ }
+ foreach my $inc (@allinc) {
+ if (ref($doms_by_intdom{$inc}) eq 'ARRAY') {
+ push(@{$trusted},@{$doms_by_intdom{$inc}});
+ }
+ }
+ }
+ }
+ return ($trusted,$untrusted);
+}
+
+sub will_trust {
+ my ($cmdtype,$domain,$possdom) = @_;
+ return 1 if ($domain eq $possdom);
+ my ($trustedref,$untrustedref) = &trusted_domains($cmdtype,$possdom);
+ my $willtrust;
+ if ((ref($trustedref) eq 'ARRAY') && (@{$trustedref} > 0)) {
+ if (grep(/^\Q$domain\E$/,@{$trustedref})) {
+ $willtrust = 1;
+ }
+ } elsif ((ref($untrustedref) eq 'ARRAY') && (@{$untrustedref} > 0)) {
+ unless (grep(/^\Q$domain\E$/,@{$untrustedref})) {
+ $willtrust = 1;
+ }
+ } else {
+ $willtrust = 1;
+ }
+ return $willtrust;
+}
+
# ---------------------- Find the homebase for a user from domain's lib servers
my %homecache;
@@ -1778,17 +2023,33 @@ sub homeserver {
return 'no_host';
}
-# ------------------------------------- Find the usernames behind a list of IDs
+# ----- Find the usernames behind a list of student/employee IDs or clicker IDs
sub idget {
- my ($udom,@ids)=@_;
+ my ($udom,$idsref,$namespace)=@_;
my %returnhash=();
+ my @ids=();
+ if (ref($idsref) eq 'ARRAY') {
+ @ids = @{$idsref};
+ } else {
+ return %returnhash;
+ }
+ if ($namespace eq '') {
+ $namespace = 'ids';
+ }
my %servers = &get_servers($udom,'library');
foreach my $tryserver (keys(%servers)) {
my $idlist=join('&', map { &escape($_); } @ids);
- $idlist=~tr/A-Z/a-z/;
- my $reply=&reply("idget:$udom:".$idlist,$tryserver);
+ if ($namespace eq 'ids') {
+ $idlist=~tr/A-Z/a-z/;
+ }
+ my $reply;
+ if ($namespace eq 'ids') {
+ $reply=&reply("idget:$udom:".$idlist,$tryserver);
+ } else {
+ $reply=&reply("getdom:$udom:$namespace:$idlist",$tryserver);
+ }
my @answer=();
if (($reply ne 'con_lost') && ($reply!~/^error\:/)) {
@answer=split(/\&/,$reply);
@@ -1797,9 +2058,9 @@ sub idget {
for ($i=0;$i<=$#ids;$i++) {
if ($answer[$i]) {
$returnhash{$ids[$i]}=&unescape($answer[$i]);
- }
+ }
}
- }
+ }
return %returnhash;
}
@@ -1814,60 +2075,141 @@ sub idrget {
return %returnhash;
}
-# ------------------------------- Store away a list of names and associated IDs
+# Store away a list of names and associated student/employee IDs or clicker IDs
sub idput {
- my ($udom,%ids)=@_;
+ my ($udom,$idsref,$uhom,$namespace)=@_;
my %servers=();
+ my %ids=();
+ my %byid = ();
+ if (ref($idsref) eq 'HASH') {
+ %ids=%{$idsref};
+ }
+ if ($namespace eq '') {
+ $namespace = 'ids';
+ }
foreach my $uname (keys(%ids)) {
&cput('environment',{'id'=>$ids{$uname}},$udom,$uname);
- my $uhom=&homeserver($uname,$udom);
+ if ($uhom eq '') {
+ $uhom=&homeserver($uname,$udom);
+ }
if ($uhom ne 'no_host') {
- my $id=&escape($ids{$uname});
- $id=~tr/A-Z/a-z/;
my $esc_unam=&escape($uname);
- if ($servers{$uhom}) {
- $servers{$uhom}.='&'.$id.'='.$esc_unam;
+ if ($namespace eq 'ids') {
+ my $id=&escape($ids{$uname});
+ $id=~tr/A-Z/a-z/;
+ my $esc_unam=&escape($uname);
+ $servers{$uhom}.=$id.'='.$esc_unam.'&';
} else {
- $servers{$uhom}=$id.'='.$esc_unam;
+ my @currids = split(/,/,$ids{$uname});
+ foreach my $id (@currids) {
+ $byid{$uhom}{$id} .= $uname.',';
+ }
+ }
+ }
+ }
+ if ($namespace eq 'clickers') {
+ foreach my $server (keys(%byid)) {
+ if (ref($byid{$server}) eq 'HASH') {
+ foreach my $id (keys(%{$byid{$server}})) {
+ $byid{$server} =~ s/,$//;
+ $servers{$uhom}.=&escape($id).'='.&escape($byid{$server}).'&';
+ }
}
}
}
foreach my $server (keys(%servers)) {
- &critical('idput:'.$udom.':'.$servers{$server},$server);
+ $servers{$server} =~ s/\&$//;
+ if ($namespace eq 'ids') {
+ &critical('idput:'.$udom.':'.$servers{$server},$server);
+ } else {
+ &critical('updateclickers:'.$udom.':add:'.$servers{$server},$server);
+ }
}
}
-# ---------------------------------------- Delete unwanted IDs from ids.db file
+# ------------- Delete unwanted student/employee IDs or clicker IDs from domain
sub iddel {
- my ($udom,$idshashref,$uhome)=@_;
+ my ($udom,$idshashref,$uhome,$namespace)=@_;
my %result=();
- unless (ref($idshashref) eq 'HASH') {
+ my %ids=();
+ my %byid = ();
+ if (ref($idshashref) eq 'HASH') {
+ %ids=%{$idshashref};
+ } else {
return %result;
}
+ if ($namespace eq '') {
+ $namespace = 'ids';
+ }
my %servers=();
- while (my ($id,$uname) = each(%{$idshashref})) {
- my $uhom;
- if ($uhome) {
- $uhom = $uhome;
- } else {
- $uhom=&homeserver($uname,$udom);
- }
- if ($uhom ne 'no_host') {
- if ($servers{$uhom}) {
+ while (my ($id,$unamestr) = each(%ids)) {
+ if ($namespace eq 'ids') {
+ my $uhom = $uhome;
+ if ($uhom eq '') {
+ $uhom=&homeserver($unamestr,$udom);
+ }
+ if ($uhom ne 'no_host') {
$servers{$uhom}.='&'.&escape($id);
- } else {
- $servers{$uhom}=&escape($id);
+ }
+ } else {
+ my @curritems = split(/,/,$ids{$id});
+ foreach my $uname (@curritems) {
+ my $uhom = $uhome;
+ if ($uhom eq '') {
+ $uhom=&homeserver($uname,$udom);
+ }
+ if ($uhom ne 'no_host') {
+ $byid{$uhom}{$id} .= $uname.',';
+ }
+ }
+ }
+ }
+ if ($namespace eq 'clickers') {
+ foreach my $server (keys(%byid)) {
+ if (ref($byid{$server}) eq 'HASH') {
+ foreach my $id (keys(%{$byid{$server}})) {
+ $byid{$server}{$id} =~ s/,$//;
+ $servers{$server}.=&escape($id).'='.&escape($byid{$server}{$id}).'&';
+ }
}
}
}
foreach my $server (keys(%servers)) {
- $result{$server} = &critical('iddel:'.$udom.':'.$servers{$server},$uhome);
+ $servers{$server} =~ s/\&$//;
+ if ($namespace eq 'ids') {
+ $result{$server} = &critical('iddel:'.$udom.':'.$servers{$server},$uhome);
+ } elsif ($namespace eq 'clickers') {
+ $result{$server} = &critical('updateclickers:'.$udom.':del:'.$servers{$server},$server);
+ }
}
return %result;
}
+# ----- Update clicker ID-to-username look-ups in clickers.db on library server
+
+sub updateclickers {
+ my ($udom,$action,$idshashref,$uhome,$critical) = @_;
+ my %clickers;
+ if (ref($idshashref) eq 'HASH') {
+ %clickers=%{$idshashref};
+ } else {
+ return;
+ }
+ my $items='';
+ foreach my $item (keys(%clickers)) {
+ $items.=&escape($item).'='.&escape($clickers{$item}).'&';
+ }
+ $items=~s/\&$//;
+ my $request = "updateclickers:$udom:$action:$items";
+ if ($critical) {
+ return &critical($request,$uhome);
+ } else {
+ return &reply($request,$uhome);
+ }
+}
+
# ------------------------------dump from db file owned by domainconfig user
sub dump_dom {
my ($namespace, $udom, $regexp) = @_;
@@ -1882,7 +2224,7 @@ sub dump_dom {
# ------------------------------------------ get items from domain db files
sub get_dom {
- my ($namespace,$storearr,$udom,$uhome)=@_;
+ my ($namespace,$storearr,$udom,$uhome,$encrypt)=@_;
return if ($udom eq 'public');
my $items='';
foreach my $item (@$storearr) {
@@ -1909,8 +2251,12 @@ sub get_dom {
if (grep { $_ eq $uhome } ¤t_machine_ids()) {
# domain information is hosted on this machine
$rep = &LONCAPA::Lond::get_dom("getdom:$udom:$namespace:$items");
- } else {
- $rep=&reply("getdom:$udom:$namespace:$items",$uhome);
+ } else {
+ if ($encrypt) {
+ $rep=&reply("encrypt:egetdom:$udom:$namespace:$items",$uhome);
+ } else {
+ $rep=&reply("getdom:$udom:$namespace:$items",$uhome);
+ }
}
my %returnhash;
if ($rep eq '' || $rep =~ /^error: 2 /) {
@@ -1934,7 +2280,7 @@ sub get_dom {
# -------------------------------------------- put items in domain db files
sub put_dom {
- my ($namespace,$storehash,$udom,$uhome)=@_;
+ my ($namespace,$storehash,$udom,$uhome,$encrypt)=@_;
if (!$udom) {
$udom=$env{'user.domain'};
if (defined(&domain($udom,'primary'))) {
@@ -1955,7 +2301,11 @@ sub put_dom {
$items.=&escape($item).'='.&freeze_escape($$storehash{$item}).'&';
}
$items=~s/\&$//;
- return &reply("putdom:$udom:$namespace:$items",$uhome);
+ if ($encrypt) {
+ return &reply("encrypt:putdom:$udom:$namespace:$items",$uhome);
+ } else {
+ return &reply("putdom:$udom:$namespace:$items",$uhome);
+ }
} else {
&logthis("put_dom failed - no homeserver and/or domain");
}
@@ -1989,6 +2339,57 @@ sub del_dom {
}
}
+sub store_dom {
+ my ($storehash,$id,$namespace,$dom,$home,$encrypt) = @_;
+ $$storehash{'ip'}=&get_requestor_ip();
+ $$storehash{'host'}=$perlvar{'lonHostID'};
+ my $namevalue='';
+ foreach my $key (keys(%{$storehash})) {
+ $namevalue.=&escape($key).'='.&freeze_escape($$storehash{$key}).'&';
+ }
+ $namevalue=~s/\&$//;
+ if (grep { $_ eq $home } current_machine_ids()) {
+ return LONCAPA::Lond::store_dom("storedom:$dom:$namespace:$id:$namevalue");
+ } else {
+ if ($namespace eq 'private') {
+ return 'refused';
+ } elsif ($encrypt) {
+ return reply("encrypt:storedom:$dom:$namespace:$id:$namevalue",$home);
+ } else {
+ return reply("storedom:$dom:$namespace:$id:$namevalue",$home);
+ }
+ }
+}
+
+sub restore_dom {
+ my ($id,$namespace,$dom,$home,$encrypt) = @_;
+ my $answer;
+ if (grep { $_ eq $home } current_machine_ids()) {
+ $answer = LONCAPA::Lond::restore_dom("restoredom:$dom:$namespace:$id");
+ } elsif ($namespace ne 'private') {
+ if ($encrypt) {
+ $answer=&reply("encrypt:restoredom:$dom:$namespace:$id",$home);
+ } else {
+ $answer=&reply("restoredom:$dom:$namespace:$id",$home);
+ }
+ }
+ my %returnhash=();
+ unless (($answer eq '') || ($answer eq 'con_lost') || ($answer eq 'refused') ||
+ ($answer eq 'unknown_cmd') || ($answer eq 'rejected')) {
+ foreach my $line (split(/\&/,$answer)) {
+ my ($name,$value)=split(/\=/,$line);
+ $returnhash{&unescape($name)}=&thaw_unescape($value);
+ }
+ my $version;
+ for ($version=1;$version<=$returnhash{'version'};$version++) {
+ foreach my $item (split(/\:/,$returnhash{$version.':keys'})) {
+ $returnhash{$item}=$returnhash{$version.':'.$item};
+ }
+ }
+ }
+ return %returnhash;
+}
+
# ----------------------------------construct domainconfig user for a domain
sub get_domainconfiguser {
my ($udom) = @_;
@@ -1998,7 +2399,7 @@ sub get_domainconfiguser {
sub retrieve_inst_usertypes {
my ($udom) = @_;
my (%returnhash,@order);
- my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
+ my %domdefs = &get_domain_defaults($udom);
if ((ref($domdefs{'inststatustypes'}) eq 'HASH') &&
(ref($domdefs{'inststatusorder'}) eq 'ARRAY')) {
return ($domdefs{'inststatustypes'},$domdefs{'inststatusorder'});
@@ -2049,10 +2450,9 @@ sub inst_directory_query {
unless ($homeserver eq $perlvar{'lonHostID'}) {
if ($srch->{'srchby'} eq 'email') {
my $lcrev = &get_server_loncaparev($udom,$homeserver);
- my ($major,$minor,$subver) = ($lcrev =~ /^\'?(\d+)\.(\d+)\.(\d+)[\w.\-]+\'?$/);
+ my ($major,$minor) = ($lcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
if (($major eq '' && $minor eq '') || ($major < 2) ||
- (($major == 2) && ($minor < 11)) ||
- (($major == 2) && ($minor == 11) && ($subver < 3))) {
+ (($major == 2) && ($minor < 12))) {
return;
}
}
@@ -2101,10 +2501,9 @@ sub usersearch {
unless ($tryserver eq $perlvar{'lonHostID'}) {
if ($srch->{'srchby'} eq 'email') {
my $lcrev = &get_server_loncaparev($dom,$tryserver);
- my ($major,$minor,$subver) = ($lcrev =~ /^\'?(\d+)\.(\d+)\.(\d+)[\w.\-]+\'?$/);
+ my ($major,$minor) = ($lcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
next if (($major eq '' && $minor eq '') || ($major < 2) ||
- (($major == 2) && ($minor < 11)) ||
- (($major == 2) && ($minor == 11) && ($subver < 3)));
+ (($major == 2) && ($minor < 12)));
}
}
my $host=&hostname($tryserver);
@@ -2196,7 +2595,7 @@ sub get_multiple_instusers {
my ($udom,$users,$caller) = @_;
my ($outcome,$results);
if (ref($users) eq 'HASH') {
- my $count = keys(%{$users});
+ my $count = keys(%{$users});
my $requested = &freeze_escape($users);
my $homeserver = &domain($udom,'primary');
if ($homeserver ne '') {
@@ -2240,7 +2639,7 @@ sub get_multiple_instusers {
} else {
($outcome,my $userdata) = split(/=/,$response,2);
if ($outcome eq 'ok') {
- $results = &thaw_unescape($userdata);
+ $results = &thaw_unescape($userdata);
}
}
}
@@ -2306,7 +2705,7 @@ sub inst_userrules {
$homeserver);
} elsif ($check eq 'unamemap') {
$response=&reply('unamemaprules:'.&escape($udom),
- $homeserver);
+ $homeserver);
} else {
$response=&reply('instuserrules:'.&escape($udom),
$homeserver);
@@ -2348,13 +2747,15 @@ sub get_domain_defaults {
}
my %domdefaults;
my %domconfig =
- &Apache::lonnet::get_dom('configuration',['defaults','quotas',
+ &get_dom('configuration',['defaults','quotas',
'requestcourses','inststatus',
'coursedefaults','usersessions',
'requestauthor','selfenrollment',
- 'coursecategories','autoenroll',
- 'helpsettings','wafproxy'],$domain);
- my @coursetypes = ('official','unofficial','community','textbook');
+ 'coursecategories','ssl','autoenroll',
+ 'trust','helpsettings','wafproxy',
+ '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'};
$domdefaults{'auth_def'} = $domconfig{'defaults'}{'auth_def'};
@@ -2362,6 +2763,8 @@ sub get_domain_defaults {
$domdefaults{'timezone_def'} = $domconfig{'defaults'}{'timezone_def'};
$domdefaults{'datelocale_def'} = $domconfig{'defaults'}{'datelocale_def'};
$domdefaults{'portal_def'} = $domconfig{'defaults'}{'portal_def'};
+ $domdefaults{'portal_def_email'} = $domconfig{'defaults'}{'portal_def_email'};
+ $domdefaults{'portal_def_web'} = $domconfig{'defaults'}{'portal_def_web'};
$domdefaults{'intauth_cost'} = $domconfig{'defaults'}{'intauth_cost'};
$domdefaults{'intauth_switch'} = $domconfig{'defaults'}{'intauth_switch'};
$domdefaults{'intauth_check'} = $domconfig{'defaults'}{'intauth_check'};
@@ -2388,7 +2791,7 @@ sub get_domain_defaults {
}
}
if (ref($domconfig{'requestcourses'}) eq 'HASH') {
- foreach my $item ('official','unofficial','community','textbook') {
+ foreach my $item ('official','unofficial','community','textbook','placement') {
$domdefaults{$item} = $domconfig{'requestcourses'}{$item};
}
}
@@ -2401,6 +2804,7 @@ sub get_domain_defaults {
}
}
if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
+ $domdefaults{'canuse_pdfforms'} = $domconfig{'coursedefaults'}{'canuse_pdfforms'};
$domdefaults{'usejsme'} = $domconfig{'coursedefaults'}{'usejsme'};
$domdefaults{'inline_chem'} = $domconfig{'coursedefaults'}{'inline_chem'};
$domdefaults{'uselcmath'} = $domconfig{'coursedefaults'}{'uselcmath'};
@@ -2418,10 +2822,20 @@ sub get_domain_defaults {
}
if ($domdefaults{'postsubmit'} eq 'on') {
if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
- $domdefaults{$type.'postsubtimeout'} =
- $domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
+ $domdefaults{$type.'postsubtimeout'} =
+ $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') {
@@ -2436,6 +2850,9 @@ sub get_domain_defaults {
if ($domconfig{'coursedefaults'}{'texengine'}) {
$domdefaults{'texengine'} = $domconfig{'coursedefaults'}{'texengine'};
}
+ if (exists($domconfig{'coursedefaults'}{'ltiauth'})) {
+ $domdefaults{'crsltiauth'} = $domconfig{'coursedefaults'}{'ltiauth'};
+ }
}
if (ref($domconfig{'usersessions'}) eq 'HASH') {
if (ref($domconfig{'usersessions'}{'remote'}) eq 'HASH') {
@@ -2489,6 +2906,25 @@ sub get_domain_defaults {
$domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
}
}
+ if (ref($domconfig{'ssl'}) eq 'HASH') {
+ if (ref($domconfig{'ssl'}{'replication'}) eq 'HASH') {
+ $domdefaults{'replication'} = $domconfig{'ssl'}{'replication'};
+ }
+ if (ref($domconfig{'ssl'}{'connto'}) eq 'HASH') {
+ $domdefaults{'connect'} = $domconfig{'ssl'}{'connto'};
+ }
+ if (ref($domconfig{'ssl'}{'connfrom'}) eq 'HASH') {
+ $domdefaults{'connect'} = $domconfig{'ssl'}{'connfrom'};
+ }
+ }
+ if (ref($domconfig{'trust'}) eq 'HASH') {
+ my @prefixes = qw(content shared enroll othcoau coaurem domroles catalog reqcrs msg);
+ foreach my $prefix (@prefixes) {
+ if (ref($domconfig{'trust'}{$prefix}) eq 'HASH') {
+ $domdefaults{'trust'.$prefix} = $domconfig{'trust'}{$prefix};
+ }
+ }
+ }
if (ref($domconfig{'autoenroll'}) eq 'HASH') {
$domdefaults{'autofailsafe'} = $domconfig{'autoenroll'}{'autofailsafe'};
$domdefaults{'failsafe'} = $domconfig{'autoenroll'}{'failsafe'};
@@ -2506,6 +2942,29 @@ sub get_domain_defaults {
}
}
}
+ if (ref($domconfig{'ltisec'}) eq 'HASH') {
+ if (ref($domconfig{'ltisec'}{'encrypt'}) eq 'HASH') {
+ $domdefaults{'linkprotenc_crs'} = $domconfig{'ltisec'}{'encrypt'}{'crs'};
+ $domdefaults{'linkprotenc_dom'} = $domconfig{'ltisec'}{'encrypt'}{'dom'};
+ $domdefaults{'ltienc_consumers'} = $domconfig{'ltisec'}{'encrypt'}{'consumers'};
+ }
+ if (ref($domconfig{'ltisec'}{'private'}) eq 'HASH') {
+ if (ref($domconfig{'ltisec'}{'private'}{'keys'}) eq 'ARRAY') {
+ $domdefaults{'ltiprivhosts'} = $domconfig{'ltisec'}{'private'}{'keys'};
+ }
+ }
+ }
+ if (ref($domconfig{'toolsec'}) eq 'HASH') {
+ if (ref($domconfig{'toolsec'}{'encrypt'}) eq 'HASH') {
+ $domdefaults{'toolenc_crs'} = $domconfig{'toolsec'}{'encrypt'}{'crs'};
+ $domdefaults{'toolenc_dom'} = $domconfig{'toolsec'}{'encrypt'}{'dom'};
+ }
+ if (ref($domconfig{'toolsec'}{'private'}) eq 'HASH') {
+ if (ref($domconfig{'toolsec'}{'private'}{'keys'}) eq 'ARRAY') {
+ $domdefaults{'toolprivhosts'} = $domconfig{'toolsec'}{'private'}{'keys'};
+ }
+ }
+ }
&do_cache_new('domdefaults',$domain,\%domdefaults,$cachetime);
return %domdefaults;
}
@@ -2525,7 +2984,7 @@ sub get_dom_cats {
} else {
$cats = {};
}
- &Apache::lonnet::do_cache_new('cats',$dom,$cats,3600);
+ &do_cache_new('cats',$dom,$cats,3600);
}
return $cats;
}
@@ -2542,6 +3001,7 @@ sub get_dom_instcats {
if (&auto_instcode_format($caller,$dom,\%coursecodes,\%codes,
\@codetitles,\%cat_titles,\%cat_order) eq 'ok') {
$instcats = {
+ totcodes => $totcodes,
codes => \%codes,
codetitles => \@codetitles,
cat_titles => \%cat_titles,
@@ -2569,6 +3029,44 @@ sub retrieve_instcodes {
return $totcodes;
}
+sub course_portal_url {
+ my ($cnum,$cdom,$r) = @_;
+ my $chome = &homeserver($cnum,$cdom);
+ my $hostname = &hostname($chome);
+ my $protocol = $protocol{$chome};
+ $protocol = 'http' if ($protocol ne 'https');
+ my %domdefaults = &get_domain_defaults($cdom);
+ my $firsturl;
+ if ($domdefaults{'portal_def'}) {
+ $firsturl = $domdefaults{'portal_def'};
+ } else {
+ my $alias = &use_proxy_alias($r,$chome);
+ $hostname = $alias if ($alias ne '');
+ $firsturl = $protocol.'://'.$hostname;
+ }
+ return $firsturl;
+}
+
+sub url_prefix {
+ my ($r,$dom,$home,$context) = @_;
+ my $prefix;
+ my %domdefs = &get_domain_defaults($dom);
+ if ($domdefs{'portal_def'} && $domdefs{'portal_def_'.$context}) {
+ if ($domdefs{'portal_def'} =~ m{^(https?://[^/]+)}) {
+ $prefix = $1;
+ }
+ }
+ if ($prefix eq '') {
+ my $hostname = &hostname($home);
+ my $protocol = $protocol{$home};
+ $protocol = 'http' if ($protocol{$home} ne 'https');
+ my $alias = &use_proxy_alias($r,$home);
+ $hostname = $alias if ($alias ne '');
+ $prefix = $protocol.'://'.$hostname;
+ }
+ return $prefix;
+}
+
# --------------------------------------------- Get domain config for passwords
sub get_passwdconf {
@@ -2740,7 +3238,7 @@ sub courseid_to_courseurl {
return "/$cdom/$cnum";
}
- my %courseinfo=&Apache::lonnet::coursedescription($courseid);
+ my %courseinfo=&coursedescription($courseid);
if (exists($courseinfo{'num'})) {
return "/$courseinfo{'domain'}/$courseinfo{'num'}";
}
@@ -2837,9 +3335,7 @@ sub devalidate_cache_new {
sub is_cached_new {
my ($name,$id,$debug) = @_;
- my $remembered_id=$name.':'.$id; # this is to avoid make_key (which is slow) for
- # keys in %remembered hash, which persists for
- # duration of request (no restriction on key length).
+ my $remembered_id=$name.':'.$id; # this is to avoid make_key (which is slow) whenever possible
if (exists($remembered{$remembered_id})) {
if ($debug) { &Apache::lonnet::logthis("Early return $remembered_id of $remembered{$remembered_id} "); }
$accessed{$remembered_id}=[&gettimeofday()];
@@ -2940,14 +3436,14 @@ sub userenvironment {
# ---------------------------------------------------------- Get a studentphoto
sub studentphoto {
my ($udom,$unam,$ext) = @_;
- my $home=&Apache::lonnet::homeserver($unam,$udom);
+ my $home=&homeserver($unam,$udom);
if (defined($env{'request.course.id'})) {
if ($env{'course.'.$env{'request.course.id'}.'.internal.showphoto'}) {
if ($udom eq $env{'course.'.$env{'request.course.id'}.'.domain'}) {
return(&retrievestudentphoto($udom,$unam,$ext));
} else {
my ($result,$perm_reqd)=
- &Apache::lonnet::auto_photo_permission($unam,$udom);
+ &auto_photo_permission($unam,$udom);
if ($result eq 'ok') {
if (!($perm_reqd eq 'yes')) {
return(&retrievestudentphoto($udom,$unam,$ext));
@@ -2957,7 +3453,7 @@ sub studentphoto {
}
} else {
my ($result,$perm_reqd) =
- &Apache::lonnet::auto_photo_permission($unam,$udom);
+ &auto_photo_permission($unam,$udom);
if ($result eq 'ok') {
if (!($perm_reqd eq 'yes')) {
return(&retrievestudentphoto($udom,$unam,$ext));
@@ -2969,14 +3465,14 @@ sub studentphoto {
sub retrievestudentphoto {
my ($udom,$unam,$ext,$type) = @_;
- my $home=&Apache::lonnet::homeserver($unam,$udom);
- my $ret=&Apache::lonnet::reply("studentphoto:$udom:$unam:$ext:$type",$home);
+ my $home=&homeserver($unam,$udom);
+ my $ret=&reply("studentphoto:$udom:$unam:$ext:$type",$home);
if ($ret eq 'ok') {
my $url="/uploaded/$udom/$unam/internal/studentphoto.$ext";
if ($type eq 'thumbnail') {
$url="/uploaded/$udom/$unam/internal/studentphoto_tn.$ext";
}
- my $tokenurl=&Apache::lonnet::tokenwrapper($url);
+ my $tokenurl=&tokenwrapper($url);
return $tokenurl;
} else {
if ($type eq 'thumbnail') {
@@ -3101,9 +3597,13 @@ sub repcopy {
mkdir($path,0777);
}
}
- my $ua=new LWP::UserAgent;
my $request=new HTTP::Request('GET',"$remoteurl");
- my $response=$ua->request($request,$transname);
+ my $response;
+ if ($remoteurl =~ m{/raw/}) {
+ $response=&LONCAPA::LWPReq::makerequest($home,$request,$transname,\%perlvar,'',0,1);
+ } else {
+ $response=&LONCAPA::LWPReq::makerequest($home,$request,$transname,\%perlvar,'',1);
+ }
if ($response->is_error()) {
unlink($transname);
my $message=$response->status_line;
@@ -3113,7 +3613,12 @@ sub repcopy {
} else {
if ($remoteurl!~/\.meta$/) {
my $mrequest=new HTTP::Request('GET',$remoteurl.'.meta');
- my $mresponse=$ua->request($mrequest,$filename.'.meta');
+ my $mresponse;
+ if ($remoteurl =~ m{/raw/}) {
+ $mresponse = &LONCAPA::LWPReq::makerequest($home,$mrequest,$filename.'.meta',\%perlvar,'',0,1);
+ } else {
+ $mresponse = &LONCAPA::LWPReq::makerequest($home,$mrequest,$filename.'.meta',\%perlvar,'',1);
+ }
if ($mresponse->is_error()) {
unlink($filename.'.meta');
&logthis(
@@ -3143,7 +3648,12 @@ sub unsubscribe {
} elsif (grep { $_ eq $home } ¤t_machine_ids()) {
$answer = 'home';
} else {
- $answer = reply("unsub:$fname",$home);
+ my $defdom = $perlvar{'lonDefDomain'};
+ if (&will_trust('content',$defdom,$udom)) {
+ $answer = reply("unsub:$fname",$home);
+ } else {
+ $answer = 'untrusted';
+ }
}
return $answer;
}
@@ -3186,7 +3696,7 @@ sub absolute_url {
if ($alias eq $host_name) {
my $lonhost = $perlvar{'lonHostID'};
my $hostname = &hostname($lonhost);
- my $lcproto;
+ my $lcproto;
if (($keep_proto) || ($hostname eq '')) {
$lcproto = $protocol;
} else {
@@ -3198,7 +3708,7 @@ sub absolute_url {
return $lcproto.$hostname;
}
}
- }
+ }
return $protocol.$host_name;
}
@@ -3222,41 +3732,30 @@ sub ssi {
&Apache::lonenc::check_encrypt(\$fn);
if (%form) {
$request=new HTTP::Request('POST',$host.$fn);
- $request->content(join('&',map {
+ $request->content(join('&',map {
my $name = escape($_);
- "$name=" . ( ref($form{$_}) eq 'ARRAY'
- ? join("&$name=", map {escape($_) } @{$form{$_}})
- : &escape($form{$_}) );
+ "$name=" . ( ref($form{$_}) eq 'ARRAY'
+ ? join("&$name=", map {escape($_) } @{$form{$_}})
+ : &escape($form{$_}) );
} keys(%form)));
} else {
$request=new HTTP::Request('GET',$host.$fn);
}
$request->header(Cookie => $ENV{'HTTP_COOKIE'});
-
+ my $lonhost = $perlvar{'lonHostID'};
+ my $islocal;
if (($env{'request.course.id'}) &&
($form{'grade_courseid'} eq $env{'request.course.id'}) &&
($form{'grade_username'} ne '') && ($form{'grade_domain'} ne '') &&
($form{'grade_symb'} ne '') &&
- (&Apache::lonnet::allowed('mgr',$env{'request.course.id'}.
- ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) {
- if (LWP::UserAgent->VERSION >= 5.834) {
- my $ua=new LWP::UserAgent;
- $ua->local_address('127.0.0.1');
- $response = $ua->request($request);
- } else {
- {
- require LWP::Protocol::http;
- local @LWP::Protocol::http::EXTRA_SOCK_OPTS = (LocalAddr => '127.0.0.1');
- my $ua=new LWP::UserAgent;
- $response = $ua->request($request);
- @LWP::Protocol::http::EXTRA_SOCK_OPTS = ();
- }
- }
- } else {
- my $ua=new LWP::UserAgent;
- $response = $ua->request($request);
+ (&allowed('mgr',$env{'request.course.id'}.
+ ($env{'request.course.sec'}?'/'.$env{'request.course.sec'}:'')))) {
+ $islocal = 1;
}
+ $response= &LONCAPA::LWPReq::makerequest($lonhost,$request,'',\%perlvar,
+ '','','',$islocal);
+
if (wantarray) {
return ($response->content, $response);
} else {
@@ -3266,9 +3765,8 @@ sub ssi {
sub externalssi {
my ($url)=@_;
- my $ua=new LWP::UserAgent;
my $request=new HTTP::Request('GET',$url);
- my $response=$ua->request($request);
+ my $response = &LONCAPA::LWPReq::makerequest('',$request,'',\%perlvar);
if (wantarray) {
return ($response->content, $response);
} else {
@@ -3276,8 +3774,9 @@ sub externalssi {
}
}
-# If the local copy of a replicated resource is outdated, trigger a
-# connection from the homeserver to flush the delayed queue. If no update
+
+# If the local copy of a replicated resource is outdated, trigger a
+# connection from the homeserver to flush the delayed queue. If no update
# happens, remove local copies of outdated resource (and corresponding
# metadata file).
@@ -3297,11 +3796,9 @@ sub remove_stale_resfile {
if ($hostname) {
my $protocol = $protocol{$homeserver};
$protocol = 'http' if ($protocol ne 'https');
- my $uri = $protocol.'://'.$hostname.'/raw/'.&declutter($url);
- my $ua=new LWP::UserAgent;
- $ua->timeout(5);
- my $request=new HTTP::Request('HEAD',$uri);
- my $response=$ua->request($request);
+ my $uri = &declutter($url);
+ my $request=new HTTP::Request('HEAD',$protocol.'://'.$hostname.'/raw/'.$uri);
+ my $response = &LONCAPA::LWPReq::makerequest($homeserver,$request,'',\%perlvar,5,0,1);
if ($response->is_success()) {
my $remmodtime = &HTTP::Date::str2time( $response->header('Last-modified') );
my $locmodtime = (stat($fname))[9];
@@ -3364,7 +3861,7 @@ sub allowuploaded {
#
# Determine if the current user should be able to edit a particular resource,
# when viewing in course context.
-# (a) When viewing resource used to determine if "Edit" item is included in
+# (a) When viewing resource used to determine if "Edit" item is included in
# Functions.
# (b) When displaying folder contents in course editor, used to determine if
# "Edit" link will be displayed alongside resource.
@@ -3372,12 +3869,12 @@ sub allowuploaded {
# input: six args -- filename (decluttered), course number, course domain,
# url, symb (if registered) and group (if this is a group
# item -- e.g., bulletin board, group page etc.).
-# output: array of five scalars --
+# output: array of five scalars --
# $cfile -- url for file editing if editable on current server
# $home -- homeserver of resource (i.e., for author if published,
# or course if uploaded.).
# $switchserver -- 1 if server switch will be needed.
-# $forceedit -- 1 if icon/link should be to go to edit mode
+# $forceedit -- 1 if icon/link should be to go to edit mode
# $forceview -- 1 if icon/link should be to go to view mode
#
@@ -3404,7 +3901,7 @@ sub can_edit_resource {
}
if ($env{'request.course.id'}) {
- my $crsedit = &Apache::lonnet::allowed('mdc',$env{'request.course.id'});
+ my $crsedit = &allowed('mdc',$env{'request.course.id'});
if ($group ne '') {
# if this is a group homepage or group bulletin board, check group privs
my $allowed = 0;
@@ -3433,14 +3930,19 @@ sub can_edit_resource {
}
} else {
if ($resurl =~ m{^/?adm/viewclasslist$}) {
- unless (&Apache::lonnet::allowed('opa',$env{'request.course.id'})) {
+ unless (&allowed('opa',$env{'request.course.id'})) {
return;
}
} elsif (!$crsedit) {
+ if ($env{'request.role'} =~ m{^st\./$cdom/$cnum}) {
#
# No edit allowed where CC has switched to student role.
#
- return;
+ return;
+ } elsif (($resurl !~ m{^/res/$match_domain/$match_username/}) ||
+ ($resurl =~ m{^/res/lib/templates/})) {
+ return;
+ }
}
}
}
@@ -3498,6 +4000,14 @@ sub can_edit_resource {
$cfile = '/adm/wrapper'.$resurl;
}
}
+ } elsif ($resurl =~ m{^/adm/wrapper/adm/$cdom/$cnum/\d+/ext\.tool$}) {
+ $incourse = 1;
+ if ($env{'form.forceedit'}) {
+ $forceview = 1;
+ } else {
+ $forceedit = 1;
+ }
+ $cfile = $resurl;
} elsif ($resurl =~ m{^/?adm/viewclasslist$}) {
$incourse = 1;
if ($env{'form.forceedit'}) {
@@ -3509,7 +4019,7 @@ sub can_edit_resource {
}
} elsif ($resurl eq '/res/lib/templates/simpleproblem.problem/smpedit') {
my $template = '/res/lib/templates/simpleproblem.problem';
- if (&is_on_map($template)) {
+ if (&is_on_map($template)) {
$incourse = 1;
$forceview = 1;
$cfile = $template;
@@ -3522,6 +4032,14 @@ sub can_edit_resource {
$forceedit = 1;
}
$cfile = $resurl;
+ } elsif (($resurl =~ m{^/adm/wrapper/adm/$cdom/$cnum/\d+/ext\.tool$}) && ($env{'form.folderpath'} =~ /^supplemental/)) {
+ $incourse = 1;
+ if ($env{'form.forceedit'}) {
+ $forceview = 1;
+ } else {
+ $forceedit = 1;
+ }
+ $cfile = $resurl;
} elsif (($resurl eq '/adm/extresedit') && ($symb || $env{'form.folderpath'})) {
$incourse = 1;
$forceview = 1;
@@ -3531,8 +4049,13 @@ sub can_edit_resource {
$cfile = &clutter($res);
} else {
$cfile = $env{'form.suppurl'};
- $cfile =~ s{^http://}{};
- $cfile = '/adm/wrapper/ext/'.$cfile;
+ my $escfile = &unescape($cfile);
+ if ($escfile =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
+ $cfile = '/adm/wrapper'.$escfile;
+ } else {
+ $escfile =~ s{^http://}{};
+ $cfile = &escape("/adm/wrapper/ext/$escfile");
+ }
}
} elsif ($resurl =~ m{^/?adm/viewclasslist$}) {
if ($env{'form.forceedit'}) {
@@ -3556,7 +4079,7 @@ sub can_edit_resource {
$cfile=$file;
}
}
- if (($cfile ne '') && (!$incourse || $uploaded) &&
+ if (($cfile ne '') && (!$incourse || $uploaded) &&
(($home ne '') && ($home ne 'no_host'))) {
my @ids=¤t_machine_ids();
unless (grep(/^\Q$home\E$/,@ids)) {
@@ -3583,9 +4106,9 @@ sub in_course {
if ($hideprivileged) {
my $skipuser;
my %coursehash = &coursedescription($cdom.'_'.$cnum);
- my @possdoms = ($cdom);
- if ($coursehash{'checkforpriv'}) {
- push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
+ my @possdoms = ($cdom);
+ if ($coursehash{'checkforpriv'}) {
+ push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
}
if (&privileged($uname,$udom,\@possdoms)) {
$skipuser = 1;
@@ -3779,7 +4302,7 @@ sub clean_filename {
# Replace all .\d. sequences with _\d. so they no longer look like version
# numbers
$fname=~s/\.(\d+)(?=\.)/_$1/g;
-# Replace three or more adjacent underscores with one for consistency
+# Replace three or more adjacent underscores with one for consistency
# with loncfile::filename_check() so complete url can be extracted by
# lonnet::decode_symb()
$fname=~s/_{3,}/_/g;
@@ -3828,7 +4351,7 @@ sub resizeImage {
# input: $formname - the contents of the file are in $env{"form.$formname"}
# the desired filename is in $env{"form.$formname.filename"}
# $context - possible values: coursedoc, existingfile, overwrite,
-# canceloverwrite, scantron or ''.
+# canceloverwrite, scantron, toollogo or ''.
# if 'coursedoc': upload to the current course
# if 'existingfile': write file to tmp/overwrites directory
# if 'canceloverwrite': delete file written to tmp/overwrites directory
@@ -3836,12 +4359,12 @@ sub resizeImage {
# $subdir - directory in userfile to store the file into
# $parser - instruction to parse file for objects ($parser = parse) or
# if context is 'scantron', $parser is hashref of csv column mapping
-# (e.g.,{ PaperID => 0, LastName => 1, FirstName => 2, ID => 3,
+# (e.g.,{ PaperID => 0, LastName => 1, FirstName => 2, ID => 3,
# Section => 4, CODE => 5, FirstQuestion => 9 }).
# $allfiles - reference to hash for embedded objects
# $codebase - reference to hash for codebase of java objects
-# $desuname - username for permanent storage of uploaded file
-# $dsetudom - domain for permanaent storage of uploaded file
+# $destuname - username for permanent storage of uploaded file
+# $destudom - domain for permanaent storage of uploaded file
# $thumbwidth - width (pixels) of thumbnail to make for uploaded image
# $thumbheight - height (pixels) of thumbnail to make for uploaded image
# $resizewidth - width (pixels) to which to resize uploaded image
@@ -3886,7 +4409,7 @@ sub userfileupload {
} else {
$docudom = $env{'user.domain'};
}
- if ($destuname =~ /^$match_username$/) {
+ if ($destuname =~ /^$match_username$/) {
$docuname = $destuname;
} else {
$docuname = $env{'user.name'};
@@ -4051,11 +4574,24 @@ sub finishuserfileupload {
if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
my $input = $filepath.'/'.$file;
my $output = $filepath.'/'.'tn-'.$file;
+ my $makethumb;
my $thumbsize = $thumbwidth.'x'.$thumbheight;
- my @args = ('convert','-sample',$thumbsize,$input,$output);
- system({$args[0]} @args);
- if (-e $filepath.'/'.'tn-'.$file) {
- $fetchthumb = 1;
+ if ($context eq 'toollogo') {
+ my ($fullwidth,$fullheight) = &check_dimensions($input);
+ if ($fullwidth ne '' && $fullheight ne '') {
+ if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
+ $makethumb = 1;
+ }
+ }
+ } else {
+ $makethumb = 1;
+ }
+ if ($makethumb) {
+ my @args = ('convert','-sample',$thumbsize,$input,$output);
+ system({$args[0]} @args);
+ if (-e $filepath.'/'.'tn-'.$file) {
+ $fetchthumb = 1;
+ }
}
}
@@ -4112,7 +4648,7 @@ sub extract_embedded_items {
}
if (lc($tagname) eq 'a') {
unless (($attr->{'href'} =~ /^#/) || ($attr->{'href'} eq '')) {
- &add_filetype($allfiles,$attr->{'href'},'href');
+ &add_filetype($allfiles,$attr->{'href'},'href');
}
}
if (lc($tagname) eq 'script') {
@@ -4287,13 +4823,37 @@ sub embedded_dependency {
return;
}
+sub check_dimensions {
+ my ($inputfile) = @_;
+ my ($fullwidth,$fullheight);
+ if (($inputfile =~ m|^[/\w.\-]+$|) && (-e $inputfile)) {
+ my $mm = new File::MMagic;
+ my $mime_type = $mm->checktype_filename($inputfile);
+ if ($mime_type =~ m{^image/}) {
+ if (open(PIPE,"identify $inputfile 2>&1 |")) {
+ my $imageinfo =
'.$space.' - '.$qualifier.' - '.$spacequalifierrest;
# ----------------------------------------------------- Cascading lookup scheme
my $symbp=$symbparm;
- my $mapp=&deversion((&decode_symb($symbp))[0]);
-
+ $mapp=&deversion((&decode_symb($symbp))[0]);
my $symbparm=$symbp.'.'.$spacequalifierrest;
+ my $recurseparm=$mapp.'___(rec).'.$spacequalifierrest;
my $mapparm=$mapp.'___(all).'.$spacequalifierrest;
-
if (($env{'user.name'} eq $uname) &&
($env{'user.domain'} eq $udom)) {
$section=$env{'request.course.sec'};
@@ -11748,17 +12951,21 @@ sub EXT {
my $seclevel=$courseid.'.['.$section.'].'.$spacequalifierrest;
my $seclevelr=$courseid.'.['.$section.'].'.$symbparm;
+ my $secleveli=$courseid.'.['.$section.'].'.$recurseparm;
my $seclevelm=$courseid.'.['.$section.'].'.$mapparm;
$courselevel=$courseid.'.'.$spacequalifierrest;
my $courselevelr=$courseid.'.'.$symbparm;
+ $courseleveli=$courseid.'.'.$recurseparm;
$courselevelm=$courseid.'.'.$mapparm;
# ----------------------------------------------------------- first, check user
- my $userreply=&resdata($uname,$udom,'user',
+ my $userreply=&resdata($uname,$udom,'user',$mapp,\$recursed,
+ \@recurseup,$courseid,'.',$spacequalifierrest,
([$courselevelr,'resource'],
[$courselevelm,'map' ],
+ [$courseleveli,'map' ],
[$courselevel, 'course' ]));
if (defined($userreply)) { return &get_reply($userreply); }
@@ -11766,15 +12973,18 @@ sub EXT {
my $coursereply;
if (@groups > 0) {
$coursereply = &check_group_parms($courseid,\@groups,$symbparm,
- $mapparm,$spacequalifierrest);
- if (defined($coursereply)) { return &get_reply($coursereply); }
+ $recurseparm,$mapparm,$spacequalifierrest,
+ $mapp,\$recursed,\@recurseup);
+ if (defined($coursereply)) { return &get_reply($coursereply); }
}
$coursereply=&resdata($env{'course.'.$courseid.'.num'},
$env{'course.'.$courseid.'.domain'},
- 'course',
+ 'course',$mapp,\$recursed,\@recurseup,
+ $courseid,'.['.$section.'].',$spacequalifierrest,
([$seclevelr, 'resource'],
[$seclevelm, 'map' ],
+ [$secleveli, 'map' ],
[$seclevel, 'course' ],
[$courselevelr,'resource']));
if (defined($coursereply)) { return &get_reply($coursereply); }
@@ -11791,8 +13001,9 @@ sub EXT {
if ($thisparm) { return &get_reply([$thisparm,'resource']); }
}
# ------------------------------------------ fourth, look in resource metadata
-
- $spacequalifierrest=~s/\./\_/;
+
+ my $what = $spacequalifierrest;
+ $what=~s/\./\_/;
my $filename;
if (!$symbparm) { $symbparm=&symbread(); }
if ($symbparm) {
@@ -11800,18 +13011,24 @@ sub EXT {
} else {
$filename=$env{'request.filename'};
}
- my $metadata=&metadata($filename,$spacequalifierrest);
+ my $toolsymb;
+ if (($filename =~ /ext\.tool$/) && ($what ne '0_gradable')) {
+ $toolsymb = $symbparm;
+ }
+ my $metadata=&metadata($filename,$what,$toolsymb);
if (defined($metadata)) { return &get_reply([$metadata,'resource']); }
- $metadata=&metadata($filename,'parameter_'.$spacequalifierrest);
+ $metadata=&metadata($filename,'parameter_'.$what,$toolsymb);
if (defined($metadata)) { return &get_reply([$metadata,'resource']); }
-# ---------------------------------------------- fourth, look in rest of course
+# ----------------------------------------------- fifth, look in rest of course
if ($symbparm && defined($courseid) &&
$courseid eq $env{'request.course.id'}) {
my $coursereply=&resdata($env{'course.'.$courseid.'.num'},
$env{'course.'.$courseid.'.domain'},
- 'course',
+ 'course',$mapp,\$recursed,\@recurseup,
+ $courseid,'.',$spacequalifierrest,
([$courselevelm,'map' ],
+ [$courseleveli,'map' ],
[$courselevel, 'course']));
if (defined($coursereply)) { return &get_reply($coursereply); }
}
@@ -11826,7 +13043,7 @@ sub EXT {
if (defined($partgeneral[0])) { return &get_reply(\@partgeneral); }
}
if ($recurse) { return undef; }
- my $pack_def=&packages_tab_default($filename,$varname);
+ my $pack_def=&packages_tab_default($filename,$varname,$toolsymb);
if (defined($pack_def)) { return &get_reply([$pack_def,'resource']); }
# ---------------------------------------------------- Any other user namespace
} elsif ($realm eq 'environment') {
@@ -11851,6 +13068,10 @@ sub EXT {
if ($space eq 'name') {
return $ENV{'SERVER_NAME'};
}
+ } elsif ($realm eq 'client') {
+ if ($space eq 'remote_addr') {
+ return &get_requestor_ip();
+ }
}
return '';
}
@@ -11868,22 +13089,51 @@ sub get_reply {
}
sub check_group_parms {
- my ($courseid,$groups,$symbparm,$mapparm,$what) = @_;
- my @groupitems = ();
- my $resultitem;
- my @levels = ([$symbparm,'resource'],[$mapparm,'map'],[$what,'course']);
+ my ($courseid,$groups,$symbparm,$recurseparm,$mapparm,$what,$mapp,
+ $recursed,$recurseupref) = @_;
+ my @levels = ([$symbparm,'resource'],[$mapparm,'map'],[$recurseparm,'map'],
+ [$what,'course']);
+ my $coursereply;
foreach my $group (@{$groups}) {
+ my @groupitems = ();
foreach my $level (@levels) {
my $item = $courseid.'.['.$group.'].'.$level->[0];
push(@groupitems,[$item,$level->[1]]);
}
+ my $coursereply = &resdata($env{'course.'.$courseid.'.num'},
+ $env{'course.'.$courseid.'.domain'},
+ 'course',$mapp,$recursed,$recurseupref,
+ $courseid,'.['.$group.'].',$what,
+ @groupitems);
+ last if (defined($coursereply));
}
- my $coursereply = &resdata($env{'course.'.$courseid.'.num'},
- $env{'course.'.$courseid.'.domain'},
- 'course',@groupitems);
return $coursereply;
}
+sub get_map_hierarchy {
+ my ($mapname,$courseid) = @_;
+ my @recurseup = ();
+ if ($mapname) {
+ if (($cachedmapkey eq $courseid) &&
+ (abs($cachedmaptime-time)<5)) {
+ if (ref($cachedmaps{$mapname}) eq 'ARRAY') {
+ return @{$cachedmaps{$mapname}};
+ }
+ }
+ my $navmap = Apache::lonnavmaps::navmap->new();
+ if (ref($navmap)) {
+ @recurseup = $navmap->recurseup_maps($mapname);
+ undef($navmap);
+ $cachedmaps{$mapname} = \@recurseup;
+ $cachedmaptime=time;
+ $cachedmapkey=$courseid;
+ }
+ }
+ return @recurseup;
+}
+
+}
+
sub sort_course_groups { # Sort groups based on defined rankings. Default is sort().
my ($courseid,@groups) = @_;
@groups = sort(@groups);
@@ -11891,11 +13141,11 @@ sub sort_course_groups { # Sort groups b
}
sub packages_tab_default {
- my ($uri,$varname)=@_;
+ my ($uri,$varname,$toolsymb)=@_;
my (undef,$part,$name)=split(/\./,$varname);
my (@extension,@specifics,$do_default);
- foreach my $package (split(/,/,&metadata($uri,'packages'))) {
+ foreach my $package (split(/,/,&metadata($uri,'packages',$toolsymb))) {
my ($pack_type,$pack_part)=split(/_/,$package,2);
if ($pack_type eq 'default') {
$do_default=1;
@@ -11964,12 +13214,12 @@ my %metaentry;
my %importedpartids;
my %importedrespids;
sub metadata {
- my ($uri,$what,$liburi,$prefix,$depthcount)=@_;
+ my ($uri,$what,$toolsymb,$liburi,$prefix,$depthcount)=@_;
$uri=&declutter($uri);
# if it is a non metadata possible uri return quickly
if (($uri eq '') ||
(($uri =~ m|^/*adm/|) &&
- ($uri !~ m|^adm/includes|) && ($uri !~ m{/(smppg|bulletinboard)$})) ||
+ ($uri !~ m|^adm/includes|) && ($uri !~ m{/(smppg|bulletinboard|ext\.tool)$})) ||
($uri =~ m|/$|) || ($uri =~ m|/.meta$|) || ($uri =~ m{^/*uploaded/.+\.sequence$})) {
return undef;
}
@@ -11988,6 +13238,65 @@ sub metadata {
my ($result,$cached)=&is_cached_new('meta',$uri);
if (defined($cached)) { return $result->{':'.$what}; }
}
+
+#
+# If the uri is for an external tool the file from
+# which metadata should be retrieved depends on whether
+# the tool had been configured to be gradable (set in the Course
+# Editor or Resource Editor).
+#
+# If a valid symb has been included as the third arg in the call
+# to &metadata() that can be used to retrieve the value of
+# parameter_0_gradable set for the resource, and included in the
+# uploaded map containing the tool. The value is retrieved via
+# &EXT(), if a valid symb is available. Otherwise the value of
+# gradable in the exttool_$marker.db file for the tool instance
+# is retrieved via &get().
+#
+# When lonuserstate::traceroute() calls lonnet::EXT() for
+# hiddenresource and encrypturl (during course initialization)
+# the map-level parameter for resource.0.gradable included in the
+# uploaded map containing the tool will not yet have been stored
+# in the user_course_parms.db file for the user's session, so in
+# this case fall back to retrieving gradable status from the
+# exttool_$marker.db file.
+#
+# In order to avoid an infinite loop, &metadata() will return
+# before a call to &EXT(), if the uri is for an external tool
+# and the $what for which metadata is being requested is
+# parameter_0_gradable or 0_gradable.
+#
+
+ if ($uri =~ /ext\.tool$/) {
+ if (($what eq 'parameter_0_gradable') || ($what eq '0_gradable')) {
+ return;
+ } else {
+ my ($checked,$use_passback);
+ if ($toolsymb ne '') {
+ (undef,undef,my $tooluri) = &decode_symb($toolsymb);
+ if (($tooluri eq $uri) && (&EXT('resource.0.gradable',$toolsymb))) {
+ $checked = 1;
+ if (&EXT('resource.0.gradable',$toolsymb) =~ /^yes$/i) {
+ $use_passback = 1;
+ }
+ }
+ }
+ unless ($checked) {
+ my ($ignore,$cdom,$cnum,$marker) = split(m{/},$uri);
+ $marker=~s/\D//g;
+ if ($marker) {
+ my %toolsettings=&get('exttool_'.$marker,['gradable'],$cdom,$cnum);
+ $use_passback = $toolsettings{'gradable'};
+ }
+ }
+ if ($use_passback) {
+ $filename = '/home/httpd/html/res/lib/templates/LTIpassback.tool';
+ } else {
+ $filename = '/home/httpd/html/res/lib/templates/LTIstandard.tool';
+ }
+ }
+ }
+
{
# Imported parts would go here
my @origfiletagids=();
@@ -12096,23 +13405,31 @@ sub metadata {
# Check metadata for imported file to
# see if it contained response items
#
+ my ($origfile,@libfilekeys);
my %currmetaentry = %metaentry;
- my $libresponseorder = &metadata($location,'responseorder');
- my $origfile;
- if ($libresponseorder ne '') {
- if ($#origfiletagids<0) {
- undef(%importedrespids);
- undef(%importedpartids);
- }
- @{$importedrespids{$importid}} = split(/\s*,\s*/,$libresponseorder);
- if (@{$importedrespids{$importid}} > 0) {
- $importedresponses = 1;
+ @libfilekeys = split(/,/,&metadata($location,'keys',undef,undef,undef,
+ $depthcount+1));
+ if (grep(/^responseorder$/,@libfilekeys)) {
+ my $libresponseorder = &metadata($location,'responseorder',undef,undef,
+ undef,$depthcount+1);
+ if ($libresponseorder ne '') {
+ if ($#origfiletagids<0) {
+ undef(%importedrespids);
+ undef(%importedpartids);
+ }
+ my @respids = split(/\s*,\s*/,$libresponseorder);
+ if (@respids) {
+ $importedrespids{$importid} = join(',',map { $importid.'_'.$_ } @respids);
+ }
+ if ($importedrespids{$importid} ne '') {
+ $importedresponses = 1;
# We need to get the original file and the imported file to get the response order correct
# Load and inspect original file
- if ($#origfiletagids<0) {
- my $origfilelocation=$perlvar{'lonDocRoot'}.&clutter($uri);
- $origfile=&getfile($origfilelocation);
- @origfiletagids=($origfile=~/<((?:\w+)response|import|part)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs);
+ if ($#origfiletagids<0) {
+ my $origfilelocation=$perlvar{'lonDocRoot'}.&clutter($uri);
+ $origfile=&getfile($origfilelocation);
+ @origfiletagids=($origfile=~/<((?:\w+)response|import|part)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs);
+ }
}
}
}
@@ -12120,10 +13437,7 @@ sub metadata {
# hash populated for imported library file
%metaentry = %currmetaentry;
undef(%currmetaentry);
- if ($importmode eq 'problem') {
-# Import as problem/response
- $unikey=&add_prefix_and_part($prefix,$token->[2]->{'part'});
- } elsif ($importmode eq 'part') {
+ if ($importmode eq 'part') {
# Import as part(s)
$importedparts=1;
# We need to get the original file and the imported file to get the part order correct
@@ -12138,10 +13452,23 @@ sub metadata {
@origfiletagids=($origfile=~/<(part|import)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs);
}
}
-
-# Load and inspect imported file
- my $impfile=&getfile($location);
- my @impfilepartids=($impfile=~/