version 1.788, 2006/10/04 19:48:32
|
version 1.793, 2006/10/16 19:39:57
|
Line 52 use Storable qw(lock_store lock_nstore l
|
Line 52 use Storable qw(lock_store lock_nstore l
|
use Time::HiRes qw( 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 lib '/home/httpd/lib/perl'; |
use lib '/home/httpd/lib/perl'; |
use LONCAPA; |
use LONCAPA; |
use LONCAPA::Configuration; |
use LONCAPA::Configuration; |
Line 412 sub delenv {
|
Line 413 sub delenv {
|
return 'ok'; |
return 'ok'; |
} |
} |
|
|
|
=pod |
|
|
|
=item * get_env_multiple($name) |
|
|
|
gets $name from the %env hash, it seemlessly handles the cases where multiple |
|
values may be defined and end up as an array ref. |
|
|
|
returns an array of values |
|
|
|
=cut |
|
|
|
sub get_env_multiple { |
|
my ($name) = @_; |
|
my @values; |
|
if (defined($env{$name})) { |
|
# exists is it an array |
|
if (ref($env{$name})) { |
|
@values=@{ $env{$name} }; |
|
} else { |
|
$values[0]=$env{$name}; |
|
} |
|
} |
|
return(@values); |
|
} |
|
|
# ------------------------------------------ Find out current server userload |
# ------------------------------------------ Find out current server userload |
# there is a copy in lond |
# there is a copy in lond |
sub userload { |
sub userload { |
Line 1184 sub absolute_url {
|
Line 1210 sub absolute_url {
|
return $protocol.$host_name; |
return $protocol.$host_name; |
} |
} |
|
|
sub absolute_url { |
|
my ($host_name) = @_; |
|
my $protocol = ($ENV{'SERVER_PORT'} == 443?'https://':'http://'); |
|
if ($host_name eq '') { |
|
$host_name = $ENV{'SERVER_NAME'}; |
|
} |
|
return $protocol.$host_name; |
|
} |
|
|
|
sub ssi { |
sub ssi { |
|
|
my ($fn,%form)=@_; |
my ($fn,%form)=@_; |
Line 1962 sub courseidput {
|
Line 1979 sub courseidput {
|
} |
} |
|
|
sub courseiddump { |
sub courseiddump { |
my ($domfilter,$descfilter,$sincefilter,$instcodefilter,$ownerfilter,$coursefilter,$hostidflag,$hostidref,$typefilter)=@_; |
my ($domfilter,$descfilter,$sincefilter,$instcodefilter,$ownerfilter,$coursefilter,$hostidflag,$hostidref,$typefilter,$regexp_ok)=@_; |
my %returnhash=(); |
my %returnhash=(); |
unless ($domfilter) { $domfilter=''; } |
unless ($domfilter) { $domfilter=''; } |
foreach my $tryserver (keys %libserv) { |
foreach my $tryserver (keys %libserv) { |
Line 1971 sub courseiddump {
|
Line 1988 sub courseiddump {
|
foreach ( |
foreach ( |
split(/\&/,&reply('courseiddump:'.$hostdom{$tryserver}.':'. |
split(/\&/,&reply('courseiddump:'.$hostdom{$tryserver}.':'. |
$sincefilter.':'.&escape($descfilter).':'. |
$sincefilter.':'.&escape($descfilter).':'. |
&escape($instcodefilter).':'.&escape($ownerfilter).':'.&escape($coursefilter).':'.&escape($typefilter), |
&escape($instcodefilter).':'.&escape($ownerfilter).':'.&escape($coursefilter).':'.&escape($typefilter).':'.&escape($regexp_ok), |
$tryserver))) { |
$tryserver))) { |
my ($key,$value)=split(/\=/,$_); |
my ($key,$value)=split(/\=/,$_); |
if (($key) && ($value)) { |
if (($key) && ($value)) { |
Line 2044 sub get_domain_roles {
|
Line 2061 sub get_domain_roles {
|
|
|
sub get_first_access { |
sub get_first_access { |
my ($type,$argsymb)=@_; |
my ($type,$argsymb)=@_; |
my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::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); |
if ($type eq 'map') { |
if ($type eq 'map') { |
Line 2058 sub get_first_access {
|
Line 2075 sub get_first_access {
|
|
|
sub set_first_access { |
sub set_first_access { |
my ($type)=@_; |
my ($type)=@_; |
my ($symb,$courseid,$udom,$uname)=&Apache::lonxml::whichuser(); |
my ($symb,$courseid,$udom,$uname)=&whichuser(); |
my ($map,$id,$res)=&decode_symb($symb); |
my ($map,$id,$res)=&decode_symb($symb); |
if ($type eq 'map') { |
if ($type eq 'map') { |
$res=&symbread($map); |
$res=&symbread($map); |
Line 4200 sub auto_photoupdate {
|
Line 4217 sub auto_photoupdate {
|
} |
} |
|
|
sub auto_instcode_format { |
sub auto_instcode_format { |
my ($caller,$codedom,$instcodes,$codes,$codetitles,$cat_titles,$cat_order) = @_; |
my ($caller,$codedom,$instcodes,$codes,$codetitles,$cat_titles, |
|
$cat_order) = @_; |
my $courses = ''; |
my $courses = ''; |
my @homeservers; |
my @homeservers; |
if ($caller eq 'global') { |
if ($caller eq 'global') { |
foreach my $tryserver (keys %libserv) { |
foreach my $tryserver (keys(%libserv)) { |
if ($hostdom{$tryserver} eq $codedom) { |
if ($hostdom{$tryserver} eq $codedom) { |
if (!grep/^\Q$tryserver\E$/,@homeservers) { |
if (!grep(/^\Q$tryserver\E$/,@homeservers)) { |
push(@homeservers,$tryserver); |
push(@homeservers,$tryserver); |
} |
} |
} |
} |
Line 4214 sub auto_instcode_format {
|
Line 4232 sub auto_instcode_format {
|
} else { |
} else { |
push(@homeservers,&homeserver($caller,$codedom)); |
push(@homeservers,&homeserver($caller,$codedom)); |
} |
} |
foreach (keys %{$instcodes}) { |
foreach my $code (keys(%{$instcodes})) { |
$courses .= &escape($_).'='.&escape($$instcodes{$_}).'&'; |
$courses .= &escape($code).'='.&escape($$instcodes{$code}).'&'; |
} |
} |
chop($courses); |
chop($courses); |
my $ok_response = 0; |
my $ok_response = 0; |
Line 4225 sub auto_instcode_format {
|
Line 4243 sub auto_instcode_format {
|
$response=&reply('autoinstcodeformat:'.$codedom.':'.$courses,$server); |
$response=&reply('autoinstcodeformat:'.$codedom.':'.$courses,$server); |
if ($response !~ /(con_lost|error|no_such_host|refused)/) { |
if ($response !~ /(con_lost|error|no_such_host|refused)/) { |
my ($codes_str,$codetitles_str,$cat_titles_str,$cat_order_str) = |
my ($codes_str,$codetitles_str,$cat_titles_str,$cat_order_str) = |
split/:/,$response; |
split/:/,$response; |
%{$codes} = (%{$codes},&str2hash($codes_str)); |
%{$codes} = (%{$codes},&str2hash($codes_str)); |
push(@{$codetitles},&str2array($codetitles_str)); |
push(@{$codetitles},&str2array($codetitles_str)); |
%{$cat_titles} = (%{$cat_titles},&str2hash($cat_titles_str)); |
%{$cat_titles} = (%{$cat_titles},&str2hash($cat_titles_str)); |
Line 4240 sub auto_instcode_format {
|
Line 4258 sub auto_instcode_format {
|
} |
} |
} |
} |
|
|
|
sub auto_instcode_defaults { |
|
my ($domain,$returnhash,$code_order) = @_; |
|
my @homeservers; |
|
foreach my $tryserver (keys(%libserv)) { |
|
if ($hostdom{$tryserver} eq $domain) { |
|
if (!grep(/^\Q$tryserver\E$/,@homeservers)) { |
|
push(@homeservers,$tryserver); |
|
} |
|
} |
|
} |
|
my $ok_response = 0; |
|
my $response; |
|
while (@homeservers > 0 && $ok_response == 0) { |
|
my $server = shift(@homeservers); |
|
$response=&reply('autoinstcodedefaults:'.$domain,$server); |
|
if ($response !~ /(con_lost|error|no_such_host|refused)/) { |
|
foreach my $pair (split(/\&/,$response)) { |
|
my ($name,$value)=split(/\=/,$pair); |
|
if ($name eq 'code_order') { |
|
$code_order = [split(/\&/,&unescape($value))]; |
|
} else { |
|
$$returnhash{&unescape($name)}=&unescape($value); |
|
} |
|
} |
|
} |
|
$ok_response = 1; |
|
} |
|
if ($ok_response) { |
|
return 'ok'; |
|
} else { |
|
return $response; |
|
} |
|
} |
|
|
sub auto_validate_class_sec { |
sub auto_validate_class_sec { |
my ($cdom,$cnum,$owner,$inst_class) = @_; |
my ($cdom,$cnum,$owner,$inst_class) = @_; |
my $homeserver = &homeserver($cnum,$cdom); |
my $homeserver = &homeserver($cnum,$cdom); |
Line 5519 sub EXT {
|
Line 5571 sub EXT {
|
$symbparm=&get_symb_from_alias($symbparm); |
$symbparm=&get_symb_from_alias($symbparm); |
} |
} |
if (!($uname && $udom)) { |
if (!($uname && $udom)) { |
(my $cursymb,$courseid,$udom,$uname,$publicuser)= |
(my $cursymb,$courseid,$udom,$uname,$publicuser)= &whichuser($symbparm); |
&Apache::lonxml::whichuser($symbparm); |
|
if (!$symbparm) { $symbparm=$cursymb; } |
if (!$symbparm) { $symbparm=$cursymb; } |
} else { |
} else { |
$courseid=$env{'request.course.id'}; |
$courseid=$env{'request.course.id'}; |
Line 6174 sub gettitle {
|
Line 6225 sub gettitle {
|
sub get_slot { |
sub get_slot { |
my ($which,$cnum,$cdom)=@_; |
my ($which,$cnum,$cdom)=@_; |
if (!$cnum || !$cdom) { |
if (!$cnum || !$cdom) { |
(undef,my $courseid)=&Apache::lonxml::whichuser(); |
(undef,my $courseid)=&whichuser(); |
$cdom=$env{'course.'.$courseid.'.domain'}; |
$cdom=$env{'course.'.$courseid.'.domain'}; |
$cnum=$env{'course.'.$courseid.'.num'}; |
$cnum=$env{'course.'.$courseid.'.num'}; |
} |
} |
Line 6505 sub latest_rnd_algorithm_id {
|
Line 6556 sub latest_rnd_algorithm_id {
|
|
|
sub get_rand_alg { |
sub get_rand_alg { |
my ($courseid)=@_; |
my ($courseid)=@_; |
if (!$courseid) { $courseid=(&Apache::lonxml::whichuser())[1]; } |
if (!$courseid) { $courseid=(&whichuser())[1]; } |
if ($courseid) { |
if ($courseid) { |
return $env{"course.$courseid.rndseed"}; |
return $env{"course.$courseid.rndseed"}; |
} |
} |
Line 6531 sub getCODE {
|
Line 6582 sub getCODE {
|
sub rndseed { |
sub rndseed { |
my ($symb,$courseid,$domain,$username)=@_; |
my ($symb,$courseid,$domain,$username)=@_; |
|
|
my ($wsymb,$wcourseid,$wdomain,$wusername)=&Apache::lonxml::whichuser(); |
my ($wsymb,$wcourseid,$wdomain,$wusername)=&whichuser(); |
if (!$symb) { |
if (!$symb) { |
unless ($symb=$wsymb) { return time; } |
unless ($symb=$wsymb) { return time; } |
} |
} |
Line 6572 sub rndseed_32bit {
|
Line 6623 sub rndseed_32bit {
|
my $domainseed=unpack("%32C*",$domain) << 7; |
my $domainseed=unpack("%32C*",$domain) << 7; |
my $courseseed=unpack("%32C*",$courseid); |
my $courseseed=unpack("%32C*",$courseid); |
my $num=$symbseed+$nameseed+$domainseed+$courseseed+$namechck+$symbchck; |
my $num=$symbseed+$nameseed+$domainseed+$courseseed+$namechck+$symbchck; |
#&Apache::lonxml::debug("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck"); |
#&logthis("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck"); |
#&Apache::lonxml::debug("rndseed :$num:$symb"); |
#&logthis("rndseed :$num:$symb"); |
if ($_64bit) { $num=(($num<<32)>>32); } |
if ($_64bit) { $num=(($num<<32)>>32); } |
return $num; |
return $num; |
} |
} |
Line 6593 sub rndseed_64bit {
|
Line 6644 sub rndseed_64bit {
|
|
|
my $num1=$symbchck+$symbseed+$namechck; |
my $num1=$symbchck+$symbseed+$namechck; |
my $num2=$nameseed+$domainseed+$courseseed; |
my $num2=$nameseed+$domainseed+$courseseed; |
#&Apache::lonxml::debug("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck"); |
#&logthis("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck"); |
#&Apache::lonxml::debug("rndseed :$num:$symb"); |
#&logthis("rndseed :$num:$symb"); |
if ($_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
if ($_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
if ($_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
if ($_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
return "$num1,$num2"; |
return "$num1,$num2"; |
Line 6617 sub rndseed_64bit2 {
|
Line 6668 sub rndseed_64bit2 {
|
|
|
my $num1=$symbchck+$symbseed+$namechck; |
my $num1=$symbchck+$symbseed+$namechck; |
my $num2=$nameseed+$domainseed+$courseseed; |
my $num2=$nameseed+$domainseed+$courseseed; |
#&Apache::lonxml::debug("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck"); |
#&logthis("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck"); |
#&Apache::lonxml::debug("rndseed :$num:$symb"); |
#&logthis("rndseed :$num:$symb"); |
return "$num1,$num2"; |
return "$num1,$num2"; |
} |
} |
} |
} |
Line 6639 sub rndseed_64bit3 {
|
Line 6690 sub rndseed_64bit3 {
|
|
|
my $num1=$symbchck+$symbseed+$namechck; |
my $num1=$symbchck+$symbseed+$namechck; |
my $num2=$nameseed+$domainseed+$courseseed; |
my $num2=$nameseed+$domainseed+$courseseed; |
#&Apache::lonxml::debug("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck"); |
#&logthis("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck"); |
#&Apache::lonxml::debug("rndseed :$num1:$num2:$_64bit"); |
#&logthis("rndseed :$num1:$num2:$_64bit"); |
if ($_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
if ($_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
|
|
return "$num1:$num2"; |
return "$num1:$num2"; |
Line 6663 sub rndseed_64bit4 {
|
Line 6714 sub rndseed_64bit4 {
|
|
|
my $num1=$symbchck+$symbseed+$namechck; |
my $num1=$symbchck+$symbseed+$namechck; |
my $num2=$nameseed+$domainseed+$courseseed; |
my $num2=$nameseed+$domainseed+$courseseed; |
#&Apache::lonxml::debug("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck"); |
#&logthis("$symbseed:$nameseed;$domainseed|$courseseed;$namechck:$symbchck"); |
#&Apache::lonxml::debug("rndseed :$num1:$num2:$_64bit"); |
#&logthis("rndseed :$num1:$num2:$_64bit"); |
if ($_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
if ($_64bit) { $num1=(($num1<<32)>>32); $num2=(($num2<<32)>>32); } |
|
|
return "$num1:$num2"; |
return "$num1:$num2"; |
Line 6688 sub rndseed_CODE_64bit {
|
Line 6739 sub rndseed_CODE_64bit {
|
my $courseseed=unpack("%32S*",$courseid.' '); |
my $courseseed=unpack("%32S*",$courseid.' '); |
my $num1=$symbseed+$CODEchck; |
my $num1=$symbseed+$CODEchck; |
my $num2=$CODEseed+$courseseed+$symbchck; |
my $num2=$CODEseed+$courseseed+$symbchck; |
#&Apache::lonxml::debug("$symbseed:$CODEchck|$CODEseed:$courseseed:$symbchck"); |
#&logthis("$symbseed:$CODEchck|$CODEseed:$courseseed:$symbchck"); |
#&Apache::lonxml::debug("rndseed :$num1:$num2:$symb"); |
#&logthis("rndseed :$num1:$num2:$symb"); |
if ($_64bit) { $num1=(($num1<<32)>>32); } |
if ($_64bit) { $num1=(($num1<<32)>>32); } |
if ($_64bit) { $num2=(($num2<<32)>>32); } |
if ($_64bit) { $num2=(($num2<<32)>>32); } |
return "$num1:$num2"; |
return "$num1:$num2"; |
Line 6707 sub rndseed_CODE_64bit4 {
|
Line 6758 sub rndseed_CODE_64bit4 {
|
my $courseseed=unpack("%32S*",$courseid.' '); |
my $courseseed=unpack("%32S*",$courseid.' '); |
my $num1=$symbseed+$CODEchck; |
my $num1=$symbseed+$CODEchck; |
my $num2=$CODEseed+$courseseed+$symbchck; |
my $num2=$CODEseed+$courseseed+$symbchck; |
#&Apache::lonxml::debug("$symbseed:$CODEchck|$CODEseed:$courseseed:$symbchck"); |
#&logthis("$symbseed:$CODEchck|$CODEseed:$courseseed:$symbchck"); |
#&Apache::lonxml::debug("rndseed :$num1:$num2:$symb"); |
#&logthis("rndseed :$num1:$num2:$symb"); |
if ($_64bit) { $num1=(($num1<<32)>>32); } |
if ($_64bit) { $num1=(($num1<<32)>>32); } |
if ($_64bit) { $num2=(($num2<<32)>>32); } |
if ($_64bit) { $num2=(($num2<<32)>>32); } |
return "$num1:$num2"; |
return "$num1:$num2"; |
Line 6769 sub ireceipt {
|
Line 6820 sub ireceipt {
|
my $return =&recprefix($fucourseid).'-'; |
my $return =&recprefix($fucourseid).'-'; |
if ($env{"course.$fucourseid.receiptalg"} eq 'receipt2' || |
if ($env{"course.$fucourseid.receiptalg"} eq 'receipt2' || |
$env{'request.state'} eq 'construct') { |
$env{'request.state'} eq 'construct') { |
&Apache::lonxml::debug("doing receipt2 using parts $cpart, uname $cuname and udom $cudom gets ".($cpart%$cuname). |
#&logthis("doing receipt2 using parts $cpart, uname $cuname and udom $cudom gets ".($cpart%$cuname)." and ".($cpart%$cudom)); |
" and ".($cpart%$cudom)); |
|
|
|
$return.= ($cunique%$cuname+ |
$return.= ($cunique%$cuname+ |
$cunique%$cudom+ |
$cunique%$cudom+ |
Line 6793 sub ireceipt {
|
Line 6843 sub ireceipt {
|
|
|
sub receipt { |
sub receipt { |
my ($part)=@_; |
my ($part)=@_; |
my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); |
my ($symb,$courseid,$domain,$name) = &whichuser(); |
return &ireceipt($name,$domain,$courseid,$symb,$part); |
return &ireceipt($name,$domain,$courseid,$symb,$part); |
} |
} |
|
|
|
sub whichuser { |
|
my ($passedsymb)=@_; |
|
my ($symb,$courseid,$domain,$name,$publicuser); |
|
if (defined($env{'form.grade_symb'})) { |
|
my ($tmp_courseid)=&get_env_multiple('form.grade_courseid'); |
|
my $allowed=&allowed('vgr',$tmp_courseid); |
|
if (!$allowed && |
|
exists($env{'request.course.sec'}) && |
|
$env{'request.course.sec'} !~ /^\s*$/) { |
|
$allowed=&allowed('vgr',$tmp_courseid. |
|
'/'.$env{'request.course.sec'}); |
|
} |
|
if ($allowed) { |
|
($symb)=&get_env_multiple('form.grade_symb'); |
|
$courseid=$tmp_courseid; |
|
($domain)=&get_env_multiple('form.grade_domain'); |
|
($name)=&get_env_multiple('form.grade_username'); |
|
return ($symb,$courseid,$domain,$name,$publicuser); |
|
} |
|
} |
|
if (!$passedsymb) { |
|
$symb=&symbread(); |
|
} else { |
|
$symb=$passedsymb; |
|
} |
|
$courseid=$env{'request.course.id'}; |
|
$domain=$env{'user.domain'}; |
|
$name=$env{'user.name'}; |
|
if ($name eq 'public' && $domain eq 'public') { |
|
if (!defined($env{'form.username'})) { |
|
$env{'form.username'}.=time.rand(10000000); |
|
} |
|
$name.=$env{'form.username'}; |
|
} |
|
return ($symb,$courseid,$domain,$name,$publicuser); |
|
|
|
} |
|
|
# ------------------------------------------------------------ Serves up a file |
# ------------------------------------------------------------ Serves up a file |
# returns either the contents of the file or |
# returns either the contents of the file or |
# -1 if the file doesn't exist |
# -1 if the file doesn't exist |