X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/e31b4973197f7d0ca6b9ca5fbf2ba923d3ea63fe..0705361ceafdfaec2a911e7d34878156bfad1cca:/modules/Command.pm diff --git a/modules/Command.pm b/modules/Command.pm index 24e9a69..6c02aa1 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-12-16 +# Last modified: 2004-12-21 # use strict; @@ -72,7 +72,7 @@ sub exec_command($$$) } } - return error($config->{'errors'}->{'cmd_unknown'},'/',{COMMAND => $command}); + return error($config->{'errors'}->{'cmd_unknown'},'/',{COMMAND => encode_entities($command)}); } # exec_show() @@ -141,7 +141,7 @@ sub exec_show($$) $dtpl->fillin("DIR",$virt_path); $dtpl->fillin("DIR_NAME",encode_entities($dir)); $dtpl->fillin("DATE",encode_entities(strftime($config->{'timeformat'},localtime($stat[9])))); - $dtpl->fillin("URL",equal_url($config->{'httproot'},$virt_path)); + $dtpl->fillin("URL",equal_url(encode_entities($config->{'httproot'}),$virt_path)); $dtpl->parse_if_block("readable",-r $phys_path && -x $phys_path); $dtpl->parse_if_block("users",$users && -o $phys_path); @@ -167,7 +167,7 @@ sub exec_show($$) $ftpl->fillin("FILE_NAME",encode_entities($file)); $ftpl->fillin("SIZE",$stat[7]); $ftpl->fillin("DATE",encode_entities(strftime($config->{'timeformat'},localtime($stat[9])))); - $ftpl->fillin("URL",equal_url($config->{'httproot'},$virt_path)); + $ftpl->fillin("URL",equal_url(encode_entities($config->{'httproot'}),$virt_path)); $ftpl->parse_if_block("not_readable",not -r $phys_path); $ftpl->parse_if_block("binary",-B $phys_path); @@ -191,7 +191,7 @@ sub exec_show($$) $tpl->fillin("DIRLIST",$dirlist); $tpl->fillin("DIR",encode_entities($virtual)); $tpl->fillin("SCRIPT",$script); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); + $tpl->fillin("URL",encode_entities(equal_url($config->{'httproot'},$virtual))); $tpl->parse_if_block("dir_writeable",$dir_writeable); } @@ -228,7 +228,7 @@ sub exec_show($$) $tpl->fillin("FILE",encode_entities($virtual)); $tpl->fillin("DIR",$upper_path); - $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual)); + $tpl->fillin("URL",encode_entities(equal_url($config->{'httproot'},$virtual))); $tpl->fillin("SCRIPT",$script); $tpl->parse_if_block("editable",-w $physical && $uselist->unused($virtual)); @@ -493,24 +493,23 @@ sub exec_upload($$) my $file_phys = $physical."/".$filename; my $file_virt = $virtual.$filename; - return error($config->{'errors'}->{'in_use'},$virtual,{FILE => $file_virt}) if($data->{'uselist'}->in_use($file_virt)); - return error($config->{'errors'}->{'file_exists'},$virtual,{FILE => $file_virt}) if(-e $file_phys && not $cgi->param('overwrite')); + return error($config->{'errors'}->{'in_use'},$virtual,{FILE => $file_virt}) if($data->{'uselist'}->in_use($file_virt)); + + if(-e $file_phys) + { + return error($config->{'errors'}->{'dir_replace'},$virtual) if(-d $file_phys); + return error($config->{'errors'}->{'exist_no_write'},$virtual,{FILE => $file_virt}) unless(-w $file_phys); + return error($config->{'errors'}->{'file_exists'},$virtual,{FILE => $file_virt}) unless($cgi->param('overwrite')); + } my $ascii = $cgi->param('ascii'); my $handle = $cgi->upload('uploaded_file'); - local *FILE; - - open(FILE,">".$file_phys) or return error($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE => $file_virt}); - binmode(FILE) unless($ascii); - # Read transferred file and write it to disk read($handle, my $data, -s $handle); $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode - print FILE $data; - - close(FILE); + file_save($file_phys,\$data,not $ascii) or return error($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE => $file_virt}); return devedit_reload({command => "show", file => $virtual}); } @@ -547,8 +546,8 @@ sub exec_copy($$) my $dir = upper_path($virtual); my $new_physical = $data->{'new_physical'}; - return error($config->{'errors'}->{'dircopy'},upper_path($virtual)) if(-d $physical); - return error($config->{'errors'}->{'no_copy'},upper_path($virtual)) unless(-r $physical); + return error($config->{'errors'}->{'dircopy'},$dir) if(-d $physical); + return error($config->{'errors'}->{'no_copy'},$dir) unless(-r $physical); if($new_physical) { @@ -558,13 +557,11 @@ sub exec_copy($$) if(-e $new_physical) { - return error($config->{'errors'}->{'exist_edited'},$new_dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'})); + return error($config->{'errors'}->{'exist_edited'},$new_dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'})); + return error($config->{'errors'}->{'dir_replace'},$new_dir) if(-d $new_physical); + return error($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE => $new_virtual}) unless(-w $new_physical); - if(-d $new_physical) - { - return error($config->{'errors'}->{'dir_replace'},$new_dir); - } - elsif(not $data->{'cgi'}->param('confirmed')) + if(not $data->{'cgi'}->param('confirmed')) { my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'confirm_replace'}); @@ -623,8 +620,8 @@ sub exec_rename($$) my $dir = upper_path($virtual); my $new_physical = $data->{'new_physical'}; - return error($config->{'errors'}->{'rename_root'},"/") if($virtual eq "/"); - return error($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path($physical)); + return error($config->{'errors'}->{'rename_root'},"/") if($virtual eq "/"); + return error($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path($physical)); return error($config->{'errors'}->{'in_use'},$dir,{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual)); if($new_physical) @@ -635,13 +632,11 @@ sub exec_rename($$) if(-e $new_physical) { - return error($config->{'errors'}->{'exist_edited'},$new_dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'})); + return error($config->{'errors'}->{'exist_edited'},$new_dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'})); + return error($config->{'errors'}->{'dir_replace'},$new_dir) if(-d $new_physical); + return error($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE => $new_virtual}) unless(-w $new_physical); - if(-d $new_physical) - { - return error($config->{'errors'}->{'dir_replace'},$new_dir); - } - elsif(not $data->{'cgi'}->param('confirmed')) + if(not $data->{'cgi'}->param('confirmed')) { my $tpl = new Template; $tpl->read_file($config->{'templates'}->{'confirm_replace'});