M
mike
Hi,
We are using a perl script to delete file/folder in apache ( cgi-bin).
When we do a delete with and url that ends with <directoryname>/ the
delete is performed.
However when we use only <directoryname> without the slash then we get
the response saying,
Directory permanently moved.
This is the perl-script we are using ( see below). Any hints on what
we have been missing out?
----------------------------------
#!/usr/bin/perl
use warnings;
use File::Basename;
use File:ath;
#Very simple delete handler implementation.
#Note: This script should be used securely.
# A simple log file, must be writable by the user that this program
runs as.
# Should not be within the document tree.
$deletelog = "/tmp/delete1.log";
my $files_deleted = 0;
# Check we are using PUT method
if ($ENV{'REQUEST_METHOD'} ne "DELETE") { &reply(500, "Request method
is not DELETE"); }
&log("Request is DELETE");
# Note: should also check we are an authentication user by checking
# REMOTE_USER
# Check we got a destination filename
$filenamein = $ENV{'PATH_TRANSLATED'};
if (!$filenamein) {
&reply(500, "No PATH_TRANSLATED");
}
my($filename, $directories) = fileparse($filenamein);
&log("Filename : $filename \n");
&log("Directory : $directories \n");
if(! $filename) {
#we are deleting a directory remove the tree in quiet mode
$files_deleted = rmtree($directories);
&log("Number files deleted in $directories : $files_deleted\n");
} else {
#delete a file
&log("Will remove single file : $filenamein\n");
if(unlink($filenamein) == 0) {
&reply(500, "Cannot delete unknown $filenamein");
}
}
# Everything seemed to work, reply with 204 (or 200). Should reply
with 201
# if content was created, not updated.
&reply(200);
exit(0);
------------------------
We are using a perl script to delete file/folder in apache ( cgi-bin).
When we do a delete with and url that ends with <directoryname>/ the
delete is performed.
However when we use only <directoryname> without the slash then we get
the response saying,
Directory permanently moved.
This is the perl-script we are using ( see below). Any hints on what
we have been missing out?
----------------------------------
#!/usr/bin/perl
use warnings;
use File::Basename;
use File:ath;
#Very simple delete handler implementation.
#Note: This script should be used securely.
# A simple log file, must be writable by the user that this program
runs as.
# Should not be within the document tree.
$deletelog = "/tmp/delete1.log";
my $files_deleted = 0;
# Check we are using PUT method
if ($ENV{'REQUEST_METHOD'} ne "DELETE") { &reply(500, "Request method
is not DELETE"); }
&log("Request is DELETE");
# Note: should also check we are an authentication user by checking
# REMOTE_USER
# Check we got a destination filename
$filenamein = $ENV{'PATH_TRANSLATED'};
if (!$filenamein) {
&reply(500, "No PATH_TRANSLATED");
}
my($filename, $directories) = fileparse($filenamein);
&log("Filename : $filename \n");
&log("Directory : $directories \n");
if(! $filename) {
#we are deleting a directory remove the tree in quiet mode
$files_deleted = rmtree($directories);
&log("Number files deleted in $directories : $files_deleted\n");
} else {
#delete a file
&log("Will remove single file : $filenamein\n");
if(unlink($filenamein) == 0) {
&reply(500, "Cannot delete unknown $filenamein");
}
}
# Everything seemed to work, reply with 204 (or 200). Should reply
with 201
# if content was created, not updated.
&reply(200);
exit(0);
------------------------