]>
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-01-24
20 use POSIX qw(strftime);
30 my $script = encode_entities
($ENV{'SCRIPT_NAME'});
31 my $users = eval('getpwuid(0)') && eval('getgrgid(0)');
33 my %dispatch = ('show' => \
&exec_show
,
34 'beginedit' => \
&exec_beginedit
,
35 'canceledit' => \
&exec_canceledit
,
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 'unlock' => \
&exec_unlock
,
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'}->{'cmd_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));
95 my $uselist = $data->{'uselist'};
97 my $tpl = new Template
;
101 # Create directory listing
103 return error
($config->{'errors'}->{'no_dir_access'},$upper_path) unless(-r
$physical && -x
$physical);
105 my $direntries = dir_read
($physical);
106 return error
($config->{'dir_read_fail'},$upper_path,{DIR
=> encode_entities
($virtual)}) unless($direntries);
108 my $files = $direntries->{'files'};
109 my $dirs = $direntries->{'dirs'};
111 my $dir_writeable = -w
$physical;
115 my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
116 my $filter2 = ($filter1 && $filter1 ne '*') ?
$filter1 : ''; # Wildcard for output
118 # Create the link to the upper directory
119 # (only if we are not in the root directory)
121 unless($virtual eq '/')
123 my @stat = stat($physical.'/..');
125 my $udtpl = new Template
;
126 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
128 $udtpl->fillin('UPPER_DIR',$upper_path);
129 $udtpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
131 $dirlist .= $udtpl->get_template;
136 foreach my $dir(@
$dirs)
138 next unless(dos_wildcard_match
($filter1,$dir));
140 my $phys_path = $physical.'/'.$dir;
141 my $virt_path = encode_entities
($virtual.$dir.'/');
143 my @stat = stat($phys_path);
145 my $dtpl = new Template
;
146 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
148 $dtpl->fillin('DIR',$virt_path);
149 $dtpl->fillin('DIR_NAME',encode_entities
($dir));
150 $dtpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
151 $dtpl->fillin('URL',equal_url
(encode_entities
($config->{'httproot'}),$virt_path));
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 unless(dos_wildcard_match
($filter1,$file));
165 my $phys_path = $physical.'/'.$file;
166 my $virt_path = encode_entities
($virtual.$file);
168 my @stat = stat($phys_path);
169 my $in_use = $uselist->in_use($virtual.$file);
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('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);
186 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not $in_use);
188 $ftpl->parse_if_block('in_use',$in_use);
189 $ftpl->parse_if_block('unused',not $in_use);
191 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
193 $ftpl->parse_if_block('users',$users && -o
$phys_path);
195 $dirlist .= $ftpl->get_template;
198 $tpl->read_file($config->{'templates'}->{'dirlist'});
200 $tpl->fillin('DIRLIST',$dirlist);
201 $tpl->fillin('DIR',encode_entities
($virtual));
202 $tpl->fillin('SCRIPT',$script);
203 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
205 $tpl->fillin('FILTER',encode_entities
($filter2));
206 $tpl->fillin('FILTER_URL',escape
($filter2));
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'});
216 return error
($config->{'errors'}->{'no_view'},$upper_path) unless(-r
$physical);
218 # Check on binary files
219 # We have to do it in this way or empty files will be recognized
222 return error
($config->{'errors'}->{'binary'},$upper_path) unless(-T
$physical);
224 # Is the file too large?
226 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'});
230 my $content = file_read
($physical);
231 $$content =~ s/\015\012|\012|\015/\n/g;
233 $tpl->read_file($config->{'templates'}->{'viewfile'});
235 $tpl->fillin('FILE',encode_entities
($virtual));
236 $tpl->fillin('DIR',$upper_path);
237 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
238 $tpl->fillin('SCRIPT',$script);
240 $tpl->parse_if_block('editable',-w
$physical && $uselist->unused($virtual));
242 $tpl->fillin('CONTENT',encode_entities
($$content));
245 my $output = header
(-type
=> 'text/html');
246 $output .= $tpl->get_template;
253 # Lock a file and display a form to edit it
255 # Params: 1. Reference to user input hash
256 # 2. Reference to config hash
258 # Return: Output of the command (Scalar Reference)
260 sub exec_beginedit
($$)
262 my ($data,$config) = @_;
263 my $physical = $data->{'physical'};
264 my $virtual = $data->{'virtual'};
265 my $dir = upper_path
($virtual);
266 my $uselist = $data->{'uselist'};
268 return error
($config->{'errors'}->{'editdir'},$dir) if(-d
$physical);
269 return error
($config->{'errors'}->{'in_use'}, $dir,{FILE
=> $virtual}) if($uselist->in_use($virtual));
270 return error
($config->{'errors'}->{'no_edit'},$dir) unless(-r
$physical && -w
$physical);
272 # Check on binary files
274 return error
($config->{'errors'}->{'binary'},$dir) unless(-T
$physical);
276 # Is the file too large?
278 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
282 $uselist->add_file($virtual);
285 # ... and show the editing form
287 my $content = file_read
($physical);
288 $$content =~ s/\015\012|\012|\015/\n/g;
290 my $tpl = new Template
;
291 $tpl->read_file($config->{'templates'}->{'editfile'});
293 $tpl->fillin('FILE',$virtual);
294 $tpl->fillin('DIR',$dir);
295 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
296 $tpl->fillin('SCRIPT',$script);
297 $tpl->fillin('CONTENT',encode_entities
($$content));
299 my $output = header
(-type
=> 'text/html');
300 $output .= $tpl->get_template;
309 # Params: 1. Reference to user input hash
310 # 2. Reference to config hash
312 # Return: Output of the command (Scalar Reference)
314 sub exec_canceledit
($$)
316 my ($data,$config) = @_;
317 my $virtual = $data->{'virtual'};
319 file_unlock
($data->{'uselist'},$virtual);
320 return devedit_reload
({command
=> 'show', file
=> upper_path
($virtual)});
325 # Save a file, unlock it and return to directory view
327 # Params: 1. Reference to user input hash
328 # 2. Reference to config hash
330 # Return: Output of the command (Scalar Reference)
334 my ($data,$config) = @_;
335 my $physical = $data->{'physical'};
336 my $virtual = $data->{'virtual'};
337 my $dir = upper_path
($virtual);
338 my $content = $data->{'cgi'}->param('filecontent');
339 my $uselist = $data->{'uselist'};
341 # We already unlock the file at the beginning of the subroutine,
342 # because if we have to abort this routine, the file keeps locked.
343 # No other user of Dev-Editor will access the file during this
344 # routine because of the concept of File::UseList.
346 file_unlock
($uselist,$virtual);
350 $content =~ s/\015\012|\012|\015/\n/g;
352 if($data->{'cgi'}->param('encode_iso'))
354 # Encode all ISO-8859-1 special chars
356 $content = encode_entities
($content,"\200-\377");
359 if($data->{'cgi'}->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
361 # Create the new filename
363 $physical = $data->{'new_physical'};
364 $virtual = $data->{'new_virtual'};
366 # Check if someone else is editing the new file
368 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($uselist->in_use($virtual));
371 return error
($config->{'errors'}->{'editdir'},$dir) if(-d
$physical);
372 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
373 return error
($config->{'errors'}->{'text_to_binary'},$dir) unless(-T
$physical);
375 if(file_save
($physical,\
$content))
377 # Saving of the file was successful!
379 return devedit_reload
({command
=> 'show', file
=> $dir});
383 return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual});
389 # Create a file and return to directory view
391 # Params: 1. Reference to user input hash
392 # 2. Reference to config hash
394 # Return: Output of the command (Scalar Reference)
398 my ($data,$config) = @_;
399 my $new_physical = $data->{'new_physical'};
400 my $new_virtual = $data->{'new_virtual'};
401 my $dir = upper_path
($new_virtual);
402 $new_virtual = encode_entities
($new_virtual);
406 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
408 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
409 return devedit_reload
({command
=> 'show', file
=> $dir});
413 my $tpl = new Template
;
414 $tpl->read_file($config->{'templates'}->{'mkfile'});
416 $tpl->fillin('DIR','/');
417 $tpl->fillin('SCRIPT',$script);
419 my $output = header
(-type
=> 'text/html');
420 $output .= $tpl->get_template;
428 # Create a directory and return to directory view
430 # Params: 1. Reference to user input hash
431 # 2. Reference to config hash
433 # Return: Output of the command (Scalar Reference)
437 my ($data,$config) = @_;
438 my $new_physical = $data->{'new_physical'};
439 my $new_virtual = $data->{'new_virtual'};
440 my $dir = upper_path
($new_virtual);
441 $new_virtual = encode_entities
($new_virtual);
445 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
447 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
448 return devedit_reload
({command
=> 'show', file
=> $dir});
452 my $tpl = new Template
;
453 $tpl->read_file($config->{'templates'}->{'mkdir'});
455 $tpl->fillin('DIR','/');
456 $tpl->fillin('SCRIPT',$script);
458 my $output = header
(-type
=> 'text/html');
459 $output .= $tpl->get_template;
469 # Params: 1. Reference to user input hash
470 # 2. Reference to config hash
472 # Return: Output of the command (Scalar Reference)
476 my ($data,$config) = @_;
477 my $physical = $data->{'physical'};
478 my $virtual = $data->{'virtual'};
479 my $cgi = $data->{'cgi'};
481 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> $virtual}) unless(-d
$physical);
482 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> $virtual}) unless(-w
$physical);
484 if(my $uploaded_file = $cgi->param('uploaded_file'))
486 # Process file upload
488 my $filename = file_name
($uploaded_file);
489 my $file_phys = $physical.'/'.$filename;
490 my $file_virt = $virtual.$filename;
492 return error
($config->{'errors'}->{'in_use'},$virtual,{FILE
=> $file_virt}) if($data->{'uselist'}->in_use($file_virt));
496 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
497 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
498 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
501 my $ascii = $cgi->param('ascii');
502 my $handle = $cgi->upload('uploaded_file');
504 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
506 # Read transferred file and write it to disk
508 read($handle, my $data, -s
$handle);
509 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
510 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
512 return devedit_reload
({command
=> 'show', file
=> $virtual});
516 my $tpl = new Template
;
517 $tpl->read_file($config->{'templates'}->{'upload'});
519 $tpl->fillin('DIR',$virtual);
520 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
521 $tpl->fillin('SCRIPT',$script);
523 my $output = header
(-type
=> 'text/html');
524 $output .= $tpl->get_template;
532 # Copy a file and return to directory view
534 # Params: 1. Reference to user input hash
535 # 2. Reference to config hash
537 # Return: Output of the command (Scalar Reference)
541 my ($data,$config) = @_;
542 my $physical = $data->{'physical'};
543 my $virtual = encode_entities
($data->{'virtual'});
544 my $dir = upper_path
($virtual);
545 my $new_physical = $data->{'new_physical'};
547 return error
($config->{'errors'}->{'dircopy'},$dir) if(-d
$physical);
548 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
552 my $new_virtual = $data->{'new_virtual'};
553 my $new_dir = upper_path
($new_virtual);
554 $new_virtual = encode_entities
($new_virtual);
558 return error
($config->{'errors'}->{'exist_edited'},$new_dir,{FILE
=> $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
559 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
560 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
562 if(not $data->{'cgi'}->param('confirmed'))
564 my $tpl = new Template
;
565 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
567 $tpl->fillin('FILE',$virtual);
568 $tpl->fillin('NEW_FILE',$new_virtual);
569 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
570 $tpl->fillin('NEW_DIR',$new_dir);
571 $tpl->fillin('DIR',$dir);
573 $tpl->fillin('COMMAND','copy');
574 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
575 $tpl->fillin('SCRIPT',$script);
577 my $output = header
(-type
=> 'text/html');
578 $output .= $tpl->get_template;
584 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
585 return devedit_reload
({command
=> 'show', file
=> $new_dir});
589 my $tpl = new Template
;
590 $tpl->read_file($config->{'templates'}->{'copyfile'});
592 $tpl->fillin('FILE',$virtual);
593 $tpl->fillin('DIR',$dir);
594 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
595 $tpl->fillin('SCRIPT',$script);
597 my $output = header
(-type
=> 'text/html');
598 $output .= $tpl->get_template;
606 # Rename/move a file and return to directory view
608 # Params: 1. Reference to user input hash
609 # 2. Reference to config hash
611 # Return: Output of the command (Scalar Reference)
615 my ($data,$config) = @_;
616 my $physical = $data->{'physical'};
617 my $virtual = $data->{'virtual'};
618 my $dir = upper_path
($virtual);
619 my $new_physical = $data->{'new_physical'};
621 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
622 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
623 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
627 my $new_virtual = $data->{'new_virtual'};
628 my $new_dir = upper_path
($new_virtual);
629 $new_virtual = encode_entities
($new_virtual);
633 return error
($config->{'errors'}->{'exist_edited'},$new_dir,{FILE
=> $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
634 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
635 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
637 if(not $data->{'cgi'}->param('confirmed'))
639 my $tpl = new Template
;
640 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
642 $tpl->fillin('FILE',$virtual);
643 $tpl->fillin('NEW_FILE',$new_virtual);
644 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
645 $tpl->fillin('NEW_DIR',$new_dir);
646 $tpl->fillin('DIR',$dir);
648 $tpl->fillin('COMMAND','rename');
649 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
650 $tpl->fillin('SCRIPT',$script);
652 my $output = header
(-type
=> 'text/html');
653 $output .= $tpl->get_template;
659 rename($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
660 return devedit_reload
({command
=> 'show', file
=> $new_dir});
664 my $tpl = new Template
;
665 $tpl->read_file($config->{'templates'}->{'renamefile'});
667 $tpl->fillin('FILE',$virtual);
668 $tpl->fillin('DIR',$dir);
669 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
670 $tpl->fillin('SCRIPT',$script);
672 my $output = header
(-type
=> 'text/html');
673 $output .= $tpl->get_template;
681 # Remove a file or a directory and return to directory view
683 # Params: 1. Reference to user input hash
684 # 2. Reference to config hash
686 # Return: Output of the command (Scalar Reference)
690 my ($data,$config) = @_;
691 my $physical = $data->{'physical'};
692 my $virtual = $data->{'virtual'};
693 my $dir = upper_path
($virtual);
695 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
696 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
702 if($data->{'cgi'}->param('confirmed'))
705 return devedit_reload
({command
=> 'show', file
=> $dir});
709 my $tpl = new Template
;
710 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
712 $tpl->fillin('DIR',$virtual);
713 $tpl->fillin('UPPER_DIR',$dir);
714 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
715 $tpl->fillin('SCRIPT',$script);
717 my $output = header
(-type
=> 'text/html');
718 $output .= $tpl->get_template;
727 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
729 if($data->{'cgi'}->param('confirmed'))
731 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
732 return devedit_reload
({command
=> 'show', file
=> $dir});
736 my $tpl = new Template
;
737 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
739 $tpl->fillin('FILE',$virtual);
740 $tpl->fillin('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 # Change the mode and the group of a file or a directory
756 # Params: 1. Reference to user input hash
757 # 2. Reference to config hash
759 # Return: Output of the command (Scalar Reference)
763 my ($data,$config) = @_;
764 my $physical = $data->{'physical'};
765 my $virtual = $data->{'virtual'};
766 my $dir = upper_path
($virtual);
768 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> $virtual}) unless($users);
769 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
770 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> $virtual}) unless(-o
$physical);
771 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
773 my $cgi = $data->{'cgi'};
774 my $mode = $cgi->param('mode');
775 my $group = $cgi->param('group');
783 chmod(oct($mode),$physical);
788 # Change the group using the `chgrp` system command
790 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_entities
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
791 system('chgrp',$group,$physical);
794 return devedit_reload
({command
=> 'show', file
=> $dir});
800 my @stat = stat($physical);
804 my $tpl = new Template
;
805 $tpl->read_file($config->{'templates'}->{'chprop'});
807 # Insert file properties into the template
809 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
810 $tpl->fillin('MODE_STRING',mode_string
($mode));
811 $tpl->fillin('GID',$gid);
813 if(my $group = getgrgid($gid))
815 $tpl->fillin('GROUP',encode_entities
($group));
816 $tpl->parse_if_block('group_detected',1);
820 $tpl->parse_if_block('group_detected',0);
823 # Insert other information
825 $tpl->fillin('FILE',$virtual);
826 $tpl->fillin('DIR',$dir);
827 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
828 $tpl->fillin('SCRIPT',$script);
830 my $output = header
(-type
=> 'text/html');
831 $output .= $tpl->get_template;
839 # Remove a file from the list of used files and
840 # return to directory view
842 # Params: 1. Reference to user input hash
843 # 2. Reference to config hash
845 # Return: Output of the command (Scalar Reference)
849 my ($data,$config) = @_;
850 my $virtual = $data->{'virtual'};
851 my $uselist = $data->{'uselist'};
852 my $dir = upper_path
($virtual);
854 return devedit_reload
({command
=> 'show', file
=> $dir}) if($uselist->unused($virtual));
856 if($data->{'cgi'}->param('confirmed'))
858 file_unlock
($uselist,$virtual);
859 return devedit_reload
({command
=> 'show', file
=> $dir});
863 my $tpl = new Template
;
864 $tpl->read_file($config->{'templates'}->{'confirm_unlock'});
866 $tpl->fillin('FILE',$virtual);
867 $tpl->fillin('DIR',$dir);
868 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
869 $tpl->fillin('SCRIPT',$script);
871 my $output = header
(-type
=> 'text/html');
872 $output .= $tpl->get_template;
880 # Display some information about Dev-Editor
882 # Params: 1. Reference to user input hash
883 # 2. Reference to config hash
885 # Return: Output of the command (Scalar Reference)
889 my ($data,$config) = @_;
891 my $tpl = new Template
;
892 $tpl->read_file($config->{'templates'}->{'about'});
894 $tpl->fillin('SCRIPT',$script);
896 # Dev-Editor's version number
898 $tpl->fillin('VERSION',$data->{'version'});
900 # Some path information
902 $tpl->fillin('SCRIPT_PHYS',encode_entities
($ENV{'SCRIPT_FILENAME'}));
903 $tpl->fillin('CONFIG_PATH',encode_entities
($data->{'configfile'}));
904 $tpl->fillin('FILE_ROOT', encode_entities
($config->{'fileroot'}));
905 $tpl->fillin('HTTP_ROOT', encode_entities
($config->{'httproot'}));
909 $tpl->fillin('PERL_PROG',encode_entities
($^X
));
910 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
912 # Information about the server
914 $tpl->fillin('HTTPD',encode_entities
($ENV{'SERVER_SOFTWARE'}));
915 $tpl->fillin('OS', encode_entities
($^O
));
916 $tpl->fillin('TIME', encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
918 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
920 # Process information
922 $tpl->fillin('PID',$$);
924 # Check if the functions getpwuid() and getgrgid() are available
928 # Dev-Editor is running on a system which allows users and groups
929 # So we display the user and the group of our process
931 my $uid = POSIX
::getuid
;
932 my $gid = POSIX
::getgid
;
934 $tpl->parse_if_block('users',1);
936 # ID's of user and group
938 $tpl->fillin('UID',$uid);
939 $tpl->fillin('GID',$gid);
941 # Names of user and group
943 if(my $user = getpwuid($uid))
945 $tpl->fillin('USER',encode_entities
($user));
946 $tpl->parse_if_block('user_detected',1);
950 $tpl->parse_if_block('user_detected',0);
953 if(my $group = getgrgid($gid))
955 $tpl->fillin('GROUP',encode_entities
($group));
956 $tpl->parse_if_block('group_detected',1);
960 $tpl->parse_if_block('group_detected',0);
965 $tpl->fillin('UMASK',sprintf('%04o',umask));
969 $tpl->parse_if_block('users',0);
972 my $output = header
(-type
=> 'text/html');
973 $output .= $tpl->get_template;
978 # it's true, baby ;-)
patrick-canterino.de