--- loncom/publisher/loncfile.pm 2004/07/02 08:07:17 1.58 +++ loncom/publisher/loncfile.pm 2004/12/28 21:28:49 1.64 @@ -9,7 +9,7 @@ # and displays a page showing the results of the action. # # -# $Id: loncfile.pm,v 1.58 2004/07/02 08:07:17 albertel Exp $ +# $Id: loncfile.pm,v 1.64 2004/12/28 21:28:49 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -289,7 +289,7 @@ sub checksuffix { } sub cleanDest { - my ($request,$dest,$subdir)=@_; + my ($request,$dest,$subdir,$fn,$uname)=@_; #remove bad characters my $foundbad=0; if ($subdir && $dest =~/\./) { @@ -298,7 +298,15 @@ sub cleanDest { } if ($dest=~/[\#\?&%\"]/) { $foundbad=1; - $dest=~s/[\#\?&%]//g; + $dest=~s/[\#\?&%\"]//g; + } + if ($dest=~m|/|) { + my ($newpath)=($dest=~m|(.*)/|); + $newpath=&relativeDest($fn,$newpath,$uname); + if (! -d "$newpath") { + $request->print("

".&mt('You have requested to create file in directory [_1] which doesn\'t exist. The requested directory path has been removed from the requested file name.','"'.$newpath.'"')."

"); + $dest=~s|.*/||; + } } if ($foundbad) { $request->print("

".&mt('Invalid characters in requested name have been removed.')."

"); @@ -760,7 +768,7 @@ sub phaseone { my $doingdir=0; if ($ENV{'form.action'} eq 'newdir') { $doingdir=1; } - my $newfilename=&cleanDest($r,$ENV{'form.newfilename'},$doingdir); + my $newfilename=&cleanDest($r,$ENV{'form.newfilename'},$doingdir,$fn,$uname); $newfilename=&relativeDest($fn,$newfilename,$uname); $r->print('
'. ''. @@ -988,11 +996,16 @@ sub Copy2 { unless (copy($oldfile, $newfile)) { $request->print(' '.&mt('copy Error').': '.$!.''); return 0; + } elsif (!chmod(0660, $newfile)) { + $request->print(' '.&mt('chmod error').': '.$!.''); + return 0; + } elsif (-e $oldfile.'.meta' && + !copy($oldfile.'.meta', $newfile.'.meta') && + !chmod(0660, $newfile.'.meta')) { + $request->print(' '.&mt('copy metadata error'). + ': '.$!.''); + return 0; } else { - unless (chmod(0660, $newfile)) { - $request->print(' '.&mt('chmod error').': '.$!.''); - return 0; - } return 1; } } else { @@ -1118,7 +1131,8 @@ sub phasetwo { return ; } $dest = $dir."/."; - } elsif ($ENV{'form.action'} eq 'rename') { # Rename. + } elsif ($ENV{'form.action'} eq 'rename' || + $ENV{'form.action'} eq 'move') { if($ENV{'form.newfilename'}) { if (!defined($dir)) { $fn=~m:^(.*)/:; @@ -1166,6 +1180,7 @@ sub handler { $r=shift; + &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress','action','filename','newfilename']); &Debug($r, "loncfile.pm - handler entered"); &Debug($r, " filename: ".$ENV{'form.filename'}); @@ -1184,7 +1199,6 @@ sub handler { } elsif($ENV{'QUERY_STRING'} && $ENV{'form.phase'} ne 'two') { #Just hijack the script only the first time around to inject the #correct information for further processing - &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress']); $fn=&Apache::lonnet::unescape($ENV{'form.decompress'}); $fn=&URLToPath($fn); $ENV{'form.action'}="decompress";