]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
2905545490d5458f307697871485ceefb89e12fd
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2009-03-30
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'};
111 my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
112 my $filter2 = ($filter1 && $filter1 ne '*') ?
$filter1 : ''; # Wildcard for output
114 # Create the link to the upper directory
115 # (only if the current directory is not the root directory)
117 unless($virtual eq '/')
119 my @stat = stat($physical.'/..');
121 my $udtpl = new Template
;
122 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
124 $udtpl->fillin('UPPER_DIR',$upper_path->{'html'});
125 $udtpl->fillin('UPPER_DIR_URL',$upper_path->{'url'});
126 $udtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
128 $dirlist .= $udtpl->get_template;
133 foreach my $dir(@
$dirs)
135 next unless(dos_wildcard_match
($filter1,$dir));
137 my $phys_path = $physical.'/'.$dir;
138 my $virt_path = multi_string
($virtual.$dir.'/');
140 my @stat = stat($phys_path);
142 my $dtpl = new Template
;
143 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
145 $dtpl->fillin('DIR',$virt_path->{'html'});
146 $dtpl->fillin('DIR_URL',$virt_path->{'url'});
147 $dtpl->fillin('DIR_NAME',encode_html
($dir));
148 $dtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
149 $dtpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
151 $dtpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
152 $dtpl->parse_if_block('readable',-r
$phys_path && -x
$phys_path);
153 $dtpl->parse_if_block('users',$users && -o
$phys_path);
155 $dirlist .= $dtpl->get_template;
160 foreach my $file(@
$files)
162 next unless(dos_wildcard_match
($filter1,$file));
164 my $phys_path = $physical.'/'.$file;
165 my $virt_path = multi_string
($virtual.$file);
167 my @stat = lstat($phys_path);
168 my $too_large = $config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'};
170 my $ftpl = new Template
;
171 $ftpl->read_file($config->{'templates'}->{'dirlist_file'});
173 $ftpl->fillin('FILE',$virt_path->{'html'});
174 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
175 $ftpl->fillin('FILE_NAME',encode_html
($file));
176 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
177 $ftpl->fillin('SIZE',$stat[7]);
178 $ftpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
179 $ftpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
181 $ftpl->parse_if_block('link',-l
$phys_path);
182 $ftpl->parse_if_block('readable',-r
$phys_path);
183 $ftpl->parse_if_block('writeable',-w
$phys_path);
184 $ftpl->parse_if_block('binary',-B
$phys_path);
186 $ftpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
187 $ftpl->parse_if_block('viewable',(-r
$phys_path && -T
$phys_path && not $too_large) || -l
$phys_path);
188 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not -l
$phys_path);
190 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
192 $ftpl->parse_if_block('users',$users && -o
$phys_path);
194 $dirlist .= $ftpl->get_template;
197 $tpl->read_file($config->{'templates'}->{'dirlist'});
199 $tpl->fillin('DIRLIST',$dirlist);
200 $tpl->fillin('DIR',encode_html
($virtual));
201 $tpl->fillin('DIR_URL',escape
($virtual));
202 $tpl->fillin('SCRIPT',$script);
203 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
205 $tpl->fillin('FILTER',encode_html
($filter2));
206 $tpl->fillin('FILTER_URL',escape
($filter2));
208 $tpl->parse_if_block('empty',$dirlist eq '');
209 $tpl->parse_if_block('dir_writeable',-w
$physical);
210 $tpl->parse_if_block('filter',$filter2);
211 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
215 # Show the target of a symbolic link
217 my $link_target = readlink($physical);
219 $tpl->read_file($config->{'templates'}->{'viewlink'});
221 $tpl->fillin('FILE',encode_html
($virtual));
222 $tpl->fillin('DIR',$upper_path->{'html'});
223 $tpl->fillin('DIR_URL',$upper_path->{'url'});
224 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
225 $tpl->fillin('SCRIPT',$script);
227 $tpl->fillin('LINK_TARGET',encode_html
($link_target));
233 return error
($config->{'errors'}->{'no_view'},$upper_path->{'normal'}) unless(-r
$physical);
235 # Check on binary files
236 # We have to do it in this way or empty files will be recognized
239 return error
($config->{'errors'}->{'binary_file'},$upper_path->{'normal'}) unless(-T
$physical);
241 # Is the file too large?
243 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'});
247 my $content = file_read
($physical);
248 $$content =~ s/\015\012|\012|\015/\n/g;
250 $tpl->read_file($config->{'templates'}->{'viewfile'});
252 $tpl->fillin('FILE',encode_html
($virtual));
253 $tpl->fillin('FILE_URL',escape
($virtual));
254 $tpl->fillin('DIR',$upper_path->{'html'});
255 $tpl->fillin('DIR_URL',$upper_path->{'url'});
256 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
257 $tpl->fillin('SCRIPT',$script);
259 $tpl->parse_if_block('editable',-w
$physical);
261 $tpl->fillin('CONTENT',encode_html
($$content));
264 my $output = header
(-type
=> 'text/html');
265 $output .= $tpl->get_template;
272 # Lock a file and display a form to edit it
274 # Params: 1. Reference to user input hash
275 # 2. Reference to config hash
277 # Return: Output of the command (Scalar Reference)
279 sub exec_beginedit
($$)
281 my ($data,$config) = @_;
282 my $physical = $data->{'physical'};
283 my $virtual = $data->{'virtual'};
284 my $dir = upper_path
($virtual);
286 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
287 return error
($config->{'errors'}->{'dir_edit'}, $dir) if(-d
$physical);
288 return error
($config->{'errors'}->{'no_edit'}, $dir) unless(-r
$physical && -w
$physical);
290 # Check on binary files
292 return error
($config->{'errors'}->{'binary_file'},$dir) unless(-T
$physical);
294 # Is the file too large?
296 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
298 # Show the editing form
300 my $content = file_read
($physical);
301 my $md5sum = md5_hex
($$content);
302 $$content =~ s/\015\012|\012|\015/\n/g;
304 my $tpl = new Template
;
305 $tpl->read_file($config->{'templates'}->{'editfile'});
307 $tpl->fillin('FILE',encode_html
($virtual));
308 $tpl->fillin('FILE_URL',escape
($virtual));
309 $tpl->fillin('DIR',encode_html
($dir));
310 $tpl->fillin('DIR_URL',escape
($dir));
311 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
312 $tpl->fillin('SCRIPT',$script);
313 $tpl->fillin('MD5SUM',$md5sum);
314 $tpl->fillin('CONTENT',encode_html
($$content));
316 $tpl->parse_if_block('error',0);
318 my $output = header
(-type
=> 'text/html');
319 $output .= $tpl->get_template;
326 # Save a file, unlock it and return to directory view
328 # Params: 1. Reference to user input hash
329 # 2. Reference to config hash
331 # Return: Output of the command (Scalar Reference)
335 my ($data,$config) = @_;
336 my $physical = $data->{'physical'};
337 my $virtual = $data->{'virtual'};
338 my $dir = upper_path
($virtual);
339 my $cgi = $data->{'cgi'};
340 my $content = $cgi->param('filecontent');
341 my $md5sum = $cgi->param('md5sum');
344 if(defined $content && $md5sum)
348 $content =~ s/\015\012|\012|\015/\n/g;
350 if($cgi->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
352 # Create the new filename
354 $physical = $data->{'new_physical'};
355 $virtual = $data->{'new_virtual'};
358 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
359 return error
($config->{'errors'}->{'dir_edit'},$dir) if(-d
$physical);
360 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
361 return error
($config->{'errors'}->{'text_to_binary'},$dir) if(-e
$physical && not -T
$physical);
363 # For technical reasons, we can't use file_save() for
368 sysopen(FILE
,$physical,O_RDWR
| O_CREAT
) or return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)});
369 file_lock
(*FILE
,LOCK_EX
) or do { close(FILE
); return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)}) };
371 my $md5 = new Digest
::MD5
;
372 $md5->addfile(*FILE
);
374 my $md5file = $md5->hexdigest;
375 my $md5data = md5_hex
($content);
377 if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
379 # The file changed meanwhile
381 my $tpl = new Template
;
382 $tpl->read_file($config->{'templates'}->{'editfile'});
384 $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
386 $tpl->fillin('FILE',encode_html
($virtual));
387 $tpl->fillin('FILE_URL',escape
($virtual));
388 $tpl->fillin('DIR',encode_html
($dir));
389 $tpl->fillin('DIR_URL',escape
($dir));
390 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
391 $tpl->fillin('SCRIPT',$script);
392 $tpl->fillin('MD5SUM',$md5file);
393 $tpl->fillin('CONTENT',encode_html
($content));
395 $tpl->parse_if_block('error',1);
397 my $data = header
(-type
=> 'text/html');
398 $data .= $tpl->get_template;
404 if($md5data ne $md5file)
412 $output = ($cgi->param('continue'))
413 ? devedit_reload
({command
=> 'beginedit', file
=> $virtual})
414 : devedit_reload
({command
=> 'show', file
=> $dir});
422 return devedit_reload
({command
=> 'beginedit', file
=> $virtual});
427 # Create a file and return to directory view
429 # Params: 1. Reference to user input hash
430 # 2. Reference to config hash
432 # Return: Output of the command (Scalar Reference)
436 my ($data,$config) = @_;
437 my $new_physical = $data->{'new_physical'};
438 my $new_virtual = $data->{'new_virtual'};
439 my $dir = upper_path
($new_virtual);
440 $new_virtual = encode_html
($new_virtual);
444 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
446 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
447 return devedit_reload
({command
=> 'show', file
=> $dir});
451 my $tpl = new Template
;
452 $tpl->read_file($config->{'templates'}->{'mkfile'});
454 $tpl->fillin('DIR','/');
455 $tpl->fillin('SCRIPT',$script);
457 my $output = header
(-type
=> 'text/html');
458 $output .= $tpl->get_template;
466 # Create a directory and return to directory view
468 # Params: 1. Reference to user input hash
469 # 2. Reference to config hash
471 # Return: Output of the command (Scalar Reference)
475 my ($data,$config) = @_;
476 my $new_physical = $data->{'new_physical'};
477 my $new_virtual = $data->{'new_virtual'};
478 my $dir = upper_path
($new_virtual);
479 $new_virtual = encode_html
($new_virtual);
483 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
485 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
486 return devedit_reload
({command
=> 'show', file
=> $dir});
490 my $tpl = new Template
;
491 $tpl->read_file($config->{'templates'}->{'mkdir'});
493 $tpl->fillin('DIR','/');
494 $tpl->fillin('SCRIPT',$script);
496 my $output = header
(-type
=> 'text/html');
497 $output .= $tpl->get_template;
505 # Process a file upload
507 # Params: 1. Reference to user input hash
508 # 2. Reference to config hash
510 # Return: Output of the command (Scalar Reference)
514 my ($data,$config) = @_;
515 my $physical = $data->{'physical'};
516 my $virtual = $data->{'virtual'};
517 my $cgi = $data->{'cgi'};
519 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> encode_html
($virtual)}) unless(-d
$physical && not -l
$physical);
520 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> encode_html
($virtual)}) unless(-w
$physical);
522 if(my $uploaded_file = $cgi->param('uploaded_file'))
524 if($cgi->param('remote_file'))
526 $uploaded_file = $cgi->param('remote_file');
528 $uploaded_file =~ s!/!!g;
529 $uploaded_file =~ s!\\!!g;
532 # Process file upload
534 my $filename = file_name
($uploaded_file);
535 my $file_phys = $physical.'/'.$filename;
536 my $file_virt = encode_html
($virtual.$filename);
540 return error
($config->{'errors'}->{'link_replace'},$virtual) if(-l
$file_phys);
541 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
542 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
543 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
546 my $ascii = $cgi->param('ascii');
547 my $handle = $cgi->upload('uploaded_file');
549 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
551 # Read transferred file and write it to disk
553 read($handle, my $data, -s
$handle);
554 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
555 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
557 return devedit_reload
({command
=> 'show', file
=> $virtual});
561 my $tpl = new Template
;
562 $tpl->read_file($config->{'templates'}->{'upload'});
564 $tpl->fillin('DIR',encode_html
($virtual));
565 $tpl->fillin('DIR_URL',escape
($virtual));
566 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
567 $tpl->fillin('SCRIPT',$script);
569 my $output = header
(-type
=> 'text/html');
570 $output .= $tpl->get_template;
578 # Copy a file and return to directory view
580 # Params: 1. Reference to user input hash
581 # 2. Reference to config hash
583 # Return: Output of the command (Scalar Reference)
587 my ($data,$config) = @_;
588 my $physical = $data->{'physical'};
589 my $virtual = $data->{'virtual'};
590 my $dir = upper_path
($virtual);
591 my $new_physical = $data->{'new_physical'};
593 return error
($config->{'errors'}->{'link_copy'},$dir) if(-l
$physical);
594 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
598 my $new_virtual = multi_string
($data->{'new_virtual'});
599 my $new_dir = upper_path
($new_virtual->{'normal'});
603 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-x
$physical);
604 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual->{'html'}}) if(-e
$new_physical);
605 return error
($config->{'errors'}->{'dir_copy_self'},$dir) if(index($new_virtual->{'normal'},$virtual) == 0);
607 dir_copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
608 return devedit_reload
({command
=> 'show', file
=> $new_dir});
614 return error
($config->{'errors'}->{'link_replace'},$new_dir) if(-l
$new_physical);
615 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
616 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual->{'html'}}) unless(-w
$new_physical);
618 if(not $data->{'cgi'}->param('confirmed'))
620 my $tpl = new Template
;
621 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
623 $tpl->fillin('FILE',encode_html
($virtual));
624 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
625 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
626 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
627 $tpl->fillin('DIR',encode_html
($dir));
628 $tpl->fillin('DIR_URL',escape
($dir));
630 $tpl->fillin('COMMAND','copy');
631 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
632 $tpl->fillin('SCRIPT',$script);
634 my $output = header
(-type
=> 'text/html');
635 $output .= $tpl->get_template;
641 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
642 return devedit_reload
({command
=> 'show', file
=> $new_dir});
649 my $tpl = new Template
;
650 $tpl->read_file($config->{'templates'}->{'copydir'});
652 $tpl->fillin('FILE',encode_html
($virtual));
653 $tpl->fillin('DIR',encode_html
($dir));
654 $tpl->fillin('DIR_URL',escape
($dir));
655 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
656 $tpl->fillin('SCRIPT',$script);
658 my $output = header
(-type
=> 'text/html');
659 $output .= $tpl->get_template;
665 my $tpl = new Template
;
666 $tpl->read_file($config->{'templates'}->{'copyfile'});
668 $tpl->fillin('FILE',encode_html
($virtual));
669 $tpl->fillin('DIR',encode_html
($dir));
670 $tpl->fillin('DIR_URL',escape
($dir));
671 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
672 $tpl->fillin('SCRIPT',$script);
674 my $output = header
(-type
=> 'text/html');
675 $output .= $tpl->get_template;
684 # Rename/move a file and return to directory view
686 # Params: 1. Reference to user input hash
687 # 2. Reference to config hash
689 # Return: Output of the command (Scalar Reference)
693 my ($data,$config) = @_;
694 my $physical = $data->{'physical'};
695 my $virtual = $data->{'virtual'};
696 my $dir = upper_path
($virtual);
697 my $new_physical = $data->{'new_physical'};
699 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
700 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
704 my $new_virtual = multi_string
($data->{'new_virtual'});
705 my $new_dir = upper_path
($new_virtual->{'normal'});
709 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical && not -l
$new_physical);
710 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
712 if(not $data->{'cgi'}->param('confirmed'))
714 my $tpl = new Template
;
715 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
717 $tpl->fillin('FILE',encode_html
($virtual));
718 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
719 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
720 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
721 $tpl->fillin('DIR',encode_html
($dir));
723 $tpl->fillin('COMMAND','rename');
724 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
725 $tpl->fillin('SCRIPT',$script);
727 my $output = header
(-type
=> 'text/html');
728 $output .= $tpl->get_template;
734 move
($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
735 return devedit_reload
({command
=> 'show', file
=> $new_dir});
739 my $tpl = new Template
;
740 $tpl->read_file($config->{'templates'}->{'renamefile'});
742 $tpl->fillin('FILE',encode_html
($virtual));
743 $tpl->fillin('DIR',encode_html
($dir));
744 $tpl->fillin('DIR_URL',escape
($dir));
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;
757 # Remove a file or a directory and return to directory view
759 # Params: 1. Reference to user input hash
760 # 2. Reference to config hash
762 # Return: Output of the command (Scalar Reference)
766 my ($data,$config) = @_;
767 my $physical = $data->{'physical'};
768 my $virtual = $data->{'virtual'};
769 my $dir = upper_path
($virtual);
771 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
772 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
774 if(-d
$physical && not -l
$physical)
778 if($data->{'cgi'}->param('confirmed'))
781 return devedit_reload
({command
=> 'show', file
=> $dir});
785 my $tpl = new Template
;
786 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
788 $tpl->fillin('DIR',encode_html
($virtual));
789 $tpl->fillin('DIR_URL',escape
($virtual));
790 $tpl->fillin('UPPER_DIR',encode_html
($dir));
791 $tpl->fillin('UPPER_DIR_URL',escape
($dir));
792 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
793 $tpl->fillin('SCRIPT',$script);
795 my $output = header
(-type
=> 'text/html');
796 $output .= $tpl->get_template;
805 if($data->{'cgi'}->param('confirmed'))
807 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
808 return devedit_reload
({command
=> 'show', file
=> $dir});
812 my $tpl = new Template
;
813 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
815 $tpl->fillin('FILE',encode_html
($virtual));
816 $tpl->fillin('FILE_URL',escape
($virtual));
817 $tpl->fillin('DIR',encode_html
($dir));
818 $tpl->fillin('DIR_URL',escape
($dir));
819 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
820 $tpl->fillin('SCRIPT',$script);
822 my $output = header
(-type
=> 'text/html');
823 $output .= $tpl->get_template;
832 # Change the mode and the group of a file or a directory
834 # Params: 1. Reference to user input hash
835 # 2. Reference to config hash
837 # Return: Output of the command (Scalar Reference)
841 my ($data,$config) = @_;
842 my $physical = $data->{'physical'};
843 my $virtual = $data->{'virtual'};
844 my $dir = upper_path
($virtual);
846 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> encode_html
($virtual)}) unless($users);
847 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
848 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> encode_html
($virtual)}) unless(-o
$physical);
849 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
851 my $cgi = $data->{'cgi'};
852 my $mode = $cgi->param('mode');
853 my $group = $cgi->param('group');
861 return error
($config->{'errors'}->{'invalid_mode'},$dir) unless($mode =~ /^[0-7]{3,}$/);
862 chmod(oct($mode),$physical);
867 # Change the group using the `chgrp` system command
869 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_html
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
870 system('chgrp',$group,$physical);
873 return devedit_reload
({command
=> 'show', file
=> $dir});
879 my @stat = stat($physical);
883 my $tpl = new Template
;
884 $tpl->read_file($config->{'templates'}->{'chprop'});
886 # Insert file properties into the template
888 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
889 $tpl->fillin('MODE_STRING',mode_string
($mode));
890 $tpl->fillin('GID',$gid);
892 if(my $group = getgrgid($gid))
894 $tpl->fillin('GROUP',encode_html
($group));
895 $tpl->parse_if_block('group_detected',1);
899 $tpl->parse_if_block('group_detected',0);
902 # Insert other information
904 $tpl->fillin('FILE',encode_html
($virtual));
905 $tpl->fillin('FILE_URL',escape
($virtual));
906 $tpl->fillin('DIR',encode_html
($dir));
907 $tpl->fillin('DIR_URL',escape
($dir));
908 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
909 $tpl->fillin('SCRIPT',$script);
911 my $output = header
(-type
=> 'text/html');
912 $output .= $tpl->get_template;
920 # Display some information about Dev-Editor
922 # Params: 1. Reference to user input hash
923 # 2. Reference to config hash
925 # Return: Output of the command (Scalar Reference)
929 my ($data,$config) = @_;
931 my $tpl = new Template
;
932 $tpl->read_file($config->{'templates'}->{'about'});
934 $tpl->fillin('SCRIPT',$script);
936 # Dev-Editor's version number
938 $tpl->fillin('VERSION',$data->{'version'});
940 # Some path information
942 $tpl->fillin('SCRIPT_PHYS',encode_html
($ENV{'SCRIPT_FILENAME'}));
943 $tpl->fillin('CONFIG_PATH',encode_html
($data->{'configfile'}));
944 $tpl->fillin('FILE_ROOT', encode_html
($config->{'fileroot'}));
945 $tpl->fillin('HTTP_ROOT', encode_html
($config->{'httproot'}));
949 $tpl->fillin('PERL_PROG',encode_html
($^X
));
950 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
952 # Information about the server
954 $tpl->fillin('HTTPD',encode_html
($ENV{'SERVER_SOFTWARE'}));
955 $tpl->fillin('OS', encode_html
($^O
));
956 $tpl->fillin('TIME', encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
958 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
960 # Process information
962 $tpl->fillin('PID',$$);
964 # The following information is only available on systems supporting
969 # Dev-Editor is running on a system which allows users and groups
970 # So we display the user and the group of our process
972 my $uid = POSIX
::getuid
;
973 my $gid = POSIX
::getgid
;
975 $tpl->parse_if_block('users',1);
977 # IDs of user and group
979 $tpl->fillin('UID',$uid);
980 $tpl->fillin('GID',$gid);
982 # Names of user and group
984 if(my $user = getpwuid($uid))
986 $tpl->fillin('USER',encode_html
($user));
987 $tpl->parse_if_block('user_detected',1);
991 $tpl->parse_if_block('user_detected',0);
994 if(my $group = getgrgid($gid))
996 $tpl->fillin('GROUP',encode_html
($group));
997 $tpl->parse_if_block('group_detected',1);
1001 $tpl->parse_if_block('group_detected',0);
1006 $tpl->fillin('UMASK',sprintf('%04o',umask));
1010 $tpl->parse_if_block('users',0);
1013 my $output = header
(-type
=> 'text/html');
1014 $output .= $tpl->get_template;
1019 # it's true, baby ;-)
patrick-canterino.de