X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/548d69a4ee38cc59612e787f479ac198d5c37741..4420382fd54774603ff1d4b23bf321280051a1ce:/modules/Command.pm diff --git a/modules/Command.pm b/modules/Command.pm index bb335dd..b9467a5 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: 2005-01-06 +# Last modified: 2005-04-22 # use strict; @@ -96,14 +96,14 @@ sub exec_show($$) my $tpl = new Template; - if(-d $physical) + if(-d $physical && not -l $physical) { # Create directory listing return error($config->{'errors'}->{'no_dir_access'},$upper_path) unless(-r $physical && -x $physical); my $direntries = dir_read($physical); - return error($config->{'dir_read_fail'},$upper_path,{DIR => encode_entities($virtual)}) unless($direntries); + return error($config->{'errors'}->{'dir_read_fail'},$upper_path,{DIR => encode_entities($virtual)}) unless($direntries); my $files = $direntries->{'files'}; my $dirs = $direntries->{'dirs'}; @@ -116,7 +116,7 @@ sub exec_show($$) my $filter2 = ($filter1 && $filter1 ne '*') ? $filter1 : ''; # Wildcard for output # Create the link to the upper directory - # (only if we are not in the root directory) + # (only if the current directory is not the root directory) unless($virtual eq '/') { @@ -126,7 +126,7 @@ sub exec_show($$) $udtpl->read_file($config->{'templates'}->{'dirlist_up'}); $udtpl->fillin('UPPER_DIR',$upper_path); - $udtpl->fillin('DATE',encode_entities(strftime($config->{'timeformat'},localtime($stat[9])))); + $udtpl->fillin('DATE',encode_entities(strftime($config->{'timeformat'},($config->{'use_gmt'}) ? gmtime($stat[9]) : localtime($stat[9])))); $dirlist .= $udtpl->get_template; } @@ -147,7 +147,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('DATE',encode_entities(strftime($config->{'timeformat'},($config->{'use_gmt'}) ? gmtime($stat[9]) : localtime($stat[9])))); $dtpl->fillin('URL',equal_url(encode_entities($config->{'httproot'}),$virt_path)); $dtpl->parse_if_block('readable',-r $phys_path && -x $phys_path); @@ -165,7 +165,7 @@ sub exec_show($$) my $phys_path = $physical.'/'.$file; my $virt_path = encode_entities($virtual.$file); - my @stat = stat($phys_path); + my @stat = lstat($phys_path); my $in_use = $uselist->in_use($virtual.$file); my $too_large = $config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'}; @@ -175,15 +175,17 @@ sub exec_show($$) $ftpl->fillin('FILE',$virt_path); $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('DATE',encode_entities(strftime($config->{'timeformat'},($config->{'use_gmt'}) ? gmtime($stat[9]) : localtime($stat[9])))); $ftpl->fillin('URL',equal_url(encode_entities($config->{'httproot'}),$virt_path)); + $ftpl->parse_if_block('link',-l $phys_path); + $ftpl->parse_if_block('no_link',not -l $phys_path); $ftpl->parse_if_block('not_readable',not -r $phys_path); $ftpl->parse_if_block('binary',-B $phys_path); $ftpl->parse_if_block('readonly',not -w $phys_path); - $ftpl->parse_if_block('viewable',-r $phys_path && -T $phys_path && not $too_large); - $ftpl->parse_if_block('editable',(-r $phys_path && -w $phys_path && -T $phys_path && not $too_large) && not $in_use); + $ftpl->parse_if_block('viewable',(-r $phys_path && -T $phys_path && not $too_large) || -l $phys_path); + $ftpl->parse_if_block('editable',((-r $phys_path && -w $phys_path && -T $phys_path && not $too_large) && not $in_use) && not -l $phys_path); $ftpl->parse_if_block('in_use',$in_use); $ftpl->parse_if_block('unused',not $in_use); @@ -205,8 +207,25 @@ sub exec_show($$) $tpl->fillin('FILTER',encode_entities($filter2)); $tpl->fillin('FILTER_URL',escape($filter2)); + $tpl->parse_if_block('empty',$dirlist eq ''); $tpl->parse_if_block('dir_writeable',$dir_writeable); $tpl->parse_if_block('filter',$filter2); + $tpl->parse_if_block('gmt',$config->{'use_gmt'}); + } + elsif(-l $physical) + { + # Show the target of a symbolic link + + my $link_target = readlink($physical); + + $tpl->read_file($config->{'templates'}->{'viewlink'}); + + $tpl->fillin('FILE',encode_entities($virtual)); + $tpl->fillin('DIR',$upper_path); + $tpl->fillin('URL',encode_entities(equal_url($config->{'httproot'},$virtual))); + $tpl->fillin('SCRIPT',$script); + + $tpl->fillin('LINK_TARGET',encode_entities($link_target)); } else { @@ -264,9 +283,10 @@ sub exec_beginedit($$) my $dir = upper_path($virtual); my $uselist = $data->{'uselist'}; - return error($config->{'errors'}->{'editdir'},$dir) if(-d $physical); - return error($config->{'errors'}->{'in_use'}, $dir,{FILE => $virtual}) if($uselist->in_use($virtual)); - return error($config->{'errors'}->{'no_edit'},$dir) unless(-r $physical && -w $physical); + return error($config->{'errors'}->{'link_edit'},$dir) if(-l $physical); + return error($config->{'errors'}->{'dir_edit'}, $dir) if(-d $physical); + return error($config->{'errors'}->{'in_use'}, $dir,{FILE => $virtual}) if($uselist->in_use($virtual)); + return error($config->{'errors'}->{'no_edit'}, $dir) unless(-r $physical && -w $physical); # Check on binary files @@ -278,8 +298,8 @@ sub exec_beginedit($$) # Lock the file... - $uselist->add_file($virtual); - $uselist->save; + ($uselist->add_file($virtual) and + $uselist->save) or return error($config->{'errors'}->{'ul_add_failed'},$dir,{FILE => $virtual}); # ... and show the editing form @@ -314,9 +334,11 @@ sub exec_canceledit($$) { my ($data,$config) = @_; my $virtual = $data->{'virtual'}; + my $dir = upper_path($virtual); + my $uselist = $data->{'uselist'}; - file_unlock($data->{'uselist'},$virtual); - return devedit_reload({command => 'show', file => upper_path($virtual)}); + file_unlock($uselist,$virtual) or return error($config->{'errors'}->{'ul_rm_failed'},$dir,{FILE => $virtual, USELIST => $uselist->{'listfile'}}); + return devedit_reload({command => 'show', file => $dir}); } # exec_endedit() @@ -342,7 +364,7 @@ sub exec_endedit($$) # No other user of Dev-Editor will access the file during this # routine because of the concept of File::UseList. - file_unlock($uselist,$virtual); + file_unlock($uselist,$virtual) or return error($config->{'errors'}->{'ul_rm_failed'},$dir,{FILE => $virtual, USELIST => $uselist->{'listfile'}}); # Normalize newlines @@ -367,13 +389,14 @@ sub exec_endedit($$) return error($config->{'errors'}->{'in_use'},$dir,{FILE => $virtual}) if($uselist->in_use($virtual)); } - return error($config->{'errors'}->{'editdir'},$dir) if(-d $physical); + return error($config->{'errors'}->{'link_edit'},$dir) if(-l $physical); + return error($config->{'errors'}->{'dir_edit'},$dir) if(-d $physical); return error($config->{'errors'}->{'no_edit'},$dir) if(-e $physical && !(-r $physical && -w $physical)); - return error($config->{'errors'}->{'text_to_binary'},$dir) unless(-T $physical); + return error($config->{'errors'}->{'text_to_binary'},$dir) if(-e $physical && not -T $physical); if(file_save($physical,\$content)) { - # Saving of the file was successful! + # The file was successfully saved! return devedit_reload({command => 'show', file => $dir}); } @@ -463,7 +486,7 @@ sub exec_mkdir($$) # exec_upload() # -# Upload a file +# Process a file upload # # Params: 1. Reference to user input hash # 2. Reference to config hash @@ -477,7 +500,7 @@ sub exec_upload($$) my $virtual = $data->{'virtual'}; my $cgi = $data->{'cgi'}; - return error($config->{'errors'}->{'no_directory'},upper_path($virtual),{FILE => $virtual}) unless(-d $physical); + return error($config->{'errors'}->{'no_directory'},upper_path($virtual),{FILE => $virtual}) unless(-d $physical && not -l $physical); return error($config->{'errors'}->{'dir_no_create'},$virtual,{DIR => $virtual}) unless(-w $physical); if(my $uploaded_file = $cgi->param('uploaded_file')) @@ -492,6 +515,7 @@ sub exec_upload($$) if(-e $file_phys) { + return error($config->{'errors'}->{'link_replace'},$virtual) if(-l $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')); @@ -543,8 +567,9 @@ sub exec_copy($$) my $dir = upper_path($virtual); my $new_physical = $data->{'new_physical'}; - return error($config->{'errors'}->{'dircopy'},$dir) if(-d $physical); - return error($config->{'errors'}->{'no_copy'},$dir) unless(-r $physical); + return error($config->{'errors'}->{'link_copy'},$dir) if(-l $physical); + return error($config->{'errors'}->{'dir_copy'},$dir) if(-d $physical); + return error($config->{'errors'}->{'no_copy'},$dir) unless(-r $physical); if($new_physical) { @@ -555,6 +580,7 @@ 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'}->{'link_replace'},$new_dir) if(-l $new_physical); 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); @@ -630,7 +656,7 @@ 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'}->{'dir_replace'},$new_dir) if(-d $new_physical); + return error($config->{'errors'}->{'dir_replace'},$new_dir) if(-d $new_physical && not -l $new_physical); return error($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE => $new_virtual}) unless(-w $new_physical); if(not $data->{'cgi'}->param('confirmed')) @@ -655,7 +681,7 @@ sub exec_rename($$) } } - rename($physical,$new_physical) or return error($config->{'errors'}->{'rename_failed'},$dir,{FILE => $virtual, NEW_FILE => $new_virtual}); + move($physical,$new_physical) or return error($config->{'errors'}->{'rename_failed'},$dir,{FILE => $virtual, NEW_FILE => $new_virtual}); return devedit_reload({command => 'show', file => $new_dir}); } else @@ -694,7 +720,7 @@ sub exec_remove($$) return error($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/'); return error($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path($physical)); - if(-d $physical) + if(-d $physical && not -l $physical) { # Remove a directory @@ -767,6 +793,7 @@ sub exec_chprop($$) return error($config->{'errors'}->{'no_users'},$dir,{FILE => $virtual}) unless($users); return error($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/'); return error($config->{'errors'}->{'not_owner'},$dir,{FILE => $virtual}) unless(-o $physical); + return error($config->{'errors'}->{'chprop_link'},$dir) if(-l $physical); return error($config->{'errors'}->{'in_use'},$dir,{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual)); my $cgi = $data->{'cgi'}; @@ -854,7 +881,7 @@ sub exec_unlock($$) if($data->{'cgi'}->param('confirmed')) { - file_unlock($uselist,$virtual); + file_unlock($uselist,$virtual) or return error($config->{'errors'}->{'ul_rm_failed'},$dir,{FILE => $virtual, USELIST => $uselist->{'listfile'}}); return devedit_reload({command => 'show', file => $dir}); } else @@ -912,13 +939,16 @@ sub exec_about($$) $tpl->fillin('HTTPD',encode_entities($ENV{'SERVER_SOFTWARE'})); $tpl->fillin('OS', encode_entities($^O)); - $tpl->fillin('TIME', encode_entities(strftime($config->{'timeformat'},localtime))); + $tpl->fillin('TIME', encode_entities(strftime($config->{'timeformat'},($config->{'use_gmt'}) ? gmtime : localtime))); + + $tpl->parse_if_block('gmt',$config->{'use_gmt'}); # Process information $tpl->fillin('PID',$$); - # Check if the functions getpwuid() and getgrgid() are available + # The following information is only available on systems supporting + # users and groups if($users) {