]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
e06d0b61877b42657b2a5519041c724c91ecc386
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2005-01-20
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'},localtime($stat[9]))));
131 $udtpl->parse_if_block('gmt',$config->{'use_gmt'});
133 $dirlist .= $udtpl->get_template;
138 foreach my $dir(@
$dirs)
140 next unless(dos_wildcard_match
($filter1,$dir));
142 my $phys_path = $physical.'/'.$dir;
143 my $virt_path = encode_entities
($virtual.$dir.'/');
145 my @stat = stat($phys_path);
147 my $dtpl = new Template
;
148 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
150 $dtpl->fillin('DIR',$virt_path);
151 $dtpl->fillin('DIR_NAME',encode_entities
($dir));
152 $dtpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
153 $dtpl->fillin('URL',equal_url
(encode_entities
($config->{'httproot'}),$virt_path));
155 $dtpl->parse_if_block('readable',-r
$phys_path && -x
$phys_path);
156 $dtpl->parse_if_block('users',$users && -o
$phys_path);
158 $dtpl->parse_if_block('gmt',$config->{'use_gmt'});
160 $dirlist .= $dtpl->get_template;
165 foreach my $file(@
$files)
167 next unless(dos_wildcard_match
($filter1,$file));
169 my $phys_path = $physical.'/'.$file;
170 my $virt_path = encode_entities
($virtual.$file);
172 my @stat = stat($phys_path);
173 my $in_use = $uselist->in_use($virtual.$file);
174 my $too_large = $config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'};
176 my $ftpl = new Template
;
177 $ftpl->read_file($config->{'templates'}->{'dirlist_file'});
179 $ftpl->fillin('FILE',$virt_path);
180 $ftpl->fillin('FILE_NAME',encode_entities
($file));
181 $ftpl->fillin('SIZE',$stat[7]);
182 $ftpl->fillin('DATE',encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
183 $ftpl->fillin('URL',equal_url
(encode_entities
($config->{'httproot'}),$virt_path));
185 $ftpl->parse_if_block('not_readable',not -r
$phys_path);
186 $ftpl->parse_if_block('binary',-B
$phys_path);
187 $ftpl->parse_if_block('readonly',not -w
$phys_path);
189 $ftpl->parse_if_block('viewable',-r
$phys_path && -T
$phys_path && not $too_large);
190 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not $in_use);
192 $ftpl->parse_if_block('in_use',$in_use);
193 $ftpl->parse_if_block('unused',not $in_use);
195 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
197 $ftpl->parse_if_block('gmt',$config->{'use_gmt'});
199 $ftpl->parse_if_block('users',$users && -o
$phys_path);
201 $dirlist .= $ftpl->get_template;
204 $tpl->read_file($config->{'templates'}->{'dirlist'});
206 $tpl->fillin('DIRLIST',$dirlist);
207 $tpl->fillin('DIR',encode_entities
($virtual));
208 $tpl->fillin('SCRIPT',$script);
209 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
211 $tpl->fillin('FILTER',encode_entities
($filter2));
212 $tpl->fillin('FILTER_URL',escape
($filter2));
214 $tpl->parse_if_block('dir_writeable',$dir_writeable);
215 $tpl->parse_if_block('filter',$filter2);
221 return error
($config->{'errors'}->{'no_view'},$upper_path) unless(-r
$physical);
223 # Check on binary files
224 # We have to do it in this way or empty files will be recognized
227 return error
($config->{'errors'}->{'binary'},$upper_path) unless(-T
$physical);
229 # Is the file too large?
231 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'});
235 my $content = file_read
($physical);
236 $$content =~ s/\015\012|\012|\015/\n/g;
238 $tpl->read_file($config->{'templates'}->{'viewfile'});
240 $tpl->fillin('FILE',encode_entities
($virtual));
241 $tpl->fillin('DIR',$upper_path);
242 $tpl->fillin('URL',encode_entities
(equal_url
($config->{'httproot'},$virtual)));
243 $tpl->fillin('SCRIPT',$script);
245 $tpl->parse_if_block('editable',-w
$physical && $uselist->unused($virtual));
247 $tpl->fillin('CONTENT',encode_entities
($$content));
250 my $output = header
(-type
=> 'text/html');
251 $output .= $tpl->get_template;
258 # Lock a file and display a form to edit it
260 # Params: 1. Reference to user input hash
261 # 2. Reference to config hash
263 # Return: Output of the command (Scalar Reference)
265 sub exec_beginedit
($$)
267 my ($data,$config) = @_;
268 my $physical = $data->{'physical'};
269 my $virtual = $data->{'virtual'};
270 my $dir = upper_path
($virtual);
271 my $uselist = $data->{'uselist'};
273 return error
($config->{'errors'}->{'editdir'},$dir) if(-d
$physical);
274 return error
($config->{'errors'}->{'in_use'}, $dir,{FILE
=> $virtual}) if($uselist->in_use($virtual));
275 return error
($config->{'errors'}->{'no_edit'},$dir) unless(-r
$physical && -w
$physical);
277 # Check on binary files
279 return error
($config->{'errors'}->{'binary'},$dir) unless(-T
$physical);
281 # Is the file too large?
283 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
287 $uselist->add_file($virtual);
290 # ... and show the editing form
292 my $content = file_read
($physical);
293 $$content =~ s/\015\012|\012|\015/\n/g;
295 my $tpl = new Template
;
296 $tpl->read_file($config->{'templates'}->{'editfile'});
298 $tpl->fillin('FILE',$virtual);
299 $tpl->fillin('DIR',$dir);
300 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
301 $tpl->fillin('SCRIPT',$script);
302 $tpl->fillin('CONTENT',encode_entities
($$content));
304 my $output = header
(-type
=> 'text/html');
305 $output .= $tpl->get_template;
314 # Params: 1. Reference to user input hash
315 # 2. Reference to config hash
317 # Return: Output of the command (Scalar Reference)
319 sub exec_canceledit
($$)
321 my ($data,$config) = @_;
322 my $virtual = $data->{'virtual'};
324 file_unlock
($data->{'uselist'},$virtual);
325 return devedit_reload
({command
=> 'show', file
=> upper_path
($virtual)});
330 # Save a file, unlock it and return to directory view
332 # Params: 1. Reference to user input hash
333 # 2. Reference to config hash
335 # Return: Output of the command (Scalar Reference)
339 my ($data,$config) = @_;
340 my $physical = $data->{'physical'};
341 my $virtual = $data->{'virtual'};
342 my $dir = upper_path
($virtual);
343 my $content = $data->{'cgi'}->param('filecontent');
344 my $uselist = $data->{'uselist'};
346 # We already unlock the file at the beginning of the subroutine,
347 # because if we have to abort this routine, the file keeps locked.
348 # No other user of Dev-Editor will access the file during this
349 # routine because of the concept of File::UseList.
351 file_unlock
($uselist,$virtual);
355 $content =~ s/\015\012|\012|\015/\n/g;
357 if($data->{'cgi'}->param('encode_iso'))
359 # Encode all ISO-8859-1 special chars
361 $content = encode_entities
($content,"\200-\377");
364 if($data->{'cgi'}->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
366 # Create the new filename
368 $physical = $data->{'new_physical'};
369 $virtual = $data->{'new_virtual'};
371 # Check if someone else is editing the new file
373 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($uselist->in_use($virtual));
376 return error
($config->{'errors'}->{'editdir'},$dir) if(-d
$physical);
377 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
378 return error
($config->{'errors'}->{'text_to_binary'},$dir) unless(-T
$physical);
380 if(file_save
($physical,\
$content))
382 # Saving of the file was successful!
384 return devedit_reload
({command
=> 'show', file
=> $dir});
388 return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual});
394 # Create a file and return to directory view
396 # Params: 1. Reference to user input hash
397 # 2. Reference to config hash
399 # Return: Output of the command (Scalar Reference)
403 my ($data,$config) = @_;
404 my $new_physical = $data->{'new_physical'};
405 my $new_virtual = $data->{'new_virtual'};
406 my $dir = upper_path
($new_virtual);
407 $new_virtual = encode_entities
($new_virtual);
411 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
413 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
414 return devedit_reload
({command
=> 'show', file
=> $dir});
418 my $tpl = new Template
;
419 $tpl->read_file($config->{'templates'}->{'mkfile'});
421 $tpl->fillin('DIR','/');
422 $tpl->fillin('SCRIPT',$script);
424 my $output = header
(-type
=> 'text/html');
425 $output .= $tpl->get_template;
433 # Create a directory and return to directory view
435 # Params: 1. Reference to user input hash
436 # 2. Reference to config hash
438 # Return: Output of the command (Scalar Reference)
442 my ($data,$config) = @_;
443 my $new_physical = $data->{'new_physical'};
444 my $new_virtual = $data->{'new_virtual'};
445 my $dir = upper_path
($new_virtual);
446 $new_virtual = encode_entities
($new_virtual);
450 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
452 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
453 return devedit_reload
({command
=> 'show', file
=> $dir});
457 my $tpl = new Template
;
458 $tpl->read_file($config->{'templates'}->{'mkdir'});
460 $tpl->fillin('DIR','/');
461 $tpl->fillin('SCRIPT',$script);
463 my $output = header
(-type
=> 'text/html');
464 $output .= $tpl->get_template;
474 # Params: 1. Reference to user input hash
475 # 2. Reference to config hash
477 # Return: Output of the command (Scalar Reference)
481 my ($data,$config) = @_;
482 my $physical = $data->{'physical'};
483 my $virtual = $data->{'virtual'};
484 my $cgi = $data->{'cgi'};
486 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> $virtual}) unless(-d
$physical);
487 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> $virtual}) unless(-w
$physical);
489 if(my $uploaded_file = $cgi->param('uploaded_file'))
491 # Process file upload
493 my $filename = file_name
($uploaded_file);
494 my $file_phys = $physical.'/'.$filename;
495 my $file_virt = $virtual.$filename;
497 return error
($config->{'errors'}->{'in_use'},$virtual,{FILE
=> $file_virt}) if($data->{'uselist'}->in_use($file_virt));
501 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
502 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
503 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
506 my $ascii = $cgi->param('ascii');
507 my $handle = $cgi->upload('uploaded_file');
509 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
511 # Read transferred file and write it to disk
513 read($handle, my $data, -s
$handle);
514 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
515 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
517 return devedit_reload
({command
=> 'show', file
=> $virtual});
521 my $tpl = new Template
;
522 $tpl->read_file($config->{'templates'}->{'upload'});
524 $tpl->fillin('DIR',$virtual);
525 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
526 $tpl->fillin('SCRIPT',$script);
528 my $output = header
(-type
=> 'text/html');
529 $output .= $tpl->get_template;
537 # Copy a file and return to directory view
539 # Params: 1. Reference to user input hash
540 # 2. Reference to config hash
542 # Return: Output of the command (Scalar Reference)
546 my ($data,$config) = @_;
547 my $physical = $data->{'physical'};
548 my $virtual = encode_entities
($data->{'virtual'});
549 my $dir = upper_path
($virtual);
550 my $new_physical = $data->{'new_physical'};
552 return error
($config->{'errors'}->{'dircopy'},$dir) if(-d
$physical);
553 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
557 my $new_virtual = $data->{'new_virtual'};
558 my $new_dir = upper_path
($new_virtual);
559 $new_virtual = encode_entities
($new_virtual);
563 return error
($config->{'errors'}->{'exist_edited'},$new_dir,{FILE
=> $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
564 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
565 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
567 if(not $data->{'cgi'}->param('confirmed'))
569 my $tpl = new Template
;
570 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
572 $tpl->fillin('FILE',$virtual);
573 $tpl->fillin('NEW_FILE',$new_virtual);
574 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
575 $tpl->fillin('NEW_DIR',$new_dir);
576 $tpl->fillin('DIR',$dir);
578 $tpl->fillin('COMMAND','copy');
579 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
580 $tpl->fillin('SCRIPT',$script);
582 my $output = header
(-type
=> 'text/html');
583 $output .= $tpl->get_template;
589 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
590 return devedit_reload
({command
=> 'show', file
=> $new_dir});
594 my $tpl = new Template
;
595 $tpl->read_file($config->{'templates'}->{'copyfile'});
597 $tpl->fillin('FILE',$virtual);
598 $tpl->fillin('DIR',$dir);
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;
611 # Rename/move a file and return to directory view
613 # Params: 1. Reference to user input hash
614 # 2. Reference to config hash
616 # Return: Output of the command (Scalar Reference)
620 my ($data,$config) = @_;
621 my $physical = $data->{'physical'};
622 my $virtual = $data->{'virtual'};
623 my $dir = upper_path
($virtual);
624 my $new_physical = $data->{'new_physical'};
626 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
627 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
628 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
632 my $new_virtual = $data->{'new_virtual'};
633 my $new_dir = upper_path
($new_virtual);
634 $new_virtual = encode_entities
($new_virtual);
638 return error
($config->{'errors'}->{'exist_edited'},$new_dir,{FILE
=> $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
639 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
640 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
642 if(not $data->{'cgi'}->param('confirmed'))
644 my $tpl = new Template
;
645 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
647 $tpl->fillin('FILE',$virtual);
648 $tpl->fillin('NEW_FILE',$new_virtual);
649 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
650 $tpl->fillin('NEW_DIR',$new_dir);
651 $tpl->fillin('DIR',$dir);
653 $tpl->fillin('COMMAND','rename');
654 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
655 $tpl->fillin('SCRIPT',$script);
657 my $output = header
(-type
=> 'text/html');
658 $output .= $tpl->get_template;
664 rename($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
665 return devedit_reload
({command
=> 'show', file
=> $new_dir});
669 my $tpl = new Template
;
670 $tpl->read_file($config->{'templates'}->{'renamefile'});
672 $tpl->fillin('FILE',$virtual);
673 $tpl->fillin('DIR',$dir);
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;
686 # Remove a file or a directory and return to directory view
688 # Params: 1. Reference to user input hash
689 # 2. Reference to config hash
691 # Return: Output of the command (Scalar Reference)
695 my ($data,$config) = @_;
696 my $physical = $data->{'physical'};
697 my $virtual = $data->{'virtual'};
698 my $dir = upper_path
($virtual);
700 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
701 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
707 if($data->{'cgi'}->param('confirmed'))
710 return devedit_reload
({command
=> 'show', file
=> $dir});
714 my $tpl = new Template
;
715 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
717 $tpl->fillin('DIR',$virtual);
718 $tpl->fillin('UPPER_DIR',$dir);
719 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
720 $tpl->fillin('SCRIPT',$script);
722 my $output = header
(-type
=> 'text/html');
723 $output .= $tpl->get_template;
732 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
734 if($data->{'cgi'}->param('confirmed'))
736 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
737 return devedit_reload
({command
=> 'show', file
=> $dir});
741 my $tpl = new Template
;
742 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
744 $tpl->fillin('FILE',$virtual);
745 $tpl->fillin('DIR',$dir);
746 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
747 $tpl->fillin('SCRIPT',$script);
749 my $output = header
(-type
=> 'text/html');
750 $output .= $tpl->get_template;
759 # Change the mode and the group of a file or a directory
761 # Params: 1. Reference to user input hash
762 # 2. Reference to config hash
764 # Return: Output of the command (Scalar Reference)
768 my ($data,$config) = @_;
769 my $physical = $data->{'physical'};
770 my $virtual = $data->{'virtual'};
771 my $dir = upper_path
($virtual);
773 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> $virtual}) unless($users);
774 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
775 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> $virtual}) unless(-o
$physical);
776 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
778 my $cgi = $data->{'cgi'};
779 my $mode = $cgi->param('mode');
780 my $group = $cgi->param('group');
788 chmod(oct($mode),$physical);
793 # Change the group using the `chgrp` system command
795 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_entities
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
796 system('chgrp',$group,$physical);
799 return devedit_reload
({command
=> 'show', file
=> $dir});
805 my @stat = stat($physical);
809 my $tpl = new Template
;
810 $tpl->read_file($config->{'templates'}->{'chprop'});
812 # Insert file properties into the template
814 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
815 $tpl->fillin('MODE_STRING',mode_string
($mode));
816 $tpl->fillin('GID',$gid);
818 if(my $group = getgrgid($gid))
820 $tpl->fillin('GROUP',encode_entities
($group));
821 $tpl->parse_if_block('group_detected',1);
825 $tpl->parse_if_block('group_detected',0);
828 # Insert other information
830 $tpl->fillin('FILE',$virtual);
831 $tpl->fillin('DIR',$dir);
832 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
833 $tpl->fillin('SCRIPT',$script);
835 my $output = header
(-type
=> 'text/html');
836 $output .= $tpl->get_template;
844 # Remove a file from the list of used files and
845 # return to directory view
847 # Params: 1. Reference to user input hash
848 # 2. Reference to config hash
850 # Return: Output of the command (Scalar Reference)
854 my ($data,$config) = @_;
855 my $virtual = $data->{'virtual'};
856 my $uselist = $data->{'uselist'};
857 my $dir = upper_path
($virtual);
859 return devedit_reload
({command
=> 'show', file
=> $dir}) if($uselist->unused($virtual));
861 if($data->{'cgi'}->param('confirmed'))
863 file_unlock
($uselist,$virtual);
864 return devedit_reload
({command
=> 'show', file
=> $dir});
868 my $tpl = new Template
;
869 $tpl->read_file($config->{'templates'}->{'confirm_unlock'});
871 $tpl->fillin('FILE',$virtual);
872 $tpl->fillin('DIR',$dir);
873 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
874 $tpl->fillin('SCRIPT',$script);
876 my $output = header
(-type
=> 'text/html');
877 $output .= $tpl->get_template;
885 # Display some information about Dev-Editor
887 # Params: 1. Reference to user input hash
888 # 2. Reference to config hash
890 # Return: Output of the command (Scalar Reference)
894 my ($data,$config) = @_;
896 my $tpl = new Template
;
897 $tpl->read_file($config->{'templates'}->{'about'});
899 $tpl->fillin('SCRIPT',$script);
901 # Dev-Editor's version number
903 $tpl->fillin('VERSION',$data->{'version'});
905 # Some path information
907 $tpl->fillin('SCRIPT_PHYS',encode_entities
($ENV{'SCRIPT_FILENAME'}));
908 $tpl->fillin('CONFIG_PATH',encode_entities
($data->{'configfile'}));
909 $tpl->fillin('FILE_ROOT', encode_entities
($config->{'fileroot'}));
910 $tpl->fillin('HTTP_ROOT', encode_entities
($config->{'httproot'}));
914 $tpl->fillin('PERL_PROG',encode_entities
($^X
));
915 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
917 # Information about the server
919 $tpl->fillin('HTTPD',encode_entities
($ENV{'SERVER_SOFTWARE'}));
920 $tpl->fillin('OS', encode_entities
($^O
));
921 $tpl->fillin('TIME', encode_entities
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime : localtime)));
923 $tpl->parse_if_block('gmt',$config->{'use_gmt'});
925 # Process information
927 $tpl->fillin('PID',$$);
929 # Check if the functions getpwuid() and getgrgid() are available
933 # Dev-Editor is running on a system which allows users and groups
934 # So we display the user and the group of our process
936 my $uid = POSIX
::getuid
;
937 my $gid = POSIX
::getgid
;
939 $tpl->parse_if_block('users',1);
941 # ID's of user and group
943 $tpl->fillin('UID',$uid);
944 $tpl->fillin('GID',$gid);
946 # Names of user and group
948 if(my $user = getpwuid($uid))
950 $tpl->fillin('USER',encode_entities
($user));
951 $tpl->parse_if_block('user_detected',1);
955 $tpl->parse_if_block('user_detected',0);
958 if(my $group = getgrgid($gid))
960 $tpl->fillin('GROUP',encode_entities
($group));
961 $tpl->parse_if_block('group_detected',1);
965 $tpl->parse_if_block('group_detected',0);
970 $tpl->fillin('UMASK',sprintf('%04o',umask));
974 $tpl->parse_if_block('users',0);
977 my $output = header
(-type
=> 'text/html');
978 $output .= $tpl->get_template;
983 # it's true, baby ;-)
patrick-canterino.de