X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/f7bedef2be14af8b8c93360bdf16850406679be6..75f5e16d99e4474d8c84ad4dc010f0379f4bd02f:/modules/Command.pm?ds=sidebyside diff --git a/modules/Command.pm b/modules/Command.pm index 64f4900..17f9470 100644 --- a/modules/Command.pm +++ b/modules/Command.pm @@ -6,7 +6,7 @@ package Command; # Execute Dev-Editor's commands # # Author: Patrick Canterino -# Last modified: 2004-07-03 +# Last modified: 2004-07-27 # use strict; @@ -25,8 +25,6 @@ use HTML::Entities; use Output; use Template; -use Data::Dumper; - my $script = $ENV{'SCRIPT_NAME'}; my %dispatch = ('show' => \&exec_show, @@ -63,10 +61,16 @@ sub exec_command($$$) { my ($command,$data,$config) = @_; - return error($config->{'errors'}->{'cmd_unknown'},'/',{COMMAND => $command}) unless($dispatch{$command}); + foreach(keys(%dispatch)) + { + if(lc($_) eq lc($command)) + { + my $output = &{$dispatch{$_}}($data,$config); + return $output; + } + } - my $output = &{$dispatch{$command}}($data,$config); - return $output; + return error($config->{'errors'}->{'cmd_unknown'},'/',{COMMAND => $command}); } # exec_show() @@ -83,6 +87,7 @@ sub exec_show($$) my ($data,$config) = @_; my $physical = $data->{'physical'}; my $virtual = $data->{'virtual'}; + my $uselist = $data->{'uselist'}; my $tpl = new Template; @@ -140,7 +145,7 @@ sub exec_show($$) my $virt_path = encode_entities($virtual.$file); my @stat = stat($phys_path); - my $in_use = $data->{'uselist'}->in_use($virtual.$file); + my $in_use = $uselist->in_use($virtual.$file); my $ftpl = new Template; $ftpl->read_file($config->{'templates'}->{'dirlist_file'}); @@ -194,7 +199,9 @@ sub exec_show($$) { # Text file - if($config->{'max_file_size'} && (stat($physical))[7] > $config->{'max_file_size'}) + my $size = (stat($physical))[7]; + + if($config->{'max_file_size'} && $size > $config->{'max_file_size'}) { return error($config->{'errors'}->{'file_too_large'},upper_path($virtual),{SIZE => $config->{'max_file_size'}}) } @@ -210,6 +217,8 @@ sub exec_show($$) $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); $tpl->fillin("SCRIPT",$script); $tpl->fillin("CONTENT",encode_entities($$content)); + + $tpl->parse_if_block("editable",-r $physical && -w $physical && -T $physical && not ($config->{'max_file_size'} && $size > $config->{'max_file_size'}) && $uselist->unused($virtual)); } } } @@ -376,10 +385,26 @@ sub exec_mkfile($$) my $dir = upper_path($new_virtual); $new_virtual = encode_entities($new_virtual); - return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical); + if($new_physical) + { + return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical); + + file_create($new_physical) or return error($config->{'errors'}->{'mkfile_failed'},$dir,{FILE => $new_virtual}); + return devedit_reload({command => 'show', file => $dir}); + } + else + { + my $tpl = new Template; + $tpl->read_file($config->{'templates'}->{'mkfile'}); + + $tpl->fillin("DIR","/"); + $tpl->fillin("SCRIPT",$script); + + my $output = header(-type => "text/html"); + $output .= $tpl->get_template; - file_create($new_physical) or return error($config->{'errors'}->{'mkfile_failed'},$dir,{FILE => $new_virtual}); - return devedit_reload({command => 'show', file => $dir}); + return \$output; + } } # exec_mkdir() @@ -401,8 +426,24 @@ sub exec_mkdir($$) return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical); - mkdir($new_physical,0777) or return error($config->{'errors'}->{'mkdir_failed'},$dir,{DIR => $new_virtual}); - return devedit_reload({command => 'show', file => $dir}); + if($new_physical) + { + mkdir($new_physical,0777) or return error($config->{'errors'}->{'mkdir_failed'},$dir,{DIR => $new_virtual}); + return devedit_reload({command => 'show', file => $dir}); + } + else + { + my $tpl = new Template; + $tpl->read_file($config->{'templates'}->{'mkdir'}); + + $tpl->fillin("DIR","/"); + $tpl->fillin("SCRIPT",$script); + + my $output = header(-type => "text/html"); + $output .= $tpl->get_template; + + return \$output; + } } # exec_upload() @@ -555,6 +596,7 @@ sub exec_rename($$) my $virtual = $data->{'virtual'}; my $new_physical = $data->{'new_physical'}; + return error($config->{'errors'}->{'rename_root'},"/") if($virtual eq "/"); return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual)); if($new_physical) @@ -628,6 +670,8 @@ sub exec_remove($$) my $physical = $data->{'physical'}; my $virtual = $data->{'virtual'}; + return error($config->{'errors'}->{'remove_root'},"/") if($virtual eq "/"); + if(-d $physical) { # Remove a directory