version 1.683.2.18, 2006/02/10 22:37:15
|
version 1.734, 2006/05/01 16:00:44
|
Line 45 qw(%perlvar %hostname %badServerCache %i
|
Line 45 qw(%perlvar %hostname %badServerCache %i
|
|
|
use IO::Socket; |
use IO::Socket; |
use GDBM_File; |
use GDBM_File; |
use Apache::Constants qw(:common :http); |
|
use HTML::LCParser; |
use HTML::LCParser; |
use HTML::Parser; |
use HTML::Parser; |
use Fcntl qw(:flock); |
use Fcntl qw(:flock); |
Line 86 delayed.
|
Line 85 delayed.
|
|
|
|
|
# --------------------------------------------------------------------- Logging |
# --------------------------------------------------------------------- Logging |
|
{ |
|
my $logid; |
|
sub instructor_log { |
|
my ($hash_name,$storehash,$delflag,$uname,$udom)=@_; |
|
$logid++; |
|
my $id=time().'00000'.$$.'00000'.$logid; |
|
return &Apache::lonnet::put('nohist_'.$hash_name, |
|
{ $id => { |
|
'exe_uname' => $env{'user.name'}, |
|
'exe_udom' => $env{'user.domain'}, |
|
'exe_time' => time(), |
|
'exe_ip' => $ENV{'REMOTE_ADDR'}, |
|
'delflag' => $delflag, |
|
'logentry' => $storehash, |
|
'uname' => $uname, |
|
'udom' => $udom, |
|
} |
|
}, |
|
$env{'course.'.$env{'request.course.id'}.'.domain'}, |
|
$env{'course.'.$env{'request.course.id'}.'.num'} |
|
); |
|
} |
|
} |
|
|
sub logtouch { |
sub logtouch { |
my $execdir=$perlvar{'lonDaemons'}; |
my $execdir=$perlvar{'lonDaemons'}; |
Line 124 sub logperm {
|
Line 146 sub logperm {
|
# -------------------------------------------------- Non-critical communication |
# -------------------------------------------------- Non-critical communication |
sub subreply { |
sub subreply { |
my ($cmd,$server)=@_; |
my ($cmd,$server)=@_; |
my $peerfile="$perlvar{'lonSockDir'}/$server"; |
my $peerfile="$perlvar{'lonSockDir'}/".$hostname{$server}; |
# |
# |
# With loncnew process trimming, there's a timing hole between lonc server |
# With loncnew process trimming, there's a timing hole between lonc server |
# process exit and the master server picking up the listen on the AF_UNIX |
# process exit and the master server picking up the listen on the AF_UNIX |
Line 152 sub subreply {
|
Line 174 sub subreply {
|
} |
} |
my $answer; |
my $answer; |
if ($client) { |
if ($client) { |
print $client "$cmd\n"; |
print $client "sethost:$server:$cmd\n"; |
$answer=<$client>; |
$answer=<$client>; |
if (!$answer) { $answer="con_lost"; } |
if (!$answer) { $answer="con_lost"; } |
chomp($answer); |
chomp($answer); |
Line 260 sub critical {
|
Line 282 sub critical {
|
|
|
sub transfer_profile_to_env { |
sub transfer_profile_to_env { |
my ($lonidsdir,$handle)=@_; |
my ($lonidsdir,$handle)=@_; |
|
if (!defined($lonidsdir)) { |
|
$lonidsdir = $perlvar{'lonIDsDir'}; |
|
} |
|
if (!defined($handle)) { |
|
($handle) = ($env{'user.environment'} =~m|/([^/]+)\.id$| ); |
|
} |
|
|
my @profile; |
my @profile; |
{ |
{ |
open(my $idf,"$lonidsdir/$handle.id"); |
open(my $idf,"$lonidsdir/$handle.id"); |
Line 272 sub transfer_profile_to_env {
|
Line 301 sub transfer_profile_to_env {
|
for ($envi=0;$envi<=$#profile;$envi++) { |
for ($envi=0;$envi<=$#profile;$envi++) { |
chomp($profile[$envi]); |
chomp($profile[$envi]); |
my ($envname,$envvalue)=split(/=/,$profile[$envi],2); |
my ($envname,$envvalue)=split(/=/,$profile[$envi],2); |
|
$envname=&unescape($envname); |
|
$envvalue=&unescape($envvalue); |
$env{$envname} = $envvalue; |
$env{$envname} = $envvalue; |
if (my ($key,$time) = ($envname =~ /^(cgi\.(\d+)_\d+\.)/)) { |
if (my ($key,$time) = ($envname =~ /^(cgi\.(\d+)_\d+\.)/)) { |
if ($time < time-300) { |
if ($time < time-300) { |
Line 289 sub transfer_profile_to_env {
|
Line 320 sub transfer_profile_to_env {
|
|
|
sub appenv { |
sub appenv { |
my %newenv=@_; |
my %newenv=@_; |
foreach (keys %newenv) { |
foreach my $key (keys(%newenv)) { |
if (($newenv{$_}=~/^user\.role/) || ($newenv{$_}=~/^user\.priv/)) { |
if (($newenv{$key}=~/^user\.role/) || ($newenv{$key}=~/^user\.priv/)) { |
&logthis("<font color=\"blue\">WARNING: ". |
&logthis("<font color=\"blue\">WARNING: ". |
"Attempt to modify environment ".$_." to ".$newenv{$_} |
"Attempt to modify environment ".$key." to ".$newenv{$key} |
.'</font>'); |
.'</font>'); |
delete($newenv{$_}); |
delete($newenv{$key}); |
} else { |
} else { |
$env{$_}=$newenv{$_}; |
$env{$key}=$newenv{$key}; |
} |
} |
} |
} |
|
|
Line 324 sub appenv {
|
Line 355 sub appenv {
|
chomp($oldenv[$i]); |
chomp($oldenv[$i]); |
if ($oldenv[$i] ne '') { |
if ($oldenv[$i] ne '') { |
my ($name,$value)=split(/=/,$oldenv[$i],2); |
my ($name,$value)=split(/=/,$oldenv[$i],2); |
|
$name=&unescape($name); |
|
$value=&unescape($value); |
unless (defined($newenv{$name})) { |
unless (defined($newenv{$name})) { |
$newenv{$name}=$value; |
$newenv{$name}=$value; |
} |
} |
Line 336 sub appenv {
|
Line 369 sub appenv {
|
} |
} |
my $newname; |
my $newname; |
foreach $newname (keys %newenv) { |
foreach $newname (keys %newenv) { |
print $fh "$newname=$newenv{$newname}\n"; |
print $fh &escape($newname).'='.&escape($newenv{$newname})."\n"; |
} |
} |
close($fh); |
close($fh); |
} |
} |
Line 348 sub appenv {
|
Line 381 sub appenv {
|
|
|
sub delenv { |
sub delenv { |
my $delthis=shift; |
my $delthis=shift; |
my %newenv=(); |
|
if (($delthis=~/user\.role/) || ($delthis=~/user\.priv/)) { |
if (($delthis=~/user\.role/) || ($delthis=~/user\.priv/)) { |
&logthis("<font color=\"blue\">WARNING: ". |
&logthis("<font color=\"blue\">WARNING: ". |
"Attempt to delete from environment ".$delthis); |
"Attempt to delete from environment ".$delthis); |
Line 380 sub delenv {
|
Line 412 sub delenv {
|
close($fh); |
close($fh); |
return 'error: '.$!; |
return 'error: '.$!; |
} |
} |
foreach (@oldenv) { |
foreach my $cur_key (@oldenv) { |
if ($_=~/^$delthis/) { |
my $unescaped_cur_key = &unescape($cur_key); |
my ($key,undef) = split('=',$_,2); |
if ($unescaped_cur_key=~/^$delthis/) { |
|
my ($key) = split('=',$cur_key,2); |
|
$key = &unescape($key); |
delete($env{$key}); |
delete($env{$key}); |
} else { |
} else { |
print $fh $_; |
print $fh $cur_key; |
} |
} |
} |
} |
close($fh); |
close($fh); |
Line 840 sub getsection {
|
Line 874 sub getsection {
|
} |
} |
|
|
sub save_cache { |
sub save_cache { |
my ($r)=@_; |
|
if (! $r->is_initial_req()) { return DECLINED; } |
|
&purge_remembered(); |
&purge_remembered(); |
|
#&Apache::loncommon::validate_page(); |
undef(%env); |
undef(%env); |
return OK; |
|
} |
} |
|
|
my $to_remember=-1; |
my $to_remember=-1; |
Line 996 sub retrievestudentphoto {
|
Line 1028 sub retrievestudentphoto {
|
# -------------------------------------------------------------------- New chat |
# -------------------------------------------------------------------- New chat |
|
|
sub chatsend { |
sub chatsend { |
my ($newentry,$anon)=@_; |
my ($newentry,$anon,$group)=@_; |
my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'}; |
my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'}; |
my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'}; |
my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'}; |
my $chome=$env{'course.'.$env{'request.course.id'}.'.home'}; |
my $chome=$env{'course.'.$env{'request.course.id'}.'.home'}; |
&reply('chatsend:'.$cdom.':'.$cnum.':'. |
&reply('chatsend:'.$cdom.':'.$cnum.':'. |
&escape($env{'user.domain'}.':'.$env{'user.name'}.':'.$anon.':'. |
&escape($env{'user.domain'}.':'.$env{'user.name'}.':'.$anon.':'. |
&escape($newentry)),$chome); |
&escape($newentry)).':'.$group,$chome); |
} |
} |
|
|
# ------------------------------------------ Find current version of a resource |
# ------------------------------------------ Find current version of a resource |
Line 1145 sub ssi {
|
Line 1177 sub ssi {
|
my $ua=new LWP::UserAgent; |
my $ua=new LWP::UserAgent; |
|
|
my $request; |
my $request; |
|
|
|
$form{'no_update_last_known'}=1; |
|
|
if (%form) { |
if (%form) { |
$request=new HTTP::Request('POST',"http://".$ENV{'HTTP_HOST'}.$fn); |
$request=new HTTP::Request('POST',"http://".$ENV{'HTTP_HOST'}.$fn); |
$request->content(join('&',map { &escape($_).'='.&escape($form{$_}) } keys %form)); |
$request->content(join('&',map { &escape($_).'='.&escape($form{$_}) } keys %form)); |
Line 1317 sub clean_filename {
|
Line 1351 sub clean_filename {
|
} |
} |
|
|
# --------------- Take an uploaded file and put it into the userfiles directory |
# --------------- Take an uploaded file and put it into the userfiles directory |
# input: name of form element, coursedoc=1 means this is for the course |
# input: $formname - the contents of the file are in $env{"form.$formname"} |
# output: url of file in userspace |
# the desired filenam is in $env{"form.$formname.filename"} |
|
# $coursedoc - if true up to the current course |
|
# if false |
|
# $subdir - directory in userfile to store the file into |
|
# $parser, $allfiles, $codebase - unknown |
|
# |
|
# output: url of file in userspace, or error: <message> |
|
# or /adm/notfound.html if failure to upload occurse |
|
|
|
|
sub userfileupload { |
sub userfileupload { |
my ($formname,$coursedoc,$subdir,$parser,$allfiles,$codebase)=@_; |
my ($formname,$coursedoc,$subdir,$parser,$allfiles,$codebase,$destuname,$destudom)=@_; |
if (!defined($subdir)) { $subdir='unknown'; } |
if (!defined($subdir)) { $subdir='unknown'; } |
my $fname=$env{'form.'.$formname.'.filename'}; |
my $fname=$env{'form.'.$formname.'.filename'}; |
$fname=&clean_filename($fname); |
$fname=&clean_filename($fname); |
Line 1345 sub userfileupload {
|
Line 1386 sub userfileupload {
|
close($fh); |
close($fh); |
return $fullpath.'/'.$fname; |
return $fullpath.'/'.$fname; |
} |
} |
|
|
# Create the directory if not present |
# Create the directory if not present |
$fname="$subdir/$fname"; |
$fname="$subdir/$fname"; |
if ($coursedoc) { |
if ($coursedoc) { |
Line 1360 sub userfileupload {
|
Line 1402 sub userfileupload {
|
$fname,$formname,$parser, |
$fname,$formname,$parser, |
$allfiles,$codebase); |
$allfiles,$codebase); |
} |
} |
|
} elsif (defined($destuname)) { |
|
my $docuname=$destuname; |
|
my $docudom=$destudom; |
|
return &finishuserfileupload($docuname,$docudom,$formname, |
|
$fname,$parser,$allfiles,$codebase); |
|
|
} else { |
} else { |
my $docuname=$env{'user.name'}; |
my $docuname=$env{'user.name'}; |
my $docudom=$env{'user.domain'}; |
my $docudom=$env{'user.domain'}; |
|
if (exists($env{'form.group'})) { |
|
$docuname=$env{'course.'.$env{'request.course.id'}.'.num'}; |
|
$docudom=$env{'course.'.$env{'request.course.id'}.'.domain'}; |
|
} |
return &finishuserfileupload($docuname,$docudom,$formname, |
return &finishuserfileupload($docuname,$docudom,$formname, |
$fname,$parser,$allfiles,$codebase); |
$fname,$parser,$allfiles,$codebase); |
} |
} |
Line 1388 sub finishuserfileupload {
|
Line 1440 sub finishuserfileupload {
|
} |
} |
# Save the file |
# Save the file |
{ |
{ |
open(FH,'>'.$filepath.'/'.$file); |
if (!open(FH,'>'.$filepath.'/'.$file)) { |
print FH $env{'form.'.$formname}; |
&logthis('Failed to create '.$filepath.'/'.$file); |
|
print STDERR ('Failed to create '.$filepath.'/'.$file."\n"); |
|
return '/adm/notfound.html'; |
|
} |
|
if (!print FH ($env{'form.'.$formname})) { |
|
&logthis('Failed to write to '.$filepath.'/'.$file); |
|
print STDERR ('Failed to write to '.$filepath.'/'.$file."\n"); |
|
return '/adm/notfound.html'; |
|
} |
close(FH); |
close(FH); |
} |
} |
if ($parser eq 'parse') { |
if ($parser eq 'parse') { |
Line 2540 sub restore {
|
Line 2600 sub restore {
|
# ---------------------------------------------------------- Course Description |
# ---------------------------------------------------------- Course Description |
|
|
sub coursedescription { |
sub coursedescription { |
my $courseid=shift; |
my ($courseid,$args)=@_; |
$courseid=~s/^\///; |
$courseid=~s/^\///; |
$courseid=~s/\_/\//g; |
$courseid=~s/\_/\//g; |
my ($cdomain,$cnum)=split(/\//,$courseid); |
my ($cdomain,$cnum)=split(/\//,$courseid); |
Line 2550 sub coursedescription {
|
Line 2610 sub coursedescription {
|
# trying and trying and trying to get the course description. |
# trying and trying and trying to get the course description. |
my %envhash=(); |
my %envhash=(); |
my %returnhash=(); |
my %returnhash=(); |
$envhash{'course.'.$normalid.'.last_cache'}=time; |
|
|
my $expiretime=600; |
|
if ($env{'request.course.id'} eq $normalid) { |
|
$expiretime=120; |
|
} |
|
|
|
my $prefix='course.'.$cdomain.'_'.$cnum.'.'; |
|
if (!$args->{'freshen_cache'} |
|
&& ((time-$env{$prefix.'last_cache'}) < $expiretime) ) { |
|
foreach my $key (keys(%env)) { |
|
next if ($key !~ /^\Q$prefix\E(.*)/); |
|
my ($setting) = $1; |
|
$returnhash{$setting} = $env{$key}; |
|
} |
|
return %returnhash; |
|
} |
|
|
|
# get the data agin |
|
if (!$args->{'one_time'}) { |
|
$envhash{'course.'.$normalid.'.last_cache'}=time; |
|
} |
if ($chome ne 'no_host') { |
if ($chome ne 'no_host') { |
%returnhash=&dump('environment',$cdomain,$cnum); |
%returnhash=&dump('environment',$cdomain,$cnum); |
if (!exists($returnhash{'con_lost'})) { |
if (!exists($returnhash{'con_lost'})) { |
Line 2568 sub coursedescription {
|
Line 2648 sub coursedescription {
|
$envhash{'course.'.$normalid.'.num'}=$cnum; |
$envhash{'course.'.$normalid.'.num'}=$cnum; |
} |
} |
} |
} |
&appenv(%envhash); |
if (!$args->{'one_time'}) { |
|
&appenv(%envhash); |
|
} |
return %returnhash; |
return %returnhash; |
} |
} |
|
|
Line 2815 sub del {
|
Line 2897 sub del {
|
# -------------------------------------------------------------- dump interface |
# -------------------------------------------------------------- dump interface |
|
|
sub dump { |
sub dump { |
my ($namespace,$udomain,$uname,$regexp)=@_; |
my ($namespace,$udomain,$uname,$regexp,$range)=@_; |
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 2824 sub dump {
|
Line 2906 sub dump {
|
} else { |
} else { |
$regexp='.'; |
$regexp='.'; |
} |
} |
my $rep=reply("dump:$udomain:$uname:$namespace:$regexp",$uhome); |
my $rep=reply("dump:$udomain:$uname:$namespace:$regexp:$range",$uhome); |
my @pairs=split(/\&/,$rep); |
my @pairs=split(/\&/,$rep); |
my %returnhash=(); |
my %returnhash=(); |
foreach (@pairs) { |
foreach (@pairs) { |
my ($key,$value)=split(/=/,$_); |
my ($key,$value)=split(/=/,$_,2); |
$returnhash{unescape($key)}=&thaw_unescape($value); |
$returnhash{unescape($key)}=&thaw_unescape($value); |
} |
} |
return %returnhash; |
return %returnhash; |
} |
} |
|
|
|
# --------------------------------------------------------- dumpstore interface |
|
|
|
sub dumpstore { |
|
my ($namespace,$udomain,$uname,$regexp,$range)=@_; |
|
return &dump($namespace,$udomain,$uname,$regexp,$range); |
|
} |
|
|
# -------------------------------------------------------------- keys interface |
# -------------------------------------------------------------- keys interface |
|
|
sub getkeys { |
sub getkeys { |
Line 2975 sub newput {
|
Line 3064 sub newput {
|
# --------------------------------------------------------- putstore interface |
# --------------------------------------------------------- putstore interface |
|
|
sub putstore { |
sub putstore { |
my ($namespace,$storehash,$udomain,$uname)=@_; |
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); |
my $items=''; |
my $items=''; |
my %allitems = (); |
foreach my $key (keys(%$storehash)) { |
foreach (keys %$storehash) { |
$items.= &escape($key).'='.&freeze_escape($storehash->{$key}).'&'; |
if ($_ =~ m/^([^\:]+):([^\:]+):([^\:]+)$/) { |
|
my $key = $1.':keys:'.$2; |
|
$allitems{$key} .= $3.':'; |
|
} |
|
$items.=$_.'='.&freeze_escape($$storehash{$_}).'&'; |
|
} |
|
foreach (keys %allitems) { |
|
$allitems{$_} =~ s/\:$//; |
|
$items.= $_.'='.$allitems{$_}.'&'; |
|
} |
} |
$items=~s/\&$//; |
$items=~s/\&$//; |
return &reply("put:$udomain:$uname:$namespace:$items",$uhome); |
my $esc_symb=&escape($symb); |
|
my $esc_v=&escape($version); |
|
my $reply = |
|
&reply("putstore:$udomain:$uname:$namespace:$esc_symb:$esc_v:$items", |
|
$uhome); |
|
if ($reply eq 'unknown_cmd') { |
|
# gfall back to way things use to be done |
|
return &old_putstore($namespace,$symb,$version,$storehash,$udomain, |
|
$uname); |
|
} |
|
return $reply; |
|
} |
|
|
|
sub old_putstore { |
|
my ($namespace,$symb,$version,$storehash,$udomain,$uname)=@_; |
|
if (!$udomain) { $udomain=$env{'user.domain'}; } |
|
if (!$uname) { $uname=$env{'user.name'}; } |
|
my $uhome=&homeserver($uname,$udomain); |
|
my %newstorehash; |
|
foreach (keys %$storehash) { |
|
my $key = $version.':'.&escape($symb).':'.$_; |
|
$newstorehash{$key} = $storehash->{$_}; |
|
} |
|
my $items=''; |
|
my %allitems = (); |
|
foreach (keys %newstorehash) { |
|
if ($_ =~ m/^([^\:]+):([^\:]+):([^\:]+)$/) { |
|
my $key = $1.':keys:'.$2; |
|
$allitems{$key} .= $3.':'; |
|
} |
|
$items.=$_.'='.&freeze_escape($newstorehash{$_}).'&'; |
|
} |
|
foreach (keys %allitems) { |
|
$allitems{$_} =~ s/\:$//; |
|
$items.= $_.'='.$allitems{$_}.'&'; |
|
} |
|
$items=~s/\&$//; |
|
return &reply("put:$udomain:$uname:$namespace:$items",$uhome); |
} |
} |
|
|
# ------------------------------------------------------ critical put interface |
# ------------------------------------------------------ critical put interface |
Line 3005 sub cput {
|
Line 3122 sub cput {
|
my $uhome=&homeserver($uname,$udomain); |
my $uhome=&homeserver($uname,$udomain); |
my $items=''; |
my $items=''; |
foreach (keys %$storehash) { |
foreach (keys %$storehash) { |
$items.=escape($_).'='.&freeze_escape($$storehash{$_}).'&'; |
$items.=&escape($_).'='.&freeze_escape($$storehash{$_}).'&'; |
} |
} |
$items=~s/\&$//; |
$items=~s/\&$//; |
return &critical("put:$udomain:$uname:$namespace:$items",$uhome); |
return &critical("put:$udomain:$uname:$namespace:$items",$uhome); |
Line 3116 sub allowed {
|
Line 3233 sub allowed {
|
} |
} |
|
|
# Free bre access to user's own portfolio contents |
# Free bre access to user's own portfolio contents |
my ($space,$domain,$name,$dir)=split('/',$uri); |
my ($space,$domain,$name,@dir)=split('/',$uri); |
if (($space=~/^(uploaded|editupload)$/) && ($env{'user.name'} eq $name) && |
if (($space=~/^(uploaded|editupload)$/) && ($env{'user.name'} eq $name) && |
($env{'user.domain'} eq $domain) && ('portfolio' eq $dir)) { |
($env{'user.domain'} eq $domain) && ('portfolio' eq $dir[0])) { |
return 'F'; |
return 'F'; |
} |
} |
|
|
|
# bre access to group if user has rgf priv for this group and course. |
|
if (($space=~/^(uploaded|editupload)$/) && ($dir[0] eq 'groups') |
|
&& ($dir[2] eq 'portfolio') && ($priv eq 'bre')) { |
|
if (exists($env{'request.course.id'})) { |
|
my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; |
|
my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; |
|
if (($domain eq $cdom) && ($name eq $cnum)) { |
|
my $courseprivid=$env{'request.course.id'}; |
|
$courseprivid=~s/\_/\//; |
|
if ($env{'user.priv.'.$env{'request.role'}.'./'.$courseprivid |
|
.'/'.$dir[1]} =~/rgf\&([^\:]*)/) { |
|
return $1; |
|
} |
|
} |
|
} |
|
} |
|
|
# Free bre to public access |
# Free bre to public access |
|
|
if ($priv eq 'bre') { |
if ($priv eq 'bre') { |
Line 3336 sub allowed {
|
Line 3470 sub allowed {
|
my ($cdom,$cnum,$csec)=split(/\//,$courseid); |
my ($cdom,$cnum,$csec)=split(/\//,$courseid); |
my $prefix='course.'.$cdom.'_'.$cnum.'.'; |
my $prefix='course.'.$cdom.'_'.$cnum.'.'; |
if ((time-$env{$prefix.'last_cache'})>$expiretime) { |
if ((time-$env{$prefix.'last_cache'})>$expiretime) { |
&coursedescription($courseid); |
&coursedescription($courseid,{'freshen_cache' => 1}); |
} |
} |
if (($env{$prefix.'res.'.$uri.'.lock.sections'}=~/\,\Q$csec\E\,/) |
if (($env{$prefix.'res.'.$uri.'.lock.sections'}=~/\,\Q$csec\E\,/) |
|| ($env{$prefix.'res.'.$uri.'.lock.sections'} eq 'all')) { |
|| ($env{$prefix.'res.'.$uri.'.lock.sections'} eq 'all')) { |
Line 3845 sub modify_group_roles {
|
Line 3979 sub modify_group_roles {
|
my $role = 'gr/'.&escape($userprivs); |
my $role = 'gr/'.&escape($userprivs); |
my ($uname,$udom) = split(/:/,$user); |
my ($uname,$udom) = split(/:/,$user); |
my $result = &assignrole($udom,$uname,$url,$role,$end,$start); |
my $result = &assignrole($udom,$uname,$url,$role,$end,$start); |
|
if ($result eq 'ok') { |
|
&devalidate_getgroups_cache($udom,$uname,$cdom,$cnum); |
|
} |
|
|
return $result; |
return $result; |
} |
} |
|
|
Line 3878 sub get_group_membership {
|
Line 4016 sub get_group_membership {
|
|
|
sub get_users_groups { |
sub get_users_groups { |
my ($udom,$uname,$courseid) = @_; |
my ($udom,$uname,$courseid) = @_; |
|
my @usersgroups; |
my $cachetime=1800; |
my $cachetime=1800; |
$courseid=~s/\_/\//g; |
$courseid=~s/\_/\//g; |
$courseid=~s/^(\w)/\/$1/; |
$courseid=~s/^(\w)/\/$1/; |
|
|
my $hashid="$udom:$uname:$courseid"; |
my $hashid="$udom:$uname:$courseid"; |
my ($result,$cached)=&is_cached_new('getgroups',$hashid); |
my ($grouplist,$cached)=&is_cached_new('getgroups',$hashid); |
if (defined($cached)) { return $result; } |
if (defined($cached)) { |
|
@usersgroups = split(/:/,$grouplist); |
my %roleshash = &dump('roles',$udom,$uname,$courseid); |
} else { |
my ($tmp) = keys(%roleshash); |
$grouplist = ''; |
if ($tmp=~/^error:/) { |
my %roleshash = &dump('roles',$udom,$uname,$courseid); |
&logthis('Error retrieving roles: '.$tmp.' for '.$uname.':'.$udom); |
my ($tmp) = keys(%roleshash); |
return ''; |
if ($tmp=~/^error:/) { |
} else { |
&logthis('Error retrieving roles: '.$tmp.' for '.$uname.':'.$udom); |
my $grouplist; |
} else { |
foreach my $key (keys %roleshash) { |
my $access_end = $env{'course.'.$courseid. |
if ($key =~ /^\Q$courseid\E\/(\w+)\_gr$/) { |
'.default_enrollment_end_date'}; |
unless ($roleshash{$key} =~ /_1_1$/) { # deleted membership |
my $now = time; |
$grouplist .= $1.':'; |
foreach my $key (keys(%roleshash)) { |
|
if ($key =~ /^\Q$courseid\E\/(\w+)\_gr$/) { |
|
my $group = $1; |
|
if ($roleshash{$key} =~ /_(\d+)_(\d+)$/) { |
|
my $start = $2; |
|
my $end = $1; |
|
if ($start == -1) { next; } # deleted from group |
|
if (($start!=0) && ($start>$now)) { next; } |
|
if (($end!=0) && ($end<$now)) { |
|
if ($access_end && $access_end < $now) { |
|
if ($access_end - $end < 86400) { |
|
push(@usersgroups,$group); |
|
} |
|
} |
|
next; |
|
} |
|
push(@usersgroups,$group); |
|
} |
} |
} |
} |
} |
|
@usersgroups = &sort_course_groups($courseid,@usersgroups); |
|
$grouplist = join(':',@usersgroups); |
|
&do_cache_new('getgroups',$hashid,$grouplist,$cachetime); |
} |
} |
$grouplist =~ s/:$//; |
|
return &do_cache_new('getgroups',$hashid,$grouplist,$cachetime); |
|
} |
} |
|
return @usersgroups; |
} |
} |
|
|
sub devalidate_getgroups_cache { |
sub devalidate_getgroups_cache { |
Line 4646 sub GetFileTimestamp {
|
Line 4804 sub GetFileTimestamp {
|
} |
} |
} |
} |
|
|
|
sub stat_file { |
|
my ($uri) = @_; |
|
$uri = &clutter($uri); |
|
|
|
# we want just the url part without the unneeded accessor url bits |
|
if ($uri =~ m-^/adm/-) { |
|
$uri=~s-^/adm/wrapper/-/-; |
|
$uri=~s-^/adm/coursedocs/showdoc/-/-; |
|
} |
|
my ($udom,$uname,$file,$dir); |
|
if ($uri =~ m-^/(uploaded|editupload)/-) { |
|
($udom,$uname,$file) = |
|
($uri =~ m-/(?:uploaded|editupload)/?([^/]*)/?([^/]*)/?(.*)-); |
|
$file = 'userfiles/'.$file; |
|
$dir = &Apache::loncommon::propath($udom,$uname); |
|
} |
|
if ($uri =~ m-^/res/-) { |
|
($udom,$uname) = |
|
($uri =~ m-/(?:res)/?([^/]*)/?([^/]*)/-); |
|
$file = $uri; |
|
} |
|
|
|
if (!$udom || !$uname || !$file) { |
|
# unable to handle the uri |
|
return (); |
|
} |
|
|
|
my ($result) = &dirlist($file,$udom,$uname,$dir); |
|
my @stats = split('&', $result); |
|
|
|
if($stats[0] ne 'empty' && $stats[0] ne 'no_such_dir') { |
|
shift(@stats); #filename is first |
|
return @stats; |
|
} |
|
return (); |
|
} |
|
|
# -------------------------------------------------------- Value of a Condition |
# -------------------------------------------------------- Value of a Condition |
|
|
|
# gets the value of a specific preevaluated condition |
|
# stored in the string $env{user.state.<cid>} |
|
# or looks up a condition reference in the bighash and if if hasn't |
|
# already been evaluated recurses into docondval to get the value of |
|
# the condition, then memoizing it to |
|
# $env{user.state.<cid>.<condition>} |
sub directcondval { |
sub directcondval { |
my $number=shift; |
my $number=shift; |
if (!defined($env{'user.state.'.$env{'request.course.id'}})) { |
if (!defined($env{'user.state.'.$env{'request.course.id'}})) { |
&Apache::lonuserstate::evalstate(); |
&Apache::lonuserstate::evalstate(); |
} |
} |
|
if (exists($env{'user.state.'.$env{'request.course.id'}.".$number"})) { |
|
return $env{'user.state.'.$env{'request.course.id'}.".$number"}; |
|
} elsif ($number =~ /^_/) { |
|
my $sub_condition; |
|
if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db', |
|
&GDBM_READER(),0640)) { |
|
$sub_condition=$bighash{'conditions'.$number}; |
|
untie(%bighash); |
|
} |
|
my $value = &docondval($sub_condition); |
|
&appenv('user.state.'.$env{'request.course.id'}.".$number" => $value); |
|
return $value; |
|
} |
if ($env{'user.state.'.$env{'request.course.id'}}) { |
if ($env{'user.state.'.$env{'request.course.id'}}) { |
return substr($env{'user.state.'.$env{'request.course.id'}},$number,1); |
return substr($env{'user.state.'.$env{'request.course.id'}},$number,1); |
} else { |
} else { |
Line 4660 sub directcondval {
|
Line 4874 sub directcondval {
|
} |
} |
} |
} |
|
|
|
# get the collection of conditions for this resource |
sub condval { |
sub condval { |
my $condidx=shift; |
my $condidx=shift; |
my $result=0; |
|
my $allpathcond=''; |
my $allpathcond=''; |
foreach (split(/\|/,$condidx)) { |
foreach my $cond (split(/\|/,$condidx)) { |
if (defined($env{'acc.cond.'.$env{'request.course.id'}.'.'.$_})) { |
if (defined($env{'acc.cond.'.$env{'request.course.id'}.'.'.$cond})) { |
$allpathcond.= |
$allpathcond.= |
'('.$env{'acc.cond.'.$env{'request.course.id'}.'.'.$_}.')|'; |
'('.$env{'acc.cond.'.$env{'request.course.id'}.'.'.$cond}.')|'; |
} |
} |
} |
} |
$allpathcond=~s/\|$//; |
$allpathcond=~s/\|$//; |
if ($env{'request.course.id'}) { |
return &docondval($allpathcond); |
if ($allpathcond) { |
} |
my $operand='|'; |
|
my @stack; |
#evaluates an expression of conditions |
foreach ($allpathcond=~/(\d+|\(|\)|\&|\|)/g) { |
sub docondval { |
if ($_ eq '(') { |
my ($allpathcond) = @_; |
push @stack,($operand,$result) |
my $result=0; |
} elsif ($_ eq ')') { |
if ($env{'request.course.id'} |
my $before=pop @stack; |
&& defined($allpathcond)) { |
if (pop @stack eq '&') { |
my $operand='|'; |
$result=$result>$before?$before:$result; |
my @stack; |
} else { |
foreach my $chunk ($allpathcond=~/(\d+|_\d+\.\d+|\(|\)|\&|\|)/g) { |
$result=$result>$before?$result:$before; |
if ($chunk eq '(') { |
} |
push @stack,($operand,$result); |
} elsif (($_ eq '&') || ($_ eq '|')) { |
} elsif ($chunk eq ')') { |
$operand=$_; |
my $before=pop @stack; |
} else { |
if (pop @stack eq '&') { |
my $new=directcondval($_); |
$result=$result>$before?$before:$result; |
if ($operand eq '&') { |
} else { |
$result=$result>$new?$new:$result; |
$result=$result>$before?$result:$before; |
} else { |
} |
$result=$result>$new?$result:$new; |
} elsif (($chunk eq '&') || ($chunk eq '|')) { |
} |
$operand=$chunk; |
} |
} else { |
} |
my $new=directcondval($chunk); |
} |
if ($operand eq '&') { |
|
$result=$result>$new?$new:$result; |
|
} else { |
|
$result=$result>$new?$result:$new; |
|
} |
|
} |
|
} |
} |
} |
return $result; |
return $result; |
} |
} |
Line 4813 sub EXT_cache_set {
|
Line 5033 sub EXT_cache_set {
|
|
|
# --------------------------------------------------------- Value of a Variable |
# --------------------------------------------------------- Value of a Variable |
sub EXT { |
sub EXT { |
my ($varname,$symbparm,$udom,$uname,$usection,$recurse)=@_; |
|
|
|
|
my ($varname,$symbparm,$udom,$uname,$usection,$recurse)=@_; |
unless ($varname) { return ''; } |
unless ($varname) { return ''; } |
#get real user name/domain, courseid and symb |
#get real user name/domain, courseid and symb |
my $courseid; |
my $courseid; |
Line 4928 sub EXT {
|
Line 5148 sub EXT {
|
return $env{'course.'.$courseid.'.'.$spacequalifierrest}; |
return $env{'course.'.$courseid.'.'.$spacequalifierrest}; |
} elsif ($realm eq 'resource') { |
} elsif ($realm eq 'resource') { |
|
|
my $section; |
|
if (defined($courseid) && $courseid eq $env{'request.course.id'}) { |
if (defined($courseid) && $courseid eq $env{'request.course.id'}) { |
if (!$symbparm) { $symbparm=&symbread(); } |
if (!$symbparm) { $symbparm=&symbread(); } |
} |
} |
|
|
|
if ($space eq 'title') { |
|
if (!$symbparm) { $symbparm = $env{'request.filename'}; } |
|
return &gettitle($symbparm); |
|
} |
|
|
|
if ($space eq 'map') { |
|
my ($map) = &decode_symb($symbparm); |
|
return &symbread($map); |
|
} |
|
|
|
my ($section, $group, @groups); |
my ($courselevelm,$courselevel); |
my ($courselevelm,$courselevel); |
if ($symbparm && defined($courseid) && |
if ($symbparm && defined($courseid) && |
$courseid eq $env{'request.course.id'}) { |
$courseid eq $env{'request.course.id'}) { |
Line 4948 sub EXT {
|
Line 5179 sub EXT {
|
if (($env{'user.name'} eq $uname) && |
if (($env{'user.name'} eq $uname) && |
($env{'user.domain'} eq $udom)) { |
($env{'user.domain'} eq $udom)) { |
$section=$env{'request.course.sec'}; |
$section=$env{'request.course.sec'}; |
|
@groups = split(/:/,$env{'request.course.groups'}); |
|
@groups=&sort_course_groups($courseid,@groups); |
} else { |
} else { |
if (! defined($usection)) { |
if (! defined($usection)) { |
$section=&getsection($udom,$uname,$courseid); |
$section=&getsection($udom,$uname,$courseid); |
} else { |
} else { |
$section = $usection; |
$section = $usection; |
} |
} |
|
@groups = &get_users_groups($udom,$uname,$courseid); |
} |
} |
|
|
my $seclevel=$courseid.'.['.$section.'].'.$spacequalifierrest; |
my $seclevel=$courseid.'.['.$section.'].'.$spacequalifierrest; |
Line 4969 sub EXT {
|
Line 5203 sub EXT {
|
my $userreply=&resdata($uname,$udom,'user', |
my $userreply=&resdata($uname,$udom,'user', |
($courselevelr,$courselevelm, |
($courselevelr,$courselevelm, |
$courselevel)); |
$courselevel)); |
|
|
if (defined($userreply)) { return $userreply; } |
if (defined($userreply)) { return $userreply; } |
|
|
# ------------------------------------------------ second, check some of course |
# ------------------------------------------------ second, check some of course |
|
my $coursereply; |
|
if (@groups > 0) { |
|
$coursereply = &check_group_parms($courseid,\@groups,$symbparm, |
|
$mapparm,$spacequalifierrest); |
|
if (defined($coursereply)) { return $coursereply; } |
|
} |
|
|
my $coursereply=&resdata($env{'course.'.$courseid.'.num'}, |
$coursereply=&resdata($env{'course.'.$courseid.'.num'}, |
$env{'course.'.$courseid.'.domain'}, |
$env{'course.'.$courseid.'.domain'}, |
'course', |
'course', |
($seclevelr,$seclevelm,$seclevel, |
($seclevelr,$seclevelm,$seclevel, |
Line 5054 sub EXT {
|
Line 5293 sub EXT {
|
return ''; |
return ''; |
} |
} |
|
|
|
sub check_group_parms { |
|
my ($courseid,$groups,$symbparm,$mapparm,$what) = @_; |
|
my @groupitems = (); |
|
my $resultitem; |
|
my @levels = ($symbparm,$mapparm,$what); |
|
foreach my $group (@{$groups}) { |
|
foreach my $level (@levels) { |
|
my $item = $courseid.'.['.$group.'].'.$level; |
|
push(@groupitems,$item); |
|
} |
|
} |
|
my $coursereply = &resdata($env{'course.'.$courseid.'.num'}, |
|
$env{'course.'.$courseid.'.domain'}, |
|
'course',@groupitems); |
|
return $coursereply; |
|
} |
|
|
|
sub sort_course_groups { # Sort groups based on defined rankings. Default is sort(). |
|
my ($courseid,@groups) = @_; |
|
@groups = sort(@groups); |
|
return @groups; |
|
} |
|
|
sub packages_tab_default { |
sub packages_tab_default { |
my ($uri,$varname)=@_; |
my ($uri,$varname)=@_; |
my (undef,$part,$name)=split(/\./,$varname); |
my (undef,$part,$name)=split(/\./,$varname); |
Line 5402 sub symblist {
|
Line 5664 sub symblist {
|
if (($env{'request.course.fn'}) && (%newhash)) { |
if (($env{'request.course.fn'}) && (%newhash)) { |
if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db', |
if (tie(%hash,'GDBM_File',$env{'request.course.fn'}.'_symb.db', |
&GDBM_WRCREAT(),0640)) { |
&GDBM_WRCREAT(),0640)) { |
foreach (keys %newhash) { |
foreach my $url (keys %newhash) { |
$hash{declutter($_)}=&encode_symb($mapname,$newhash{$_}->[1], |
next if ($url eq 'last_known' |
$newhash{$_}->[0]); |
&& $env{'form.no_update_last_known'}); |
|
$hash{declutter($url)}=&encode_symb($mapname, |
|
$newhash{$url}->[1], |
|
$newhash{$url}->[0]); |
} |
} |
if (untie(%hash)) { |
if (untie(%hash)) { |
return 'ok'; |
return 'ok'; |
Line 6251 sub clutter {
|
Line 6516 sub clutter {
|
&& $thisfn!~/\.(sequence|page)$/) { |
&& $thisfn!~/\.(sequence|page)$/) { |
$thisfn='/adm/coursedocs/showdoc'.$thisfn; |
$thisfn='/adm/coursedocs/showdoc'.$thisfn; |
} else { |
} else { |
#&logthis("Got a blank emb style"); |
# &logthis("Got a blank emb style"); |
} |
} |
} |
} |
} |
} |
Line 6319 sub goodbye {
|
Line 6584 sub goodbye {
|
&logthis(sprintf("%-20s is %s",'hits',$hits)); |
&logthis(sprintf("%-20s is %s",'hits',$hits)); |
&flushcourselogs(); |
&flushcourselogs(); |
&logthis("Shutting down"); |
&logthis("Shutting down"); |
return DONE; |
|
} |
} |
|
|
BEGIN { |
BEGIN { |
Line 6398 BEGIN {
|
Line 6662 BEGIN {
|
} |
} |
close($config); |
close($config); |
# FIXME: dev server don't want this, production servers _do_ want this |
# FIXME: dev server don't want this, production servers _do_ want this |
&get_iphost(); |
#&get_iphost(); |
} |
} |
|
|
sub get_iphost { |
sub get_iphost { |
Line 7072 all args are optional
|
Line 7336 all args are optional
|
|
|
=item * |
=item * |
|
|
|
dumpstore($namespace,$udom,$uname,$regexp,$range) : |
|
dumps the complete (or key matching regexp) namespace into a hash |
|
($udom, $uname, $regexp, $range are optional) for a namespace that is |
|
normally &store()ed into |
|
|
|
$range should be either an integer '100' (give me the first 100 |
|
matching records) |
|
or be two integers sperated by a - with no spaces |
|
'30-50' (give me the 30th through the 50th matching |
|
records) |
|
|
|
|
|
=item * |
|
|
|
putstore($namespace,$symb,$version,$storehash,$udomain,$uname) : |
|
replaces a &store() version of data with a replacement set of data |
|
for a particular resource in a namespace passed in the $storehash hash |
|
reference |
|
|
|
=item * |
|
|
tmpstore($storehash,$symb,$namespace,$udom,$uname) : storage that |
tmpstore($storehash,$symb,$namespace,$udom,$uname) : storage that |
works very similar to store/cstore, but all data is stored in a |
works very similar to store/cstore, but all data is stored in a |
temporary location and can be reset using tmpreset, $storehash should |
temporary location and can be reset using tmpreset, $storehash should |
Line 7101 namesp ($udom and $uname are optional)
|
Line 7386 namesp ($udom and $uname are optional)
|
|
|
=item * |
=item * |
|
|
dump($namespace,$udom,$uname,$regexp) : |
dump($namespace,$udom,$uname,$regexp,$range) : |
dumps the complete (or key matching regexp) namespace into a hash |
dumps the complete (or key matching regexp) namespace into a hash |
($udom, $uname and $regexp are optional) |
($udom, $uname, $regexp, $range are optional) |
|
|
|
$range should be either an integer '100' (give me the first 100 |
|
matching records) |
|
or be two integers sperated by a - with no spaces |
|
'30-50' (give me the 30th through the 50th matching |
|
records) |
=item * |
=item * |
|
|
inc($namespace,$store,$udom,$uname) : increments $store in $namespace. |
inc($namespace,$store,$udom,$uname) : increments $store in $namespace. |
Line 7120 put($namespace,$storehash,$udom,$uname)
|
Line 7410 put($namespace,$storehash,$udom,$uname)
|
|
|
=item * |
=item * |
|
|
putstore($namespace,$storehash,$udomain,$uname) : stores hash in namesp |
|
keys used in storehash include version information (e.g., 1:$symb:message etc.) as |
|
used in records written by &store and retrieved by &restore. This function |
|
was created for use in editing discussion posts, without incrementing the |
|
version number included in the key for a particular post. The colon |
|
separated list of attribute names (e.g., the value associated with the key |
|
1:keys:$symb) is also generated and passed in the ampersand separated |
|
items sent to lonnet::reply(). |
|
|
|
=item * |
|
|
|
cput($namespace,$storehash,$udom,$uname) : critical put |
cput($namespace,$storehash,$udom,$uname) : critical put |
($udom and $uname are optional) |
($udom and $uname are optional) |
|
|
Line 7260 getfile($file,$caller) : two cases - req
|
Line 7539 getfile($file,$caller) : two cases - req
|
- returns the entire contents of a file or -1; |
- returns the entire contents of a file or -1; |
it properly subscribes to and replicates the file if neccessary. |
it properly subscribes to and replicates the file if neccessary. |
|
|
|
|
|
=item * |
|
|
|
stat_file($url) : $url is expected to be a /res/ or /uploaded/ style file |
|
reference |
|
|
|
returns either a stat() list of data about the file or an empty list |
|
if the file doesn't exist or couldn't find out about it (connection |
|
problems or user unknown) |
|
|
=item * |
=item * |
|
|
filelocation($dir,$file) : returns file system location of a file |
filelocation($dir,$file) : returns file system location of a file |