version 1.69, 2003/12/15 15:26:26
|
version 1.79, 2004/10/26 15:10:42
|
Line 41 use Apache::lonmsg;
|
Line 41 use Apache::lonmsg;
|
use Safe; |
use Safe; |
use Safe::Hole; |
use Safe::Hole; |
use Opcode; |
use Opcode; |
|
use Apache::lonenc; |
|
|
# ---------------------------------------------------- Globals for this package |
# ---------------------------------------------------- Globals for this package |
|
|
Line 52 my $errtext; # variable with all errors
|
Line 53 my $errtext; # variable with all errors
|
my $retfurl; # variable with the very first URL in the course |
my $retfurl; # variable with the very first URL in the course |
my %randompick; # randomly picked resources |
my %randompick; # randomly picked resources |
my %randompickseed; # optional seed for randomly picking resources |
my %randompickseed; # optional seed for randomly picking resources |
|
my %encurl; # URLs in this folder are supposed to be encrypted |
|
my %hiddenurl; # this URL (or complete folder) is supposed to be hidden |
|
|
# ----------------------------------- Remove version from URL and store in hash |
# ----------------------------------- Remove version from URL and store in hash |
|
|
Line 157 sub loadmap {
|
Line 160 sub loadmap {
|
if ($token->[2]->{'external'} eq 'true') { # external |
if ($token->[2]->{'external'} eq 'true') { # external |
$turi=~s/^http\:\/\//\/adm\/wrapper\/ext\//; |
$turi=~s/^http\:\/\//\/adm\/wrapper\/ext\//; |
} elsif ($turi=~/^\/*uploaded\//) { # uploaded |
} elsif ($turi=~/^\/*uploaded\//) { # uploaded |
if (($embstyle eq 'img') || ($embstyle eq 'emb') |
if (($embstyle eq 'img') || ($embstyle eq 'emb')) { |
|| ($embstyle eq 'ssi')) { |
|
$turi='/adm/wrapper'.$turi; |
$turi='/adm/wrapper'.$turi; |
} elsif ($turi!~/\.(sequence|page)$/) { |
} elsif ($embstyle eq 'ssi') { |
|
#do nothing with these |
|
} elsif ($turi!~/\.(sequence|page)$/) { |
$turi='/adm/coursedocs/showdoc'.$turi; |
$turi='/adm/coursedocs/showdoc'.$turi; |
} |
} |
} elsif ($turi) { # normal non-empty internal resource |
} elsif ($turi=~/\S/) { # normal non-empty internal resource |
my $mapdir=$uri; |
my $mapdir=$uri; |
$mapdir=~s/[^\/]+$//; |
$mapdir=~s/[^\/]+$//; |
$turi=&Apache::lonnet::hreflocation($mapdir,$turi); |
$turi=&Apache::lonnet::hreflocation($mapdir,$turi); |
Line 172 sub loadmap {
|
Line 176 sub loadmap {
|
} |
} |
} |
} |
} |
} |
|
# Store reverse lookup, remove query string |
if (defined($hash{'ids_'.$turi})) { |
my $idsuri=$turi; |
$hash{'ids_'.$turi}.=','.$rid; |
$idsuri=~s/\?.+$//; |
|
if (defined($hash{'ids_'.$idsuri})) { |
|
$hash{'ids_'.$idsuri}.=','.$rid; |
} else { |
} else { |
$hash{'ids_'.$turi}=''.$rid; |
$hash{'ids_'.$idsuri}=''.$rid; |
} |
} |
|
|
if |
if |
Line 272 sub loadmap {
|
Line 278 sub loadmap {
|
} else { |
} else { |
$hash{'param_'.$referid}=''.$newparam; |
$hash{'param_'.$referid}=''.$newparam; |
} |
} |
if ($token->[2]->{'name'} eq 'parameter_mapalias') { |
if ($token->[2]->{'name'}=~/^parameter_(0_)*mapalias$/) { |
$hash{'mapalias_'.$token->[2]->{'value'}}=$referid; |
$hash{'mapalias_'.$token->[2]->{'value'}}=$referid; |
} |
} |
if ($token->[2]->{'name'} eq 'parameter_randompick') { |
if ($token->[2]->{'name'}=~/^parameter_(0_)*randompick$/) { |
$randompick{$referid}=$token->[2]->{'value'}; |
$randompick{$referid}=$token->[2]->{'value'}; |
} |
} |
if ($token->[2]->{'name'} eq 'parameter_randompickseed') { |
if ($token->[2]->{'name'}=~/^parameter_(0_)*randompickseed$/) { |
$randompick{$referid}=$token->[2]->{'value'}; |
$randompick{$referid}=$token->[2]->{'value'}; |
} |
} |
|
if ($token->[2]->{'name'}=~/^parameter_(0_)*encrypturl$/) { |
|
if ($token->[2]->{'value'}=~/^yes$/i) { |
|
$encurl{$referid}=1; |
|
} |
|
} |
|
if ($token->[2]->{'name'}=~/^parameter_(0_)*hiddenresource$/) { |
|
if ($token->[2]->{'value'}=~/^yes$/i) { |
|
$hiddenurl{$referid}=1; |
|
} |
|
} |
} |
} |
|
|
} |
} |
Line 315 sub simplify {
|
Line 331 sub simplify {
|
# -------------------------------------------------------- Build condition hash |
# -------------------------------------------------------- Build condition hash |
|
|
sub traceroute { |
sub traceroute { |
my ($sofar,$rid,$beenhere)=@_; |
my ($sofar,$rid,$beenhere,$encflag,$hdnflag)=@_; |
$sofar=simplify($sofar); |
$sofar=simplify($sofar); |
unless ($beenhere=~/\&$rid\&/) { |
unless ($beenhere=~/\&$rid\&/) { |
$beenhere.=$rid.'&'; |
$beenhere.=$rid.'&'; |
|
my ($mapid,$resid)=split(/\./,$rid); |
|
my $symb=&Apache::lonnet::encode_symb($hash{'map_id_'.$mapid},$resid,$hash{'src_'.$rid}); |
|
my $encrypt=&Apache::lonnet::EXT('resource.0.hiddenresource',$symb); |
|
if ($hdnflag || lc($encrypt) eq 'yes') { $hiddenurl{$rid}=1; } |
|
my $encrypt=&Apache::lonnet::EXT('resource.0.encrypturl',$symb); |
|
if ($encflag || lc($encrypt) eq 'yes') { $encurl{$rid}=1; } |
if (($retfurl eq '') && ($hash{'src_'.$rid}) |
if (($retfurl eq '') && ($hash{'src_'.$rid}) |
&& ($hash{'src_'.$rid}!~/\.sequence$/)) { |
&& ($hash{'src_'.$rid}!~/\.sequence$/)) { |
my ($mapid,$resid)=split(/\./,$rid); |
$retfurl=$hash{'src_'.$rid}.(($hash{'src_'.$rid}=~/\?/)?'&':'?'). |
$retfurl=$hash{'src_'.$rid}. |
'symb='.$symb; |
(($hash{'src_'.$rid}=~/\?/)?'&':'?').'symb='. |
|
&Apache::lonnet::symbclean( |
|
&Apache::lonnet::declutter($hash{'map_id_'.$mapid}). |
|
'___'.$resid.'___'. |
|
&Apache::lonnet::declutter($hash{'src_'.$rid})); |
|
} |
} |
if (defined($hash{'conditions_'.$rid})) { |
if (defined($hash{'conditions_'.$rid})) { |
$hash{'conditions_'.$rid}=simplify( |
$hash{'conditions_'.$rid}=simplify( |
Line 337 sub traceroute {
|
Line 354 sub traceroute {
|
} |
} |
if (defined($hash{'is_map_'.$rid})) { |
if (defined($hash{'is_map_'.$rid})) { |
if (defined($hash{'map_start_'.$hash{'src_'.$rid}})) { |
if (defined($hash{'map_start_'.$hash{'src_'.$rid}})) { |
&traceroute($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},'&'); |
&traceroute($sofar,$hash{'map_start_'.$hash{'src_'.$rid}},'&', |
|
$encflag || $encurl{$rid}, |
|
$hdnflag || $hiddenurl{$rid}); |
if (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) { |
if (defined($hash{'map_finish_'.$hash{'src_'.$rid}})) { |
$sofar= |
$sofar= |
$hash{'conditions_'.$hash{'map_finish_'.$hash{'src_'.$rid}}}; |
$hash{'conditions_'.$hash{'map_finish_'.$hash{'src_'.$rid}}}; |
Line 356 sub traceroute {
|
Line 375 sub traceroute {
|
.$hash{'undercond_'.$_}.'. '; |
.$hash{'undercond_'.$_}.'. '; |
} |
} |
} |
} |
&traceroute($further,$hash{'goesto_'.$_},$beenhere); |
&traceroute($further,$hash{'goesto_'.$_},$beenhere,$encflag,$hdnflag); |
} |
} |
} |
} |
} |
} |
Line 425 sub accinit {
|
Line 444 sub accinit {
|
/(\&\Q$urifile\E\:[^\&]*)/) { |
/(\&\Q$urifile\E\:[^\&]*)/) { |
my $replace=$1; |
my $replace=$1; |
my $regexp=$replace; |
my $regexp=$replace; |
$regexp=~s/\|/\\\|/g; |
#$regexp=~s/\|/\\\|/g; |
$acchash{'acc.res.'.$short.'.'.$uripath} |
$acchash{'acc.res.'.$short.'.'.$uripath} |
=~s/$regexp/$replace\|$uricond/; |
=~s/\Q$regexp\E/$replace\|$uricond/; |
} else { |
} else { |
$acchash{'acc.res.'.$short.'.'.$uripath}.= |
$acchash{'acc.res.'.$short.'.'.$uripath}.= |
$urifile.':'.$uricond.'&'; |
$urifile.':'.$uricond.'&'; |
Line 444 sub accinit {
|
Line 463 sub accinit {
|
my $courseuri=$uri; |
my $courseuri=$uri; |
$courseuri=~s/^\/res\///; |
$courseuri=~s/^\/res\///; |
&Apache::lonnet::delenv('(acc\.|httpref\.)'); |
&Apache::lonnet::delenv('(acc\.|httpref\.)'); |
&Apache::lonnet::appenv(%acchash, |
&Apache::lonnet::appenv(%acchash); |
"request.course.id" => $short, |
|
"request.course.fn" => $fn, |
|
"request.course.uri" => $courseuri); |
|
} |
} |
|
|
# ------------------------------------- Selectively delete from randompick maps |
# ---------------- Selectively delete from randompick maps and hidden url parms |
|
|
sub pickrandom { |
sub hiddenurls { |
my $randomoutentry=''; |
my $randomoutentry=''; |
foreach my $rid (keys %randompick) { |
foreach my $rid (keys %randompick) { |
my $rndpick=$randompick{$rid}; |
my $rndpick=$randompick{$rid}; |
Line 494 sub pickrandom {
|
Line 510 sub pickrandom {
|
} |
} |
} |
} |
} |
} |
|
# ------------------------------ take care of explicitly hidden urls or folders |
|
foreach my $rid (keys %hiddenurl) { |
|
$hash{'randomout_'.$rid}=1; |
|
my ($mapid,$resid)=split(/\./,$rid); |
|
$randomoutentry.='&'. |
|
&Apache::lonnet::symbclean( |
|
&Apache::lonnet::declutter($hash{'map_id_'.$mapid}). |
|
'___'.$resid.'___'. |
|
&Apache::lonnet::declutter($hash{'src_'.$rid}) |
|
).'&'; |
|
} |
|
# --------------------------------------- append randomout entry to environment |
if ($randomoutentry) { |
if ($randomoutentry) { |
&Apache::lonnet::appenv('acc.randomout' => $randomoutentry); |
&Apache::lonnet::appenv('acc.randomout' => $randomoutentry); |
} |
} |
Line 519 sub readmap {
|
Line 547 sub readmap {
|
unlink($fn.'.state'); |
unlink($fn.'.state'); |
unlink($fn.'parms.db'); |
unlink($fn.'parms.db'); |
undef %randompick; |
undef %randompick; |
|
undef %hiddenurl; |
|
undef %encurl; |
$retfurl=''; |
$retfurl=''; |
if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT(),0640)) && |
if ((tie(%hash,'GDBM_File',"$fn.db",&GDBM_WRCREAT(),0640)) && |
(tie(%parmhash,'GDBM_File',$fn.'_parms.db',&GDBM_WRCREAT(),0640))) { |
(tie(%parmhash,'GDBM_File',$fn.'_parms.db',&GDBM_WRCREAT(),0640))) { |
Line 534 sub readmap {
|
Line 564 sub readmap {
|
$hash{'is_map_0.0'}=1; |
$hash{'is_map_0.0'}=1; |
loadmap($uri); |
loadmap($uri); |
if (defined($hash{'map_start_'.$uri})) { |
if (defined($hash{'map_start_'.$uri})) { |
|
&Apache::lonnet::appenv("request.course.id" => $short, |
|
"request.course.fn" => $fn, |
|
"request.course.uri" => $uri); |
&traceroute('0',$hash{'map_start_'.$uri},'&'); |
&traceroute('0',$hash{'map_start_'.$uri},'&'); |
&accinit($uri,$short,$fn); |
&accinit($uri,$short,$fn); |
&pickrandom(); |
&hiddenurls(); |
} |
} |
# ------------------------------------------------------- Put versions into src |
# ------------------------------------------------------- Put versions into src |
foreach (keys %hash) { |
foreach (keys %hash) { |
Line 544 sub readmap {
|
Line 577 sub readmap {
|
$hash{$_}=&putinversion($hash{$_}); |
$hash{$_}=&putinversion($hash{$_}); |
} |
} |
} |
} |
|
# ---------------------------------------------------------------- Encrypt URLs |
|
foreach (keys %encurl) { |
|
$hash{'src_'.$_}=&Apache::lonenc::encrypted($hash{'src_'.$_}); |
|
} |
|
# ----------------------------------------------- Close hashes to finally store |
|
# --------------------------------- Routine must pass this point, no early outs |
unless ((untie(%hash)) && (untie(%parmhash))) { |
unless ((untie(%hash)) && (untie(%parmhash))) { |
&Apache::lonnet::logthis("<font color=blue>WARNING: ". |
&Apache::lonnet::logthis("<font color=blue>WARNING: ". |
"Could not untie coursemap $fn for $uri.</font>"); |
"Could not untie coursemap $fn for $uri.</font>"); |
} |
} |
|
# ---------------------------------------------------- Store away initial state |
{ |
{ |
my $cfh; |
my $cfh; |
if ($cfh=Apache::File->new(">$fn.state")) { |
if ($cfh=Apache::File->new(">$fn.state")) { |