]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
8acd1d7ccebc86b0e41a738b9a3678c29db9ec28
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2009-05-09
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->set_var('DIR',encode_html
($virtual));
811 $tpl->set_var('DIR_URL',escape
($virtual));
812 $tpl->set_var('UPPER_DIR',encode_html
($dir));
813 $tpl->set_var('UPPER_DIR_URL',escape
($dir));
814 $tpl->set_var('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
815 $tpl->set_var('SCRIPT',$script);
819 my $output = header
(-type
=> 'text/html');
820 $output .= $tpl->get_template;
829 if($data->{'cgi'}->param('confirmed'))
831 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
832 return devedit_reload
({command
=> 'show', file
=> $dir});
836 my $tpl = new Template
;
837 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
839 $tpl->set_var('FILE',encode_html
($virtual));
840 $tpl->set_var('FILE_URL',escape
($virtual));
841 $tpl->set_var('DIR',encode_html
($dir));
842 $tpl->set_var('DIR_URL',escape
($dir));
843 $tpl->set_var('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
844 $tpl->set_var('SCRIPT',$script);
848 my $output = header
(-type
=> 'text/html');
849 $output .= $tpl->get_template;
856 # exec_remove_multi()
858 # Remove a file or a directory and return to directory view
860 # Params: 1. Reference to user input hash
861 # 2. Reference to config hash
863 # Return: Output of the command (Scalar Reference)
865 sub exec_remove_multi
($$)
867 my ($data,$config) = @_;
868 my $physical = $data->{'physical'};
869 my $virtual = $data->{'virtual'};
870 my $cgi = $data->{'cgi'};
872 my @files = $cgi->param('files');
877 foreach my $file(@files)
879 # Filter out some "bad" files (e.g. files going up in the
880 # directory hierarchy or files containing slashes (it's too
883 next if($file =~ m!^\.+$!);
884 next if($file =~ m!/!);
885 next if($file =~ m!\\!);
887 push(@new_files,$file);
893 if($cgi->param('confirmed'))
898 foreach my $file(@new_files)
900 my $file_path = clean_path
($physical.'/'.$file);
904 if(-d
$file_path && not -l
$file_path)
908 if(rmtree
($file_path))
910 push(@success,clean_path
($file));
914 push(@failed,clean_path
($file));
921 if(unlink($file_path))
923 push(@success,clean_path
($file));
927 push(@failed,clean_path
($file));
933 push(@failed,clean_path
($file));
937 my $tpl = new Template
;
938 $tpl->read_file($config->{'templates'}->{'rmmulti'});
940 if(scalar(@success) > 0)
942 if(scalar(@success) == scalar(@new_files) && scalar(@failed) == 0)
944 return devedit_reload
({command
=> 'show', file
=> $virtual});
948 $tpl->parse_if_block('success',1);
950 foreach my $file_success(@success)
952 $tpl->add_loop_data('SUCCESS',{FILE
=> encode_html
($file_success),
953 FILE_PATH
=> encode_html
(clean_path
($virtual.'/'.$file_success))});
959 $tpl->parse_if_block('success',0);
962 if(scalar(@failed) > 0)
964 $tpl->parse_if_block('failed',1);
966 foreach my $file_failed(@failed)
968 $tpl->add_loop_data('FAILED',{FILE
=> encode_html
($file_failed),
969 FILE_PATH
=> encode_html
(clean_path
($virtual.'/'.$file_failed))});
974 $tpl->parse_if_block('failed',0);
978 $tpl->set_var('DIR',encode_html
($virtual));
979 $tpl->set_var('SCRIPT',$script);
983 my $output = header
(-type
=> 'text/html');
984 $output .= $tpl->get_template;
990 my $tpl = new Template
;
991 $tpl->read_file($config->{'templates'}->{'confirm_rmmulti'});
993 foreach my $file(@new_files)
995 $tpl->add_loop_data('FILES',{FILE
=> encode_html
($file),
996 FILE_PATH
=> encode_html
(clean_path
($virtual.'/'.$file))});
999 $tpl->set_var('COUNT',scalar(@new_files));
1001 $tpl->set_var('DIR',encode_html
($virtual));
1002 $tpl->set_var('SCRIPT',$script);
1006 my $output = header
(-type
=> 'text/html');
1007 $output .= $tpl->get_template;
1014 return devedit_reload
({command
=> 'show', file
=> $virtual});
1020 # Change the mode and the group of a file or a directory
1022 # Params: 1. Reference to user input hash
1023 # 2. Reference to config hash
1025 # Return: Output of the command (Scalar Reference)
1029 my ($data,$config) = @_;
1030 my $physical = $data->{'physical'};
1031 my $virtual = $data->{'virtual'};
1032 my $dir = upper_path
($virtual);
1034 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> encode_html
($virtual)}) unless($users);
1035 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
1036 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> encode_html
($virtual)}) unless(-o
$physical);
1037 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
1039 my $cgi = $data->{'cgi'};
1040 my $mode = $cgi->param('mode');
1041 my $group = $cgi->param('group');
1049 return error
($config->{'errors'}->{'invalid_mode'},$dir) unless($mode =~ /^[0-7]{3,}$/);
1050 chmod(oct($mode),$physical);
1055 # Change the group using the `chgrp` system command
1057 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_html
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
1058 system('chgrp',$group,$physical);
1061 return devedit_reload
({command
=> 'show', file
=> $dir});
1067 my @stat = stat($physical);
1068 my $mode = $stat[2];
1071 my $tpl = new Template
;
1072 $tpl->read_file($config->{'templates'}->{'chprop'});
1074 # Insert file properties into the template
1076 $tpl->set_var('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
1077 $tpl->set_var('MODE_STRING',mode_string
($mode));
1078 $tpl->set_var('GID',$gid);
1080 if(my $group = getgrgid($gid))
1082 $tpl->set_var('GROUP',encode_html
($group));
1083 $tpl->parse_if_block('group_detected',1);
1087 $tpl->parse_if_block('group_detected',0);
1090 # Insert other information
1092 $tpl->set_var('FILE',encode_html
($virtual));
1093 $tpl->set_var('FILE_URL',escape
($virtual));
1094 $tpl->set_var('DIR',encode_html
($dir));
1095 $tpl->set_var('DIR_URL',escape
($dir));
1096 $tpl->set_var('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
1097 $tpl->set_var('SCRIPT',$script);
1101 my $output = header
(-type
=> 'text/html');
1102 $output .= $tpl->get_template;
1110 # Display some information about Dev-Editor
1112 # Params: 1. Reference to user input hash
1113 # 2. Reference to config hash
1115 # Return: Output of the command (Scalar Reference)
1119 my ($data,$config) = @_;
1121 my $tpl = new Template
;
1122 $tpl->read_file($config->{'templates'}->{'about'});
1124 $tpl->set_var('SCRIPT',$script);
1126 # Dev-Editor's version number
1128 $tpl->set_var('VERSION',$data->{'version'});
1130 # Some path information
1132 $tpl->set_var('SCRIPT_PHYS',encode_html
($ENV{'SCRIPT_FILENAME'}));
1133 $tpl->set_var('CONFIG_PATH',encode_html
($data->{'configfile'}));
1134 $tpl->set_var('FILE_ROOT', encode_html
($config->{'fileroot'}));
1135 $tpl->set_var('HTTP_ROOT', encode_html
($config->{'httproot'}));
1139 $tpl->set_var('PERL_PROG',encode_html
($^X
));
1140 $tpl->set_var('PERL_VER', sprintf('%vd',$^V
));
1142 # Information about the server
1144 $tpl->set_var('HTTPD',encode_html
($ENV{'SERVER_SOFTWARE'}));
1145 $tpl->set_var('OS', encode_html
($^O
));
1146 $tpl->set_var('TIME', encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
1148 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
1150 # Process information
1152 $tpl->set_var('PID',$$);
1154 # The following information is only available on systems supporting
1159 # Dev-Editor is running on a system which allows users and groups
1160 # So we display the user and the group of our process
1162 my $uid = POSIX
::getuid
;
1163 my $gid = POSIX
::getgid
;
1165 $tpl->parse_if_block('users',1);
1167 # IDs of user and group
1169 $tpl->set_var('UID',$uid);
1170 $tpl->set_var('GID',$gid);
1172 # Names of user and group
1174 if(my $user = getpwuid($uid))
1176 $tpl->set_var('USER',encode_html
($user));
1177 $tpl->parse_if_block('user_detected',1);
1181 $tpl->parse_if_block('user_detected',0);
1184 if(my $group = getgrgid($gid))
1186 $tpl->set_var('GROUP',encode_html
($group));
1187 $tpl->parse_if_block('group_detected',1);
1191 $tpl->parse_if_block('group_detected',0);
1196 $tpl->set_var('UMASK',sprintf('%04o',umask));
1200 $tpl->parse_if_block('users',0);
1205 my $output = header
(-type
=> 'text/html');
1206 $output .= $tpl->get_template;
1211 # it's true, baby ;-)
patrick-canterino.de