[LON-CAPA-cvs] cvs: loncom / lonenc.pm

raeburn lon-capa-cvs@mail.lon-capa.org
Sun, 24 Dec 2006 21:22:33 -0000


raeburn		Sun Dec 24 16:22:33 2006 EDT

  Modified files:              
    /loncom	lonenc.pm 
  Log:
  Allow &encryptseed() to take an optional argument - a courseID, and to retrieve the course's internal.encseed when it is not currently available in %env.  Used to perform decryption on encrypted URLs included in the baseurl of feedback messages, if the message is read when the corresponding course role is unselected.
  
  
Index: loncom/lonenc.pm
diff -u loncom/lonenc.pm:1.18 loncom/lonenc.pm:1.19
--- loncom/lonenc.pm:1.18	Fri Dec  8 17:04:57 2006
+++ loncom/lonenc.pm	Sun Dec 24 16:22:33 2006
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # URL translation for encrypted filenames
 #
-# $Id: lonenc.pm,v 1.18 2006/12/08 22:04:57 raeburn Exp $
+# $Id: lonenc.pm,v 1.19 2006/12/24 21:22:33 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -35,20 +35,41 @@
 use LONCAPA;
  
 sub encryptseed {
-    my $seed=$env{'course.'.$env{'request.course.id'}.'.internal.encseed'};
-    $seed=~s/[^0-9a-f]/0/g;
-    $seed.='0123456789abcdef';
-    $seed=substr($seed.$seed,0,32);
-    return pack("H32",$seed);
+    my ($cid) = @_;
+    if (!defined($cid)) {
+        $cid = $env{'request.course.id'};
+    }
+    my $seed;
+    if (defined($cid)) {
+        if (defined$env{'course.'.$cid.'.internal.encseed'}) {
+            $seed = $env{'course.'.$cid.'.internal.encseed'};
+        } else {
+            my %descargs = ( 'one_time' => 1);
+            my %course = 
+               &Apache::lonnet::coursedescription($cid,\%descargs);
+            my %seedhash = 
+               &Apache::lonnet::get('environment',['internal.encseed'],
+                                    $course{'domain'},$course{'num'});
+            $seed = $seedhash{'internal.encseed'};
+        }
+    }
+    if (defined($seed)) {
+        $seed=~s/[^0-9a-f]/0/g;
+        $seed.='0123456789abcdef';
+        $seed=substr($seed.$seed,0,32);
+        return pack("H32",$seed);
+    } else {
+        return;
+    }
 }
 
 sub unencrypted {
-    my $uri=shift;
+    my ($uri,$cid) = @_;
     $uri=~s/^\/enc\/(\d+)\///;
     my $cmdlength=$1;
     # strip any added extension
     $uri=~s/\.[^.]*//;
-    my $seed=&encryptseed();
+    my $seed=&encryptseed($cid);
     unless ($seed) {
 	return '/'.$uri;
     }