version 1.1417, 2020/01/17 04:51:33
|
version 1.1424, 2020/09/28 00:10:29
|
Line 1230 sub choose_server {
|
Line 1230 sub choose_server {
|
return ($login_host,$hostname,$portal_path,$isredirect,$lowest_load); |
return ($login_host,$hostname,$portal_path,$isredirect,$lowest_load); |
} |
} |
|
|
|
sub get_course_sessions { |
|
my ($cnum,$cdom,$lastactivity) = @_; |
|
my %servers = &internet_dom_servers($cdom); |
|
my %returnhash; |
|
foreach my $server (sort(keys(%servers))) { |
|
my $rep = &reply("coursesessions:$cdom:$cnum:$lastactivity",$server); |
|
my @pairs=split(/\&/,$rep); |
|
unless (($rep eq 'unknown_cmd') || ($rep =~ /^error/)) { |
|
foreach my $item (@pairs) { |
|
my ($key,$value)=split(/=/,$item,2); |
|
$key = &unescape($key); |
|
next if ($key =~ /^error: 2 /); |
|
if (exists($returnhash{$key})) { |
|
next if ($value < $returnhash{$key}); |
|
} |
|
$returnhash{$key}=$value; |
|
} |
|
} |
|
} |
|
return %returnhash; |
|
} |
|
|
# --------------------------------------------- Try to change a user's password |
# --------------------------------------------- Try to change a user's password |
|
|
sub changepass { |
sub changepass { |
Line 3361 sub repcopy {
|
Line 3383 sub repcopy {
|
} |
} |
} |
} |
|
|
|
# ------------------------------------------------- Unsubscribe from a resource |
|
|
|
sub unsubscribe { |
|
my ($fname) = @_; |
|
my $answer; |
|
if ($fname=~/\/(aboutme|syllabus|bulletinboard|smppg)$/) { return $answer; } |
|
$fname=~s/[\n\r]//g; |
|
my $author=$fname; |
|
$author=~s/\/home\/httpd\/html\/res\/([^\/]*)\/([^\/]*).*/$1\/$2/; |
|
my ($udom,$uname)=split(/\//,$author); |
|
my $home=homeserver($uname,$udom); |
|
if ($home eq 'no_host') { |
|
$answer = 'no_host'; |
|
} elsif (grep { $_ eq $home } ¤t_machine_ids()) { |
|
$answer = 'home'; |
|
} else { |
|
my $defdom = $perlvar{'lonDefDomain'}; |
|
if (&will_trust('content',$defdom,$udom)) { |
|
$answer = reply("unsub:$fname",$home); |
|
} else { |
|
$answer = 'untrusted'; |
|
} |
|
} |
|
return $answer; |
|
} |
|
|
# ------------------------------------------------ Get server side include body |
# ------------------------------------------------ Get server side include body |
sub ssi_body { |
sub ssi_body { |
my ($filelink,%form)=@_; |
my ($filelink,%form)=@_; |
Line 3506 sub remove_stale_resfile {
|
Line 3554 sub remove_stale_resfile {
|
$stale = 1; |
$stale = 1; |
} |
} |
if ($stale) { |
if ($stale) { |
unlink($fname); |
if (unlink($fname)) { |
if ($uri!~/\.meta$/) { |
if ($uri!~/\.meta$/) { |
unlink($fname.'.meta'); |
if (-e $fname.'.meta') { |
|
unlink($fname.'.meta'); |
|
} |
|
} |
|
my $unsubresult = &unsubscribe($fname); |
|
unless ($unsubresult eq 'ok') { |
|
&logthis("no unsub of $fname from $homeserver, reason: $unsubresult"); |
|
} |
|
$removed = 1; |
} |
} |
&reply("unsub:$fname",$homeserver); |
|
$removed = 1; |
|
} |
} |
} |
} |
} |
} |
Line 3661 sub can_edit_resource {
|
Line 3715 sub can_edit_resource {
|
$forceedit = 1; |
$forceedit = 1; |
} |
} |
$cfile = $resurl; |
$cfile = $resurl; |
|
} elsif (($resurl =~ m{^/ext/}) && ($symb ne '')) { |
|
my ($map,$id,$res) = &decode_symb($symb); |
|
if ($map =~ /\.page$/) { |
|
$incourse = 1; |
|
if ($env{'form.forceedit'}) { |
|
$forceview = 1; |
|
$cfile = $map; |
|
} else { |
|
$forceedit = 1; |
|
$cfile = '/adm/wrapper'.$resurl; |
|
} |
|
} |
} elsif ($resurl =~ m{^/adm/wrapper/adm/$cdom/$cnum/\d+/ext\.tool$}) { |
} elsif ($resurl =~ m{^/adm/wrapper/adm/$cdom/$cnum/\d+/ext\.tool$}) { |
$incourse = 1; |
$incourse = 1; |
if ($env{'form.forceedit'}) { |
if ($env{'form.forceedit'}) { |
Line 3686 sub can_edit_resource {
|
Line 3752 sub can_edit_resource {
|
$cfile = $template; |
$cfile = $template; |
} |
} |
} elsif (($resurl =~ m{^/adm/wrapper/ext/}) && ($env{'form.folderpath'} =~ /^supplemental/)) { |
} elsif (($resurl =~ m{^/adm/wrapper/ext/}) && ($env{'form.folderpath'} =~ /^supplemental/)) { |
$incourse = 1; |
$incourse = 1; |
if ($env{'form.forceedit'}) { |
if ($env{'form.forceedit'}) { |
$forceview = 1; |
$forceview = 1; |
} else { |
} else { |
$forceedit = 1; |
$forceedit = 1; |
} |
} |
$cfile = $resurl; |
$cfile = $resurl; |
} elsif (($resurl =~ m{^/adm/wrapper/adm/$cdom/$cnum/\d+/ext\.tool$}) && ($env{'form.folderpath'} =~ /^supplemental/)) { |
} elsif (($resurl =~ m{^/adm/wrapper/adm/$cdom/$cnum/\d+/ext\.tool$}) && ($env{'form.folderpath'} =~ /^supplemental/)) { |
$incourse = 1; |
$incourse = 1; |
if ($env{'form.forceedit'}) { |
if ($env{'form.forceedit'}) { |
Line 7970 sub customaccess {
|
Line 8036 sub customaccess {
|
# ------------------------------------------------- Check for a user privilege |
# ------------------------------------------------- Check for a user privilege |
|
|
sub allowed { |
sub allowed { |
my ($priv,$uri,$symb,$role,$clientip,$noblockcheck)=@_; |
my ($priv,$uri,$symb,$role,$clientip,$noblockcheck,$ignorecache)=@_; |
my $ver_orguri=$uri; |
my $ver_orguri=$uri; |
$uri=&deversion($uri); |
$uri=&deversion($uri); |
my $orguri=$uri; |
my $orguri=$uri; |
Line 8201 sub allowed {
|
Line 8267 sub allowed {
|
} elsif ($noblockcheck) { |
} elsif ($noblockcheck) { |
$thisallowed.=$value; |
$thisallowed.=$value; |
} else { |
} else { |
my @blockers = &has_comm_blocking($priv,$symb,$uri); |
my @blockers = &has_comm_blocking($priv,$symb,$uri,$ignorecache); |
if (@blockers > 0) { |
if (@blockers > 0) { |
$thisallowed = 'B'; |
$thisallowed = 'B'; |
} else { |
} else { |
Line 8224 sub allowed {
|
Line 8290 sub allowed {
|
} elsif ($noblockcheck) { |
} elsif ($noblockcheck) { |
$thisallowed='F'; |
$thisallowed='F'; |
} else { |
} else { |
my @blockers = &has_comm_blocking($priv,$symb,$refuri); |
my @blockers = &has_comm_blocking($priv,$symb,$refuri,$ignorecache); |
if (@blockers > 0) { |
if (@blockers > 0) { |
$thisallowed = 'B'; |
$thisallowed = 'B'; |
} else { |
} else { |
Line 8297 sub allowed {
|
Line 8363 sub allowed {
|
if ($noblockcheck) { |
if ($noblockcheck) { |
$thisallowed.=$value; |
$thisallowed.=$value; |
} else { |
} else { |
my @blockers = &has_comm_blocking($priv,$symb,$uri); |
my @blockers = &has_comm_blocking($priv,$symb,$uri,$ignorecache); |
if (@blockers > 0) { |
if (@blockers > 0) { |
$thisallowed = 'B'; |
$thisallowed = 'B'; |
} else { |
} else { |
Line 8310 sub allowed {
|
Line 8376 sub allowed {
|
$checkreferer=0; |
$checkreferer=0; |
} |
} |
} |
} |
|
|
if ($checkreferer) { |
if ($checkreferer) { |
my $refuri=$env{'httpref.'.$orguri}; |
my $refuri=$env{'httpref.'.$orguri}; |
unless ($refuri) { |
unless ($refuri) { |
Line 8342 sub allowed {
|
Line 8408 sub allowed {
|
} elsif ($noblockcheck) { |
} elsif ($noblockcheck) { |
$thisallowed.=$value; |
$thisallowed.=$value; |
} else { |
} else { |
my @blockers = &has_comm_blocking($priv,$symb,$refuri); |
my @blockers = &has_comm_blocking($priv,'',$refuri,$ignorecache); |
if (@blockers > 0) { |
if (@blockers > 0) { |
$thisallowed = 'B'; |
$thisallowed = 'B'; |
} else { |
} else { |
Line 8428 sub allowed {
|
Line 8494 sub allowed {
|
} |
} |
} |
} |
} |
} |
|
|
# |
# |
# Rest of the restrictions depend on selected course |
# Rest of the restrictions depend on selected course |
# |
# |
Line 8597 sub constructaccess {
|
Line 8663 sub constructaccess {
|
# |
# |
# User for whom data are being temporarily cached. |
# User for whom data are being temporarily cached. |
my $cacheduser=''; |
my $cacheduser=''; |
|
# Course for which data are being temporarily cached. |
|
my $cachedcid=''; |
|
# List of blocks passed to &get_commblock_resources(); |
|
my $cachedblocks=''; |
# Cached blockers for this user (a hash of blocking items). |
# Cached blockers for this user (a hash of blocking items). |
my %cachedblockers=(); |
my %cachedblockers=(); |
# When the data were last cached. |
# When the data were last cached. |
Line 8606 sub load_all_blockers {
|
Line 8676 sub load_all_blockers {
|
my ($uname,$udom,$blocks)=@_; |
my ($uname,$udom,$blocks)=@_; |
if (($uname ne '') && ($udom ne '')) { |
if (($uname ne '') && ($udom ne '')) { |
if (($cacheduser eq $uname.':'.$udom) && |
if (($cacheduser eq $uname.':'.$udom) && |
(abs($cachedlast-time)<5)) { |
($cachedcid eq $env{'request.course.id'}) && |
|
(abs($cachedlast-time)<5) && |
|
(((ref($blocks) eq 'HASH') && |
|
($cachedblocks eq join(',',sort(keys(%{$blocks}))))) || |
|
(!ref($blocks) && $cachedblocks eq ''))) { |
return; |
return; |
} |
} |
} |
} |
$cachedlast=time; |
$cachedlast=time; |
$cacheduser=$uname.':'.$udom; |
$cacheduser=$uname.':'.$udom; |
|
$cachedcid=$env{'request.course.id'}; |
%cachedblockers = &get_commblock_resources($blocks); |
%cachedblockers = &get_commblock_resources($blocks); |
|
if ((ref($blocks) eq 'HASH') && (keys(%{$blocks}) > 0)) { |
|
$cachedblocks = join(',',sort(keys(%{$blocks}))); |
|
} |
|
return; |
} |
} |
|
|
sub get_comm_blocks { |
sub get_comm_blocks { |
Line 8750 sub get_commblock_resources {
|
Line 8829 sub get_commblock_resources {
|
} |
} |
|
|
sub has_comm_blocking { |
sub has_comm_blocking { |
my ($priv,$symb,$uri,$blocks) = @_; |
my ($priv,$symb,$uri,$nosymbcache,$blocked,$blocks) = @_; |
my @blockers; |
my @blockers; |
return unless ($env{'request.course.id'}); |
return unless ($env{'request.course.id'}); |
return unless ($priv eq 'bre'); |
return unless ($priv eq 'bre'); |
Line 8760 sub has_comm_blocking {
|
Line 8839 sub has_comm_blocking {
|
return unless (keys(%cachedblockers) > 0); |
return unless (keys(%cachedblockers) > 0); |
my (%possibles,@symbs); |
my (%possibles,@symbs); |
if (!$symb) { |
if (!$symb) { |
$symb = &symbread($uri,1,1,1,\%possibles); |
$symb = &symbread($uri,1,1,'',\%possibles,$nosymbcache); |
} |
} |
if ($symb) { |
if ($symb) { |
@symbs = ($symb); |
@symbs = ($symb); |
Line 8774 sub has_comm_blocking {
|
Line 8853 sub has_comm_blocking {
|
foreach my $block (keys(%cachedblockers)) { |
foreach my $block (keys(%cachedblockers)) { |
if ($block =~ /^firstaccess____(.+)$/) { |
if ($block =~ /^firstaccess____(.+)$/) { |
my $item = $1; |
my $item = $1; |
if (($item eq $map) || ($item eq $symb)) { |
unless ($blocked) { |
$noblock = 1; |
if (($item eq $map) || ($item eq $symb)) { |
last; |
$noblock = 1; |
|
last; |
|
} |
} |
} |
} |
} |
if (ref($cachedblockers{$block}) eq 'HASH') { |
if (ref($cachedblockers{$block}) eq 'HASH') { |
Line 8787 sub has_comm_blocking {
|
Line 8868 sub has_comm_blocking {
|
} |
} |
} |
} |
} |
} |
} |
if (ref($cachedblockers{$block}{'maps'}) eq 'HASH') { |
if (ref($cachedblockers{$block}{'maps'}) eq 'HASH') { |
if ($cachedblockers{$block}{'maps'}{$map}) { |
if ($cachedblockers{$block}{'maps'}{$map}) { |
unless (grep(/^\Q$block\E$/,@blockers)) { |
unless (grep(/^\Q$block\E$/,@blockers)) { |
push(@blockers,$block); |
push(@blockers,$block); |
} |
} |
} |
} |
} |
} |
} |
} |
} |
} |
} |
return if ($noblock); |
unless ($noblock) { |
return @blockers; |
return @blockers; |
|
} |
|
return; |
} |
} |
} |
} |
|
|
Line 10541 sub writecoursepref {
|
Line 10624 sub writecoursepref {
|
|
|
sub createcourse { |
sub createcourse { |
my ($udom,$description,$url,$course_server,$nonstandard,$inst_code, |
my ($udom,$description,$url,$course_server,$nonstandard,$inst_code, |
$course_owner,$crstype,$cnum,$context,$category)=@_; |
$course_owner,$crstype,$cnum,$context,$category,$callercontext)=@_; |
$url=&declutter($url); |
$url=&declutter($url); |
my $cid=''; |
my $cid=''; |
if ($context eq 'requestcourses') { |
if ($context eq 'requestcourses') { |
my $can_create = 0; |
my $can_create = 0; |
my ($ownername,$ownerdom) = split(':',$course_owner); |
my ($ownername,$ownerdom) = split(':',$course_owner); |
if ($udom eq $ownerdom) { |
if ($udom eq $ownerdom) { |
if (&usertools_access($ownername,$ownerdom,$category,undef, |
my $reload; |
|
if (($callercontext eq 'auto') && |
|
($ownerdom eq $env{'user.domain'}) && ($ownername eq $env{'user.name'})) { |
|
$reload = 'reload'; |
|
} |
|
if (&usertools_access($ownername,$ownerdom,$category,$reload, |
$context)) { |
$context)) { |
$can_create = 1; |
$can_create = 1; |
} |
} |
Line 13112 sub symbverify {
|
Line 13200 sub symbverify {
|
|
|
if (tie(%bighash,'GDBM_File',$env{'request.course.fn'}.'.db', |
if (tie(%bighash,'GDBM_File',$env{'request.course.fn'}.'.db', |
&GDBM_READER(),0640)) { |
&GDBM_READER(),0640)) { |
my $noclutter; |
|
if (($thisurl =~ m{^/adm/wrapper/ext/}) || ($thisurl =~ m{^ext/})) { |
if (($thisurl =~ m{^/adm/wrapper/ext/}) || ($thisurl =~ m{^ext/})) { |
$thisurl =~ s/\?.+$//; |
$thisurl =~ s/\?.+$//; |
if ($map =~ m{^uploaded/.+\.page$}) { |
if ($map =~ m{^uploaded/.+\.page$}) { |
$thisurl =~ s{^(/adm/wrapper|)/ext/}{http://}; |
$thisurl =~ s{^(/adm/wrapper|)/ext/}{http://}; |
$thisurl =~ s{^\Qhttp://https://\E}{https://}; |
$thisurl =~ s{^\Qhttp://https://\E}{https://}; |
$noclutter = 1; |
|
} |
} |
} |
} |
my $ids; |
my $ids; |
if ($noclutter) { |
if ($map =~ m{^uploaded/.+\.page$}) { |
$ids=$bighash{'ids_'.$thisurl}; |
$ids=$bighash{'ids_'.&clutter_with_no_wrapper($thisurl)}; |
} else { |
} else { |
$ids=$bighash{'ids_'.&clutter($thisurl)}; |
$ids=$bighash{'ids_'.&clutter($thisurl)}; |
} |
} |
Line 13223 sub deversion {
|
Line 13309 sub deversion {
|
# ------------------------------------------------------ Return symb list entry |
# ------------------------------------------------------ Return symb list entry |
|
|
sub symbread { |
sub symbread { |
my ($thisfn,$donotrecurse,$ignorecachednull,$checkforblock,$possibles)=@_; |
my ($thisfn,$donotrecurse,$ignorecachednull,$checkforblock,$possibles, |
|
$nocache)=@_; |
my $cache_str='request.symbread.cached.'.$thisfn; |
my $cache_str='request.symbread.cached.'.$thisfn; |
if (defined($env{$cache_str})) { |
if (defined($env{$cache_str}) && !$nocache) { |
if ($ignorecachednull) { |
unless (ref($possibles) eq 'HASH') { |
return $env{$cache_str} unless ($env{$cache_str} eq ''); |
if ($ignorecachednull) { |
} else { |
return $env{$cache_str} unless ($env{$cache_str} eq ''); |
return $env{$cache_str}; |
} else { |
|
return $env{$cache_str}; |
|
} |
} |
} |
} |
} |
# no filename provided? try from environment |
# no filename provided? try from environment |
unless ($thisfn) { |
unless ($thisfn) { |
if ($env{'request.symb'}) { |
if ($env{'request.symb'}) { |
return $env{$cache_str}=&symbclean($env{'request.symb'}); |
if ($nocache) { |
|
return &symbclean($env{'request.symb'}); |
|
} else { |
|
return $env{$cache_str}=&symbclean($env{'request.symb'}); |
|
} |
} |
} |
$thisfn=$env{'request.filename'}; |
$thisfn=$env{'request.filename'}; |
} |
} |
Line 13243 sub symbread {
|
Line 13336 sub symbread {
|
# is that filename actually a symb? Verify, clean, and return |
# is that filename actually a symb? Verify, clean, and return |
if ($thisfn=~/\_\_\_\d+\_\_\_(.*)$/) { |
if ($thisfn=~/\_\_\_\d+\_\_\_(.*)$/) { |
if (&symbverify($thisfn,$1)) { |
if (&symbverify($thisfn,$1)) { |
return $env{$cache_str}=&symbclean($thisfn); |
if ($nocache) { |
|
return &symbclean($thisfn); |
|
} else { |
|
return $env{$cache_str}=&symbclean($thisfn); |
|
} |
} |
} |
} |
} |
$thisfn=declutter($thisfn); |
$thisfn=declutter($thisfn); |
Line 13258 sub symbread {
|
Line 13355 sub symbread {
|
if ($targetfn =~ m|^adm/wrapper/(ext/.*)|) { |
if ($targetfn =~ m|^adm/wrapper/(ext/.*)|) { |
$targetfn=$1; |
$targetfn=$1; |
} |
} |
if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db', |
unless ($nocache) { |
&GDBM_READER(),0640)) { |
if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db', |
$syval=$hash{$targetfn}; |
&GDBM_READER(),0640)) { |
untie(%hash); |
$syval=$hash{$targetfn}; |
|
untie(%hash); |
|
} |
|
if ($syval) { |
|
my @blockers = &has_comm_blocking('bre',$syval,$thisfn,$nocache); |
|
if (@blockers) { |
|
$syval=''; |
|
} |
|
} |
} |
} |
# ---------------------------------------------------------- There was an entry |
# ---------------------------------------------------------- There was an entry |
if ($syval) { |
if ($syval) { |
Line 13294 sub symbread {
|
Line 13399 sub symbread {
|
$syval=&encode_symb($bighash{'map_id_'.$mapid}, |
$syval=&encode_symb($bighash{'map_id_'.$mapid}, |
$resid,$thisfn); |
$resid,$thisfn); |
if (ref($possibles) eq 'HASH') { |
if (ref($possibles) eq 'HASH') { |
$possibles->{$syval} = 1; |
unless ($bighash{'randomout_'.$ids} || $env{'request.role.adv'}) { |
|
$possibles->{$syval} = 1; |
|
} |
} |
} |
if ($checkforblock) { |
if ($checkforblock) { |
my @blockers = &has_comm_blocking('bre',$syval,$bighash{'src_'.$ids}); |
unless ($bighash{'randomout_'.$ids} || $env{'request.role.adv'}) { |
if (@blockers) { |
my @blockers = &has_comm_blocking('bre',$syval,$bighash{'src_'.$ids}); |
$syval = ''; |
if (@blockers) { |
return; |
$syval = ''; |
|
return; |
|
} |
} |
} |
} |
} |
} elsif ((!$donotrecurse) || ($checkforblock) || (ref($possibles) eq 'HASH')) { |
} elsif ((!$donotrecurse) || ($checkforblock) || (ref($possibles) eq 'HASH')) { |
Line 13319 sub symbread {
|
Line 13428 sub symbread {
|
if ($bighash{'map_type_'.$mapid} ne 'page') { |
if ($bighash{'map_type_'.$mapid} ne 'page') { |
my $poss_syval=&encode_symb($bighash{'map_id_'.$mapid}, |
my $poss_syval=&encode_symb($bighash{'map_id_'.$mapid}, |
$resid,$thisfn); |
$resid,$thisfn); |
if (ref($possibles) eq 'HASH') { |
next if ($bighash{'randomout_'.$id} && !$env{'request.role.adv'}); |
$possibles->{$syval} = 1; |
next unless ($bighash{'encrypted_'.$id} eq $env{'request.enc'}); |
} |
|
if ($checkforblock) { |
if ($checkforblock) { |
my @blockers = &has_comm_blocking('bre',$poss_syval,$file); |
my @blockers = &has_comm_blocking('bre',$poss_syval,$file); |
unless (@blockers > 0) { |
if (@blockers > 0) { |
|
$syval = ''; |
|
} else { |
$syval = $poss_syval; |
$syval = $poss_syval; |
$realpossible++; |
$realpossible++; |
} |
} |
Line 13332 sub symbread {
|
Line 13442 sub symbread {
|
$syval = $poss_syval; |
$syval = $poss_syval; |
$realpossible++; |
$realpossible++; |
} |
} |
|
if ($syval) { |
|
if (ref($possibles) eq 'HASH') { |
|
$possibles->{$syval} = 1; |
|
} |
|
} |
} |
} |
} |
} |
} |
} |
Line 13344 sub symbread {
|
Line 13459 sub symbread {
|
} |
} |
} |
} |
if ($syval) { |
if ($syval) { |
return $env{$cache_str}=$syval; |
if ($nocache) { |
|
return $syval; |
|
} else { |
|
return $env{$cache_str}=$syval; |
|
} |
} |
} |
} |
} |
&appenv({'request.ambiguous' => $thisfn}); |
&appenv({'request.ambiguous' => $thisfn}); |
|
return '' if ($nocache); |
return $env{$cache_str}=''; |
return $env{$cache_str}=''; |
} |
} |
|
|