version 1.39, 2003/08/04 20:34:19
|
version 1.45, 2003/11/19 15:06:33
|
Line 110 sub Debug {
|
Line 110 sub Debug {
|
# Put out the indicated message butonly if DEBUG is true. |
# Put out the indicated message butonly if DEBUG is true. |
|
|
if ($DEBUG) { |
if ($DEBUG) { |
$log->debug($message); |
$log->debug($message); |
} |
} |
} |
} |
|
|
Line 168 sub url {
|
Line 168 sub url {
|
|
|
sub display { |
sub display { |
my $fn=shift; |
my $fn=shift; |
$fn=~s/^\/home\/(\w+)\/public\_html//; |
$fn=~s-^/home/(\w+)/public_html-/priv/$1-; |
return '<tt>'.$fn.'</tt>'; |
return '<tt>'.$fn.'</tt>'; |
} |
} |
|
|
Line 387 sub Rename1 {
|
Line 387 sub Rename1 {
|
|
|
if(-e $fn) { |
if(-e $fn) { |
if($newfilename) { |
if($newfilename) { |
|
# is dest a dir |
|
if (-d $newfilename) { |
|
if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; } |
|
} |
if ($newfilename =~ m|/[^\.]+$|) { |
if ($newfilename =~ m|/[^\.]+$|) { |
#no extension add on original extension |
#no extension add on original extension |
if ($fn =~ m|/[^\.]*\.([^\.]+)$|) { |
if ($fn =~ m|/[^\.]*\.([^\.]+)$|) { |
Line 399 sub Rename1 {
|
Line 403 sub Rename1 {
|
if (-d $fn) { |
if (-d $fn) { |
$newfilename=~s/\/[^\/]+\/([^\/]+)$/\/$1/; |
$newfilename=~s/\/[^\/]+\/([^\/]+)$/\/$1/; |
} |
} |
|
$newfilename=~s://+:/:g; # remove duplicate / |
|
while ($newfilename=~m:/\.\./:) { |
|
$newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/.. |
|
} |
my $return=&exists($user, $domain, $newfilename); |
my $return=&exists($user, $domain, $newfilename); |
$request->print($return); |
$request->print($return); |
if ($return =~/^Error:/) { |
if ($return =~/^Error:/) { |
Line 485 Parameters:
|
Line 493 Parameters:
|
=cut |
=cut |
|
|
sub Copy1 { |
sub Copy1 { |
my ($request, $user, $domain, $fn, $newfilename) = @_; |
my ($request, $user, $domain, $fn, $newfilename) = @_; |
|
|
if(-e $fn) { |
if(-e $fn) { |
$request->print(&checksuffix($fn,$newfilename)); |
# is dest a dir |
my $return=&exists($user, $domain, $newfilename); |
if (-d $newfilename) { |
$request->print($return); |
if ($fn =~ m|/([^/]*)$|) { $newfilename .= '/'.$1; } |
if ($return =~/^Error:/) { |
} |
$request->print('<br /><a href="'.&url($fn).'">Cancel</a>'); |
if ($newfilename =~ m|/[^\.]+$|) { |
return; |
#no extension add on original extension |
|
if ($fn =~ m|/[^\.]*\.([^\.]+)$|) { $newfilename.='.'.$1; } |
|
} |
|
$newfilename=~s://+:/:g; # remove duplicate / |
|
while ($newfilename=~m:/\.\./:) { |
|
$newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/.. |
|
} |
|
$request->print(&checksuffix($fn,$newfilename)); |
|
my $return=&exists($user, $domain, $newfilename); |
|
$request->print($return); |
|
if ($return =~/^Error:/) { |
|
$request->print('<br /><a href="'.&url($fn).'">Cancel</a>'); |
|
return; |
|
} |
|
$request->print('<input type="hidden" name="newfilename" value="'. |
|
$newfilename. |
|
'" /><p>Copy '.&display($fn).'<br />to '. |
|
&display($newfilename).'?</p>'); |
|
&CloseForm1($request, $fn); |
|
} else { |
|
$request->print('<p>No such file: '.&display($fn).'</p></form>'); |
} |
} |
$request->print('<input type = "hidden" name = "newfilename" value = "'. |
|
$newfilename. |
|
'" /><p>Copy '.&display($fn).'<br />to '. |
|
&display($newfilename).'?</p>'); |
|
&CloseForm1($request, $fn); |
|
} else { |
|
$request->print('<p>No such file: '.&display($fn).'</p></form>'); |
|
} |
|
} |
} |
|
|
=pod |
=pod |
Line 559 sub NewDir1
|
Line 579 sub NewDir1
|
} |
} |
} |
} |
|
|
|
|
|
sub Decompress1 { |
|
my ($request, $user, $domain, $fn) = @_; |
|
if( -e $fn) { |
|
$request->print('<input type="hidden" name="newfilename" value="'.$fn.'"/>'); |
|
$request->print('<p>Decompress '.&display($fn).'?</p>'); |
|
&CloseForm1($request, $fn); |
|
} else { |
|
$request->print('<p>No such file: '.&display($fn).'</p></form>'); |
|
} |
|
} |
=pod |
=pod |
|
|
=item NewFile1 |
=item NewFile1 |
Line 605 sub NewFile1 {
|
Line 636 sub NewFile1 {
|
|
|
if ($ENV{'form.action'} =~ /new(.+)file/) { |
if ($ENV{'form.action'} =~ /new(.+)file/) { |
my $extension=$1; |
my $extension=$1; |
|
|
|
##Informs User (name).(number).(extension) not allowed |
|
if($newfilename =~ /\.(\d+)\.(\w+)$/){ |
|
$r->print('<font color="red">'.$newfilename. |
|
' - Bad Filename<br />(name).(number).(extension)'. |
|
' Not Allowed</font>'); |
|
return; |
|
} |
if ($newfilename !~ /\Q.$extension\E$/) { |
if ($newfilename !~ /\Q.$extension\E$/) { |
if ($newfilename =~ m|^[^\.]*\.([^\.]+)$|) { |
if ($newfilename =~ m|^[^\.]*\.([^\.]+)$|) { |
#already has an extension strip it and add in expected one |
#already has an extension strip it and add in expected one |
Line 659 sub phaseone {
|
Line 698 sub phaseone {
|
|
|
my $newfilename=&cleanDest($r,$ENV{'form.newfilename'}); |
my $newfilename=&cleanDest($r,$ENV{'form.newfilename'}); |
$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.'" />'. |
'<input type="hidden" name="phase" value="two" />'. |
'<input type="hidden" name="phase" value="two" />'. |
Line 669 sub phaseone {
|
Line 707 sub phaseone {
|
&Rename1($r, $uname, $udom, $fn, $newfilename); |
&Rename1($r, $uname, $udom, $fn, $newfilename); |
} elsif ($ENV{'form.action'} eq 'delete') { |
} elsif ($ENV{'form.action'} eq 'delete') { |
&Delete1($r, $uname, $udom, $fn); |
&Delete1($r, $uname, $udom, $fn); |
|
} elsif ($ENV{'form.action'} eq 'decompress') { |
|
&Decompress1($r, $uname, $udom, $fn); |
} elsif ($ENV{'form.action'} eq 'copy') { |
} elsif ($ENV{'form.action'} eq 'copy') { |
if($newfilename) { |
if($newfilename) { |
&Copy1($r, $uname, $udom, $fn, $newfilename); |
&Copy1($r, $uname, $udom, $fn, $newfilename); |
Line 736 sub Rename2 {
|
Line 776 sub Rename2 {
|
&Debug($request, "Target is: ".$directory.'/'. |
&Debug($request, "Target is: ".$directory.'/'. |
$newfile); |
$newfile); |
if (-e $oldfile) { |
if (-e $oldfile) { |
|
|
|
my $oRN=$oldfile; |
|
my $nRN=$newfile; |
unless (rename($oldfile,$newfile)) { |
unless (rename($oldfile,$newfile)) { |
$request->print('<font color="red">Error: '.$!.'</font>'); |
$request->print('<font color="red">Error: '.$!.'</font>'); |
return 0; |
return 0; |
} |
} |
|
## If old name.(extension) exits, move under new name. |
|
## If it doesn't exist and a new.(extension) exists |
|
## delete it (only concern when renaming over files) |
|
my $tmp1=$oRN.'.meta'; |
|
my $tmp2=$nRN.'.meta'; |
|
if(-e $tmp1){ |
|
unless(rename($tmp1,$tmp2)){ } |
|
} elsif(-e $tmp2){ |
|
unlink $tmp2; |
|
} |
|
$tmp1=$oRN.'.save'; |
|
$tmp2=$nRN.'.save'; |
|
if(-e $tmp1){ |
|
unless(rename($tmp1,$tmp2)){ } |
|
} elsif(-e $tmp2){ |
|
unlink $tmp2; |
|
} |
|
$tmp1=$oRN.'.log'; |
|
$tmp2=$nRN.'.log'; |
|
if(-e $tmp1){ |
|
unless(rename($tmp1,$tmp2)){ } |
|
} elsif(-e $tmp2){ |
|
unlink $tmp2; |
|
} |
|
$tmp1=$oRN.'.bak'; |
|
$tmp2=$nRN.'.bak'; |
|
if(-e $tmp1){ |
|
unless(rename($tmp1,$tmp2)){ } |
|
} elsif(-e $tmp2){ |
|
unlink $tmp2; |
|
} |
} else { |
} else { |
$request->print("<p> No such file: ".&display($oldfile).'</p></form>'); |
$request->print("<p> No such file: ".&display($oldfile).'</p></form>'); |
return 0; |
return 0; |
Line 873 sub NewDir2 {
|
Line 947 sub NewDir2 {
|
} |
} |
return 1; |
return 1; |
} |
} |
|
sub decompress2 { |
|
my ($r, $user, $dir, $file) = @_; |
|
&Apache::lonnet::appenv('cgi.file' => $file); |
|
&Apache::lonnet::appenv('cgi.dir' => $dir); |
|
my $result=&Apache::lonnet::ssi_body('/cgi-bin/decompress.pl'); |
|
$r->print($result); |
|
&Apache::lonnet::delenv('cgi.file'); |
|
&Apache::lonnet::delenv('cgi.dir'); |
|
return 1; |
|
} |
=pod |
=pod |
|
|
=item phasetwo($r, $fn, $uname, $udom) |
=item phasetwo($r, $fn, $uname, $udom) |
Line 939 sub phasetwo {
|
Line 1022 sub phasetwo {
|
"loncfie::phase2 action is $ENV{'form.action'}"); |
"loncfie::phase2 action is $ENV{'form.action'}"); |
|
|
# Select the appropriate processing sub. |
# Select the appropriate processing sub. |
|
if ($ENV{'form.action'} eq 'decompress') { |
if ($ENV{'form.action'} eq 'rename') { # Rename. |
$main .= '.'; |
|
$main .= $suffix; |
|
if(!&decompress2($r, $uname, $dir, $main)) { |
|
return ; |
|
} |
|
$dest = $dir."/."; |
|
|
|
|
|
} elsif ($ENV{'form.action'} eq 'rename') { # Rename. |
if($ENV{'form.newfilename'}) { |
if($ENV{'form.newfilename'}) { |
if (!defined($dir)) { |
if (!defined($dir)) { |
$fn=~m:^(.*)/:; |
$fn=~m:^(.*)/:; |
Line 962 sub phasetwo {
|
Line 1053 sub phasetwo {
|
} elsif ($ENV{'form.action'} eq 'copy') { |
} elsif ($ENV{'form.action'} eq 'copy') { |
if($ENV{'form.newfilename'}) { |
if($ENV{'form.newfilename'}) { |
if(!&Copy2($r, $uname, $dir, $fn, $ENV{'form.newfilename'})) { |
if(!&Copy2($r, $uname, $dir, $fn, $ENV{'form.newfilename'})) { |
return |
return ; |
} |
} |
$dest = $ENV{'form.newfilename'}; |
$dest = $ENV{'form.newfilename'}; |
|
|
Line 997 sub handler {
|
Line 1088 sub handler {
|
my $fn; |
my $fn; |
|
|
if ($ENV{'form.filename'}) { |
if ($ENV{'form.filename'}) { |
|
|
|
&Debug($r, "test: $ENV{'form.filename'}"); |
$fn=&Apache::lonnet::unescape($ENV{'form.filename'}); |
$fn=&Apache::lonnet::unescape($ENV{'form.filename'}); |
$fn=&URLToPath($fn); |
$fn=&URLToPath($fn); |
} elsif ($ENV{'form.qualifiedfilename'}) { |
} |
|
#Just hijack the script only the first time around to inject the correct information for further processing |
|
elsif($ENV{'QUERY_STRING'} && $ENV{'form.phase'} ne 'two') { |
|
&Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},['decompress']); |
|
$fn=&Apache::lonnet::unescape($ENV{'form.decompress'}); |
|
$fn=&URLToPath($fn); |
|
$ENV{'form.action'}="decompress"; |
|
} |
|
|
|
elsif ($ENV{'form.qualifiedfilename'}) { |
$fn=$ENV{'form.qualifiedfilename'}; |
$fn=$ENV{'form.qualifiedfilename'}; |
} else { |
} else { |
&Debug($r, "loncfile::handler - no form.filename"); |
&Debug($r, "loncfile::handler - no form.filename"); |
Line 1056 sub handler {
|
Line 1158 sub handler {
|
$r->print('<h3>Rename</h3>'); |
$r->print('<h3>Rename</h3>'); |
} elsif ($ENV{'form.action'} eq 'newdir') { |
} elsif ($ENV{'form.action'} eq 'newdir') { |
$r->print('<h3>New Directory</h3>'); |
$r->print('<h3>New Directory</h3>'); |
|
} elsif ($ENV{'form.action'} eq 'decompress') { |
|
$r->print('<h3>Decompress</h3>'); |
} elsif ($ENV{'form.action'} eq 'copy') { |
} elsif ($ENV{'form.action'} eq 'copy') { |
$r->print('<h3>Copy</h3>'); |
$r->print('<h3>Copy</h3>'); |
} elsif ($ENV{'form.action'} eq 'newfile' || |
} elsif ($ENV{'form.action'} eq 'newfile' || |