]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
a35abd4af5d24967c337f81eaeb90c03414ecc48
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 if($config->{'hide_dot_files'} && substr($dir,0,1) eq '.');
136 next unless(dos_wildcard_match
($filter1,$dir));
138 my $phys_path = $physical.'/'.$dir;
139 my $virt_path = multi_string
($virtual.$dir.'/');
141 my @stat = stat($phys_path);
143 my $dtpl = new Template
;
144 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
146 $dtpl->fillin('DIR',$virt_path->{'html'});
147 $dtpl->fillin('DIR_URL',$virt_path->{'url'});
148 $dtpl->fillin('DIR_NAME',encode_html
($dir));
149 $dtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
150 $dtpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
152 $dtpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
153 $dtpl->parse_if_block('readable',-r
$phys_path && -x
$phys_path);
154 $dtpl->parse_if_block('users',$users && -o
$phys_path);
156 $dirlist .= $dtpl->get_template;
161 foreach my $file(@
$files)
163 next if($config->{'hide_dot_files'} && substr($file,0,1) eq '.');
164 next unless(dos_wildcard_match
($filter1,$file));
166 my $phys_path = $physical.'/'.$file;
167 my $virt_path = multi_string
($virtual.$file);
169 my @stat = lstat($phys_path);
170 my $too_large = $config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'};
172 my $ftpl = new Template
;
173 $ftpl->read_file($config->{'templates'}->{'dirlist_file'});
175 $ftpl->fillin('FILE',$virt_path->{'html'});
176 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
177 $ftpl->fillin('FILE_NAME',encode_html
($file));
178 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
179 $ftpl->fillin('SIZE',$stat[7]);
180 $ftpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
181 $ftpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
183 $ftpl->parse_if_block('link',-l
$phys_path);
184 $ftpl->parse_if_block('readable',-r
$phys_path);
185 $ftpl->parse_if_block('writeable',-w
$phys_path);
186 $ftpl->parse_if_block('binary',-B
$phys_path);
188 $ftpl->parse_if_block('forbidden',is_forbidden_file
($config->{'forbidden'},$virt_path->{'normal'}));
189 $ftpl->parse_if_block('viewable',(-r
$phys_path && -T
$phys_path && not $too_large) || -l
$phys_path);
190 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not -l
$phys_path);
192 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
194 $ftpl->parse_if_block('users',$users && -o
$phys_path);
196 $dirlist .= $ftpl->get_template;
199 $tpl->read_file($config->{'templates'}->{'dirlist'});
201 $tpl->fillin('DIRLIST',$dirlist);
202 $tpl->fillin('DIR',encode_html
($virtual));
203 $tpl->fillin('DIR_URL',escape
($virtual));
204 $tpl->fillin('SCRIPT',$script);
205 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
207 $tpl->fillin('FILTER',encode_html
($filter2));
208 $tpl->fillin('FILTER_URL',escape
($filter2));
210 $tpl->parse_if_block('empty',$dirlist eq '');
211 $tpl->parse_if_block('dir_writeable',-w
$physical);
212 $tpl->parse_if_block('filter',$filter2);
213 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
217 # Show the target of a symbolic link
219 my $link_target = readlink($physical);
221 $tpl->read_file($config->{'templates'}->{'viewlink'});
223 $tpl->fillin('FILE',encode_html
($virtual));
224 $tpl->fillin('DIR',$upper_path->{'html'});
225 $tpl->fillin('DIR_URL',$upper_path->{'url'});
226 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
227 $tpl->fillin('SCRIPT',$script);
229 $tpl->fillin('LINK_TARGET',encode_html
($link_target));
235 return error
($config->{'errors'}->{'no_view'},$upper_path->{'normal'}) unless(-r
$physical);
237 # Check on binary files
238 # We have to do it in this way or empty files will be recognized
241 return error
($config->{'errors'}->{'binary_file'},$upper_path->{'normal'}) unless(-T
$physical);
243 # Is the file too large?
245 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'});
249 my $content = file_read
($physical);
250 $$content =~ s/\015\012|\012|\015/\n/g;
252 $tpl->read_file($config->{'templates'}->{'viewfile'});
254 $tpl->fillin('FILE',encode_html
($virtual));
255 $tpl->fillin('FILE_URL',escape
($virtual));
256 $tpl->fillin('DIR',$upper_path->{'html'});
257 $tpl->fillin('DIR_URL',$upper_path->{'url'});
258 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
259 $tpl->fillin('SCRIPT',$script);
261 $tpl->parse_if_block('editable',-w
$physical);
263 $tpl->fillin('CONTENT',encode_html
($$content));
266 my $output = header
(-type
=> 'text/html');
267 $output .= $tpl->get_template;
274 # Lock a file and display a form to edit it
276 # Params: 1. Reference to user input hash
277 # 2. Reference to config hash
279 # Return: Output of the command (Scalar Reference)
281 sub exec_beginedit
($$)
283 my ($data,$config) = @_;
284 my $physical = $data->{'physical'};
285 my $virtual = $data->{'virtual'};
286 my $dir = upper_path
($virtual);
288 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
289 return error
($config->{'errors'}->{'dir_edit'}, $dir) if(-d
$physical);
290 return error
($config->{'errors'}->{'no_edit'}, $dir) unless(-r
$physical && -w
$physical);
292 # Check on binary files
294 return error
($config->{'errors'}->{'binary_file'},$dir) unless(-T
$physical);
296 # Is the file too large?
298 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
300 # Show the editing form
302 my $content = file_read
($physical);
303 my $md5sum = md5_hex
($$content);
304 $$content =~ s/\015\012|\012|\015/\n/g;
306 my $tpl = new Template
;
307 $tpl->read_file($config->{'templates'}->{'editfile'});
309 $tpl->fillin('FILE',encode_html
($virtual));
310 $tpl->fillin('FILE_URL',escape
($virtual));
311 $tpl->fillin('DIR',encode_html
($dir));
312 $tpl->fillin('DIR_URL',escape
($dir));
313 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
314 $tpl->fillin('SCRIPT',$script);
315 $tpl->fillin('MD5SUM',$md5sum);
316 $tpl->fillin('CONTENT',encode_html
($$content));
318 $tpl->parse_if_block('error',0);
320 my $output = header
(-type
=> 'text/html');
321 $output .= $tpl->get_template;
328 # Save a file, unlock it and return to directory view
330 # Params: 1. Reference to user input hash
331 # 2. Reference to config hash
333 # Return: Output of the command (Scalar Reference)
337 my ($data,$config) = @_;
338 my $physical = $data->{'physical'};
339 my $virtual = $data->{'virtual'};
340 my $dir = upper_path
($virtual);
341 my $cgi = $data->{'cgi'};
342 my $content = $cgi->param('filecontent');
343 my $md5sum = $cgi->param('md5sum');
346 if(defined $content && $md5sum)
350 $content =~ s/\015\012|\012|\015/\n/g;
352 if($cgi->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
354 # Create the new filename
356 $physical = $data->{'new_physical'};
357 $virtual = $data->{'new_virtual'};
360 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
361 return error
($config->{'errors'}->{'dir_edit'},$dir) if(-d
$physical);
362 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
363 return error
($config->{'errors'}->{'text_to_binary'},$dir) if(-e
$physical && not -T
$physical);
365 # For technical reasons, we can't use file_save() for
370 sysopen(FILE
,$physical,O_RDWR
| O_CREAT
) or return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)});
371 file_lock
(*FILE
,LOCK_EX
) or do { close(FILE
); return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> encode_html
($virtual)}) };
373 my $md5 = new Digest
::MD5
;
374 $md5->addfile(*FILE
);
376 my $md5file = $md5->hexdigest;
377 my $md5data = md5_hex
($content);
379 if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
381 # The file changed meanwhile
383 my $tpl = new Template
;
384 $tpl->read_file($config->{'templates'}->{'editfile'});
386 $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
388 $tpl->fillin('FILE',encode_html
($virtual));
389 $tpl->fillin('FILE_URL',escape
($virtual));
390 $tpl->fillin('DIR',encode_html
($dir));
391 $tpl->fillin('DIR_URL',escape
($dir));
392 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
393 $tpl->fillin('SCRIPT',$script);
394 $tpl->fillin('MD5SUM',$md5file);
395 $tpl->fillin('CONTENT',encode_html
($content));
397 $tpl->parse_if_block('error',1);
399 my $data = header
(-type
=> 'text/html');
400 $data .= $tpl->get_template;
406 if($md5data ne $md5file)
414 $output = ($cgi->param('continue'))
415 ? devedit_reload
({command
=> 'beginedit', file
=> $virtual})
416 : devedit_reload
({command
=> 'show', file
=> $dir});
424 return devedit_reload
({command
=> 'beginedit', file
=> $virtual});
429 # Create a file and return to directory view
431 # Params: 1. Reference to user input hash
432 # 2. Reference to config hash
434 # Return: Output of the command (Scalar Reference)
438 my ($data,$config) = @_;
439 my $new_physical = $data->{'new_physical'};
440 my $new_virtual = $data->{'new_virtual'};
441 my $dir = upper_path
($new_virtual);
442 $new_virtual = encode_html
($new_virtual);
446 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
448 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
449 return devedit_reload
({command
=> 'show', file
=> $dir});
453 my $tpl = new Template
;
454 $tpl->read_file($config->{'templates'}->{'mkfile'});
456 $tpl->fillin('DIR','/');
457 $tpl->fillin('SCRIPT',$script);
459 my $output = header
(-type
=> 'text/html');
460 $output .= $tpl->get_template;
468 # Create a directory and return to directory view
470 # Params: 1. Reference to user input hash
471 # 2. Reference to config hash
473 # Return: Output of the command (Scalar Reference)
477 my ($data,$config) = @_;
478 my $new_physical = $data->{'new_physical'};
479 my $new_virtual = $data->{'new_virtual'};
480 my $dir = upper_path
($new_virtual);
481 $new_virtual = encode_html
($new_virtual);
485 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
487 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
488 return devedit_reload
({command
=> 'show', file
=> $dir});
492 my $tpl = new Template
;
493 $tpl->read_file($config->{'templates'}->{'mkdir'});
495 $tpl->fillin('DIR','/');
496 $tpl->fillin('SCRIPT',$script);
498 my $output = header
(-type
=> 'text/html');
499 $output .= $tpl->get_template;
507 # Process a file upload
509 # Params: 1. Reference to user input hash
510 # 2. Reference to config hash
512 # Return: Output of the command (Scalar Reference)
516 my ($data,$config) = @_;
517 my $physical = $data->{'physical'};
518 my $virtual = $data->{'virtual'};
519 my $cgi = $data->{'cgi'};
521 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> encode_html
($virtual)}) unless(-d
$physical && not -l
$physical);
522 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> encode_html
($virtual)}) unless(-w
$physical);
524 if(my $uploaded_file = $cgi->param('uploaded_file'))
526 if($cgi->param('remote_file'))
528 $uploaded_file = $cgi->param('remote_file');
530 $uploaded_file =~ s!/!!g;
531 $uploaded_file =~ s!\\!!g;
534 # Process file upload
536 my $filename = file_name
($uploaded_file);
537 my $file_phys = $physical.'/'.$filename;
538 my $file_virt = encode_html
($virtual.$filename);
542 return error
($config->{'errors'}->{'link_replace'},$virtual) if(-l
$file_phys);
543 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
544 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
545 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
548 my $ascii = $cgi->param('ascii');
549 my $handle = $cgi->upload('uploaded_file');
551 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
553 # Read transferred file and write it to disk
555 read($handle, my $data, -s
$handle);
556 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
557 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
559 return devedit_reload
({command
=> 'show', file
=> $virtual});
563 my $tpl = new Template
;
564 $tpl->read_file($config->{'templates'}->{'upload'});
566 $tpl->fillin('DIR',encode_html
($virtual));
567 $tpl->fillin('DIR_URL',escape
($virtual));
568 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
569 $tpl->fillin('SCRIPT',$script);
571 my $output = header
(-type
=> 'text/html');
572 $output .= $tpl->get_template;
580 # Copy a file and return to directory view
582 # Params: 1. Reference to user input hash
583 # 2. Reference to config hash
585 # Return: Output of the command (Scalar Reference)
589 my ($data,$config) = @_;
590 my $physical = $data->{'physical'};
591 my $virtual = $data->{'virtual'};
592 my $dir = upper_path
($virtual);
593 my $new_physical = $data->{'new_physical'};
595 return error
($config->{'errors'}->{'link_copy'},$dir) if(-l
$physical);
596 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
600 my $new_virtual = multi_string
($data->{'new_virtual'});
601 my $new_dir = upper_path
($new_virtual->{'normal'});
605 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-x
$physical);
606 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual->{'html'}}) if(-e
$new_physical);
607 return error
($config->{'errors'}->{'dir_copy_self'},$dir) if(index($new_virtual->{'normal'},$virtual) == 0);
609 dir_copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
610 return devedit_reload
({command
=> 'show', file
=> $new_dir});
616 return error
($config->{'errors'}->{'link_replace'},$new_dir) if(-l
$new_physical);
617 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
618 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual->{'html'}}) unless(-w
$new_physical);
620 if(not $data->{'cgi'}->param('confirmed'))
622 my $tpl = new Template
;
623 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
625 $tpl->fillin('FILE',encode_html
($virtual));
626 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
627 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
628 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
629 $tpl->fillin('DIR',encode_html
($dir));
630 $tpl->fillin('DIR_URL',escape
($dir));
632 $tpl->fillin('COMMAND','copy');
633 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
634 $tpl->fillin('SCRIPT',$script);
636 my $output = header
(-type
=> 'text/html');
637 $output .= $tpl->get_template;
643 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
644 return devedit_reload
({command
=> 'show', file
=> $new_dir});
651 my $tpl = new Template
;
652 $tpl->read_file($config->{'templates'}->{'copydir'});
654 $tpl->fillin('FILE',encode_html
($virtual));
655 $tpl->fillin('DIR',encode_html
($dir));
656 $tpl->fillin('DIR_URL',escape
($dir));
657 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
658 $tpl->fillin('SCRIPT',$script);
660 my $output = header
(-type
=> 'text/html');
661 $output .= $tpl->get_template;
667 my $tpl = new Template
;
668 $tpl->read_file($config->{'templates'}->{'copyfile'});
670 $tpl->fillin('FILE',encode_html
($virtual));
671 $tpl->fillin('DIR',encode_html
($dir));
672 $tpl->fillin('DIR_URL',escape
($dir));
673 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
674 $tpl->fillin('SCRIPT',$script);
676 my $output = header
(-type
=> 'text/html');
677 $output .= $tpl->get_template;
686 # Rename/move a file and return to directory view
688 # Params: 1. Reference to user input hash
689 # 2. Reference to config hash
691 # Return: Output of the command (Scalar Reference)
695 my ($data,$config) = @_;
696 my $physical = $data->{'physical'};
697 my $virtual = $data->{'virtual'};
698 my $dir = upper_path
($virtual);
699 my $new_physical = $data->{'new_physical'};
701 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
702 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
706 my $new_virtual = multi_string
($data->{'new_virtual'});
707 my $new_dir = upper_path
($new_virtual->{'normal'});
711 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical && not -l
$new_physical);
712 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
714 if(not $data->{'cgi'}->param('confirmed'))
716 my $tpl = new Template
;
717 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
719 $tpl->fillin('FILE',encode_html
($virtual));
720 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
721 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
722 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
723 $tpl->fillin('DIR',encode_html
($dir));
725 $tpl->fillin('COMMAND','rename');
726 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
727 $tpl->fillin('SCRIPT',$script);
729 my $output = header
(-type
=> 'text/html');
730 $output .= $tpl->get_template;
736 move
($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> encode_html
($virtual), NEW_FILE
=> $new_virtual->{'html'}});
737 return devedit_reload
({command
=> 'show', file
=> $new_dir});
741 my $tpl = new Template
;
742 $tpl->read_file($config->{'templates'}->{'renamefile'});
744 $tpl->fillin('FILE',encode_html
($virtual));
745 $tpl->fillin('DIR',encode_html
($dir));
746 $tpl->fillin('DIR_URL',escape
($dir));
747 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
748 $tpl->fillin('SCRIPT',$script);
750 my $output = header
(-type
=> 'text/html');
751 $output .= $tpl->get_template;
759 # Remove a file or a directory and return to directory view
761 # Params: 1. Reference to user input hash
762 # 2. Reference to config hash
764 # Return: Output of the command (Scalar Reference)
768 my ($data,$config) = @_;
769 my $physical = $data->{'physical'};
770 my $virtual = $data->{'virtual'};
771 my $dir = upper_path
($virtual);
773 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
774 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
776 if(-d
$physical && not -l
$physical)
780 if($data->{'cgi'}->param('confirmed'))
783 return devedit_reload
({command
=> 'show', file
=> $dir});
787 my $tpl = new Template
;
788 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
790 $tpl->fillin('DIR',encode_html
($virtual));
791 $tpl->fillin('DIR_URL',escape
($virtual));
792 $tpl->fillin('UPPER_DIR',encode_html
($dir));
793 $tpl->fillin('UPPER_DIR_URL',escape
($dir));
794 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
795 $tpl->fillin('SCRIPT',$script);
797 my $output = header
(-type
=> 'text/html');
798 $output .= $tpl->get_template;
807 if($data->{'cgi'}->param('confirmed'))
809 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
810 return devedit_reload
({command
=> 'show', file
=> $dir});
814 my $tpl = new Template
;
815 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
817 $tpl->fillin('FILE',encode_html
($virtual));
818 $tpl->fillin('FILE_URL',escape
($virtual));
819 $tpl->fillin('DIR',encode_html
($dir));
820 $tpl->fillin('DIR_URL',escape
($dir));
821 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
822 $tpl->fillin('SCRIPT',$script);
824 my $output = header
(-type
=> 'text/html');
825 $output .= $tpl->get_template;
834 # Change the mode and the group of a file or a directory
836 # Params: 1. Reference to user input hash
837 # 2. Reference to config hash
839 # Return: Output of the command (Scalar Reference)
843 my ($data,$config) = @_;
844 my $physical = $data->{'physical'};
845 my $virtual = $data->{'virtual'};
846 my $dir = upper_path
($virtual);
848 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> encode_html
($virtual)}) unless($users);
849 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
850 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> encode_html
($virtual)}) unless(-o
$physical);
851 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
853 my $cgi = $data->{'cgi'};
854 my $mode = $cgi->param('mode');
855 my $group = $cgi->param('group');
863 return error
($config->{'errors'}->{'invalid_mode'},$dir) unless($mode =~ /^[0-7]{3,}$/);
864 chmod(oct($mode),$physical);
869 # Change the group using the `chgrp` system command
871 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_html
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
872 system('chgrp',$group,$physical);
875 return devedit_reload
({command
=> 'show', file
=> $dir});
881 my @stat = stat($physical);
885 my $tpl = new Template
;
886 $tpl->read_file($config->{'templates'}->{'chprop'});
888 # Insert file properties into the template
890 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
891 $tpl->fillin('MODE_STRING',mode_string
($mode));
892 $tpl->fillin('GID',$gid);
894 if(my $group = getgrgid($gid))
896 $tpl->fillin('GROUP',encode_html
($group));
897 $tpl->parse_if_block('group_detected',1);
901 $tpl->parse_if_block('group_detected',0);
904 # Insert other information
906 $tpl->fillin('FILE',encode_html
($virtual));
907 $tpl->fillin('FILE_URL',escape
($virtual));
908 $tpl->fillin('DIR',encode_html
($dir));
909 $tpl->fillin('DIR_URL',escape
($dir));
910 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
911 $tpl->fillin('SCRIPT',$script);
913 my $output = header
(-type
=> 'text/html');
914 $output .= $tpl->get_template;
922 # Display some information about Dev-Editor
924 # Params: 1. Reference to user input hash
925 # 2. Reference to config hash
927 # Return: Output of the command (Scalar Reference)
931 my ($data,$config) = @_;
933 my $tpl = new Template
;
934 $tpl->read_file($config->{'templates'}->{'about'});
936 $tpl->fillin('SCRIPT',$script);
938 # Dev-Editor's version number
940 $tpl->fillin('VERSION',$data->{'version'});
942 # Some path information
944 $tpl->fillin('SCRIPT_PHYS',encode_html
($ENV{'SCRIPT_FILENAME'}));
945 $tpl->fillin('CONFIG_PATH',encode_html
($data->{'configfile'}));
946 $tpl->fillin('FILE_ROOT', encode_html
($config->{'fileroot'}));
947 $tpl->fillin('HTTP_ROOT', encode_html
($config->{'httproot'}));
951 $tpl->fillin('PERL_PROG',encode_html
($^X
));
952 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
954 # Information about the server
956 $tpl->fillin('HTTPD',encode_html
($ENV{'SERVER_SOFTWARE'}));
957 $tpl->fillin('OS', encode_html
($^O
));
958 $tpl->fillin('TIME', encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
960 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
962 # Process information
964 $tpl->fillin('PID',$$);
966 # The following information is only available on systems supporting
971 # Dev-Editor is running on a system which allows users and groups
972 # So we display the user and the group of our process
974 my $uid = POSIX
::getuid
;
975 my $gid = POSIX
::getgid
;
977 $tpl->parse_if_block('users',1);
979 # IDs of user and group
981 $tpl->fillin('UID',$uid);
982 $tpl->fillin('GID',$gid);
984 # Names of user and group
986 if(my $user = getpwuid($uid))
988 $tpl->fillin('USER',encode_html
($user));
989 $tpl->parse_if_block('user_detected',1);
993 $tpl->parse_if_block('user_detected',0);
996 if(my $group = getgrgid($gid))
998 $tpl->fillin('GROUP',encode_html
($group));
999 $tpl->parse_if_block('group_detected',1);
1003 $tpl->parse_if_block('group_detected',0);
1008 $tpl->fillin('UMASK',sprintf('%04o',umask));
1012 $tpl->parse_if_block('users',0);
1015 my $output = header
(-type
=> 'text/html');
1016 $output .= $tpl->get_template;
1021 # it's true, baby ;-)
patrick-canterino.de