[LON-CAPA-cvs] cvs: loncom / lonencurl.pm /xml londefdef.pm

raeburn raeburn at source.lon-capa.org
Fri Sep 30 23:19:06 EDT 2011


raeburn		Sat Oct  1 03:19:06 2011 EDT

  Modified files:              
    /loncom	lonencurl.pm 
    /loncom/xml	londefdef.pm 
  Log:
  - Bug 5047.
    - Display applets where encrypted URL is in operation, at least for cases
      where there is a single archive file, and code and archive are in
      same directory as html file containing applet, object or embed tag.
  - Also allows display of Camtasia files with encrypted URL where there 
    are dependencies on .js, .swf and .mp4 files.
  - Note: the names of the java class file, java archive file, .swf,
    and .mp4 files is visible, unencrypted in the HTML source for the
    web page containing the applet or the movie.  
  
  
Index: loncom/lonencurl.pm
diff -u loncom/lonencurl.pm:1.4 loncom/lonencurl.pm:1.5
--- loncom/lonencurl.pm:1.4	Tue Oct  2 01:10:16 2007
+++ loncom/lonencurl.pm	Sat Oct  1 03:18:57 2011
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # URL translation for encrypted filenames
 #
-# $Id: lonencurl.pm,v 1.4 2007/10/02 01:10:16 albertel Exp $
+# $Id: lonencurl.pm,v 1.5 2011/10/01 03:18:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -33,6 +33,7 @@
 use Apache::Constants qw(:common :remotehost);
 use Apache::lonnet;
 use Apache::lonenc;
+use GDBM_File;
 
 sub handler {
     my $r = shift;
@@ -44,8 +45,40 @@
 # Initialize Environment
 	my $lonidsdir=$r->dir_config('lonIDsDir');
 	&Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle);
-# Decrypt URL and redirect
-	my $redirect=&Apache::lonenc::unencrypted($r->uri);
+# Decrypt URL, if appropriate, and redirect
+        my $redirect;
+        my ($decrypted,$encnum,$remainder) = &checkdecryption($r->uri);
+        if (($encnum ne '') && ($remainder ne '')) {
+            my $referrer = $r->headers_in->{'Referer'} || '';
+            my $host = $r->headers_in->{'Host'};
+            my $decryptreferrer;
+            if ($referrer =~ m{^https?://\Q$host\E(/enc/\Q$encnum\E/[^?]+)}) {
+                ($decryptreferrer) = &checkdecryption($1);
+            }
+            if ($decryptreferrer eq '') {
+                if ($env{'request.course.fn'} ne '') {
+                    my %symbhash;
+                    if (tie(%symbhash,'GDBM_File',$env{'request.course.fn'}.'_symb.db',
+                        &GDBM_READER(),0640)) {
+                        my $lastsymb=$symbhash{'last_known'};
+                        untie(%symbhash);
+                        (undef,undef,$decryptreferrer)=&Apache::lonnet::decode_symb($lastsymb);
+                        $decryptreferrer = &Apache::lonnet::clutter($decryptreferrer);
+                    }
+                }
+            }
+            if ($decryptreferrer ne '') {
+                my ($referrerpath) = ($decryptreferrer =~ m{^(.+/)[^/]+$});
+                if (($env{'httpref.'.$referrerpath.$remainder} eq $decryptreferrer) ||
+                    ($env{'httpref.'.$referrerpath.'*'} eq $decryptreferrer) ||
+                    ($env{'httpref.'.$referrerpath} eq $decryptreferrer)) {
+                   $redirect=$referrerpath.$remainder;
+                }
+            }
+        }
+        if ($redirect eq '') {
+            $redirect=&Apache::lonenc::unencrypted($r->uri);
+        }
 	if ($r->args) { $redirect.='?'.$r->args; }
 	$r->internal_redirect($redirect);
 	return OK;
@@ -53,5 +86,17 @@
     return FORBIDDEN;
 }
 
+sub checkdecryption {
+    my ($uri) = @_;
+    my ($encnum,$encname,$rest) = ($uri =~ m{^/enc/(\d+)/([^.]+)(.*)$});
+    my $enclength = length($encname);
+    my $rem = $enclength%16;
+    if (($encname =~ /[^a-f0-9]/) || ($rem != 0) || ($enclength < 16)) {
+        return ('',$encnum,$encname.$rest);
+    } else {
+        return (&Apache::lonenc::unencrypted($uri));
+    }
+}
+
 1;
 __END__
Index: loncom/xml/londefdef.pm
diff -u loncom/xml/londefdef.pm:1.433 loncom/xml/londefdef.pm:1.434
--- loncom/xml/londefdef.pm:1.433	Thu Sep 15 19:08:15 2011
+++ loncom/xml/londefdef.pm	Sat Oct  1 03:19:06 2011
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # Tags Default Definition Module 
 #
-# $Id: londefdef.pm,v 1.433 2011/09/15 19:08:15 raeburn Exp $
+# $Id: londefdef.pm,v 1.434 2011/10/01 03:19:06 raeburn Exp $
 # 
 #
 # Copyright Michigan State University Board of Trustees
@@ -2885,10 +2885,7 @@
     &Apache::lonxml::extlink($archive);
     my $currentstring = '';
     if ($target eq 'web' || $target eq 'webgrade') {
-        $currentstring = &Apache::lonenc::encrypt_ref($token,
-                                                      {'code'=>$code,
-                                                       'archive'=>$archive}
-                                                     );
+        $currentstring = $token->[4];
     } elsif ($target eq 'tex') {
         # Turn off some stuff we can't be inside thank you LaTeX
 




More information about the LON-CAPA-cvs mailing list