version 1.37, 2003/08/04 17:45:06
|
version 1.41, 2003/08/28 20:28:33
|
Line 174 sub display {
|
Line 174 sub display {
|
|
|
=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 188 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 205 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 476 sub Rename1 {
|
Line 395 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); |
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 572 sub Copy1 {
|
Line 489 sub Copy1 {
|
|
|
if(-e $fn) { |
if(-e $fn) { |
$request->print(&checksuffix($fn,$newfilename)); |
$request->print(&checksuffix($fn,$newfilename)); |
my $return=&exists($user, $domain, $fn, $newfilename); |
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 631 sub NewDir1
|
Line 548 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 688 sub NewFile1 {
|
Line 605 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 621 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 819 sub Rename2 {
|
Line 743 sub Rename2 {
|
" new file ".$newfile."\n"); |
" new file ".$newfile."\n"); |
&Debug($request, "Target is: ".$directory.'/'. |
&Debug($request, "Target is: ".$directory.'/'. |
$newfile); |
$newfile); |
|
if (-e $oldfile) { |
|
|
if(-e $oldfile) { |
my $oRN=$oldfile; |
my $dest; |
my $nRN=$newfile; |
|
unless (rename($oldfile,$newfile)) { |
if ($oldfile =~ m|/$|) { |
|
#renaming a dir |
|
$oldfile =~ s|/$||; |
|
$dest=$directory; |
|
$dest=~s|(/)([^/]*)$|$1|; |
|
$dest.='/'.$newfile; |
|
} else { |
|
$dest=$directory.'/'.$newfile; |
|
} |
|
|
|
unless(rename($oldfile,$dest)) { |
|
$request->print('<font color="red">Error: '.$!.'</font>'); |
$request->print('<font color="red">Error: '.$!.'</font>'); |
return 0; |
return 0; |
} else {} |
} |
|
## 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: /home".$user.'/public_html'. |
$request->print("<p> No such file: ".&display($oldfile).'</p></form>'); |
$oldfile.' </p></form>'); |
|
return 0; |
return 0; |
} |
} |
return 1; |
return 1; |
Line 1047 sub phasetwo {
|
Line 991 sub phasetwo {
|
if(!&Rename2($r, $uname, $dir, $fn, $ENV{'form.newfilename'})) { |
if(!&Rename2($r, $uname, $dir, $fn, $ENV{'form.newfilename'})) { |
return; |
return; |
} |
} |
# Prepend the directory to the new name to form the basis of the |
$dest = &url($ENV{'form.newfilename'}); |
# url of the new resource. |
|
# |
|
#renaming a dir |
|
#remove last element for current dir |
|
if ($fn =~ m|/$|) { $dir =~ s|/[^/]*$||; } |
|
$dest = $dir."/".$ENV{'form.newfilename'}; |
|
} |
} |
} elsif ($ENV{'form.action'} eq 'delete') { |
} elsif ($ENV{'form.action'} eq 'delete') { |
if(!&Delete2($r, $uname, $ENV{'form.newfilename'})) { |
if(!&Delete2($r, $uname, $ENV{'form.newfilename'})) { |
Line 1076 sub phasetwo {
|
Line 1014 sub phasetwo {
|
} |
} |
|
|
} elsif ($ENV{'form.action'} eq 'newdir') { |
} elsif ($ENV{'form.action'} eq 'newdir') { |
# |
my $newdir= $ENV{'form.newfilename'}; |
# Since the newfilename form field is construction space |
|
# relative, ew need to prepend the current path; now in $fn. |
|
# |
|
my $newdir= $fn.$ENV{'form.newfilename'}; |
|
if(!&NewDir2($r, $uname, $newdir)) { |
if(!&NewDir2($r, $uname, $newdir)) { |
return; |
return; |
} |
} |
$dest = $newdir."/" |
$dest = $newdir."/" |
} |
} |
# |
$r->print('<h3><a href="'.&url($dest).'">Done</a></h3>'); |
# Substitute for priv for the first home in $dir to get our |
|
# construction space path. |
|
# |
|
$dest=&MakeFinalUrl($r,$dest); |
|
|
|
$r->print('<h3><a href="'.$dest.'">Done</a></h3>'); |
|
} |
|
|
|
sub MakeFinalUrl { |
|
my($r,$dest)=@_; |
|
&Debug($r, "Final url is: $dest"); |
|
$dest =~ s|/home/|/priv/|; |
|
$dest =~ s|/public_html||; |
|
|
|
my $base = &File::Basename::basename($dest); |
|
my $dpath= &File::Basename::dirname($dest); |
|
if ($base eq '.') { $base=''; } |
|
$dest = &HTML::Entities::encode($dpath.'/'.$base); |
|
|
|
&Debug($r, "Final url after rewrite: $dest"); |
|
return $dest; |
|
} |
} |
|
|
sub handler { |
sub handler { |