From: pcanterino <> Date: Tue, 2 Dec 2003 17:55:16 +0000 (+0000) Subject: - The commands are now dispatched in Command.pm. Only the method exec_command() is... X-Git-Tag: version_1_2~6 X-Git-Url: https://git.p6c8.net/devedit.git/commitdiff_plain/f0cd6d2f27ac9fcf1b121b9c2f7f8eb40b7a222c - The commands are now dispatched in Command.pm. Only the method exec_command() is exported now (devedit.pl became a little bit cleaner). - In directory listing, the link "Do other stuff" was renamed to "Work with file". - In directory listing, there is now a link called "Work with directory" which displays a form to rename and to remove a directory. - Added the possibility to completely remove a directory (I built a confirmation dialog!). - Added default permission to mkdir() (sometimes, this is necessary). --- diff --git a/devedit.pl b/devedit.pl index ed624df..2c46f85 100644 --- a/devedit.pl +++ b/devedit.pl @@ -6,7 +6,7 @@ # Dev-Editor's main program # # Author: Patrick Canterino -# Last modified: 2003-10-18 +# Last modified: 2003-12-02 # use strict; @@ -86,21 +86,6 @@ if(-e clean_path($config{'fileroot'}."/".$file)) { if(my ($physical,$virtual) = check_path($config{'fileroot'},$file)) { - # Copied from old Dev-Editor (great idea) - - my %dispatch = ('show' => \&exec_show, - 'beginedit' => \&exec_beginedit, - 'canceledit' => \&exec_unlock, - 'endedit' => \&exec_endedit, - 'mkdir' => \&exec_mkdir, - 'mkfile' => \&exec_mkfile, - 'workwithfile' => \&exec_workwithfile, - 'copy' => \&exec_copy, - 'rename' => \&exec_rename, - 'remove' => \&exec_remove, - 'unlock' => \&exec_unlock - ); - # Create a File::UseList object and load the list my $uselist = new File::UseList(listfile => $config{'uselist_file'}, @@ -120,13 +105,7 @@ if(-e clean_path($config{'fileroot'}."/".$file)) uselist => $uselist, cgi => $cgi); - unless($dispatch{$command}) - { - $uselist->unlock; - abort("Unknown command: $command"); - } - - my $output = &{$dispatch{$command}}(\%data,\%config); # Execute the command... + my $output = exec_command($command,\%data,\%config); # Execute the command... $uselist->unlock; # ... unlock the list with files in use... print $$output; # ... and print the output of the command diff --git a/modules/Command.pm b/modules/Command.pm index 0a368e9..635d43d 100644 --- a/modules/Command.pm +++ b/modules/Command.pm @@ -6,38 +6,64 @@ package Command; # Execute Dev-Editor's commands # # Author: Patrick Canterino -# Last modified: 2003-11-10 +# Last modified: 2003-12-02 # use strict; -use vars qw(@EXPORT - $script); +use vars qw(@EXPORT); use File::Access; use File::Copy; +use File::Path; use HTML::Entities; use Output; use POSIX qw(strftime); use Tool; -$script = $ENV{'SCRIPT_NAME'}; +my $script = $ENV{'SCRIPT_NAME'}; + +my %dispatch = ('show' => \&exec_show, + 'beginedit' => \&exec_beginedit, + 'canceledit' => \&exec_unlock, + 'endedit' => \&exec_endedit, + 'mkdir' => \&exec_mkdir, + 'mkfile' => \&exec_mkfile, + 'workwithfile' => \&exec_workwithfile, + 'workwithdir' => \&exec_workwithdir, + 'copy' => \&exec_copy, + 'rename' => \&exec_rename, + 'remove' => \&exec_remove, + 'rmdir' => \&exec_rmdir, + 'unlock' => \&exec_unlock + ); ### Export ### use base qw(Exporter); -@EXPORT = qw(exec_show - exec_beginedit - exec_endedit - exec_mkfile - exec_mkdir - exec_workwithfile - exec_copy - exec_rename - exec_remove - exec_unlock); +@EXPORT = qw(exec_command); + +# exec_command() +# +# Execute the specified command +# +# Params: 1. Command to execute +# 2. Reference to user input hash +# 3. Reference to config hash +# +# Return: Output of the command (Scalar Reference) + +sub exec_command($$$) +{ + my ($command,$data,$config) = @_; + + return error("Unknown command: $command") unless($dispatch{$command}); + + my $output = &{$dispatch{$command}}($data,$config); + return $output; +} # exec_show() # @@ -48,7 +74,7 @@ use base qw(Exporter); # # Return: Output of the command (Scalar Reference) -sub exec_show($$$) +sub exec_show($$) { my ($data,$config) = @_; my $physical = $data->{'physical'}; @@ -97,13 +123,16 @@ sub exec_show($$$) foreach my $dir(@$dirs) { - my @stat = stat($physical."/".$dir); + my @stat = stat($physical."/".$dir); + my $virt_path = encode_entities($virtual.$dir."/"); $output .= " "; $output .= "[SUBDIR] "; $output .= strftime($config->{'timeformat'},localtime($stat[9])); $output .= " " x 10; - $output .= "".encode_entities($dir)."/\n"; + $output .= "".encode_entities($dir)."/"; + $output .= " " x ($max_name_len - length($dir) - 1)."\t ("; + $output .= "Work with directory)\n"; } # Files @@ -162,7 +191,7 @@ sub exec_show($$$) # Link "Do other stuff" - $output .= " | Do other stuff)\n"; + $output .= " | Work with file)\n"; } $output .= "\n\n
\n\n"; @@ -402,7 +431,7 @@ sub exec_mkdir($$) return error("A file or directory called '$new_virtual' already exists.",$dir) if(-e $new_physical); - mkdir($new_physical) or return error("Could not create directory '$new_virtual'.",$dir); + mkdir($new_physical,0777) or return error("Could not create directory '$new_virtual'.",$dir); return devedit_reload({command => 'show', file => $dir}); } @@ -446,7 +475,7 @@ sub exec_workwithfile($$)
-

