]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 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'};
112 my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
113 my $filter2 = ($filter1 && $filter1 ne '*') ?
$filter1 : ''; # Wildcard for output
115 # Create the link to the upper directory
116 # (only if the current directory is not the root directory)
118 unless($virtual eq '/')
120 my @stat = stat($physical.'/..');
122 my $udtpl = new Template
;
123 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
125 $udtpl->fillin('UPPER_DIR',$upper_path);
126 $udtpl->fillin('DATE',encode_entities
(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 = encode_entities
($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);
146 $dtpl->fillin('DIR_NAME',encode_entities
($dir));
147 $dtpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
148 $dtpl->fillin('URL',equal_url
(encode_entities
($config->{'httproot'}),$virt_path));
150 $dtpl->parse_if_block('readable',-r
$phys_path && -x
$phys_path);
151 $dtpl->parse_if_block('users',$users && -o
$phys_path);
153 $dirlist .= $dtpl->get_template;
158 foreach my $file(@
$files)
160 next unless(dos_wildcard_match
($filter1,$file));
162 my $phys_path = $physical.'/'.$file;
163 my $virt_path = encode_entities
($virtual.$file);
165 my @stat = lstat($phys_path);
166 my $too_large = $config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'};
168 my $ftpl = new Template
;
169 $ftpl->read_file($config->{'templates'}->{'dirlist_file'});
171 $ftpl->fillin('FILE',$virt_path);
172 $ftpl->fillin('FILE_NAME',encode_entities
($file));
173 $ftpl->fillin('SIZE',$stat[7]);
174 $ftpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
175 $ftpl->fillin('URL',equal_url
(encode_entities
($config->{'httproot'}),$virt_path));
177 $ftpl->parse_if_block('link',-l
$phys_path);
178 $ftpl->parse_if_block('no_link',not -l
$phys_path);
179 $ftpl->parse_if_block('not_readable',not -r
$phys_path);
180 $ftpl->parse_if_block('binary',-B
$phys_path);
181 $ftpl->parse_if_block('readonly',not -w
$phys_path);
183 $ftpl->parse_if_block('viewable',(-r
$phys_path && -T
$phys_path && not $too_large) || -l
$phys_path);
184 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not -l
$phys_path);
186 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
188 $ftpl->parse_if_block('users',$users && -o
$phys_path);
190 $dirlist .= $ftpl->get_template;
193 $tpl->read_file($config->{'templates'}->{'dirlist'});
195 $tpl->fillin('DIRLIST',$dirlist);
196 $tpl->fillin('DIR',encode_entities
($virtual));
197 $tpl->fillin('SCRIPT',$script);
198 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
200 $tpl->fillin('FILTER',encode_entities
($filter2));
201 $tpl->fillin('FILTER_URL',escape
($filter2));
203 $tpl->parse_if_block('empty',$dirlist eq '');
204 $tpl->parse_if_block('dir_writeable',-w
$physical);
205 $tpl->parse_if_block('filter',$filter2);
206 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
210 # Show the target of a symbolic link
212 my $link_target = readlink($physical);
214 $tpl->read_file($config->{'templates'}->{'viewlink'});
216 $tpl->fillin('FILE',encode_entities
($virtual));
217 $tpl->fillin('DIR',$upper_path);
218 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
219 $tpl->fillin('SCRIPT',$script);
221 $tpl->fillin('LINK_TARGET',encode_entities
($link_target));
227 return error
($config->{'errors'}->{'no_view'},$upper_path) unless(-r
$physical);
229 # Check on binary files
230 # We have to do it in this way or empty files will be recognized
233 return error
($config->{'errors'}->{'binary_file'},$upper_path) unless(-T
$physical);
235 # Is the file too large?
237 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'});
241 my $content = file_read
($physical);
242 $$content =~ s/\015\012|\012|\015/\n/g;
244 $tpl->read_file($config->{'templates'}->{'viewfile'});
246 $tpl->fillin('FILE',encode_entities
($virtual));
247 $tpl->fillin('DIR',$upper_path);
248 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
249 $tpl->fillin('SCRIPT',$script);
251 $tpl->parse_if_block('editable',-w
$physical);
253 $tpl->fillin('CONTENT',encode_entities
($$content));
256 my $output = header
(-type
=> 'text/html');
257 $output .= $tpl->get_template;
264 # Lock a file and display a form to edit it
266 # Params: 1. Reference to user input hash
267 # 2. Reference to config hash
269 # Return: Output of the command (Scalar Reference)
271 sub exec_beginedit
($$)
273 my ($data,$config) = @_;
274 my $physical = $data->{'physical'};
275 my $virtual = $data->{'virtual'};
276 my $dir = upper_path
($virtual);
277 my $cgi = $data->{'cgi'};
279 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
280 return error
($config->{'errors'}->{'dir_edit'}, $dir) if(-d
$physical);
281 return error
($config->{'errors'}->{'no_edit'}, $dir) unless(-r
$physical && -w
$physical);
283 # Check on binary files
285 return error
($config->{'errors'}->{'binary_file'},$dir) unless(-T
$physical);
287 # Is the file too large?
289 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
291 # ... and show the editing form
293 my $content = file_read
($physical);
294 my $md5sum = md5_hex
($$content);
295 $$content =~ s/\015\012|\012|\015/\n/g;
297 my $tpl = new Template
;
298 $tpl->read_file($config->{'templates'}->{'editfile'});
300 $tpl->fillin('FILE',$virtual);
301 $tpl->fillin('DIR',$dir);
302 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
303 $tpl->fillin('SCRIPT',$script);
304 $tpl->fillin('MD5SUM',$md5sum);
305 $tpl->fillin('CONTENT',encode_entities
($$content));
307 $tpl->parse_if_block('error',0);
309 my $output = header
(-type
=> 'text/html');
310 $output .= $tpl->get_template;
317 # Save a file, unlock it and return to directory view
319 # Params: 1. Reference to user input hash
320 # 2. Reference to config hash
322 # Return: Output of the command (Scalar Reference)
326 my ($data,$config) = @_;
327 my $physical = $data->{'physical'};
328 my $virtual = $data->{'virtual'};
329 my $dir = upper_path
($virtual);
330 my $cgi = $data->{'cgi'};
331 my $content = $cgi->param('filecontent');
332 my $md5sum = $cgi->param('md5sum');
335 if(defined $content && $md5sum)
339 $content =~ s/\015\012|\012|\015/\n/g;
341 if($cgi->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
343 # Create the new filename
345 $physical = $data->{'new_physical'};
346 $virtual = $data->{'new_virtual'};
349 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
350 return error
($config->{'errors'}->{'dir_edit'},$dir) if(-d
$physical);
351 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
352 return error
($config->{'errors'}->{'text_to_binary'},$dir) if(-e
$physical && not -T
$physical);
354 # For technical reasons, we can't use file_save() for
359 sysopen(FILE
,$physical,O_RDWR
| O_CREAT
) or return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual});
360 file_lock
(*FILE
,LOCK_EX
) or do { close(FILE
); return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual}) };
362 my $md5 = new Digest
::MD5
;
363 $md5->addfile(*FILE
);
365 my $md5file = $md5->hexdigest;
366 my $md5data = md5_hex
($content);
368 if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
370 # The file changed meanwhile
372 my $tpl = new Template
;
373 $tpl->read_file($config->{'templates'}->{'editfile'});
375 $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
377 $tpl->fillin('FILE',$virtual);
378 $tpl->fillin('DIR',$dir);
379 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
380 $tpl->fillin('SCRIPT',$script);
381 $tpl->fillin('MD5SUM',$md5file);
382 $tpl->fillin('CONTENT',encode_entities
($content));
384 $tpl->parse_if_block('error',1);
386 my $data = header
(-type
=> 'text/html');
387 $data .= $tpl->get_template;
393 if($md5data ne $md5file)
401 $output = devedit_reload
({command
=> 'show', file
=> $dir});
409 return devedit_reload
({command
=> 'beginedit', file
=> $virtual});
414 # Create a file and return to directory view
416 # Params: 1. Reference to user input hash
417 # 2. Reference to config hash
419 # Return: Output of the command (Scalar Reference)
423 my ($data,$config) = @_;
424 my $new_physical = $data->{'new_physical'};
425 my $new_virtual = $data->{'new_virtual'};
426 my $dir = upper_path
($new_virtual);
427 $new_virtual = encode_entities
($new_virtual);
431 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
433 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
434 return devedit_reload
({command
=> 'show', file
=> $dir});
438 my $tpl = new Template
;
439 $tpl->read_file($config->{'templates'}->{'mkfile'});
441 $tpl->fillin('DIR','/');
442 $tpl->fillin('SCRIPT',$script);
444 my $output = header
(-type
=> 'text/html');
445 $output .= $tpl->get_template;
453 # Create a directory and return to directory view
455 # Params: 1. Reference to user input hash
456 # 2. Reference to config hash
458 # Return: Output of the command (Scalar Reference)
462 my ($data,$config) = @_;
463 my $new_physical = $data->{'new_physical'};
464 my $new_virtual = $data->{'new_virtual'};
465 my $dir = upper_path
($new_virtual);
466 $new_virtual = encode_entities
($new_virtual);
470 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
472 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
473 return devedit_reload
({command
=> 'show', file
=> $dir});
477 my $tpl = new Template
;
478 $tpl->read_file($config->{'templates'}->{'mkdir'});
480 $tpl->fillin('DIR','/');
481 $tpl->fillin('SCRIPT',$script);
483 my $output = header
(-type
=> 'text/html');
484 $output .= $tpl->get_template;
492 # Process a file upload
494 # Params: 1. Reference to user input hash
495 # 2. Reference to config hash
497 # Return: Output of the command (Scalar Reference)
501 my ($data,$config) = @_;
502 my $physical = $data->{'physical'};
503 my $virtual = $data->{'virtual'};
504 my $cgi = $data->{'cgi'};
506 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> $virtual}) unless(-d
$physical && not -l
$physical);
507 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> $virtual}) unless(-w
$physical);
509 if(my $uploaded_file = $cgi->param('uploaded_file'))
511 # Process file upload
513 my $filename = file_name
($uploaded_file);
514 my $file_phys = $physical.'/'.$filename;
515 my $file_virt = $virtual.$filename;
519 return error
($config->{'errors'}->{'link_replace'},$virtual) if(-l
$file_phys);
520 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
521 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
522 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
525 my $ascii = $cgi->param('ascii');
526 my $handle = $cgi->upload('uploaded_file');
528 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
530 # Read transferred file and write it to disk
532 read($handle, my $data, -s
$handle);
533 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
534 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
536 return devedit_reload
({command
=> 'show', file
=> $virtual});
540 my $tpl = new Template
;
541 $tpl->read_file($config->{'templates'}->{'upload'});
543 $tpl->fillin('DIR',$virtual);
544 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
545 $tpl->fillin('SCRIPT',$script);
547 my $output = header
(-type
=> 'text/html');
548 $output .= $tpl->get_template;
556 # Copy a file and return to directory view
558 # Params: 1. Reference to user input hash
559 # 2. Reference to config hash
561 # Return: Output of the command (Scalar Reference)
565 my ($data,$config) = @_;
566 my $physical = $data->{'physical'};
567 my $virtual = encode_entities
($data->{'virtual'});
568 my $dir = upper_path
($virtual);
569 my $new_physical = $data->{'new_physical'};
571 return error
($config->{'errors'}->{'link_copy'},$dir) if(-l
$physical);
572 return error
($config->{'errors'}->{'dir_copy'},$dir) if(-d
$physical);
573 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
577 my $new_virtual = $data->{'new_virtual'};
578 my $new_dir = upper_path
($new_virtual);
579 $new_virtual = encode_entities
($new_virtual);
583 return error
($config->{'errors'}->{'link_replace'},$new_dir) if(-l
$new_physical);
584 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
585 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
587 if(not $data->{'cgi'}->param('confirmed'))
589 my $tpl = new Template
;
590 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
592 $tpl->fillin('FILE',$virtual);
593 $tpl->fillin('NEW_FILE',$new_virtual);
594 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
595 $tpl->fillin('NEW_DIR',$new_dir);
596 $tpl->fillin('DIR',$dir);
598 $tpl->fillin('COMMAND','copy');
599 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
600 $tpl->fillin('SCRIPT',$script);
602 my $output = header
(-type
=> 'text/html');
603 $output .= $tpl->get_template;
609 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
610 return devedit_reload
({command
=> 'show', file
=> $new_dir});
614 my $tpl = new Template
;
615 $tpl->read_file($config->{'templates'}->{'copyfile'});
617 $tpl->fillin('FILE',$virtual);
618 $tpl->fillin('DIR',$dir);
619 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
620 $tpl->fillin('SCRIPT',$script);
622 my $output = header
(-type
=> 'text/html');
623 $output .= $tpl->get_template;
631 # Rename/move a file and return to directory view
633 # Params: 1. Reference to user input hash
634 # 2. Reference to config hash
636 # Return: Output of the command (Scalar Reference)
640 my ($data,$config) = @_;
641 my $physical = $data->{'physical'};
642 my $virtual = $data->{'virtual'};
643 my $dir = upper_path
($virtual);
644 my $new_physical = $data->{'new_physical'};
646 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
647 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
651 my $new_virtual = $data->{'new_virtual'};
652 my $new_dir = upper_path
($new_virtual);
653 $new_virtual = encode_entities
($new_virtual);
657 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical && not -l
$new_physical);
658 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
660 if(not $data->{'cgi'}->param('confirmed'))
662 my $tpl = new Template
;
663 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
665 $tpl->fillin('FILE',$virtual);
666 $tpl->fillin('NEW_FILE',$new_virtual);
667 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
668 $tpl->fillin('NEW_DIR',$new_dir);
669 $tpl->fillin('DIR',$dir);
671 $tpl->fillin('COMMAND','rename');
672 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
673 $tpl->fillin('SCRIPT',$script);
675 my $output = header
(-type
=> 'text/html');
676 $output .= $tpl->get_template;
682 move
($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
683 return devedit_reload
({command
=> 'show', file
=> $new_dir});
687 my $tpl = new Template
;
688 $tpl->read_file($config->{'templates'}->{'renamefile'});
690 $tpl->fillin('FILE',$virtual);
691 $tpl->fillin('DIR',$dir);
692 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
693 $tpl->fillin('SCRIPT',$script);
695 my $output = header
(-type
=> 'text/html');
696 $output .= $tpl->get_template;
704 # Remove a file or a directory and return to directory view
706 # Params: 1. Reference to user input hash
707 # 2. Reference to config hash
709 # Return: Output of the command (Scalar Reference)
713 my ($data,$config) = @_;
714 my $physical = $data->{'physical'};
715 my $virtual = $data->{'virtual'};
716 my $dir = upper_path
($virtual);
718 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
719 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
721 if(-d
$physical && not -l
$physical)
725 if($data->{'cgi'}->param('confirmed'))
728 return devedit_reload
({command
=> 'show', file
=> $dir});
732 my $tpl = new Template
;
733 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
735 $tpl->fillin('DIR',$virtual);
736 $tpl->fillin('UPPER_DIR',$dir);
737 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
738 $tpl->fillin('SCRIPT',$script);
740 my $output = header
(-type
=> 'text/html');
741 $output .= $tpl->get_template;
750 if($data->{'cgi'}->param('confirmed'))
752 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
753 return devedit_reload
({command
=> 'show', file
=> $dir});
757 my $tpl = new Template
;
758 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
760 $tpl->fillin('FILE',$virtual);
761 $tpl->fillin('DIR',$dir);
762 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
763 $tpl->fillin('SCRIPT',$script);
765 my $output = header
(-type
=> 'text/html');
766 $output .= $tpl->get_template;
775 # Change the mode and the group of a file or a directory
777 # Params: 1. Reference to user input hash
778 # 2. Reference to config hash
780 # Return: Output of the command (Scalar Reference)
784 my ($data,$config) = @_;
785 my $physical = $data->{'physical'};
786 my $virtual = $data->{'virtual'};
787 my $dir = upper_path
($virtual);
789 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> $virtual}) unless($users);
790 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
791 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> $virtual}) unless(-o
$physical);
792 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
794 my $cgi = $data->{'cgi'};
795 my $mode = $cgi->param('mode');
796 my $group = $cgi->param('group');
804 chmod(oct($mode),$physical);
809 # Change the group using the `chgrp` system command
811 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_entities
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
812 system('chgrp',$group,$physical);
815 return devedit_reload
({command
=> 'show', file
=> $dir});
821 my @stat = stat($physical);
825 my $tpl = new Template
;
826 $tpl->read_file($config->{'templates'}->{'chprop'});
828 # Insert file properties into the template
830 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
831 $tpl->fillin('MODE_STRING',mode_string
($mode));
832 $tpl->fillin('GID',$gid);
834 if(my $group = getgrgid($gid))
836 $tpl->fillin('GROUP',encode_entities
($group));
837 $tpl->parse_if_block('group_detected',1);
841 $tpl->parse_if_block('group_detected',0);
844 # Insert other information
846 $tpl->fillin('FILE',$virtual);
847 $tpl->fillin('DIR',$dir);
848 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
849 $tpl->fillin('SCRIPT',$script);
851 my $output = header
(-type
=> 'text/html');
852 $output .= $tpl->get_template;
860 # Display some information about Dev-Editor
862 # Params: 1. Reference to user input hash
863 # 2. Reference to config hash
865 # Return: Output of the command (Scalar Reference)
869 my ($data,$config) = @_;
871 my $tpl = new Template
;
872 $tpl->read_file($config->{'templates'}->{'about'});
874 $tpl->fillin('SCRIPT',$script);
876 # Dev-Editor's version number
878 $tpl->fillin('VERSION',$data->{'version'});
880 # Some path information
882 $tpl->fillin('SCRIPT_PHYS',encode_entities
($ENV{'SCRIPT_FILENAME'}));
883 $tpl->fillin('CONFIG_PATH',encode_entities
($data->{'configfile'}));
884 $tpl->fillin('FILE_ROOT', encode_entities
($config->{'fileroot'}));
885 $tpl->fillin('HTTP_ROOT', encode_entities
($config->{'httproot'}));
889 $tpl->fillin('PERL_PROG',encode_entities
($^X
));
890 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
892 # Information about the server
894 $tpl->fillin('HTTPD',encode_entities
($ENV{'SERVER_SOFTWARE'}));
895 $tpl->fillin('OS', encode_entities
($^O
));
896 $tpl->fillin('TIME', encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
898 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
900 # Process information
902 $tpl->fillin('PID',$$);
904 # The following information is only available on systems supporting
909 # Dev-Editor is running on a system which allows users and groups
910 # So we display the user and the group of our process
912 my $uid = POSIX
::getuid
;
913 my $gid = POSIX
::getgid
;
915 $tpl->parse_if_block('users',1);
917 # ID's of user and group
919 $tpl->fillin('UID',$uid);
920 $tpl->fillin('GID',$gid);
922 # Names of user and group
924 if(my $user = getpwuid($uid))
926 $tpl->fillin('USER',encode_entities
($user));
927 $tpl->parse_if_block('user_detected',1);
931 $tpl->parse_if_block('user_detected',0);
934 if(my $group = getgrgid($gid))
936 $tpl->fillin('GROUP',encode_entities
($group));
937 $tpl->parse_if_block('group_detected',1);
941 $tpl->parse_if_block('group_detected',0);
946 $tpl->fillin('UMASK',sprintf('%04o',umask));
950 $tpl->parse_if_block('users',0);
953 my $output = header
(-type
=> 'text/html');
954 $output .= $tpl->get_template;
959 # it's true, baby ;-)
patrick-canterino.de