# Execute Dev-Editor's commands
#
# Author: Patrick Canterino <patrick@patshaping.de>
-# Last modified: 2005-04-10
+# Last modified: 2005-04-15
#
use strict;
use Output;
use Template;
-use Data::Dumper;
-
my $script = encode_entities($ENV{'SCRIPT_NAME'});
my $users = eval('getpwuid(0)') && eval('getgrgid(0)');
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'};
- my $dir_writeable = -w $physical;
-
my $dirlist = '';
my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
$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('dir_writeable',-w $physical);
$tpl->parse_if_block('filter',$filter2);
$tpl->parse_if_block('gmt',$config->{'use_gmt'});
}
# ... and show the editing form
- my $content = file_read($physical,1);
+ my $content = file_read($physical);
my $md5sum = md5_hex($$content);
$$content =~ s/\015\012|\012|\015/\n/g;
sysopen(FILE,$physical,O_RDWR | O_CREAT) or return error($config->{'errors'}->{'edit_failed'},$dir,{FILE => $virtual});
file_lock(*FILE,LOCK_EX) or do { close(FILE); return error($config->{'errors'}->{'edit_failed'},$dir,{FILE => $virtual}) };
- binmode(FILE);
my $md5 = new Digest::MD5;
$md5->addfile(*FILE);
- my $md5_new = $md5->hexdigest;
+ my $md5file = $md5->hexdigest;
+ my $md5data = md5_hex($content);
- if($md5_new ne $md5sum && not $cgi->param('saveas'))
+ if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
{
# The file changed meanwhile
$tpl->fillin('DIR',$dir);
$tpl->fillin('URL',equal_url($config->{'httproot'},$virtual));
$tpl->fillin('SCRIPT',$script);
- $tpl->fillin('MD5SUM',$md5_new);
+ $tpl->fillin('MD5SUM',$md5file);
$tpl->fillin('CONTENT',encode_entities($content));
$tpl->parse_if_block('error',1);
}
else
{
- # The file was saved successfully!
-
- seek(FILE,0,0);
- truncate(FILE,0);
+ if($md5data ne $md5file)
+ {
+ seek(FILE,0,0);
+ truncate(FILE,0);
- print FILE $content;
+ print FILE $content;
+ }
$output = devedit_reload({command => 'show', file => $dir});
-
- #return error($config->{'errors'}->{'edit_failed'},$dir,{FILE => $virtual});
}
close(FILE);
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');
+ my $ascii = $cgi->param('ascii');
+ my $handle = $cgi->upload('uploaded_file');
return error($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
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));
if($new_physical)
{