]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2009-03-31
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 'chprop' => \
&exec_chprop
,
52 'about' => \
&exec_about
57 use base
qw(Exporter);
59 @EXPORT = qw(exec_command);
63 # Execute the specified command
65 # Params: 1. Command to execute
66 # 2. Reference to user input hash
67 # 3. Reference to config hash
69 # Return: Output of the command (Scalar Reference)
73 my ($command,$data,$config) = @_;
75 foreach(keys(%dispatch))
77 if(lc($_) eq lc($command))
79 my $output = &{$dispatch{$_}}($data,$config);
84 return error
($config->{'errors'}->{'command_unknown'},'/',{COMMAND
=> encode_html
($command)});
89 # View a directory or a file
91 # Params: 1. Reference to user input hash
92 # 2. Reference to config hash
94 # Return: Output of the command (Scalar Reference)
98 my ($data,$config) = @_;
99 my $physical = $data->{'physical'};
100 my $virtual = $data->{'virtual'};
101 my $upper_path = multi_string
(upper_path
($virtual));
103 my $tpl = new Template
;
105 if(-d
$physical && not -l
$physical)
107 # Create directory listing
109 return error
($config->{'errors'}->{'no_dir_access'},$upper_path->{'normal'}) unless(-r
$physical && -x
$physical);
111 my $direntries = dir_read
($physical);
112 return error
($config->{'errors'}->{'dir_read_failed'},$upper_path->{'normal'},{DIR
=> encode_html
($virtual)}) unless($direntries);
114 my $files = $direntries->{'files'};
115 my $dirs = $direntries->{'dirs'};
121 my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
122 my $filter2 = ($filter1 && $filter1 ne '*') ?
$filter1 : ''; # Wildcard for output
124 # Create the link to the upper directory
125 # (only if the current directory is not the root directory)
127 unless($virtual eq '/')
131 my @stat = stat($physical.'/..');
133 my $udtpl = new Template
;
134 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
136 $udtpl->fillin('UPPER_DIR',$upper_path->{'html'});
137 $udtpl->fillin('UPPER_DIR_URL',$upper_path->{'url'});
138 $udtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
140 $dirlist .= $udtpl->get_template;
145 foreach my $dir(@
$dirs)
147 next if($config->{'hide_dot_files'} && substr($dir,0,1) eq '.');
148 next unless(dos_wildcard_match
($filter1,$dir));
152 my $phys_path = $physical.'/'.$dir;
153 my $virt_path = multi_string
($virtual.$dir.'/');
155 my @stat = stat($phys_path);
157 my $dtpl = new Template
;
158 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
160 $dtpl->fillin('DIR',$virt_path->{'html'});
161 $dtpl->fillin('DIR_URL',$virt_path->{'url'});
162 $dtpl->fillin('DIR_NAME',encode_html
($dir));
163 $dtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
164 $dtpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
166 $dtpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
167 $dtpl->parse_if_block('readable',-r
$phys_path && -x
$phys_path);
168 $dtpl->parse_if_block('users',$users && -o
$phys_path);
169 $dtpl->parse_if_block('even',($count % 2) == 0);
171 $dirlist .= $dtpl->get_template;
176 foreach my $file(@
$files)
178 next if($config->{'hide_dot_files'} && substr($file,0,1) eq '.');
179 next unless(dos_wildcard_match
($filter1,$file));
183 my $phys_path = $physical.'/'.$file;
184 my $virt_path = multi_string
($virtual.$file);
186 my @stat = lstat($phys_path);
187 my $too_large = $config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'};
189 my $ftpl = new Template
;
190 $ftpl->read_file($config->{'templates'}->{'dirlist_file'});
192 $ftpl->fillin('FILE',$virt_path->{'html'});
193 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
194 $ftpl->fillin('FILE_NAME',encode_html
($file));
195 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
196 $ftpl->fillin('SIZE',$stat[7]);
197 $ftpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
198 $ftpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
200 $ftpl->parse_if_block('link',-l
$phys_path);
201 $ftpl->parse_if_block('readable',-r
$phys_path);
202 $ftpl->parse_if_block('writeable',-w
$phys_path);
203 $ftpl->parse_if_block('binary',-B
$phys_path);
205 $ftpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
206 $ftpl->parse_if_block('viewable',(-r
$phys_path && -T
$phys_path && not $too_large) || -l
$phys_path);
207 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not -l
$phys_path);
209 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
211 $ftpl->parse_if_block('users',$users && -o
$phys_path);
213 $ftpl->parse_if_block('even',($count % 2) == 0);
215 $dirlist .= $ftpl->get_template;
218 $tpl->read_file($config->{'templates'}->{'dirlist'});
220 $tpl->fillin('DIRLIST',$dirlist);
221 $tpl->fillin('DIR',encode_html
($virtual));
222 $tpl->fillin('DIR_URL',escape
($virtual));
223 $tpl->fillin('SCRIPT',$script);
224 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
226 $tpl->fillin('FILTER',encode_html
($filter2));
227 $tpl->fillin('FILTER_URL',escape
($filter2));
229 $tpl->parse_if_block('empty',$dirlist eq '');
230 $tpl->parse_if_block('dir_writeable',-w
$physical);
231 $tpl->parse_if_block('filter',$filter2);
232 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
236 # Show the target of a symbolic link
238 my $link_target = readlink($physical);
240 $tpl->read_file($config->{'templates'}->{'viewlink'});
242 $tpl->fillin('FILE',encode_html
($virtual));
243 $tpl->fillin('DIR',$upper_path->{'html'});
244 $tpl->fillin('DIR_URL',$upper_path->{'url'});
245 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
246 $tpl->fillin('SCRIPT',$script);
248 $tpl->fillin('LINK_TARGET',encode_html
($link_target));
254 return error
($config->{'errors'}->{'no_view'},$upper_path->{'normal'}) unless(-r
$physical);
256 # Check on binary files
257 # We have to do it in this way or empty files will be recognized
260 return error
($config->{'errors'}->{'binary_file'},$upper_path->{'normal'}) unless(-T
$physical);
262 # Is the file too large?
264 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'});
268 my $content = file_read
($physical);
269 $$content =~ s/\015\012|\012|\015/\n/g;
271 $tpl->read_file($config->{'templates'}->{'viewfile'});
273 $tpl->fillin('FILE',encode_html
($virtual));
274 $tpl->fillin('FILE_URL',escape
($virtual));
275 $tpl->fillin('DIR',$upper_path->{'html'});
276 $tpl->fillin('DIR_URL',$upper_path->{'url'});
277 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
278 $tpl->fillin('SCRIPT',$script);
280 $tpl->parse_if_block('editable',-w
$physical);
282 $tpl->fillin('CONTENT',encode_html
($$content));
285 my $output = header
(-type
=> 'text/html');
286 $output .= $tpl->get_template;
293 # Lock a file and display a form to edit it
295 # Params: 1. Reference to user input hash
296 # 2. Reference to config hash
298 # Return: Output of the command (Scalar Reference)
300 sub exec_beginedit
($$)
302 my ($data,$config) = @_;
303 my $physical = $data->{'physical'};
304 my $virtual = $data->{'virtual'};
305 my $dir = upper_path
($virtual);
307 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
308 return error
($config->{'errors'}->{'dir_edit'}, $dir) if(-d
$physical);
309 return error
($config->{'errors'}->{'no_edit'}, $dir) unless(-r
$physical && -w
$physical);
311 # Check on binary files
313 return error
($config->{'errors'}->{'binary_file'},$dir) unless(-T
$physical);
315 # Is the file too large?
317 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
319 # Show the editing form
321 my $content = file_read
($physical);
322 my $md5sum = md5_hex
($$content);
323 $$content =~ s/\015\012|\012|\015/\n/g;
325 my $tpl = new Template
;
326 $tpl->read_file($config->{'templates'}->{'editfile'});
328 $tpl->fillin('FILE',encode_html
($virtual));
329 $tpl->fillin('FILE_URL',escape
($virtual));
330 $tpl->fillin('DIR',encode_html
($dir));
331 $tpl->fillin('DIR_URL',escape
($dir));
332 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
333 $tpl->fillin('SCRIPT',$script);
334 $tpl->fillin('MD5SUM',$md5sum);
335 $tpl->fillin('CONTENT',encode_html
($$content));
337 $tpl->parse_if_block('error',0);
339 my $output = header
(-type
=> 'text/html');
340 $output .= $tpl->get_template;
347 # Save a file, unlock it and return to directory view
349 # Params: 1. Reference to user input hash
350 # 2. Reference to config hash
352 # Return: Output of the command (Scalar Reference)
356 my ($data,$config) = @_;
357 my $physical = $data->{'physical'};
358 my $virtual = $data->{'virtual'};
359 my $dir = upper_path
($virtual);
360 my $cgi = $data->{'cgi'};
361 my $content = $cgi->param('filecontent');
362 my $md5sum = $cgi->param('md5sum');
365 if(defined $content && $md5sum)
369 $content =~ s/\015\012|\012|\015/\n/g;
371 if($cgi->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
373 # Create the new filename
375 $physical = $data->{'new_physical'};
376 $virtual = $data->{'new_virtual'};
379 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
380 return error
($config->{'errors'}->{'dir_edit'},$dir) if(-d
$physical);
381 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
382 return error
($config->{'errors'}->{'text_to_binary'},$dir) if(-e
$physical && not -T
$physical);
384 # For technical reasons, we can't use file_save() for
389 sysopen(FILE
,$physical,O_RDWR
| O_CREAT
) or return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)});
390 file_lock
(*FILE
,LOCK_EX
) or do { close(FILE
); return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)}) };
392 my $md5 = new Digest
::MD5
;
393 $md5->addfile(*FILE
);
395 my $md5file = $md5->hexdigest;
396 my $md5data = md5_hex
($content);
398 if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
400 # The file changed meanwhile
402 my $tpl = new Template
;
403 $tpl->read_file($config->{'templates'}->{'editfile'});
405 $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
407 $tpl->fillin('FILE',encode_html
($virtual));
408 $tpl->fillin('FILE_URL',escape
($virtual));
409 $tpl->fillin('DIR',encode_html
($dir));
410 $tpl->fillin('DIR_URL',escape
($dir));
411 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
412 $tpl->fillin('SCRIPT',$script);
413 $tpl->fillin('MD5SUM',$md5file);
414 $tpl->fillin('CONTENT',encode_html
($content));
416 $tpl->parse_if_block('error',1);
418 my $data = header
(-type
=> 'text/html');
419 $data .= $tpl->get_template;
425 if($md5data ne $md5file)
433 $output = ($cgi->param('continue'))
434 ? devedit_reload
({command
=> 'beginedit', file
=> $virtual})
435 : devedit_reload
({command
=> 'show', file
=> $dir});
443 return devedit_reload
({command
=> 'beginedit', file
=> $virtual});
448 # Create a file and return to directory view
450 # Params: 1. Reference to user input hash
451 # 2. Reference to config hash
453 # Return: Output of the command (Scalar Reference)
457 my ($data,$config) = @_;
458 my $new_physical = $data->{'new_physical'};
459 my $new_virtual = $data->{'new_virtual'};
460 my $dir = upper_path
($new_virtual);
461 $new_virtual = encode_html
($new_virtual);
465 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
467 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
468 return devedit_reload
({command
=> 'show', file
=> $dir});
472 my $tpl = new Template
;
473 $tpl->read_file($config->{'templates'}->{'mkfile'});
475 $tpl->fillin('DIR','/');
476 $tpl->fillin('SCRIPT',$script);
478 my $output = header
(-type
=> 'text/html');
479 $output .= $tpl->get_template;
487 # Create a directory and return to directory view
489 # Params: 1. Reference to user input hash
490 # 2. Reference to config hash
492 # Return: Output of the command (Scalar Reference)
496 my ($data,$config) = @_;
497 my $new_physical = $data->{'new_physical'};
498 my $new_virtual = $data->{'new_virtual'};
499 my $dir = upper_path
($new_virtual);
500 $new_virtual = encode_html
($new_virtual);
504 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
506 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
507 return devedit_reload
({command
=> 'show', file
=> $dir});
511 my $tpl = new Template
;
512 $tpl->read_file($config->{'templates'}->{'mkdir'});
514 $tpl->fillin('DIR','/');
515 $tpl->fillin('SCRIPT',$script);
517 my $output = header
(-type
=> 'text/html');
518 $output .= $tpl->get_template;
526 # Process a file upload
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 $physical = $data->{'physical'};
537 my $virtual = $data->{'virtual'};
538 my $cgi = $data->{'cgi'};
540 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> encode_html
($virtual)}) unless(-d
$physical && not -l
$physical);
541 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> encode_html
($virtual)}) unless(-w
$physical);
543 if(my $uploaded_file = $cgi->param('uploaded_file'))
545 if($cgi->param('remote_file'))
547 $uploaded_file = $cgi->param('remote_file');
549 $uploaded_file =~ s!/!!g;
550 $uploaded_file =~ s!\\!!g;
553 # Process file upload
555 my $filename = file_name
($uploaded_file);
556 my $file_phys = $physical.'/'.$filename;
557 my $file_virt = encode_html
($virtual.$filename);
561 return error
($config->{'errors'}->{'link_replace'},$virtual) if(-l
$file_phys);
562 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
563 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
564 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
567 my $ascii = $cgi->param('ascii');
568 my $handle = $cgi->upload('uploaded_file');
570 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
572 # Read transferred file and write it to disk
574 read($handle, my $data, -s
$handle);
575 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
576 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
578 return devedit_reload
({command
=> 'show', file
=> $virtual});
582 my $tpl = new Template
;
583 $tpl->read_file($config->{'templates'}->{'upload'});
585 $tpl->fillin('DIR',encode_html
($virtual));
586 $tpl->fillin('DIR_URL',escape
($virtual));
587 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
588 $tpl->fillin('SCRIPT',$script);
590 my $output = header
(-type
=> 'text/html');
591 $output .= $tpl->get_template;
599 # Copy a file and return to directory view
601 # Params: 1. Reference to user input hash
602 # 2. Reference to config hash
604 # Return: Output of the command (Scalar Reference)
608 my ($data,$config) = @_;
609 my $physical = $data->{'physical'};
610 my $virtual = $data->{'virtual'};
611 my $dir = upper_path
($virtual);
612 my $new_physical = $data->{'new_physical'};
614 return error
($config->{'errors'}->{'link_copy'},$dir) if(-l
$physical);
615 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
619 my $new_virtual = multi_string
($data->{'new_virtual'});
620 my $new_dir = upper_path
($new_virtual->{'normal'});
624 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-x
$physical);
625 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual->{'html'}}) if(-e
$new_physical);
626 return error
($config->{'errors'}->{'dir_copy_self'},$dir) if(index($new_virtual->{'normal'},$virtual) == 0);
628 dir_copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
629 return devedit_reload
({command
=> 'show', file
=> $new_dir});
635 return error
($config->{'errors'}->{'link_replace'},$new_dir) if(-l
$new_physical);
636 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
637 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual->{'html'}}) unless(-w
$new_physical);
639 if(not $data->{'cgi'}->param('confirmed'))
641 my $tpl = new Template
;
642 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
644 $tpl->fillin('FILE',encode_html
($virtual));
645 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
646 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
647 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
648 $tpl->fillin('DIR',encode_html
($dir));
649 $tpl->fillin('DIR_URL',escape
($dir));
651 $tpl->fillin('COMMAND','copy');
652 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
653 $tpl->fillin('SCRIPT',$script);
655 my $output = header
(-type
=> 'text/html');
656 $output .= $tpl->get_template;
662 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
663 return devedit_reload
({command
=> 'show', file
=> $new_dir});
670 my $tpl = new Template
;
671 $tpl->read_file($config->{'templates'}->{'copydir'});
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;
686 my $tpl = new Template
;
687 $tpl->read_file($config->{'templates'}->{'copyfile'});
689 $tpl->fillin('FILE',encode_html
($virtual));
690 $tpl->fillin('DIR',encode_html
($dir));
691 $tpl->fillin('DIR_URL',escape
($dir));
692 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
693 $tpl->fillin('SCRIPT',$script);
695 my $output = header
(-type
=> 'text/html');
696 $output .= $tpl->get_template;
705 # Rename/move a file and return to directory view
707 # Params: 1. Reference to user input hash
708 # 2. Reference to config hash
710 # Return: Output of the command (Scalar Reference)
714 my ($data,$config) = @_;
715 my $physical = $data->{'physical'};
716 my $virtual = $data->{'virtual'};
717 my $dir = upper_path
($virtual);
718 my $new_physical = $data->{'new_physical'};
720 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
721 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
725 my $new_virtual = multi_string
($data->{'new_virtual'});
726 my $new_dir = upper_path
($new_virtual->{'normal'});
730 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical && not -l
$new_physical);
731 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
733 if(not $data->{'cgi'}->param('confirmed'))
735 my $tpl = new Template
;
736 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
738 $tpl->fillin('FILE',encode_html
($virtual));
739 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
740 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
741 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
742 $tpl->fillin('DIR',encode_html
($dir));
744 $tpl->fillin('COMMAND','rename');
745 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
746 $tpl->fillin('SCRIPT',$script);
748 my $output = header
(-type
=> 'text/html');
749 $output .= $tpl->get_template;
755 move
($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
756 return devedit_reload
({command
=> 'show', file
=> $new_dir});
760 my $tpl = new Template
;
761 $tpl->read_file($config->{'templates'}->{'renamefile'});
763 $tpl->fillin('FILE',encode_html
($virtual));
764 $tpl->fillin('DIR',encode_html
($dir));
765 $tpl->fillin('DIR_URL',escape
($dir));
766 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
767 $tpl->fillin('SCRIPT',$script);
769 my $output = header
(-type
=> 'text/html');
770 $output .= $tpl->get_template;
778 # Remove a file or a directory and return to directory view
780 # Params: 1. Reference to user input hash
781 # 2. Reference to config hash
783 # Return: Output of the command (Scalar Reference)
787 my ($data,$config) = @_;
788 my $physical = $data->{'physical'};
789 my $virtual = $data->{'virtual'};
790 my $dir = upper_path
($virtual);
792 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
793 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
795 if(-d
$physical && not -l
$physical)
799 if($data->{'cgi'}->param('confirmed'))
802 return devedit_reload
({command
=> 'show', file
=> $dir});
806 my $tpl = new Template
;
807 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
809 $tpl->fillin('DIR',encode_html
($virtual));
810 $tpl->fillin('DIR_URL',escape
($virtual));
811 $tpl->fillin('UPPER_DIR',encode_html
($dir));
812 $tpl->fillin('UPPER_DIR_URL',escape
($dir));
813 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
814 $tpl->fillin('SCRIPT',$script);
816 my $output = header
(-type
=> 'text/html');
817 $output .= $tpl->get_template;
826 if($data->{'cgi'}->param('confirmed'))
828 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
829 return devedit_reload
({command
=> 'show', file
=> $dir});
833 my $tpl = new Template
;
834 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
836 $tpl->fillin('FILE',encode_html
($virtual));
837 $tpl->fillin('FILE_URL',escape
($virtual));
838 $tpl->fillin('DIR',encode_html
($dir));
839 $tpl->fillin('DIR_URL',escape
($dir));
840 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
841 $tpl->fillin('SCRIPT',$script);
843 my $output = header
(-type
=> 'text/html');
844 $output .= $tpl->get_template;
853 # Change the mode and the group of a file or a directory
855 # Params: 1. Reference to user input hash
856 # 2. Reference to config hash
858 # Return: Output of the command (Scalar Reference)
862 my ($data,$config) = @_;
863 my $physical = $data->{'physical'};
864 my $virtual = $data->{'virtual'};
865 my $dir = upper_path
($virtual);
867 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> encode_html
($virtual)}) unless($users);
868 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
869 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> encode_html
($virtual)}) unless(-o
$physical);
870 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
872 my $cgi = $data->{'cgi'};
873 my $mode = $cgi->param('mode');
874 my $group = $cgi->param('group');
882 return error
($config->{'errors'}->{'invalid_mode'},$dir) unless($mode =~ /^[0-7]{3,}$/);
883 chmod(oct($mode),$physical);
888 # Change the group using the `chgrp` system command
890 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_html
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
891 system('chgrp',$group,$physical);
894 return devedit_reload
({command
=> 'show', file
=> $dir});
900 my @stat = stat($physical);
904 my $tpl = new Template
;
905 $tpl->read_file($config->{'templates'}->{'chprop'});
907 # Insert file properties into the template
909 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
910 $tpl->fillin('MODE_STRING',mode_string
($mode));
911 $tpl->fillin('GID',$gid);
913 if(my $group = getgrgid($gid))
915 $tpl->fillin('GROUP',encode_html
($group));
916 $tpl->parse_if_block('group_detected',1);
920 $tpl->parse_if_block('group_detected',0);
923 # Insert other information
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;
941 # Display some information about Dev-Editor
943 # Params: 1. Reference to user input hash
944 # 2. Reference to config hash
946 # Return: Output of the command (Scalar Reference)
950 my ($data,$config) = @_;
952 my $tpl = new Template
;
953 $tpl->read_file($config->{'templates'}->{'about'});
955 $tpl->fillin('SCRIPT',$script);
957 # Dev-Editor's version number
959 $tpl->fillin('VERSION',$data->{'version'});
961 # Some path information
963 $tpl->fillin('SCRIPT_PHYS',encode_html
($ENV{'SCRIPT_FILENAME'}));
964 $tpl->fillin('CONFIG_PATH',encode_html
($data->{'configfile'}));
965 $tpl->fillin('FILE_ROOT', encode_html
($config->{'fileroot'}));
966 $tpl->fillin('HTTP_ROOT', encode_html
($config->{'httproot'}));
970 $tpl->fillin('PERL_PROG',encode_html
($^X
));
971 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
973 # Information about the server
975 $tpl->fillin('HTTPD',encode_html
($ENV{'SERVER_SOFTWARE'}));
976 $tpl->fillin('OS', encode_html
($^O
));
977 $tpl->fillin('TIME', encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
979 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
981 # Process information
983 $tpl->fillin('PID',$$);
985 # The following information is only available on systems supporting
990 # Dev-Editor is running on a system which allows users and groups
991 # So we display the user and the group of our process
993 my $uid = POSIX
::getuid
;
994 my $gid = POSIX
::getgid
;
996 $tpl->parse_if_block('users',1);
998 # IDs of user and group
1000 $tpl->fillin('UID',$uid);
1001 $tpl->fillin('GID',$gid);
1003 # Names of user and group
1005 if(my $user = getpwuid($uid))
1007 $tpl->fillin('USER',encode_html
($user));
1008 $tpl->parse_if_block('user_detected',1);
1012 $tpl->parse_if_block('user_detected',0);
1015 if(my $group = getgrgid($gid))
1017 $tpl->fillin('GROUP',encode_html
($group));
1018 $tpl->parse_if_block('group_detected',1);
1022 $tpl->parse_if_block('group_detected',0);
1027 $tpl->fillin('UMASK',sprintf('%04o',umask));
1031 $tpl->parse_if_block('users',0);
1034 my $output = header
(-type
=> 'text/html');
1035 $output .= $tpl->get_template;
1040 # it's true, baby ;-)
patrick-canterino.de