]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
5132a170e9448fd024482d3fd77a59fa0b8f61d6
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2005-04-15
21 use Digest::MD5 qw(md5_hex);
22 use POSIX
qw(strftime);
32 my $script = encode_entities
($ENV{'SCRIPT_NAME'});
33 my $users = eval('getpwuid(0)') && eval('getgrgid(0)');
35 my %dispatch = ('show' => \
&exec_show
,
36 'beginedit' => \
&exec_beginedit
,
37 'endedit' => \
&exec_endedit
,
38 'mkdir' => \
&exec_mkdir
,
39 'mkfile' => \
&exec_mkfile
,
40 'upload' => \
&exec_upload
,
41 'copy' => \
&exec_copy
,
42 'rename' => \
&exec_rename
,
43 'remove' => \
&exec_remove
,
44 'chprop' => \
&exec_chprop
,
45 'about' => \
&exec_about
50 use base
qw(Exporter);
52 @EXPORT = qw(exec_command);
56 # Execute the specified command
58 # Params: 1. Command to execute
59 # 2. Reference to user input hash
60 # 3. Reference to config hash
62 # Return: Output of the command (Scalar Reference)
66 my ($command,$data,$config) = @_;
68 foreach(keys(%dispatch))
70 if(lc($_) eq lc($command))
72 my $output = &{$dispatch{$_}}($data,$config);
77 return error
($config->{'errors'}->{'command_unknown'},'/',{COMMAND
=> encode_entities
($command)});
82 # View a directory or a file
84 # Params: 1. Reference to user input hash
85 # 2. Reference to config hash
87 # Return: Output of the command (Scalar Reference)
91 my ($data,$config) = @_;
92 my $physical = $data->{'physical'};
93 my $virtual = $data->{'virtual'};
94 my $upper_path = encode_entities
(upper_path
($virtual));
96 my $tpl = new Template
;
98 if(-d
$physical && not -l
$physical)
100 # Create directory listing
102 return error
($config->{'errors'}->{'no_dir_access'},$upper_path) unless(-r
$physical && -x
$physical);
104 my $direntries = dir_read
($physical);
105 return error
($config->{'errors'}->{'dir_read_fail'},$upper_path,{DIR
=> encode_entities
($virtual)}) unless($direntries);
107 my $files = $direntries->{'files'};
108 my $dirs = $direntries->{'dirs'};
110 my $dir_writeable = -w
$physical;
114 my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
115 my $filter2 = ($filter1 && $filter1 ne '*') ?
$filter1 : ''; # Wildcard for output
117 # Create the link to the upper directory
118 # (only if the current directory is not the root directory)
120 unless($virtual eq '/')
122 my @stat = stat($physical.'/..');
124 my $udtpl = new Template
;
125 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
127 $udtpl->fillin('UPPER_DIR',$upper_path);
128 $udtpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
130 $dirlist .= $udtpl->get_template;
135 foreach my $dir(@
$dirs)
137 next unless(dos_wildcard_match
($filter1,$dir));
139 my $phys_path = $physical.'/'.$dir;
140 my $virt_path = encode_entities
($virtual.$dir.'/');
142 my @stat = stat($phys_path);
144 my $dtpl = new Template
;
145 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
147 $dtpl->fillin('DIR',$virt_path);
148 $dtpl->fillin('DIR_NAME',encode_entities
($dir));
149 $dtpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
150 $dtpl->fillin('URL',equal_url
(encode_entities
($config->{'httproot'}),$virt_path));
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 = encode_entities
($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);
174 $ftpl->fillin('FILE_NAME',encode_entities
($file));
175 $ftpl->fillin('SIZE',$stat[7]);
176 $ftpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
177 $ftpl->fillin('URL',equal_url
(encode_entities
($config->{'httproot'}),$virt_path));
179 $ftpl->parse_if_block('link',-l
$phys_path);
180 $ftpl->parse_if_block('no_link',not -l
$phys_path);
181 $ftpl->parse_if_block('not_readable',not -r
$phys_path);
182 $ftpl->parse_if_block('binary',-B
$phys_path);
183 $ftpl->parse_if_block('readonly',not -w
$phys_path);
185 $ftpl->parse_if_block('viewable',(-r
$phys_path && -T
$phys_path && not $too_large) || -l
$phys_path);
186 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not -l
$phys_path);
188 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
190 $ftpl->parse_if_block('users',$users && -o
$phys_path);
192 $dirlist .= $ftpl->get_template;
195 $tpl->read_file($config->{'templates'}->{'dirlist'});
197 $tpl->fillin('DIRLIST',$dirlist);
198 $tpl->fillin('DIR',encode_entities
($virtual));
199 $tpl->fillin('SCRIPT',$script);
200 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
202 $tpl->fillin('FILTER',encode_entities
($filter2));
203 $tpl->fillin('FILTER_URL',escape
($filter2));
205 $tpl->parse_if_block('empty',$dirlist eq '');
206 $tpl->parse_if_block('dir_writeable',$dir_writeable);
207 $tpl->parse_if_block('filter',$filter2);
208 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
212 # Show the target of a symbolic link
214 my $link_target = readlink($physical);
216 $tpl->read_file($config->{'templates'}->{'viewlink'});
218 $tpl->fillin('FILE',encode_entities
($virtual));
219 $tpl->fillin('DIR',$upper_path);
220 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
221 $tpl->fillin('SCRIPT',$script);
223 $tpl->fillin('LINK_TARGET',encode_entities
($link_target));
229 return error
($config->{'errors'}->{'no_view'},$upper_path) unless(-r
$physical);
231 # Check on binary files
232 # We have to do it in this way or empty files will be recognized
235 return error
($config->{'errors'}->{'binary_file'},$upper_path) unless(-T
$physical);
237 # Is the file too large?
239 return error
($config->{'errors'}->{'file_too_large'},$upper_path,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
243 my $content = file_read
($physical);
244 $$content =~ s/\015\012|\012|\015/\n/g;
246 $tpl->read_file($config->{'templates'}->{'viewfile'});
248 $tpl->fillin('FILE',encode_entities
($virtual));
249 $tpl->fillin('DIR',$upper_path);
250 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
251 $tpl->fillin('SCRIPT',$script);
253 $tpl->parse_if_block('editable',-w
$physical);
255 $tpl->fillin('CONTENT',encode_entities
($$content));
258 my $output = header
(-type
=> 'text/html');
259 $output .= $tpl->get_template;
266 # Lock a file and display a form to edit it
268 # Params: 1. Reference to user input hash
269 # 2. Reference to config hash
271 # Return: Output of the command (Scalar Reference)
273 sub exec_beginedit
($$)
275 my ($data,$config) = @_;
276 my $physical = $data->{'physical'};
277 my $virtual = $data->{'virtual'};
278 my $dir = upper_path
($virtual);
279 my $cgi = $data->{'cgi'};
281 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
282 return error
($config->{'errors'}->{'dir_edit'}, $dir) if(-d
$physical);
283 return error
($config->{'errors'}->{'no_edit'}, $dir) unless(-r
$physical && -w
$physical);
285 # Check on binary files
287 return error
($config->{'errors'}->{'binary_file'},$dir) unless(-T
$physical);
289 # Is the file too large?
291 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
293 # ... and show the editing form
295 my $content = file_read
($physical);
296 my $md5sum = md5_hex
($$content);
297 $$content =~ s/\015\012|\012|\015/\n/g;
299 my $tpl = new Template
;
300 $tpl->read_file($config->{'templates'}->{'editfile'});
302 $tpl->fillin('FILE',$virtual);
303 $tpl->fillin('DIR',$dir);
304 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
305 $tpl->fillin('SCRIPT',$script);
306 $tpl->fillin('MD5SUM',$md5sum);
307 $tpl->fillin('CONTENT',encode_entities
($$content));
309 $tpl->parse_if_block('error',0);
311 my $output = header
(-type
=> 'text/html');
312 $output .= $tpl->get_template;
319 # Save a file, unlock it and return to directory view
321 # Params: 1. Reference to user input hash
322 # 2. Reference to config hash
324 # Return: Output of the command (Scalar Reference)
328 my ($data,$config) = @_;
329 my $physical = $data->{'physical'};
330 my $virtual = $data->{'virtual'};
331 my $dir = upper_path
($virtual);
332 my $cgi = $data->{'cgi'};
333 my $content = $cgi->param('filecontent');
334 my $md5sum = $cgi->param('md5sum');
337 if(defined $content && $md5sum)
341 $content =~ s/\015\012|\012|\015/\n/g;
343 if($cgi->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
345 # Create the new filename
347 $physical = $data->{'new_physical'};
348 $virtual = $data->{'new_virtual'};
351 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
352 return error
($config->{'errors'}->{'dir_edit'},$dir) if(-d
$physical);
353 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
354 return error
($config->{'errors'}->{'text_to_binary'},$dir) if(-e
$physical && not -T
$physical);
356 # For technical reasons, we can't use file_save() for
361 sysopen(FILE
,$physical,O_RDWR
| O_CREAT
) or return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual});
362 file_lock
(*FILE
,LOCK_EX
) or do { close(FILE
); return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual}) };
364 my $md5 = new Digest
::MD5
;
365 $md5->addfile(*FILE
);
367 my $md5file = $md5->hexdigest;
368 my $md5data = md5_hex
($content);
370 if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
372 # The file changed meanwhile
374 my $tpl = new Template
;
375 $tpl->read_file($config->{'templates'}->{'editfile'});
377 $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
379 $tpl->fillin('FILE',$virtual);
380 $tpl->fillin('DIR',$dir);
381 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
382 $tpl->fillin('SCRIPT',$script);
383 $tpl->fillin('MD5SUM',$md5file);
384 $tpl->fillin('CONTENT',encode_entities
($content));
386 $tpl->parse_if_block('error',1);
388 my $data = header
(-type
=> 'text/html');
389 $data .= $tpl->get_template;
395 if($md5data ne $md5file)
403 $output = devedit_reload
({command
=> 'show', file
=> $dir});
411 return devedit_reload
({command
=> 'beginedit', file
=> $virtual});
416 # Create a file and return to directory view
418 # Params: 1. Reference to user input hash
419 # 2. Reference to config hash
421 # Return: Output of the command (Scalar Reference)
425 my ($data,$config) = @_;
426 my $new_physical = $data->{'new_physical'};
427 my $new_virtual = $data->{'new_virtual'};
428 my $dir = upper_path
($new_virtual);
429 $new_virtual = encode_entities
($new_virtual);
433 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
435 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
436 return devedit_reload
({command
=> 'show', file
=> $dir});
440 my $tpl = new Template
;
441 $tpl->read_file($config->{'templates'}->{'mkfile'});
443 $tpl->fillin('DIR','/');
444 $tpl->fillin('SCRIPT',$script);
446 my $output = header
(-type
=> 'text/html');
447 $output .= $tpl->get_template;
455 # Create a directory and return to directory view
457 # Params: 1. Reference to user input hash
458 # 2. Reference to config hash
460 # Return: Output of the command (Scalar Reference)
464 my ($data,$config) = @_;
465 my $new_physical = $data->{'new_physical'};
466 my $new_virtual = $data->{'new_virtual'};
467 my $dir = upper_path
($new_virtual);
468 $new_virtual = encode_entities
($new_virtual);
472 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
474 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
475 return devedit_reload
({command
=> 'show', file
=> $dir});
479 my $tpl = new Template
;
480 $tpl->read_file($config->{'templates'}->{'mkdir'});
482 $tpl->fillin('DIR','/');
483 $tpl->fillin('SCRIPT',$script);
485 my $output = header
(-type
=> 'text/html');
486 $output .= $tpl->get_template;
494 # Process a file upload
496 # Params: 1. Reference to user input hash
497 # 2. Reference to config hash
499 # Return: Output of the command (Scalar Reference)
503 my ($data,$config) = @_;
504 my $physical = $data->{'physical'};
505 my $virtual = $data->{'virtual'};
506 my $cgi = $data->{'cgi'};
508 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> $virtual}) unless(-d
$physical && not -l
$physical);
509 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> $virtual}) unless(-w
$physical);
511 if(my $uploaded_file = $cgi->param('uploaded_file'))
513 # Process file upload
515 my $filename = file_name
($uploaded_file);
516 my $file_phys = $physical.'/'.$filename;
517 my $file_virt = $virtual.$filename;
521 return error
($config->{'errors'}->{'link_replace'},$virtual) if(-l
$file_phys);
522 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
523 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
524 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
527 my $ascii = $cgi->param('ascii');
528 my $handle = $cgi->upload('uploaded_file');
530 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
532 # Read transferred file and write it to disk
534 read($handle, my $data, -s
$handle);
535 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
536 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
538 return devedit_reload
({command
=> 'show', file
=> $virtual});
542 my $tpl = new Template
;
543 $tpl->read_file($config->{'templates'}->{'upload'});
545 $tpl->fillin('DIR',$virtual);
546 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
547 $tpl->fillin('SCRIPT',$script);
549 my $output = header
(-type
=> 'text/html');
550 $output .= $tpl->get_template;
558 # Copy a file and return to directory view
560 # Params: 1. Reference to user input hash
561 # 2. Reference to config hash
563 # Return: Output of the command (Scalar Reference)
567 my ($data,$config) = @_;
568 my $physical = $data->{'physical'};
569 my $virtual = encode_entities
($data->{'virtual'});
570 my $dir = upper_path
($virtual);
571 my $new_physical = $data->{'new_physical'};
573 return error
($config->{'errors'}->{'link_copy'},$dir) if(-l
$physical);
574 return error
($config->{'errors'}->{'dir_copy'},$dir) if(-d
$physical);
575 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
579 my $new_virtual = $data->{'new_virtual'};
580 my $new_dir = upper_path
($new_virtual);
581 $new_virtual = encode_entities
($new_virtual);
585 return error
($config->{'errors'}->{'link_replace'},$new_dir) if(-l
$new_physical);
586 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
587 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
589 if(not $data->{'cgi'}->param('confirmed'))
591 my $tpl = new Template
;
592 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
594 $tpl->fillin('FILE',$virtual);
595 $tpl->fillin('NEW_FILE',$new_virtual);
596 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
597 $tpl->fillin('NEW_DIR',$new_dir);
598 $tpl->fillin('DIR',$dir);
600 $tpl->fillin('COMMAND','copy');
601 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
602 $tpl->fillin('SCRIPT',$script);
604 my $output = header
(-type
=> 'text/html');
605 $output .= $tpl->get_template;
611 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
612 return devedit_reload
({command
=> 'show', file
=> $new_dir});
616 my $tpl = new Template
;
617 $tpl->read_file($config->{'templates'}->{'copyfile'});
619 $tpl->fillin('FILE',$virtual);
620 $tpl->fillin('DIR',$dir);
621 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
622 $tpl->fillin('SCRIPT',$script);
624 my $output = header
(-type
=> 'text/html');
625 $output .= $tpl->get_template;
633 # Rename/move a file and return to directory view
635 # Params: 1. Reference to user input hash
636 # 2. Reference to config hash
638 # Return: Output of the command (Scalar Reference)
642 my ($data,$config) = @_;
643 my $physical = $data->{'physical'};
644 my $virtual = $data->{'virtual'};
645 my $dir = upper_path
($virtual);
646 my $new_physical = $data->{'new_physical'};
648 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
649 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
653 my $new_virtual = $data->{'new_virtual'};
654 my $new_dir = upper_path
($new_virtual);
655 $new_virtual = encode_entities
($new_virtual);
659 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical && not -l
$new_physical);
660 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
662 if(not $data->{'cgi'}->param('confirmed'))
664 my $tpl = new Template
;
665 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
667 $tpl->fillin('FILE',$virtual);
668 $tpl->fillin('NEW_FILE',$new_virtual);
669 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
670 $tpl->fillin('NEW_DIR',$new_dir);
671 $tpl->fillin('DIR',$dir);
673 $tpl->fillin('COMMAND','rename');
674 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
675 $tpl->fillin('SCRIPT',$script);
677 my $output = header
(-type
=> 'text/html');
678 $output .= $tpl->get_template;
684 move
($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
685 return devedit_reload
({command
=> 'show', file
=> $new_dir});
689 my $tpl = new Template
;
690 $tpl->read_file($config->{'templates'}->{'renamefile'});
692 $tpl->fillin('FILE',$virtual);
693 $tpl->fillin('DIR',$dir);
694 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
695 $tpl->fillin('SCRIPT',$script);
697 my $output = header
(-type
=> 'text/html');
698 $output .= $tpl->get_template;
706 # Remove a file or a directory and return to directory view
708 # Params: 1. Reference to user input hash
709 # 2. Reference to config hash
711 # Return: Output of the command (Scalar Reference)
715 my ($data,$config) = @_;
716 my $physical = $data->{'physical'};
717 my $virtual = $data->{'virtual'};
718 my $dir = upper_path
($virtual);
720 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
721 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
723 if(-d
$physical && not -l
$physical)
727 if($data->{'cgi'}->param('confirmed'))
730 return devedit_reload
({command
=> 'show', file
=> $dir});
734 my $tpl = new Template
;
735 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
737 $tpl->fillin('DIR',$virtual);
738 $tpl->fillin('UPPER_DIR',$dir);
739 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
740 $tpl->fillin('SCRIPT',$script);
742 my $output = header
(-type
=> 'text/html');
743 $output .= $tpl->get_template;
752 if($data->{'cgi'}->param('confirmed'))
754 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
755 return devedit_reload
({command
=> 'show', file
=> $dir});
759 my $tpl = new Template
;
760 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
762 $tpl->fillin('FILE',$virtual);
763 $tpl->fillin('DIR',$dir);
764 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
765 $tpl->fillin('SCRIPT',$script);
767 my $output = header
(-type
=> 'text/html');
768 $output .= $tpl->get_template;
777 # Change the mode and the group of a file or a directory
779 # Params: 1. Reference to user input hash
780 # 2. Reference to config hash
782 # Return: Output of the command (Scalar Reference)
786 my ($data,$config) = @_;
787 my $physical = $data->{'physical'};
788 my $virtual = $data->{'virtual'};
789 my $dir = upper_path
($virtual);
791 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> $virtual}) unless($users);
792 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
793 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> $virtual}) unless(-o
$physical);
794 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
796 my $cgi = $data->{'cgi'};
797 my $mode = $cgi->param('mode');
798 my $group = $cgi->param('group');
806 chmod(oct($mode),$physical);
811 # Change the group using the `chgrp` system command
813 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_entities
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
814 system('chgrp',$group,$physical);
817 return devedit_reload
({command
=> 'show', file
=> $dir});
823 my @stat = stat($physical);
827 my $tpl = new Template
;
828 $tpl->read_file($config->{'templates'}->{'chprop'});
830 # Insert file properties into the template
832 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
833 $tpl->fillin('MODE_STRING',mode_string
($mode));
834 $tpl->fillin('GID',$gid);
836 if(my $group = getgrgid($gid))
838 $tpl->fillin('GROUP',encode_entities
($group));
839 $tpl->parse_if_block('group_detected',1);
843 $tpl->parse_if_block('group_detected',0);
846 # Insert other information
848 $tpl->fillin('FILE',$virtual);
849 $tpl->fillin('DIR',$dir);
850 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
851 $tpl->fillin('SCRIPT',$script);
853 my $output = header
(-type
=> 'text/html');
854 $output .= $tpl->get_template;
862 # Display some information about Dev-Editor
864 # Params: 1. Reference to user input hash
865 # 2. Reference to config hash
867 # Return: Output of the command (Scalar Reference)
871 my ($data,$config) = @_;
873 my $tpl = new Template
;
874 $tpl->read_file($config->{'templates'}->{'about'});
876 $tpl->fillin('SCRIPT',$script);
878 # Dev-Editor's version number
880 $tpl->fillin('VERSION',$data->{'version'});
882 # Some path information
884 $tpl->fillin('SCRIPT_PHYS',encode_entities
($ENV{'SCRIPT_FILENAME'}));
885 $tpl->fillin('CONFIG_PATH',encode_entities
($data->{'configfile'}));
886 $tpl->fillin('FILE_ROOT', encode_entities
($config->{'fileroot'}));
887 $tpl->fillin('HTTP_ROOT', encode_entities
($config->{'httproot'}));
891 $tpl->fillin('PERL_PROG',encode_entities
($^X
));
892 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
894 # Information about the server
896 $tpl->fillin('HTTPD',encode_entities
($ENV{'SERVER_SOFTWARE'}));
897 $tpl->fillin('OS', encode_entities
($^O
));
898 $tpl->fillin('TIME', encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
900 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
902 # Process information
904 $tpl->fillin('PID',$$);
906 # The following information is only available on systems supporting
911 # Dev-Editor is running on a system which allows users and groups
912 # So we display the user and the group of our process
914 my $uid = POSIX
::getuid
;
915 my $gid = POSIX
::getgid
;
917 $tpl->parse_if_block('users',1);
919 # ID's of user and group
921 $tpl->fillin('UID',$uid);
922 $tpl->fillin('GID',$gid);
924 # Names of user and group
926 if(my $user = getpwuid($uid))
928 $tpl->fillin('USER',encode_entities
($user));
929 $tpl->parse_if_block('user_detected',1);
933 $tpl->parse_if_block('user_detected',0);
936 if(my $group = getgrgid($gid))
938 $tpl->fillin('GROUP',encode_entities
($group));
939 $tpl->parse_if_block('group_detected',1);
943 $tpl->parse_if_block('group_detected',0);
948 $tpl->fillin('UMASK',sprintf('%04o',umask));
952 $tpl->parse_if_block('users',0);
955 my $output = header
(-type
=> 'text/html');
956 $output .= $tpl->get_template;
961 # it's true, baby ;-)
patrick-canterino.de