version 1.38, 2003/08/04 20:08:23
|
version 1.44, 2003/11/19 14:57:32
|
Line 73 use Apache::Log ();
|
Line 73 use Apache::Log ();
|
use Apache::lonnet; |
use Apache::lonnet; |
use Apache::loncommon(); |
use Apache::loncommon(); |
|
|
my $DEBUG=0; |
my $DEBUG=2; |
my $r; # Needs to be global for some stuff RF. |
my $r; # Needs to be global for some stuff RF. |
|
|
=pod |
=pod |
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); |
$r->log_reason($message); |
} |
} |
} |
} |
|
|
=pod |
=pod |
|
|
|
=item checksuffix($old, $new) |
|
|
|
Determine if a resource filename suffix (the stuff after the .) would change |
|
as a result of this operation. |
|
|
|
Parameters: |
|
|
|
=over 4 |
|
|
|
=item $old = string [in] Previous filename. |
|
|
|
=item $new = string [in] Resultant filename. |
|
|
|
=back |
|
|
|
=cut |
|
|
|
=pod |
|
|
=item URLToPath($url) |
=item URLToPath($url) |
|
|
Convert a URL to a file system path. |
Convert a URL to a file system path. |
Line 168 sub url {
|
Line 187 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>'; |
} |
} |
|
|
=pod |
=pod |
|
|
=item PublicationPath($domain, $user, $dir, $file) |
=item exists($user, $domain, $file) |
|
|
Determines the filesystem path corresponding to a published resource |
|
specification. The returned value is the path. |
|
Parameters: |
|
|
|
=over 4 |
|
|
|
=item $domain - string [in] Name of the domain within which the resource is |
|
stored. |
|
|
|
=item $user - string [in] Name of the user asking about the resource. |
|
|
|
=item $dir - Directory path relative to the top of the resource space. |
|
|
|
=item $file - name of the resource file itself without path info. |
|
|
|
=back |
|
|
|
=over 4 |
|
|
|
Returns: |
|
|
|
=item string - full path to the file if it exists in publication space. |
|
|
|
=back |
|
|
|
=cut |
|
|
|
sub PublicationPath |
|
{ |
|
my ($domain, $user, $dir, $file)=@_; |
|
|
|
return '/home/httpd/html/res/'.$domain.'/'.$user.'/'.$dir.'/'. |
|
$file; |
|
} |
|
|
|
=pod |
|
|
|
=item ConstructionPath($domain, $user, $dir, $file) |
|
|
|
Determines the filesystem path corresponding to a construction space |
|
resource specification. The returned value is the path |
|
Parameters: |
|
|
|
=over 4 |
|
|
|
=item $user - string [in] Name of the user asking about the resource. |
|
|
|
=item $dir - Directory path relative to the top of the resource space. |
|
|
|
=item $file - name of the resource file itself without path info. |
|
|
|
Returns: |
|
|
|
=item string - full path to the file if it exists in Construction space. |
|
|
|
=back |
|
|
|
=cut |
|
|
|
sub ConstructionPath { |
|
my ($user, $dir, $file) = @_; |
|
|
|
return '/home/'.$user.'/public_html/'.$dir.'/'.$file; |
|
|
|
} |
|
|
|
=pod |
|
|
|
=item exists($user, $domain, $directory, $file) |
|
|
|
Determine if a resource file name has been published or exists |
Determine if a resource file name has been published or exists |
in the construction space. |
in the construction space. |
Line 258 sub ConstructionPath {
|
Line 207 sub ConstructionPath {
|
=item $domain - string [in] - Name of the domain in which the resource |
=item $domain - string [in] - Name of the domain in which the resource |
might have been published. |
might have been published. |
|
|
=item $dir - string [in] - Path relative to construction or resource space |
|
in which the resource might live. |
|
|
|
=item $file - string [in] - Name of the file. |
=item $file - string [in] - Name of the file. |
|
|
=back |
=back |
Line 278 Returns:
|
Line 224 Returns:
|
=cut |
=cut |
|
|
sub exists { |
sub exists { |
my ($user, $domain, $dir, $file) = @_; |
my ($user, $domain, $construct) = @_; |
|
my $published=$construct; |
# Create complete paths in publication and construction space. |
$published=~ |
my $relativedir=$dir; |
s/^\/home\/$user\/public\_html\//\/home\/httpd\/html\/res\/$domain\/$user\//; |
$relativedir=s|/home/\Q$user\E/public_html||; |
my $result=''; |
my $published = &PublicationPath($domain, $user, $relativedir, $file); |
|
my $construct = &ConstructionPath($user, $relativedir, $file); |
|
|
|
# If the resource exists in either space indicate this fact. |
|
# Note that the check for existence in resource space is stricter. |
|
|
|
my $result; |
|
if ( -d $construct ) { |
if ( -d $construct ) { |
return 'Error: destination for operation is a directory.'; |
return 'Error: destination for operation is an existing directory.'; |
} |
} |
if ( -e $published) { |
if ( -e $published) { |
$result.='<p><font color="red">Warning: target file exists, and has been published!</font></p>'; |
$result.='<p><font color="red">Warning: target file exists, and has been published!</font></p>'; |
} elsif ( -e $construct) { |
} elsif ( -e $construct) { |
$result.='<p><font color="red">Warning: target file exists!</font></p>'; |
$result.='<p><font color="red">Warning: target file exists!</font></p>'; |
} |
} |
|
|
return $result; |
return $result; |
|
|
} |
} |
Line 468 sub Rename1 {
|
Line 406 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 476 sub Rename1 {
|
Line 418 sub Rename1 {
|
} |
} |
$request->print(&checksuffix($fn, $newfilename)); |
$request->print(&checksuffix($fn, $newfilename)); |
#renaming a dir, delete the trailing / |
#renaming a dir, delete the trailing / |
#remove last element for current dir |
#remove second to last element for current dir |
my $dir=$fn; |
if (-d $fn) { |
if ($fn =~ m|/$|) { |
$newfilename=~s/\/[^\/]+\/([^\/]+)$/\/$1/; |
$fn =~ s|/$||; |
|
$dir =~ s|/[^/]*$||; |
|
} |
} |
my $return=&exists($user, $domain, $dir, $newfilename); |
$newfilename=~s://+:/:g; # remove duplicate / |
|
while ($newfilename=~m:/\.\./:) { |
|
$newfilename=~ s:/[^/]+/\.\./:/:g; #remove dir/.. |
|
} |
|
my $return=&exists($user, $domain, $newfilename); |
$request->print($return); |
$request->print($return); |
if ($return =~/^Error:/) { |
if ($return =~/^Error:/) { |
$request->print('<br /><a href="'.&url($fn).'">Cancel</a>'); |
$request->print('<br /><a href="'.&url($fn).'">Cancel</a>'); |
Line 568 Parameters:
|
Line 512 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, $fn, $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 631 sub NewDir1
|
Line 587 sub NewDir1
|
{ |
{ |
my ($request, $username, $domain, $fn, $newfilename) = @_; |
my ($request, $username, $domain, $fn, $newfilename) = @_; |
|
|
if(-e $newfilename) { |
my $result=&exists($username,$domain,$newfilename); |
$request->print('<p>Directory exists.</p></form>'); |
if ($result) { |
} |
$request->print('<font color="red">'.$result.'</font></form>'); |
else { |
} else { |
$request->print('<input type="hidden" name="newfilename" value="'. |
$request->print('<input type="hidden" name="newfilename" value="'. |
$newfilename.'" /><p>Make new directory '. |
$newfilename.'" /><p>Make new directory '. |
&display($newfilename).'?</p>'); |
&display($newfilename).'?</p>'); |
Line 642 sub NewDir1
|
Line 598 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 688 sub NewFile1 {
|
Line 655 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 696 sub NewFile1 {
|
Line 671 sub NewFile1 {
|
$newfilename.=".$extension"; |
$newfilename.=".$extension"; |
} |
} |
} |
} |
|
my $result=&exists($user,$domain,$newfilename); |
if(-e $newfilename) { |
if($result) { |
$request->print('<p>File exists.</p></form>'); |
$request->print('<font color="red">'.$result.'</font></form>'); |
} |
} else { |
else { |
|
$request->print('<p>Make new file '.&display($newfilename).'?</p>'); |
$request->print('<p>Make new file '.&display($newfilename).'?</p>'); |
$request->print('</form>'); |
$request->print('</form>'); |
$request->print('<form action="'.&url($newfilename). |
$request->print('<form action="'.&url($newfilename). |
Line 743 sub phaseone {
|
Line 717 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); |
|
&Debug($r, "Newfile: $newfilename"); |
$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 753 sub phaseone {
|
Line 727 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') { |
|
&Apache::lonnet::appenv('cgi.path' => $newfilename); |
|
&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 820 sub Rename2 {
|
Line 797 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 957 sub NewDir2 {
|
Line 968 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 1023 sub phasetwo {
|
Line 1043 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 1046 sub phasetwo {
|
Line 1074 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 1081 sub handler {
|
Line 1109 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'}) { |
} |
|
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 1140 sub handler {
|
Line 1178 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' || |