Diff for /loncom/publisher/loncfile.pm between versions 1.59 and 1.66

version 1.59, 2004/08/12 06:50:15 version 1.66, 2005/04/07 04:46:36
Line 289  sub checksuffix { Line 289  sub checksuffix {
 }  }
   
 sub cleanDest {  sub cleanDest {
     my ($request,$dest,$subdir)=@_;      my ($request,$dest,$subdir,$fn,$uname)=@_;
     #remove bad characters      #remove bad characters
     my $foundbad=0;      my $foundbad=0;
     if ($subdir && $dest =~/\./) {      if ($subdir && $dest =~/\./) {
Line 300  sub cleanDest { Line 300  sub cleanDest {
  $foundbad=1;   $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("<p><font color=\"red\">".&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.','"<tt>'.$newpath.'</tt>"')."</font></p>");
       $dest=~s|.*/||;
    }
       }
     if ($foundbad) {      if ($foundbad) {
  $request->print("<p><font color=\"red\">".&mt('Invalid characters in requested name have been removed.')."</font></p>");   $request->print("<p><font color=\"red\">".&mt('Invalid characters in requested name have been removed.')."</font></p>");
     }      }
Line 760  sub phaseone { Line 768  sub phaseone {
       
     my $doingdir=0;      my $doingdir=0;
     if ($ENV{'form.action'} eq 'newdir') { $doingdir=1; }      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);      $newfilename=&relativeDest($fn,$newfilename,$uname);
     $r->print('<form action="/adm/cfile" method="post">'.      $r->print('<form action="/adm/cfile" method="post">'.
       '<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'.        '<input type="hidden" name="qualifiedfilename" value="'.$fn.'" />'.
Line 794  sub phaseone { Line 802  sub phaseone {
       $ENV{'form.action'} eq 'newsequencefile' ||        $ENV{'form.action'} eq 'newsequencefile' ||
       $ENV{'form.action'} eq 'newrightsfile' ||        $ENV{'form.action'} eq 'newrightsfile' ||
       $ENV{'form.action'} eq 'newstyfile' ||        $ENV{'form.action'} eq 'newstyfile' ||
                 $ENV{'form.action'} eq 'newlibraryfile' ||
       $ENV{'form.action'} eq 'Select Action') {        $ENV{'form.action'} eq 'Select Action') {
  if ($newfilename) {          my $empty=&mt('Type Name Here');
    if (($newfilename!~/\/$/) && ($newfilename!~/$empty$/)) {
     &NewFile1($r, $uname, $udom, $fn, $newfilename);      &NewFile1($r, $uname, $udom, $fn, $newfilename);
  } else {   } else {
     $r->print('<p>'.&mt('No new filename specified.').'</p></form>');      $r->print('<p>'.&mt('No new filename specified.').'</p></form>');
Line 988  sub Copy2 { Line 998  sub Copy2 {
  unless (copy($oldfile, $newfile)) {   unless (copy($oldfile, $newfile)) {
     $request->print('<font color="red"> '.&mt('copy Error').': '.$!.'</font>');      $request->print('<font color="red"> '.&mt('copy Error').': '.$!.'</font>');
     return 0;      return 0;
    } elsif (!chmod(0660, $newfile)) {
       $request->print('<font color="red"> '.&mt('chmod error').': '.$!.'</font>');
       return 0;
    } elsif (-e $oldfile.'.meta' && 
    !copy($oldfile.'.meta', $newfile.'.meta') &&
    !chmod(0660, $newfile.'.meta')) {
       $request->print('<font color="red"> '.&mt('copy metadata error').
       ': '.$!.'</font>');
       return 0;
  } else {   } else {
     unless (chmod(0660, $newfile)) {  
  $request->print('<font color="red"> '.&mt('chmod error').': '.$!.'</font>');  
  return 0;  
     }  
     return 1;      return 1;
  }   }
     } else {      } else {
Line 1096  sub phasetwo { Line 1111  sub phasetwo {
  $main=$2; # Filename.   $main=$2; # Filename.
     }      }
     if($main=~m:\.(\w+)$:){ # Fixes problems with filenames with no extensions      if($main=~m:\.(\w+)$:){ # Fixes problems with filenames with no extensions
  $main=$`; #This is what is before the match (.) so it's just the main filename, yea it's nasty   $main=~s/\.\w+$//; #strip the extension
  $suffix=$1; #This is the actually filename extension if it exists   $suffix=$1; #This is the actually filename extension if it exists
     }      }
     my $dest;                   # On success this is where we'll go.      my $dest;                   # On success this is where we'll go.
Line 1112  sub phasetwo { Line 1127  sub phasetwo {
           
     # Select the appropriate processing sub.      # Select the appropriate processing sub.
     if ($ENV{'form.action'} eq 'decompress') {       if ($ENV{'form.action'} eq 'decompress') { 
  $main .= '.';   $main .= '.'.$suffix;
  $main .= $suffix;  
  if(!&decompress2($r, $uname, $dir, $main)) {   if(!&decompress2($r, $uname, $dir, $main)) {
     return ;      return ;
  }   }
  $dest = $dir."/.";   $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($ENV{'form.newfilename'}) {
     if (!defined($dir)) {      if (!defined($dir)) {
  $fn=~m:^(.*)/:;   $fn=~m:^(.*)/:;
Line 1166  sub handler { Line 1181  sub handler {
   
     $r=shift;      $r=shift;
   
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress','action','filename','newfilename']);
   
     &Debug($r, "loncfile.pm - handler entered");      &Debug($r, "loncfile.pm - handler entered");
     &Debug($r, " filename: ".$ENV{'form.filename'});      &Debug($r, " filename: ".$ENV{'form.filename'});
Line 1184  sub handler { Line 1200  sub handler {
     }  elsif($ENV{'QUERY_STRING'} && $ENV{'form.phase'} ne 'two') {        }  elsif($ENV{'QUERY_STRING'} && $ENV{'form.phase'} ne 'two') {  
  #Just hijack the script only the first time around to inject the   #Just hijack the script only the first time around to inject the
  #correct information for further processing   #correct information for further processing
  &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress']);  
  $fn=&Apache::lonnet::unescape($ENV{'form.decompress'});   $fn=&Apache::lonnet::unescape($ENV{'form.decompress'});
  $fn=&URLToPath($fn);   $fn=&URLToPath($fn);
  $ENV{'form.action'}="decompress";   $ENV{'form.action'}="decompress";
Line 1272  function writeDone() { Line 1287  function writeDone() {
      $ENV{'form.action'} eq 'newsequencefile' ||       $ENV{'form.action'} eq 'newsequencefile' ||
      $ENV{'form.action'} eq 'newrightsfile' ||       $ENV{'form.action'} eq 'newrightsfile' ||
      $ENV{'form.action'} eq 'newstyfile' ||       $ENV{'form.action'} eq 'newstyfile' ||
                $ENV{'form.action'} eq 'newlibraryfile' ||
      $ENV{'form.action'} eq 'Select Action' ) {       $ENV{'form.action'} eq 'Select Action' ) {
  $r->print('<h3>'.&mt('New Resource').'</h3>');   $r->print('<h3>'.&mt('New Resource').'</h3>');
     } else {      } else {

Removed from v.1.59  
changed lines
  Added in v.1.66


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>