]>
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-10
21 use Digest::MD5 qw(md5_hex);
22 use POSIX
qw(strftime);
34 my $script = encode_entities
($ENV{'SCRIPT_NAME'});
35 my $users = eval('getpwuid(0)') && eval('getgrgid(0)');
37 my %dispatch = ('show' => \
&exec_show
,
38 'beginedit' => \
&exec_beginedit
,
39 'endedit' => \
&exec_endedit
,
40 'mkdir' => \
&exec_mkdir
,
41 'mkfile' => \
&exec_mkfile
,
42 'upload' => \
&exec_upload
,
43 'copy' => \
&exec_copy
,
44 'rename' => \
&exec_rename
,
45 'remove' => \
&exec_remove
,
46 'chprop' => \
&exec_chprop
,
47 'about' => \
&exec_about
52 use base
qw(Exporter);
54 @EXPORT = qw(exec_command);
58 # Execute the specified command
60 # Params: 1. Command to execute
61 # 2. Reference to user input hash
62 # 3. Reference to config hash
64 # Return: Output of the command (Scalar Reference)
68 my ($command,$data,$config) = @_;
70 foreach(keys(%dispatch))
72 if(lc($_) eq lc($command))
74 my $output = &{$dispatch{$_}}($data,$config);
79 return error
($config->{'errors'}->{'command_unknown'},'/',{COMMAND
=> encode_entities
($command)});
84 # View a directory or a file
86 # Params: 1. Reference to user input hash
87 # 2. Reference to config hash
89 # Return: Output of the command (Scalar Reference)
93 my ($data,$config) = @_;
94 my $physical = $data->{'physical'};
95 my $virtual = $data->{'virtual'};
96 my $upper_path = encode_entities
(upper_path
($virtual));
98 my $tpl = new Template
;
100 if(-d
$physical && not -l
$physical)
102 # Create directory listing
104 return error
($config->{'errors'}->{'no_dir_access'},$upper_path) unless(-r
$physical && -x
$physical);
106 my $direntries = dir_read
($physical);
107 return error
($config->{'dir_read_fail'},$upper_path,{DIR
=> encode_entities
($virtual)}) unless($direntries);
109 my $files = $direntries->{'files'};
110 my $dirs = $direntries->{'dirs'};
112 my $dir_writeable = -w
$physical;
116 my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
117 my $filter2 = ($filter1 && $filter1 ne '*') ?
$filter1 : ''; # Wildcard for output
119 # Create the link to the upper directory
120 # (only if the current directory is not the root directory)
122 unless($virtual eq '/')
124 my @stat = stat($physical.'/..');
126 my $udtpl = new Template
;
127 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
129 $udtpl->fillin('UPPER_DIR',$upper_path);
130 $udtpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
132 $dirlist .= $udtpl->get_template;
137 foreach my $dir(@
$dirs)
139 next unless(dos_wildcard_match
($filter1,$dir));
141 my $phys_path = $physical.'/'.$dir;
142 my $virt_path = encode_entities
($virtual.$dir.'/');
144 my @stat = stat($phys_path);
146 my $dtpl = new Template
;
147 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
149 $dtpl->fillin('DIR',$virt_path);
150 $dtpl->fillin('DIR_NAME',encode_entities
($dir));
151 $dtpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
152 $dtpl->fillin('URL',equal_url
(encode_entities
($config->{'httproot'}),$virt_path));
154 $dtpl->parse_if_block('readable',-r
$phys_path && -x
$phys_path);
155 $dtpl->parse_if_block('users',$users && -o
$phys_path);
157 $dirlist .= $dtpl->get_template;
162 foreach my $file(@
$files)
164 next unless(dos_wildcard_match
($filter1,$file));
166 my $phys_path = $physical.'/'.$file;
167 my $virt_path = encode_entities
($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);
176 $ftpl->fillin('FILE_NAME',encode_entities
($file));
177 $ftpl->fillin('SIZE',$stat[7]);
178 $ftpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
179 $ftpl->fillin('URL',equal_url
(encode_entities
($config->{'httproot'}),$virt_path));
181 $ftpl->parse_if_block('link',-l
$phys_path);
182 $ftpl->parse_if_block('no_link',not -l
$phys_path);
183 $ftpl->parse_if_block('not_readable',not -r
$phys_path);
184 $ftpl->parse_if_block('binary',-B
$phys_path);
185 $ftpl->parse_if_block('readonly',not -w
$phys_path);
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_entities
($virtual));
201 $tpl->fillin('SCRIPT',$script);
202 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
204 $tpl->fillin('FILTER',encode_entities
($filter2));
205 $tpl->fillin('FILTER_URL',escape
($filter2));
207 $tpl->parse_if_block('empty',$dirlist eq '');
208 $tpl->parse_if_block('dir_writeable',$dir_writeable);
209 $tpl->parse_if_block('filter',$filter2);
210 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
214 # Show the target of a symbolic link
216 my $link_target = readlink($physical);
218 $tpl->read_file($config->{'templates'}->{'viewlink'});
220 $tpl->fillin('FILE',encode_entities
($virtual));
221 $tpl->fillin('DIR',$upper_path);
222 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
223 $tpl->fillin('SCRIPT',$script);
225 $tpl->fillin('LINK_TARGET',encode_entities
($link_target));
231 return error
($config->{'errors'}->{'no_view'},$upper_path) unless(-r
$physical);
233 # Check on binary files
234 # We have to do it in this way or empty files will be recognized
237 return error
($config->{'errors'}->{'binary_file'},$upper_path) unless(-T
$physical);
239 # Is the file too large?
241 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'});
245 my $content = file_read
($physical);
246 $$content =~ s/\015\012|\012|\015/\n/g;
248 $tpl->read_file($config->{'templates'}->{'viewfile'});
250 $tpl->fillin('FILE',encode_entities
($virtual));
251 $tpl->fillin('DIR',$upper_path);
252 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
253 $tpl->fillin('SCRIPT',$script);
255 $tpl->parse_if_block('editable',-w
$physical);
257 $tpl->fillin('CONTENT',encode_entities
($$content));
260 my $output = header
(-type
=> 'text/html');
261 $output .= $tpl->get_template;
268 # Lock a file and display a form to edit it
270 # Params: 1. Reference to user input hash
271 # 2. Reference to config hash
273 # Return: Output of the command (Scalar Reference)
275 sub exec_beginedit
($$)
277 my ($data,$config) = @_;
278 my $physical = $data->{'physical'};
279 my $virtual = $data->{'virtual'};
280 my $dir = upper_path
($virtual);
281 my $cgi = $data->{'cgi'};
283 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
284 return error
($config->{'errors'}->{'dir_edit'}, $dir) if(-d
$physical);
285 return error
($config->{'errors'}->{'no_edit'}, $dir) unless(-r
$physical && -w
$physical);
287 # Check on binary files
289 return error
($config->{'errors'}->{'binary_file'},$dir) unless(-T
$physical);
291 # Is the file too large?
293 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
295 # ... and show the editing form
297 my $content = file_read
($physical);
298 my $md5sum = md5_hex
($$content);
299 $$content =~ s/\015\012|\012|\015/\n/g;
301 my $tpl = new Template
;
302 $tpl->read_file($config->{'templates'}->{'editfile'});
304 $tpl->fillin('FILE',$virtual);
305 $tpl->fillin('DIR',$dir);
306 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
307 $tpl->fillin('SCRIPT',$script);
308 $tpl->fillin('MD5SUM',$md5sum);
309 $tpl->fillin('CONTENT',encode_entities
($$content));
311 $tpl->parse_if_block('error',0);
313 my $output = header
(-type
=> 'text/html');
314 $output .= $tpl->get_template;
321 # Save a file, unlock it and return to directory view
323 # Params: 1. Reference to user input hash
324 # 2. Reference to config hash
326 # Return: Output of the command (Scalar Reference)
330 my ($data,$config) = @_;
331 my $physical = $data->{'physical'};
332 my $virtual = $data->{'virtual'};
333 my $dir = upper_path
($virtual);
334 my $cgi = $data->{'cgi'};
335 my $content = $cgi->param('filecontent');
336 my $md5sum = $cgi->param('md5sum');
339 if(defined $content && $md5sum)
343 $content =~ s/\015\012|\012|\015/\n/g;
345 if($cgi->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
347 # Create the new filename
349 $physical = $data->{'new_physical'};
350 $virtual = $data->{'new_virtual'};
353 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
354 return error
($config->{'errors'}->{'dir_edit'},$dir) if(-d
$physical);
355 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
356 return error
($config->{'errors'}->{'text_to_binary'},$dir) if(-e
$physical && not -T
$physical);
358 # For technical reasons, we can't use file_save() for
363 sysopen(FILE
,$physical,O_RDWR
| O_CREAT
) or return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual});
364 file_lock
(*FILE
,LOCK_EX
) or do { close(FILE
); return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual}) };
366 my $md5 = new Digest
::MD5
;
367 $md5->addfile(*FILE
);
369 my $md5_new = $md5->hexdigest;
371 if($md5_new ne $md5sum && not $cgi->param('saveas'))
373 # The file changed meanwhile
375 my $tpl = new Template
;
376 $tpl->read_file($config->{'templates'}->{'editfile'});
378 $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
380 $tpl->fillin('FILE',$virtual);
381 $tpl->fillin('DIR',$dir);
382 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
383 $tpl->fillin('SCRIPT',$script);
384 $tpl->fillin('MD5SUM',$md5_new);
385 $tpl->fillin('CONTENT',encode_entities
($content));
387 $tpl->parse_if_block('error',1);
389 my $data = header
(-type
=> 'text/html');
390 $data .= $tpl->get_template;
396 # The file was saved successfully!
403 $output = devedit_reload
({command
=> 'show', file
=> $dir});
405 #return error($config->{'errors'}->{'edit_failed'},$dir,{FILE => $virtual});
413 return devedit_reload
({command
=> 'beginedit', file
=> $virtual});
418 # Create a file and return to directory view
420 # Params: 1. Reference to user input hash
421 # 2. Reference to config hash
423 # Return: Output of the command (Scalar Reference)
427 my ($data,$config) = @_;
428 my $new_physical = $data->{'new_physical'};
429 my $new_virtual = $data->{'new_virtual'};
430 my $dir = upper_path
($new_virtual);
431 $new_virtual = encode_entities
($new_virtual);
435 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
437 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
438 return devedit_reload
({command
=> 'show', file
=> $dir});
442 my $tpl = new Template
;
443 $tpl->read_file($config->{'templates'}->{'mkfile'});
445 $tpl->fillin('DIR','/');
446 $tpl->fillin('SCRIPT',$script);
448 my $output = header
(-type
=> 'text/html');
449 $output .= $tpl->get_template;
457 # Create a directory and return to directory view
459 # Params: 1. Reference to user input hash
460 # 2. Reference to config hash
462 # Return: Output of the command (Scalar Reference)
466 my ($data,$config) = @_;
467 my $new_physical = $data->{'new_physical'};
468 my $new_virtual = $data->{'new_virtual'};
469 my $dir = upper_path
($new_virtual);
470 $new_virtual = encode_entities
($new_virtual);
474 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
476 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
477 return devedit_reload
({command
=> 'show', file
=> $dir});
481 my $tpl = new Template
;
482 $tpl->read_file($config->{'templates'}->{'mkdir'});
484 $tpl->fillin('DIR','/');
485 $tpl->fillin('SCRIPT',$script);
487 my $output = header
(-type
=> 'text/html');
488 $output .= $tpl->get_template;
496 # Process a file upload
498 # Params: 1. Reference to user input hash
499 # 2. Reference to config hash
501 # Return: Output of the command (Scalar Reference)
505 my ($data,$config) = @_;
506 my $physical = $data->{'physical'};
507 my $virtual = $data->{'virtual'};
508 my $cgi = $data->{'cgi'};
510 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> $virtual}) unless(-d
$physical && not -l
$physical);
511 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> $virtual}) unless(-w
$physical);
513 if(my $uploaded_file = $cgi->param('uploaded_file'))
515 # Process file upload
517 my $filename = file_name
($uploaded_file);
518 my $file_phys = $physical.'/'.$filename;
519 my $file_virt = $virtual.$filename;
523 return error
($config->{'errors'}->{'link_replace'},$virtual) if(-l
$file_phys);
524 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
525 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
526 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
529 my $ascii = $cgi->param('ascii');
530 my $handle = $cgi->upload('uploaded_file');
532 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
534 # Read transferred file and write it to disk
536 read($handle, my $data, -s
$handle);
537 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
538 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
540 return devedit_reload
({command
=> 'show', file
=> $virtual});
544 my $tpl = new Template
;
545 $tpl->read_file($config->{'templates'}->{'upload'});
547 $tpl->fillin('DIR',$virtual);
548 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
549 $tpl->fillin('SCRIPT',$script);
551 my $output = header
(-type
=> 'text/html');
552 $output .= $tpl->get_template;
560 # Copy a file and return to directory view
562 # Params: 1. Reference to user input hash
563 # 2. Reference to config hash
565 # Return: Output of the command (Scalar Reference)
569 my ($data,$config) = @_;
570 my $physical = $data->{'physical'};
571 my $virtual = encode_entities
($data->{'virtual'});
572 my $dir = upper_path
($virtual);
573 my $new_physical = $data->{'new_physical'};
575 return error
($config->{'errors'}->{'link_copy'},$dir) if(-l
$physical);
576 return error
($config->{'errors'}->{'dir_copy'},$dir) if(-d
$physical);
577 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
581 my $new_virtual = $data->{'new_virtual'};
582 my $new_dir = upper_path
($new_virtual);
583 $new_virtual = encode_entities
($new_virtual);
587 return error
($config->{'errors'}->{'link_replace'},$new_dir) if(-l
$new_physical);
588 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
589 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
591 if(not $data->{'cgi'}->param('confirmed'))
593 my $tpl = new Template
;
594 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
596 $tpl->fillin('FILE',$virtual);
597 $tpl->fillin('NEW_FILE',$new_virtual);
598 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
599 $tpl->fillin('NEW_DIR',$new_dir);
600 $tpl->fillin('DIR',$dir);
602 $tpl->fillin('COMMAND','copy');
603 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
604 $tpl->fillin('SCRIPT',$script);
606 my $output = header
(-type
=> 'text/html');
607 $output .= $tpl->get_template;
613 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
614 return devedit_reload
({command
=> 'show', file
=> $new_dir});
618 my $tpl = new Template
;
619 $tpl->read_file($config->{'templates'}->{'copyfile'});
621 $tpl->fillin('FILE',$virtual);
622 $tpl->fillin('DIR',$dir);
623 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
624 $tpl->fillin('SCRIPT',$script);
626 my $output = header
(-type
=> 'text/html');
627 $output .= $tpl->get_template;
635 # Rename/move a file and return to directory view
637 # Params: 1. Reference to user input hash
638 # 2. Reference to config hash
640 # Return: Output of the command (Scalar Reference)
644 my ($data,$config) = @_;
645 my $physical = $data->{'physical'};
646 my $virtual = $data->{'virtual'};
647 my $dir = upper_path
($virtual);
648 my $new_physical = $data->{'new_physical'};
650 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
651 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
655 my $new_virtual = $data->{'new_virtual'};
656 my $new_dir = upper_path
($new_virtual);
657 $new_virtual = encode_entities
($new_virtual);
661 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical && not -l
$new_physical);
662 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
664 if(not $data->{'cgi'}->param('confirmed'))
666 my $tpl = new Template
;
667 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
669 $tpl->fillin('FILE',$virtual);
670 $tpl->fillin('NEW_FILE',$new_virtual);
671 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
672 $tpl->fillin('NEW_DIR',$new_dir);
673 $tpl->fillin('DIR',$dir);
675 $tpl->fillin('COMMAND','rename');
676 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
677 $tpl->fillin('SCRIPT',$script);
679 my $output = header
(-type
=> 'text/html');
680 $output .= $tpl->get_template;
686 move
($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
687 return devedit_reload
({command
=> 'show', file
=> $new_dir});
691 my $tpl = new Template
;
692 $tpl->read_file($config->{'templates'}->{'renamefile'});
694 $tpl->fillin('FILE',$virtual);
695 $tpl->fillin('DIR',$dir);
696 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
697 $tpl->fillin('SCRIPT',$script);
699 my $output = header
(-type
=> 'text/html');
700 $output .= $tpl->get_template;
708 # Remove a file or a directory and return to directory view
710 # Params: 1. Reference to user input hash
711 # 2. Reference to config hash
713 # Return: Output of the command (Scalar Reference)
717 my ($data,$config) = @_;
718 my $physical = $data->{'physical'};
719 my $virtual = $data->{'virtual'};
720 my $dir = upper_path
($virtual);
722 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
723 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
725 if(-d
$physical && not -l
$physical)
729 if($data->{'cgi'}->param('confirmed'))
732 return devedit_reload
({command
=> 'show', file
=> $dir});
736 my $tpl = new Template
;
737 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
739 $tpl->fillin('DIR',$virtual);
740 $tpl->fillin('UPPER_DIR',$dir);
741 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
742 $tpl->fillin('SCRIPT',$script);
744 my $output = header
(-type
=> 'text/html');
745 $output .= $tpl->get_template;
754 if($data->{'cgi'}->param('confirmed'))
756 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
757 return devedit_reload
({command
=> 'show', file
=> $dir});
761 my $tpl = new Template
;
762 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
764 $tpl->fillin('FILE',$virtual);
765 $tpl->fillin('DIR',$dir);
766 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
767 $tpl->fillin('SCRIPT',$script);
769 my $output = header
(-type
=> 'text/html');
770 $output .= $tpl->get_template;
779 # Change the mode and the group of a file or a directory
781 # Params: 1. Reference to user input hash
782 # 2. Reference to config hash
784 # Return: Output of the command (Scalar Reference)
788 my ($data,$config) = @_;
789 my $physical = $data->{'physical'};
790 my $virtual = $data->{'virtual'};
791 my $dir = upper_path
($virtual);
793 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> $virtual}) unless($users);
794 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
795 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> $virtual}) unless(-o
$physical);
796 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
798 my $cgi = $data->{'cgi'};
799 my $mode = $cgi->param('mode');
800 my $group = $cgi->param('group');
808 chmod(oct($mode),$physical);
813 # Change the group using the `chgrp` system command
815 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_entities
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
816 system('chgrp',$group,$physical);
819 return devedit_reload
({command
=> 'show', file
=> $dir});
825 my @stat = stat($physical);
829 my $tpl = new Template
;
830 $tpl->read_file($config->{'templates'}->{'chprop'});
832 # Insert file properties into the template
834 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
835 $tpl->fillin('MODE_STRING',mode_string
($mode));
836 $tpl->fillin('GID',$gid);
838 if(my $group = getgrgid($gid))
840 $tpl->fillin('GROUP',encode_entities
($group));
841 $tpl->parse_if_block('group_detected',1);
845 $tpl->parse_if_block('group_detected',0);
848 # Insert other information
850 $tpl->fillin('FILE',$virtual);
851 $tpl->fillin('DIR',$dir);
852 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
853 $tpl->fillin('SCRIPT',$script);
855 my $output = header
(-type
=> 'text/html');
856 $output .= $tpl->get_template;
864 # Display some information about Dev-Editor
866 # Params: 1. Reference to user input hash
867 # 2. Reference to config hash
869 # Return: Output of the command (Scalar Reference)
873 my ($data,$config) = @_;
875 my $tpl = new Template
;
876 $tpl->read_file($config->{'templates'}->{'about'});
878 $tpl->fillin('SCRIPT',$script);
880 # Dev-Editor's version number
882 $tpl->fillin('VERSION',$data->{'version'});
884 # Some path information
886 $tpl->fillin('SCRIPT_PHYS',encode_entities
($ENV{'SCRIPT_FILENAME'}));
887 $tpl->fillin('CONFIG_PATH',encode_entities
($data->{'configfile'}));
888 $tpl->fillin('FILE_ROOT', encode_entities
($config->{'fileroot'}));
889 $tpl->fillin('HTTP_ROOT', encode_entities
($config->{'httproot'}));
893 $tpl->fillin('PERL_PROG',encode_entities
($^X
));
894 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
896 # Information about the server
898 $tpl->fillin('HTTPD',encode_entities
($ENV{'SERVER_SOFTWARE'}));
899 $tpl->fillin('OS', encode_entities
($^O
));
900 $tpl->fillin('TIME', encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
902 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
904 # Process information
906 $tpl->fillin('PID',$$);
908 # The following information is only available on systems supporting
913 # Dev-Editor is running on a system which allows users and groups
914 # So we display the user and the group of our process
916 my $uid = POSIX
::getuid
;
917 my $gid = POSIX
::getgid
;
919 $tpl->parse_if_block('users',1);
921 # ID's of user and group
923 $tpl->fillin('UID',$uid);
924 $tpl->fillin('GID',$gid);
926 # Names of user and group
928 if(my $user = getpwuid($uid))
930 $tpl->fillin('USER',encode_entities
($user));
931 $tpl->parse_if_block('user_detected',1);
935 $tpl->parse_if_block('user_detected',0);
938 if(my $group = getgrgid($gid))
940 $tpl->fillin('GROUP',encode_entities
($group));
941 $tpl->parse_if_block('group_detected',1);
945 $tpl->parse_if_block('group_detected',0);
950 $tpl->fillin('UMASK',sprintf('%04o',umask));
954 $tpl->parse_if_block('users',0);
957 my $output = header
(-type
=> 'text/html');
958 $output .= $tpl->get_template;
963 # it's true, baby ;-)
patrick-canterino.de