]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
ec7ca69ed2098779b9882c34532159025e461383
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2010-10-30
11 # Copyright (C) 1999-2000 Roland Bluethgen, Frank Schoenmann
12 # Copyright (C) 2003-2009 Patrick Canterino
13 # All Rights Reserved.
15 # This file can be distributed and/or modified under the terms of
16 # of the Artistic License 1.0 (see also the LICENSE file found at
17 # the top level of the Dev-Editor distribution).
29 use Digest::MD5 qw(md5_hex);
30 use POSIX
qw(strftime);
39 my $script = encode_html
($ENV{'SCRIPT_NAME'});
40 my $users = eval('getpwuid(0)') && eval('getgrgid(0)');
42 my %dispatch = ('show' => \
&exec_show
,
43 'beginedit' => \
&exec_beginedit
,
44 'endedit' => \
&exec_endedit
,
45 'download' => \
&exec_download
,
46 'mkdir' => \
&exec_mkdir
,
47 'mkfile' => \
&exec_mkfile
,
48 'upload' => \
&exec_upload
,
49 'unpack' => \
&exec_unpack
,
50 'copy' => \
&exec_copy
,
51 'rename' => \
&exec_rename
,
52 'remove' => \
&exec_remove
,
53 'remove_multi' => \
&exec_remove_multi
,
54 'chprop' => \
&exec_chprop
,
55 'about' => \
&exec_about
60 use base
qw(Exporter);
62 @EXPORT = qw(exec_command);
66 # Execute the specified command
68 # Params: 1. Command to execute
69 # 2. Reference to user input hash
70 # 3. Reference to config hash
72 # Return: Output of the command (Scalar Reference)
76 my ($command,$data,$config) = @_;
78 foreach(keys(%dispatch))
80 if(lc($_) eq lc($command))
82 my $output = &{$dispatch{$_}}($data,$config);
87 return error
($config->{'errors'}->{'command_unknown'},'/',{COMMAND
=> encode_html
($command)});
92 # View a directory or a file
94 # Params: 1. Reference to user input hash
95 # 2. Reference to config hash
97 # Return: Output of the command (Scalar Reference)
101 my ($data,$config) = @_;
102 my $physical = $data->{'physical'};
103 my $virtual = $data->{'virtual'};
104 my $upper_path = multi_string
(upper_path
($virtual));
106 my $tpl = new Template
;
108 if(-d
$physical && not -l
$physical)
110 # Create directory listing
112 return error
($config->{'errors'}->{'no_dir_access'},$upper_path->{'normal'}) unless(-r
$physical && -x
$physical);
114 my $direntries = dir_read
($physical);
115 return error
($config->{'errors'}->{'dir_read_failed'},$upper_path->{'normal'},{DIR
=> encode_html
($virtual)}) unless($direntries);
117 my $files = $direntries->{'files'};
118 my $dirs = $direntries->{'dirs'};
124 my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
125 my $filter2 = ($filter1 && $filter1 ne '*') ?
$filter1 : ''; # Wildcard for output
127 # Create the link to the upper directory
128 # (only if the current directory is not the root directory)
130 unless($virtual eq '/')
134 my @stat = stat($physical.'/..');
136 my $udtpl = new Template
;
137 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
139 $udtpl->fillin('UPPER_DIR',$upper_path->{'html'});
140 $udtpl->fillin('UPPER_DIR_URL',$upper_path->{'url'});
141 $udtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
143 $dirlist .= $udtpl->get_template;
148 foreach my $dir(@
$dirs)
150 next if($config->{'hide_dot_files'} && substr($dir,0,1) eq '.');
151 next unless(dos_wildcard_match
($filter1,$dir));
155 my $phys_path = $physical.'/'.$dir;
156 my $virt_path = multi_string
($virtual.$dir.'/');
158 my @stat = stat($phys_path);
160 my $dtpl = new Template
;
161 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
163 $dtpl->fillin('DIR',$virt_path->{'html'});
164 $dtpl->fillin('DIR_URL',$virt_path->{'url'});
165 $dtpl->fillin('DIR_NAME',encode_html
($dir));
166 $dtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
167 $dtpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
169 $dtpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
170 $dtpl->parse_if_block('readable',-r
$phys_path && -x
$phys_path);
171 $dtpl->parse_if_block('users',$users && -o
$phys_path);
172 $dtpl->parse_if_block('even',($count % 2) == 0);
174 $dirlist .= $dtpl->get_template;
179 foreach my $file(@
$files)
181 next if($config->{'hide_dot_files'} && substr($file,0,1) eq '.');
182 next unless(dos_wildcard_match
($filter1,$file));
186 my $phys_path = $physical.'/'.$file;
187 my $virt_path = multi_string
($virtual.$file);
189 my @stat = lstat($phys_path);
190 my $too_large = $config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'};
192 my $ftpl = new Template
;
193 $ftpl->read_file($config->{'templates'}->{'dirlist_file'});
195 $ftpl->fillin('FILE',$virt_path->{'html'});
196 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
197 $ftpl->fillin('FILE_NAME',encode_html
($file));
198 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
199 $ftpl->fillin('SIZE',$stat[7]);
200 $ftpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
201 $ftpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
203 $ftpl->parse_if_block('link',-l
$phys_path);
204 $ftpl->parse_if_block('readable',-r
$phys_path);
205 $ftpl->parse_if_block('writeable',-w
$phys_path);
206 $ftpl->parse_if_block('binary',-B
$phys_path);
208 $ftpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
209 $ftpl->parse_if_block('viewable',(-r
$phys_path && -T
$phys_path && not $too_large) || -l
$phys_path);
210 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not -l
$phys_path);
212 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
214 $ftpl->parse_if_block('users',$users && -o
$phys_path);
216 $ftpl->parse_if_block('archive',$File::Access
::has_archive_extract
&& is_archive
($file));
218 $ftpl->parse_if_block('even',($count % 2) == 0);
220 $dirlist .= $ftpl->get_template;
223 $tpl->read_file($config->{'templates'}->{'dirlist'});
225 $tpl->fillin('DIRLIST',$dirlist);
226 $tpl->fillin('DIR',encode_html
($virtual));
227 $tpl->fillin('DIR_URL',escape
($virtual));
228 $tpl->fillin('SCRIPT',$script);
229 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
231 $tpl->fillin('FILTER',encode_html
($filter2));
232 $tpl->fillin('FILTER_URL',escape
($filter2));
234 $tpl->parse_if_block('empty',$dirlist eq '');
235 $tpl->parse_if_block('dir_writeable',-w
$physical);
236 $tpl->parse_if_block('filter',$filter2);
237 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
241 # Show the target of a symbolic link
243 my $link_target = readlink($physical);
245 $tpl->read_file($config->{'templates'}->{'viewlink'});
247 $tpl->fillin('FILE',encode_html
($virtual));
248 $tpl->fillin('DIR',$upper_path->{'html'});
249 $tpl->fillin('DIR_URL',$upper_path->{'url'});
250 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
251 $tpl->fillin('SCRIPT',$script);
253 $tpl->fillin('LINK_TARGET',encode_html
($link_target));
259 return error
($config->{'errors'}->{'no_view'},$upper_path->{'normal'}) unless(-r
$physical);
261 # Check on binary files
262 # We have to do it in this way or empty files will be recognized
265 return error
($config->{'errors'}->{'binary_file'},$upper_path->{'normal'}) unless(-T
$physical);
267 # Is the file too large?
269 return error
($config->{'errors'}->{'file_too_large'},$upper_path->{'normal'},{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
273 my $content = file_read
($physical);
274 $$content =~ s/\015\012|\012|\015/\n/g;
276 $tpl->read_file($config->{'templates'}->{'viewfile'});
278 $tpl->fillin('FILE',encode_html
($virtual));
279 $tpl->fillin('FILE_URL',escape
($virtual));
280 $tpl->fillin('DIR',$upper_path->{'html'});
281 $tpl->fillin('DIR_URL',$upper_path->{'url'});
282 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
283 $tpl->fillin('SCRIPT',$script);
285 $tpl->parse_if_block('editable',-w
$physical);
287 $tpl->fillin('CONTENT',encode_html
($$content));
290 my $output = header
(-type
=> 'text/html');
291 $output .= $tpl->get_template;
298 # Lock a file and display a form to edit it
300 # Params: 1. Reference to user input hash
301 # 2. Reference to config hash
303 # Return: Output of the command (Scalar Reference)
305 sub exec_beginedit
($$)
307 my ($data,$config) = @_;
308 my $physical = $data->{'physical'};
309 my $virtual = $data->{'virtual'};
310 my $dir = upper_path
($virtual);
312 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
313 return error
($config->{'errors'}->{'dir_edit'}, $dir) if(-d
$physical);
314 return error
($config->{'errors'}->{'no_edit'}, $dir) unless(-r
$physical && -w
$physical);
316 # Check on binary files
318 return error
($config->{'errors'}->{'binary_file'},$dir) unless(-T
$physical);
320 # Is the file too large?
322 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
324 # Show the editing form
326 my $content = file_read
($physical);
327 my $md5sum = md5_hex
($$content);
328 $$content =~ s/\015\012|\012|\015/\n/g;
330 my $tpl = new Template
;
331 $tpl->read_file($config->{'templates'}->{'editfile'});
333 $tpl->fillin('FILE',encode_html
($virtual));
334 $tpl->fillin('FILE_URL',escape
($virtual));
335 $tpl->fillin('DIR',encode_html
($dir));
336 $tpl->fillin('DIR_URL',escape
($dir));
337 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
338 $tpl->fillin('SCRIPT',$script);
339 $tpl->fillin('MD5SUM',$md5sum);
340 $tpl->fillin('CONTENT',encode_html
($$content));
342 $tpl->parse_if_block('error',0);
344 my $output = header
(-type
=> 'text/html');
345 $output .= $tpl->get_template;
352 # Save a file, unlock it and return to directory view
354 # Params: 1. Reference to user input hash
355 # 2. Reference to config hash
357 # Return: Output of the command (Scalar Reference)
361 my ($data,$config) = @_;
362 my $physical = $data->{'physical'};
363 my $virtual = $data->{'virtual'};
364 my $dir = upper_path
($virtual);
365 my $cgi = $data->{'cgi'};
366 my $content = $cgi->param('filecontent');
367 my $md5sum = $cgi->param('md5sum');
370 if(defined $content && $md5sum)
374 $content =~ s/\015\012|\012|\015/\n/g;
376 if($cgi->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
378 # Create the new filename
380 $physical = $data->{'new_physical'};
381 $virtual = $data->{'new_virtual'};
384 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
385 return error
($config->{'errors'}->{'dir_edit'},$dir) if(-d
$physical);
386 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
387 return error
($config->{'errors'}->{'text_to_binary'},$dir) if(-e
$physical && not -T
$physical);
389 # For technical reasons, we can't use file_save() for
394 sysopen(FILE
,$physical,O_RDWR
| O_CREAT
) or return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)});
395 file_lock
(*FILE
,LOCK_EX
) or do { close(FILE
); return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)}) };
397 my $md5 = new Digest
::MD5
;
398 $md5->addfile(*FILE
);
400 my $md5file = $md5->hexdigest;
401 my $md5data = md5_hex
($content);
403 if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
405 # The file changed meanwhile
407 my $tpl = new Template
;
408 $tpl->read_file($config->{'templates'}->{'editfile'});
410 $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
412 $tpl->fillin('FILE',encode_html
($virtual));
413 $tpl->fillin('FILE_URL',escape
($virtual));
414 $tpl->fillin('DIR',encode_html
($dir));
415 $tpl->fillin('DIR_URL',escape
($dir));
416 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
417 $tpl->fillin('SCRIPT',$script);
418 $tpl->fillin('MD5SUM',$md5file);
419 $tpl->fillin('CONTENT',encode_html
($content));
421 $tpl->parse_if_block('error',1);
423 my $data = header
(-type
=> 'text/html');
424 $data .= $tpl->get_template;
430 if($md5data ne $md5file)
438 $output = ($cgi->param('continue'))
439 ? devedit_reload
({command
=> 'beginedit', file
=> $virtual})
440 : devedit_reload
({command
=> 'show', file
=> $dir});
448 return devedit_reload
({command
=> 'beginedit', file
=> $virtual});
453 # Execute a HTTP download of a file
455 # Params: 1. Reference to user input hash
456 # 2. Reference to config hash
458 # Return: Output of the command (Scalar Reference)
460 sub exec_download
($$)
462 my ($data,$config) = @_;
463 my $physical = $data->{'physical'};
464 my $virtual = $data->{'virtual'};
465 my $dir = upper_path
($virtual);
467 return return error
($config->{'errors'}->{'no_download'},$dir,{FILE
=> $virtual}) if((not -r
$physical) || (-d
$physical || -l
$physical));
469 my $filename = file_name
($virtual);
471 my $output = header
(-type
=> 'application/octet-stream', -attachment
=> $filename);
472 $output .= ${ file_read
($physical,1) };
479 # Create a file and return to directory view
481 # Params: 1. Reference to user input hash
482 # 2. Reference to config hash
484 # Return: Output of the command (Scalar Reference)
488 my ($data,$config) = @_;
489 my $new_physical = $data->{'new_physical'};
490 my $new_virtual = $data->{'new_virtual'};
491 my $dir = upper_path
($new_virtual);
492 $new_virtual = encode_html
($new_virtual);
496 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
498 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
500 if($data->{'cgi'}->param('edit'))
502 return devedit_reload
({command
=> 'beginedit', file
=> $new_virtual});
506 return devedit_reload
({command
=> 'show', file
=> $dir});
511 my $tpl = new Template
;
512 $tpl->read_file($config->{'templates'}->{'mkfile'});
514 $tpl->fillin('DIR','/');
515 $tpl->fillin('SCRIPT',$script);
517 my $output = header
(-type
=> 'text/html');
518 $output .= $tpl->get_template;
526 # Create a directory and return to directory view
528 # Params: 1. Reference to user input hash
529 # 2. Reference to config hash
531 # Return: Output of the command (Scalar Reference)
535 my ($data,$config) = @_;
536 my $new_physical = $data->{'new_physical'};
537 my $new_virtual = $data->{'new_virtual'};
538 my $dir = upper_path
($new_virtual);
539 $new_virtual = encode_html
($new_virtual);
543 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
545 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
546 return devedit_reload
({command
=> 'show', file
=> $dir});
550 my $tpl = new Template
;
551 $tpl->read_file($config->{'templates'}->{'mkdir'});
553 $tpl->fillin('DIR','/');
554 $tpl->fillin('SCRIPT',$script);
556 my $output = header
(-type
=> 'text/html');
557 $output .= $tpl->get_template;
565 # Process a file upload
567 # Params: 1. Reference to user input hash
568 # 2. Reference to config hash
570 # Return: Output of the command (Scalar Reference)
574 my ($data,$config) = @_;
575 my $physical = $data->{'physical'};
576 my $virtual = $data->{'virtual'};
577 my $cgi = $data->{'cgi'};
579 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> encode_html
($virtual)}) unless(-d
$physical && not -l
$physical);
580 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> encode_html
($virtual)}) unless(-w
$physical);
582 if(my $uploaded_file = $cgi->param('uploaded_file'))
584 if($cgi->param('remote_file'))
586 $uploaded_file = $cgi->param('remote_file');
588 $uploaded_file =~ s!/!!g;
589 $uploaded_file =~ s!\\!!g;
592 # Process file upload
594 my $filename = file_name
($uploaded_file);
595 my $file_phys = $physical.'/'.$filename;
596 my $file_virt = encode_html
($virtual.$filename);
600 return error
($config->{'errors'}->{'link_replace'},$virtual) if(-l
$file_phys);
601 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
602 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
603 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
606 my $ascii = $cgi->param('ascii');
607 my $handle = $cgi->upload('uploaded_file');
609 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
611 # Read transferred file and write it to disk
613 read($handle, my $data, -s
$handle);
614 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
615 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
617 return devedit_reload
({command
=> 'show', file
=> $virtual});
621 my $tpl = new Template
;
622 $tpl->read_file($config->{'templates'}->{'upload'});
624 $tpl->fillin('DIR',encode_html
($virtual));
625 $tpl->fillin('DIR_URL',escape
($virtual));
626 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
627 $tpl->fillin('SCRIPT',$script);
629 my $output = header
(-type
=> 'text/html');
630 $output .= $tpl->get_template;
640 # Params: 1. Reference to user input hash
641 # 2. Reference to config hash
643 # Return: Output of the command (Scalar Reference)
647 my ($data,$config) = @_;
648 my $physical = $data->{'physical'};
649 my $virtual = $data->{'virtual'};
650 my $dir = upper_path
($virtual);
651 my $new_physical = $data->{'new_physical'};
652 my $new_virtual = $data->{'new_virtual'};
653 my $cgi = $data->{'cgi'};
655 return error
($config->{'errors'}->{'no_ae'},$dir) unless($File::Access
::has_archive_extract
);
656 return error
($config->{'errors'}->{'no_archive'},$dir,{FILE
=> encode_html
($virtual)}) unless(is_archive
($physical));
660 return error
($config->{'errors'}->{'unpack_no_dir'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> encode_html
($new_virtual)}) if(-l
$new_physical || not -d
$new_physical);
662 my $return_unpack = archive_unpack
($physical,$new_physical);
664 return error
($config->{'errors'}->{'unpack_failed'},$dir,{FILE
=> encode_html
($virtual), AE_ERROR
=> ''}) unless($return_unpack);
666 return devedit_reload
({command
=> 'show', file
=> $new_virtual});
670 my $tpl = new Template
;
671 $tpl->read_file($config->{'templates'}->{'unpack'});
673 $tpl->fillin('FILE',encode_html
($virtual));
674 $tpl->fillin('DIR',encode_html
($dir));
675 $tpl->fillin('DIR_URL',escape
($dir));
676 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
677 $tpl->fillin('SCRIPT',$script);
679 my $output = header
(-type
=> 'text/html');
680 $output .= $tpl->get_template;
688 # Copy a file and return to directory view
690 # Params: 1. Reference to user input hash
691 # 2. Reference to config hash
693 # Return: Output of the command (Scalar Reference)
697 my ($data,$config) = @_;
698 my $physical = $data->{'physical'};
699 my $virtual = $data->{'virtual'};
700 my $dir = upper_path
($virtual);
701 my $new_physical = $data->{'new_physical'};
703 return error
($config->{'errors'}->{'link_copy'},$dir) if(-l
$physical);
704 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
708 my $new_virtual = multi_string
($data->{'new_virtual'});
709 my $new_dir = upper_path
($new_virtual->{'normal'});
713 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-x
$physical);
714 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual->{'html'}}) if(-e
$new_physical);
715 return error
($config->{'errors'}->{'dir_copy_self'},$dir) if(index($new_virtual->{'normal'},$virtual) == 0);
717 dir_copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
718 return devedit_reload
({command
=> 'show', file
=> $new_dir});
724 return error
($config->{'errors'}->{'link_replace'},$new_dir) if(-l
$new_physical);
725 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
726 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual->{'html'}}) unless(-w
$new_physical);
728 if(not $data->{'cgi'}->param('confirmed'))
730 my $tpl = new Template
;
731 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
733 $tpl->fillin('FILE',encode_html
($virtual));
734 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
735 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
736 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
737 $tpl->fillin('DIR',encode_html
($dir));
738 $tpl->fillin('DIR_URL',escape
($dir));
740 $tpl->fillin('COMMAND','copy');
741 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
742 $tpl->fillin('SCRIPT',$script);
744 my $output = header
(-type
=> 'text/html');
745 $output .= $tpl->get_template;
751 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
752 return devedit_reload
({command
=> 'show', file
=> $new_dir});
759 my $tpl = new Template
;
760 $tpl->read_file($config->{'templates'}->{'copydir'});
762 $tpl->fillin('FILE',encode_html
($virtual));
763 $tpl->fillin('DIR',encode_html
($dir));
764 $tpl->fillin('DIR_URL',escape
($dir));
765 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
766 $tpl->fillin('SCRIPT',$script);
768 my $output = header
(-type
=> 'text/html');
769 $output .= $tpl->get_template;
775 my $tpl = new Template
;
776 $tpl->read_file($config->{'templates'}->{'copyfile'});
778 $tpl->fillin('FILE',encode_html
($virtual));
779 $tpl->fillin('DIR',encode_html
($dir));
780 $tpl->fillin('DIR_URL',escape
($dir));
781 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
782 $tpl->fillin('SCRIPT',$script);
784 my $output = header
(-type
=> 'text/html');
785 $output .= $tpl->get_template;
794 # Rename/move a file and return to directory view
796 # Params: 1. Reference to user input hash
797 # 2. Reference to config hash
799 # Return: Output of the command (Scalar Reference)
803 my ($data,$config) = @_;
804 my $physical = $data->{'physical'};
805 my $virtual = $data->{'virtual'};
806 my $dir = upper_path
($virtual);
807 my $new_physical = $data->{'new_physical'};
809 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
810 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
814 my $new_virtual = multi_string
($data->{'new_virtual'});
815 my $new_dir = upper_path
($new_virtual->{'normal'});
819 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical && not -l
$new_physical);
820 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
822 if(not $data->{'cgi'}->param('confirmed'))
824 my $tpl = new Template
;
825 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
827 $tpl->fillin('FILE',encode_html
($virtual));
828 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
829 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
830 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
831 $tpl->fillin('DIR',encode_html
($dir));
833 $tpl->fillin('COMMAND','rename');
834 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
835 $tpl->fillin('SCRIPT',$script);
837 my $output = header
(-type
=> 'text/html');
838 $output .= $tpl->get_template;
844 move
($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
845 return devedit_reload
({command
=> 'show', file
=> $new_dir});
849 my $tpl = new Template
;
850 $tpl->read_file($config->{'templates'}->{'renamefile'});
852 $tpl->fillin('FILE',encode_html
($virtual));
853 $tpl->fillin('DIR',encode_html
($dir));
854 $tpl->fillin('DIR_URL',escape
($dir));
855 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
856 $tpl->fillin('SCRIPT',$script);
858 my $output = header
(-type
=> 'text/html');
859 $output .= $tpl->get_template;
867 # Remove a file or a directory and return to directory view
869 # Params: 1. Reference to user input hash
870 # 2. Reference to config hash
872 # Return: Output of the command (Scalar Reference)
876 my ($data,$config) = @_;
877 my $physical = $data->{'physical'};
878 my $virtual = $data->{'virtual'};
879 my $dir = upper_path
($virtual);
881 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
882 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
884 if(-d
$physical && not -l
$physical)
888 if($data->{'cgi'}->param('confirmed'))
891 return devedit_reload
({command
=> 'show', file
=> $dir});
895 my $tpl = new Template
;
896 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
898 $tpl->fillin('DIR',encode_html
($virtual));
899 $tpl->fillin('DIR_URL',escape
($virtual));
900 $tpl->fillin('UPPER_DIR',encode_html
($dir));
901 $tpl->fillin('UPPER_DIR_URL',escape
($dir));
902 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
903 $tpl->fillin('SCRIPT',$script);
905 my $output = header
(-type
=> 'text/html');
906 $output .= $tpl->get_template;
915 if($data->{'cgi'}->param('confirmed'))
917 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
918 return devedit_reload
({command
=> 'show', file
=> $dir});
922 my $tpl = new Template
;
923 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
925 $tpl->fillin('FILE',encode_html
($virtual));
926 $tpl->fillin('FILE_URL',escape
($virtual));
927 $tpl->fillin('DIR',encode_html
($dir));
928 $tpl->fillin('DIR_URL',escape
($dir));
929 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
930 $tpl->fillin('SCRIPT',$script);
932 my $output = header
(-type
=> 'text/html');
933 $output .= $tpl->get_template;
940 # exec_remove_multi()
942 # Remove a file or a directory and return to directory view
944 # Params: 1. Reference to user input hash
945 # 2. Reference to config hash
947 # Return: Output of the command (Scalar Reference)
949 sub exec_remove_multi
($$)
951 my ($data,$config) = @_;
952 my $physical = $data->{'physical'};
953 my $virtual = $data->{'virtual'};
954 my $cgi = $data->{'cgi'};
956 my @files = $cgi->param('files');#
961 foreach my $file(@files)
963 # Filter out some "bad" files (e.g. files going up in the
964 # directory hierarchy or files containing slashes (it's too
967 next if($file =~ m!^\.+$!);
968 next if($file =~ m!/!);
969 next if($file =~ m!\\!);
971 push(@new_files,$file);
977 if($cgi->param('confirmed'))
982 foreach my $file(@new_files)
984 my $file_path = clean_path
($physical.'/'.$file);
988 if(-d
$file_path && not -l
$file_path)
992 if(rmtree
($file_path))
994 push(@success,clean_path
($file));
998 push(@failed,clean_path
($file));
1005 if(unlink($file_path))
1007 push(@success,clean_path
($file));
1011 push(@failed,clean_path
($file));
1017 push(@failed,clean_path
($file));
1021 my $tpl = new Template
;
1022 $tpl->read_file($config->{'templates'}->{'rmmulti'});
1024 if(scalar(@success) > 0)
1026 if(scalar(@success) == scalar(@new_files) && scalar(@failed) == 0)
1028 return devedit_reload
({command
=> 'show', file
=> $virtual});
1032 $tpl->parse_if_block('success',1);
1034 foreach my $file_success(@success)
1036 $tpl->add_loop_data('SUCCESS',{FILE
=> encode_html
($file_success),
1037 FILE_PATH
=> encode_html
(clean_path
($virtual.'/'.$file_success))});
1040 $tpl->parse_loop('SUCCESS');
1045 $tpl->parse_if_block('success',0);
1048 if(scalar(@failed) > 0)
1050 $tpl->parse_if_block('failed',1);
1052 foreach my $file_failed(@failed)
1054 $tpl->add_loop_data('FAILED',{FILE
=> encode_html
($file_failed),
1055 FILE_PATH
=> encode_html
(clean_path
($virtual.'/'.$file_failed))});
1058 $tpl->parse_loop('FAILED');
1062 $tpl->parse_if_block('failed',0);
1066 $tpl->fillin('DIR',encode_html
($virtual));
1067 $tpl->fillin('SCRIPT',$script);
1069 my $output = header
(-type
=> 'text/html');
1070 $output .= $tpl->get_template;
1076 my $tpl = new Template
;
1077 $tpl->read_file($config->{'templates'}->{'confirm_rmmulti'});
1079 foreach my $file(@new_files)
1081 $tpl->add_loop_data('FILES',{FILE
=> encode_html
($file),
1082 FILE_PATH
=> encode_html
(clean_path
($virtual.'/'.$file))});
1085 $tpl->parse_loop('FILES');
1087 $tpl->fillin('COUNT',scalar(@new_files));
1089 $tpl->fillin('DIR',encode_html
($virtual));
1090 $tpl->fillin('SCRIPT',$script);
1092 my $output = header
(-type
=> 'text/html');
1093 $output .= $tpl->get_template;
1100 return devedit_reload
({command
=> 'show', file
=> $virtual});
1106 # Change the mode and the group of a file or a directory
1108 # Params: 1. Reference to user input hash
1109 # 2. Reference to config hash
1111 # Return: Output of the command (Scalar Reference)
1115 my ($data,$config) = @_;
1116 my $physical = $data->{'physical'};
1117 my $virtual = $data->{'virtual'};
1118 my $dir = upper_path
($virtual);
1120 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> encode_html
($virtual)}) unless($users);
1121 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
1122 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> encode_html
($virtual)}) unless(-o
$physical);
1123 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
1125 my $cgi = $data->{'cgi'};
1126 my $mode = $cgi->param('mode');
1127 my $group = $cgi->param('group');
1135 return error
($config->{'errors'}->{'invalid_mode'},$dir) unless($mode =~ /^[0-7]{3,}$/);
1136 chmod(oct($mode),$physical);
1141 # Change the group using the `chgrp` system command
1143 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_html
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
1144 system('chgrp',$group,$physical);
1147 return devedit_reload
({command
=> 'show', file
=> $dir});
1153 my @stat = stat($physical);
1154 my $mode = $stat[2];
1157 my $tpl = new Template
;
1158 $tpl->read_file($config->{'templates'}->{'chprop'});
1160 # Insert file properties into the template
1162 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
1163 $tpl->fillin('MODE_STRING',mode_string
($mode));
1164 $tpl->fillin('GID',$gid);
1166 if(my $group = getgrgid($gid))
1168 $tpl->fillin('GROUP',encode_html
($group));
1169 $tpl->parse_if_block('group_detected',1);
1173 $tpl->parse_if_block('group_detected',0);
1176 # Insert other information
1178 $tpl->fillin('FILE',encode_html
($virtual));
1179 $tpl->fillin('FILE_URL',escape
($virtual));
1180 $tpl->fillin('DIR',encode_html
($dir));
1181 $tpl->fillin('DIR_URL',escape
($dir));
1182 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
1183 $tpl->fillin('SCRIPT',$script);
1185 my $output = header
(-type
=> 'text/html');
1186 $output .= $tpl->get_template;
1194 # Display some information about Dev-Editor
1196 # Params: 1. Reference to user input hash
1197 # 2. Reference to config hash
1199 # Return: Output of the command (Scalar Reference)
1203 my ($data,$config) = @_;
1205 my $tpl = new Template
;
1206 $tpl->read_file($config->{'templates'}->{'about'});
1208 $tpl->fillin('SCRIPT',$script);
1210 # Dev-Editor's version number
1212 $tpl->fillin('VERSION',$data->{'version'});
1214 # Some path information
1216 $tpl->fillin('SCRIPT_PHYS',encode_html
($ENV{'SCRIPT_FILENAME'}));
1217 $tpl->fillin('CONFIG_PATH',encode_html
($data->{'configfile'}));
1218 $tpl->fillin('FILE_ROOT', encode_html
($config->{'fileroot'}));
1219 $tpl->fillin('HTTP_ROOT', encode_html
($config->{'httproot'}));
1223 $tpl->fillin('PERL_PROG',encode_html
($^X
));
1224 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
1226 $tpl->parse_if_block('PERL_ARCHIVE_EXTRACT',$File::Access
::has_archive_extract
);
1228 # Information about the server
1230 $tpl->fillin('HTTPD',encode_html
($ENV{'SERVER_SOFTWARE'}));
1231 $tpl->fillin('OS', encode_html
($^O
));
1232 $tpl->fillin('TIME', encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
1234 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
1236 # Process information
1238 $tpl->fillin('PID',$$);
1240 # The following information is only available on systems supporting
1245 # Dev-Editor is running on a system which allows users and groups
1246 # So we display the user and the group of our process
1248 my $uid = POSIX
::getuid
;
1249 my $gid = POSIX
::getgid
;
1251 $tpl->parse_if_block('users',1);
1253 # IDs of user and group
1255 $tpl->fillin('UID',$uid);
1256 $tpl->fillin('GID',$gid);
1258 # Names of user and group
1260 if(my $user = getpwuid($uid))
1262 $tpl->fillin('USER',encode_html
($user));
1263 $tpl->parse_if_block('user_detected',1);
1267 $tpl->parse_if_block('user_detected',0);
1270 if(my $group = getgrgid($gid))
1272 $tpl->fillin('GROUP',encode_html
($group));
1273 $tpl->parse_if_block('group_detected',1);
1277 $tpl->parse_if_block('group_detected',0);
1282 $tpl->fillin('UMASK',sprintf('%04o',umask));
1286 $tpl->parse_if_block('users',0);
1289 my $output = header
(-type
=> 'text/html');
1290 $output .= $tpl->get_template;
1295 # it's true, baby ;-)
patrick-canterino.de