]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
c1b8989c68d90fa175db33bdde65da505c09fe89
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2005-05-11
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 'mkdir' => \
&exec_mkdir
,
46 'mkfile' => \
&exec_mkfile
,
47 'upload' => \
&exec_upload
,
48 'copy' => \
&exec_copy
,
49 'rename' => \
&exec_rename
,
50 'remove' => \
&exec_remove
,
51 'remove_multi' => \
&exec_remove_multi
,
52 'chprop' => \
&exec_chprop
,
53 'about' => \
&exec_about
58 use base
qw(Exporter);
60 @EXPORT = qw(exec_command);
64 # Execute the specified command
66 # Params: 1. Command to execute
67 # 2. Reference to user input hash
68 # 3. Reference to config hash
70 # Return: Output of the command (Scalar Reference)
74 my ($command,$data,$config) = @_;
76 foreach(keys(%dispatch))
78 if(lc($_) eq lc($command))
80 my $output = &{$dispatch{$_}}($data,$config);
85 return error
($config->{'errors'}->{'command_unknown'},'/',{COMMAND
=> encode_html
($command)});
90 # View a directory or a file
92 # Params: 1. Reference to user input hash
93 # 2. Reference to config hash
95 # Return: Output of the command (Scalar Reference)
99 my ($data,$config) = @_;
100 my $physical = $data->{'physical'};
101 my $virtual = $data->{'virtual'};
102 my $upper_path = multi_string
(upper_path
($virtual));
104 my $tpl = new Template
;
106 if(-d
$physical && not -l
$physical)
108 # Create directory listing
110 return error
($config->{'errors'}->{'no_dir_access'},$upper_path->{'normal'}) unless(-r
$physical && -x
$physical);
112 my $direntries = dir_read
($physical);
113 return error
($config->{'errors'}->{'dir_read_failed'},$upper_path->{'normal'},{DIR
=> encode_html
($virtual)}) unless($direntries);
115 my $files = $direntries->{'files'};
116 my $dirs = $direntries->{'dirs'};
122 my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
123 my $filter2 = ($filter1 && $filter1 ne '*') ?
$filter1 : ''; # Wildcard for output
125 # Create the link to the upper directory
126 # (only if the current directory is not the root directory)
128 unless($virtual eq '/')
132 my @stat = stat($physical.'/..');
134 my $udtpl = new Template
;
135 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
137 $udtpl->fillin('UPPER_DIR',$upper_path->{'html'});
138 $udtpl->fillin('UPPER_DIR_URL',$upper_path->{'url'});
139 $udtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
141 $dirlist .= $udtpl->get_template;
146 foreach my $dir(@
$dirs)
148 next if($config->{'hide_dot_files'} && substr($dir,0,1) eq '.');
149 next unless(dos_wildcard_match
($filter1,$dir));
153 my $phys_path = $physical.'/'.$dir;
154 my $virt_path = multi_string
($virtual.$dir.'/');
156 my @stat = stat($phys_path);
158 my $dtpl = new Template
;
159 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
161 $dtpl->fillin('DIR',$virt_path->{'html'});
162 $dtpl->fillin('DIR_URL',$virt_path->{'url'});
163 $dtpl->fillin('DIR_NAME',encode_html
($dir));
164 $dtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
165 $dtpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
167 $dtpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
168 $dtpl->parse_if_block('readable',-r
$phys_path && -x
$phys_path);
169 $dtpl->parse_if_block('users',$users && -o
$phys_path);
170 $dtpl->parse_if_block('even',($count % 2) == 0);
172 $dirlist .= $dtpl->get_template;
177 foreach my $file(@
$files)
179 next if($config->{'hide_dot_files'} && substr($file,0,1) eq '.');
180 next unless(dos_wildcard_match
($filter1,$file));
184 my $phys_path = $physical.'/'.$file;
185 my $virt_path = multi_string
($virtual.$file);
187 my @stat = lstat($phys_path);
188 my $too_large = $config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'};
190 my $ftpl = new Template
;
191 $ftpl->read_file($config->{'templates'}->{'dirlist_file'});
193 $ftpl->fillin('FILE',$virt_path->{'html'});
194 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
195 $ftpl->fillin('FILE_NAME',encode_html
($file));
196 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
197 $ftpl->fillin('SIZE',$stat[7]);
198 $ftpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
199 $ftpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
201 $ftpl->parse_if_block('link',-l
$phys_path);
202 $ftpl->parse_if_block('readable',-r
$phys_path);
203 $ftpl->parse_if_block('writeable',-w
$phys_path);
204 $ftpl->parse_if_block('binary',-B
$phys_path);
206 $ftpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
207 $ftpl->parse_if_block('viewable',(-r
$phys_path && -T
$phys_path && not $too_large) || -l
$phys_path);
208 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not -l
$phys_path);
210 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
212 $ftpl->parse_if_block('users',$users && -o
$phys_path);
214 $ftpl->parse_if_block('even',($count % 2) == 0);
216 $dirlist .= $ftpl->get_template;
219 $tpl->read_file($config->{'templates'}->{'dirlist'});
221 $tpl->fillin('DIRLIST',$dirlist);
222 $tpl->fillin('DIR',encode_html
($virtual));
223 $tpl->fillin('DIR_URL',escape
($virtual));
224 $tpl->fillin('SCRIPT',$script);
225 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
227 $tpl->fillin('FILTER',encode_html
($filter2));
228 $tpl->fillin('FILTER_URL',escape
($filter2));
230 $tpl->parse_if_block('empty',$dirlist eq '');
231 $tpl->parse_if_block('dir_writeable',-w
$physical);
232 $tpl->parse_if_block('filter',$filter2);
233 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
237 # Show the target of a symbolic link
239 my $link_target = readlink($physical);
241 $tpl->read_file($config->{'templates'}->{'viewlink'});
243 $tpl->fillin('FILE',encode_html
($virtual));
244 $tpl->fillin('DIR',$upper_path->{'html'});
245 $tpl->fillin('DIR_URL',$upper_path->{'url'});
246 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
247 $tpl->fillin('SCRIPT',$script);
249 $tpl->fillin('LINK_TARGET',encode_html
($link_target));
255 return error
($config->{'errors'}->{'no_view'},$upper_path->{'normal'}) unless(-r
$physical);
257 # Check on binary files
258 # We have to do it in this way or empty files will be recognized
261 return error
($config->{'errors'}->{'binary_file'},$upper_path->{'normal'}) unless(-T
$physical);
263 # Is the file too large?
265 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'});
269 my $content = file_read
($physical);
270 $$content =~ s/\015\012|\012|\015/\n/g;
272 $tpl->read_file($config->{'templates'}->{'viewfile'});
274 $tpl->fillin('FILE',encode_html
($virtual));
275 $tpl->fillin('FILE_URL',escape
($virtual));
276 $tpl->fillin('DIR',$upper_path->{'html'});
277 $tpl->fillin('DIR_URL',$upper_path->{'url'});
278 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
279 $tpl->fillin('SCRIPT',$script);
281 $tpl->parse_if_block('editable',-w
$physical);
283 $tpl->fillin('CONTENT',encode_html
($$content));
286 my $output = header
(-type
=> 'text/html');
287 $output .= $tpl->get_template;
294 # Lock a file and display a form to edit it
296 # Params: 1. Reference to user input hash
297 # 2. Reference to config hash
299 # Return: Output of the command (Scalar Reference)
301 sub exec_beginedit
($$)
303 my ($data,$config) = @_;
304 my $physical = $data->{'physical'};
305 my $virtual = $data->{'virtual'};
306 my $dir = upper_path
($virtual);
308 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
309 return error
($config->{'errors'}->{'dir_edit'}, $dir) if(-d
$physical);
310 return error
($config->{'errors'}->{'no_edit'}, $dir) unless(-r
$physical && -w
$physical);
312 # Check on binary files
314 return error
($config->{'errors'}->{'binary_file'},$dir) unless(-T
$physical);
316 # Is the file too large?
318 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
320 # Show the editing form
322 my $content = file_read
($physical);
323 my $md5sum = md5_hex
($$content);
324 $$content =~ s/\015\012|\012|\015/\n/g;
326 my $tpl = new Template
;
327 $tpl->read_file($config->{'templates'}->{'editfile'});
329 $tpl->fillin('FILE',encode_html
($virtual));
330 $tpl->fillin('FILE_URL',escape
($virtual));
331 $tpl->fillin('DIR',encode_html
($dir));
332 $tpl->fillin('DIR_URL',escape
($dir));
333 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
334 $tpl->fillin('SCRIPT',$script);
335 $tpl->fillin('MD5SUM',$md5sum);
336 $tpl->fillin('CONTENT',encode_html
($$content));
338 $tpl->parse_if_block('error',0);
340 my $output = header
(-type
=> 'text/html');
341 $output .= $tpl->get_template;
348 # Save a file, unlock it and return to directory view
350 # Params: 1. Reference to user input hash
351 # 2. Reference to config hash
353 # Return: Output of the command (Scalar Reference)
357 my ($data,$config) = @_;
358 my $physical = $data->{'physical'};
359 my $virtual = $data->{'virtual'};
360 my $dir = upper_path
($virtual);
361 my $cgi = $data->{'cgi'};
362 my $content = $cgi->param('filecontent');
363 my $md5sum = $cgi->param('md5sum');
366 if(defined $content && $md5sum)
370 $content =~ s/\015\012|\012|\015/\n/g;
372 if($cgi->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
374 # Create the new filename
376 $physical = $data->{'new_physical'};
377 $virtual = $data->{'new_virtual'};
380 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
381 return error
($config->{'errors'}->{'dir_edit'},$dir) if(-d
$physical);
382 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
383 return error
($config->{'errors'}->{'text_to_binary'},$dir) if(-e
$physical && not -T
$physical);
385 # For technical reasons, we can't use file_save() for
390 sysopen(FILE
,$physical,O_RDWR
| O_CREAT
) or return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)});
391 file_lock
(*FILE
,LOCK_EX
) or do { close(FILE
); return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)}) };
393 my $md5 = new Digest
::MD5
;
394 $md5->addfile(*FILE
);
396 my $md5file = $md5->hexdigest;
397 my $md5data = md5_hex
($content);
399 if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
401 # The file changed meanwhile
403 my $tpl = new Template
;
404 $tpl->read_file($config->{'templates'}->{'editfile'});
406 $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
408 $tpl->fillin('FILE',encode_html
($virtual));
409 $tpl->fillin('FILE_URL',escape
($virtual));
410 $tpl->fillin('DIR',encode_html
($dir));
411 $tpl->fillin('DIR_URL',escape
($dir));
412 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
413 $tpl->fillin('SCRIPT',$script);
414 $tpl->fillin('MD5SUM',$md5file);
415 $tpl->fillin('CONTENT',encode_html
($content));
417 $tpl->parse_if_block('error',1);
419 my $data = header
(-type
=> 'text/html');
420 $data .= $tpl->get_template;
426 if($md5data ne $md5file)
434 $output = ($cgi->param('continue'))
435 ? devedit_reload
({command
=> 'beginedit', file
=> $virtual})
436 : devedit_reload
({command
=> 'show', file
=> $dir});
444 return devedit_reload
({command
=> 'beginedit', file
=> $virtual});
449 # Create a file and return to directory view
451 # Params: 1. Reference to user input hash
452 # 2. Reference to config hash
454 # Return: Output of the command (Scalar Reference)
458 my ($data,$config) = @_;
459 my $new_physical = $data->{'new_physical'};
460 my $new_virtual = $data->{'new_virtual'};
461 my $dir = upper_path
($new_virtual);
462 $new_virtual = encode_html
($new_virtual);
466 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
468 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
469 return devedit_reload
({command
=> 'show', file
=> $dir});
473 my $tpl = new Template
;
474 $tpl->read_file($config->{'templates'}->{'mkfile'});
476 $tpl->fillin('DIR','/');
477 $tpl->fillin('SCRIPT',$script);
479 my $output = header
(-type
=> 'text/html');
480 $output .= $tpl->get_template;
488 # Create a directory and return to directory view
490 # Params: 1. Reference to user input hash
491 # 2. Reference to config hash
493 # Return: Output of the command (Scalar Reference)
497 my ($data,$config) = @_;
498 my $new_physical = $data->{'new_physical'};
499 my $new_virtual = $data->{'new_virtual'};
500 my $dir = upper_path
($new_virtual);
501 $new_virtual = encode_html
($new_virtual);
505 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
507 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
508 return devedit_reload
({command
=> 'show', file
=> $dir});
512 my $tpl = new Template
;
513 $tpl->read_file($config->{'templates'}->{'mkdir'});
515 $tpl->fillin('DIR','/');
516 $tpl->fillin('SCRIPT',$script);
518 my $output = header
(-type
=> 'text/html');
519 $output .= $tpl->get_template;
527 # Process a file upload
529 # Params: 1. Reference to user input hash
530 # 2. Reference to config hash
532 # Return: Output of the command (Scalar Reference)
536 my ($data,$config) = @_;
537 my $physical = $data->{'physical'};
538 my $virtual = $data->{'virtual'};
539 my $cgi = $data->{'cgi'};
541 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> encode_html
($virtual)}) unless(-d
$physical && not -l
$physical);
542 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> encode_html
($virtual)}) unless(-w
$physical);
544 if(my $uploaded_file = $cgi->param('uploaded_file'))
546 if($cgi->param('remote_file'))
548 $uploaded_file = $cgi->param('remote_file');
550 $uploaded_file =~ s!/!!g;
551 $uploaded_file =~ s!\\!!g;
554 # Process file upload
556 my $filename = file_name
($uploaded_file);
557 my $file_phys = $physical.'/'.$filename;
558 my $file_virt = encode_html
($virtual.$filename);
562 return error
($config->{'errors'}->{'link_replace'},$virtual) if(-l
$file_phys);
563 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
564 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
565 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
568 my $ascii = $cgi->param('ascii');
569 my $handle = $cgi->upload('uploaded_file');
571 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
573 # Read transferred file and write it to disk
575 read($handle, my $data, -s
$handle);
576 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
577 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
579 return devedit_reload
({command
=> 'show', file
=> $virtual});
583 my $tpl = new Template
;
584 $tpl->read_file($config->{'templates'}->{'upload'});
586 $tpl->fillin('DIR',encode_html
($virtual));
587 $tpl->fillin('DIR_URL',escape
($virtual));
588 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
589 $tpl->fillin('SCRIPT',$script);
591 my $output = header
(-type
=> 'text/html');
592 $output .= $tpl->get_template;
600 # Copy a file and return to directory view
602 # Params: 1. Reference to user input hash
603 # 2. Reference to config hash
605 # Return: Output of the command (Scalar Reference)
609 my ($data,$config) = @_;
610 my $physical = $data->{'physical'};
611 my $virtual = $data->{'virtual'};
612 my $dir = upper_path
($virtual);
613 my $new_physical = $data->{'new_physical'};
615 return error
($config->{'errors'}->{'link_copy'},$dir) if(-l
$physical);
616 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
620 my $new_virtual = multi_string
($data->{'new_virtual'});
621 my $new_dir = upper_path
($new_virtual->{'normal'});
625 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-x
$physical);
626 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual->{'html'}}) if(-e
$new_physical);
627 return error
($config->{'errors'}->{'dir_copy_self'},$dir) if(index($new_virtual->{'normal'},$virtual) == 0);
629 dir_copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
630 return devedit_reload
({command
=> 'show', file
=> $new_dir});
636 return error
($config->{'errors'}->{'link_replace'},$new_dir) if(-l
$new_physical);
637 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
638 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual->{'html'}}) unless(-w
$new_physical);
640 if(not $data->{'cgi'}->param('confirmed'))
642 my $tpl = new Template
;
643 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
645 $tpl->fillin('FILE',encode_html
($virtual));
646 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
647 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
648 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
649 $tpl->fillin('DIR',encode_html
($dir));
650 $tpl->fillin('DIR_URL',escape
($dir));
652 $tpl->fillin('COMMAND','copy');
653 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
654 $tpl->fillin('SCRIPT',$script);
656 my $output = header
(-type
=> 'text/html');
657 $output .= $tpl->get_template;
663 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
664 return devedit_reload
({command
=> 'show', file
=> $new_dir});
671 my $tpl = new Template
;
672 $tpl->read_file($config->{'templates'}->{'copydir'});
674 $tpl->fillin('FILE',encode_html
($virtual));
675 $tpl->fillin('DIR',encode_html
($dir));
676 $tpl->fillin('DIR_URL',escape
($dir));
677 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
678 $tpl->fillin('SCRIPT',$script);
680 my $output = header
(-type
=> 'text/html');
681 $output .= $tpl->get_template;
687 my $tpl = new Template
;
688 $tpl->read_file($config->{'templates'}->{'copyfile'});
690 $tpl->fillin('FILE',encode_html
($virtual));
691 $tpl->fillin('DIR',encode_html
($dir));
692 $tpl->fillin('DIR_URL',escape
($dir));
693 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
694 $tpl->fillin('SCRIPT',$script);
696 my $output = header
(-type
=> 'text/html');
697 $output .= $tpl->get_template;
706 # Rename/move a file and return to directory view
708 # Params: 1. Reference to user input hash
709 # 2. Reference to config hash
711 # Return: Output of the command (Scalar Reference)
715 my ($data,$config) = @_;
716 my $physical = $data->{'physical'};
717 my $virtual = $data->{'virtual'};
718 my $dir = upper_path
($virtual);
719 my $new_physical = $data->{'new_physical'};
721 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
722 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
726 my $new_virtual = multi_string
($data->{'new_virtual'});
727 my $new_dir = upper_path
($new_virtual->{'normal'});
731 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical && not -l
$new_physical);
732 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
734 if(not $data->{'cgi'}->param('confirmed'))
736 my $tpl = new Template
;
737 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
739 $tpl->fillin('FILE',encode_html
($virtual));
740 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
741 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
742 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
743 $tpl->fillin('DIR',encode_html
($dir));
745 $tpl->fillin('COMMAND','rename');
746 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
747 $tpl->fillin('SCRIPT',$script);
749 my $output = header
(-type
=> 'text/html');
750 $output .= $tpl->get_template;
756 move
($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
757 return devedit_reload
({command
=> 'show', file
=> $new_dir});
761 my $tpl = new Template
;
762 $tpl->read_file($config->{'templates'}->{'renamefile'});
764 $tpl->fillin('FILE',encode_html
($virtual));
765 $tpl->fillin('DIR',encode_html
($dir));
766 $tpl->fillin('DIR_URL',escape
($dir));
767 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
768 $tpl->fillin('SCRIPT',$script);
770 my $output = header
(-type
=> 'text/html');
771 $output .= $tpl->get_template;
779 # Remove a file or a directory and return to directory view
781 # Params: 1. Reference to user input hash
782 # 2. Reference to config hash
784 # Return: Output of the command (Scalar Reference)
788 my ($data,$config) = @_;
789 my $physical = $data->{'physical'};
790 my $virtual = $data->{'virtual'};
791 my $dir = upper_path
($virtual);
793 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
794 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
796 if(-d
$physical && not -l
$physical)
800 if($data->{'cgi'}->param('confirmed'))
803 return devedit_reload
({command
=> 'show', file
=> $dir});
807 my $tpl = new Template
;
808 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
810 $tpl->fillin('DIR',encode_html
($virtual));
811 $tpl->fillin('DIR_URL',escape
($virtual));
812 $tpl->fillin('UPPER_DIR',encode_html
($dir));
813 $tpl->fillin('UPPER_DIR_URL',escape
($dir));
814 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
815 $tpl->fillin('SCRIPT',$script);
817 my $output = header
(-type
=> 'text/html');
818 $output .= $tpl->get_template;
827 if($data->{'cgi'}->param('confirmed'))
829 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
830 return devedit_reload
({command
=> 'show', file
=> $dir});
834 my $tpl = new Template
;
835 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
837 $tpl->fillin('FILE',encode_html
($virtual));
838 $tpl->fillin('FILE_URL',escape
($virtual));
839 $tpl->fillin('DIR',encode_html
($dir));
840 $tpl->fillin('DIR_URL',escape
($dir));
841 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
842 $tpl->fillin('SCRIPT',$script);
844 my $output = header
(-type
=> 'text/html');
845 $output .= $tpl->get_template;
852 # exec_remove_multi()
854 # Remove a file or a directory and return to directory view
856 # Params: 1. Reference to user input hash
857 # 2. Reference to config hash
859 # Return: Output of the command (Scalar Reference)
861 sub exec_remove_multi
($$)
863 my ($data,$config) = @_;
864 my $physical = $data->{'physical'};
865 my $virtual = $data->{'virtual'};
866 my $cgi = $data->{'cgi'};
868 my @files = $cgi->param('files');#
873 foreach my $file(@files)
875 # Filter out some "bad" files (e.g. files going up in the
876 # directory hierarchy or files containing slashes (it's too
879 next if($file =~ m!^\.+$!);
880 next if($file =~ m!/!);
881 next if($file =~ m!\\!);
883 push(@new_files,$file);
889 if($cgi->param('confirmed'))
894 foreach my $file(@new_files)
896 my $file_path = clean_path
($physical.'/'.$file);
900 if(-d
$file_path && not -l
$file_path)
904 if(rmtree
($file_path))
906 push(@success,clean_path
($file));
910 push(@failed,clean_path
($file));
917 if(unlink($file_path))
919 push(@success,clean_path
($file));
923 push(@failed,clean_path
($file));
929 push(@failed,clean_path
($file));
933 my $tpl = new Template
;
934 $tpl->read_file($config->{'templates'}->{'rmmulti'});
936 if(scalar(@success) > 0)
938 if(scalar(@success) == scalar(@new_files) && scalar(@failed) == 0)
940 return devedit_reload
({command
=> 'show', file
=> $virtual});
944 $tpl->parse_if_block('success',1);
946 foreach my $file_success(@success)
948 $tpl->add_loop_data('SUCCESS',{FILE
=> encode_html
($file_success),
949 FILE_PATH
=> encode_html
(clean_path
($virtual.'/'.$file_success))});
952 $tpl->parse_loop('SUCCESS');
957 $tpl->parse_if_block('success',0);
960 if(scalar(@failed) > 0)
962 $tpl->parse_if_block('failed',1);
964 foreach my $file_failed(@failed)
966 $tpl->add_loop_data('FAILED',{FILE
=> encode_html
($file_failed),
967 FILE_PATH
=> encode_html
(clean_path
($virtual.'/'.$file_failed))});
970 $tpl->parse_loop('FAILED');
974 $tpl->parse_if_block('failed',0);
978 $tpl->fillin('DIR',encode_html
($virtual));
979 $tpl->fillin('SCRIPT',$script);
981 my $output = header
(-type
=> 'text/html');
982 $output .= $tpl->get_template;
988 my $tpl = new Template
;
989 $tpl->read_file($config->{'templates'}->{'confirm_rmmulti'});
991 foreach my $file(@new_files)
993 $tpl->add_loop_data('FILES',{FILE
=> encode_html
($file),
994 FILE_PATH
=> encode_html
(clean_path
($virtual.'/'.$file))});
997 $tpl->parse_loop('FILES');
999 $tpl->fillin('COUNT',scalar(@new_files));
1001 $tpl->fillin('DIR',encode_html
($virtual));
1002 $tpl->fillin('SCRIPT',$script);
1004 my $output = header
(-type
=> 'text/html');
1005 $output .= $tpl->get_template;
1012 return devedit_reload
({command
=> 'show', file
=> $virtual});
1018 # Change the mode and the group of a file or a directory
1020 # Params: 1. Reference to user input hash
1021 # 2. Reference to config hash
1023 # Return: Output of the command (Scalar Reference)
1027 my ($data,$config) = @_;
1028 my $physical = $data->{'physical'};
1029 my $virtual = $data->{'virtual'};
1030 my $dir = upper_path
($virtual);
1032 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> encode_html
($virtual)}) unless($users);
1033 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
1034 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> encode_html
($virtual)}) unless(-o
$physical);
1035 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
1037 my $cgi = $data->{'cgi'};
1038 my $mode = $cgi->param('mode');
1039 my $group = $cgi->param('group');
1047 return error
($config->{'errors'}->{'invalid_mode'},$dir) unless($mode =~ /^[0-7]{3,}$/);
1048 chmod(oct($mode),$physical);
1053 # Change the group using the `chgrp` system command
1055 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_html
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
1056 system('chgrp',$group,$physical);
1059 return devedit_reload
({command
=> 'show', file
=> $dir});
1065 my @stat = stat($physical);
1066 my $mode = $stat[2];
1069 my $tpl = new Template
;
1070 $tpl->read_file($config->{'templates'}->{'chprop'});
1072 # Insert file properties into the template
1074 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
1075 $tpl->fillin('MODE_STRING',mode_string
($mode));
1076 $tpl->fillin('GID',$gid);
1078 if(my $group = getgrgid($gid))
1080 $tpl->fillin('GROUP',encode_html
($group));
1081 $tpl->parse_if_block('group_detected',1);
1085 $tpl->parse_if_block('group_detected',0);
1088 # Insert other information
1090 $tpl->fillin('FILE',encode_html
($virtual));
1091 $tpl->fillin('FILE_URL',escape
($virtual));
1092 $tpl->fillin('DIR',encode_html
($dir));
1093 $tpl->fillin('DIR_URL',escape
($dir));
1094 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
1095 $tpl->fillin('SCRIPT',$script);
1097 my $output = header
(-type
=> 'text/html');
1098 $output .= $tpl->get_template;
1106 # Display some information about Dev-Editor
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) = @_;
1117 my $tpl = new Template
;
1118 $tpl->read_file($config->{'templates'}->{'about'});
1120 $tpl->fillin('SCRIPT',$script);
1122 # Dev-Editor's version number
1124 $tpl->fillin('VERSION',$data->{'version'});
1126 # Some path information
1128 $tpl->fillin('SCRIPT_PHYS',encode_html
($ENV{'SCRIPT_FILENAME'}));
1129 $tpl->fillin('CONFIG_PATH',encode_html
($data->{'configfile'}));
1130 $tpl->fillin('FILE_ROOT', encode_html
($config->{'fileroot'}));
1131 $tpl->fillin('HTTP_ROOT', encode_html
($config->{'httproot'}));
1135 $tpl->fillin('PERL_PROG',encode_html
($^X
));
1136 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
1138 # Information about the server
1140 $tpl->fillin('HTTPD',encode_html
($ENV{'SERVER_SOFTWARE'}));
1141 $tpl->fillin('OS', encode_html
($^O
));
1142 $tpl->fillin('TIME', encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
1144 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
1146 # Process information
1148 $tpl->fillin('PID',$$);
1150 # The following information is only available on systems supporting
1155 # Dev-Editor is running on a system which allows users and groups
1156 # So we display the user and the group of our process
1158 my $uid = POSIX
::getuid
;
1159 my $gid = POSIX
::getgid
;
1161 $tpl->parse_if_block('users',1);
1163 # IDs of user and group
1165 $tpl->fillin('UID',$uid);
1166 $tpl->fillin('GID',$gid);
1168 # Names of user and group
1170 if(my $user = getpwuid($uid))
1172 $tpl->fillin('USER',encode_html
($user));
1173 $tpl->parse_if_block('user_detected',1);
1177 $tpl->parse_if_block('user_detected',0);
1180 if(my $group = getgrgid($gid))
1182 $tpl->fillin('GROUP',encode_html
($group));
1183 $tpl->parse_if_block('group_detected',1);
1187 $tpl->parse_if_block('group_detected',0);
1192 $tpl->fillin('UMASK',sprintf('%04o',umask));
1196 $tpl->parse_if_block('users',0);
1199 my $output = header
(-type
=> 'text/html');
1200 $output .= $tpl->get_template;
1205 # it's true, baby ;-)
patrick-canterino.de