--- loncom/lonnet/perl/lonnet.pm 2024/02/28 05:40:11 1.1172.2.146.2.19 +++ loncom/lonnet/perl/lonnet.pm 2022/10/07 14:31:28 1.1494 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.1172.2.146.2.19 2024/02/28 05:40:11 raeburn Exp $ +# $Id: lonnet.pm,v 1.1494 2022/10/07 14:31:28 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; @@ -128,19 +131,19 @@ our @EXPORT = qw(%env); 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 $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,64 +411,8 @@ sub remote_devalidate_cache {
my $items;
return unless (ref($cachekeys) eq 'ARRAY');
my $cachestr = join('&',@{$cachekeys});
- return &reply('devalidatecache:'.&escape($cachestr),$lonhost);
-}
-
-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)");
- }
+ my $response = &reply('devalidatecache:'.&escape($cachestr),$lonhost);
+ return $response;
}
# -------------------------------------------------- Non-critical communication
@@ -451,7 +444,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) {
@@ -525,7 +518,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");
@@ -720,7 +713,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)) {
@@ -992,9 +985,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);
@@ -1030,7 +1023,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;
}
@@ -1111,7 +1104,6 @@ sub delusersession {
return;
}
-
# check if user's browser sent load balancer cookie and server still has session
# and is not overloaded.
sub check_for_balancer_cookie {
@@ -1219,7 +1211,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);
@@ -1227,12 +1219,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) {
@@ -1412,7 +1404,7 @@ sub can_switchserver {
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'}})) {
@@ -1448,8 +1440,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'}}))) {
@@ -1541,7 +1533,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') {
@@ -1590,14 +1582,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)) {
@@ -1609,7 +1601,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 {
@@ -1617,7 +1609,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') {
@@ -1670,7 +1662,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 {
@@ -1678,7 +1670,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') {
@@ -1754,12 +1746,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'};
@@ -1768,20 +1760,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 {
@@ -1799,7 +1795,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 '') {
@@ -1853,6 +1849,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;
@@ -1878,17 +1969,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);
@@ -1897,9 +2004,9 @@ sub idget {
for ($i=0;$i<=$#ids;$i++) {
if ($answer[$i]) {
$returnhash{$ids[$i]}=&unescape($answer[$i]);
- }
+ }
}
- }
+ }
return %returnhash;
}
@@ -1914,60 +2021,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) = @_;
@@ -2132,7 +2320,7 @@ sub restore_dom {
}
}
my %returnhash=();
- unless (($answer eq '') || ($answer eq 'con_lost') || ($answer eq 'refused') ||
+ 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);
@@ -2157,7 +2345,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'});
@@ -2208,10 +2396,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;
}
}
@@ -2260,10 +2447,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);
@@ -2355,7 +2541,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 '') {
@@ -2399,7 +2585,7 @@ sub get_multiple_instusers {
} else {
($outcome,my $userdata) = split(/=/,$response,2);
if ($outcome eq 'ok') {
- $results = &thaw_unescape($userdata);
+ $results = &thaw_unescape($userdata);
}
}
}
@@ -2426,14 +2612,14 @@ sub inst_rulecheck {
$response=&unescape(&reply('instidrulecheck:'.&escape($udom).
':'.&escape($id).':'.$rulestr,
$homeserver));
- } elsif ($item eq 'unamemap') {
- $response=&unescape(&reply('instunamemapcheck:'.
- &escape($udom).':'.&escape($uname).
- ':'.$rulestr,$homeserver));
} elsif ($item eq 'selfcreate') {
$response=&unescape(&reply('instselfcreatecheck:'.
&escape($udom).':'.&escape($uname).
':'.$rulestr,$homeserver));
+ } elsif ($item eq 'unamemap') {
+ $response=&unescape(&reply('instunamemapcheck:'.
+ &escape($udom).':'.&escape($uname).
+ ':'.$rulestr,$homeserver));
}
if ($response ne 'refused') {
my @pairs=split(/\&/,$response);
@@ -2465,7 +2651,7 @@ sub inst_userrules {
$homeserver);
} elsif ($check eq 'unamemap') {
$response=&reply('unamemaprules:'.&escape($udom),
- $homeserver);
+ $homeserver);
} else {
$response=&reply('instuserrules:'.&escape($udom),
$homeserver);
@@ -2507,15 +2693,13 @@ 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','authordefaults',
- 'selfenrollment','coursecategories',
- 'autoenroll','helpsettings',
- 'wafproxy','ltisec','toolsec',
- 'domexttool','exttool'],$domain);
- my @coursetypes = ('official','unofficial','community','textbook');
+ 'requestauthor','selfenrollment',
+ 'coursecategories','ssl','autoenroll',
+ 'trust','helpsettings','wafproxy','ltisec'],$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'};
@@ -2551,21 +2735,10 @@ 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};
}
}
- if (ref($domconfig{'authordefaults'}) eq 'HASH') {
- foreach my $item ('nocodemirror','copyright','sourceavail','domcoordacc','editors') {
- if ($item eq 'editors') {
- if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
- $domdefaults{$item} = join(',',@{$domconfig{'authordefaults'}{'editors'}});
- }
- } else {
- $domdefaults{$item} = $domconfig{'authordefaults'}{$item};
- }
- }
- }
if (ref($domconfig{'requestauthor'}) eq 'HASH') {
$domdefaults{'requestauthor'} = $domconfig{'requestauthor'};
}
@@ -2575,6 +2748,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'};
@@ -2590,25 +2764,12 @@ sub get_domain_defaults {
if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
$domdefaults{$type.'quota'} = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
}
- if (ref($domconfig{'coursedefaults'}{'coursequota'}) eq 'HASH') {
- $domdefaults{$type.'coursequota'} = $domconfig{'coursedefaults'}{'coursequota'}{$type};
- }
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') {
@@ -2679,6 +2840,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'};
@@ -2704,29 +2884,7 @@ sub get_domain_defaults {
}
if (ref($domconfig{'ltisec'}{'private'}) eq 'HASH') {
if (ref($domconfig{'ltisec'}{'private'}{'keys'}) eq 'ARRAY') {
- $domdefaults{'ltiprivhosts'} = $domconfig{'ltisec'}{'private'}{'keys'};
- }
- }
- if (ref($domconfig{'ltisec'}{'suggested'}) eq 'HASH') {
- my %suggestions = %{$domconfig{'ltisec'}{'suggested'}};
- foreach my $item (keys(%{$domconfig{'ltisec'}{'suggested'}})) {
- unless (ref($domconfig{'ltisec'}{'suggested'}{$item}) eq 'HASH') {
- delete($suggestions{$item});
- }
- }
- if (keys(%suggestions)) {
- $domdefaults{'linkprotsuggested'} = \%suggestions;
- }
- }
- }
- 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'};
+ $domdefaults{'privhosts'} = $domconfig{'ltisec'}{'private'}{'keys'};
}
}
}
@@ -2749,7 +2907,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;
}
@@ -2766,7 +2924,6 @@ 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,
@@ -2794,29 +2951,6 @@ sub retrieve_instcodes {
return $totcodes;
}
-# --------------------------------------------- Get domain config for passwords
-
-sub get_passwdconf {
- my ($dom) = @_;
- my (%passwdconf,$gotconf,$lookup);
- my ($result,$cached)=&is_cached_new('passwdconf',$dom);
- if (defined($cached)) {
- if (ref($result) eq 'HASH') {
- %passwdconf = %{$result};
- $gotconf = 1;
- }
- }
- unless ($gotconf) {
- my %domconfig = &get_dom('configuration',['passwords'],$dom);
- if (ref($domconfig{'passwords'}) eq 'HASH') {
- %passwdconf = %{$domconfig{'passwords'}};
- }
- my $cachetime = 24*60*60;
- &do_cache_new('passwdconf',$dom,\%passwdconf,$cachetime);
- }
- return %passwdconf;
-}
-
sub course_portal_url {
my ($cnum,$cdom,$r) = @_;
my $chome = &homeserver($cnum,$cdom);
@@ -2828,7 +2962,7 @@ sub course_portal_url {
if ($domdefaults{'portal_def'}) {
$firsturl = $domdefaults{'portal_def'};
} else {
- my $alias = &Apache::lonnet::use_proxy_alias($r,$chome);
+ my $alias = &use_proxy_alias($r,$chome);
$hostname = $alias if ($alias ne '');
$firsturl = $protocol.'://'.$hostname;
}
@@ -2855,6 +2989,29 @@ sub url_prefix {
return $prefix;
}
+# --------------------------------------------- Get domain config for passwords
+
+sub get_passwdconf {
+ my ($dom) = @_;
+ my (%passwdconf,$gotconf,$lookup);
+ my ($result,$cached)=&is_cached_new('passwdconf',$dom);
+ if (defined($cached)) {
+ if (ref($result) eq 'HASH') {
+ %passwdconf = %{$result};
+ $gotconf = 1;
+ }
+ }
+ unless ($gotconf) {
+ my %domconfig = &get_dom('configuration',['passwords'],$dom);
+ if (ref($domconfig{'passwords'}) eq 'HASH') {
+ %passwdconf = %{$domconfig{'passwords'}};
+ }
+ my $cachetime = 24*60*60;
+ &do_cache_new('passwdconf',$dom,\%passwdconf,$cachetime);
+ }
+ return %passwdconf;
+}
+
# --------------------------------------------------- Assign a key to a student
sub assign_access_key {
@@ -3003,7 +3160,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'}";
}
@@ -3100,9 +3257,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()];
@@ -3203,14 +3358,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));
@@ -3220,7 +3375,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));
@@ -3232,14 +3387,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') {
@@ -3364,9 +3519,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;
@@ -3376,7 +3535,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(
@@ -3406,7 +3570,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;
}
@@ -3449,7 +3618,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 {
@@ -3461,7 +3630,7 @@ sub absolute_url {
return $lcproto.$hostname;
}
}
- }
+ }
return $protocol.$host_name;
}
@@ -3485,41 +3654,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 {
@@ -3529,9 +3687,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 {
@@ -3539,8 +3696,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).
@@ -3560,11 +3718,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];
@@ -3627,7 +3783,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.
@@ -3635,12 +3791,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
#
@@ -3667,7 +3823,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;
@@ -3696,7 +3852,7 @@ 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) {
@@ -3729,7 +3885,7 @@ sub can_edit_resource {
$forceedit = 1;
}
$cfile = $resurl;
- } elsif (($resurl ne '') && (&is_on_map($resurl))) {
+ } elsif (($resurl ne '') && (&is_on_map($resurl))) {
if ($resurl =~ m{^/adm/$match_domain/$match_username/\d+/smppg|bulletinboard$}) {
$incourse = 1;
if ($env{'form.forceedit'}) {
@@ -3780,7 +3936,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;
@@ -3840,7 +3996,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)) {
@@ -3867,9 +4023,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;
@@ -4063,7 +4219,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;
@@ -4112,7 +4268,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, toollogo or ''.
+# canceloverwrite, scantron 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
@@ -4120,12 +4276,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
-# $destuname - username for permanent storage of uploaded file
-# $destudom - domain for permanaent storage of uploaded file
+# $desuname - username for permanent storage of uploaded file
+# $dsetudom - 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
@@ -4170,7 +4326,7 @@ sub userfileupload {
} else {
$docudom = $env{'user.domain'};
}
- if ($destuname =~ /^$match_username$/) {
+ if ($destuname =~ /^$match_username$/) {
$docuname = $destuname;
} else {
$docuname = $env{'user.name'};
@@ -4335,24 +4491,11 @@ sub finishuserfileupload {
if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
my $input = $filepath.'/'.$file;
my $output = $filepath.'/'.'tn-'.$file;
- my $makethumb;
my $thumbsize = $thumbwidth.'x'.$thumbheight;
- 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;
- }
+ my @args = ('convert','-sample',$thumbsize,$input,$output);
+ system({$args[0]} @args);
+ if (-e $filepath.'/'.'tn-'.$file) {
+ $fetchthumb = 1;
}
}
@@ -4409,7 +4552,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') {
@@ -4584,37 +4727,13 @@ 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'};
@@ -12527,17 +12705,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); }
@@ -12545,15 +12727,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); }
@@ -12570,10 +12755,10 @@ sub EXT {
if ($thisparm) { return &get_reply([$thisparm,'resource']); }
}
# ------------------------------------------ fourth, look in resource metadata
-
+
my $what = $spacequalifierrest;
- $what=~s/\./\_/;
- my $filename;
+ $what=~s/\./\_/;
+ my $filename;
if (!$symbparm) { $symbparm=&symbread(); }
if ($symbparm) {
$filename=(&decode_symb($symbparm))[2];
@@ -12594,8 +12779,10 @@ sub EXT {
$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); }
}
@@ -12656,19 +12843,24 @@ 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;
}
@@ -12815,11 +13007,11 @@ sub metadata {
# gradable in the exttool_$marker.db file for the tool instance
# is retrieved via &get().
#
-# When lonuserstate::traceroute() calls lonnet::EXT() for
+# When lonuserstate::traceroute() calls lonnet::EXT() for
# hiddenresource and encrypturl (during course initialization)
-# the map-level parameter for resource.0.gradable included in the
+# 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
+# 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.
#
@@ -12967,23 +13159,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);
+ }
}
}
}
@@ -12991,10 +13191,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
@@ -13009,10 +13206,23 @@ sub metadata {
@origfiletagids=($origfile=~/<(part|import)[^>]*id\s*=\s*[\"\']([^\"\']+)[\"\'][^>]*>/gs);
}
}
-
-# Load and inspect imported file
- my $impfile=&getfile($location);
- my @impfilepartids=($impfile=~/