version 1.1172.2.93.4.3, 2017/10/14 21:27:51
|
version 1.1237, 2013/09/01 22:39:48
|
Line 75 use LWP::UserAgent();
|
Line 75 use LWP::UserAgent();
|
use HTTP::Date; |
use HTTP::Date; |
use Image::Magick; |
use Image::Magick; |
|
|
use vars qw(%perlvar %spareid %pr %prp $memcache %packagetab $tmpdir |
|
|
use Encode; |
|
|
|
use vars qw(%perlvar %spareid %pr %prp $memcache %packagetab $tmpdir $apache |
$_64bit %env %protocol %loncaparevs %serverhomeIDs %needsrelease |
$_64bit %env %protocol %loncaparevs %serverhomeIDs %needsrelease |
%managerstab); |
%managerstab); |
|
|
Line 89 use GDBM_File;
|
Line 92 use GDBM_File;
|
use HTML::LCParser; |
use HTML::LCParser; |
use Fcntl qw(:flock); |
use Fcntl qw(:flock); |
use Storable qw(thaw nfreeze); |
use Storable qw(thaw nfreeze); |
use Time::HiRes qw( sleep gettimeofday tv_interval ); |
use Time::HiRes qw( gettimeofday tv_interval ); |
use Cache::Memcached; |
use Cache::Memcached; |
use Digest::MD5; |
use Digest::MD5; |
use Math::Random; |
use Math::Random; |
Line 102 use LONCAPA::Lond;
|
Line 105 use LONCAPA::Lond;
|
use File::Copy; |
use File::Copy; |
|
|
my $readit; |
my $readit; |
my $max_connection_retries = 20; # Or some such value. |
my $max_connection_retries = 10; # Or some such value. |
|
|
require Exporter; |
require Exporter; |
|
|
our @ISA = qw (Exporter); |
our @ISA = qw (Exporter); |
our @EXPORT = qw(%env); |
our @EXPORT = qw(%env); |
|
|
|
|
# ------------------------------------ Logging (parameters, docs, slots, roles) |
# ------------------------------------ Logging (parameters, docs, slots, roles) |
{ |
{ |
my $logid; |
my $logid; |
Line 123 our @EXPORT = qw(%env);
|
Line 127 our @EXPORT = qw(%env);
|
$logid ++; |
$logid ++; |
my $now = time(); |
my $now = time(); |
my $id=$now.'00000'.$$.'00000'.$logid; |
my $id=$now.'00000'.$$.'00000'.$logid; |
my $logentry = { |
my $logentry = { |
$id => { |
$id => { |
'exe_uname' => $env{'user.name'}, |
'exe_uname' => $env{'user.name'}, |
'exe_udom' => $env{'user.domain'}, |
'exe_udom' => $env{'user.domain'}, |
'exe_time' => $now, |
'exe_time' => $now, |
'exe_ip' => $ENV{'REMOTE_ADDR'}, |
'exe_ip' => $ENV{'REMOTE_ADDR'}, |
'delflag' => $delflag, |
'delflag' => $delflag, |
'logentry' => $storehash, |
'logentry' => $storehash, |
'uname' => $uname, |
'uname' => $uname, |
'udom' => $udom, |
'udom' => $udom, |
} |
} |
}; |
}; |
return &put('nohist_'.$hash_name,$logentry,$cdom,$cnum); |
return &put('nohist_'.$hash_name,$logentry,$cdom,$cnum); |
} |
} |
} |
} |
|
|
Line 352 sub get_remote_globals {
|
Line 356 sub get_remote_globals {
|
} |
} |
|
|
sub remote_devalidate_cache { |
sub remote_devalidate_cache { |
my ($lonhost,$cachekeys) = @_; |
my ($lonhost,$name,$id) = @_; |
my $items; |
my $response = &reply('devalidatecache:'.&escape($name).':'.&escape($id),$lonhost); |
return unless (ref($cachekeys) eq 'ARRAY'); |
return $response; |
my $cachestr = join('&',@{$cachekeys}); |
|
return &reply('devalidatecache:'.&escape($cachestr),$lonhost); |
|
} |
} |
|
|
# -------------------------------------------------- Non-critical communication |
# -------------------------------------------------- Non-critical communication |
Line 370 sub subreply {
|
Line 372 sub subreply {
|
|
|
my $lockfile=$peerfile.".lock"; |
my $lockfile=$peerfile.".lock"; |
while (-e $lockfile) { # Need to wait for the lockfile to disappear. |
while (-e $lockfile) { # Need to wait for the lockfile to disappear. |
sleep(0.1); |
sleep(1); |
} |
} |
# At this point, either a loncnew parent is listening or an old lonc |
# At this point, either a loncnew parent is listening or an old lonc |
# or loncnew child is listening so we can connect or everything's dead. |
# or loncnew child is listening so we can connect or everything's dead. |
Line 388 sub subreply {
|
Line 390 sub subreply {
|
} else { |
} else { |
&create_connection(&hostname($server),$server); |
&create_connection(&hostname($server),$server); |
} |
} |
sleep(0.1); # Try again later if failed connection. |
sleep(1); # Try again later if failed connection. |
} |
} |
my $answer; |
my $answer; |
if ($client) { |
if ($client) { |
Line 417 sub reply {
|
Line 419 sub reply {
|
|
|
sub reconlonc { |
sub reconlonc { |
my ($lonid) = @_; |
my ($lonid) = @_; |
|
my $hostname = &hostname($lonid); |
if ($lonid) { |
if ($lonid) { |
my $hostname = &hostname($lonid); |
|
my $peerfile="$perlvar{'lonSockDir'}/$hostname"; |
my $peerfile="$perlvar{'lonSockDir'}/$hostname"; |
if ($hostname && -e $peerfile) { |
if ($hostname && -e $peerfile) { |
&logthis("Trying to reconnect lonc for $lonid ($hostname)"); |
&logthis("Trying to reconnect lonc for $lonid ($hostname)"); |
Line 464 sub critical {
|
Line 466 sub critical {
|
} |
} |
my $answer=reply($cmd,$server); |
my $answer=reply($cmd,$server); |
if ($answer eq 'con_lost') { |
if ($answer eq 'con_lost') { |
&reconlonc($server); |
&reconlonc("$perlvar{'lonSockDir'}/$server"); |
my $answer=reply($cmd,$server); |
my $answer=reply($cmd,$server); |
if ($answer eq 'con_lost') { |
if ($answer eq 'con_lost') { |
my $now=time; |
my $now=time; |
Line 481 sub critical {
|
Line 483 sub critical {
|
close($dfh); |
close($dfh); |
} |
} |
} |
} |
sleep 1; |
sleep 2; |
my $wcmd=''; |
my $wcmd=''; |
{ |
{ |
my $dfh; |
my $dfh; |
Line 601 sub transfer_profile_to_env {
|
Line 603 sub transfer_profile_to_env {
|
|
|
# ---------------------------------------------------- Check for valid session |
# ---------------------------------------------------- Check for valid session |
sub check_for_valid_session { |
sub check_for_valid_session { |
my ($r,$name,$userhashref,$domref) = @_; |
my ($r,$name) = @_; |
my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); |
my %cookies=CGI::Cookie->parse($r->header_in('Cookie')); |
if ($name eq '') { |
if ($name eq '') { |
$name = 'lonID'; |
$name = 'lonID'; |
Line 616 sub check_for_valid_session {
|
Line 618 sub check_for_valid_session {
|
} else { |
} else { |
$lonidsdir=$r->dir_config('lonIDsDir'); |
$lonidsdir=$r->dir_config('lonIDsDir'); |
} |
} |
if (!-e "$lonidsdir/$handle.id") { |
return undef if (!-e "$lonidsdir/$handle.id"); |
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)) { |
|
$$domref = $possudom; |
|
} |
|
} |
|
return undef; |
|
} |
|
|
|
my $opened = open(my $idf,'+<',"$lonidsdir/$handle.id"); |
my $opened = open(my $idf,'+<',"$lonidsdir/$handle.id"); |
return undef if (!$opened); |
return undef if (!$opened); |
Line 641 sub check_for_valid_session {
|
Line 634 sub check_for_valid_session {
|
|| !defined($disk_env{'user.domain'})) { |
|| !defined($disk_env{'user.domain'})) { |
return undef; |
return undef; |
} |
} |
|
if (($r->user() eq '') && ($apache >= 2.4)) { |
if (ref($userhashref) eq 'HASH') { |
if ($disk_env{'user.domain'} eq $r->dir_config('lonDefDomain')) { |
$userhashref->{'name'} = $disk_env{'user.name'}; |
$r->user($disk_env{'user.name'}); |
$userhashref->{'domain'} = $disk_env{'user.domain'}; |
} else { |
|
$r->user($disk_env{'user.name'}.':'.$disk_env{'user.domain'}); |
|
} |
} |
} |
|
|
return $handle; |
return $handle; |
} |
} |
|
|
Line 680 sub appenv {
|
Line 674 sub appenv {
|
if (($key =~ /^user\.role/) || ($key =~ /^user\.priv/)) { |
if (($key =~ /^user\.role/) || ($key =~ /^user\.priv/)) { |
$refused = 1; |
$refused = 1; |
if (ref($roles) eq 'ARRAY') { |
if (ref($roles) eq 'ARRAY') { |
my ($type,$role) = ($key =~ m{^user\.(role|priv)\.(.+?)\./}); |
my ($type,$role) = ($key =~ /^user\.(role|priv)\.([^.]+)\./); |
if (grep(/^\Q$role\E$/,@{$roles})) { |
if (grep(/^\Q$role\E$/,@{$roles})) { |
$refused = 0; |
$refused = 0; |
} |
} |
Line 853 sub spareserver {
|
Line 847 sub spareserver {
|
if (ref($spareshash) eq 'HASH') { |
if (ref($spareshash) eq 'HASH') { |
if (ref($spareshash->{'primary'}) eq 'ARRAY') { |
if (ref($spareshash->{'primary'}) eq 'ARRAY') { |
foreach my $try_server (@{ $spareshash->{'primary'} }) { |
foreach my $try_server (@{ $spareshash->{'primary'} }) { |
next unless (&spare_can_host($udom,$uint_dom,$remotesessions, |
if ($uint_dom) { |
$try_server)); |
next unless (&spare_can_host($udom,$uint_dom,$remotesessions, |
|
$try_server)); |
|
} |
($spare_server, $lowest_load) = |
($spare_server, $lowest_load) = |
&compare_server_load($try_server, $spare_server, $lowest_load); |
&compare_server_load($try_server, $spare_server, $lowest_load); |
} |
} |
Line 865 sub spareserver {
|
Line 861 sub spareserver {
|
if (!$found_server) { |
if (!$found_server) { |
if (ref($spareshash->{'default'}) eq 'ARRAY') { |
if (ref($spareshash->{'default'}) eq 'ARRAY') { |
foreach my $try_server (@{ $spareshash->{'default'} }) { |
foreach my $try_server (@{ $spareshash->{'default'} }) { |
next unless (&spare_can_host($udom,$uint_dom, |
if ($uint_dom) { |
$remotesessions,$try_server)); |
next unless (&spare_can_host($udom,$uint_dom, |
|
$remotesessions,$try_server)); |
|
} |
($spare_server, $lowest_load) = |
($spare_server, $lowest_load) = |
&compare_server_load($try_server, $spare_server, $lowest_load); |
&compare_server_load($try_server, $spare_server, $lowest_load); |
} |
} |
Line 890 sub spareserver {
|
Line 888 sub spareserver {
|
} |
} |
|
|
sub compare_server_load { |
sub compare_server_load { |
my ($try_server, $spare_server, $lowest_load, $required) = @_; |
my ($try_server, $spare_server, $lowest_load) = @_; |
|
|
if ($required) { |
|
my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/); |
|
my $remoterev = &get_server_loncaparev(undef,$try_server); |
|
my ($major,$minor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/); |
|
if (($major eq '' && $minor eq '') || |
|
(($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) { |
|
return ($spare_server,$lowest_load); |
|
} |
|
} |
|
|
|
my $loadans = &reply('load', $try_server); |
my $loadans = &reply('load', $try_server); |
my $userloadans = &reply('userload',$try_server); |
my $userloadans = &reply('userload',$try_server); |
Line 961 sub has_user_session {
|
Line 949 sub has_user_session {
|
# --------- determine least loaded server in a user's domain which allows login |
# --------- determine least loaded server in a user's domain which allows login |
|
|
sub choose_server { |
sub choose_server { |
my ($udom,$checkloginvia,$required,$skiploadbal) = @_; |
my ($udom,$checkloginvia) = @_; |
my %domconfhash = &Apache::loncommon::get_domainconf($udom); |
my %domconfhash = &Apache::loncommon::get_domainconf($udom); |
my %servers = &get_servers($udom); |
my %servers = &get_servers($udom); |
my $lowest_load = 30000; |
my $lowest_load = 30000; |
my ($login_host,$hostname,$portal_path,$isredirect,$balancers); |
my ($login_host,$hostname,$portal_path,$isredirect); |
if ($skiploadbal) { |
|
($balancers,my $cached)=&is_cached_new('loadbalancing',$udom); |
|
unless (defined($cached)) { |
|
my $cachetime = 60*60*24; |
|
my %domconfig = |
|
&Apache::lonnet::get_dom('configuration',['loadbalancing'],$udom); |
|
if (ref($domconfig{'loadbalancing'}) eq 'HASH') { |
|
$balancers = &do_cache_new('loadbalancing',$udom,$domconfig{'loadbalancing'}, |
|
$cachetime); |
|
} |
|
} |
|
} |
|
foreach my $lonhost (keys(%servers)) { |
foreach my $lonhost (keys(%servers)) { |
my $loginvia; |
my $loginvia; |
if ($skiploadbal) { |
|
if (ref($balancers) eq 'HASH') { |
|
next if (exists($balancers->{$lonhost})); |
|
} |
|
} |
|
if ($checkloginvia) { |
if ($checkloginvia) { |
$loginvia = $domconfhash{$udom.'.login.loginvia_'.$lonhost}; |
$loginvia = $domconfhash{$udom.'.login.loginvia_'.$lonhost}; |
if ($loginvia) { |
if ($loginvia) { |
my ($server,$path) = split(/:/,$loginvia); |
my ($server,$path) = split(/:/,$loginvia); |
($login_host, $lowest_load) = |
($login_host, $lowest_load) = |
&compare_server_load($server, $login_host, $lowest_load, $required); |
&compare_server_load($server, $login_host, $lowest_load); |
if ($login_host eq $server) { |
if ($login_host eq $server) { |
$portal_path = $path; |
$portal_path = $path; |
$isredirect = 1; |
$isredirect = 1; |
} |
} |
} else { |
} else { |
($login_host, $lowest_load) = |
($login_host, $lowest_load) = |
&compare_server_load($lonhost, $login_host, $lowest_load, $required); |
&compare_server_load($lonhost, $login_host, $lowest_load); |
if ($login_host eq $lonhost) { |
if ($login_host eq $lonhost) { |
$portal_path = ''; |
$portal_path = ''; |
$isredirect = ''; |
$isredirect = ''; |
Line 1005 sub choose_server {
|
Line 976 sub choose_server {
|
} |
} |
} else { |
} else { |
($login_host, $lowest_load) = |
($login_host, $lowest_load) = |
&compare_server_load($lonhost, $login_host, $lowest_load, $required); |
&compare_server_load($lonhost, $login_host, $lowest_load); |
} |
} |
} |
} |
if ($login_host ne '') { |
if ($login_host ne '') { |
$hostname = &hostname($login_host); |
$hostname = &hostname($login_host); |
} |
} |
return ($login_host,$hostname,$portal_path,$isredirect,$lowest_load); |
return ($login_host,$hostname,$portal_path,$isredirect); |
} |
} |
|
|
# --------------------------------------------- Try to change a user's password |
# --------------------------------------------- Try to change a user's password |
Line 1178 sub can_host_session {
|
Line 1149 sub can_host_session {
|
sub spare_can_host { |
sub spare_can_host { |
my ($udom,$uint_dom,$remotesessions,$try_server)=@_; |
my ($udom,$uint_dom,$remotesessions,$try_server)=@_; |
my $canhost=1; |
my $canhost=1; |
my $try_server_hostname = &hostname($try_server); |
my @intdoms; |
my $serverhomeID = &get_server_homeID($try_server_hostname); |
my $internet_names = &Apache::lonnet::get_internet_names($try_server); |
my $serverhomedom = &host_domain($serverhomeID); |
if (ref($internet_names) eq 'ARRAY') { |
my %defdomdefaults = &get_domain_defaults($serverhomedom); |
@intdoms = @{$internet_names}; |
if (ref($defdomdefaults{'offloadnow'}) eq 'HASH') { |
} |
if ($defdomdefaults{'offloadnow'}{$try_server}) { |
unless (grep(/^\Q$uint_dom\E$/,@intdoms)) { |
$canhost = 0; |
my $serverhomeID = &Apache::lonnet::get_server_homeID($try_server); |
} |
my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID); |
} |
my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom); |
if (($canhost) && ($uint_dom)) { |
my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$try_server); |
my @intdoms; |
$canhost = &can_host_session($udom,$try_server,$remoterev, |
my $internet_names = &get_internet_names($try_server); |
$remotesessions, |
if (ref($internet_names) eq 'ARRAY') { |
$defdomdefaults{'hostedsessions'}); |
@intdoms = @{$internet_names}; |
|
} |
|
unless (grep(/^\Q$uint_dom\E$/,@intdoms)) { |
|
my $remoterev = &get_server_loncaparev(undef,$try_server); |
|
$canhost = &can_host_session($udom,$try_server,$remoterev, |
|
$remotesessions, |
|
$defdomdefaults{'hostedsessions'}); |
|
} |
|
} |
} |
return $canhost; |
return $canhost; |
} |
} |
Line 1283 sub get_lonbalancer_config {
|
Line 1246 sub get_lonbalancer_config {
|
} |
} |
|
|
sub check_loadbalancing { |
sub check_loadbalancing { |
my ($uname,$udom,$caller) = @_; |
my ($uname,$udom) = @_; |
my ($is_balancer,$currtargets,$currrules,$dom_in_use,$homeintdom, |
my ($is_balancer,$currtargets,$currrules,$dom_in_use,$homeintdom, |
$rule_in_effect,$offloadto,$otherserver); |
$rule_in_effect,$offloadto,$otherserver); |
my $lonhost = $perlvar{'lonHostID'}; |
my $lonhost = $perlvar{'lonHostID'}; |
Line 1292 sub check_loadbalancing {
|
Line 1255 sub check_loadbalancing {
|
my $uintdom = &Apache::lonnet::internet_dom($uprimary_id); |
my $uintdom = &Apache::lonnet::internet_dom($uprimary_id); |
my $intdom = &Apache::lonnet::internet_dom($lonhost); |
my $intdom = &Apache::lonnet::internet_dom($lonhost); |
my $serverhomedom = &host_domain($lonhost); |
my $serverhomedom = &host_domain($lonhost); |
my $domneedscache; |
|
my $cachetime = 60*60*24; |
my $cachetime = 60*60*24; |
|
|
if (($uintdom ne '') && ($uintdom eq $intdom)) { |
if (($uintdom ne '') && ($uintdom eq $intdom)) { |
Line 1307 sub check_loadbalancing {
|
Line 1270 sub check_loadbalancing {
|
&Apache::lonnet::get_dom('configuration',['loadbalancing'],$dom_in_use); |
&Apache::lonnet::get_dom('configuration',['loadbalancing'],$dom_in_use); |
if (ref($domconfig{'loadbalancing'}) eq 'HASH') { |
if (ref($domconfig{'loadbalancing'}) eq 'HASH') { |
$result = &do_cache_new('loadbalancing',$dom_in_use,$domconfig{'loadbalancing'},$cachetime); |
$result = &do_cache_new('loadbalancing',$dom_in_use,$domconfig{'loadbalancing'},$cachetime); |
} else { |
|
$domneedscache = $dom_in_use; |
|
} |
} |
} |
} |
if (ref($result) eq 'HASH') { |
if (ref($result) eq 'HASH') { |
($is_balancer,$currtargets,$currrules) = |
($is_balancer,$currtargets,$currrules) = |
&check_balancer_result($result,@hosts); |
&check_balancer_result($result,@hosts); |
if ($is_balancer) { |
if ($is_balancer) { |
if (ref($currrules) eq 'HASH') { |
if (ref($currrules) eq 'HASH') { |
Line 1362 sub check_loadbalancing {
|
Line 1323 sub check_loadbalancing {
|
} |
} |
} |
} |
} elsif (($homeintdom) && ($udom ne $serverhomedom)) { |
} elsif (($homeintdom) && ($udom ne $serverhomedom)) { |
($result,$cached)=&is_cached_new('loadbalancing',$serverhomedom); |
my ($result,$cached)=&is_cached_new('loadbalancing',$serverhomedom); |
unless (defined($cached)) { |
unless (defined($cached)) { |
my %domconfig = |
my %domconfig = |
&Apache::lonnet::get_dom('configuration',['loadbalancing'],$serverhomedom); |
&Apache::lonnet::get_dom('configuration',['loadbalancing'],$serverhomedom); |
if (ref($domconfig{'loadbalancing'}) eq 'HASH') { |
if (ref($domconfig{'loadbalancing'}) eq 'HASH') { |
$result = &do_cache_new('loadbalancing',$serverhomedom,$domconfig{'loadbalancing'},$cachetime); |
$result = &do_cache_new('loadbalancing',$dom_in_use,$domconfig{'loadbalancing'},$cachetime); |
} else { |
|
$domneedscache = $serverhomedom; |
|
} |
} |
} |
} |
if (ref($result) eq 'HASH') { |
if (ref($result) eq 'HASH') { |
($is_balancer,$currtargets,$currrules) = |
($is_balancer,$currtargets,$currrules) = |
&check_balancer_result($result,@hosts); |
&check_balancer_result($result,@hosts); |
if ($is_balancer) { |
if ($is_balancer) { |
if (ref($currrules) eq 'HASH') { |
if (ref($currrules) eq 'HASH') { |
Line 1389 sub check_loadbalancing {
|
Line 1348 sub check_loadbalancing {
|
$is_balancer = 1; |
$is_balancer = 1; |
$offloadto = &this_host_spares($dom_in_use); |
$offloadto = &this_host_spares($dom_in_use); |
} |
} |
unless (defined($cached)) { |
|
$domneedscache = $serverhomedom; |
|
} |
|
} |
} |
} else { |
} else { |
if ($perlvar{'lonBalancer'} eq 'yes') { |
if ($perlvar{'lonBalancer'} eq 'yes') { |
$is_balancer = 1; |
$is_balancer = 1; |
$offloadto = &this_host_spares($dom_in_use); |
$offloadto = &this_host_spares($dom_in_use); |
} |
} |
unless (defined($cached)) { |
|
$domneedscache = $serverhomedom; |
|
} |
|
} |
|
if ($domneedscache) { |
|
&do_cache_new('loadbalancing',$domneedscache,$is_balancer,$cachetime); |
|
} |
} |
if ($is_balancer) { |
if ($is_balancer) { |
my $lowest_load = 30000; |
my $lowest_load = 30000; |
Line 1434 sub check_loadbalancing {
|
Line 1384 sub check_loadbalancing {
|
} |
} |
} |
} |
} |
} |
unless ($caller eq 'login') { |
if (($otherserver ne '') && (grep(/^\Q$otherserver\E$/,@hosts))) { |
if (($otherserver ne '') && (grep(/^\Q$otherserver\E$/,@hosts))) { |
$is_balancer = 0; |
$is_balancer = 0; |
if ($uname ne '' && $udom ne '') { |
if ($uname ne '' && $udom ne '') { |
if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) { |
if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) { |
|
|
&appenv({'user.loadbalexempt' => $lonhost, |
&appenv({'user.loadbalexempt' => $lonhost, |
'user.loadbalcheck.time' => time}); |
'user.loadbalcheck.time' => time}); |
|
} |
|
} |
} |
} |
} |
} |
} |
Line 1578 sub idget {
|
Line 1526 sub idget {
|
|
|
my %servers = &get_servers($udom,'library'); |
my %servers = &get_servers($udom,'library'); |
foreach my $tryserver (keys(%servers)) { |
foreach my $tryserver (keys(%servers)) { |
my $idlist=join('&', map { &escape($_); } @ids); |
my $idlist=join('&',@ids); |
$idlist=~tr/A-Z/a-z/; |
$idlist=~tr/A-Z/a-z/; |
my $reply=&reply("idget:$udom:".$idlist,$tryserver); |
my $reply=&reply("idget:$udom:".$idlist,$tryserver); |
my @answer=(); |
my @answer=(); |
Line 1588 sub idget {
|
Line 1536 sub idget {
|
my $i; |
my $i; |
for ($i=0;$i<=$#ids;$i++) { |
for ($i=0;$i<=$#ids;$i++) { |
if ($answer[$i]) { |
if ($answer[$i]) { |
$returnhash{$ids[$i]}=&unescape($answer[$i]); |
$returnhash{$ids[$i]}=$answer[$i]; |
} |
} |
} |
} |
} |
} |
Line 1630 sub idput {
|
Line 1578 sub idput {
|
} |
} |
} |
} |
|
|
# ---------------------------------------- Delete unwanted IDs from ids.db file |
# ---------------------------------------- Delete unwanted IDs from ids.db file |
|
|
sub iddel { |
sub iddel { |
my ($udom,$idshashref,$uhome)=@_; |
my ($udom,$idshashref,$uhome)=@_; |
Line 1675 sub dump_dom {
|
Line 1623 sub dump_dom {
|
|
|
sub get_dom { |
sub get_dom { |
my ($namespace,$storearr,$udom,$uhome)=@_; |
my ($namespace,$storearr,$udom,$uhome)=@_; |
return if ($udom eq 'public'); |
|
my $items=''; |
my $items=''; |
foreach my $item (@$storearr) { |
foreach my $item (@$storearr) { |
$items.=&escape($item).'&'; |
$items.=&escape($item).'&'; |
Line 1683 sub get_dom {
|
Line 1630 sub get_dom {
|
$items=~s/\&$//; |
$items=~s/\&$//; |
if (!$udom) { |
if (!$udom) { |
$udom=$env{'user.domain'}; |
$udom=$env{'user.domain'}; |
return if ($udom eq 'public'); |
|
if (defined(&domain($udom,'primary'))) { |
if (defined(&domain($udom,'primary'))) { |
$uhome=&domain($udom,'primary'); |
$uhome=&domain($udom,'primary'); |
} else { |
} else { |
Line 1697 sub get_dom {
|
Line 1643 sub get_dom {
|
} |
} |
} |
} |
if ($udom && $uhome && ($uhome ne 'no_host')) { |
if ($udom && $uhome && ($uhome ne 'no_host')) { |
my $rep; |
my $rep=&reply("getdom:$udom:$namespace:$items",$uhome); |
if ($namespace =~ /^enc/) { |
|
$rep=&reply("encrypt:egetdom:$udom:$namespace:$items",$uhome); |
|
} else { |
|
$rep=&reply("getdom:$udom:$namespace:$items",$uhome); |
|
} |
|
my %returnhash; |
my %returnhash; |
if ($rep eq '' || $rep =~ /^error: 2 /) { |
if ($rep eq '' || $rep =~ /^error: 2 /) { |
return %returnhash; |
return %returnhash; |
Line 1746 sub put_dom {
|
Line 1687 sub put_dom {
|
$items.=&escape($item).'='.&freeze_escape($$storehash{$item}).'&'; |
$items.=&escape($item).'='.&freeze_escape($$storehash{$item}).'&'; |
} |
} |
$items=~s/\&$//; |
$items=~s/\&$//; |
if ($namespace =~ /^enc/) { |
return &reply("putdom:$udom:$namespace:$items",$uhome); |
return &reply("encrypt:putdom:$udom:$namespace:$items",$uhome); |
|
} else { |
|
return &reply("putdom:$udom:$namespace:$items",$uhome); |
|
} |
|
} else { |
} else { |
&logthis("put_dom failed - no homeserver and/or domain"); |
&logthis("put_dom failed - no homeserver and/or domain"); |
} |
} |
Line 1796 sub retrieve_inst_usertypes {
|
Line 1733 sub retrieve_inst_usertypes {
|
my %domdefs = &Apache::lonnet::get_domain_defaults($udom); |
my %domdefs = &Apache::lonnet::get_domain_defaults($udom); |
if ((ref($domdefs{'inststatustypes'}) eq 'HASH') && |
if ((ref($domdefs{'inststatustypes'}) eq 'HASH') && |
(ref($domdefs{'inststatusorder'}) eq 'ARRAY')) { |
(ref($domdefs{'inststatusorder'}) eq 'ARRAY')) { |
return ($domdefs{'inststatustypes'},$domdefs{'inststatusorder'}); |
%returnhash = %{$domdefs{'inststatustypes'}}; |
|
@order = @{$domdefs{'inststatusorder'}}; |
} else { |
} else { |
if (defined(&domain($udom,'primary'))) { |
if (defined(&domain($udom,'primary'))) { |
my $uhome=&domain($udom,'primary'); |
my $uhome=&domain($udom,'primary'); |
my $rep=&reply("inst_usertypes:$udom",$uhome); |
my $rep=&reply("inst_usertypes:$udom",$uhome); |
if ($rep =~ /^(con_lost|error|no_such_host|refused)/) { |
if ($rep =~ /^(con_lost|error|no_such_host|refused)/) { |
&logthis("retrieve_inst_usertypes failed - $rep returned from $uhome in domain: $udom"); |
&logthis("get_dom failed - $rep returned from $uhome in domain: $udom"); |
return (\%returnhash,\@order); |
return (\%returnhash,\@order); |
} |
} |
my ($hashitems,$orderitems) = split(/:/,$rep); |
my ($hashitems,$orderitems) = split(/:/,$rep); |
Line 1818 sub retrieve_inst_usertypes {
|
Line 1756 sub retrieve_inst_usertypes {
|
push(@order,&unescape($item)); |
push(@order,&unescape($item)); |
} |
} |
} else { |
} else { |
&logthis("retrieve_inst_usertypes failed - no primary domain server for $udom"); |
&logthis("get_dom failed - no primary domain server for $udom"); |
} |
} |
return (\%returnhash,\@order); |
|
} |
} |
|
return (\%returnhash,\@order); |
} |
} |
|
|
sub is_domainimage { |
sub is_domainimage { |
my ($url) = @_; |
my ($url) = @_; |
if ($url=~m-^/+res/+($match_domain)/+\1\-domainconfig/+(img|logo|domlogo)/+[^/]-) { |
if ($url=~m-^/+res/+($match_domain)/+\1\-domainconfig/+(img|logo|domlogo)/+-) { |
if (&domain($1) ne '') { |
if (&domain($1) ne '') { |
return '1'; |
return '1'; |
} |
} |
Line 1847 sub inst_directory_query {
|
Line 1785 sub inst_directory_query {
|
&escape($srch->{'srchtype'}),$homeserver); |
&escape($srch->{'srchtype'}),$homeserver); |
my $host=&hostname($homeserver); |
my $host=&hostname($homeserver); |
if ($queryid !~/^\Q$host\E\_/) { |
if ($queryid !~/^\Q$host\E\_/) { |
&logthis('institutional directory search invalid queryid: '.$queryid.' for host: '.$homeserver.' in domain '.$udom); |
&logthis('instituional directory search invalid queryid: '.$queryid.' for host: '.$homeserver.'in domain '.$udom); |
return; |
return; |
} |
} |
my $response = &get_query_reply($queryid); |
my $response = &get_query_reply($queryid); |
Line 1967 sub get_instuser {
|
Line 1905 sub get_instuser {
|
return ($outcome,%userinfo); |
return ($outcome,%userinfo); |
} |
} |
|
|
sub get_multiple_instusers { |
|
my ($udom,$users,$caller) = @_; |
|
my ($outcome,$results); |
|
if (ref($users) eq 'HASH') { |
|
my $count = keys(%{$users}); |
|
my $requested = &freeze_escape($users); |
|
my $homeserver = &domain($udom,'primary'); |
|
if ($homeserver ne '') { |
|
my $queryid=&reply('querysend:getmultinstusers:::'.$caller.'='.$requested,$homeserver); |
|
my $host=&hostname($homeserver); |
|
if ($queryid !~/^\Q$host\E\_/) { |
|
&logthis('get_multiple_instusers invalid queryid: '.$queryid. |
|
' for host: '.$homeserver.'in domain '.$udom); |
|
return ($outcome,$results); |
|
} |
|
my $response = &get_query_reply($queryid); |
|
my $maxtries = 5; |
|
if ($count > 100) { |
|
$maxtries = 1+int($count/20); |
|
} |
|
my $tries = 1; |
|
while (($response=~/^timeout/) && ($tries <= $maxtries)) { |
|
$response = &get_query_reply($queryid); |
|
$tries ++; |
|
} |
|
if ($response eq '') { |
|
$results = {}; |
|
foreach my $key (keys(%{$users})) { |
|
my ($uname,$id); |
|
if ($caller eq 'id') { |
|
$id = $key; |
|
} else { |
|
$uname = $key; |
|
} |
|
my ($resp,%info) = &get_instuser($udom,$uname,$id); |
|
$outcome = $resp; |
|
if ($resp eq 'ok') { |
|
%{$results} = (%{$results}, %info); |
|
} else { |
|
last; |
|
} |
|
} |
|
} elsif(!&error($response) && ($response ne 'refused')) { |
|
if (($response eq 'unavailable') || ($response eq 'invalid') || ($response eq 'timeout')) { |
|
$outcome = $response; |
|
} else { |
|
($outcome,my $userdata) = split(/=/,$response,2); |
|
if ($outcome eq 'ok') { |
|
$results = &thaw_unescape($userdata); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
return ($outcome,$results); |
|
} |
|
|
|
sub inst_rulecheck { |
sub inst_rulecheck { |
my ($udom,$uname,$id,$item,$rules) = @_; |
my ($udom,$uname,$id,$item,$rules) = @_; |
my %returnhash; |
my %returnhash; |
Line 2103 sub inst_userrules {
|
Line 1984 sub inst_userrules {
|
# ------------- Get Authentication, Language and User Tools Defaults for Domain |
# ------------- Get Authentication, Language and User Tools Defaults for Domain |
|
|
sub get_domain_defaults { |
sub get_domain_defaults { |
my ($domain,$ignore_cache) = @_; |
my ($domain) = @_; |
return if (($domain eq '') || ($domain eq 'public')); |
|
my $cachetime = 60*60*24; |
my $cachetime = 60*60*24; |
unless ($ignore_cache) { |
my ($result,$cached)=&is_cached_new('domdefaults',$domain); |
my ($result,$cached)=&is_cached_new('domdefaults',$domain); |
if (defined($cached)) { |
if (defined($cached)) { |
if (ref($result) eq 'HASH') { |
if (ref($result) eq 'HASH') { |
return %{$result}; |
return %{$result}; |
|
} |
|
} |
} |
} |
} |
my %domdefaults; |
my %domdefaults; |
Line 2119 sub get_domain_defaults {
|
Line 1997 sub get_domain_defaults {
|
&Apache::lonnet::get_dom('configuration',['defaults','quotas', |
&Apache::lonnet::get_dom('configuration',['defaults','quotas', |
'requestcourses','inststatus', |
'requestcourses','inststatus', |
'coursedefaults','usersessions', |
'coursedefaults','usersessions', |
'requestauthor','selfenrollment', |
'requestauthor'],$domain); |
'coursecategories','autoenroll', |
|
'helpsettings'],$domain); |
|
my @coursetypes = ('official','unofficial','community','textbook'); |
|
if (ref($domconfig{'defaults'}) eq 'HASH') { |
if (ref($domconfig{'defaults'}) eq 'HASH') { |
$domdefaults{'lang_def'} = $domconfig{'defaults'}{'lang_def'}; |
$domdefaults{'lang_def'} = $domconfig{'defaults'}{'lang_def'}; |
$domdefaults{'auth_def'} = $domconfig{'defaults'}{'auth_def'}; |
$domdefaults{'auth_def'} = $domconfig{'defaults'}{'auth_def'}; |
Line 2130 sub get_domain_defaults {
|
Line 2005 sub get_domain_defaults {
|
$domdefaults{'timezone_def'} = $domconfig{'defaults'}{'timezone_def'}; |
$domdefaults{'timezone_def'} = $domconfig{'defaults'}{'timezone_def'}; |
$domdefaults{'datelocale_def'} = $domconfig{'defaults'}{'datelocale_def'}; |
$domdefaults{'datelocale_def'} = $domconfig{'defaults'}{'datelocale_def'}; |
$domdefaults{'portal_def'} = $domconfig{'defaults'}{'portal_def'}; |
$domdefaults{'portal_def'} = $domconfig{'defaults'}{'portal_def'}; |
$domdefaults{'intauth_cost'} = $domconfig{'defaults'}{'intauth_cost'}; |
|
$domdefaults{'intauth_switch'} = $domconfig{'defaults'}{'intauth_switch'}; |
|
$domdefaults{'intauth_check'} = $domconfig{'defaults'}{'intauth_check'}; |
|
} else { |
} else { |
$domdefaults{'lang_def'} = &domain($domain,'lang_def'); |
$domdefaults{'lang_def'} = &domain($domain,'lang_def'); |
$domdefaults{'auth_def'} = &domain($domain,'auth_def'); |
$domdefaults{'auth_def'} = &domain($domain,'auth_def'); |
Line 2155 sub get_domain_defaults {
|
Line 2027 sub get_domain_defaults {
|
} |
} |
} |
} |
if (ref($domconfig{'requestcourses'}) eq 'HASH') { |
if (ref($domconfig{'requestcourses'}) eq 'HASH') { |
foreach my $item ('official','unofficial','community','textbook') { |
foreach my $item ('official','unofficial','community') { |
$domdefaults{$item} = $domconfig{'requestcourses'}{$item}; |
$domdefaults{$item} = $domconfig{'requestcourses'}{$item}; |
} |
} |
} |
} |
Line 2163 sub get_domain_defaults {
|
Line 2035 sub get_domain_defaults {
|
$domdefaults{'requestauthor'} = $domconfig{'requestauthor'}; |
$domdefaults{'requestauthor'} = $domconfig{'requestauthor'}; |
} |
} |
if (ref($domconfig{'inststatus'}) eq 'HASH') { |
if (ref($domconfig{'inststatus'}) eq 'HASH') { |
foreach my $item ('inststatustypes','inststatusorder','inststatusguest') { |
foreach my $item ('inststatustypes','inststatusorder') { |
$domdefaults{$item} = $domconfig{'inststatus'}{$item}; |
$domdefaults{$item} = $domconfig{'inststatus'}{$item}; |
} |
} |
} |
} |
if (ref($domconfig{'coursedefaults'}) eq 'HASH') { |
if (ref($domconfig{'coursedefaults'}) eq 'HASH') { |
$domdefaults{'usejsme'} = $domconfig{'coursedefaults'}{'usejsme'}; |
$domdefaults{'canuse_pdfforms'} = $domconfig{'coursedefaults'}{'canuse_pdfforms'}; |
$domdefaults{'uselcmath'} = $domconfig{'coursedefaults'}{'uselcmath'}; |
if (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') { |
if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') { |
$domdefaults{'officialcredits'} = $domconfig{'coursedefaults'}{'coursecredits'}{'official'}; |
$domdefaults{'postsubmit'} = $domconfig{'coursedefaults'}{'postsubmit'}{'client'}; |
$domdefaults{'unofficialcredits'} = $domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'}; |
} |
} |
foreach my $type (@coursetypes) { |
if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') { |
if (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') { |
$domdefaults{'officialquota'} = $domconfig{'coursedefaults'}{'uploadquota'}{'official'}; |
unless ($type eq 'community') { |
$domdefaults{'unofficialquota'} = $domconfig{'coursedefaults'}{'uploadquota'}{'unofficial'}; |
$domdefaults{$type.'credits'} = $domconfig{'coursedefaults'}{'coursecredits'}{$type}; |
$domdefaults{'communityquota'} = $domconfig{'coursedefaults'}{'uploadquota'}{'community'}; |
} |
|
} |
|
if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') { |
|
$domdefaults{$type.'quota'} = $domconfig{'coursedefaults'}{'uploadquota'}{$type}; |
|
} |
|
if ($domdefaults{'postsubmit'} eq 'on') { |
|
if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') { |
|
$domdefaults{$type.'postsubtimeout'} = |
|
$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}{$type}; |
|
} |
|
} |
|
} |
|
if (ref($domconfig{'coursedefaults'}{'canclone'}) eq 'HASH') { |
|
if (ref($domconfig{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') { |
|
my @clonecodes = @{$domconfig{'coursedefaults'}{'canclone'}{'instcode'}}; |
|
if (@clonecodes) { |
|
$domdefaults{'canclone'} = join('+',@clonecodes); |
|
} |
|
} |
|
} elsif ($domconfig{'coursedefaults'}{'canclone'}) { |
|
$domdefaults{'canclone'}=$domconfig{'coursedefaults'}{'canclone'}; |
|
} |
} |
} |
} |
if (ref($domconfig{'usersessions'}) eq 'HASH') { |
if (ref($domconfig{'usersessions'}) eq 'HASH') { |
Line 2207 sub get_domain_defaults {
|
Line 2058 sub get_domain_defaults {
|
if (ref($domconfig{'usersessions'}{'hosted'}) eq 'HASH') { |
if (ref($domconfig{'usersessions'}{'hosted'}) eq 'HASH') { |
$domdefaults{'hostedsessions'} = $domconfig{'usersessions'}{'hosted'}; |
$domdefaults{'hostedsessions'} = $domconfig{'usersessions'}{'hosted'}; |
} |
} |
if (ref($domconfig{'usersessions'}{'offloadnow'}) eq 'HASH') { |
|
$domdefaults{'offloadnow'} = $domconfig{'usersessions'}{'offloadnow'}; |
|
} |
|
} |
|
if (ref($domconfig{'selfenrollment'}) eq 'HASH') { |
|
if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') { |
|
my @settings = ('types','registered','enroll_dates','access_dates','section', |
|
'approval','limit'); |
|
foreach my $type (@coursetypes) { |
|
if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') { |
|
my @mgrdc = (); |
|
foreach my $item (@settings) { |
|
if ($domconfig{'selfenrollment'}{'admin'}{$type}{$item} eq '0') { |
|
push(@mgrdc,$item); |
|
} |
|
} |
|
if (@mgrdc) { |
|
$domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc); |
|
} |
|
} |
|
} |
|
} |
|
if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') { |
|
foreach my $type (@coursetypes) { |
|
if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') { |
|
foreach my $item (keys(%{$domconfig{'selfenrollment'}{'default'}{$type}})) { |
|
$domdefaults{$type.'selfenroll'.$item} = $domconfig{'selfenrollment'}{'default'}{$type}{$item}; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
if (ref($domconfig{'coursecategories'}) eq 'HASH') { |
|
$domdefaults{'catauth'} = 'std'; |
|
$domdefaults{'catunauth'} = 'std'; |
|
if ($domconfig{'coursecategories'}{'auth'}) { |
|
$domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'}; |
|
} |
|
if ($domconfig{'coursecategories'}{'unauth'}) { |
|
$domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'}; |
|
} |
|
} |
|
if (ref($domconfig{'autoenroll'}) eq 'HASH') { |
|
$domdefaults{'autofailsafe'} = $domconfig{'autoenroll'}{'autofailsafe'}; |
|
} |
|
if (ref($domconfig{'helpsettings'}) eq 'HASH') { |
|
$domdefaults{'submitbugs'} = $domconfig{'helpsettings'}{'submitbugs'}; |
|
if (ref($domconfig{'helpsettings'}{'adhoc'}) eq 'HASH') { |
|
$domdefaults{'adhocroles'} = $domconfig{'helpsettings'}{'adhoc'}; |
|
} |
|
} |
} |
&do_cache_new('domdefaults',$domain,\%domdefaults,$cachetime); |
&do_cache_new('domdefaults',$domain,\%domdefaults,$cachetime); |
return %domdefaults; |
return %domdefaults; |
} |
} |
|
|
sub course_portal_url { |
|
my ($cnum,$cdom) = @_; |
|
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 { |
|
$firsturl = $protocol.'://'.$hostname; |
|
} |
|
return $firsturl; |
|
} |
|
|
|
# --------------------------------------------------- Assign a key to a student |
# --------------------------------------------------- Assign a key to a student |
|
|
sub assign_access_key { |
sub assign_access_key { |
Line 2514 sub make_key {
|
Line 2299 sub make_key {
|
sub devalidate_cache_new { |
sub devalidate_cache_new { |
my ($name,$id,$debug) = @_; |
my ($name,$id,$debug) = @_; |
if ($debug) { &Apache::lonnet::logthis("deleting $name:$id"); } |
if ($debug) { &Apache::lonnet::logthis("deleting $name:$id"); } |
my $remembered_id=$name.':'.$id; |
|
$id=&make_key($name,$id); |
$id=&make_key($name,$id); |
$memcache->delete($id); |
$memcache->delete($id); |
delete($remembered{$remembered_id}); |
delete($remembered{$id}); |
delete($accessed{$remembered_id}); |
delete($accessed{$id}); |
} |
} |
|
|
sub is_cached_new { |
sub is_cached_new { |
my ($name,$id,$debug) = @_; |
my ($name,$id,$debug) = @_; |
my $remembered_id=$name.':'.$id; # this is to avoid make_key (which is slow) for |
$id=&make_key($name,$id); |
# keys in %remembered hash, which persists for |
if (exists($remembered{$id})) { |
# duration of request (no restriction on key length). |
if ($debug) { &Apache::lonnet::logthis("Early return $id of $remembered{$id} "); } |
if (exists($remembered{$remembered_id})) { |
$accessed{$id}=[&gettimeofday()]; |
if ($debug) { &Apache::lonnet::logthis("Early return $remembered_id of $remembered{$remembered_id} "); } |
|
$accessed{$remembered_id}=[&gettimeofday()]; |
|
$hits++; |
$hits++; |
return ($remembered{$remembered_id},1); |
return ($remembered{$id},1); |
} |
} |
$id=&make_key($name,$id); |
|
my $value = $memcache->get($id); |
my $value = $memcache->get($id); |
if (!(defined($value))) { |
if (!(defined($value))) { |
if ($debug) { &Apache::lonnet::logthis("getting $id is not defined"); } |
if ($debug) { &Apache::lonnet::logthis("getting $id is not defined"); } |
Line 2542 sub is_cached_new {
|
Line 2323 sub is_cached_new {
|
if ($debug) { &Apache::lonnet::logthis("getting $id is __undef__"); } |
if ($debug) { &Apache::lonnet::logthis("getting $id is __undef__"); } |
$value=undef; |
$value=undef; |
} |
} |
&make_room($remembered_id,$value,$debug); |
&make_room($id,$value,$debug); |
if ($debug) { &Apache::lonnet::logthis("getting $id is $value"); } |
if ($debug) { &Apache::lonnet::logthis("getting $id is $value"); } |
return ($value,1); |
return ($value,1); |
} |
} |
|
|
sub do_cache_new { |
sub do_cache_new { |
my ($name,$id,$value,$time,$debug) = @_; |
my ($name,$id,$value,$time,$debug) = @_; |
my $remembered_id=$name.':'.$id; |
|
$id=&make_key($name,$id); |
$id=&make_key($name,$id); |
my $setvalue=$value; |
my $setvalue=$value; |
if (!defined($setvalue)) { |
if (!defined($setvalue)) { |
Line 2565 sub do_cache_new {
|
Line 2345 sub do_cache_new {
|
$memcache->disconnect_all(); |
$memcache->disconnect_all(); |
} |
} |
# need to make a copy of $value |
# need to make a copy of $value |
&make_room($remembered_id,$value,$debug); |
&make_room($id,$value,$debug); |
return $value; |
return $value; |
} |
} |
|
|
sub make_room { |
sub make_room { |
my ($remembered_id,$value,$debug)=@_; |
my ($id,$value,$debug)=@_; |
|
|
$remembered{$remembered_id}= (ref($value)) ? &Storable::dclone($value) |
$remembered{$id}= (ref($value)) ? &Storable::dclone($value) |
: $value; |
: $value; |
if ($to_remember<0) { return; } |
if ($to_remember<0) { return; } |
$accessed{$remembered_id}=[&gettimeofday()]; |
$accessed{$id}=[&gettimeofday()]; |
if (scalar(keys(%remembered)) <= $to_remember) { return; } |
if (scalar(keys(%remembered)) <= $to_remember) { return; } |
my $to_kick; |
my $to_kick; |
my $max_time=0; |
my $max_time=0; |
Line 2869 sub ssi {
|
Line 2649 sub ssi {
|
&Apache::lonenc::check_encrypt(\$fn); |
&Apache::lonenc::check_encrypt(\$fn); |
if (%form) { |
if (%form) { |
$request=new HTTP::Request('POST',&absolute_url().$fn); |
$request=new HTTP::Request('POST',&absolute_url().$fn); |
$request->content(join('&',map { |
$request->content(join('&',map { &escape($_).'='.&escape($form{$_}) } keys(%form))); |
my $name = escape($_); |
|
"$name=" . ( ref($form{$_}) eq 'ARRAY' |
|
? join("&$name=", map {escape($_) } @{$form{$_}}) |
|
: &escape($form{$_}) ); |
|
} keys(%form))); |
|
} else { |
} else { |
$request=new HTTP::Request('GET',&absolute_url().$fn); |
$request=new HTTP::Request('GET',&absolute_url().$fn); |
} |
} |
|
|
$request->header(Cookie => $ENV{'HTTP_COOKIE'}); |
$request->header(Cookie => $ENV{'HTTP_COOKIE'}); |
my $response= $ua->request($request); |
my $response= $ua->request($request); |
|
my $content = $response->content; |
|
|
|
|
if (wantarray) { |
if (wantarray) { |
return ($response->content, $response); |
return ($content, $response); |
} else { |
} else { |
return $response->content; |
return $content; |
} |
} |
} |
} |
|
|
Line 2916 sub allowuploaded {
|
Line 2694 sub allowuploaded {
|
# |
# |
# Determine if the current user should be able to edit a particular resource, |
# Determine if the current user should be able to edit a particular resource, |
# when viewing in course context. |
# 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. |
# Functions. |
# (b) When displaying folder contents in course editor, used to determine if |
# (b) When displaying folder contents in course editor, used to determine if |
# "Edit" link will be displayed alongside resource. |
# "Edit" link will be displayed alongside resource. |
Line 2924 sub allowuploaded {
|
Line 2702 sub allowuploaded {
|
# input: six args -- filename (decluttered), course number, course domain, |
# input: six args -- filename (decluttered), course number, course domain, |
# url, symb (if registered) and group (if this is a group |
# url, symb (if registered) and group (if this is a group |
# item -- e.g., bulletin board, group page etc.). |
# 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 |
# $cfile -- url for file editing if editable on current server |
# $home -- homeserver of resource (i.e., for author if published, |
# $home -- homeserver of resource (i.e., for author if published, |
# or course if uploaded.). |
# or course if uploaded.). |
# $switchserver -- 1 if server switch will be needed. |
# $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 |
# $forceview -- 1 if icon/link should be to go to view mode |
# |
# |
|
|
Line 3018 sub can_edit_resource {
|
Line 2796 sub can_edit_resource {
|
$forceedit = 1; |
$forceedit = 1; |
} |
} |
$cfile = $resurl; |
$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$}) { |
if ($resurl =~ m{^/adm/$match_domain/$match_username/\d+/smppg|bulletinboard$}) { |
$incourse = 1; |
$incourse = 1; |
if ($env{'form.forceedit'}) { |
if ($env{'form.forceedit'}) { |
Line 3038 sub can_edit_resource {
|
Line 2816 sub can_edit_resource {
|
$forceedit = 1; |
$forceedit = 1; |
} |
} |
$cfile = $resurl; |
$cfile = $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$}) { |
} elsif ($resurl =~ m{^/?adm/viewclasslist$}) { |
$incourse = 1; |
$incourse = 1; |
if ($env{'form.forceedit'}) { |
if ($env{'form.forceedit'}) { |
Line 3057 sub can_edit_resource {
|
Line 2827 sub can_edit_resource {
|
} |
} |
} elsif ($resurl eq '/res/lib/templates/simpleproblem.problem/smpedit') { |
} elsif ($resurl eq '/res/lib/templates/simpleproblem.problem/smpedit') { |
my $template = '/res/lib/templates/simpleproblem.problem'; |
my $template = '/res/lib/templates/simpleproblem.problem'; |
if (&is_on_map($template)) { |
if (&is_on_map($template)) { |
$incourse = 1; |
$incourse = 1; |
$forceview = 1; |
$forceview = 1; |
$cfile = $template; |
$cfile = $template; |
Line 3070 sub can_edit_resource {
|
Line 2840 sub can_edit_resource {
|
$forceedit = 1; |
$forceedit = 1; |
} |
} |
$cfile = $resurl; |
$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'})) { |
} elsif (($resurl eq '/adm/extresedit') && ($symb || $env{'form.folderpath'})) { |
$incourse = 1; |
$incourse = 1; |
$forceview = 1; |
$forceview = 1; |
Line 3087 sub can_edit_resource {
|
Line 2849 sub can_edit_resource {
|
$cfile = &clutter($res); |
$cfile = &clutter($res); |
} else { |
} else { |
$cfile = $env{'form.suppurl'}; |
$cfile = $env{'form.suppurl'}; |
my $escfile = &unescape($cfile); |
$cfile =~ s{^http://}{}; |
if ($escfile =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) { |
$cfile = '/adm/wrapper/ext/'.$cfile; |
$cfile = '/adm/wrapper'.$escfile; |
|
} else { |
|
$escfile =~ s{^http://}{}; |
|
$cfile = &escape("/adm/wrapper/ext/$escfile"); |
|
} |
|
} |
} |
} elsif ($resurl =~ m{^/?adm/viewclasslist$}) { |
} elsif ($resurl =~ m{^/?adm/viewclasslist$}) { |
if ($env{'form.forceedit'}) { |
if ($env{'form.forceedit'}) { |
Line 3117 sub can_edit_resource {
|
Line 2874 sub can_edit_resource {
|
$cfile=$file; |
$cfile=$file; |
} |
} |
} |
} |
if (($cfile ne '') && (!$incourse || $uploaded) && |
if (($cfile ne '') && (!$incourse || $uploaded) && |
(($home ne '') && ($home ne 'no_host'))) { |
(($home ne '') && ($home ne 'no_host'))) { |
my @ids=¤t_machine_ids(); |
my @ids=¤t_machine_ids(); |
unless (grep(/^\Q$home\E$/,@ids)) { |
unless (grep(/^\Q$home\E$/,@ids)) { |
Line 3144 sub in_course {
|
Line 2901 sub in_course {
|
if ($hideprivileged) { |
if ($hideprivileged) { |
my $skipuser; |
my $skipuser; |
my %coursehash = &coursedescription($cdom.'_'.$cnum); |
my %coursehash = &coursedescription($cdom.'_'.$cnum); |
my @possdoms = ($cdom); |
my @possdoms = ($cdom); |
if ($coursehash{'checkforpriv'}) { |
if ($coursehash{'checkforpriv'}) { |
push(@possdoms,split(/,/,$coursehash{'checkforpriv'})); |
push(@possdoms,split(/,/,$coursehash{'checkforpriv'})); |
} |
} |
if (&privileged($uname,$udom,\@possdoms)) { |
if (&privileged($uname,$udom,\@possdoms)) { |
$skipuser = 1; |
$skipuser = 1; |
Line 3650 sub extract_embedded_items {
|
Line 3407 sub extract_embedded_items {
|
} |
} |
if (lc($tagname) eq 'a') { |
if (lc($tagname) eq 'a') { |
unless (($attr->{'href'} =~ /^#/) || ($attr->{'href'} eq '')) { |
unless (($attr->{'href'} =~ /^#/) || ($attr->{'href'} eq '')) { |
&add_filetype($allfiles,$attr->{'href'},'href'); |
&add_filetype($allfiles,$attr->{'href'},'href'); |
} |
} |
} |
} |
if (lc($tagname) eq 'script') { |
if (lc($tagname) eq 'script') { |
Line 3739 sub extract_embedded_items {
|
Line 3496 sub extract_embedded_items {
|
} |
} |
} |
} |
} |
} |
if (lc($tagname) eq 'iframe') { |
|
my $src = $attr->{'src'} ; |
|
if (($src ne '') && ($src !~ m{^(/|https?://)})) { |
|
&add_filetype($allfiles,$src,'src'); |
|
} elsif ($src =~ m{^/}) { |
|
if ($env{'request.course.id'}) { |
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
|
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
|
my $url = &hreflocation('',$fullpath); |
|
if ($url =~ m{^/uploaded/$cdom/$cnum/docs/(\w+/\d+)/}) { |
|
my $relpath = $1; |
|
if ($src =~ m{^/uploaded/$cdom/$cnum/docs/\Q$relpath\E/(.+)$}) { |
|
&add_filetype($allfiles,$1,'src'); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
if ($t->[4] =~ m{/>$}) { |
if ($t->[4] =~ m{/>$}) { |
pop(@state); |
pop(@state); |
} |
} |
} elsif ($t->[0] eq 'E') { |
} elsif ($t->[0] eq 'E') { |
my ($tagname) = ($t->[1]); |
my ($tagname) = ($t->[1]); |
Line 3975 sub flushcourselogs {
|
Line 3714 sub flushcourselogs {
|
} |
} |
} |
} |
# |
# |
# Reverse lookup of domain roles (dc, ad, li, sc, dh, da, au) |
# Reverse lookup of domain roles (dc, ad, li, sc, au) |
# |
# |
my %domrolebuffer = (); |
my %domrolebuffer = (); |
foreach my $entry (keys(%domainrolehash)) { |
foreach my $entry (keys(%domainrolehash)) { |
Line 3990 sub flushcourselogs {
|
Line 3729 sub flushcourselogs {
|
delete $domainrolehash{$entry}; |
delete $domainrolehash{$entry}; |
} |
} |
foreach my $dom (keys(%domrolebuffer)) { |
foreach my $dom (keys(%domrolebuffer)) { |
my %servers; |
my %servers = &get_servers($dom,'library'); |
if (defined(&domain($dom,'primary'))) { |
|
my $primary=&domain($dom,'primary'); |
|
my $hostname=&hostname($primary); |
|
$servers{$primary} = $hostname; |
|
} else { |
|
%servers = &get_servers($dom,'library'); |
|
} |
|
foreach my $tryserver (keys(%servers)) { |
foreach my $tryserver (keys(%servers)) { |
if (&reply('domroleput:'.$dom.':'. |
unless (&reply('domroleput:'.$dom.':'. |
$domrolebuffer{$dom},$tryserver) eq 'ok') { |
$domrolebuffer{$dom},$tryserver) eq 'ok') { |
last; |
|
} else { |
|
&logthis('Put of domain roles failed for '.$dom.' and '.$tryserver); |
&logthis('Put of domain roles failed for '.$dom.' and '.$tryserver); |
} |
} |
} |
} |
Line 4122 sub userrolelog {
|
Line 3852 sub userrolelog {
|
{$trole.':'.$username.':'.$domain.':'.$env{'user.name'}.':'.$env{'user.domain'}.':'} |
{$trole.':'.$username.':'.$domain.':'.$env{'user.name'}.':'.$env{'user.domain'}.':'} |
=$tend.':'.$tstart; |
=$tend.':'.$tstart; |
} |
} |
if ($trole =~ /^(dc|ad|li|au|dg|sc|dh|da)/ ) { |
if ($trole =~ /^(dc|ad|li|au|dg|sc)/ ) { |
my (undef,$rudom,$runame,$rsec)=split(/\//,$area); |
my (undef,$rudom,$runame,$rsec)=split(/\//,$area); |
$domainrolehash |
$domainrolehash |
{$trole.':'.$username.':'.$domain.':'.$runame.':'.$rudom.':'.$rsec} |
{$trole.':'.$username.':'.$domain.':'.$runame.':'.$rudom.':'.$rsec} |
Line 4330 sub get_my_roles {
|
Line 4060 sub get_my_roles {
|
} else { |
} else { |
my $possdoms = [$domain]; |
my $possdoms = [$domain]; |
if (ref($roledoms) eq 'ARRAY') { |
if (ref($roledoms) eq 'ARRAY') { |
push(@{$possdoms},@{$roledoms}); |
push(@{$possdoms},@{$roledoms}); |
} |
} |
if (&privileged($username,$domain,$possdoms,\@privroles)) { |
if (&privileged($username,$domain,$possdoms,\@privroles)) { |
if (!$nothide{$username.':'.$domain}) { |
if (!$nothide{$username.':'.$domain}) { |
Line 4349 sub get_my_roles {
|
Line 4079 sub get_my_roles {
|
return %returnhash; |
return %returnhash; |
} |
} |
|
|
sub get_all_adhocroles { |
|
my ($dom) = @_; |
|
my @roles_by_num = (); |
|
my %domdefaults = &get_domain_defaults($dom); |
|
my (%description,%access_in_dom,%access_info); |
|
if (ref($domdefaults{'adhocroles'}) eq 'HASH') { |
|
my $count = 0; |
|
my %domcurrent = %{$domdefaults{'adhocroles'}}; |
|
my %ordered; |
|
foreach my $role (sort(keys(%domcurrent))) { |
|
my ($order,$desc,$access_in_dom); |
|
if (ref($domcurrent{$role}) eq 'HASH') { |
|
$order = $domcurrent{$role}{'order'}; |
|
$desc = $domcurrent{$role}{'desc'}; |
|
$access_in_dom{$role} = $domcurrent{$role}{'access'}; |
|
$access_info{$role} = $domcurrent{$role}{$access_in_dom{$role}}; |
|
} |
|
if ($order eq '') { |
|
$order = $count; |
|
} |
|
$ordered{$order} = $role; |
|
if ($desc ne '') { |
|
$description{$role} = $desc; |
|
} else { |
|
$description{$role}= $role; |
|
} |
|
$count++; |
|
} |
|
foreach my $item (sort {$a <=> $b } (keys(%ordered))) { |
|
push(@roles_by_num,$ordered{$item}); |
|
} |
|
} |
|
return (\@roles_by_num,\%description,\%access_in_dom,\%access_info); |
|
} |
|
|
|
sub get_my_adhocroles { |
|
my ($cid,$checkreg) = @_; |
|
my ($cdom,$cnum,%info,@possroles,$description,$roles_by_num); |
|
if ($env{'request.course.id'} eq $cid) { |
|
$cdom = $env{'course.'.$cid.'.domain'}; |
|
$cnum = $env{'course.'.$cid.'.num'}; |
|
$info{'internal.coursecode'} = $env{'course.'.$cid.'.internal.coursecode'}; |
|
} elsif ($cid =~ /^($match_domain)_($match_courseid)$/) { |
|
$cdom = $1; |
|
$cnum = $2; |
|
%info = &Apache::lonnet::get('environment',['internal.coursecode'], |
|
$cdom,$cnum); |
|
} |
|
if (($info{'internal.coursecode'} ne '') && ($checkreg)) { |
|
my $user = $env{'user.name'}.':'.$env{'user.domain'}; |
|
my %rosterhash = &get('classlist',[$user],$cdom,$cnum); |
|
if ($rosterhash{$user} ne '') { |
|
my $type = (split(/:/,$rosterhash{$user}))[5]; |
|
return ([],{}) if ($type eq 'auto'); |
|
} |
|
} |
|
if (($cdom ne '') && ($cnum ne '')) { |
|
if (($env{"user.role.dh./$cdom/"}) || ($env{"user.role.da./$cdom/"})) { |
|
my $then=$env{'user.login.time'}; |
|
my $update=$env{'user.update.time'}; |
|
if (!$update) { |
|
$update = $then; |
|
} |
|
my @liveroles; |
|
foreach my $role ('dh','da') { |
|
if ($env{"user.role.$role./$cdom/"}) { |
|
my ($tstart,$tend)=split(/\./,$env{"user.role.$role./$cdom/"}); |
|
my $limit = $update; |
|
if ($env{'request.role'} eq "$role./$cdom/") { |
|
$limit = $then; |
|
} |
|
my $activerole = 1; |
|
if ($tstart && $tstart>$limit) { $activerole = 0; } |
|
if ($tend && $tend <$limit) { $activerole = 0; } |
|
if ($activerole) { |
|
push(@liveroles,$role); |
|
} |
|
} |
|
} |
|
if (@liveroles) { |
|
if (&homeserver($cnum,$cdom) ne 'no_host') { |
|
my ($accessref,$accessinfo,%access_in_dom); |
|
($roles_by_num,$description,$accessref,$accessinfo) = &get_all_adhocroles($cdom); |
|
if (ref($roles_by_num) eq 'ARRAY') { |
|
if (@{$roles_by_num}) { |
|
my %settings; |
|
if ($env{'request.course.id'} eq $cid) { |
|
foreach my $envkey (keys(%env)) { |
|
if ($envkey =~ /^\Qcourse.$cid.\E(internal\.adhoc.+)$/) { |
|
$settings{$1} = $env{$envkey}; |
|
} |
|
} |
|
} else { |
|
%settings = &dump('environment',$cdom,$cnum,'internal\.adhoc'); |
|
} |
|
my %setincrs; |
|
if ($settings{'internal.adhocaccess'}) { |
|
map { $setincrs{$_} = 1; } split(/,/,$settings{'internal.adhocaccess'}); |
|
} |
|
my @statuses; |
|
if ($env{'environment.inststatus'}) { |
|
@statuses = split(/,/,$env{'environment.inststatus'}); |
|
} |
|
my $user = $env{'user.name'}.':'.$env{'user.domain'}; |
|
if (ref($accessref) eq 'HASH') { |
|
%access_in_dom = %{$accessref}; |
|
} |
|
foreach my $role (@{$roles_by_num}) { |
|
my ($curraccess,@okstatus,@personnel); |
|
if ($setincrs{$role}) { |
|
($curraccess,my $rest) = split(/=/,$settings{'internal.adhoc.'.$role}); |
|
if ($curraccess eq 'status') { |
|
@okstatus = split(/\&/,$rest); |
|
} elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) { |
|
@personnel = split(/\&/,$rest); |
|
} |
|
} else { |
|
$curraccess = $access_in_dom{$role}; |
|
if (ref($accessinfo) eq 'HASH') { |
|
if ($curraccess eq 'status') { |
|
if (ref($accessinfo->{$role}) eq 'ARRAY') { |
|
@okstatus = @{$accessinfo->{$role}}; |
|
} |
|
} elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) { |
|
if (ref($accessinfo->{$role}) eq 'ARRAY') { |
|
@personnel = @{$accessinfo->{$role}}; |
|
} |
|
} |
|
} |
|
} |
|
if ($curraccess eq 'none') { |
|
next; |
|
} elsif ($curraccess eq 'all') { |
|
push(@possroles,$role); |
|
} elsif ($curraccess eq 'dh') { |
|
if (grep(/^dh$/,@liveroles)) { |
|
push(@possroles,$role); |
|
} else { |
|
next; |
|
} |
|
} elsif ($curraccess eq 'da') { |
|
if (grep(/^da$/,@liveroles)) { |
|
push(@possroles,$role); |
|
} else { |
|
next; |
|
} |
|
} elsif ($curraccess eq 'status') { |
|
if (@okstatus) { |
|
if (!@statuses) { |
|
if (grep(/^default$/,@okstatus)) { |
|
push(@possroles,$role); |
|
} |
|
} else { |
|
foreach my $status (@okstatus) { |
|
if (grep(/^\Q$status\E$/,@statuses)) { |
|
push(@possroles,$role); |
|
last; |
|
} |
|
} |
|
} |
|
} |
|
} elsif (($curraccess eq 'exc') || ($curraccess eq 'inc')) { |
|
if (grep(/^\Q$user\E$/,@personnel)) { |
|
if ($curraccess eq 'exc') { |
|
push(@possroles,$role); |
|
} |
|
} elsif ($curraccess eq 'inc') { |
|
push(@possroles,$role); |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
} |
|
unless (ref($description) eq 'HASH') { |
|
if (ref($roles_by_num) eq 'ARRAY') { |
|
my %desc; |
|
map { $desc{$_} = $_; } (@{$roles_by_num}); |
|
$description = \%desc; |
|
} else { |
|
$description = {}; |
|
} |
|
} |
|
return (\@possroles,$description); |
|
} |
|
|
|
# ----------------------------------------------------- Frontpage Announcements |
# ----------------------------------------------------- Frontpage Announcements |
# |
# |
# |
# |
Line 4613 sub courseiddump {
|
Line 4154 sub courseiddump {
|
my ($domfilter,$descfilter,$sincefilter,$instcodefilter,$ownerfilter, |
my ($domfilter,$descfilter,$sincefilter,$instcodefilter,$ownerfilter, |
$coursefilter,$hostidflag,$hostidref,$typefilter,$regexp_ok, |
$coursefilter,$hostidflag,$hostidref,$typefilter,$regexp_ok, |
$selfenrollonly,$catfilter,$showhidden,$caller,$cloner,$cc_clone, |
$selfenrollonly,$catfilter,$showhidden,$caller,$cloner,$cc_clone, |
$cloneonly,$createdbefore,$createdafter,$creationcontext,$domcloner, |
$cloneonly,$createdbefore,$createdafter,$creationcontext,$domcloner)=@_; |
$hasuniquecode,$reqcrsdom,$reqinstcode)=@_; |
|
my $as_hash = 1; |
my $as_hash = 1; |
my %returnhash; |
my %returnhash; |
if (!$domfilter) { $domfilter=''; } |
if (!$domfilter) { $domfilter=''; } |
Line 4627 sub courseiddump {
|
Line 4167 sub courseiddump {
|
if (($domfilter eq '') || |
if (($domfilter eq '') || |
(&host_domain($tryserver) eq $domfilter)) { |
(&host_domain($tryserver) eq $domfilter)) { |
my $rep; |
my $rep; |
if (grep { $_ eq $tryserver } ¤t_machine_ids()) { |
if (grep { $_ eq $tryserver } current_machine_ids()) { |
$rep = &LONCAPA::Lond::dump_course_id_handler( |
$rep = LONCAPA::Lond::dump_course_id_handler( |
join(":", (&host_domain($tryserver), $sincefilter, |
join(":", (&host_domain($tryserver), $sincefilter, |
&escape($descfilter), &escape($instcodefilter), |
&escape($descfilter), &escape($instcodefilter), |
&escape($ownerfilter), &escape($coursefilter), |
&escape($ownerfilter), &escape($coursefilter), |
&escape($typefilter), &escape($regexp_ok), |
&escape($typefilter), &escape($regexp_ok), |
$as_hash, &escape($selfenrollonly), |
$as_hash, &escape($selfenrollonly), |
&escape($catfilter), $showhidden, $caller, |
&escape($catfilter), $showhidden, $caller, |
&escape($cloner), &escape($cc_clone), $cloneonly, |
&escape($cloner), &escape($cc_clone), $cloneonly, |
&escape($createdbefore), &escape($createdafter), |
&escape($createdbefore), &escape($createdafter), |
&escape($creationcontext),$domcloner,$hasuniquecode, |
&escape($creationcontext), $domcloner))); |
$reqcrsdom,&escape($reqinstcode)))); |
|
} else { |
} else { |
$rep = &reply('courseiddump:'.&host_domain($tryserver).':'. |
$rep = &reply('courseiddump:'.&host_domain($tryserver).':'. |
$sincefilter.':'.&escape($descfilter).':'. |
$sincefilter.':'.&escape($descfilter).':'. |
Line 4649 sub courseiddump {
|
Line 4188 sub courseiddump {
|
$showhidden.':'.$caller.':'.&escape($cloner).':'. |
$showhidden.':'.$caller.':'.&escape($cloner).':'. |
&escape($cc_clone).':'.$cloneonly.':'. |
&escape($cc_clone).':'.$cloneonly.':'. |
&escape($createdbefore).':'.&escape($createdafter).':'. |
&escape($createdbefore).':'.&escape($createdafter).':'. |
&escape($creationcontext).':'.$domcloner.':'.$hasuniquecode. |
&escape($creationcontext).':'.$domcloner, |
':'.$reqcrsdom.':'.&escape($reqinstcode),$tryserver); |
$tryserver); |
} |
} |
|
|
my @pairs=split(/\&/,$rep); |
my @pairs=split(/\&/,$rep); |
foreach my $item (@pairs) { |
foreach my $item (@pairs) { |
my ($key,$value)=split(/\=/,$item,2); |
my ($key,$value)=split(/\=/,$item,2); |
Line 4778 sub get_domain_roles {
|
Line 4317 sub get_domain_roles {
|
return %personnel; |
return %personnel; |
} |
} |
|
|
sub get_active_domroles { |
|
my ($dom,$roles) = @_; |
|
return () unless (ref($roles) eq 'ARRAY'); |
|
my $now = time; |
|
my %dompersonnel = &get_domain_roles($dom,$roles,$now,$now); |
|
my %domroles; |
|
foreach my $server (keys(%dompersonnel)) { |
|
foreach my $user (sort(keys(%{$dompersonnel{$server}}))) { |
|
my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user); |
|
$domroles{$uname.':'.$udom} = $dompersonnel{$server}{$user}; |
|
} |
|
} |
|
return %domroles; |
|
} |
|
|
|
# ----------------------------------------------------------- Interval timing |
# ----------------------------------------------------------- Interval timing |
|
|
{ |
{ |
Line 4804 my $cachedkey='';
|
Line 4328 my $cachedkey='';
|
# The cached times for this user |
# The cached times for this user |
my %cachedtimes=(); |
my %cachedtimes=(); |
# When this was last done |
# When this was last done |
my $cachedtime=''; |
my $cachedtime=(); |
|
|
sub load_all_first_access { |
sub load_all_first_access { |
my ($uname,$udom,$ignorecache)=@_; |
my ($uname,$udom)=@_; |
if (($cachedkey eq $uname.':'.$udom) && |
if (($cachedkey eq $uname.':'.$udom) && |
(abs($cachedtime-time)<5) && (!$env{'form.markaccess'}) && |
(abs($cachedtime-time)<5) && (!$env{'form.markaccess'})) { |
(!$ignorecache)) { |
|
return; |
return; |
} |
} |
$cachedtime=time; |
$cachedtime=time; |
Line 4819 sub load_all_first_access {
|
Line 4342 sub load_all_first_access {
|
} |
} |
|
|
sub get_first_access { |
sub get_first_access { |
my ($type,$argsymb,$argmap,$ignorecache)=@_; |
my ($type,$argsymb,$argmap)=@_; |
my ($symb,$courseid,$udom,$uname)=&whichuser(); |
my ($symb,$courseid,$udom,$uname)=&whichuser(); |
if ($argsymb) { $symb=$argsymb; } |
if ($argsymb) { $symb=$argsymb; } |
my ($map,$id,$res)=&decode_symb($symb); |
my ($map,$id,$res)=&decode_symb($symb); |
Line 4831 sub get_first_access {
|
Line 4354 sub get_first_access {
|
} else { |
} else { |
$res=$symb; |
$res=$symb; |
} |
} |
&load_all_first_access($uname,$udom,$ignorecache); |
&load_all_first_access($uname,$udom); |
return $cachedtimes{"$courseid\0$res"}; |
return $cachedtimes{"$courseid\0$res"}; |
} |
} |
|
|
Line 4867 sub set_first_access {
|
Line 4390 sub set_first_access {
|
return 'already_set'; |
return 'already_set'; |
} |
} |
} |
} |
|
|
sub checkout { |
|
my ($symb,$tuname,$tudom,$tcrsid)=@_; |
|
my $now=time; |
|
my $lonhost=$perlvar{'lonHostID'}; |
|
my $infostr=&escape( |
|
'CHECKOUTTOKEN&'. |
|
$tuname.'&'. |
|
$tudom.'&'. |
|
$tcrsid.'&'. |
|
$symb.'&'. |
|
$now.'&'.$ENV{'REMOTE_ADDR'}); |
|
my $token=&reply('tmpput:'.$infostr,$lonhost); |
|
if ($token=~/^error\:/) { |
|
&logthis("<font color=\"blue\">WARNING: ". |
|
"Checkout tmpput failed ".$tudom.' - '.$tuname.' - '.$symb. |
|
"</font>"); |
|
return ''; |
|
} |
|
|
|
$token=~s/^(\d+)\_.*\_(\d+)$/$1\*$2\*$lonhost/; |
|
$token=~tr/a-z/A-Z/; |
|
|
|
my %infohash=('resource.0.outtoken' => $token, |
|
'resource.0.checkouttime' => $now, |
|
'resource.0.outremote' => $ENV{'REMOTE_ADDR'}); |
|
|
|
unless (&cstore(\%infohash,$symb,$tcrsid,$tudom,$tuname) eq 'ok') { |
|
return ''; |
|
} else { |
|
&logthis("<font color=\"blue\">WARNING: ". |
|
"Checkout cstore failed ".$tudom.' - '.$tuname.' - '.$symb. |
|
"</font>"); |
|
} |
|
|
|
if (&log($tudom,$tuname,&homeserver($tuname,$tudom), |
|
&escape('Checkout '.$infostr.' - '. |
|
$token)) ne 'ok') { |
|
return ''; |
|
} else { |
|
&logthis("<font color=\"blue\">WARNING: ". |
|
"Checkout log failed ".$tudom.' - '.$tuname.' - '.$symb. |
|
"</font>"); |
|
} |
|
return $token; |
|
} |
|
|
|
# ------------------------------------------------------------ Check in an item |
|
|
|
sub checkin { |
|
my $token=shift; |
|
my $now=time; |
|
my ($ta,$tb,$lonhost)=split(/\*/,$token); |
|
$lonhost=~tr/A-Z/a-z/; |
|
my $dtoken=$ta.'_'.&hostname($lonhost).'_'.$tb; |
|
$dtoken=~s/\W/\_/g; |
|
my ($dummy,$tuname,$tudom,$tcrsid,$symb,$chtim,$rmaddr)= |
|
split(/\&/,&unescape(&reply('tmpget:'.$dtoken,$lonhost))); |
|
|
|
unless (($tuname) && ($tudom)) { |
|
&logthis('Check in '.$token.' ('.$dtoken.') failed'); |
|
return ''; |
|
} |
|
|
|
unless (&allowed('mgr',$tcrsid)) { |
|
&logthis('Check in '.$token.' ('.$dtoken.') unauthorized: '. |
|
$env{'user.name'}.' - '.$env{'user.domain'}); |
|
return ''; |
|
} |
|
|
|
my %infohash=('resource.0.intoken' => $token, |
|
'resource.0.checkintime' => $now, |
|
'resource.0.inremote' => $ENV{'REMOTE_ADDR'}); |
|
|
|
unless (&cstore(\%infohash,$symb,$tcrsid,$tudom,$tuname) eq 'ok') { |
|
return ''; |
|
} |
|
|
|
if (&log($tudom,$tuname,&homeserver($tuname,$tudom), |
|
&escape('Checkin - '.$token)) ne 'ok') { |
|
return ''; |
|
} |
|
|
|
return ($symb,$tuname,$tudom,$tcrsid); |
|
} |
|
|
|
# --------------------------------------------- Set Expire Date for Spreadsheet |
# --------------------------------------------- Set Expire Date for Spreadsheet |
|
|
sub expirespread { |
sub expirespread { |
Line 5323 sub tmprestore {
|
Line 4760 sub tmprestore {
|
# ----------------------------------------------------------------------- Store |
# ----------------------------------------------------------------------- Store |
|
|
sub store { |
sub store { |
my ($storehash,$symb,$namespace,$domain,$stuname,$laststore) = @_; |
my ($storehash,$symb,$namespace,$domain,$stuname) = @_; |
my $home=''; |
my $home=''; |
|
|
if ($stuname) { $home=&homeserver($stuname,$domain); } |
if ($stuname) { $home=&homeserver($stuname,$domain); } |
Line 5353 sub store {
|
Line 4790 sub store {
|
} |
} |
$namevalue=~s/\&$//; |
$namevalue=~s/\&$//; |
&courselog($symb.':'.$stuname.':'.$domain.':STORE:'.$namevalue); |
&courselog($symb.':'.$stuname.':'.$domain.':STORE:'.$namevalue); |
return reply("store:$domain:$stuname:$namespace:$symb:$namevalue:$laststore","$home"); |
return reply("store:$domain:$stuname:$namespace:$symb:$namevalue","$home"); |
} |
} |
|
|
# -------------------------------------------------------------- Critical Store |
# -------------------------------------------------------------- Critical Store |
|
|
sub cstore { |
sub cstore { |
my ($storehash,$symb,$namespace,$domain,$stuname,$laststore) = @_; |
my ($storehash,$symb,$namespace,$domain,$stuname) = @_; |
my $home=''; |
my $home=''; |
|
|
if ($stuname) { $home=&homeserver($stuname,$domain); } |
if ($stuname) { $home=&homeserver($stuname,$domain); } |
Line 5390 sub cstore {
|
Line 4827 sub cstore {
|
$namevalue=~s/\&$//; |
$namevalue=~s/\&$//; |
&courselog($symb.':'.$stuname.':'.$domain.':CSTORE:'.$namevalue); |
&courselog($symb.':'.$stuname.':'.$domain.':CSTORE:'.$namevalue); |
return critical |
return critical |
("store:$domain:$stuname:$namespace:$symb:$namevalue:$laststore","$home"); |
("store:$domain:$stuname:$namespace:$symb:$namevalue","$home"); |
} |
} |
|
|
# --------------------------------------------------------------------- Restore |
# --------------------------------------------------------------------- Restore |
Line 5546 sub privileged {
|
Line 4983 sub privileged {
|
my $now = time; |
my $now = time; |
my $roles; |
my $roles; |
if (ref($possroles) eq 'ARRAY') { |
if (ref($possroles) eq 'ARRAY') { |
$roles = $possroles; |
$roles = $possroles; |
} else { |
} else { |
$roles = ['dc','su']; |
$roles = ['dc','su']; |
} |
} |
Line 5570 sub privileged {
|
Line 5007 sub privileged {
|
my %rolesdump = &dump("roles", $domain, $username) or return 0; |
my %rolesdump = &dump("roles", $domain, $username) or return 0; |
my $now = time; |
my $now = time; |
|
|
for my $role (@rolesdump{grep { ! /^rolesdef_/ } keys(%rolesdump)}) { |
for my $role (@rolesdump{grep { ! /^rolesdef_/ } keys %rolesdump}) { |
my ($trole, $tend, $tstart) = split(/_/, $role); |
my ($trole, $tend, $tstart) = split(/_/, $role); |
if (grep(/^\Q$trole\E$/,@{$roles})) { |
if (grep(/^\Q$trole\E$/,@{$roles})) { |
return 1 unless ($tend && $tend < $now) |
return 1 unless ($tend && $tend < $now) |
or ($tstart && $tstart > $now); |
or ($tstart && $tstart > $now); |
} |
} |
} |
} |
Line 5611 sub privileged_by_domain {
|
Line 5048 sub privileged_by_domain {
|
my ($trole,$uname,$udom,$rest) = split(/:/,$item,4); |
my ($trole,$uname,$udom,$rest) = split(/:/,$item,4); |
my ($end,$start) = split(/:/,$dompersonnel{$server}{$item}); |
my ($end,$start) = split(/:/,$dompersonnel{$server}{$item}); |
next if ($end && $end < $now); |
next if ($end && $end < $now); |
$privileged{$dom}{$trole}{$uname.':'.$udom} = |
$privileged{$dom}{$trole}{$uname.':'.$udom} = |
$dompersonnel{$server}{$item}; |
$dompersonnel{$server}{$item}; |
} |
} |
} |
} |
Line 5659 sub rolesinit {
|
Line 5096 sub rolesinit {
|
my %allroles=(); |
my %allroles=(); |
my %allgroups=(); |
my %allgroups=(); |
|
|
for my $area (grep { ! /^rolesdef_/ } keys(%rolesdump)) { |
for my $area (grep { ! /^rolesdef_/ } keys %rolesdump) { |
my $role = $rolesdump{$area}; |
my $role = $rolesdump{$area}; |
$area =~ s/\_\w\w$//; |
$area =~ s/\_\w\w$//; |
|
|
Line 5732 sub rolesinit {
|
Line 5169 sub rolesinit {
|
} |
} |
} |
} |
|
|
@userroles{'user.author','user.adv','user.rar'} = &set_userprivs(\%userroles, |
@userroles{'user.author', 'user.adv'} = &set_userprivs(\%userroles, |
\%allroles, \%allgroups); |
\%allroles, \%allgroups); |
$env{'user.adv'} = $userroles{'user.adv'}; |
$env{'user.adv'} = $userroles{'user.adv'}; |
$env{'user.rar'} = $userroles{'user.rar'}; |
|
|
|
return (\%userroles,\%firstaccenv,\%timerintenv); |
return (\%userroles,\%firstaccenv,\%timerintenv); |
} |
} |
Line 5752 sub set_arearole {
|
Line 5188 sub set_arearole {
|
sub custom_roleprivs { |
sub custom_roleprivs { |
my ($allroles,$trole,$tdomain,$trest,$spec,$area) = @_; |
my ($allroles,$trole,$tdomain,$trest,$spec,$area) = @_; |
my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$trole); |
my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$trole); |
my $homsvr = &homeserver($rauthor,$rdomain); |
my $homsvr=homeserver($rauthor,$rdomain); |
if (&hostname($homsvr) ne '') { |
if (&hostname($homsvr) ne '') { |
my ($rdummy,$roledef)= |
my ($rdummy,$roledef)= |
&get('roles',["rolesdef_$rrole"],$rdomain,$rauthor); |
&get('roles',["rolesdef_$rrole"],$rdomain,$rauthor); |
Line 5771 sub custom_roleprivs {
|
Line 5207 sub custom_roleprivs {
|
$$allroles{$spec.'./'.$tdomain.'/'}.=':'.$dompriv; |
$$allroles{$spec.'./'.$tdomain.'/'}.=':'.$dompriv; |
} |
} |
if (($trest ne '') && (defined($coursepriv))) { |
if (($trest ne '') && (defined($coursepriv))) { |
if ($trole =~ m{^cr/$tdomain/$tdomain\Q-domainconfig\E/([^/]+)$}) { |
|
my $rolename = $1; |
|
$coursepriv = &course_adhocrole_privs($rolename,$tdomain,$trest,$coursepriv); |
|
} |
|
$$allroles{'cm.'.$area}.=':'.$coursepriv; |
$$allroles{'cm.'.$area}.=':'.$coursepriv; |
$$allroles{$spec.'.'.$area}.=':'.$coursepriv; |
$$allroles{$spec.'.'.$area}.=':'.$coursepriv; |
} |
} |
Line 5783 sub custom_roleprivs {
|
Line 5215 sub custom_roleprivs {
|
} |
} |
} |
} |
|
|
sub course_adhocrole_privs { |
|
my ($rolename,$cdom,$cnum,$coursepriv) = @_; |
|
my %overrides = &get('environment',["internal.adhocpriv.$rolename"],$cdom,$cnum); |
|
if ($overrides{"internal.adhocpriv.$rolename"}) { |
|
my (%currprivs,%storeprivs); |
|
foreach my $item (split(/:/,$coursepriv)) { |
|
my ($priv,$restrict) = split(/\&/,$item); |
|
$currprivs{$priv} = $restrict; |
|
} |
|
my (%possadd,%possremove,%full); |
|
foreach my $item (split(/\:/,$Apache::lonnet::pr{'cr:c'})) { |
|
my ($priv,$restrict)=split(/\&/,$item); |
|
$full{$priv} = $restrict; |
|
} |
|
foreach my $item (split(/,/,$overrides{"internal.adhocpriv.$rolename"})) { |
|
next if ($item eq ''); |
|
my ($rule,$rest) = split(/=/,$item); |
|
next unless (($rule eq 'off') || ($rule eq 'on')); |
|
foreach my $priv (split(/:/,$rest)) { |
|
if ($priv ne '') { |
|
if ($rule eq 'off') { |
|
$possremove{$priv} = 1; |
|
} else { |
|
$possadd{$priv} = 1; |
|
} |
|
} |
|
} |
|
} |
|
foreach my $priv (sort(keys(%full))) { |
|
if (exists($currprivs{$priv})) { |
|
unless (exists($possremove{$priv})) { |
|
$storeprivs{$priv} = $currprivs{$priv}; |
|
} |
|
} elsif (exists($possadd{$priv})) { |
|
$storeprivs{$priv} = $full{$priv}; |
|
} |
|
} |
|
$coursepriv = ':'.join(':',map { $_.'&'.$storeprivs{$_}; } sort(keys(%storeprivs))); |
|
} |
|
return $coursepriv; |
|
} |
|
|
|
sub group_roleprivs { |
sub group_roleprivs { |
my ($allgroups,$area,$group_privs,$tend,$tstart) = @_; |
my ($allgroups,$area,$group_privs,$tend,$tstart) = @_; |
my $access = 1; |
my $access = 1; |
Line 5859 sub set_userprivs {
|
Line 5249 sub set_userprivs {
|
my ($userroles,$allroles,$allgroups,$groups_roles) = @_; |
my ($userroles,$allroles,$allgroups,$groups_roles) = @_; |
my $author=0; |
my $author=0; |
my $adv=0; |
my $adv=0; |
my $rar=0; |
|
my %grouproles = (); |
my %grouproles = (); |
if (keys(%{$allgroups}) > 0) { |
if (keys(%{$allgroups}) > 0) { |
my @groupkeys; |
my @groupkeys; |
Line 5907 sub set_userprivs {
|
Line 5296 sub set_userprivs {
|
$thesepriv{$privilege}.=$restrictions; |
$thesepriv{$privilege}.=$restrictions; |
} |
} |
if ($thesepriv{'adv'} eq 'F') { $adv=1; } |
if ($thesepriv{'adv'} eq 'F') { $adv=1; } |
if ($thesepriv{'rar'} eq 'F') { $rar=1; } |
|
} |
} |
} |
} |
my $thesestr=''; |
my $thesestr=''; |
Line 5916 sub set_userprivs {
|
Line 5304 sub set_userprivs {
|
} |
} |
$userroles->{'user.priv.'.$role} = $thesestr; |
$userroles->{'user.priv.'.$role} = $thesestr; |
} |
} |
return ($author,$adv,$rar); |
return ($author,$adv); |
} |
} |
|
|
sub role_status { |
sub role_status { |
my ($rolekey,$update,$refresh,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_; |
my ($rolekey,$update,$refresh,$now,$role,$where,$trolecode,$tstatus,$tstart,$tend) = @_; |
|
my @pwhere = (); |
if (exists($env{$rolekey}) && $env{$rolekey} ne '') { |
if (exists($env{$rolekey}) && $env{$rolekey} ne '') { |
my ($one,$two) = split(m{\./},$rolekey,2); |
(undef,undef,$$role,@pwhere)=split(/\./,$rolekey); |
(undef,undef,$$role) = split(/\./,$one,3); |
|
unless (!defined($$role) || $$role eq '') { |
unless (!defined($$role) || $$role eq '') { |
$$where = '/'.$two; |
$$where=join('.',@pwhere); |
$$trolecode=$$role.'.'.$$where; |
$$trolecode=$$role.'.'.$$where; |
($$tstart,$$tend)=split(/\./,$env{$rolekey}); |
($$tstart,$$tend)=split(/\./,$env{$rolekey}); |
$$tstatus='is'; |
$$tstatus='is'; |
Line 5961 sub role_status {
|
Line 5349 sub role_status {
|
push(@rolecodes,$$role); |
push(@rolecodes,$$role); |
&standard_roleprivs(\%allroles,$$role,$tdomain,$spec,$trest,$$where); |
&standard_roleprivs(\%allroles,$$role,$tdomain,$spec,$trest,$$where); |
} |
} |
my ($author,$adv,$rar)= &set_userprivs(\%userroles,\%allroles,\%allgroups, |
my ($author,$adv)= &set_userprivs(\%userroles,\%allroles,\%allgroups,\%groups_roles); |
\%groups_roles); |
|
&appenv(\%userroles,\@rolecodes); |
&appenv(\%userroles,\@rolecodes); |
&log($env{'user.domain'},$env{'user.name'},$env{'user.home'},"Role ".$spec); |
&log($env{'user.domain'},$env{'user.name'},$env{'user.home'},"Role ".$role); |
} |
} |
} |
} |
$$tstatus = 'is'; |
$$tstatus = 'is'; |
Line 6040 sub delete_env_groupprivs {
|
Line 5427 sub delete_env_groupprivs {
|
} |
} |
|
|
sub check_adhoc_privs { |
sub check_adhoc_privs { |
my ($cdom,$cnum,$update,$refresh,$now,$checkrole,$caller,$sec) = @_; |
my ($cdom,$cnum,$update,$refresh,$now,$checkrole,$caller) = @_; |
my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum; |
my $cckey = 'user.role.'.$checkrole.'./'.$cdom.'/'.$cnum; |
if ($sec) { |
|
$cckey .= '/'.$sec; |
|
} |
|
my $setprivs; |
my $setprivs; |
if ($env{$cckey}) { |
if ($env{$cckey}) { |
my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend); |
my ($role,$where,$trolecode,$tstart,$tend,$tremark,$tstatus,$tpstart,$tpend); |
&role_status($cckey,$update,$refresh,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend); |
&role_status($cckey,$update,$refresh,$now,\$role,\$where,\$trolecode,\$tstatus,\$tstart,\$tend); |
unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) { |
unless (($tstatus eq 'is') || ($tstatus eq 'will_not')) { |
&set_adhoc_privileges($cdom,$cnum,$checkrole,$caller,$sec); |
&set_adhoc_privileges($cdom,$cnum,$checkrole,$caller); |
$setprivs = 1; |
$setprivs = 1; |
} |
} |
} else { |
} else { |
&set_adhoc_privileges($cdom,$cnum,$checkrole,$caller,$sec); |
&set_adhoc_privileges($cdom,$cnum,$checkrole,$caller); |
$setprivs = 1; |
$setprivs = 1; |
} |
} |
return $setprivs; |
return $setprivs; |
} |
} |
|
|
sub set_adhoc_privileges { |
sub set_adhoc_privileges { |
# role can be cc, ca, or cr/<dom>/<dom>-domainconfig/role |
# role can be cc or ca |
my ($dcdom,$pickedcourse,$role,$caller,$sec) = @_; |
my ($dcdom,$pickedcourse,$role,$caller) = @_; |
my $area = '/'.$dcdom.'/'.$pickedcourse; |
my $area = '/'.$dcdom.'/'.$pickedcourse; |
if ($sec ne '') { |
|
$area .= '/'.$sec; |
|
} |
|
my $spec = $role.'.'.$area; |
my $spec = $role.'.'.$area; |
my %userroles = &set_arearole($role,$area,'','',$env{'user.domain'}, |
my %userroles = &set_arearole($role,$area,'','',$env{'user.domain'}, |
$env{'user.name'},1); |
$env{'user.name'},1); |
my %rolehash = (); |
my %ccrole = (); |
if ($role =~ m{^\Qcr/$dcdom/$dcdom\E\-domainconfig/(\w+)$}) { |
&standard_roleprivs(\%ccrole,$role,$dcdom,$spec,$pickedcourse,$area); |
my $rolename = $1; |
my ($author,$adv)= &set_userprivs(\%userroles,\%ccrole); |
&custom_roleprivs(\%rolehash,$role,$dcdom,$pickedcourse,$spec,$area); |
|
my %domdef = &get_domain_defaults($dcdom); |
|
if (ref($domdef{'adhocroles'}) eq 'HASH') { |
|
if (ref($domdef{'adhocroles'}{$rolename}) eq 'HASH') { |
|
&appenv({'request.role.desc' => $domdef{'adhocroles'}{$rolename}{'desc'},}); |
|
} |
|
} |
|
} else { |
|
&standard_roleprivs(\%rolehash,$role,$dcdom,$spec,$pickedcourse,$area); |
|
} |
|
my ($author,$adv,$rar)= &set_userprivs(\%userroles,\%rolehash); |
|
&appenv(\%userroles,[$role,'cm']); |
&appenv(\%userroles,[$role,'cm']); |
&log($env{'user.domain'},$env{'user.name'},$env{'user.home'},"Role ".$spec); |
&log($env{'user.domain'},$env{'user.name'},$env{'user.home'},"Role ".$role); |
unless ($caller eq 'constructaccess' && $env{'request.course.id'}) { |
unless ($caller eq 'constructaccess' && $env{'request.course.id'}) { |
&appenv( {'request.role' => $spec, |
&appenv( {'request.role' => $spec, |
'request.role.domain' => $dcdom, |
'request.role.domain' => $dcdom, |
'request.course.sec' => $sec, |
'request.course.sec' => '' |
} |
} |
); |
); |
my $tadv=0; |
my $tadv=0; |
Line 6149 sub unserialize {
|
Line 5519 sub unserialize {
|
return {} if $rep =~ /^error/; |
return {} if $rep =~ /^error/; |
|
|
my %returnhash=(); |
my %returnhash=(); |
foreach my $item (split(/\&/,$rep)) { |
foreach my $item (split /\&/, $rep) { |
my ($key, $value) = split(/=/, $item, 2); |
my ($key, $value) = split(/=/, $item, 2); |
$key = unescape($key) unless $escapedkeys; |
$key = unescape($key) unless $escapedkeys; |
next if $key =~ /^error: 2 /; |
next if $key =~ /^error: 2 /; |
$returnhash{$key} = &thaw_unescape($value); |
$returnhash{$key} = Apache::lonnet::thaw_unescape($value); |
} |
} |
|
#return %returnhash; |
return \%returnhash; |
return \%returnhash; |
} |
} |
|
|
# see Lond::dump_with_regexp |
# see Lond::dump_with_regexp |
# if $escapedkeys hash keys won't get unescaped. |
# if $escapedkeys hash keys won't get unescaped. |
Line 6166 sub dump {
|
Line 5537 sub dump {
|
if (!$uname) { $uname=$env{'user.name'}; } |
if (!$uname) { $uname=$env{'user.name'}; } |
my $uhome=&homeserver($uname,$udomain); |
my $uhome=&homeserver($uname,$udomain); |
|
|
if ($regexp) { |
my $reply; |
$regexp=&escape($regexp); |
if (grep { $_ eq $uhome } current_machine_ids()) { |
} else { |
|
$regexp='.'; |
|
} |
|
if (grep { $_ eq $uhome } ¤t_machine_ids()) { |
|
# user is hosted on this machine |
# user is hosted on this machine |
my $reply = LONCAPA::Lond::dump_with_regexp(join(':', ($udomain, |
$reply = LONCAPA::Lond::dump_with_regexp(join(":", ($udomain, |
$uname, $namespace, $regexp, $range)), $perlvar{'lonVersion'}); |
$uname, $namespace, $regexp, $range)), $perlvar{'lonVersion'}); |
return %{&unserialize($reply, $escapedkeys)}; |
return %{unserialize($reply, $escapedkeys)}; |
|
} |
|
if ($regexp) { |
|
$regexp=&escape($regexp); |
|
} else { |
|
$regexp='.'; |
} |
} |
my $rep=&reply("dump:$udomain:$uname:$namespace:$regexp:$range",$uhome); |
my $rep=&reply("dump:$udomain:$uname:$namespace:$regexp:$range",$uhome); |
my @pairs=split(/\&/,$rep); |
my @pairs=split(/\&/,$rep); |
Line 6183 sub dump {
|
Line 5555 sub dump {
|
if (!($rep =~ /^error/ )) { |
if (!($rep =~ /^error/ )) { |
foreach my $item (@pairs) { |
foreach my $item (@pairs) { |
my ($key,$value)=split(/=/,$item,2); |
my ($key,$value)=split(/=/,$item,2); |
$key = &unescape($key) unless ($escapedkeys); |
$key = unescape($key) unless $escapedkeys; |
|
#$key = &unescape($key); |
next if ($key =~ /^error: 2 /); |
next if ($key =~ /^error: 2 /); |
$returnhash{$key}=&thaw_unescape($value); |
$returnhash{$key}=&thaw_unescape($value); |
} |
} |
Line 6227 sub currentdump {
|
Line 5600 sub currentdump {
|
my $rep; |
my $rep; |
|
|
if (grep { $_ eq $uhome } current_machine_ids()) { |
if (grep { $_ eq $uhome } current_machine_ids()) { |
$rep = LONCAPA::Lond::dump_profile_database(join(":", ($sdom, $sname, |
$rep = LONCAPA::Lond::dump_profile_database(join(":", ($sdom, $sname, |
$courseid))); |
$courseid))); |
} else { |
} else { |
$rep = reply('currentdump:'.$sdom.':'.$sname.':'.$courseid,$uhome); |
$rep = reply('currentdump:'.$sdom.':'.$sname.':'.$courseid,$uhome); |
Line 6237 sub currentdump {
|
Line 5610 sub currentdump {
|
# |
# |
my %returnhash=(); |
my %returnhash=(); |
# |
# |
if ($rep eq 'unknown_cmd') { |
if ($rep eq "unknown_cmd") { |
# an old lond will not know currentdump |
# an old lond will not know currentdump |
# Do a dump and make it look like a currentdump |
# Do a dump and make it look like a currentdump |
my @tmp = &dumpstore($courseid,$sdom,$sname,'.'); |
my @tmp = &dumpstore($courseid,$sdom,$sname,'.'); |
Line 6353 sub newput {
|
Line 5726 sub newput {
|
# --------------------------------------------------------- putstore interface |
# --------------------------------------------------------- putstore interface |
|
|
sub putstore { |
sub putstore { |
my ($namespace,$symb,$version,$storehash,$udomain,$uname,$tolog)=@_; |
my ($namespace,$symb,$version,$storehash,$udomain,$uname)=@_; |
if (!$udomain) { $udomain=$env{'user.domain'}; } |
if (!$udomain) { $udomain=$env{'user.domain'}; } |
if (!$uname) { $uname=$env{'user.name'}; } |
if (!$uname) { $uname=$env{'user.name'}; } |
my $uhome=&homeserver($uname,$udomain); |
my $uhome=&homeserver($uname,$udomain); |
Line 6367 sub putstore {
|
Line 5740 sub putstore {
|
my $reply = |
my $reply = |
&reply("putstore:$udomain:$uname:$namespace:$esc_symb:$esc_v:$items", |
&reply("putstore:$udomain:$uname:$namespace:$esc_symb:$esc_v:$items", |
$uhome); |
$uhome); |
if (($tolog) && ($reply eq 'ok')) { |
|
my $namevalue=''; |
|
foreach my $key (keys(%{$storehash})) { |
|
$namevalue.=&escape($key).'='.&freeze_escape($storehash->{$key}).'&'; |
|
} |
|
$namevalue .= 'ip='.&escape($ENV{'REMOTE_ADDR'}). |
|
'&host='.&escape($perlvar{'lonHostID'}). |
|
'&version='.$esc_v. |
|
'&by='.&escape($env{'user.name'}.':'.$env{'user.domain'}); |
|
&Apache::lonnet::courselog($symb.':'.$uname.':'.$udomain.':PUTSTORE:'.$namevalue); |
|
} |
|
if ($reply eq 'unknown_cmd') { |
if ($reply eq 'unknown_cmd') { |
# gfall back to way things use to be done |
# gfall back to way things use to be done |
return &old_putstore($namespace,$symb,$version,$storehash,$udomain, |
return &old_putstore($namespace,$symb,$version,$storehash,$udomain, |
Line 6471 sub tmpget {
|
Line 5833 sub tmpget {
|
if (!defined($server)) { $server = $perlvar{'lonHostID'}; } |
if (!defined($server)) { $server = $perlvar{'lonHostID'}; } |
my $rep=&reply("tmpget:$token",$server); |
my $rep=&reply("tmpget:$token",$server); |
my %returnhash; |
my %returnhash; |
if ($rep =~ /^(con_lost|error|no_such_host)/i) { |
|
return %returnhash; |
|
} |
|
foreach my $item (split(/\&/,$rep)) { |
foreach my $item (split(/\&/,$rep)) { |
my ($key,$value)=split(/=/,$item); |
my ($key,$value)=split(/=/,$item); |
|
next if ($key =~ /^error: 2 /); |
$returnhash{&unescape($key)}=&thaw_unescape($value); |
$returnhash{&unescape($key)}=&thaw_unescape($value); |
} |
} |
return %returnhash; |
return %returnhash; |
Line 6488 sub tmpdel {
|
Line 5848 sub tmpdel {
|
return &reply("tmpdel:$token",$server); |
return &reply("tmpdel:$token",$server); |
} |
} |
|
|
# ------------------------------------------------------------ get_timebased_id |
# ------------------------------------------------------------ get_timebased_id |
|
|
sub get_timebased_id { |
sub get_timebased_id { |
my ($prefix,$keyid,$namespace,$cdom,$cnum,$idtype,$who,$locktries, |
my ($prefix,$keyid,$namespace,$cdom,$cnum,$idtype,$who,$locktries, |
$maxtries) = @_; |
$maxtries) = @_; |
my ($newid,$error,$dellock); |
my ($newid,$error,$dellock); |
unless (($prefix =~ /^\w+$/) && ($keyid =~ /^\w+$/) && ($namespace ne '')) { |
unless (($prefix =~ /^\w+$/) && ($keyid =~ /^\w+$/) && ($namespace ne '')) { |
return ('','ok','invalid call to get suffix'); |
return ('','ok','invalid call to get suffix'); |
} |
} |
|
|
Line 6508 sub get_timebased_id {
|
Line 5868 sub get_timebased_id {
|
if (!$maxtries) { |
if (!$maxtries) { |
$maxtries = 10; |
$maxtries = 10; |
} |
} |
|
|
if (($cdom eq '') || ($cnum eq '')) { |
if (($cdom eq '') || ($cnum eq '')) { |
if ($env{'request.course.id'}) { |
if ($env{'request.course.id'}) { |
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
$cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
Line 6538 sub get_timebased_id {
|
Line 5898 sub get_timebased_id {
|
my %inuse = &Apache::lonnet::dump('nohist_'.$namespace,$cdom,$cnum,$prefix); |
my %inuse = &Apache::lonnet::dump('nohist_'.$namespace,$cdom,$cnum,$prefix); |
my $id = time; |
my $id = time; |
$newid = $id; |
$newid = $id; |
if ($idtype eq 'addcode') { |
|
$newid .= &sixnum_code(); |
|
} |
|
my $idtries = 0; |
my $idtries = 0; |
while (exists($inuse{$prefix."\0".$newid}) && $idtries < $maxtries) { |
while (exists($inuse{$prefix."\0".$newid}) && $idtries < $maxtries) { |
if ($idtype eq 'concat') { |
if ($idtype eq 'concat') { |
$newid = $id.$idtries; |
$newid = $id.$idtries; |
} elsif ($idtype eq 'addcode') { |
|
$newid = $newid.&sixnum_code(); |
|
} else { |
} else { |
$newid ++; |
$newid ++; |
} |
} |
Line 6563 sub get_timebased_id {
|
Line 5918 sub get_timebased_id {
|
$error = 'error saving new item: '.$putresult; |
$error = 'error saving new item: '.$putresult; |
} |
} |
} else { |
} else { |
undef($newid); |
|
$error = ('error: no unique suffix available for the new item '); |
$error = ('error: no unique suffix available for the new item '); |
} |
} |
# remove lock |
# remove lock |
Line 6572 sub get_timebased_id {
|
Line 5926 sub get_timebased_id {
|
} else { |
} else { |
$error = "error: could not obtain lockfile\n"; |
$error = "error: could not obtain lockfile\n"; |
$dellock = 'ok'; |
$dellock = 'ok'; |
if (($prefix eq 'paste') && ($namespace eq 'courseeditor') && ($keyid eq 'num')) { |
|
$dellock = 'nolock'; |
|
} |
|
} |
} |
return ($newid,$dellock,$error); |
return ($newid,$dellock,$error); |
} |
} |
|
|
sub sixnum_code { |
|
my $code; |
|
for (0..6) { |
|
$code .= int( rand(9) ); |
|
} |
|
return $code; |
|
} |
|
|
|
# -------------------------------------------------- portfolio access checking |
# -------------------------------------------------- portfolio access checking |
|
|
sub portfolio_access { |
sub portfolio_access { |
my ($requrl,$clientip) = @_; |
my ($requrl) = @_; |
my (undef,$udom,$unum,$file_name,$group) = &parse_portfolio_url($requrl); |
my (undef,$udom,$unum,$file_name,$group) = &parse_portfolio_url($requrl); |
my $result = &get_portfolio_access($udom,$unum,$file_name,$group,$clientip); |
my $result = &get_portfolio_access($udom,$unum,$file_name,$group); |
if ($result) { |
if ($result) { |
my %setters; |
my %setters; |
if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { |
if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { |
Line 6618 sub portfolio_access {
|
Line 5961 sub portfolio_access {
|
} |
} |
|
|
sub get_portfolio_access { |
sub get_portfolio_access { |
my ($udom,$unum,$file_name,$group,$clientip,$access_hash) = @_; |
my ($udom,$unum,$file_name,$group,$access_hash) = @_; |
|
|
if (!ref($access_hash)) { |
if (!ref($access_hash)) { |
my $current_perms = &get_portfile_permissions($udom,$unum); |
my $current_perms = &get_portfile_permissions($udom,$unum); |
Line 6627 sub get_portfolio_access {
|
Line 5970 sub get_portfolio_access {
|
$access_hash = $access_controls{$file_name}; |
$access_hash = $access_controls{$file_name}; |
} |
} |
|
|
my ($public,$guest,@domains,@users,@courses,@groups,@ips); |
my ($public,$guest,@domains,@users,@courses,@groups); |
my $now = time; |
my $now = time; |
if (ref($access_hash) eq 'HASH') { |
if (ref($access_hash) eq 'HASH') { |
foreach my $key (keys(%{$access_hash})) { |
foreach my $key (keys(%{$access_hash})) { |
Line 6651 sub get_portfolio_access {
|
Line 5994 sub get_portfolio_access {
|
push(@courses,$key); |
push(@courses,$key); |
} elsif ($scope eq 'group') { |
} elsif ($scope eq 'group') { |
push(@groups,$key); |
push(@groups,$key); |
} elsif ($scope eq 'ip') { |
|
push(@ips,$key); |
|
} |
} |
} |
} |
if ($public) { |
if ($public) { |
return 'ok'; |
return 'ok'; |
} elsif (@ips > 0) { |
|
my $allowed; |
|
foreach my $ipkey (@ips) { |
|
if (ref($access_hash->{$ipkey}{'ip'}) eq 'ARRAY') { |
|
if (&Apache::loncommon::check_ip_acc(join(',',@{$access_hash->{$ipkey}{'ip'}}),$clientip)) { |
|
$allowed = 1; |
|
last; |
|
} |
|
} |
|
} |
|
if ($allowed) { |
|
return 'ok'; |
|
} |
|
} |
} |
if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { |
if ($env{'user.name'} eq 'public' && $env{'user.domain'} eq 'public') { |
if ($guest) { |
if ($guest) { |
Line 6856 sub usertools_access {
|
Line 6184 sub usertools_access {
|
official => 1, |
official => 1, |
unofficial => 1, |
unofficial => 1, |
community => 1, |
community => 1, |
textbook => 1, |
|
); |
); |
} elsif ($context eq 'requestauthor') { |
} elsif ($context eq 'requestauthor') { |
%tools = ( |
%tools = ( |
Line 6872 sub usertools_access {
|
Line 6199 sub usertools_access {
|
} |
} |
return if (!defined($tools{$tool})); |
return if (!defined($tools{$tool})); |
|
|
if (($udom eq '') || ($uname eq '')) { |
if ((!defined($udom)) || (!defined($uname))) { |
$udom = $env{'user.domain'}; |
$udom = $env{'user.domain'}; |
$uname = $env{'user.name'}; |
$uname = $env{'user.name'}; |
} |
} |
Line 6891 sub usertools_access {
|
Line 6218 sub usertools_access {
|
|
|
my ($toolstatus,$inststatus,$envkey); |
my ($toolstatus,$inststatus,$envkey); |
if ($context eq 'requestauthor') { |
if ($context eq 'requestauthor') { |
$envkey = $context; |
$envkey = $context; |
} else { |
} else { |
$envkey = $context.'.'.$tool; |
$envkey = $context.'.'.$tool; |
} |
} |
Line 7153 sub customaccess {
|
Line 6480 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)=@_; |
my $ver_orguri=$uri; |
my $ver_orguri=$uri; |
$uri=&deversion($uri); |
$uri=&deversion($uri); |
my $orguri=$uri; |
my $orguri=$uri; |
Line 7170 sub allowed {
|
Line 6497 sub allowed {
|
|
|
if (defined($env{'allowed.'.$priv})) { return $env{'allowed.'.$priv}; } |
if (defined($env{'allowed.'.$priv})) { return $env{'allowed.'.$priv}; } |
# Free bre access to adm and meta resources |
# Free bre access to adm and meta resources |
if (((($uri=~/^adm\//) && ($uri !~ m{/(?:smppg|bulletinboard|ext\.tool)$})) |
if (((($uri=~/^adm\//) && ($uri !~ m{/(?:smppg|bulletinboard)$})) |
|| (($uri=~/\.meta$/) && ($uri!~m|^uploaded/|) )) |
|| (($uri=~/\.meta$/) && ($uri!~m|^uploaded/|) )) |
&& ($priv eq 'bre')) { |
&& ($priv eq 'bre')) { |
return 'F'; |
return 'F'; |
Line 7348 sub allowed {
|
Line 6675 sub allowed {
|
if ($match) { |
if ($match) { |
if ($env{'user.priv.'.$env{'request.role'}.'./'} |
if ($env{'user.priv.'.$env{'request.role'}.'./'} |
=~/\Q$priv\E\&([^\:]*)/) { |
=~/\Q$priv\E\&([^\:]*)/) { |
my $value = $1; |
my @blockers = &has_comm_blocking($priv,$symb,$uri); |
if ($noblockcheck) { |
if (@blockers > 0) { |
$thisallowed.=$value; |
$thisallowed = 'B'; |
} else { |
} else { |
my @blockers = &has_comm_blocking($priv,$symb,$uri); |
$thisallowed.=$1; |
if (@blockers > 0) { |
|
$thisallowed = 'B'; |
|
} else { |
|
$thisallowed.=$value; |
|
} |
|
} |
} |
} |
} |
} else { |
} else { |
Line 7369 sub allowed {
|
Line 6691 sub allowed {
|
$refuri=&declutter($refuri); |
$refuri=&declutter($refuri); |
my ($match) = &is_on_map($refuri); |
my ($match) = &is_on_map($refuri); |
if ($match) { |
if ($match) { |
if ($noblockcheck) { |
my @blockers = &has_comm_blocking($priv,$symb,$refuri); |
$thisallowed='F'; |
if (@blockers > 0) { |
|
$thisallowed = 'B'; |
} else { |
} else { |
my @blockers = &has_comm_blocking($priv,$symb,$refuri); |
$thisallowed='F'; |
if (@blockers > 0) { |
|
$thisallowed = 'B'; |
|
} else { |
|
$thisallowed='F'; |
|
} |
|
} |
} |
} |
} |
} |
} |
Line 7389 sub allowed {
|
Line 6707 sub allowed {
|
&& $thisallowed ne 'F' |
&& $thisallowed ne 'F' |
&& $thisallowed ne '2' |
&& $thisallowed ne '2' |
&& &is_portfolio_url($uri)) { |
&& &is_portfolio_url($uri)) { |
$thisallowed = &portfolio_access($uri,$clientip); |
$thisallowed = &portfolio_access($uri); |
} |
} |
|
|
# Full access at system, domain or course-wide level? Exit. |
# Full access at system, domain or course-wide level? Exit. |
Line 7432 sub allowed {
|
Line 6750 sub allowed {
|
=~/\Q$priv\E\&([^\:]*)/) { |
=~/\Q$priv\E\&([^\:]*)/) { |
my $value = $1; |
my $value = $1; |
if ($priv eq 'bre') { |
if ($priv eq 'bre') { |
if ($noblockcheck) { |
my @blockers = &has_comm_blocking($priv,$symb,$uri); |
$thisallowed.=$value; |
if (@blockers > 0) { |
|
$thisallowed = 'B'; |
} else { |
} else { |
my @blockers = &has_comm_blocking($priv,$symb,$uri); |
$thisallowed.=$value; |
if (@blockers > 0) { |
|
$thisallowed = 'B'; |
|
} else { |
|
$thisallowed.=$value; |
|
} |
|
} |
} |
} else { |
} else { |
$thisallowed.=$value; |
$thisallowed.=$value; |
Line 7474 sub allowed {
|
Line 6788 sub allowed {
|
=~/\Q$priv\E\&([^\:]*)/) { |
=~/\Q$priv\E\&([^\:]*)/) { |
my $value = $1; |
my $value = $1; |
if ($priv eq 'bre') { |
if ($priv eq 'bre') { |
if ($noblockcheck) { |
my @blockers = &has_comm_blocking($priv,$symb,$refuri); |
$thisallowed.=$value; |
if (@blockers > 0) { |
|
$thisallowed = 'B'; |
} else { |
} else { |
my @blockers = &has_comm_blocking($priv,$symb,$refuri); |
$thisallowed.=$value; |
if (@blockers > 0) { |
|
$thisallowed = 'B'; |
|
} else { |
|
$thisallowed.=$value; |
|
} |
|
} |
} |
} else { |
} else { |
$thisallowed.=$value; |
$thisallowed.=$value; |
Line 7658 sub constructaccess {
|
Line 6968 sub constructaccess {
|
my ($ownername,$ownerdomain,$ownerhome); |
my ($ownername,$ownerdomain,$ownerhome); |
|
|
($ownerdomain,$ownername) = |
($ownerdomain,$ownername) = |
($url=~ m{^(?:\Q$perlvar{'lonDocRoot'}\E|)/priv/($match_domain)/($match_username)(?:/|$)}); |
($url=~ m{^(?:\Q$perlvar{'lonDocRoot'}\E|)/priv/($match_domain)/($match_username)/}); |
|
|
# The URL does not really point to any authorspace, forget it |
# The URL does not really point to any authorspace, forget it |
unless (($ownername) && ($ownerdomain)) { return ''; } |
unless (($ownername) && ($ownerdomain)) { return ''; } |
Line 7713 sub constructaccess {
|
Line 7023 sub constructaccess {
|
return ''; |
return ''; |
} |
} |
|
|
# ----------------------------------------------------------- Content Blocking |
|
|
|
{ |
|
# Caches for faster Course Contents display where content blocking |
|
# is in operation (i.e., interval param set) for timed quiz. |
|
# |
|
# User for whom data are being temporarily cached. |
|
my $cacheduser=''; |
|
# Cached blockers for this user (a hash of blocking items). |
|
my %cachedblockers=(); |
|
# When the data were last cached. |
|
my $cachedlast=''; |
|
|
|
sub load_all_blockers { |
|
my ($uname,$udom,$blocks)=@_; |
|
if (($uname ne '') && ($udom ne '')) { |
|
if (($cacheduser eq $uname.':'.$udom) && |
|
(abs($cachedlast-time)<5)) { |
|
return; |
|
} |
|
} |
|
$cachedlast=time; |
|
$cacheduser=$uname.':'.$udom; |
|
%cachedblockers = &get_commblock_resources($blocks); |
|
} |
|
|
|
sub get_comm_blocks { |
sub get_comm_blocks { |
my ($cdom,$cnum) = @_; |
my ($cdom,$cnum) = @_; |
if ($cdom eq '' || $cnum eq '') { |
if ($cdom eq '' || $cnum eq '') { |
Line 7759 sub get_comm_blocks {
|
Line 7043 sub get_comm_blocks {
|
return %commblocks; |
return %commblocks; |
} |
} |
|
|
sub get_commblock_resources { |
sub has_comm_blocking { |
my ($blocks) = @_; |
my ($priv,$symb,$uri,$blocks) = @_; |
my %blockers = (); |
return unless ($env{'request.course.id'}); |
return %blockers unless ($env{'request.course.id'}); |
return unless ($priv eq 'bre'); |
return %blockers if ($env{'user.priv.'.$env{'request.role'}} =~/evb\&([^\:]*)/); |
return if ($env{'user.priv.'.$env{'request.role'}} =~/evb\&([^\:]*)/); |
my %commblocks; |
my %commblocks; |
if (ref($blocks) eq 'HASH') { |
if (ref($blocks) eq 'HASH') { |
%commblocks = %{$blocks}; |
%commblocks = %{$blocks}; |
} else { |
} else { |
%commblocks = &get_comm_blocks(); |
%commblocks = &get_comm_blocks(); |
} |
} |
return %blockers unless (keys(%commblocks) > 0); |
return unless (keys(%commblocks) > 0); |
my $navmap = Apache::lonnavmaps::navmap->new(); |
if (!$symb) { $symb=&symbread($uri,1); } |
return %blockers unless (ref($navmap)); |
my ($map,$resid,undef)=&decode_symb($symb); |
|
my %tocheck = ( |
|
maps => $map, |
|
resources => $symb, |
|
); |
|
my @blockers; |
my $now = time; |
my $now = time; |
|
my $navmap = Apache::lonnavmaps::navmap->new(); |
foreach my $block (keys(%commblocks)) { |
foreach my $block (keys(%commblocks)) { |
if ($block =~ /^(\d+)____(\d+)$/) { |
if ($block =~ /^(\d+)____(\d+)$/) { |
my ($start,$end) = ($1,$2); |
my ($start,$end) = ($1,$2); |
Line 7781 sub get_commblock_resources {
|
Line 7071 sub get_commblock_resources {
|
if (ref($commblocks{$block}{'blocks'}) eq 'HASH') { |
if (ref($commblocks{$block}{'blocks'}) eq 'HASH') { |
if (ref($commblocks{$block}{'blocks'}{'docs'}) eq 'HASH') { |
if (ref($commblocks{$block}{'blocks'}{'docs'}) eq 'HASH') { |
if (ref($commblocks{$block}{'blocks'}{'docs'}{'maps'}) eq 'HASH') { |
if (ref($commblocks{$block}{'blocks'}{'docs'}{'maps'}) eq 'HASH') { |
if (keys(%{$commblocks{$block}{'blocks'}{'docs'}{'maps'}})) { |
if ($commblocks{$block}{'blocks'}{'docs'}{'maps'}{$map}) { |
$blockers{$block}{maps} = $commblocks{$block}{'blocks'}{'docs'}{'maps'}; |
unless (grep(/^\Q$block\E$/,@blockers)) { |
|
push(@blockers,$block); |
|
} |
} |
} |
} |
} |
if (ref($commblocks{$block}{'blocks'}{'docs'}{'resources'}) eq 'HASH') { |
if (ref($commblocks{$block}{'blocks'}{'docs'}{'resources'}) eq 'HASH') { |
if (keys(%{$commblocks{$block}{'blocks'}{'docs'}{'resources'}})) { |
if ($commblocks{$block}{'blocks'}{'docs'}{'resources'}{$symb}) { |
$blockers{$block}{'resources'} = $commblocks{$block}{'blocks'}{'docs'}{'resources'}; |
unless (grep(/^\Q$block\E$/,@blockers)) { |
|
push(@blockers,$block); |
|
} |
} |
} |
} |
} |
} |
} |
Line 7798 sub get_commblock_resources {
|
Line 7092 sub get_commblock_resources {
|
my @to_test; |
my @to_test; |
if (ref($commblocks{$block}{'blocks'}) eq 'HASH') { |
if (ref($commblocks{$block}{'blocks'}) eq 'HASH') { |
if (ref($commblocks{$block}{'blocks'}{'docs'}) eq 'HASH') { |
if (ref($commblocks{$block}{'blocks'}{'docs'}) eq 'HASH') { |
my @interval; |
my $check_interval; |
my $type = 'map'; |
if (&check_docs_block($commblocks{$block}{'blocks'}{'docs'},\%tocheck)) { |
if ($item eq 'course') { |
my @interval; |
$type = 'course'; |
my $type = 'map'; |
@interval=&EXT("resource.0.interval"); |
if ($item eq 'course') { |
} else { |
$type = 'course'; |
if ($item =~ /___\d+___/) { |
@interval=&EXT("resource.0.interval"); |
$type = 'resource'; |
|
@interval=&EXT("resource.0.interval",$item); |
|
if (ref($navmap)) { |
|
my $res = $navmap->getBySymb($item); |
|
push(@to_test,$res); |
|
} |
|
} else { |
} else { |
my $mapsymb = &symbread($item,1); |
if ($item =~ /___\d+___/) { |
if ($mapsymb) { |
$type = 'resource'; |
if (ref($navmap)) { |
@interval=&EXT("resource.0.interval",$item); |
my $mapres = $navmap->getBySymb($mapsymb); |
if (ref($navmap)) { |
@to_test = $mapres->retrieveResources($mapres,undef,0,0,0,1); |
my $res = $navmap->getBySymb($item); |
foreach my $res (@to_test) { |
push(@to_test,$res); |
my $symb = $res->symb(); |
} |
next if ($symb eq $mapsymb); |
} else { |
if ($symb ne '') { |
my $mapsymb = &symbread($item,1); |
@interval=&EXT("resource.0.interval",$symb); |
if ($mapsymb) { |
if ($interval[1] eq 'map') { |
if (ref($navmap)) { |
|
my $mapres = $navmap->getBySymb($mapsymb); |
|
@to_test = $mapres->retrieveResources($mapres,undef,0,1); |
|
foreach my $res (@to_test) { |
|
my $symb = $res->symb(); |
|
next if ($symb eq $mapsymb); |
|
if ($symb ne '') { |
|
@interval=&EXT("resource.0.interval",$symb); |
last; |
last; |
} |
} |
} |
} |
Line 7830 sub get_commblock_resources {
|
Line 7125 sub get_commblock_resources {
|
} |
} |
} |
} |
} |
} |
} |
if ($interval[0] =~ /\d+/) { |
if ($interval[0] =~ /^(\d+)/) { |
my $first_access; |
my $timelimit = $1; |
if ($type eq 'resource') { |
my $first_access; |
$first_access=&get_first_access($interval[1],$item); |
if ($type eq 'resource') { |
} elsif ($type eq 'map') { |
$first_access=&get_first_access($interval[1],$item); |
$first_access=&get_first_access($interval[1],undef,$item); |
} elsif ($type eq 'map') { |
} else { |
$first_access=&get_first_access($interval[1],undef,$item); |
$first_access=&get_first_access($interval[1]); |
} else { |
} |
$first_access=&get_first_access($interval[1]); |
if ($first_access) { |
} |
my $timesup = $first_access+$interval[0]; |
if ($first_access) { |
if ($timesup > $now) { |
my $timesup = $first_access+$timelimit; |
foreach my $res (@to_test) { |
if ($timesup > $now) { |
if ($res->is_problem()) { |
my $activeblock; |
if ($res->completable()) { |
foreach my $res (@to_test) { |
unless (grep(/^\Q$block\E$/,@blockers)) { |
if ($res->answerable()) { |
push(@blockers,$block); |
$activeblock = 1; |
} |
last; |
last; |
} |
} |
} |
|
if ($activeblock) { |
|
if (ref($commblocks{$block}{'blocks'}{'docs'}{'maps'}) eq 'HASH') { |
|
if (keys(%{$commblocks{$block}{'blocks'}{'docs'}{'maps'}})) { |
|
$blockers{$block}{'maps'} = $commblocks{$block}{'blocks'}{'docs'}{'maps'}; |
|
} |
|
} |
|
if (ref($commblocks{$block}{'blocks'}{'docs'}{'resources'}) eq 'HASH') { |
|
if (keys(%{$commblocks{$block}{'blocks'}{'docs'}{'resources'}})) { |
|
$blockers{$block}{'resources'} = $commblocks{$block}{'blocks'}{'docs'}{'resources'}; |
|
} |
} |
} |
} |
} |
} |
Line 7870 sub get_commblock_resources {
|
Line 7155 sub get_commblock_resources {
|
} |
} |
} |
} |
} |
} |
return %blockers; |
return @blockers; |
} |
} |
|
|
sub has_comm_blocking { |
sub check_docs_block { |
my ($priv,$symb,$uri,$blocks) = @_; |
my ($docsblock,$tocheck) =@_; |
my @blockers; |
if ((ref($docsblock) ne 'HASH') || (ref($tocheck) ne 'HASH')) { |
return unless ($env{'request.course.id'}); |
return; |
return unless ($priv eq 'bre'); |
|
return if ($env{'user.priv.'.$env{'request.role'}} =~/evb\&([^\:]*)/); |
|
return if ($env{'request.state'} eq 'construct'); |
|
&load_all_blockers($env{'user.name'},$env{'user.domain'},$blocks); |
|
return unless (keys(%cachedblockers) > 0); |
|
my (%possibles,@symbs); |
|
if (!$symb) { |
|
$symb = &symbread($uri,1,1,1,\%possibles); |
|
} |
} |
if ($symb) { |
if (ref($docsblock->{'maps'}) eq 'HASH') { |
@symbs = ($symb); |
if ($tocheck->{'maps'}) { |
} elsif (keys(%possibles)) { |
if ($docsblock->{'maps'}{$tocheck->{'maps'}}) { |
@symbs = keys(%possibles); |
return 1; |
} |
|
my $noblock; |
|
foreach my $symb (@symbs) { |
|
last if ($noblock); |
|
my ($map,$resid,$resurl)=&decode_symb($symb); |
|
foreach my $block (keys(%cachedblockers)) { |
|
if ($block =~ /^firstaccess____(.+)$/) { |
|
my $item = $1; |
|
if (($item eq $map) || ($item eq $symb)) { |
|
$noblock = 1; |
|
last; |
|
} |
|
} |
|
if (ref($cachedblockers{$block}) eq 'HASH') { |
|
if (ref($cachedblockers{$block}{'resources'}) eq 'HASH') { |
|
if ($cachedblockers{$block}{'resources'}{$symb}) { |
|
unless (grep(/^\Q$block\E$/,@blockers)) { |
|
push(@blockers,$block); |
|
} |
|
} |
|
} |
|
} |
} |
if (ref($cachedblockers{$block}{'maps'}) eq 'HASH') { |
} |
if ($cachedblockers{$block}{'maps'}{$map}) { |
} |
unless (grep(/^\Q$block\E$/,@blockers)) { |
if (ref($docsblock->{'resources'}) eq 'HASH') { |
push(@blockers,$block); |
if ($tocheck->{'resources'}) { |
} |
if ($docsblock->{'resources'}{$tocheck->{'resources'}}) { |
} |
return 1; |
} |
} |
} |
} |
} |
} |
return if ($noblock); |
return; |
return @blockers; |
|
} |
|
} |
} |
|
|
# -------------------------------- Deversion and split uri into path an filename |
|
|
|
# |
# |
# Removes the version from a URI and |
# Removes the versino from a URI and |
# splits it in to its filename and path to the filename. |
# splits it in to its filename and path to the filename. |
# Seems like File::Basename could have done this more clearly. |
# Seems like File::Basename could have done this more clearly. |
# Parameters: |
# Parameters: |
Line 7997 sub get_symb_from_alias {
|
Line 7249 sub get_symb_from_alias {
|
|
|
sub definerole { |
sub definerole { |
if (allowed('mcr','/')) { |
if (allowed('mcr','/')) { |
my ($rolename,$sysrole,$domrole,$courole,$uname,$udom)=@_; |
my ($rolename,$sysrole,$domrole,$courole)=@_; |
foreach my $role (split(':',$sysrole)) { |
foreach my $role (split(':',$sysrole)) { |
my ($crole,$cqual)=split(/\&/,$role); |
my ($crole,$cqual)=split(/\&/,$role); |
if ($pr{'cr:s'}!~/\Q$crole\E/) { return "refused:s:$crole"; } |
if ($pr{'cr:s'}!~/\Q$crole\E/) { return "refused:s:$crole"; } |
Line 8025 sub definerole {
|
Line 7277 sub definerole {
|
} |
} |
} |
} |
} |
} |
my $uhome; |
|
if (($uname ne '') && ($udom ne '')) { |
|
$uhome = &homeserver($uname,$udom); |
|
return $uhome if ($uhome eq 'no_host'); |
|
} else { |
|
$uname = $env{'user.name'}; |
|
$udom = $env{'user.domain'}; |
|
$uhome = $env{'user.home'}; |
|
} |
|
my $command="encrypt:rolesput:$env{'user.domain'}:$env{'user.name'}:". |
my $command="encrypt:rolesput:$env{'user.domain'}:$env{'user.name'}:". |
"$udom:$uname:rolesdef_$rolename=". |
"$env{'user.domain'}:$env{'user.name'}:". |
|
"rolesdef_$rolename=". |
escape($sysrole.'_'.$domrole.'_'.$courole); |
escape($sysrole.'_'.$domrole.'_'.$courole); |
return reply($command,$uhome); |
return reply($command,$env{'user.home'}); |
} else { |
} else { |
return 'refused'; |
return 'refused'; |
} |
} |
Line 8052 sub metadata_query {
|
Line 7296 sub metadata_query {
|
my @server_list = (defined($server_array) ? @$server_array |
my @server_list = (defined($server_array) ? @$server_array |
: keys(%libserv) ); |
: keys(%libserv) ); |
for my $server (@server_list) { |
for my $server (@server_list) { |
my $domains = ''; |
my $domains = ''; |
if (ref($domains_hash) eq 'HASH') { |
if (ref($domains_hash) eq 'HASH') { |
$domains = $domains_hash->{$server}; |
$domains = $domains_hash->{$server}; |
} |
} |
unless ($custom or $customshow) { |
unless ($custom or $customshow) { |
my $reply=&reply("querysend:".&escape($query).':::'.&escape($domains),$server); |
my $reply=&reply("querysend:".&escape($query).':::'.&escape($domains),$server); |
Line 8119 sub update_allusers_table {
|
Line 7363 sub update_allusers_table {
|
|
|
sub fetch_enrollment_query { |
sub fetch_enrollment_query { |
my ($context,$affiliatesref,$replyref,$dom,$cnum) = @_; |
my ($context,$affiliatesref,$replyref,$dom,$cnum) = @_; |
my ($homeserver,$sleep,$loopmax); |
my $homeserver; |
my $maxtries = 1; |
my $maxtries = 1; |
if ($context eq 'automated') { |
if ($context eq 'automated') { |
$homeserver = $perlvar{'lonHostID'}; |
$homeserver = $perlvar{'lonHostID'}; |
$sleep = 2; |
|
$loopmax = 100; |
|
$maxtries = 10; # will wait for up to 2000s for retrieval of classlist data before timeout |
$maxtries = 10; # will wait for up to 2000s for retrieval of classlist data before timeout |
} else { |
} else { |
$homeserver = &homeserver($cnum,$dom); |
$homeserver = &homeserver($cnum,$dom); |
Line 8142 sub fetch_enrollment_query {
|
Line 7384 sub fetch_enrollment_query {
|
&logthis('fetch_enrollment_query: invalid queryid: '.$queryid.' for host: '.$host.' and homeserver: '.$homeserver.' context: '.$context.' '.$cnum); |
&logthis('fetch_enrollment_query: invalid queryid: '.$queryid.' for host: '.$host.' and homeserver: '.$homeserver.' context: '.$context.' '.$cnum); |
return 'error: '.$queryid; |
return 'error: '.$queryid; |
} |
} |
my $reply = &get_query_reply($queryid,$sleep,$loopmax); |
my $reply = &get_query_reply($queryid); |
my $tries = 1; |
my $tries = 1; |
while (($reply=~/^timeout/) && ($tries < $maxtries)) { |
while (($reply=~/^timeout/) && ($tries < $maxtries)) { |
$reply = &get_query_reply($queryid,$sleep,$loopmax); |
$reply = &get_query_reply($queryid); |
$tries ++; |
$tries ++; |
} |
} |
if ( ($reply =~/^timeout/) || ($reply =~/^error/) ) { |
if ( ($reply =~/^timeout/) || ($reply =~/^error/) ) { |
&logthis('fetch_enrollment_query error: '.$reply.' for '.$dom.' '.$env{'user.name'}.' for '.$queryid.' context: '.$context.' '.$cnum.' maxtries: '.$maxtries.' tries: '.$tries); |
&logthis('fetch_enrollment_query error: '.$reply.' for '.$dom.' '.$env{'user.name'}.' for '.$queryid.' context: '.$context.' '.$cnum.' maxtries: '.$maxtries.' tries: '.$tries); |
} else { |
} else { |
my @responses = split(/:/,$reply); |
my @responses = split(/:/,$reply); |
if (grep { $_ eq $homeserver } ¤t_machine_ids()) { |
if ($homeserver eq $perlvar{'lonHostID'}) { |
foreach my $line (@responses) { |
foreach my $line (@responses) { |
my ($key,$value) = split(/=/,$line,2); |
my ($key,$value) = split(/=/,$line,2); |
$$replyref{$key} = $value; |
$$replyref{$key} = $value; |
Line 8187 sub fetch_enrollment_query {
|
Line 7429 sub fetch_enrollment_query {
|
} |
} |
|
|
sub get_query_reply { |
sub get_query_reply { |
my ($queryid,$sleep,$loopmax) = @_; |
my $queryid=shift; |
if (($sleep eq '') || ($sleep !~ /^\d+\.?\d*$/)) { |
|
$sleep = 0.2; |
|
} |
|
if (($loopmax eq '') || ($loopmax =~ /\D/)) { |
|
$loopmax = 100; |
|
} |
|
my $replyfile=LONCAPA::tempdir().$queryid; |
my $replyfile=LONCAPA::tempdir().$queryid; |
my $reply=''; |
my $reply=''; |
for (1..$loopmax) { |
for (1..100) { |
sleep($sleep); |
sleep 2; |
if (-e $replyfile.'.end') { |
if (-e $replyfile.'.end') { |
if (open(my $fh,$replyfile)) { |
if (open(my $fh,$replyfile)) { |
$reply = join('',<$fh>); |
$reply = join('',<$fh>); |
Line 8559 sub auto_courserequest_checks {
|
Line 7795 sub auto_courserequest_checks {
|
} |
} |
|
|
sub auto_courserequest_validation { |
sub auto_courserequest_validation { |
my ($dom,$owner,$crstype,$inststatuslist,$instcode,$instseclist,$custominfo) = @_; |
my ($dom,$owner,$crstype,$inststatuslist,$instcode,$instseclist) = @_; |
my ($homeserver,$response); |
my ($homeserver,$response); |
if ($dom =~ /^$match_domain$/) { |
if ($dom =~ /^$match_domain$/) { |
$homeserver = &domain($dom,'primary'); |
$homeserver = &domain($dom,'primary'); |
} |
} |
unless ($homeserver eq 'no_host') { |
unless ($homeserver eq 'no_host') { |
my $customdata; |
|
if (ref($custominfo) eq 'HASH') { |
|
$customdata = &freeze_escape($custominfo); |
|
} |
|
$response=&unescape(&reply('autocrsreqvalidation:'.$dom.':'.&escape($owner). |
$response=&unescape(&reply('autocrsreqvalidation:'.$dom.':'.&escape($owner). |
':'.&escape($crstype).':'.&escape($inststatuslist). |
':'.&escape($crstype).':'.&escape($inststatuslist). |
':'.&escape($instcode).':'.&escape($instseclist).':'. |
':'.&escape($instcode).':'.&escape($instseclist), |
$customdata,$homeserver)); |
$homeserver)); |
} |
} |
return $response; |
return $response; |
} |
} |
Line 8591 sub auto_validate_class_sec {
|
Line 7824 sub auto_validate_class_sec {
|
return $response; |
return $response; |
} |
} |
|
|
sub auto_crsreq_update { |
|
my ($cdom,$cnum,$crstype,$action,$ownername,$ownerdomain,$fullname,$title, |
|
$code,$accessstart,$accessend,$inbound) = @_; |
|
my ($homeserver,%crsreqresponse); |
|
if ($cdom =~ /^$match_domain$/) { |
|
$homeserver = &domain($cdom,'primary'); |
|
} |
|
unless (($homeserver eq 'no_host') || ($homeserver eq '')) { |
|
my $info; |
|
if (ref($inbound) eq 'HASH') { |
|
$info = &freeze_escape($inbound); |
|
} |
|
my $response=&reply('autocrsrequpdate:'.$cdom.':'.$cnum.':'.&escape($crstype). |
|
':'.&escape($action).':'.&escape($ownername).':'. |
|
&escape($ownerdomain).':'.&escape($fullname).':'. |
|
&escape($title).':'.&escape($code).':'. |
|
&escape($accessstart).':'.&escape($accessend).':'.$info,$homeserver); |
|
unless ($response =~ /(con_lost|error|no_such_host|refused)/) { |
|
my @items = split(/&/,$response); |
|
foreach my $item (@items) { |
|
my ($key,$value) = split('=',$item); |
|
$crsreqresponse{&unescape($key)} = &thaw_unescape($value); |
|
} |
|
} |
|
} |
|
return \%crsreqresponse; |
|
} |
|
|
|
sub auto_export_grades { |
|
my ($cdom,$cnum,$inforef,$gradesref) = @_; |
|
my ($homeserver,%exportresponse); |
|
if ($cdom =~ /^$match_domain$/) { |
|
$homeserver = &domain($cdom,'primary'); |
|
} |
|
unless (($homeserver eq 'no_host') || ($homeserver eq '')) { |
|
my $info; |
|
if (ref($inforef) eq 'HASH') { |
|
$info = &freeze_escape($inforef); |
|
} |
|
if (ref($gradesref) eq 'HASH') { |
|
my $grades = &freeze_escape($gradesref); |
|
my $response=&reply('encrypt:autoexportgrades:'.$cdom.':'.$cnum.':'. |
|
$info.':'.$grades,$homeserver); |
|
unless ($response =~ /(con_lost|error|no_such_host|refused|unknown_command)/) { |
|
my @items = split(/&/,$response); |
|
foreach my $item (@items) { |
|
my ($key,$value) = split('=',$item); |
|
$exportresponse{&unescape($key)} = &thaw_unescape($value); |
|
} |
|
} |
|
} |
|
} |
|
return \%exportresponse; |
|
} |
|
|
|
sub check_instcode_cloning { |
|
my ($codedefaults,$code_order,$cloner,$clonefromcode,$clonetocode) = @_; |
|
unless ((ref($codedefaults) eq 'HASH') && (ref($code_order) eq 'ARRAY')) { |
|
return; |
|
} |
|
my $canclone; |
|
if (@{$code_order} > 0) { |
|
my $instcoderegexp ='^'; |
|
my @clonecodes = split(/\&/,$cloner); |
|
foreach my $item (@{$code_order}) { |
|
if (grep(/^\Q$item\E=/,@clonecodes)) { |
|
foreach my $pair (@clonecodes) { |
|
my ($key,$val) = split(/\=/,$pair,2); |
|
$val = &unescape($val); |
|
if ($key eq $item) { |
|
$instcoderegexp .= '('.$val.')'; |
|
last; |
|
} |
|
} |
|
} else { |
|
$instcoderegexp .= $codedefaults->{$item}; |
|
} |
|
} |
|
$instcoderegexp .= '$'; |
|
my (@from,@to); |
|
eval { |
|
(@from) = ($clonefromcode =~ /$instcoderegexp/); |
|
(@to) = ($clonetocode =~ /$instcoderegexp/); |
|
}; |
|
if ((@from > 0) && (@to > 0)) { |
|
my @diffs = &Apache::loncommon::compare_arrays(\@from,\@to); |
|
if (!@diffs) { |
|
$canclone = 1; |
|
} |
|
} |
|
} |
|
return $canclone; |
|
} |
|
|
|
sub default_instcode_cloning { |
|
my ($clonedom,$domdefclone,$clonefromcode,$clonetocode,$codedefaultsref,$codeorderref) = @_; |
|
my (%codedefaults,@code_order,$canclone); |
|
if ((ref($codedefaultsref) eq 'HASH') && (ref($codeorderref) eq 'ARRAY')) { |
|
%codedefaults = %{$codedefaultsref}; |
|
@code_order = @{$codeorderref}; |
|
} elsif ($clonedom) { |
|
&auto_instcode_defaults($clonedom,\%codedefaults,\@code_order); |
|
} |
|
if (($domdefclone) && (@code_order)) { |
|
my @clonecodes = split(/\+/,$domdefclone); |
|
my $instcoderegexp ='^'; |
|
foreach my $item (@code_order) { |
|
if (grep(/^\Q$item\E$/,@clonecodes)) { |
|
$instcoderegexp .= '('.$codedefaults{$item}.')'; |
|
} else { |
|
$instcoderegexp .= $codedefaults{$item}; |
|
} |
|
} |
|
$instcoderegexp .= '$'; |
|
my (@from,@to); |
|
eval { |
|
(@from) = ($clonefromcode =~ /$instcoderegexp/); |
|
(@to) = ($clonetocode =~ /$instcoderegexp/); |
|
}; |
|
if ((@from > 0) && (@to > 0)) { |
|
my @diffs = &Apache::loncommon::compare_arrays(\@from,\@to); |
|
if (!@diffs) { |
|
$canclone = 1; |
|
} |
|
} |
|
} |
|
return $canclone; |
|
} |
|
|
|
# ------------------------------------------------------- Course Group routines |
# ------------------------------------------------------- Course Group routines |
|
|
sub get_coursegroups { |
sub get_coursegroups { |
Line 8988 sub assignrole {
|
Line 8092 sub assignrole {
|
} |
} |
} |
} |
} elsif ($context eq 'requestauthor') { |
} elsif ($context eq 'requestauthor') { |
if (($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'}) && |
if (($udom eq $env{'user.domain'}) && ($uname eq $env{'user.name'}) && |
($url eq '/'.$udom.'/') && ($role eq 'au')) { |
($url eq '/'.$udom.'/') && ($role eq 'au')) { |
if ($env{'environment.requestauthor'} eq 'automatic') { |
if ($env{'environment.requestauthor'} eq 'automatic') { |
$refused = ''; |
$refused = ''; |
Line 8996 sub assignrole {
|
Line 8100 sub assignrole {
|
my %domdefaults = &get_domain_defaults($udom); |
my %domdefaults = &get_domain_defaults($udom); |
if (ref($domdefaults{'requestauthor'}) eq 'HASH') { |
if (ref($domdefaults{'requestauthor'}) eq 'HASH') { |
my $checkbystatus; |
my $checkbystatus; |
if ($env{'user.adv'}) { |
if ($env{'user.adv'}) { |
my $disposition = $domdefaults{'requestauthor'}{'_LC_adv'}; |
my $disposition = $domdefaults{'requestauthor'}{'_LC_adv'}; |
if ($disposition eq 'automatic') { |
if ($disposition eq 'automatic') { |
$refused = ''; |
$refused = ''; |
} elsif ($disposition eq '') { |
} elsif ($disposition eq '') { |
$checkbystatus = 1; |
$checkbystatus = 1; |
} |
} |
} else { |
} else { |
$checkbystatus = 1; |
$checkbystatus = 1; |
} |
} |
Line 9084 sub assignrole {
|
Line 8188 sub assignrole {
|
&courserolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag, |
&courserolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag, |
$selfenroll,$context); |
$selfenroll,$context); |
} elsif (($role eq 'li') || ($role eq 'dg') || ($role eq 'sc') || |
} elsif (($role eq 'li') || ($role eq 'dg') || ($role eq 'sc') || |
($role eq 'au') || ($role eq 'dc') || ($role eq 'dh') || |
($role eq 'au') || ($role eq 'dc')) { |
($role eq 'da')) { |
|
&domainrolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag, |
&domainrolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag, |
$context); |
$context); |
} elsif (($role eq 'ca') || ($role eq 'aa')) { |
} elsif (($role eq 'ca') || ($role eq 'aa')) { |
&coauthorrolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag, |
&coauthorrolelog($role,$uname,$udom,$url,$origstart,$origend,$delflag, |
$context); |
$context); |
} |
} |
if ($role eq 'cc') { |
if ($role eq 'cc') { |
&autoupdate_coowners($url,$end,$start,$uname,$udom); |
&autoupdate_coowners($url,$end,$start,$uname,$udom); |
Line 9390 sub modifyuser {
|
Line 8493 sub modifyuser {
|
sub modifystudent { |
sub modifystudent { |
my ($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$usec, |
my ($udom,$uname,$uid,$umode,$upass,$first,$middle,$last,$gene,$usec, |
$end,$start,$forceid,$desiredhome,$email,$type,$locktype,$cid, |
$end,$start,$forceid,$desiredhome,$email,$type,$locktype,$cid, |
$selfenroll,$context,$inststatus,$credits,$instsec)=@_; |
$selfenroll,$context,$inststatus,$credits)=@_; |
if (!$cid) { |
if (!$cid) { |
unless ($cid=$env{'request.course.id'}) { |
unless ($cid=$env{'request.course.id'}) { |
return 'not_in_class'; |
return 'not_in_class'; |
Line 9405 sub modifystudent {
|
Line 8508 sub modifystudent {
|
# student's environment |
# student's environment |
$uid = undef if (!$forceid); |
$uid = undef if (!$forceid); |
$reply = &modify_student_enrollment($udom,$uname,$uid,$first,$middle,$last, |
$reply = &modify_student_enrollment($udom,$uname,$uid,$first,$middle,$last, |
$gene,$usec,$end,$start,$type,$locktype, |
$gene,$usec,$end,$start,$type,$locktype, |
$cid,$selfenroll,$context,$credits,$instsec); |
$cid,$selfenroll,$context,$credits); |
return $reply; |
return $reply; |
} |
} |
|
|
sub modify_student_enrollment { |
sub modify_student_enrollment { |
my ($udom,$uname,$uid,$first,$middle,$last,$gene,$usec,$end,$start,$type, |
my ($udom,$uname,$uid,$first,$middle,$last,$gene,$usec,$end,$start,$type, |
$locktype,$cid,$selfenroll,$context,$credits,$instsec) = @_; |
$locktype,$cid,$selfenroll,$context,$credits) = @_; |
my ($cdom,$cnum,$chome); |
my ($cdom,$cnum,$chome); |
if (!$cid) { |
if (!$cid) { |
unless ($cid=$env{'request.course.id'}) { |
unless ($cid=$env{'request.course.id'}) { |
Line 9459 sub modify_student_enrollment {
|
Line 8562 sub modify_student_enrollment {
|
my %old_entry = &Apache::lonnet::get('classlist',[$user],$cdom,$cnum); |
my %old_entry = &Apache::lonnet::get('classlist',[$user],$cdom,$cnum); |
my $reply=cput('classlist', |
my $reply=cput('classlist', |
{$user => |
{$user => |
join(':',$end,$start,$uid,$usec,$fullname,$type,$locktype,$credits,$instsec) }, |
join(':',$end,$start,$uid,$usec,$fullname,$type,$locktype,$credits) }, |
$cdom,$cnum); |
$cdom,$cnum); |
if (($reply eq 'ok') || ($reply eq 'delayed')) { |
if (($reply eq 'ok') || ($reply eq 'delayed')) { |
&devalidate_getsection_cache($udom,$uname,$cid); |
&devalidate_getsection_cache($udom,$uname,$cid); |
Line 9983 sub modify_access_controls {
|
Line 9086 sub modify_access_controls {
|
my $tries = 0; |
my $tries = 0; |
my $gotlock = &newput('file_permissions',$lockhash,$domain,$user); |
my $gotlock = &newput('file_permissions',$lockhash,$domain,$user); |
|
|
while (($gotlock ne 'ok') && $tries < 10) { |
while (($gotlock ne 'ok') && $tries <3) { |
$tries ++; |
$tries ++; |
sleep(0.1); |
sleep 1; |
$gotlock = &newput('file_permissions',$lockhash,$domain,$user); |
$gotlock = &newput('file_permissions',$lockhash,$domain,$user); |
} |
} |
if ($gotlock eq 'ok') { |
if ($gotlock eq 'ok') { |
Line 10278 sub dirlist {
|
Line 9381 sub dirlist {
|
foreach my $user (sort(keys(%allusers))) { |
foreach my $user (sort(keys(%allusers))) { |
push(@alluserslist,$user.'&user'); |
push(@alluserslist,$user.'&user'); |
} |
} |
if (!%listerror) { |
return (\@alluserslist); |
# no errors |
|
return (\@alluserslist); |
|
} elsif (scalar(keys(%servers)) == 1) { |
|
# one library server, one error |
|
my ($key) = keys(%listerror); |
|
return (\@alluserslist, $listerror{$key}); |
|
} elsif ( grep { $_ eq 'con_lost' } values(%listerror) ) { |
|
# con_lost indicates that we might miss data from at least one |
|
# library server |
|
return (\@alluserslist, 'con_lost'); |
|
} else { |
|
# multiple library servers and no con_lost -> data should be |
|
# complete. |
|
return (\@alluserslist); |
|
} |
|
|
|
} else { |
} else { |
return ([],'missing username'); |
return ([],'missing username'); |
} |
} |
Line 10511 sub get_userresdata {
|
Line 9598 sub get_userresdata {
|
} |
} |
#error 2 occurs when the .db doesn't exist |
#error 2 occurs when the .db doesn't exist |
if ($tmp!~/error: 2 /) { |
if ($tmp!~/error: 2 /) { |
if ((!defined($cached)) || ($tmp ne 'con_lost')) { |
&logthis("<font color=\"blue\">WARNING:". |
&logthis("<font color=\"blue\">WARNING:". |
" Trying to get resource data for ". |
" Trying to get resource data for ". |
$uname." at ".$udom.": ". |
$uname." at ".$udom.": ". |
$tmp."</font>"); |
$tmp."</font>"); |
|
} |
|
} elsif ($tmp=~/error: 2 /) { |
} elsif ($tmp=~/error: 2 /) { |
#&EXT_cache_set($udom,$uname); |
#&EXT_cache_set($udom,$uname); |
&do_cache_new('userres',$hashid,undef,600); |
&do_cache_new('userres',$hashid,undef,600); |
Line 10530 sub get_userresdata {
|
Line 9615 sub get_userresdata {
|
# Parameters: |
# Parameters: |
# $name - Course/user name. |
# $name - Course/user name. |
# $domain - Name of the domain the user/course is registered on. |
# $domain - Name of the domain the user/course is registered on. |
# $type - Type of thing $name is (must be 'course' or 'user') |
# $type - Type of thing $name is (must be 'course' or 'user' |
# @which - Array of names of resources desired. |
# @which - Array of names of resources desired. |
# Returns: |
# Returns: |
# The value of the first reasource in @which that is found in the |
# The value of the first reasource in @which that is found in the |
Line 10549 sub resdata {
|
Line 9634 sub resdata {
|
} |
} |
if (!ref($result)) { return $result; } |
if (!ref($result)) { return $result; } |
foreach my $item (@which) { |
foreach my $item (@which) { |
if (ref($item) eq 'ARRAY') { |
if (defined($result->{$item->[0]})) { |
if (defined($result->{$item->[0]})) { |
return [$result->{$item->[0]},$item->[1]]; |
return [$result->{$item->[0]},$item->[1]]; |
} |
} |
|
} |
|
} |
} |
return undef; |
return undef; |
} |
} |
|
|
sub get_domain_ltitools { |
|
my ($cdom) = @_; |
|
my %ltitools; |
|
my ($result,$cached)=&is_cached_new('ltitools',$cdom); |
|
if (defined($cached)) { |
|
if (ref($result) eq 'HASH') { |
|
%ltitools = %{$result}; |
|
} |
|
} else { |
|
my %domconfig = &get_dom('configuration',['ltitools'],$cdom); |
|
if (ref($domconfig{'ltitools'}) eq 'HASH') { |
|
%ltitools = %{$domconfig{'ltitools'}}; |
|
my %encdomconfig = &get_dom('encconfig',['ltitools'],$cdom); |
|
if (ref($encdomconfig{'ltitools'}) eq 'HASH') { |
|
foreach my $id (keys(%ltitools)) { |
|
if (ref($encdomconfig{'ltitools'}{$id}) eq 'HASH') { |
|
foreach my $item ('key','secret') { |
|
$ltitools{$id}{$item} = $encdomconfig{'ltitools'}{$id}{$item}; |
|
} |
|
} |
|
} |
|
} |
|
} |
|
my $cachetime = 24*60*60; |
|
&do_cache_new('ltitools',$cdom,\%ltitools,$cachetime); |
|
} |
|
return %ltitools; |
|
} |
|
|
|
sub get_numsuppfiles { |
sub get_numsuppfiles { |
my ($cnum,$cdom,$ignorecache)=@_; |
my ($cnum,$cdom,$ignorecache)=@_; |
my $hashid=$cnum.':'.$cdom; |
my $hashid=$cnum.':'.$cdom; |
Line 10599 sub get_numsuppfiles {
|
Line 9653 sub get_numsuppfiles {
|
unless ($chome eq 'no_host') { |
unless ($chome eq 'no_host') { |
($suppcount,my $errors) = (0,0); |
($suppcount,my $errors) = (0,0); |
my $suppmap = 'supplemental.sequence'; |
my $suppmap = 'supplemental.sequence'; |
($suppcount,$errors) = |
($suppcount,$errors) = |
&Apache::loncommon::recurse_supplemental($cnum,$cdom,$suppmap,$suppcount,$errors); |
&Apache::loncommon::recurse_supplemental($cnum,$cdom,$suppmap,$suppcount,$errors); |
} |
} |
&do_cache_new('suppcount',$hashid,$suppcount,600); |
&do_cache_new('suppcount',$hashid,$suppcount,600); |
Line 10794 sub EXT {
|
Line 9848 sub EXT {
|
$courseid = $cid; |
$courseid = $cid; |
} |
} |
if (($symbparm && $courseid) && |
if (($symbparm && $courseid) && |
(($courseid eq $env{'request.course.id'}) || ($courseid eq $cid))) { |
(($courseid eq $env{'request.course.id'}) || ($courseid eq $cid))) { |
|
|
#print '<br>'.$space.' - '.$qualifier.' - '.$spacequalifierrest; |
#print '<br>'.$space.' - '.$qualifier.' - '.$spacequalifierrest; |
|
|
Line 11041 sub metadata {
|
Line 10095 sub metadata {
|
# if it is a non metadata possible uri return quickly |
# if it is a non metadata possible uri return quickly |
if (($uri eq '') || |
if (($uri eq '') || |
(($uri =~ m|^/*adm/|) && |
(($uri =~ m|^/*adm/|) && |
($uri !~ m|^adm/includes|) && ($uri !~ m{/(smppg|bulletinboard|ext\.tool)$})) || |
($uri !~ m|^adm/includes|) && ($uri !~ m{/(smppg|bulletinboard)$})) || |
($uri =~ m|/$|) || ($uri =~ m|/.meta$|) || ($uri =~ m{^/*uploaded/.+\.sequence$})) { |
($uri =~ m|/$|) || ($uri =~ m|/.meta$|) || ($uri =~ m{^/*uploaded/.+\.sequence$})) { |
return undef; |
return undef; |
} |
} |
if (($uri =~ /^priv/ || $uri=~m{^home/httpd/html/priv}) |
if (($uri =~ /^priv/ || $uri=~/home\/httpd\/html\/priv/) |
&& &Apache::lonxml::get_state('target') =~ /^(|meta)$/) { |
&& &Apache::lonxml::get_state('target') =~ /^(|meta)$/) { |
return undef; |
return undef; |
} |
} |
Line 11306 sub metadata {
|
Line 10360 sub metadata {
|
|
|
$metaentry{':keys'} = join(',',keys(%metathesekeys)); |
$metaentry{':keys'} = join(',',keys(%metathesekeys)); |
&metadata_generate_part0(\%metathesekeys,\%metaentry,$uri); |
&metadata_generate_part0(\%metathesekeys,\%metaentry,$uri); |
$metaentry{':allpossiblekeys'}=join(',',keys(%metathesekeys)); |
$metaentry{':allpossiblekeys'}=join(',',keys %metathesekeys); |
&do_cache_new('meta',$uri,\%metaentry,$cachetime); |
&do_cache_new('meta',$uri,\%metaentry,$cachetime); |
# this is the end of "was not already recently cached |
# this is the end of "was not already recently cached |
} |
} |
Line 11582 sub symbverify {
|
Line 10636 sub symbverify {
|
$ids=$bighash{'ids_'.&clutter($thisurl)}; |
$ids=$bighash{'ids_'.&clutter($thisurl)}; |
} |
} |
unless ($ids) { |
unless ($ids) { |
my $idkey = 'ids_'.($thisurl =~ m{^/}? '' : '/').$thisurl; |
my $idkey = 'ids_'.($thisurl =~ m{^/}? '' : '/').$thisurl; |
$ids=$bighash{$idkey}; |
$ids=$bighash{$idkey}; |
} |
} |
if ($ids) { |
if ($ids) { |
Line 11598 sub symbverify {
|
Line 10652 sub symbverify {
|
if (ref($encstate)) { |
if (ref($encstate)) { |
$$encstate = $bighash{'encrypted_'.$id}; |
$$encstate = $bighash{'encrypted_'.$id}; |
} |
} |
if (($env{'request.role.adv'}) || |
if (($env{'request.role.adv'}) || |
($bighash{'encrypted_'.$id} eq $env{'request.enc'}) || |
($bighash{'encrypted_'.$id} eq $env{'request.enc'}) || |
($thisurl eq '/adm/navmaps')) { |
($thisurl eq '/adm/navmaps')) { |
$okay=1; |
$okay=1; |
last; |
last; |
} |
} |
} |
} |
} |
} |
} |
} |
untie(%bighash); |
untie(%bighash); |
} |
} |
Line 11677 sub deversion {
|
Line 10731 sub deversion {
|
# ------------------------------------------------------ Return symb list entry |
# ------------------------------------------------------ Return symb list entry |
|
|
sub symbread { |
sub symbread { |
my ($thisfn,$donotrecurse,$ignorecachednull,$checkforblock,$possibles)=@_; |
my ($thisfn,$donotrecurse)=@_; |
my $cache_str='request.symbread.cached.'.$thisfn; |
my $cache_str; |
if (defined($env{$cache_str})) { |
if ($thisfn ne '') { |
if ($ignorecachednull) { |
$cache_str='request.symbread.cached.'.$thisfn; |
return $env{$cache_str} unless ($env{$cache_str} eq ''); |
if ($env{$cache_str} ne '') { |
} else { |
|
return $env{$cache_str}; |
return $env{$cache_str}; |
} |
} |
} |
} else { |
# no filename provided? try from environment |
# no filename provided? try from environment |
unless ($thisfn) { |
|
if ($env{'request.symb'}) { |
if ($env{'request.symb'}) { |
return $env{$cache_str}=&symbclean($env{'request.symb'}); |
return $env{$cache_str}=&symbclean($env{'request.symb'}); |
} |
} |
$thisfn=$env{'request.filename'}; |
$thisfn=$env{'request.filename'}; |
} |
} |
if ($thisfn=~m|^/enc/|) { $thisfn=&Apache::lonenc::unencrypted($thisfn); } |
if ($thisfn=~m|^/enc/|) { $thisfn=&Apache::lonenc::unencrypted($thisfn); } |
# is that filename actually a symb? Verify, clean, and return |
# is that filename actually a symb? Verify, clean, and return |
Line 11747 sub symbread {
|
Line 10799 sub symbread {
|
my ($mapid,$resid)=split(/\./,$ids); |
my ($mapid,$resid)=split(/\./,$ids); |
$syval=&encode_symb($bighash{'map_id_'.$mapid}, |
$syval=&encode_symb($bighash{'map_id_'.$mapid}, |
$resid,$thisfn); |
$resid,$thisfn); |
if (ref($possibles) eq 'HASH') { |
} elsif (!$donotrecurse) { |
$possibles->{$syval} = 1; |
|
} |
|
if ($checkforblock) { |
|
my @blockers = &has_comm_blocking('bre',$syval,$bighash{'src_'.$ids}); |
|
if (@blockers) { |
|
$syval = ''; |
|
return; |
|
} |
|
} |
|
} elsif ((!$donotrecurse) || ($checkforblock) || (ref($possibles) eq 'HASH')) { |
|
# ------------------------------------------ There is more than one possibility |
# ------------------------------------------ There is more than one possibility |
my $realpossible=0; |
my $realpossible=0; |
foreach my $id (@possibilities) { |
foreach my $id (@possibilities) { |
my $file=$bighash{'src_'.$id}; |
my $file=$bighash{'src_'.$id}; |
my $canaccess; |
if (&allowed('bre',$file)) { |
if (($donotrecurse) || ($checkforblock) || (ref($possibles) eq 'HASH')) { |
my ($mapid,$resid)=split(/\./,$id); |
$canaccess = 1; |
if ($bighash{'map_type_'.$mapid} ne 'page') { |
} else { |
$realpossible++; |
$canaccess = &allowed('bre',$file); |
$syval=&encode_symb($bighash{'map_id_'.$mapid}, |
} |
$resid,$thisfn); |
if ($canaccess) { |
} |
my ($mapid,$resid)=split(/\./,$id); |
|
if ($bighash{'map_type_'.$mapid} ne 'page') { |
|
my $poss_syval=&encode_symb($bighash{'map_id_'.$mapid}, |
|
$resid,$thisfn); |
|
if (ref($possibles) eq 'HASH') { |
|
$possibles->{$syval} = 1; |
|
} |
|
if ($checkforblock) { |
|
my @blockers = &has_comm_blocking('bre',$poss_syval,$file); |
|
unless (@blockers > 0) { |
|
$syval = $poss_syval; |
|
$realpossible++; |
|
} |
|
} else { |
|
$syval = $poss_syval; |
|
$realpossible++; |
|
} |
|
} |
|
} |
} |
} |
} |
if ($realpossible!=1) { $syval=''; } |
if ($realpossible!=1) { $syval=''; } |
Line 11794 sub symbread {
|
Line 10818 sub symbread {
|
$syval=''; |
$syval=''; |
} |
} |
} |
} |
untie(%bighash); |
untie(%bighash) |
} |
} |
} |
} |
if ($syval) { |
if ($syval) { |
Line 11947 sub rndseed {
|
Line 10971 sub rndseed {
|
$which =&get_rand_alg($courseid); |
$which =&get_rand_alg($courseid); |
} |
} |
if (defined(&getCODE())) { |
if (defined(&getCODE())) { |
|
|
if ($which eq '64bit5') { |
if ($which eq '64bit5') { |
return &rndseed_CODE_64bit5($symb,$courseid,$domain,$username); |
return &rndseed_CODE_64bit5($symb,$courseid,$domain,$username); |
} elsif ($which eq '64bit4') { |
} elsif ($which eq '64bit4') { |
Line 12132 sub rndseed_CODE_64bit5 {
|
Line 11157 sub rndseed_CODE_64bit5 {
|
sub setup_random_from_rndseed { |
sub setup_random_from_rndseed { |
my ($rndseed)=@_; |
my ($rndseed)=@_; |
if ($rndseed =~/([,:])/) { |
if ($rndseed =~/([,:])/) { |
my ($num1,$num2) = map { abs($_); } (split(/[,:]/,$rndseed)); |
my ($num1,$num2)=split(/[,:]/,$rndseed); |
if ((!$num1) || (!$num2) || ($num1 > 2147483562) || ($num2 > 2147483398)) { |
&Math::Random::random_set_seed(abs($num1),abs($num2)); |
&Math::Random::random_set_seed_from_phrase($rndseed); |
|
} else { |
|
&Math::Random::random_set_seed($num1,$num2); |
|
} |
|
} else { |
} else { |
&Math::Random::random_set_seed_from_phrase($rndseed); |
&Math::Random::random_set_seed_from_phrase($rndseed); |
} |
} |
Line 12528 sub default_login_domain {
|
Line 11549 sub default_login_domain {
|
sub declutter { |
sub declutter { |
my $thisfn=shift; |
my $thisfn=shift; |
if ($thisfn=~m|^/enc/|) { $thisfn=&Apache::lonenc::unencrypted($thisfn); } |
if ($thisfn=~m|^/enc/|) { $thisfn=&Apache::lonenc::unencrypted($thisfn); } |
unless ($thisfn=~m{^/home/httpd/html/priv/}) { |
$thisfn=~s/^\Q$perlvar{'lonDocRoot'}\E//; |
$thisfn=~s{^/home/httpd/html}{}; |
|
} |
|
$thisfn=~s/^\///; |
$thisfn=~s/^\///; |
$thisfn=~s|^adm/wrapper/||; |
$thisfn=~s|^adm/wrapper/||; |
$thisfn=~s|^adm/coursedocs/showdoc/||; |
$thisfn=~s|^adm/coursedocs/showdoc/||; |
Line 12573 sub clutter {
|
Line 11592 sub clutter {
|
# &logthis("Got a blank emb style"); |
# &logthis("Got a blank emb style"); |
} |
} |
} |
} |
} elsif ($thisfn =~ m{^/adm/$match_domain/$match_courseid/\d+/ext\.tool$}) { |
|
$thisfn='/adm/wrapper'.$thisfn; |
|
} |
} |
return $thisfn; |
return $thisfn; |
} |
} |
Line 12659 sub get_dns {
|
Line 11676 sub get_dns {
|
$alldns{$host} = $protocol; |
$alldns{$host} = $protocol; |
} |
} |
while (%alldns) { |
while (%alldns) { |
my ($dns) = sort { $b cmp $a } keys(%alldns); |
my ($dns) = keys(%alldns); |
my $ua=new LWP::UserAgent; |
my $ua=new LWP::UserAgent; |
$ua->timeout(30); |
$ua->timeout(30); |
my $request=new HTTP::Request('GET',"$alldns{$dns}://$dns$url"); |
my $request=new HTTP::Request('GET',"$alldns{$dns}://$dns$url"); |
Line 12667 sub get_dns {
|
Line 11684 sub get_dns {
|
delete($alldns{$dns}); |
delete($alldns{$dns}); |
next if ($response->is_error()); |
next if ($response->is_error()); |
my @content = split("\n",$response->content); |
my @content = split("\n",$response->content); |
unless ($nocache) { |
unless ($nocache) { |
&do_cache_new('dns',$url,\@content,30*24*60*60); |
&do_cache_new('dns',$url,\@content,30*24*60*60); |
} |
} |
&$func(\@content,$hashref); |
&$func(\@content,$hashref); |
return; |
return; |
} |
} |
Line 12685 sub get_dns {
|
Line 11702 sub get_dns {
|
# ------------------------------------------------------Get DNS checksums file |
# ------------------------------------------------------Get DNS checksums file |
sub parse_dns_checksums_tab { |
sub parse_dns_checksums_tab { |
my ($lines,$hashref) = @_; |
my ($lines,$hashref) = @_; |
my $lonhost = $perlvar{'lonHostID'}; |
my $machine_dom = &Apache::lonnet::host_domain($perlvar{'lonHostID'}); |
my $machine_dom = &Apache::lonnet::host_domain($lonhost); |
|
my $loncaparev = &get_server_loncaparev($machine_dom); |
my $loncaparev = &get_server_loncaparev($machine_dom); |
my $distro = (split(/\:/,&get_server_distarch($lonhost)))[0]; |
|
my $webconfdir = '/etc/httpd/conf'; |
|
if ($distro =~ /^(ubuntu|debian)(\d+)$/) { |
|
$webconfdir = '/etc/apache2'; |
|
} elsif ($distro =~ /^sles(\d+)$/) { |
|
if ($1 >= 10) { |
|
$webconfdir = '/etc/apache2'; |
|
} |
|
} elsif ($distro =~ /^suse(\d+\.\d+)$/) { |
|
if ($1 >= 10.0) { |
|
$webconfdir = '/etc/apache2'; |
|
} |
|
} |
|
my ($release,$timestamp) = split(/\-/,$loncaparev); |
my ($release,$timestamp) = split(/\-/,$loncaparev); |
my (%chksum,%revnum); |
my (%chksum,%revnum); |
if (ref($lines) eq 'ARRAY') { |
if (ref($lines) eq 'ARRAY') { |
chomp(@{$lines}); |
chomp(@{$lines}); |
my $version = shift(@{$lines}); |
my $versions = shift(@{$lines}); |
if ($version eq $release) { |
my %supported; |
|
if ($versions =~ /^VERSIONS\:([\w\.\,]+)$/) { |
|
my $releaseslist = $1; |
|
if ($releaseslist =~ /,/) { |
|
map { $supported{$_} = 1; } split(/,/,$releaseslist); |
|
} elsif ($releaseslist) { |
|
$supported{$releaseslist} = 1; |
|
} |
|
} |
|
if ($supported{$release}) { |
|
my $matchthis = 0; |
foreach my $line (@{$lines}) { |
foreach my $line (@{$lines}) { |
my ($file,$version,$shasum) = split(/,/,$line); |
if ($line =~ /^(\d[\w\.]+)$/) { |
if ($file =~ m{^/etc/httpd/conf}) { |
if ($matchthis) { |
if ($webconfdir eq '/etc/apache2') { |
last; |
$file =~ s{^\Q/etc/httpd/conf/\E}{$webconfdir/}; |
} elsif ($1 eq $release) { |
|
$matchthis = 1; |
} |
} |
|
} elsif ($matchthis) { |
|
my ($file,$version,$shasum) = split(/,/,$line); |
|
$chksum{$file} = $shasum; |
|
$revnum{$file} = $version; |
} |
} |
$chksum{$file} = $shasum; |
|
$revnum{$file} = $version; |
|
} |
} |
if (ref($hashref) eq 'HASH') { |
if (ref($hashref) eq 'HASH') { |
%{$hashref} = ( |
%{$hashref} = ( |
Line 12729 sub parse_dns_checksums_tab {
|
Line 11745 sub parse_dns_checksums_tab {
|
} |
} |
|
|
sub fetch_dns_checksums { |
sub fetch_dns_checksums { |
my %checksums; |
my %checksums; |
my $machine_dom = &Apache::lonnet::host_domain($perlvar{'lonHostID'}); |
&get_dns('/adm/dns/checksums',\&parse_dns_checksums_tab,1,1, |
my $loncaparev = &get_server_loncaparev($machine_dom,$perlvar{'lonHostID'}); |
|
my ($release,$timestamp) = split(/\-/,$loncaparev); |
|
&get_dns("/adm/dns/checksums/$release",\&parse_dns_checksums_tab,1,1, |
|
\%checksums); |
\%checksums); |
return \%checksums; |
return \%checksums; |
} |
} |
Line 12766 sub fetch_dns_checksums {
|
Line 11779 sub fetch_dns_checksums {
|
} |
} |
|
|
sub load_domain_tab { |
sub load_domain_tab { |
my ($ignore_cache,$nocache) = @_; |
my ($ignore_cache) = @_; |
&get_dns('/adm/dns/domain',\&parse_domain_tab,$ignore_cache,$nocache); |
&get_dns('/adm/dns/domain',\&parse_domain_tab,$ignore_cache); |
my $fh; |
my $fh; |
if (open($fh,"<".$perlvar{'lonTabDir'}.'/domain.tab')) { |
if (open($fh,"<".$perlvar{'lonTabDir'}.'/domain.tab')) { |
my @lines = <$fh>; |
my @lines = <$fh>; |
Line 12821 sub fetch_dns_checksums {
|
Line 11834 sub fetch_dns_checksums {
|
my ($id,$domain,$role,$name,$protocol,$intdom)=split(/:/,$configline); |
my ($id,$domain,$role,$name,$protocol,$intdom)=split(/:/,$configline); |
$name=~s/\s//g; |
$name=~s/\s//g; |
if ($id && $domain && $role && $name) { |
if ($id && $domain && $role && $name) { |
if ((exists($hostname{$id})) && ($hostname{$id} ne '')) { |
|
my $curr = $hostname{$id}; |
|
my $skip; |
|
if (ref($name_to_host{$curr}) eq 'ARRAY') { |
|
if (($curr eq $name) && (@{$name_to_host{$curr}} == 1)) { |
|
$skip = 1; |
|
} else { |
|
@{$name_to_host{$curr}} = grep { $_ ne $id } @{$name_to_host{$curr}}; |
|
} |
|
} |
|
unless ($skip) { |
|
push(@{$name_to_host{$name}},$id); |
|
} |
|
} else { |
|
push(@{$name_to_host{$name}},$id); |
|
} |
|
$hostname{$id}=$name; |
$hostname{$id}=$name; |
|
push(@{$name_to_host{$name}}, $id); |
$hostdom{$id}=$domain; |
$hostdom{$id}=$domain; |
if ($role eq 'library') { $libserv{$id}=$name; } |
if ($role eq 'library') { $libserv{$id}=$name; } |
if (defined($protocol)) { |
if (defined($protocol)) { |
Line 12868 sub fetch_dns_checksums {
|
Line 11866 sub fetch_dns_checksums {
|
} |
} |
|
|
sub load_hosts_tab { |
sub load_hosts_tab { |
my ($ignore_cache,$nocache) = @_; |
my ($ignore_cache) = @_; |
&get_dns('/adm/dns/hosts',\&parse_hosts_tab,$ignore_cache,$nocache); |
&get_dns('/adm/dns/hosts',\&parse_hosts_tab,$ignore_cache); |
open(my $config,"<$perlvar{'lonTabDir'}/hosts.tab"); |
open(my $config,"<$perlvar{'lonTabDir'}/hosts.tab"); |
my @config = <$config>; |
my @config = <$config>; |
&parse_hosts_tab(\@config); |
&parse_hosts_tab(\@config); |
Line 12891 sub fetch_dns_checksums {
|
Line 11889 sub fetch_dns_checksums {
|
} |
} |
|
|
sub all_names { |
sub all_names { |
my ($ignore_cache,$nocache) = @_; |
&load_hosts_tab() if (!$loaded); |
&load_hosts_tab($ignore_cache,$nocache) if (!$loaded); |
|
|
|
return %name_to_host; |
return %name_to_host; |
} |
} |
Line 13014 sub fetch_dns_checksums {
|
Line 12011 sub fetch_dns_checksums {
|
} |
} |
|
|
sub get_iphost { |
sub get_iphost { |
my ($ignore_cache,$nocache) = @_; |
my ($ignore_cache) = @_; |
|
|
if (!$ignore_cache) { |
if (!$ignore_cache) { |
if (%iphost) { |
if (%iphost) { |
Line 13038 sub fetch_dns_checksums {
|
Line 12035 sub fetch_dns_checksums {
|
%old_name_to_ip = %{$ip_info->[1]}; |
%old_name_to_ip = %{$ip_info->[1]}; |
} |
} |
|
|
my %name_to_host = &all_names($ignore_cache,$nocache); |
my %name_to_host = &all_names(); |
foreach my $name (keys(%name_to_host)) { |
foreach my $name (keys(%name_to_host)) { |
my $ip; |
my $ip; |
if (!exists($name_to_ip{$name})) { |
if (!exists($name_to_ip{$name})) { |
Line 13063 sub fetch_dns_checksums {
|
Line 12060 sub fetch_dns_checksums {
|
} |
} |
push(@{$iphost{$ip}},@{$name_to_host{$name}}); |
push(@{$iphost{$ip}},@{$name_to_host{$name}}); |
} |
} |
unless ($nocache) { |
&do_cache_new('iphost','iphost', |
&do_cache_new('iphost','iphost', |
[\%iphost,\%name_to_ip,\%lonid_to_ip], |
[\%iphost,\%name_to_ip,\%lonid_to_ip], |
48*60*60); |
48*60*60); |
|
} |
|
|
|
return %iphost; |
return %iphost; |
} |
} |
Line 13129 sub fetch_dns_checksums {
|
Line 12124 sub fetch_dns_checksums {
|
} |
} |
|
|
sub all_loncaparevs { |
sub all_loncaparevs { |
return qw(1.1 1.2 1.3 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10 2.11); |
return qw(1.1 1.2 1.3 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 2.9 2.10); |
} |
} |
|
|
# ------------------------------------------------------- Read loncaparev table |
# ---------------------------------------------------------- Read loncaparev table |
{ |
{ |
sub load_loncaparevs { |
sub load_loncaparevs { |
if (-e "$perlvar{'lonTabDir'}/loncaparevs.tab") { |
if (-e "$perlvar{'lonTabDir'}/loncaparevs.tab") { |
if (open(my $config,"<$perlvar{'lonTabDir'}/loncaparevs.tab")) { |
if (open(my $config,"<$perlvar{'lonTabDir'}/loncaparevs.tab")) { |
while (my $configline=<$config>) { |
while (my $configline=<$config>) { |
Line 13148 sub all_loncaparevs {
|
Line 12143 sub all_loncaparevs {
|
} |
} |
} |
} |
|
|
# ----------------------------------------------------- Read serverhostID table |
# ---------------------------------------------------------- Read serverhostID table |
{ |
{ |
sub load_serverhomeIDs { |
sub load_serverhomeIDs { |
if (-e "$perlvar{'lonTabDir'}/serverhomeIDs.tab") { |
if (-e "$perlvar{'lonTabDir'}/serverhomeIDs.tab") { |
Line 13240 BEGIN {
|
Line 12235 BEGIN {
|
close($config); |
close($config); |
} |
} |
|
|
# --------------------------------------------------------- Read loncaparev table |
# ---------------------------------------------------------- Read loncaparev table |
|
|
&load_loncaparevs(); |
&load_loncaparevs(); |
|
|
# ------------------------------------------------------- Read serverhostID table |
# ---------------------------------------------------------- Read serverhostID table |
|
|
&load_serverhomeIDs(); |
&load_serverhomeIDs(); |
|
|
Line 13307 $readit=1;
|
Line 12302 $readit=1;
|
if ($test != 0) { $_64bit=1; } else { $_64bit=0; } |
if ($test != 0) { $_64bit=1; } else { $_64bit=0; } |
&logthis(" Detected 64bit platform ($_64bit)"); |
&logthis(" Detected 64bit platform ($_64bit)"); |
} |
} |
|
|
|
{ |
|
eval { |
|
($apache) = |
|
(Apache2::ServerUtil::get_server_version() =~ m{Apache/(\d+\.\d+)}); |
|
}; |
|
if ($@) { |
|
$apache = 1.3; |
|
} |
|
} |
|
|
} |
} |
} |
} |
|
|
Line 13448 were new keys. I.E. 1:foo will become 1:
|
Line 12454 were new keys. I.E. 1:foo will become 1:
|
Calling convention: |
Calling convention: |
|
|
my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$uname); |
my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$uname); |
&Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$uname,$laststore); |
&Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$uname); |
|
|
For more detailed information, see lonnet specific documentation. |
For more detailed information, see lonnet specific documentation. |
|
|
Line 13584 escaped strings of the action recorded i
|
Line 12590 escaped strings of the action recorded i
|
|
|
=item * |
=item * |
|
|
allowed($priv,$uri,$symb,$role,$clientip,$noblockcheck) : check for a user privilege; |
allowed($priv,$uri,$symb,$role) : check for a user privilege; returns codes for allowed actions |
returns codes for allowed actions. |
|
|
|
The first argument is required, all others are optional. |
|
|
|
$priv is the privilege being checked. |
|
$uri contains additional information about what is being checked for access (e.g., |
|
URL, course ID etc.). |
|
$symb is the unique resource instance identifier in a course; if needed, |
|
but not provided, it will be retrieved via a call to &symbread(). |
|
$role is the role for which a priv is being checked (only used if priv is evb). |
|
$clientip is the user's IP address (only used when checking for access to portfolio |
|
files). |
|
$noblockcheck, if true, skips calls to &has_comm_blocking() for the bre priv. This |
|
prevents recursive calls to &allowed. |
|
|
|
F: full access |
F: full access |
U,I,K: authentication modes (cxx only) |
U,I,K: authentication modes (cxx only) |
'': forbidden |
'': forbidden |
1: user needs to choose course |
1: user needs to choose course |
2: browse allowed |
2: browse allowed |
A: passphrase authentication needed |
A: passphrase authentication needed |
B: access temporarily blocked because of a blocking event in a course. |
|
|
|
=item * |
=item * |
|
|
Line 13625 in which case the null string is returne
|
Line 12615 in which case the null string is returne
|
|
|
=item * |
=item * |
|
|
definerole($rolename,$sysrole,$domrole,$courole,$uname,$udom) : define role; |
definerole($rolename,$sysrole,$domrole,$courole) : define role; define a custom |
define a custom role rolename set privileges in format of lonTabs/roles.tab |
role rolename set privileges in format of lonTabs/roles.tab for system, domain, |
for system, domain, and course level. $uname and $udom are optional (current |
and course level |
user's username and domain will be used when either of $uname or $udom are absent. |
|
|
|
=item * |
=item * |
|
|
Line 13659 provided for types, will default to retu
|
Line 12648 provided for types, will default to retu
|
=item * |
=item * |
|
|
in_course($udom,$uname,$cdom,$cnum,$type,$hideprivileged) : determine if |
in_course($udom,$uname,$cdom,$cnum,$type,$hideprivileged) : determine if |
user: $uname:$udom has a role in the course: $cdom_$cnum. |
user: $uname:$udom has a role in the course: $cdom_$cnum. |
|
|
Additional optional arguments are: $type (if role checking is to be restricted |
Additional optional arguments are: $type (if role checking is to be restricted |
to certain user status types -- previous (expired roles), active (currently |
to certain user status types -- previous (expired roles), active (currently |
available roles) or future (roles available in the future), and |
available roles) or future (roles available in the future), and |
$hideprivileged -- if true will not report course roles for users who |
$hideprivileged -- if true will not report course roles for users who |
Line 13832 Inputs:
|
Line 12821 Inputs:
|
|
|
=item $credits, number of credits student will earn from this class |
=item $credits, number of credits student will earn from this class |
|
|
=item $instsec, institutional course section code for student |
|
|
|
=back |
=back |
|
|
|
|
Line 13900 values that are the resource value. I b
|
Line 12887 values that are the resource value. I b
|
versions are also returned. |
versions are also returned. |
|
|
get_numsuppfiles($cnum,$cdom) : retrieve number of files in a course's |
get_numsuppfiles($cnum,$cdom) : retrieve number of files in a course's |
supplemental content area. This routine caches the number of files for |
supplemental content area. This routine caches the number of files for |
10 minutes. |
10 minutes. |
|
|
=back |
=back |
Line 14003 will be stored for query
|
Line 12990 will be stored for query
|
|
|
=item * |
=item * |
|
|
symbread($filename,$donotrecurse,$ignorecachednull,$checkforblock,$possibles) : |
symbread($filename) : return symbolic list entry (filename argument optional); |
return symbolic list entry (all arguments optional). |
|
|
|
Args: filename is the filename (including path) for the file for which a symb |
|
is required; donotrecurse, if true will prevent calls to allowed() being made |
|
to check access status if more than one resource was found in the bighash |
|
(see rev. 1.249) to avoid an infinite loop if an ambiguous resource is part of |
|
a randompick); ignorecachednull, if true will prevent a symb of '' being |
|
returned if $env{$cache_str} is defined as ''; checkforblock if true will |
|
cause possible symbs to be checked to determine if they are subject to content |
|
blocking, if so they will not be included as possible symbs; possibles is a |
|
ref to a hash, which, as a side effect, will be populated with all possible |
|
symbs (content blocking not tested). |
|
|
|
returns the data handle |
returns the data handle |
|
|
=item * |
=item * |
Line 14026 and is a possible symb for the URL in $t
|
Line 13000 and is a possible symb for the URL in $t
|
resource that the user accessed using /enc/ returns a 1 on success, 0 |
resource that the user accessed using /enc/ returns a 1 on success, 0 |
on failure, user must be in a course, as it assumes the existence of |
on failure, user must be in a course, as it assumes the existence of |
the course initial hash, and uses $env('request.course.id'}. The third |
the course initial hash, and uses $env('request.course.id'}. The third |
arg is an optional reference to a scalar. If this arg is passed in the |
arg is an optional reference to a scalar. If this arg is passed in the |
call to symbverify, it will be set to 1 if the symb has been set to be |
call to symbverify, it will be set to 1 if the symb has been set to be |
encrypted; otherwise it will be null. |
encrypted; otherwise it will be null. |
|
|
=item * |
=item * |
|
|
Line 14081 expirespread($uname,$udom,$stype,$usymb)
|
Line 13055 expirespread($uname,$udom,$stype,$usymb)
|
devalidate($symb) : devalidate temporary spreadsheet calculations, |
devalidate($symb) : devalidate temporary spreadsheet calculations, |
forcing spreadsheet to reevaluate the resource scores next time. |
forcing spreadsheet to reevaluate the resource scores next time. |
|
|
=item * |
=item * |
|
|
can_edit_resource($file,$cnum,$cdom,$resurl,$symb,$group) : determine if current user can edit a particular resource, |
can_edit_resource($file,$cnum,$cdom,$resurl,$symb,$group) : determine if current user can edit a particular resource, |
when viewing in course context. |
when viewing in course context. |
|
|
input: six args -- filename (decluttered), course number, course domain, |
input: six args -- filename (decluttered), course number, course domain, |
url, symb (if registered) and group (if this is a |
url, symb (if registered) and group (if this is a |
group item -- e.g., bulletin board, group page etc.). |
group item -- e.g., bulletin board, group page etc.). |
|
|
output: array of five scalars -- |
output: array of five scalars -- |
Line 14095 when viewing in course context.
|
Line 13069 when viewing in course context.
|
$home -- homeserver of resource (i.e., for author if published, |
$home -- homeserver of resource (i.e., for author if published, |
or course if uploaded.). |
or course if uploaded.). |
$switchserver -- 1 if server switch will be needed. |
$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 |
$forceview -- 1 if icon/link should be to go to view mode |
|
|
=item * |
=item * |
|
|
is_course_upload($file,$cnum,$cdom) |
is_course_upload($file,$cnum,$cdom) |
|
|
Used in course context to determine if current file was uploaded to |
Used in course context to determine if current file was uploaded to |
the course (i.e., would be found in /userfiles/docs on the course's |
the course (i.e., would be found in /userfiles/docs on the course's |
homeserver. |
homeserver. |
|
|
input: 3 args -- filename (decluttered), course number and course domain. |
input: 3 args -- filename (decluttered), course number and course domain. |
Line 14117 homeserver.
|
Line 13091 homeserver.
|
|
|
=item * |
=item * |
|
|
store($storehash,$symb,$namespace,$udom,$uname,$laststore) : stores hash |
store($storehash,$symb,$namespace,$udom,$uname) : stores hash permanently |
permanently for this url; hashref needs to be given and should be a \%hashname; |
for this url; hashref needs to be given and should be a \%hashname; the |
the remaining args aren't required and if they aren't passed or are '' they will |
remaining args aren't required and if they aren't passed or are '' they will |
be derived from the env (with the exception of $laststore, which is an |
be derived from the env |
optional arg used when a user's submission is stored in grading). |
|
$laststore is $version=$timestamp, where $version is the most recent version |
|
number retrieved for the corresponding $symb in the $namespace db file, and |
|
$timestamp is the timestamp for that transaction (UNIX time). |
|
$laststore is currently only passed when cstore() is called by |
|
structuretags::finalize_storage(). |
|
|
|
=item * |
=item * |
|
|
cstore($storehash,$symb,$namespace,$udom,$uname,$laststore) : same as store |
cstore($storehash,$symb,$namespace,$udom,$uname) : same as store but |
but uses critical subroutine |
uses critical subroutine |
|
|
=item * |
=item * |
|
|
Line 14154 $range should be either an integer '100'
|
Line 13122 $range should be either an integer '100'
|
|
|
=item * |
=item * |
|
|
putstore($namespace,$symb,$version,$storehash,$udomain,$uname,$tolog) : |
putstore($namespace,$symb,$version,$storehash,$udomain,$uname) : |
replaces a &store() version of data with a replacement set of data |
replaces a &store() version of data with a replacement set of data |
for a particular resource in a namespace passed in the $storehash hash |
for a particular resource in a namespace passed in the $storehash hash |
reference. If $tolog is true, the transaction is logged in the courselog |
reference |
with an action=PUTSTORE. |
|
|
|
=item * |
=item * |
|
|
Line 14268 server ($udom and $uhome are optional)
|
Line 13235 server ($udom and $uhome are optional)
|
|
|
=item * |
=item * |
|
|
get_domain_defaults($target_domain,$ignore_cache) : returns hash with defaults |
get_domain_defaults($target_domain) : returns hash with defaults for |
for: authentication, language, quotas, timezone, date locale, and portal URL in |
authentication and language in the domain. Keys are: auth_def, auth_arg_def, |
the target domain. |
lang_def; corresponsing values are authentication type (internal, krb4, krb5, |
|
or localauth), initial password or a kerberos realm, language (e.g., en-us). |
May also include additional key => value pairs for the following groups: |
Values are retrieved from cache (if current), or from domain's configuration.db |
|
(if available), or lastly from values in lonTabs/dns_domain,tab, |
=over |
or lonTabs/domain.tab. |
|
|
=item |
|
disk quotas (MB allocated by default to portfolios and authoring spaces). |
|
|
|
=over |
|
|
|
=item defaultquota, authorquota |
|
|
|
=back |
|
|
|
=item |
|
tools (availability of aboutme page, blog, webDAV access for authoring spaces, |
|
portfolio for users). |
|
|
|
=over |
|
|
|
=item |
|
aboutme, blog, webdav, portfolio |
|
|
|
=back |
|
|
|
=item |
|
requestcourses: ability to request courses, and how requests are processed. |
|
|
|
=over |
|
|
|
=item |
|
official, unofficial, community, textbook |
|
|
|
=back |
|
|
|
=item |
|
inststatus: types of institutional affiliation, and order in which they are displayed. |
|
|
|
=over |
|
|
|
=item |
|
inststatustypes, inststatusorder, inststatusguest |
|
|
|
=back |
|
|
|
=item |
|
coursedefaults: can PDF forms can be created, default credits for courses, default quotas (MB) |
|
for course's uploaded content. |
|
|
|
=over |
|
|
|
=item |
|
canuse_pdfforms, officialcredits, unofficialcredits, textbookcredits, officialquota, unofficialquota, |
|
communityquota, textbookquota |
|
|
|
=back |
|
|
|
=item |
|
usersessions: set options for hosting of your users in other domains, and hosting of users from other domains |
|
on your servers. |
|
|
|
=over |
|
|
|
=item |
|
remotesessions, hostedsessions |
|
|
|
=back |
|
|
|
=back |
|
|
|
In cases where a domain coordinator has never used the "Set Domain Configuration" |
|
utility to create a configuration.db file on a domain's primary library server |
|
only the following domain defaults: auth_def, auth_arg_def, lang_def |
|
-- corresponding values are authentication type (internal, krb4, krb5, |
|
or localauth), initial password or a kerberos realm, language (e.g., en-us) -- |
|
will be available. Values are retrieved from cache (if current), unless the |
|
optional $ignore_cache arg is true, or from domain's configuration.db (if available), |
|
or lastly from values in lonTabs/dns_domain,tab, or lonTabs/domain.tab. |
|
|
|
Typical usage: |
|
|
|
%domdefaults = &get_domain_defaults($target_domain); |
%domdefaults = &get_auth_defaults($target_domain); |
|
|
=back |
=back |
|
|
Line 14577 filelocation except for hrefs
|
Line 13468 filelocation except for hrefs
|
|
|
=item * |
=item * |
|
|
declutter() : declutters URLs -- remove beginning slashes, 'res' etc. |
declutter() : declutters URLs (remove docroot, beginning slashes, 'res' etc) |
also removes beginning /home/httpd/html unless /priv/ follows it. |
|
|
|
=back |
=back |
|
|
Line 14773 Returns:
|
Line 13663 Returns:
|
|
|
get_timebased_id(): |
get_timebased_id(): |
|
|
Attempts to get a unique timestamp-based suffix for use with items added to a |
Attempts to get a unique timestamp-based suffix for use with items added to a |
course via the Course Editor (e.g., folders, composite pages, |
course via the Course Editor (e.g., folders, composite pages, |
group bulletin boards). |
group bulletin boards). |
|
|
Args: (first three required; six others optional) |
Args: (first three required; six others optional) |
Line 14785 Args: (first three required; six others
|
Line 13675 Args: (first three required; six others
|
2. keyid (alphanumeric): name of temporary locking key in hash, |
2. keyid (alphanumeric): name of temporary locking key in hash, |
e.g., num, boardids |
e.g., num, boardids |
|
|
3. namespace: name of gdbm file used to store suffixes already assigned; |
3. namespace: name of gdbm file used to store suffixes already assigned; |
file will be named nohist_namespace.db |
file will be named nohist_namespace.db |
|
|
4. cdom: domain of course; default is current course domain from %env |
4. cdom: domain of course; default is current course domain from %env |
|
|
5. cnum: course number; default is current course number from %env |
5. cnum: course number; default is current course number from %env |
|
|
6. idtype: set to concat if an additional digit is to be appended to the |
6. idtype: set to concat if an additional digit is to be appended to the |
unix timestamp to form the suffix, if the plain timestamp is already |
unix timestamp to form the suffix, if the plain timestamp is already |
in use. Default is to not do this, but simply increment the unix |
in use. Default is to not do this, but simply increment the unix |
timestamp by 1 until a unique key is obtained. |
timestamp by 1 until a unique key is obtained. |
|
|
7. who: holder of locking key; defaults to user:domain for user. |
7. who: holder of locking key; defaults to user:domain for user. |
|
|
8. locktries: number of attempts to obtain a lock (sleep of 1s before |
8. locktries: number of attempts to obtain a lock (sleep of 1s before |
retrying); default is 3. |
retrying); default is 3. |
|
|
9. maxtries: number of attempts to obtain a unique suffix; default is 20. |
9. maxtries: number of attempts to obtain a unique suffix; default is 20. |
|
|
Returns: |
Returns: |
|
|