version 1.483, 2004/04/01 15:12:26
|
version 1.493, 2004/04/30 23:10:11
|
Line 32 package Apache::lonnet;
|
Line 32 package Apache::lonnet;
|
use strict; |
use strict; |
use LWP::UserAgent(); |
use LWP::UserAgent(); |
use HTTP::Headers; |
use HTTP::Headers; |
use Date::Parse; |
use HTTP::Date; |
|
# use Date::Parse; |
use vars |
use vars |
qw(%perlvar %hostname %homecache %badServerCache %hostip %iphost %spareid %hostdom |
qw(%perlvar %hostname %homecache %badServerCache %hostip %iphost %spareid %hostdom |
%libserv %pr %prp %metacache %packagetab %titlecache %courseresversioncache %resversioncache |
%libserv %pr %prp %metacache %packagetab %titlecache %courseresversioncache %resversioncache |
Line 616 sub idput {
|
Line 617 sub idput {
|
my ($udom,%ids)=@_; |
my ($udom,%ids)=@_; |
my %servers=(); |
my %servers=(); |
foreach (keys %ids) { |
foreach (keys %ids) { |
|
&cput('environment',{'id'=>$ids{$_}},$udom,$_); |
my $uhom=&homeserver($_,$udom); |
my $uhom=&homeserver($_,$udom); |
if ($uhom ne 'no_host') { |
if ($uhom ne 'no_host') { |
my $id=&escape($ids{$_}); |
my $id=&escape($ids{$_}); |
Line 626 sub idput {
|
Line 628 sub idput {
|
} else { |
} else { |
$servers{$uhom}=$id.'='.$unam; |
$servers{$uhom}=$id.'='.$unam; |
} |
} |
&critical('put:'.$udom.':'.$unam.':environment:id='.$id,$uhom); |
|
} |
} |
} |
} |
foreach (keys %servers) { |
foreach (keys %servers) { |
Line 1164 sub externalssi {
|
Line 1165 sub externalssi {
|
return $response->content; |
return $response->content; |
} |
} |
|
|
# ------- Add a token to a remote URI's query string to vouch for access rights |
# -------------------------------- Allow a /uploaded/ URI to be vouched for |
|
|
|
sub allowuploaded { |
|
my ($srcurl,$url)=@_; |
|
$url=&clutter(&declutter($url)); |
|
my $dir=$url; |
|
$dir=~s/\/[^\/]+$//; |
|
my %httpref=(); |
|
my $httpurl=&hreflocation('',$url); |
|
$httpref{'httpref.'.$httpurl}=$srcurl; |
|
&Apache::lonnet::appenv(%httpref); |
|
} |
|
|
sub tokenwrapper { |
sub tokenwrapper { |
my $uri=shift; |
&FIXME_blow_up; |
$uri=~s/^http\:\/\/([^\/]+)//; |
|
$uri=~s/^\///; |
|
$ENV{'user.environment'}=~/\/([^\/]+)\.id/; |
|
my $token=$1; |
|
# if ($uri=~/^uploaded\/([^\/]+)\/([^\/]+)\/([^\/]+)(\?\.*)*$/) { |
|
if ($uri=~m|^uploaded/([^/]+)/([^/]+)/(.+)(\?\.*)*$|) { |
|
&appenv('userfile.'.$1.'/'.$2.'/'.$3 => $ENV{'request.course.id'}); |
|
return 'http://'.$hostname{ &homeserver($2,$1)}.'/'.$uri. |
|
(($uri=~/\?/)?'&':'?').'token='.$token. |
|
'&tokenissued='.$perlvar{'lonHostID'}; |
|
} else { |
|
return '/adm/notfound.html'; |
|
} |
|
} |
} |
|
|
# --------- File operations in /home/httpd/html/userfiles/$domain/1/2/3/$course |
# --------- File operations in /home/httpd/html/userfiles/$domain/1/2/3/$course |
# input: action, courseID, current domain, home server for course, intended |
# input: action, courseID, current domain, home server for course, intended |
# path to file, source of file. |
# path to file, source of file. |
# output: ok if successful, diagnostic message otherwise |
# output: url to file (if action was uploaddoc), |
|
# ok if successful, or diagnostic message otherwise (if action was propagate or copy) |
# |
# |
# Allows directory structure to be used within lonUsers/../userfiles/ for a |
# Allows directory structure to be used within lonUsers/../userfiles/ for a |
# course. |
# course. |
Line 1201 sub tokenwrapper {
|
Line 1201 sub tokenwrapper {
|
# and will then be copied to |
# and will then be copied to |
# /home/httpd/lonUsers/$domain/1/2/3/$course/userfiles/$file in |
# /home/httpd/lonUsers/$domain/1/2/3/$course/userfiles/$file in |
# course's home server. |
# course's home server. |
|
# |
# action = uploaddoc - /home/httpd/html/userfiles/$domain/1/2/3/$course/$file |
# action = uploaddoc - /home/httpd/html/userfiles/$domain/1/2/3/$course/$file |
# will be retrived from $ENV{form.$source} via DOCS interface to |
# will be retrived from $ENV{form.uploaddoc} (from DOCS interface) to |
# /home/httpd/html/userfiles/$domain/1/2/3/$course/$file |
# /home/httpd/html/userfiles/$domain/1/2/3/$course/$file |
# and will then be copied to /home/httpd/lonUsers/1/2/3/$course/userfiles/$file |
# and will then be copied to /home/httpd/lonUsers/1/2/3/$course/userfiles/$file |
# in course's home server. |
# in course's home server. |
Line 1255 sub process_coursefile {
|
Line 1256 sub process_coursefile {
|
} |
} |
} |
} |
} |
} |
unless ( ($fetchresult eq 'ok') || ($fetchresult eq 'no source file') ) { |
unless ( $fetchresult eq 'ok') { |
&logthis('Failed to transfer '.$docudom.'/'.$docuname.'/'.$file. |
&logthis('Failed to transfer '.$docudom.'/'.$docuname.'/'.$file. |
' to host '.$docuhome.': '.$fetchresult); |
' to host '.$docuhome.': '.$fetchresult); |
} |
} |
Line 1267 sub process_coursefile {
|
Line 1268 sub process_coursefile {
|
# output: url of file in userspace |
# output: url of file in userspace |
|
|
sub userfileupload { |
sub userfileupload { |
my ($formname,$coursedoc)=@_; |
my ($formname,$coursedoc,$subdir)=@_; |
|
if (!defined($subdir)) { $subdir='unknown'; } |
my $fname=$ENV{'form.'.$formname.'.filename'}; |
my $fname=$ENV{'form.'.$formname.'.filename'}; |
# Replace Windows backslashes by forward slashes |
# Replace Windows backslashes by forward slashes |
$fname=~s/\\/\//g; |
$fname=~s/\\/\//g; |
Line 1280 sub userfileupload {
|
Line 1282 sub userfileupload {
|
# See if there is anything left |
# See if there is anything left |
unless ($fname) { return 'error: no uploaded file'; } |
unless ($fname) { return 'error: no uploaded file'; } |
chop($ENV{'form.'.$formname}); |
chop($ENV{'form.'.$formname}); |
my $url = ''; |
|
# Create the directory if not present |
# Create the directory if not present |
my $docuname=''; |
my $docuname=''; |
my $docudom=''; |
my $docudom=''; |
my $docuhome=''; |
my $docuhome=''; |
|
$fname="$subdir/$fname"; |
if ($coursedoc) { |
if ($coursedoc) { |
$docuname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'}; |
$docuname=$ENV{'course.'.$ENV{'request.course.id'}.'.num'}; |
$docudom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; |
$docudom=$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}; |
$docuhome=$ENV{'course.'.$ENV{'request.course.id'}.'.home'}; |
$docuhome=$ENV{'course.'.$ENV{'request.course.id'}.'.home'}; |
if ($ENV{'form.folder'} =~ m/^default/) { |
if ($ENV{'form.folder'} =~ m/^default/) { |
$url = &finishuserfileupload($docuname,$docudom,$docuhome,$formname,$fname); |
return &finishuserfileupload($docuname,$docudom,$docuhome,$formname,$fname); |
} else { |
} else { |
$fname=$ENV{'form.folder'}.'/'.$fname; |
$fname=$ENV{'form.folder'}.'/'.$fname; |
$url = &process_coursefile('uploaddoc',$docuname,$docudom,$docuhome,$fname,$formname); |
return &process_coursefile('uploaddoc',$docuname,$docudom,$docuhome,$fname,$formname); |
} |
} |
} else { |
} else { |
$docuname=$ENV{'user.name'}; |
$docuname=$ENV{'user.name'}; |
$docudom=$ENV{'user.domain'}; |
$docudom=$ENV{'user.domain'}; |
$docuhome=$ENV{'user.home'}; |
$docuhome=$ENV{'user.home'}; |
|
return &finishuserfileupload($docuname,$docudom,$docuhome,$formname,$fname); |
} |
} |
return |
|
&finishuserfileupload($docuname,$docudom,$docuhome,$formname,$fname); |
|
} |
} |
|
|
sub finishuserfileupload { |
sub finishuserfileupload { |
Line 1337 sub finishuserfileupload {
|
Line 1338 sub finishuserfileupload {
|
} |
} |
} |
} |
|
|
|
sub removeuploadedurl { |
|
my ($url)=@_; |
|
my (undef,undef,$udom,$uname,$fname)=split('/',$url,5); |
|
return &Apache::lonnet::removeuserfile($uname,$udom,$fname); |
|
} |
|
|
|
sub removeuserfile { |
|
my ($docuname,$docudom,$fname)=@_; |
|
my $home=&homeserver($docuname,$docudom); |
|
return &reply("removeuserfile:$docudom/$docuname/$fname",$home); |
|
} |
|
|
# ------------------------------------------------------------------------- Log |
# ------------------------------------------------------------------------- Log |
|
|
sub log { |
sub log { |
Line 2681 sub allowed {
|
Line 2694 sub allowed {
|
|
|
# URI is an uploaded document for this course |
# URI is an uploaded document for this course |
|
|
if (($priv eq 'bre') && |
if (($priv eq 'bre') && ($uri=~m|^uploaded/|)) { |
($uri=~/^uploaded\/$ENV{'course.'.$ENV{'request.course.id'}.'.domain'}\/$ENV{'course.'.$ENV{'request.course.id'}.'.num'}/)) { |
my $refuri=$ENV{'httpref.'.$orguri}; |
return 'F'; |
if ($refuri) { |
|
if ($refuri =~ m|^/adm/|) { |
|
$thisallowed='F'; |
|
} |
|
} |
} |
} |
|
|
# Full access at system, domain or course-wide level? Exit. |
# Full access at system, domain or course-wide level? Exit. |
|
|
if ($thisallowed=~/F/) { |
if ($thisallowed=~/F/) { |
Line 3306 sub modify_student_enrollment {
|
Line 3324 sub modify_student_enrollment {
|
} |
} |
my $fullname = &Apache::loncoursedata::ProcessFullName($last,$gene, |
my $fullname = &Apache::loncoursedata::ProcessFullName($last,$gene, |
$first,$middle); |
$first,$middle); |
my $value=&escape($uname.':'.$udom).'='. |
my $reply=cput('classlist', |
&escape(join(':',$end,$start,$uid,$usec,$fullname,$type)); |
{"$uname:$udom" => |
my $reply=critical('put:'.$cdom.':'.$cnum.':classlist:'.$value,$chome); |
join(':',$end,$start,$uid,$usec,$fullname,$type) }, |
|
$cdom,$cnum); |
unless (($reply eq 'ok') || ($reply eq 'delayed')) { |
unless (($reply eq 'ok') || ($reply eq 'delayed')) { |
return 'error: '.$reply; |
return 'error: '.$reply; |
} |
} |
Line 3936 sub metadata {
|
Line 3955 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 '') || (($uri =~ m|^/*adm/|) && ($uri !~ m|^adm/includes|)) || |
if (($uri eq '') || (($uri =~ m|^/*adm/|) && ($uri !~ m|^adm/includes|)) || |
($uri =~ m|/$|) || ($uri =~ m|/.meta$|) || ($uri =~ /^~/) || |
($uri =~ m|/$|) || ($uri =~ m|/.meta$|) || ($uri =~ /^~/) || |
($uri =~ m|home/[^/]+/public_html/|) || ($uri =~ m|^uploaded/|)) { |
($uri =~ m|home/[^/]+/public_html/|)) { |
return undef; |
return undef; |
} |
} |
my $filename=$uri; |
my $filename=$uri; |
Line 3965 sub metadata {
|
Line 3984 sub metadata {
|
} |
} |
my %metathesekeys=(); |
my %metathesekeys=(); |
unless ($filename=~/\.meta$/) { $filename.='.meta'; } |
unless ($filename=~/\.meta$/) { $filename.='.meta'; } |
my $metastring=&getfile(&filelocation('',&clutter($filename))); |
my $metastring; |
|
if ($uri !~ m|^uploaded/|) { |
|
$metastring=&getfile(&filelocation('',&clutter($filename))); |
|
} |
my $parser=HTML::LCParser->new(\$metastring); |
my $parser=HTML::LCParser->new(\$metastring); |
my $token; |
my $token; |
undef %metathesekeys; |
undef %metathesekeys; |
Line 4081 sub metadata {
|
Line 4103 sub metadata {
|
#&logthis("extsion1 $extension $key !!"); |
#&logthis("extsion1 $extension $key !!"); |
#no specific packages #how's our extension |
#no specific packages #how's our extension |
if ($key!~/^extension_\Q$extension\E&/) { next; } |
if ($key!~/^extension_\Q$extension\E&/) { next; } |
&metadata_create_pacakge_def($uri,$key,'extension_'.$extension, |
&metadata_create_package_def($uri,$key,'extension_'.$extension, |
\%metathesekeys); |
\%metathesekeys); |
} |
} |
if (!exists($metacache{$uri}->{':packages'})) { |
if (!exists($metacache{$uri}->{':packages'})) { |
foreach my $key (sort(keys(%packagetab))) { |
foreach my $key (sort(keys(%packagetab))) { |
#no specific packages well let's get default then |
#no specific packages well let's get default then |
if ($key!~/^default&/) { next; } |
if ($key!~/^default&/) { next; } |
&metadata_create_pacakge_def($uri,$key,'default', |
&metadata_create_package_def($uri,$key,'default', |
\%metathesekeys); |
\%metathesekeys); |
} |
} |
} |
} |
Line 4120 sub metadata {
|
Line 4142 sub metadata {
|
return $metacache{$uri}->{':'.$what}; |
return $metacache{$uri}->{':'.$what}; |
} |
} |
|
|
sub metadata_create_pacakge_def { |
sub metadata_create_package_def { |
my ($uri,$key,$package,$metathesekeys)=@_; |
my ($uri,$key,$package,$metathesekeys)=@_; |
my ($pack,$name,$subp)=split(/\&/,$key); |
my ($pack,$name,$subp)=split(/\&/,$key); |
if ($subp eq 'default') { next; } |
if ($subp eq 'default') { next; } |
Line 4418 sub numval {
|
Line 4440 sub numval {
|
return int($txt); |
return int($txt); |
} |
} |
|
|
|
sub numval2 { |
|
my $txt=shift; |
|
$txt=~tr/A-J/0-9/; |
|
$txt=~tr/a-j/0-9/; |
|
$txt=~tr/K-T/0-9/; |
|
$txt=~tr/k-t/0-9/; |
|
$txt=~tr/U-Z/0-5/; |
|
$txt=~tr/u-z/0-5/; |
|
$txt=~s/\D//g; |
|
my @txts=split(/(\d\d\d\d\d\d\d\d\d)/,$txt); |
|
my $total; |
|
foreach my $val (@txts) { $total+=$val; } |
|
return int($total); |
|
} |
|
|
sub latest_rnd_algorithm_id { |
sub latest_rnd_algorithm_id { |
return '64bit2'; |
return '64bit2'; |
} |
} |
|
|
|
sub getCODE { |
|
if (defined($ENV{'form.CODE'})) { return $ENV{'form.CODE'}; } |
|
if (defined($Apache::lonhomework::parsing_a_problem) && |
|
defined($Apache::lonhomework::history{'resource.CODE'})) { |
|
return $Apache::lonhomework::history{'resource.CODE'}; |
|
} |
|
return undef; |
|
} |
|
|
sub rndseed { |
sub rndseed { |
my ($symb,$courseid,$domain,$username)=@_; |
my ($symb,$courseid,$domain,$username)=@_; |
|
|
Line 4433 sub rndseed {
|
Line 4479 sub rndseed {
|
if (!$domain) { $domain=$wdomain; } |
if (!$domain) { $domain=$wdomain; } |
if (!$username) { $username=$wusername } |
if (!$username) { $username=$wusername } |
my $which=$ENV{"course.$courseid.rndseed"}; |
my $which=$ENV{"course.$courseid.rndseed"}; |
my $CODE=$ENV{'scantron.CODE'}; |
if (defined(&getCODE())) { |
if (defined($CODE)) { |
return &rndseed_CODE_64bit($symb,$courseid,$domain,$username); |
&rndseed_CODE_64bit($symb,$courseid,$domain,$username); |
|
} elsif ($which eq '64bit2') { |
} elsif ($which eq '64bit2') { |
return &rndseed_64bit2($symb,$courseid,$domain,$username); |
return &rndseed_64bit2($symb,$courseid,$domain,$username); |
} elsif ($which eq '64bit') { |
} elsif ($which eq '64bit') { |
Line 4508 sub rndseed_CODE_64bit {
|
Line 4553 sub rndseed_CODE_64bit {
|
{ |
{ |
use integer; |
use integer; |
my $symbchck=unpack("%32S*",$symb.' ') << 16; |
my $symbchck=unpack("%32S*",$symb.' ') << 16; |
my $symbseed=numval($symb); |
my $symbseed=numval2($symb); |
my $CODEseed=numval($ENV{'scantron.CODE'}) << 16; |
my $CODEchck=unpack("%32S*",&getCODE().' ') << 16; |
|
my $CODEseed=numval(&getCODE()); |
my $courseseed=unpack("%32S*",$courseid.' '); |
my $courseseed=unpack("%32S*",$courseid.' '); |
my $num1=$symbseed+$CODEseed; |
my $num1=$symbseed+$CODEchck; |
my $num2=$courseseed+$symbchck; |
my $num2=$CODEseed+$courseseed+$symbchck; |
#&Apache::lonxml::debug("$symbseed:$CODEseed|$courseseed:$symbchck"); |
#&Apache::lonxml::debug("$symbseed:$CODEchck|$CODEseed:$courseseed:$symbchck"); |
#&Apache::lonxml::debug("rndseed :$num1:$num2:$symb"); |
#&Apache::lonxml::debug("rndseed :$num1:$num2:$symb"); |
return "$num1,$num2"; |
return "$num1,$num2"; |
} |
} |
Line 4674 sub getuploaded {
|
Line 4720 sub getuploaded {
|
return 'failed'; |
return 'failed'; |
} |
} |
if ($reqtype eq 'HEAD') { |
if ($reqtype eq 'HEAD') { |
$$info = &Date::Parse::str2time( $response->header('Last-modified') ); |
$$info = &HTTP::Date::str2time( $response->header('Last-modified') ); |
} elsif ($reqtype eq 'GET') { |
} elsif ($reqtype eq 'GET') { |
$$info = $response->content; |
$$info = $response->content; |
} |
} |
Line 4831 BEGIN {
|
Line 4877 BEGIN {
|
open(my $config,"</etc/httpd/conf/loncapa.conf"); |
open(my $config,"</etc/httpd/conf/loncapa.conf"); |
|
|
while (my $configline=<$config>) { |
while (my $configline=<$config>) { |
if ($configline =~ /^[^\#]*PerlSetVar/) { |
if ($configline=~/\S/ && $configline =~ /^[^\#]*PerlSetVar/) { |
my ($dummy,$varname,$varvalue)=split(/\s+/,$configline); |
my ($dummy,$varname,$varvalue)=split(/\s+/,$configline); |
chomp($varvalue); |
chomp($varvalue); |
$perlvar{$varname}=$varvalue; |
$perlvar{$varname}=$varvalue; |