version 1.824.2.4, 2007/04/24 19:38:15
|
version 1.840, 2007/03/02 23:53:19
|
Line 35 use HTTP::Headers;
|
Line 35 use HTTP::Headers;
|
use HTTP::Date; |
use HTTP::Date; |
# use Date::Parse; |
# use Date::Parse; |
use vars |
use vars |
qw(%perlvar %hostname %badServerCache %iphost %spareid %hostdom |
qw(%perlvar %badServerCache %iphost %spareid %hostdom |
%libserv %pr %prp $memcache %packagetab |
%libserv %pr %prp $memcache %packagetab |
%courselogs %accesshash %userrolehash %domainrolehash $processmarker $dumpcount |
%courselogs %accesshash %userrolehash %domainrolehash $processmarker $dumpcount |
%coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseinstcodebuf %courseownerbuf %coursetypebuf |
%coursedombuf %coursenumbuf %coursehombuf %coursedescrbuf %courseinstcodebuf %courseownerbuf %coursetypebuf |
Line 149 sub logperm {
|
Line 149 sub logperm {
|
# -------------------------------------------------- Non-critical communication |
# -------------------------------------------------- Non-critical communication |
sub subreply { |
sub subreply { |
my ($cmd,$server)=@_; |
my ($cmd,$server)=@_; |
my $peerfile="$perlvar{'lonSockDir'}/".$hostname{$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 189 sub subreply {
|
Line 189 sub subreply {
|
|
|
sub reply { |
sub reply { |
my ($cmd,$server)=@_; |
my ($cmd,$server)=@_; |
unless (defined($hostname{$server})) { return 'no_such_host'; } |
unless (defined(&hostname($server))) { return 'no_such_host'; } |
my $answer=subreply($cmd,$server); |
my $answer=subreply($cmd,$server); |
if (($answer=~/^refused/) || ($answer=~/^rejected/)) { |
if (($answer=~/^refused/) || ($answer=~/^rejected/)) { |
&logthis("<font color=\"blue\">WARNING:". |
&logthis("<font color=\"blue\">WARNING:". |
Line 201 sub reply {
|
Line 201 sub reply {
|
# ----------------------------------------------------------- Send USR1 to lonc |
# ----------------------------------------------------------- Send USR1 to lonc |
|
|
sub reconlonc { |
sub reconlonc { |
my $peerfile=shift; |
&logthis("Trying to reconnect lonc"); |
&logthis("Trying to reconnect for $peerfile"); |
|
my $loncfile="$perlvar{'lonDaemons'}/logs/lonc.pid"; |
my $loncfile="$perlvar{'lonDaemons'}/logs/lonc.pid"; |
if (open(my $fh,"<$loncfile")) { |
if (open(my $fh,"<$loncfile")) { |
my $loncpid=<$fh>; |
my $loncpid=<$fh>; |
Line 211 sub reconlonc {
|
Line 210 sub reconlonc {
|
&logthis("lonc at pid $loncpid responding, sending USR1"); |
&logthis("lonc at pid $loncpid responding, sending USR1"); |
kill USR1 => $loncpid; |
kill USR1 => $loncpid; |
sleep 1; |
sleep 1; |
if (-e "$peerfile") { return; } |
} else { |
&logthis("$peerfile still not there, give it another try"); |
|
sleep 5; |
|
if (-e "$peerfile") { return; } |
|
&logthis( |
|
"<font color=\"blue\">WARNING: $peerfile still not there, giving up</font>"); |
|
} else { |
|
&logthis( |
&logthis( |
"<font color=\"blue\">WARNING:". |
"<font color=\"blue\">WARNING:". |
" lonc at pid $loncpid not responding, giving up</font>"); |
" lonc at pid $loncpid not responding, giving up</font>"); |
} |
} |
} else { |
} else { |
&logthis('<font color="blue">WARNING: lonc not running, giving up</font>'); |
&logthis('<font color="blue">WARNING: lonc not running, giving up</font>'); |
} |
} |
} |
} |
|
|
Line 231 sub reconlonc {
|
Line 224 sub reconlonc {
|
|
|
sub critical { |
sub critical { |
my ($cmd,$server)=@_; |
my ($cmd,$server)=@_; |
unless ($hostname{$server}) { |
unless (&hostname($server)) { |
&logthis("<font color=\"blue\">WARNING:". |
&logthis("<font color=\"blue\">WARNING:". |
" Critical message to unknown server ($server)</font>"); |
" Critical message to unknown server ($server)</font>"); |
return 'no_such_host'; |
return 'no_such_host'; |
Line 524 sub spareserver {
|
Line 517 sub spareserver {
|
} |
} |
|
|
if (!$want_server_name) { |
if (!$want_server_name) { |
$spare_server="http://$hostname{$spare_server}"; |
$spare_server="http://".&hostname($spare_server); |
} |
} |
return $spare_server; |
return $spare_server; |
} |
} |
Line 615 sub authenticate {
|
Line 608 sub authenticate {
|
my ($uname,$upass,$udom)=@_; |
my ($uname,$upass,$udom)=@_; |
$upass=&escape($upass); |
$upass=&escape($upass); |
$uname= &LONCAPA::clean_username($uname); |
$uname= &LONCAPA::clean_username($uname); |
my $uhome=&homeserver($uname,$udom); |
my $uhome=&homeserver($uname,$udom,1); |
if (!$uhome) { |
if ((!$uhome) || ($uhome eq 'no_host')) { |
&logthis("User $uname at $udom is unknown in authenticate"); |
# Maybe the machine was offline and only re-appeared again recently? |
|
&reconlonc(); |
|
# One more |
|
my $uhome=&homeserver($uname,$udom,1); |
|
if ((!$uhome) || ($uhome eq 'no_host')) { |
|
&logthis("User $uname at $udom is unknown in authenticate"); |
|
} |
return 'no_host'; |
return 'no_host'; |
} |
} |
my $answer=reply("encrypt:auth:$udom:$uname:$upass",$uhome); |
my $answer=reply("encrypt:auth:$udom:$uname:$upass",$uhome); |
Line 647 sub homeserver {
|
Line 646 sub homeserver {
|
exists($badServerCache{$tryserver})); |
exists($badServerCache{$tryserver})); |
if ($hostdom{$tryserver} eq $udom) { |
if ($hostdom{$tryserver} eq $udom) { |
my $answer=reply("home:$udom:$uname",$tryserver); |
my $answer=reply("home:$udom:$uname",$tryserver); |
if ($answer eq 'found') { |
if ($answer eq 'found') { |
|
delete($badServerCache{$tryserver}); |
return $homecache{$index}=$tryserver; |
return $homecache{$index}=$tryserver; |
} elsif ($answer eq 'no_host') { |
} elsif ($answer eq 'no_host') { |
$badServerCache{$tryserver}=1; |
$badServerCache{$tryserver}=1; |
Line 766 sub put_dom {
|
Line 766 sub put_dom {
|
} |
} |
} |
} |
|
|
|
sub retrieve_inst_usertypes { |
|
my ($udom) = @_; |
|
my (%returnhash,@order); |
|
if (exists($domain_primary{$udom})) { |
|
my $uhome=$domain_primary{$udom}; |
|
my $rep=&reply("inst_usertypes:$udom",$uhome); |
|
my ($hashitems,$orderitems) = split(/:/,$rep); |
|
my @pairs=split(/\&/,$hashitems); |
|
foreach my $item (@pairs) { |
|
my ($key,$value)=split(/=/,$item,2); |
|
$key = &unescape($key); |
|
next if ($key =~ /^error: 2 /); |
|
$returnhash{$key}=&thaw_unescape($value); |
|
} |
|
my @esc_order = split(/\&/,$orderitems); |
|
foreach my $item (@esc_order) { |
|
push(@order,&unescape($item)); |
|
} |
|
} else { |
|
&logthis("get_dom failed - no primary domain server for $udom"); |
|
} |
|
return (\%returnhash,\@order); |
|
} |
|
|
# --------------------------------------------------- Assign a key to a student |
# --------------------------------------------------- Assign a key to a student |
|
|
sub assign_access_key { |
sub assign_access_key { |
Line 990 my %remembered;
|
Line 1014 my %remembered;
|
my %accessed; |
my %accessed; |
my $kicks=0; |
my $kicks=0; |
my $hits=0; |
my $hits=0; |
sub make_key { |
|
my ($name,$id) = @_; |
|
if (length($id) > 200) { $id=length($id).':'.&Digest::MD5::md5_hex($id); } |
|
return &escape($name.':'.$id); |
|
} |
|
|
|
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"); } |
$id=&make_key($name,$id); |
$id=&escape($name.':'.$id); |
$memcache->delete($id); |
$memcache->delete($id); |
delete($remembered{$id}); |
delete($remembered{$id}); |
delete($accessed{$id}); |
delete($accessed{$id}); |
Line 1007 sub devalidate_cache_new {
|
Line 1025 sub devalidate_cache_new {
|
|
|
sub is_cached_new { |
sub is_cached_new { |
my ($name,$id,$debug) = @_; |
my ($name,$id,$debug) = @_; |
$id=&make_key($name,$id); |
$id=&escape($name.':'.$id); |
if (exists($remembered{$id})) { |
if (exists($remembered{$id})) { |
if ($debug) { &Apache::lonnet::logthis("Earyl return $id of $remembered{$id} "); } |
if ($debug) { &Apache::lonnet::logthis("Earyl return $id of $remembered{$id} "); } |
$accessed{$id}=[&gettimeofday()]; |
$accessed{$id}=[&gettimeofday()]; |
Line 1030 sub is_cached_new {
|
Line 1048 sub is_cached_new {
|
|
|
sub do_cache_new { |
sub do_cache_new { |
my ($name,$id,$value,$time,$debug) = @_; |
my ($name,$id,$value,$time,$debug) = @_; |
$id=&make_key($name,$id); |
$id=&escape($name.':'.$id); |
my $setvalue=$value; |
my $setvalue=$value; |
if (!defined($setvalue)) { |
if (!defined($setvalue)) { |
$setvalue='__undef__'; |
$setvalue='__undef__'; |
Line 1208 sub repcopy {
|
Line 1226 sub repcopy {
|
} |
} |
$filename=~s/[\n\r]//g; |
$filename=~s/[\n\r]//g; |
my $transname="$filename.in.transfer"; |
my $transname="$filename.in.transfer"; |
|
# FIXME: this should flock |
if ((-e $filename) || (-e $transname)) { return 'ok'; } |
if ((-e $filename) || (-e $transname)) { return 'ok'; } |
my $remoteurl=subscribe($filename); |
my $remoteurl=subscribe($filename); |
if ($remoteurl =~ /^con_lost by/) { |
if ($remoteurl =~ /^con_lost by/) { |
Line 1456 sub store_edited_file {
|
Line 1475 sub store_edited_file {
|
} |
} |
|
|
sub clean_filename { |
sub clean_filename { |
my ($fname)=@_; |
my ($fname,$args)=@_; |
# Replace Windows backslashes by forward slashes |
# Replace Windows backslashes by forward slashes |
$fname=~s/\\/\//g; |
$fname=~s/\\/\//g; |
# Get rid of everything but the actual filename |
if (!$args->{'keep_path'}) { |
$fname=~s/^.*\/([^\/]+)$/$1/; |
# Get rid of everything but the actual filename |
|
$fname=~s/^.*\/([^\/]+)$/$1/; |
|
} |
# Replace spaces by underscores |
# Replace spaces by underscores |
$fname=~s/\s+/\_/g; |
$fname=~s/\s+/\_/g; |
# Replace all other weird characters by nothing |
# Replace all other weird characters by nothing |
$fname=~s/[^\w\.\-]//g; |
$fname=~s{[^/\w\.\-]}{}g; |
# Replace all .\d. sequences with _\d. so they no longer look like version |
# Replace all .\d. sequences with _\d. so they no longer look like version |
# numbers |
# numbers |
$fname=~s/\.(\d+)(?=\.)/_$1/g; |
$fname=~s/\.(\d+)(?=\.)/_$1/g; |
Line 1822 sub flushcourselogs {
|
Line 1843 sub flushcourselogs {
|
# Write course id database (reverse lookup) to homeserver of courses |
# Write course id database (reverse lookup) to homeserver of courses |
# Is used in pickcourse |
# Is used in pickcourse |
# |
# |
foreach my $crsid (keys(%courseidbuffer)) { |
foreach my $crs_home (keys(%courseidbuffer)) { |
&courseidput($hostdom{$crsid},$courseidbuffer{$crsid},$crsid); |
&courseidput($hostdom{$crs_home},$courseidbuffer{$crs_home}, |
|
$crs_home); |
} |
} |
# |
# |
# File accesses |
# File accesses |
Line 2030 sub get_course_adv_roles {
|
Line 2052 sub get_course_adv_roles {
|
} |
} |
|
|
sub get_my_roles { |
sub get_my_roles { |
my ($uname,$udom)=@_; |
my ($uname,$udom,$types,$roles,$roledoms)=@_; |
unless (defined($uname)) { $uname=$env{'user.name'}; } |
unless (defined($uname)) { $uname=$env{'user.name'}; } |
unless (defined($udom)) { $udom=$env{'user.domain'}; } |
unless (defined($udom)) { $udom=$env{'user.domain'}; } |
my %dumphash= |
my %dumphash= |
Line 2040 sub get_my_roles {
|
Line 2062 sub get_my_roles {
|
foreach my $entry (keys(%dumphash)) { |
foreach my $entry (keys(%dumphash)) { |
my ($tend,$tstart)=split(/\:/,$dumphash{$entry}); |
my ($tend,$tstart)=split(/\:/,$dumphash{$entry}); |
if (($tstart) && ($tstart<0)) { next; } |
if (($tstart) && ($tstart<0)) { next; } |
if (($tend) && ($tend<$now)) { next; } |
my $status = 'active'; |
if (($tstart) && ($now<$tstart)) { next; } |
if (($tend) && ($tend<$now)) { |
|
$status = 'previous'; |
|
} |
|
if (($tstart) && ($now<$tstart)) { |
|
$status = 'future'; |
|
} |
|
if (ref($types) eq 'ARRAY') { |
|
if (!grep(/^\Q$status\E$/,@{$types})) { |
|
next; |
|
} |
|
} else { |
|
if ($status ne 'active') { |
|
next; |
|
} |
|
} |
my ($role,$username,$domain,$section)=split(/\:/,$entry); |
my ($role,$username,$domain,$section)=split(/\:/,$entry); |
|
if (ref($roledoms) eq 'ARRAY') { |
|
if (!grep(/^\Q$domain\E$/,@{$roledoms})) { |
|
next; |
|
} |
|
} |
|
if (ref($roles) eq 'ARRAY') { |
|
if (!grep(/^\Q$role\E$/,@{$roles})) { |
|
next; |
|
} |
|
} |
$returnhash{$username.':'.$domain.':'.$role}=$tstart.':'.$tend; |
$returnhash{$username.':'.$domain.':'.$role}=$tstart.':'.$tend; |
} |
} |
return %returnhash; |
return %returnhash; |
} |
} |
|
|
Line 2250 sub checkin {
|
Line 2296 sub checkin {
|
my $now=time; |
my $now=time; |
my ($ta,$tb,$lonhost)=split(/\*/,$token); |
my ($ta,$tb,$lonhost)=split(/\*/,$token); |
$lonhost=~tr/A-Z/a-z/; |
$lonhost=~tr/A-Z/a-z/; |
my $dtoken=$ta.'_'.$hostname{$lonhost}.'_'.$tb; |
my $dtoken=$ta.'_'.&hostname($lonhost).'_'.$tb; |
$dtoken=~s/\W/\_/g; |
$dtoken=~s/\W/\_/g; |
my ($dummy,$tuname,$tudom,$tcrsid,$symb,$chtim,$rmaddr)= |
my ($dummy,$tuname,$tudom,$tcrsid,$symb,$chtim,$rmaddr)= |
split(/\&/,&unescape(&reply('tmpget:'.$dtoken,$lonhost))); |
split(/\&/,&unescape(&reply('tmpget:'.$dtoken,$lonhost))); |
Line 2919 sub custom_roleprivs {
|
Line 2965 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); |
if (($rdummy ne 'con_lost') && ($roledef ne '')) { |
if (($rdummy ne 'con_lost') && ($roledef ne '')) { |
Line 3461 sub get_portfolio_access {
|
Line 3507 sub get_portfolio_access {
|
} |
} |
if (@users > 0) { |
if (@users > 0) { |
foreach my $userkey (@users) { |
foreach my $userkey (@users) { |
if (ref($access_hash->{$userkey}{'users'}) eq 'ARRAY') { |
if (exists($access_hash->{$userkey}{'users'}{$env{'user.name'}.':'.$env{'user.domain'}})) { |
foreach my $item (@{$access_hash->{$userkey}{'users'}}) { |
return 'ok'; |
if (ref($item) eq 'HASH') { |
} |
if (($item->{'uname'} eq $env{'user.name'}) && |
|
($item->{'udom'} eq $env{'user.domain'})) { |
|
return 'ok'; |
|
} |
|
} |
|
} |
|
} |
|
} |
} |
} |
} |
my %roleshash; |
my %roleshash; |
Line 4157 sub log_query {
|
Line 4196 sub log_query {
|
my ($uname,$udom,$query,%filters)=@_; |
my ($uname,$udom,$query,%filters)=@_; |
my $uhome=&homeserver($uname,$udom); |
my $uhome=&homeserver($uname,$udom); |
if ($uhome eq 'no_host') { return 'error: no_host'; } |
if ($uhome eq 'no_host') { return 'error: no_host'; } |
my $uhost=$hostname{$uhome}; |
my $uhost=&hostname($uhome); |
my $command=&escape(join(':',map{$_.'='.$filters{$_}} keys(%filters))); |
my $command=&escape(join(':',map{$_.'='.$filters{$_}} keys(%filters))); |
my $queryid=&reply("querysend:".$query.':'.$udom.':'.$uname.':'.$command, |
my $queryid=&reply("querysend:".$query.':'.$udom.':'.$uname.':'.$command, |
$uhome); |
$uhome); |
Line 4189 sub fetch_enrollment_query {
|
Line 4228 sub fetch_enrollment_query {
|
} else { |
} else { |
$homeserver = &homeserver($cnum,$dom); |
$homeserver = &homeserver($cnum,$dom); |
} |
} |
my $host=$hostname{$homeserver}; |
my $host=&hostname($homeserver); |
my $cmd = ''; |
my $cmd = ''; |
foreach my $affiliate (keys %{$affiliatesref}) { |
foreach my $affiliate (keys %{$affiliatesref}) { |
$cmd .= $affiliate.'='.join(",",@{$$affiliatesref{$affiliate}}).'%%'; |
$cmd .= $affiliate.'='.join(",",@{$$affiliatesref{$affiliate}}).'%%'; |
Line 4380 sub auto_photochoice {
|
Line 4419 sub auto_photochoice {
|
sub auto_photoupdate { |
sub auto_photoupdate { |
my ($affiliatesref,$dom,$cnum,$photo) = @_; |
my ($affiliatesref,$dom,$cnum,$photo) = @_; |
my $homeserver = &homeserver($cnum,$dom); |
my $homeserver = &homeserver($cnum,$dom); |
my $host=$hostname{$homeserver}; |
my $host=&hostname($homeserver); |
my $cmd = ''; |
my $cmd = ''; |
my $maxtries = 1; |
my $maxtries = 1; |
foreach my $affiliate (keys(%{$affiliatesref})) { |
foreach my $affiliate (keys(%{$affiliatesref})) { |
Line 5120 sub is_locked {
|
Line 5159 sub is_locked {
|
|
|
sub declutter_portfile { |
sub declutter_portfile { |
my ($file) = @_; |
my ($file) = @_; |
&logthis("got $file"); |
$file =~ s{^(/portfolio/|portfolio/)}{/}; |
$file =~ s-^(/portfolio/|portfolio/)-/-; |
|
&logthis("ret $file"); |
|
return $file; |
return $file; |
} |
} |
|
|
Line 5355 sub modify_access_controls {
|
Line 5392 sub modify_access_controls {
|
return ($outcome,$deloutcome,\%new_values,\%translation); |
return ($outcome,$deloutcome,\%new_values,\%translation); |
} |
} |
|
|
|
sub make_public_indefinitely { |
|
my ($requrl) = @_; |
|
my $now = time; |
|
my $action = 'activate'; |
|
my $aclnum = 0; |
|
if (&is_portfolio_url($requrl)) { |
|
my (undef,$udom,$unum,$file_name,$group) = |
|
&parse_portfolio_url($requrl); |
|
my $current_perms = &get_portfile_permissions($udom,$unum); |
|
my %access_controls = &get_access_controls($current_perms, |
|
$group,$file_name); |
|
foreach my $key (keys(%{$access_controls{$file_name}})) { |
|
my ($num,$scope,$end,$start) = |
|
($key =~ /^([^:]+):([a-z]+)_(\d*)_?(\d*)$/); |
|
if ($scope eq 'public') { |
|
if ($start <= $now && $end == 0) { |
|
$action = 'none'; |
|
} else { |
|
$action = 'update'; |
|
$aclnum = $num; |
|
} |
|
last; |
|
} |
|
} |
|
if ($action eq 'none') { |
|
return 'ok'; |
|
} else { |
|
my %changes; |
|
my $newend = 0; |
|
my $newstart = $now; |
|
my $newkey = $aclnum.':public_'.$newend.'_'.$newstart; |
|
$changes{$action}{$newkey} = { |
|
type => 'public', |
|
time => { |
|
start => $newstart, |
|
end => $newend, |
|
}, |
|
}; |
|
my ($outcome,$deloutcome,$new_values,$translation) = |
|
&modify_access_controls($file_name,\%changes,$udom,$unum); |
|
return $outcome; |
|
} |
|
} else { |
|
return 'invalid'; |
|
} |
|
} |
|
|
#------------------------------------------------------Get Marked as Read Only |
#------------------------------------------------------Get Marked as Read Only |
|
|
sub get_marked_as_readonly { |
sub get_marked_as_readonly { |
Line 7026 sub setup_random_from_rndseed {
|
Line 7110 sub setup_random_from_rndseed {
|
} |
} |
|
|
sub latest_receipt_algorithm_id { |
sub latest_receipt_algorithm_id { |
return 'receipt2'; |
return 'receipt3'; |
} |
} |
|
|
sub recunique { |
sub recunique { |
my $fucourseid=shift; |
my $fucourseid=shift; |
my $unique; |
my $unique; |
if ($env{"course.$fucourseid.receiptalg"} eq 'receipt2') { |
if ($env{"course.$fucourseid.receiptalg"} eq 'receipt2' || |
|
$env{"course.$fucourseid.receiptalg"} eq 'receipt3' ) { |
$unique=$env{"course.$fucourseid.internal.encseed"}; |
$unique=$env{"course.$fucourseid.internal.encseed"}; |
} else { |
} else { |
$unique=$perlvar{'lonReceipt'}; |
$unique=$perlvar{'lonReceipt'}; |
Line 7043 sub recunique {
|
Line 7128 sub recunique {
|
sub recprefix { |
sub recprefix { |
my $fucourseid=shift; |
my $fucourseid=shift; |
my $prefix; |
my $prefix; |
if ($env{"course.$fucourseid.receiptalg"} eq 'receipt2') { |
if ($env{"course.$fucourseid.receiptalg"} eq 'receipt2'|| |
|
$env{"course.$fucourseid.receiptalg"} eq 'receipt3' ) { |
$prefix=$env{"course.$fucourseid.internal.encpref"}; |
$prefix=$env{"course.$fucourseid.internal.encpref"}; |
} else { |
} else { |
$prefix=$perlvar{'lonHostID'}; |
$prefix=$perlvar{'lonHostID'}; |
Line 7053 sub recprefix {
|
Line 7139 sub recprefix {
|
|
|
sub ireceipt { |
sub ireceipt { |
my ($funame,$fudom,$fucourseid,$fusymb,$part)=@_; |
my ($funame,$fudom,$fucourseid,$fusymb,$part)=@_; |
|
|
|
my $return =&recprefix($fucourseid).'-'; |
|
|
|
if ($env{"course.$fucourseid.receiptalg"} eq 'receipt3' || |
|
$env{'request.state'} eq 'construct') { |
|
$return .= (&digest("$funame,$fudom,$fucourseid,$fusymb,$part")%10000); |
|
return $return; |
|
} |
|
|
my $cuname=unpack("%32C*",$funame); |
my $cuname=unpack("%32C*",$funame); |
my $cudom=unpack("%32C*",$fudom); |
my $cudom=unpack("%32C*",$fudom); |
my $cucourseid=unpack("%32C*",$fucourseid); |
my $cucourseid=unpack("%32C*",$fucourseid); |
my $cusymb=unpack("%32C*",$fusymb); |
my $cusymb=unpack("%32C*",$fusymb); |
my $cunique=&recunique($fucourseid); |
my $cunique=&recunique($fucourseid); |
my $cpart=unpack("%32S*",$part); |
my $cpart=unpack("%32S*",$part); |
my $return =&recprefix($fucourseid).'-'; |
if ($env{"course.$fucourseid.receiptalg"} eq 'receipt2') { |
if ($env{"course.$fucourseid.receiptalg"} eq 'receipt2' || |
|
$env{'request.state'} eq 'construct') { |
|
#&logthis("doing receipt2 using parts $cpart, uname $cuname and udom $cudom gets ".($cpart%$cuname)." and ".($cpart%$cudom)); |
#&logthis("doing receipt2 using parts $cpart, uname $cuname and udom $cudom gets ".($cpart%$cuname)." and ".($cpart%$cudom)); |
|
|
$return.= ($cunique%$cuname+ |
$return.= ($cunique%$cuname+ |
Line 7150 sub repcopy_userfile {
|
Line 7244 sub repcopy_userfile {
|
if ($file =~ m|^/home/httpd/html/lonUsers/|) { return 'ok'; } |
if ($file =~ m|^/home/httpd/html/lonUsers/|) { return 'ok'; } |
my ($cdom,$cnum,$filename) = |
my ($cdom,$cnum,$filename) = |
($file=~m|^\Q$perlvar{'lonDocRoot'}\E/+userfiles/+($match_domain)/+($match_name)/+(.*)|); |
($file=~m|^\Q$perlvar{'lonDocRoot'}\E/+userfiles/+($match_domain)/+($match_name)/+(.*)|); |
my ($info,$rtncode); |
|
my $uri="/uploaded/$cdom/$cnum/$filename"; |
my $uri="/uploaded/$cdom/$cnum/$filename"; |
if (-e "$file") { |
if (-e "$file") { |
|
# we already have a local copy, check it out |
my @fileinfo = stat($file); |
my @fileinfo = stat($file); |
|
my $rtncode; |
|
my $info; |
my $lwpresp = &getuploaded('HEAD',$uri,$cdom,$cnum,\$info,\$rtncode); |
my $lwpresp = &getuploaded('HEAD',$uri,$cdom,$cnum,\$info,\$rtncode); |
if ($lwpresp ne 'ok') { |
if ($lwpresp ne 'ok') { |
|
# there is no such file anymore, even though we had a local copy |
if ($rtncode eq '404') { |
if ($rtncode eq '404') { |
unlink($file); |
unlink($file); |
} |
} |
#my $ua=new LWP::UserAgent; |
|
#my $request=new HTTP::Request('GET',&tokenwrapper($uri)); |
|
#my $response=$ua->request($request); |
|
#if ($response->is_success()) { |
|
# return $response->content; |
|
# } else { |
|
# return -1; |
|
# } |
|
return -1; |
return -1; |
} |
} |
if ($info < $fileinfo[9]) { |
if ($info < $fileinfo[9]) { |
|
# nice, the file we have is up-to-date, just say okay |
return 'ok'; |
return 'ok'; |
|
} else { |
|
# the file is outdated, get rid of it |
|
unlink($file); |
} |
} |
$info = ''; |
} |
$lwpresp = &getuploaded('GET',$uri,$cdom,$cnum,\$info,\$rtncode); |
# one way or the other, at this point, we don't have the file |
if ($lwpresp ne 'ok') { |
# construct the correct path for the file |
return -1; |
my @parts = ($cdom,$cnum); |
} |
if ($filename =~ m|^(.+)/[^/]+$|) { |
} else { |
push @parts, split(/\//,$1); |
my $lwpresp = &getuploaded('GET',$uri,$cdom,$cnum,\$info,\$rtncode); |
} |
if ($lwpresp ne 'ok') { |
my $path = $perlvar{'lonDocRoot'}.'/userfiles'; |
return -1; |
foreach my $part (@parts) { |
} |
$path .= '/'.$part; |
my @parts = ($cdom,$cnum); |
if (!-e $path) { |
if ($filename =~ m|^(.+)/[^/]+$|) { |
mkdir($path,0770); |
push @parts, split(/\//,$1); |
|
} |
|
my $path = $perlvar{'lonDocRoot'}.'/userfiles'; |
|
foreach my $part (@parts) { |
|
$path .= '/'.$part; |
|
if (!-e $path) { |
|
mkdir($path,0770); |
|
} |
|
} |
} |
} |
} |
open(FILE,">$file"); |
# now the path exists for sure |
print FILE $info; |
# get a user agent |
close(FILE); |
my $ua=new LWP::UserAgent; |
|
my $transferfile=$file.'.in.transfer'; |
|
# FIXME: this should flock |
|
if (-e $transferfile) { return 'ok'; } |
|
my $request; |
|
$uri=~s/^\///; |
|
$request=new HTTP::Request('GET','http://'.&hostname(&homeserver($cnum,$cdom)).'/raw/'.$uri); |
|
my $response=$ua->request($request,$transferfile); |
|
# did it work? |
|
if ($response->is_error()) { |
|
unlink($transferfile); |
|
&logthis("Userfile repcopy failed for $uri"); |
|
return -1; |
|
} |
|
# worked, rename the transfer file |
|
rename($transferfile,$file); |
return 'ok'; |
return 'ok'; |
} |
} |
|
|
Line 7210 sub tokenwrapper {
|
Line 7310 sub tokenwrapper {
|
if ($udom && $uname && $file) { |
if ($udom && $uname && $file) { |
$file=~s|(\?\.*)*$||; |
$file=~s|(\?\.*)*$||; |
&appenv("userfile.$udom/$uname/$file" => $env{'request.course.id'}); |
&appenv("userfile.$udom/$uname/$file" => $env{'request.course.id'}); |
return 'http://'.$hostname{ &homeserver($uname,$udom)}.'/'.$uri. |
return 'http://'.&hostname(&homeserver($uname,$udom)).'/'.$uri. |
(($uri=~/\?/)?'&':'?').'token='.$token. |
(($uri=~/\?/)?'&':'?').'token='.$token. |
'&tokenissued='.$perlvar{'lonHostID'}; |
'&tokenissued='.$perlvar{'lonHostID'}; |
} else { |
} else { |
Line 7218 sub tokenwrapper {
|
Line 7318 sub tokenwrapper {
|
} |
} |
} |
} |
|
|
|
# call with reqtype HEAD: get last modification time |
|
# call with reqtype GET: get the file contents |
|
# Do not call this with reqtype GET for large files! It loads everything into memory |
|
# |
sub getuploaded { |
sub getuploaded { |
my ($reqtype,$uri,$cdom,$cnum,$info,$rtncode) = @_; |
my ($reqtype,$uri,$cdom,$cnum,$info,$rtncode) = @_; |
$uri=~s/^\///; |
$uri=~s/^\///; |
$uri = 'http://'.$hostname{ &homeserver($cnum,$cdom)}.'/raw/'.$uri; |
$uri = 'http://'.&hostname(&homeserver($cnum,$cdom)).'/raw/'.$uri; |
my $ua=new LWP::UserAgent; |
my $ua=new LWP::UserAgent; |
my $request=new HTTP::Request($reqtype,$uri); |
my $request=new HTTP::Request($reqtype,$uri); |
my $response=$ua->request($request); |
my $response=$ua->request($request); |
Line 7311 sub hreflocation {
|
Line 7415 sub hreflocation {
|
} |
} |
|
|
sub current_machine_domains { |
sub current_machine_domains { |
my $hostname=$hostname{$perlvar{'lonHostID'}}; |
my $hostname=&hostname($perlvar{'lonHostID'}); |
my @domains; |
my @domains; |
|
my %hostname = &all_hostnames(); |
while( my($id, $name) = each(%hostname)) { |
while( my($id, $name) = each(%hostname)) { |
# &logthis("-$id-$name-$hostname-"); |
# &logthis("-$id-$name-$hostname-"); |
if ($hostname eq $name) { |
if ($hostname eq $name) { |
Line 7323 sub current_machine_domains {
|
Line 7428 sub current_machine_domains {
|
} |
} |
|
|
sub current_machine_ids { |
sub current_machine_ids { |
my $hostname=$hostname{$perlvar{'lonHostID'}}; |
my $hostname=&hostname($perlvar{'lonHostID'}); |
my @ids; |
my @ids; |
|
my %hostname = &all_hostnames(); |
while( my($id, $name) = each(%hostname)) { |
while( my($id, $name) = each(%hostname)) { |
# &logthis("-$id-$name-$hostname-"); |
# &logthis("-$id-$name-$hostname-"); |
if ($hostname eq $name) { |
if ($hostname eq $name) { |
Line 7502 BEGIN {
|
Line 7608 BEGIN {
|
|
|
# ------------------------------------------------------------- Read hosts file |
# ------------------------------------------------------------- Read hosts file |
{ |
{ |
|
my %hostname; |
open(my $config,"<$perlvar{'lonTabDir'}/hosts.tab"); |
open(my $config,"<$perlvar{'lonTabDir'}/hosts.tab"); |
|
|
while (my $configline=<$config>) { |
while (my $configline=<$config>) { |
Line 7518 BEGIN {
|
Line 7625 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 hostname { |
|
my ($lonid) = @_; |
|
return $hostname{$lonid}; |
|
} |
|
sub all_hostnames { |
|
return %hostname; |
|
} |
|
} |
|
|
|
sub get_hosts_from_ip { |
|
my ($ip) = @_; |
|
my %iphosts = &get_iphost(); |
|
if (ref($iphosts{$ip})) { |
|
return @{$iphosts{$ip}}; |
|
} |
|
return; |
} |
} |
|
|
sub get_iphost { |
sub get_iphost { |
if (%iphost) { return %iphost; } |
if (%iphost) { return %iphost; } |
my %name_to_ip; |
my %name_to_ip; |
|
my %hostname = &all_hostnames(); |
foreach my $id (keys(%hostname)) { |
foreach my $id (keys(%hostname)) { |
my $name=$hostname{$id}; |
my $name=$hostname{$id}; |
my $ip; |
my $ip; |
if (!exists($name_to_ip{$name})) { |
if (!exists($name_to_ip{$name})) { |
$ip = gethostbyname($name); |
$ip = gethostbyname($name); |
if (!$ip || length($ip) ne 4) { |
if (!$ip || length($ip) ne 4) { |
&logthis("Skipping host $id name $name no IP found\n"); |
&logthis("Skipping host $id name $name no IP found"); |
next; |
next; |
} |
} |
$ip=inet_ntoa($ip); |
$ip=inet_ntoa($ip); |
Line 7900 and course level
|
Line 8025 and course level
|
plaintext($short) : return value in %prp hash (rolesplain.tab); plain text |
plaintext($short) : return value in %prp hash (rolesplain.tab); plain text |
explanation of a user role term |
explanation of a user role term |
|
|
|
=item * |
|
|
|
get_my_roles($uname,$udom,$types,$roles,$roledoms) : All arguments are |
|
optional. Returns a hash of a user's roles, with keys set to |
|
colon-sparated $uname,$udom,and $role, and value set to |
|
colon-separated start and end times for the role. If no username and |
|
domain are specified, will default to current user/domain. Types, |
|
roles, and roledoms are references to arrays, of role statuses |
|
(active, future or previous), roles (e.g., cc,in, st etc.) and domains |
|
of the roles which can be used to restrict the list if roles |
|
reported. If no array ref is provided for types, will default to |
|
return only active roles. |
|
|
=back |
=back |
|
|
=head2 User Modification |
=head2 User Modification |