--- loncom/lonenc.pm 2004/03/31 05:29:23 1.2 +++ loncom/lonenc.pm 2004/12/17 21:44:19 1.8 @@ -1,7 +1,7 @@ # The LearningOnline Network # URL translation for encrypted filenames # -# $Id: lonenc.pm,v 1.2 2004/03/31 05:29:23 www Exp $ +# $Id: lonenc.pm,v 1.8 2004/12/17 21:44:19 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -44,11 +44,14 @@ sub handler { my $handle=$lonid->value; $handle=~s/\W//g; my $lonidsdir=$r->dir_config('lonIDsDir'); + $ENV{'request.enc'}=1; if ((-e "$lonidsdir/$handle.id") && ($handle ne '')) { # Initialize Environment &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle); # Decrypt URL and redirect - $r->internal_redirect(&unencrypted($r->uri)); + my $redirect=&unencrypted($r->uri); + if ($r->args) { $redirect.='?'.$r->args; } + $r->internal_redirect($redirect); return OK; } } @@ -79,11 +82,13 @@ sub unencrypted { pack("H16",substr($uri,$encidx,16)) ); } + $ENV{'request.enc'}=1; return substr($decuri,0,$cmdlength); } sub encrypted { my $uri=shift; + if ($ENV{'request.role.adv'}) { return($uri); } my $seed=&encryptseed(); unless ($seed) { return $uri; @@ -99,6 +104,22 @@ sub encrypted { return '/enc/'.$cmdlength.'/'.&Apache::lonnet::escape($encuri); } +sub check_encrypt { + my $str=shift; + if ($ENV{'request.enc'}) { return &Apache::lonenc::encrypted($str); } + return $str; +} + +sub check_decrypt { + my ($str)=@_; + if (ref($str)) { + if ($$str=~m|^/enc/|) { $$str=&Apache::lonenc::unencrypted($$str); } + return; + } + if ($str=~m|^/enc/|) { return &Apache::lonenc::unencrypted($str); } + return $str; +} + 1; __END__