]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
dbfea0b6e7c536cf278180cbe017a64afad10a0f
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2009-03-31
21 use Digest::MD5 qw(md5_hex);
22 use POSIX
qw(strftime);
31 my $script = encode_html
($ENV{'SCRIPT_NAME'});
32 my $users = eval('getpwuid(0)') && eval('getgrgid(0)');
34 my %dispatch = ('show' => \
&exec_show
,
35 'beginedit' => \
&exec_beginedit
,
36 'endedit' => \
&exec_endedit
,
37 'mkdir' => \
&exec_mkdir
,
38 'mkfile' => \
&exec_mkfile
,
39 'upload' => \
&exec_upload
,
40 'copy' => \
&exec_copy
,
41 'rename' => \
&exec_rename
,
42 'remove' => \
&exec_remove
,
43 'chprop' => \
&exec_chprop
,
44 'about' => \
&exec_about
49 use base
qw(Exporter);
51 @EXPORT = qw(exec_command);
55 # Execute the specified command
57 # Params: 1. Command to execute
58 # 2. Reference to user input hash
59 # 3. Reference to config hash
61 # Return: Output of the command (Scalar Reference)
65 my ($command,$data,$config) = @_;
67 foreach(keys(%dispatch))
69 if(lc($_) eq lc($command))
71 my $output = &{$dispatch{$_}}($data,$config);
76 return error
($config->{'errors'}->{'command_unknown'},'/',{COMMAND
=> encode_html
($command)});
81 # View a directory or a file
83 # Params: 1. Reference to user input hash
84 # 2. Reference to config hash
86 # Return: Output of the command (Scalar Reference)
90 my ($data,$config) = @_;
91 my $physical = $data->{'physical'};
92 my $virtual = $data->{'virtual'};
93 my $upper_path = multi_string
(upper_path
($virtual));
95 my $tpl = new Template
;
97 if(-d
$physical && not -l
$physical)
99 # Create directory listing
101 return error
($config->{'errors'}->{'no_dir_access'},$upper_path->{'normal'}) unless(-r
$physical && -x
$physical);
103 my $direntries = dir_read
($physical);
104 return error
($config->{'errors'}->{'dir_read_failed'},$upper_path->{'normal'},{DIR
=> encode_html
($virtual)}) unless($direntries);
106 my $files = $direntries->{'files'};
107 my $dirs = $direntries->{'dirs'};
113 my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
114 my $filter2 = ($filter1 && $filter1 ne '*') ?
$filter1 : ''; # Wildcard for output
116 # Create the link to the upper directory
117 # (only if the current directory is not the root directory)
119 unless($virtual eq '/')
123 my @stat = stat($physical.'/..');
125 my $udtpl = new Template
;
126 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
128 $udtpl->fillin('UPPER_DIR',$upper_path->{'html'});
129 $udtpl->fillin('UPPER_DIR_URL',$upper_path->{'url'});
130 $udtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
132 $dirlist .= $udtpl->get_template;
137 foreach my $dir(@
$dirs)
139 next if($config->{'hide_dot_files'} && substr($dir,0,1) eq '.');
140 next unless(dos_wildcard_match
($filter1,$dir));
144 my $phys_path = $physical.'/'.$dir;
145 my $virt_path = multi_string
($virtual.$dir.'/');
147 my @stat = stat($phys_path);
149 my $dtpl = new Template
;
150 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
152 $dtpl->fillin('DIR',$virt_path->{'html'});
153 $dtpl->fillin('DIR_URL',$virt_path->{'url'});
154 $dtpl->fillin('DIR_NAME',encode_html
($dir));
155 $dtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
156 $dtpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
158 $dtpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
159 $dtpl->parse_if_block('readable',-r
$phys_path && -x
$phys_path);
160 $dtpl->parse_if_block('users',$users && -o
$phys_path);
161 $dtpl->parse_if_block('even',($count % 2) == 0);
163 $dirlist .= $dtpl->get_template;
168 foreach my $file(@
$files)
170 next if($config->{'hide_dot_files'} && substr($file,0,1) eq '.');
171 next unless(dos_wildcard_match
($filter1,$file));
175 my $phys_path = $physical.'/'.$file;
176 my $virt_path = multi_string
($virtual.$file);
178 my @stat = lstat($phys_path);
179 my $too_large = $config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'};
181 my $ftpl = new Template
;
182 $ftpl->read_file($config->{'templates'}->{'dirlist_file'});
184 $ftpl->fillin('FILE',$virt_path->{'html'});
185 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
186 $ftpl->fillin('FILE_NAME',encode_html
($file));
187 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
188 $ftpl->fillin('SIZE',$stat[7]);
189 $ftpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
190 $ftpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
192 $ftpl->parse_if_block('link',-l
$phys_path);
193 $ftpl->parse_if_block('readable',-r
$phys_path);
194 $ftpl->parse_if_block('writeable',-w
$phys_path);
195 $ftpl->parse_if_block('binary',-B
$phys_path);
197 $ftpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
198 $ftpl->parse_if_block('viewable',(-r
$phys_path && -T
$phys_path && not $too_large) || -l
$phys_path);
199 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not -l
$phys_path);
201 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
203 $ftpl->parse_if_block('users',$users && -o
$phys_path);
205 $ftpl->parse_if_block('even',($count % 2) == 0);
207 $dirlist .= $ftpl->get_template;
210 $tpl->read_file($config->{'templates'}->{'dirlist'});
212 $tpl->fillin('DIRLIST',$dirlist);
213 $tpl->fillin('DIR',encode_html
($virtual));
214 $tpl->fillin('DIR_URL',escape
($virtual));
215 $tpl->fillin('SCRIPT',$script);
216 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
218 $tpl->fillin('FILTER',encode_html
($filter2));
219 $tpl->fillin('FILTER_URL',escape
($filter2));
221 $tpl->parse_if_block('empty',$dirlist eq '');
222 $tpl->parse_if_block('dir_writeable',-w
$physical);
223 $tpl->parse_if_block('filter',$filter2);
224 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
228 # Show the target of a symbolic link
230 my $link_target = readlink($physical);
232 $tpl->read_file($config->{'templates'}->{'viewlink'});
234 $tpl->fillin('FILE',encode_html
($virtual));
235 $tpl->fillin('DIR',$upper_path->{'html'});
236 $tpl->fillin('DIR_URL',$upper_path->{'url'});
237 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
238 $tpl->fillin('SCRIPT',$script);
240 $tpl->fillin('LINK_TARGET',encode_html
($link_target));
246 return error
($config->{'errors'}->{'no_view'},$upper_path->{'normal'}) unless(-r
$physical);
248 # Check on binary files
249 # We have to do it in this way or empty files will be recognized
252 return error
($config->{'errors'}->{'binary_file'},$upper_path->{'normal'}) unless(-T
$physical);
254 # Is the file too large?
256 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'});
260 my $content = file_read
($physical);
261 $$content =~ s/\015\012|\012|\015/\n/g;
263 $tpl->read_file($config->{'templates'}->{'viewfile'});
265 $tpl->fillin('FILE',encode_html
($virtual));
266 $tpl->fillin('FILE_URL',escape
($virtual));
267 $tpl->fillin('DIR',$upper_path->{'html'});
268 $tpl->fillin('DIR_URL',$upper_path->{'url'});
269 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
270 $tpl->fillin('SCRIPT',$script);
272 $tpl->parse_if_block('editable',-w
$physical);
274 $tpl->fillin('CONTENT',encode_html
($$content));
277 my $output = header
(-type
=> 'text/html');
278 $output .= $tpl->get_template;
285 # Lock a file and display a form to edit it
287 # Params: 1. Reference to user input hash
288 # 2. Reference to config hash
290 # Return: Output of the command (Scalar Reference)
292 sub exec_beginedit
($$)
294 my ($data,$config) = @_;
295 my $physical = $data->{'physical'};
296 my $virtual = $data->{'virtual'};
297 my $dir = upper_path
($virtual);
299 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
300 return error
($config->{'errors'}->{'dir_edit'}, $dir) if(-d
$physical);
301 return error
($config->{'errors'}->{'no_edit'}, $dir) unless(-r
$physical && -w
$physical);
303 # Check on binary files
305 return error
($config->{'errors'}->{'binary_file'},$dir) unless(-T
$physical);
307 # Is the file too large?
309 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
311 # Show the editing form
313 my $content = file_read
($physical);
314 my $md5sum = md5_hex
($$content);
315 $$content =~ s/\015\012|\012|\015/\n/g;
317 my $tpl = new Template
;
318 $tpl->read_file($config->{'templates'}->{'editfile'});
320 $tpl->fillin('FILE',encode_html
($virtual));
321 $tpl->fillin('FILE_URL',escape
($virtual));
322 $tpl->fillin('DIR',encode_html
($dir));
323 $tpl->fillin('DIR_URL',escape
($dir));
324 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
325 $tpl->fillin('SCRIPT',$script);
326 $tpl->fillin('MD5SUM',$md5sum);
327 $tpl->fillin('CONTENT',encode_html
($$content));
329 $tpl->parse_if_block('error',0);
331 my $output = header
(-type
=> 'text/html');
332 $output .= $tpl->get_template;
339 # Save a file, unlock it and return to directory view
341 # Params: 1. Reference to user input hash
342 # 2. Reference to config hash
344 # Return: Output of the command (Scalar Reference)
348 my ($data,$config) = @_;
349 my $physical = $data->{'physical'};
350 my $virtual = $data->{'virtual'};
351 my $dir = upper_path
($virtual);
352 my $cgi = $data->{'cgi'};
353 my $content = $cgi->param('filecontent');
354 my $md5sum = $cgi->param('md5sum');
357 if(defined $content && $md5sum)
361 $content =~ s/\015\012|\012|\015/\n/g;
363 if($cgi->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
365 # Create the new filename
367 $physical = $data->{'new_physical'};
368 $virtual = $data->{'new_virtual'};
371 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
372 return error
($config->{'errors'}->{'dir_edit'},$dir) if(-d
$physical);
373 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
374 return error
($config->{'errors'}->{'text_to_binary'},$dir) if(-e
$physical && not -T
$physical);
376 # For technical reasons, we can't use file_save() for
381 sysopen(FILE
,$physical,O_RDWR
| O_CREAT
) or return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)});
382 file_lock
(*FILE
,LOCK_EX
) or do { close(FILE
); return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)}) };
384 my $md5 = new Digest
::MD5
;
385 $md5->addfile(*FILE
);
387 my $md5file = $md5->hexdigest;
388 my $md5data = md5_hex
($content);
390 if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
392 # The file changed meanwhile
394 my $tpl = new Template
;
395 $tpl->read_file($config->{'templates'}->{'editfile'});
397 $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
399 $tpl->fillin('FILE',encode_html
($virtual));
400 $tpl->fillin('FILE_URL',escape
($virtual));
401 $tpl->fillin('DIR',encode_html
($dir));
402 $tpl->fillin('DIR_URL',escape
($dir));
403 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
404 $tpl->fillin('SCRIPT',$script);
405 $tpl->fillin('MD5SUM',$md5file);
406 $tpl->fillin('CONTENT',encode_html
($content));
408 $tpl->parse_if_block('error',1);
410 my $data = header
(-type
=> 'text/html');
411 $data .= $tpl->get_template;
417 if($md5data ne $md5file)
425 $output = ($cgi->param('continue'))
426 ? devedit_reload
({command
=> 'beginedit', file
=> $virtual})
427 : devedit_reload
({command
=> 'show', file
=> $dir});
435 return devedit_reload
({command
=> 'beginedit', file
=> $virtual});
440 # Create a file and return to directory view
442 # Params: 1. Reference to user input hash
443 # 2. Reference to config hash
445 # Return: Output of the command (Scalar Reference)
449 my ($data,$config) = @_;
450 my $new_physical = $data->{'new_physical'};
451 my $new_virtual = $data->{'new_virtual'};
452 my $dir = upper_path
($new_virtual);
453 $new_virtual = encode_html
($new_virtual);
457 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
459 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
460 return devedit_reload
({command
=> 'show', file
=> $dir});
464 my $tpl = new Template
;
465 $tpl->read_file($config->{'templates'}->{'mkfile'});
467 $tpl->fillin('DIR','/');
468 $tpl->fillin('SCRIPT',$script);
470 my $output = header
(-type
=> 'text/html');
471 $output .= $tpl->get_template;
479 # Create a directory 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 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
499 return devedit_reload
({command
=> 'show', file
=> $dir});
503 my $tpl = new Template
;
504 $tpl->read_file($config->{'templates'}->{'mkdir'});
506 $tpl->fillin('DIR','/');
507 $tpl->fillin('SCRIPT',$script);
509 my $output = header
(-type
=> 'text/html');
510 $output .= $tpl->get_template;
518 # Process a file upload
520 # Params: 1. Reference to user input hash
521 # 2. Reference to config hash
523 # Return: Output of the command (Scalar Reference)
527 my ($data,$config) = @_;
528 my $physical = $data->{'physical'};
529 my $virtual = $data->{'virtual'};
530 my $cgi = $data->{'cgi'};
532 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> encode_html
($virtual)}) unless(-d
$physical && not -l
$physical);
533 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> encode_html
($virtual)}) unless(-w
$physical);
535 if(my $uploaded_file = $cgi->param('uploaded_file'))
537 if($cgi->param('remote_file'))
539 $uploaded_file = $cgi->param('remote_file');
541 $uploaded_file =~ s!/!!g;
542 $uploaded_file =~ s!\\!!g;
545 # Process file upload
547 my $filename = file_name
($uploaded_file);
548 my $file_phys = $physical.'/'.$filename;
549 my $file_virt = encode_html
($virtual.$filename);
553 return error
($config->{'errors'}->{'link_replace'},$virtual) if(-l
$file_phys);
554 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
555 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
556 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
559 my $ascii = $cgi->param('ascii');
560 my $handle = $cgi->upload('uploaded_file');
562 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
564 # Read transferred file and write it to disk
566 read($handle, my $data, -s
$handle);
567 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
568 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
570 return devedit_reload
({command
=> 'show', file
=> $virtual});
574 my $tpl = new Template
;
575 $tpl->read_file($config->{'templates'}->{'upload'});
577 $tpl->fillin('DIR',encode_html
($virtual));
578 $tpl->fillin('DIR_URL',escape
($virtual));
579 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
580 $tpl->fillin('SCRIPT',$script);
582 my $output = header
(-type
=> 'text/html');
583 $output .= $tpl->get_template;
591 # Copy a file and return to directory view
593 # Params: 1. Reference to user input hash
594 # 2. Reference to config hash
596 # Return: Output of the command (Scalar Reference)
600 my ($data,$config) = @_;
601 my $physical = $data->{'physical'};
602 my $virtual = $data->{'virtual'};
603 my $dir = upper_path
($virtual);
604 my $new_physical = $data->{'new_physical'};
606 return error
($config->{'errors'}->{'link_copy'},$dir) if(-l
$physical);
607 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
611 my $new_virtual = multi_string
($data->{'new_virtual'});
612 my $new_dir = upper_path
($new_virtual->{'normal'});
616 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-x
$physical);
617 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual->{'html'}}) if(-e
$new_physical);
618 return error
($config->{'errors'}->{'dir_copy_self'},$dir) if(index($new_virtual->{'normal'},$virtual) == 0);
620 dir_copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
621 return devedit_reload
({command
=> 'show', file
=> $new_dir});
627 return error
($config->{'errors'}->{'link_replace'},$new_dir) if(-l
$new_physical);
628 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
629 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual->{'html'}}) unless(-w
$new_physical);
631 if(not $data->{'cgi'}->param('confirmed'))
633 my $tpl = new Template
;
634 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
636 $tpl->fillin('FILE',encode_html
($virtual));
637 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
638 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
639 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
640 $tpl->fillin('DIR',encode_html
($dir));
641 $tpl->fillin('DIR_URL',escape
($dir));
643 $tpl->fillin('COMMAND','copy');
644 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
645 $tpl->fillin('SCRIPT',$script);
647 my $output = header
(-type
=> 'text/html');
648 $output .= $tpl->get_template;
654 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
655 return devedit_reload
({command
=> 'show', file
=> $new_dir});
662 my $tpl = new Template
;
663 $tpl->read_file($config->{'templates'}->{'copydir'});
665 $tpl->fillin('FILE',encode_html
($virtual));
666 $tpl->fillin('DIR',encode_html
($dir));
667 $tpl->fillin('DIR_URL',escape
($dir));
668 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
669 $tpl->fillin('SCRIPT',$script);
671 my $output = header
(-type
=> 'text/html');
672 $output .= $tpl->get_template;
678 my $tpl = new Template
;
679 $tpl->read_file($config->{'templates'}->{'copyfile'});
681 $tpl->fillin('FILE',encode_html
($virtual));
682 $tpl->fillin('DIR',encode_html
($dir));
683 $tpl->fillin('DIR_URL',escape
($dir));
684 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
685 $tpl->fillin('SCRIPT',$script);
687 my $output = header
(-type
=> 'text/html');
688 $output .= $tpl->get_template;
697 # Rename/move a file and return to directory view
699 # Params: 1. Reference to user input hash
700 # 2. Reference to config hash
702 # Return: Output of the command (Scalar Reference)
706 my ($data,$config) = @_;
707 my $physical = $data->{'physical'};
708 my $virtual = $data->{'virtual'};
709 my $dir = upper_path
($virtual);
710 my $new_physical = $data->{'new_physical'};
712 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
713 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
717 my $new_virtual = multi_string
($data->{'new_virtual'});
718 my $new_dir = upper_path
($new_virtual->{'normal'});
722 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical && not -l
$new_physical);
723 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
725 if(not $data->{'cgi'}->param('confirmed'))
727 my $tpl = new Template
;
728 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
730 $tpl->fillin('FILE',encode_html
($virtual));
731 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
732 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
733 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
734 $tpl->fillin('DIR',encode_html
($dir));
736 $tpl->fillin('COMMAND','rename');
737 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
738 $tpl->fillin('SCRIPT',$script);
740 my $output = header
(-type
=> 'text/html');
741 $output .= $tpl->get_template;
747 move
($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
748 return devedit_reload
({command
=> 'show', file
=> $new_dir});
752 my $tpl = new Template
;
753 $tpl->read_file($config->{'templates'}->{'renamefile'});
755 $tpl->fillin('FILE',encode_html
($virtual));
756 $tpl->fillin('DIR',encode_html
($dir));
757 $tpl->fillin('DIR_URL',escape
($dir));
758 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
759 $tpl->fillin('SCRIPT',$script);
761 my $output = header
(-type
=> 'text/html');
762 $output .= $tpl->get_template;
770 # Remove a file or a directory and return to directory view
772 # Params: 1. Reference to user input hash
773 # 2. Reference to config hash
775 # Return: Output of the command (Scalar Reference)
779 my ($data,$config) = @_;
780 my $physical = $data->{'physical'};
781 my $virtual = $data->{'virtual'};
782 my $dir = upper_path
($virtual);
784 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
785 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
787 if(-d
$physical && not -l
$physical)
791 if($data->{'cgi'}->param('confirmed'))
794 return devedit_reload
({command
=> 'show', file
=> $dir});
798 my $tpl = new Template
;
799 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
801 $tpl->fillin('DIR',encode_html
($virtual));
802 $tpl->fillin('DIR_URL',escape
($virtual));
803 $tpl->fillin('UPPER_DIR',encode_html
($dir));
804 $tpl->fillin('UPPER_DIR_URL',escape
($dir));
805 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
806 $tpl->fillin('SCRIPT',$script);
808 my $output = header
(-type
=> 'text/html');
809 $output .= $tpl->get_template;
818 if($data->{'cgi'}->param('confirmed'))
820 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
821 return devedit_reload
({command
=> 'show', file
=> $dir});
825 my $tpl = new Template
;
826 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
828 $tpl->fillin('FILE',encode_html
($virtual));
829 $tpl->fillin('FILE_URL',escape
($virtual));
830 $tpl->fillin('DIR',encode_html
($dir));
831 $tpl->fillin('DIR_URL',escape
($dir));
832 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
833 $tpl->fillin('SCRIPT',$script);
835 my $output = header
(-type
=> 'text/html');
836 $output .= $tpl->get_template;
845 # Change the mode and the group of a file or a directory
847 # Params: 1. Reference to user input hash
848 # 2. Reference to config hash
850 # Return: Output of the command (Scalar Reference)
854 my ($data,$config) = @_;
855 my $physical = $data->{'physical'};
856 my $virtual = $data->{'virtual'};
857 my $dir = upper_path
($virtual);
859 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> encode_html
($virtual)}) unless($users);
860 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
861 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> encode_html
($virtual)}) unless(-o
$physical);
862 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
864 my $cgi = $data->{'cgi'};
865 my $mode = $cgi->param('mode');
866 my $group = $cgi->param('group');
874 return error
($config->{'errors'}->{'invalid_mode'},$dir) unless($mode =~ /^[0-7]{3,}$/);
875 chmod(oct($mode),$physical);
880 # Change the group using the `chgrp` system command
882 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_html
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
883 system('chgrp',$group,$physical);
886 return devedit_reload
({command
=> 'show', file
=> $dir});
892 my @stat = stat($physical);
896 my $tpl = new Template
;
897 $tpl->read_file($config->{'templates'}->{'chprop'});
899 # Insert file properties into the template
901 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
902 $tpl->fillin('MODE_STRING',mode_string
($mode));
903 $tpl->fillin('GID',$gid);
905 if(my $group = getgrgid($gid))
907 $tpl->fillin('GROUP',encode_html
($group));
908 $tpl->parse_if_block('group_detected',1);
912 $tpl->parse_if_block('group_detected',0);
915 # Insert other information
917 $tpl->fillin('FILE',encode_html
($virtual));
918 $tpl->fillin('FILE_URL',escape
($virtual));
919 $tpl->fillin('DIR',encode_html
($dir));
920 $tpl->fillin('DIR_URL',escape
($dir));
921 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
922 $tpl->fillin('SCRIPT',$script);
924 my $output = header
(-type
=> 'text/html');
925 $output .= $tpl->get_template;
933 # Display some information about Dev-Editor
935 # Params: 1. Reference to user input hash
936 # 2. Reference to config hash
938 # Return: Output of the command (Scalar Reference)
942 my ($data,$config) = @_;
944 my $tpl = new Template
;
945 $tpl->read_file($config->{'templates'}->{'about'});
947 $tpl->fillin('SCRIPT',$script);
949 # Dev-Editor's version number
951 $tpl->fillin('VERSION',$data->{'version'});
953 # Some path information
955 $tpl->fillin('SCRIPT_PHYS',encode_html
($ENV{'SCRIPT_FILENAME'}));
956 $tpl->fillin('CONFIG_PATH',encode_html
($data->{'configfile'}));
957 $tpl->fillin('FILE_ROOT', encode_html
($config->{'fileroot'}));
958 $tpl->fillin('HTTP_ROOT', encode_html
($config->{'httproot'}));
962 $tpl->fillin('PERL_PROG',encode_html
($^X
));
963 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
965 # Information about the server
967 $tpl->fillin('HTTPD',encode_html
($ENV{'SERVER_SOFTWARE'}));
968 $tpl->fillin('OS', encode_html
($^O
));
969 $tpl->fillin('TIME', encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
971 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
973 # Process information
975 $tpl->fillin('PID',$$);
977 # The following information is only available on systems supporting
982 # Dev-Editor is running on a system which allows users and groups
983 # So we display the user and the group of our process
985 my $uid = POSIX
::getuid
;
986 my $gid = POSIX
::getgid
;
988 $tpl->parse_if_block('users',1);
990 # IDs of user and group
992 $tpl->fillin('UID',$uid);
993 $tpl->fillin('GID',$gid);
995 # Names of user and group
997 if(my $user = getpwuid($uid))
999 $tpl->fillin('USER',encode_html
($user));
1000 $tpl->parse_if_block('user_detected',1);
1004 $tpl->parse_if_block('user_detected',0);
1007 if(my $group = getgrgid($gid))
1009 $tpl->fillin('GROUP',encode_html
($group));
1010 $tpl->parse_if_block('group_detected',1);
1014 $tpl->parse_if_block('group_detected',0);
1019 $tpl->fillin('UMASK',sprintf('%04o',umask));
1023 $tpl->parse_if_block('users',0);
1026 my $output = header
(-type
=> 'text/html');
1027 $output .= $tpl->get_template;
1032 # it's true, baby ;-)
patrick-canterino.de