[LON-CAPA-cvs] cvs: loncom /publisher lonupload.pm

www www at source.lon-capa.org
Wed Oct 26 18:38:49 EDT 2011


www		Wed Oct 26 22:38:49 2011 EDT

  Modified files:              
    /loncom/publisher	lonupload.pm 
  Log:
  Bug #1320: cleanup
  
  
Index: loncom/publisher/lonupload.pm
diff -u loncom/publisher/lonupload.pm:1.54 loncom/publisher/lonupload.pm:1.55
--- loncom/publisher/lonupload.pm:1.54	Sun Oct 23 23:46:07 2011
+++ loncom/publisher/lonupload.pm	Wed Oct 26 22:38:49 2011
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # Handler to upload files into construction space
 #
-# $Id: lonupload.pm,v 1.54 2011/10/23 23:46:07 www Exp $
+# $Id: lonupload.pm,v 1.55 2011/10/26 22:38:49 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -179,12 +179,9 @@
         return;
     }
 
-    $fn=~s/\/[^\/]+$//;
-    $fn=~s/([^\/])$/$1\//;
+    # Append the name of the uploaded file
     $fn.=$env{'form.upfile.filename'};
-    $fn=~s/^\///;
     $fn=~s/(\/)+/\//g;
-    #    Fn is the full path to the destination filename.
 
     # Check for illegal filename
     &Debug($r, "Filename for upload: $fn");
@@ -192,20 +189,21 @@
         $r->print('<p class="LC_warning">'.&mt('Illegal filename.').'</p>');
         return;
     }
-
+# Split part that I can change from the part that I cannot change
+    my ($fn1,$fn2)=($fn=~/^(\/priv\/[^\/]+\/[^\/]+\/)(.*)$/);
     # Display additional options for upload
     # and upload button
     $r->print(
         '<form action="'.$action.'" method="post" name="fileupload">'
        .'<input type="hidden" name="phase" value="two" />'
        .'<input type="hidden" name="datatoken" value="'.&upfile_store.'" />'
-       .'<input type="hidden" name="uploaduname" value="'.$uname.'" />'
     );
     $r->print(
         &Apache::lonhtmlcommon::start_pick_box()
        .&Apache::lonhtmlcommon::row_title(&mt('Save uploaded file as'))
-       .'<span class="LC_filename">/priv/'.$uname.'/</span>'
-       .'<input type="text" size="50" name="filename" value="'.$fn.'" />'
+       .'<span class="LC_filename">'.$fn1.'</span>'
+       .'<input type="hidden" name="filename1" value="'.$fn1.'" />'
+       .'<input type="text" size="50" name="filename2" value="'.$fn2.'" />'
        .&Apache::lonhtmlcommon::row_closure()
        .&Apache::lonhtmlcommon::row_title(&mt('File Type'))
        .'<select name="filetype">'
@@ -242,7 +240,8 @@
 }
 
 sub phasetwo {
-    my ($r,$tfn,$uname,$udom,$mode)=@_;
+    my ($r,$fn,$uname,$udom,$mode)=@_;
+
     my $output;
     my $action = '/adm/upload';
     my $returnflag = '';
@@ -251,12 +250,9 @@
     } elsif ($mode eq 'imsimport') {
         $action = '/adm/imsimport';
     }
-    my $fn='/priv/'.$uname.'/'.$tfn;
     $fn=~s/\/+/\//g;
-    &Debug($r, "Filename is ".$tfn);
-    if ($tfn) {
-	&Debug($r, "Filename for tfn = ".$tfn);
-	my $target='/home/httpd/html/priv/'.$udom.'/'.$uname.'/'.$tfn;
+    if ($fn) {
+	my $target='/home/httpd/html/'.$fn;
 	&Debug($r, "target -> ".$target);
 #     target is the full filesystem path of the destination file.
 	my $base = &File::Basename::basename($fn);
@@ -401,6 +397,7 @@
 
 sub phasethree {
     my ($r,$fn,$uname,$udom,$mode) = @_;
+
     my $action = '/adm/upload'; 
     if ($mode eq 'testbank') {
         $action = '/adm/testbank';
@@ -437,6 +434,7 @@
 
 sub phasefour {
     my ($r,$fn,$uname,$udom,$mode) = @_;
+
     my $action = '/adm/upload';
     if ($mode eq 'testbank') {
         $action = '/adm/testbank';
@@ -466,12 +464,18 @@
     my $uname;
     my $udom;
     my $javascript = '';
-#
-# phase two: re-attach user
-#
-    if ($env{'form.uploaduname'}) {
-	$env{'form.filename'}='/priv/'.$env{'form.uploaduname'}.'/'.
-	    $env{'form.filename'};
+
+    my $fn=$env{'form.filename'};
+
+    if ($env{'form.filename1'}) {
+       $fn=$env{'form.filename1'}.$env{'form.filename2'};
+    }
+    $fn=~s/\/+/\//g;
+
+    unless ($fn) {
+        $r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
+                       ' unspecified filename for upload', $r->filename);
+        return HTTP_NOT_FOUND;
     }
 
     unless ($env{'form.phase'} eq 'two') {
@@ -491,9 +495,7 @@
 }
 	|;
     }
-    ($uname,$udom)=
-	&Apache::loncacc::constructaccess($env{'form.filename'},
-					  $r->dir_config('lonDefDomain'));
+    ($uname,$udom)=&Apache::loncacc::constructaccess($fn);
 
     unless (($uname) && ($udom)) {
 	$r->log_reason($uname.' at '.$udom.
@@ -503,19 +505,6 @@
 	return HTTP_NOT_ACCEPTABLE;
     }
     
-    my $fn;
-    if ($env{'form.filename'}) {
-	$fn=$env{'form.filename'};
-	$fn=~s/^https?\:\/\/[^\/]+\///;
-	$fn=~s/^\///;
-	$fn=~s{(~|priv/)($LONCAPA::username_re)}{};
-	$fn=~s/\/+/\//g;
-    } else {
-	$r->log_reason($env{'user.name'}.' at '.$env{'user.domain'}.
-		       ' unspecified filename for upload', $r->filename); 
-	return HTTP_NOT_FOUND;
-    }
-
 # ----------------------------------------------------------- Start page output
 
 




More information about the LON-CAPA-cvs mailing list