Copy file '$virtual' to: $dir

+

Copy file '$virtual' to:
$dir


@@ -465,17 +494,19 @@ END
-

Move/Rename file '$virtual' to: $dir

+

Move/Rename file '$virtual' to:
$dir


Delete

+

Click on the button below to remove the file '$virtual'.

+
-

+

END } @@ -503,6 +534,60 @@ END return \$output; } +# exec_workwithdir() +# +# Display a form for renaming/deleting a directory +# +# Params: 1. Reference to user input hash +# 2. Reference to config hash +# +# Return: Output of the command (Scalar Reference) + +sub exec_workwithdir($$) +{ + my ($data,$config) = @_; + my $physical = $data->{'physical'}; + my $virtual = $data->{'virtual'}; + + my $dir = encode_entities(upper_path($virtual)); + + my $output = htmlhead("Work with directory ".encode_entities($virtual)); + $output .= equal_url($config->{'httproot'},$virtual); + + $virtual = encode_entities($virtual); + + $output .= dir_link($virtual); + $output .= "

Note: On UNIX systems, filenames are case-sensitive!

\n\n"; + $output .= "
\n\n"; + + $output .= <Move/rename + +
+ + +

Move/Rename directory '$virtual' to: $dir

+
+ +
+ +

Delete

+ +

Click on the button below to completely remove the directory '$virtual' and oll of it's files and sub directories.

+ +
+ + +

+
+END + + $output .= "\n
"; + $output .= htmlfoot; + + return \$output; +} + # exec_copy() # # Copy a file and return to directory view @@ -579,13 +664,70 @@ sub exec_remove($$) my $physical = $data->{'physical'}; my $virtual = $data->{'virtual'}; - return error("Deleting directories is currently unsupported.",upper_path($virtual)) if(-d $physical); - return error_in_use($virtual) if($data->{'uselist'}->in_use($virtual)); + return exec_rmdir($data,$config) if(-d $physical); + return error_in_use($virtual) if($data->{'uselist'}->in_use($virtual)); unlink($physical) or return error("Could not delete file '".encode_entities($virtual)."'.",upper_path($virtual)); return devedit_reload({command => 'show', file => upper_path($virtual)}); } +# exec_rmdir() +# +# Remove a directory and return to directory view +# +# Params: 1. Reference to user input hash +# 2. Reference to config hash +# +# Return: Output of the command (Scalar Reference) + +sub exec_rmdir($$) +{ + my ($data,$config) = @_; + my $physical = $data->{'physical'}; + my $virtual = $data->{'virtual'}; + + if($data->{'cgi'}->param('confirmed')) + { + rmtree($physical); + return devedit_reload({command => 'show', file => upper_path($virtual)}); + } + else + { + my $dir = encode_entities(upper_path($virtual)); + my $output; + + $output = htmlhead("Remove directory $virtual"); + $output .= equal_url($config->{'httproot'},$virtual); + + $virtual = encode_entities($virtual); + + $output .= dir_link($virtual); + + $output .= <<"END"; +

Do you really want to remove the directory '$virtual' and all of it's files and sub directories?

+ +
+ + + + + +
+ +
+ + + + +
+END + + $output .= htmlfoot; + + return \$output; + } +} + # exec_unlock() # # Remove a file from the list of used files and