]>
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-22
21 use Digest::MD5 qw(md5_hex);
22 use POSIX
qw(strftime);
31 my $script = encode_html
($ENV{'SCRIPT_NAME'});
32 my $users = eval('getpwuid(0)') && eval('getgrgid(0)');
34 my %dispatch = ('show' => \
&exec_show
,
35 'beginedit' => \
&exec_beginedit
,
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 'about' => \
&exec_about
49 use base
qw(Exporter);
51 @EXPORT = qw(exec_command);
55 # Execute the specified command
57 # Params: 1. Command to execute
58 # 2. Reference to user input hash
59 # 3. Reference to config hash
61 # Return: Output of the command (Scalar Reference)
65 my ($command,$data,$config) = @_;
67 foreach(keys(%dispatch))
69 if(lc($_) eq lc($command))
71 my $output = &{$dispatch{$_}}($data,$config);
76 return error
($config->{'errors'}->{'command_unknown'},'/',{COMMAND
=> encode_html
($command)});
81 # View a directory or a file
83 # Params: 1. Reference to user input hash
84 # 2. Reference to config hash
86 # Return: Output of the command (Scalar Reference)
90 my ($data,$config) = @_;
91 my $physical = $data->{'physical'};
92 my $virtual = $data->{'virtual'};
93 my $upper_path = multi_string
(upper_path
($virtual));
95 my $tpl = new Template
;
97 if(-d
$physical && not -l
$physical)
99 # Create directory listing
101 return error
($config->{'errors'}->{'no_dir_access'},$upper_path->{'normal'}) unless(-r
$physical && -x
$physical);
103 my $direntries = dir_read
($physical);
104 return error
($config->{'errors'}->{'dir_read_fail'},$upper_path->{'normal'},{DIR
=> encode_html
($virtual)}) unless($direntries);
106 my $files = $direntries->{'files'};
107 my $dirs = $direntries->{'dirs'};
111 my $filter1 = $data->{'cgi'}->param('filter') || '*'; # The real wildcard
112 my $filter2 = ($filter1 && $filter1 ne '*') ?
$filter1 : ''; # Wildcard for output
114 # Create the link to the upper directory
115 # (only if the current directory is not the root directory)
117 unless($virtual eq '/')
119 my @stat = stat($physical.'/..');
121 my $udtpl = new Template
;
122 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
124 $udtpl->fillin('UPPER_DIR',$upper_path->{'html'});
125 $udtpl->fillin('UPPER_DIR_URL',$upper_path->{'url'});
126 $udtpl->fillin('DATE',encode_html
(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 = multi_string
($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->{'html'});
146 $dtpl->fillin('DIR_URL',$virt_path->{'url'});
147 $dtpl->fillin('DIR_NAME',encode_html
($dir));
148 $dtpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
149 $dtpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
151 $dtpl->parse_if_block('readable',-r
$phys_path && -x
$phys_path);
152 $dtpl->parse_if_block('users',$users && -o
$phys_path);
154 $dirlist .= $dtpl->get_template;
159 foreach my $file(@
$files)
161 next unless(dos_wildcard_match
($filter1,$file));
163 my $phys_path = $physical.'/'.$file;
164 my $virt_path = multi_string
($virtual.$file);
166 my @stat = lstat($phys_path);
167 my $too_large = $config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'};
169 my $ftpl = new Template
;
170 $ftpl->read_file($config->{'templates'}->{'dirlist_file'});
172 $ftpl->fillin('FILE',$virt_path->{'html'});
173 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
174 $ftpl->fillin('FILE_NAME',encode_html
($file));
175 $ftpl->fillin('FILE_URL',$virt_path->{'url'});
176 $ftpl->fillin('SIZE',$stat[7]);
177 $ftpl->fillin('DATE',encode_html
(strftime
($config->{'timeformat'},($config->{'use_gmt'}) ?
gmtime($stat[9]) : localtime($stat[9]))));
178 $ftpl->fillin('URL',equal_url
(encode_html
($config->{'httproot'}),$virt_path->{'html'}));
180 $ftpl->parse_if_block('link',-l
$phys_path);
181 $ftpl->parse_if_block('no_link',not -l
$phys_path);
182 $ftpl->parse_if_block('not_readable',not -r
$phys_path);
183 $ftpl->parse_if_block('binary',-B
$phys_path);
184 $ftpl->parse_if_block('readonly',not -w
$phys_path);
186 $ftpl->parse_if_block('viewable',(-r
$phys_path && -T
$phys_path && not $too_large) || -l
$phys_path);
187 $ftpl->parse_if_block('editable',(-r
$phys_path && -w
$phys_path && -T
$phys_path && not $too_large) && not -l
$phys_path);
189 $ftpl->parse_if_block('too_large',$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
191 $ftpl->parse_if_block('users',$users && -o
$phys_path);
193 $dirlist .= $ftpl->get_template;
196 $tpl->read_file($config->{'templates'}->{'dirlist'});
198 $tpl->fillin('DIRLIST',$dirlist);
199 $tpl->fillin('DIR',encode_html
($virtual));
200 $tpl->fillin('DIR_URL',escape
($virtual));
201 $tpl->fillin('SCRIPT',$script);
202 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
204 $tpl->fillin('FILTER',encode_html
($filter2));
205 $tpl->fillin('FILTER_URL',escape
($filter2));
207 $tpl->parse_if_block('empty',$dirlist eq '');
208 $tpl->parse_if_block('dir_writeable',-w
$physical);
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_html
($virtual));
221 $tpl->fillin('DIR',$upper_path->{'html'});
222 $tpl->fillin('DIR_URL',$upper_path->{'url'});
223 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
224 $tpl->fillin('SCRIPT',$script);
226 $tpl->fillin('LINK_TARGET',encode_html
($link_target));
232 return error
($config->{'errors'}->{'no_view'},$upper_path->{'normal'}) unless(-r
$physical);
234 # Check on binary files
235 # We have to do it in this way or empty files will be recognized
238 return error
($config->{'errors'}->{'binary_file'},$upper_path->{'normal'}) unless(-T
$physical);
240 # Is the file too large?
242 return error
($config->{'errors'}->{'file_too_large'},$upper_path->{'normal'},{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
246 my $content = file_read
($physical);
247 $$content =~ s/\015\012|\012|\015/\n/g;
249 $tpl->read_file($config->{'templates'}->{'viewfile'});
251 $tpl->fillin('FILE',encode_html
($virtual));
252 $tpl->fillin('FILE_URL',escape
($virtual));
253 $tpl->fillin('DIR',$upper_path->{'html'});
254 $tpl->fillin('DIR_URL',$upper_path->{'url'});
255 $tpl->fillin('URL',encode_html
(equal_url
($config->{'httproot'},$virtual)));
256 $tpl->fillin('SCRIPT',$script);
258 $tpl->parse_if_block('editable',-w
$physical);
260 $tpl->fillin('CONTENT',encode_html
($$content));
263 my $output = header
(-type
=> 'text/html');
264 $output .= $tpl->get_template;
271 # Lock a file and display a form to edit it
273 # Params: 1. Reference to user input hash
274 # 2. Reference to config hash
276 # Return: Output of the command (Scalar Reference)
278 sub exec_beginedit
($$)
280 my ($data,$config) = @_;
281 my $physical = $data->{'physical'};
282 my $virtual = $data->{'virtual'};
283 my $dir = upper_path
($virtual);
284 my $cgi = $data->{'cgi'};
286 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
287 return error
($config->{'errors'}->{'dir_edit'}, $dir) if(-d
$physical);
288 return error
($config->{'errors'}->{'no_edit'}, $dir) unless(-r
$physical && -w
$physical);
290 # Check on binary files
292 return error
($config->{'errors'}->{'binary_file'},$dir) unless(-T
$physical);
294 # Is the file too large?
296 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
298 # ... and show the editing form
300 my $content = file_read
($physical);
301 my $md5sum = md5_hex
($$content);
302 $$content =~ s/\015\012|\012|\015/\n/g;
304 my $tpl = new Template
;
305 $tpl->read_file($config->{'templates'}->{'editfile'});
307 $tpl->fillin('FILE',encode_html
($virtual));
308 $tpl->fillin('FILE_URL',escape
($virtual));
309 $tpl->fillin('DIR',encode_html
($dir));
310 $tpl->fillin('DIR_URL',escape
($dir));
311 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
312 $tpl->fillin('SCRIPT',$script);
313 $tpl->fillin('MD5SUM',$md5sum);
314 $tpl->fillin('CONTENT',encode_html
($$content));
316 $tpl->parse_if_block('error',0);
318 my $output = header
(-type
=> 'text/html');
319 $output .= $tpl->get_template;
326 # Save a file, unlock it and return to directory view
328 # Params: 1. Reference to user input hash
329 # 2. Reference to config hash
331 # Return: Output of the command (Scalar Reference)
335 my ($data,$config) = @_;
336 my $physical = $data->{'physical'};
337 my $virtual = $data->{'virtual'};
338 my $dir = upper_path
($virtual);
339 my $cgi = $data->{'cgi'};
340 my $content = $cgi->param('filecontent');
341 my $md5sum = $cgi->param('md5sum');
344 if(defined $content && $md5sum)
348 $content =~ s/\015\012|\012|\015/\n/g;
350 if($cgi->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
352 # Create the new filename
354 $physical = $data->{'new_physical'};
355 $virtual = $data->{'new_virtual'};
358 return error
($config->{'errors'}->{'link_edit'},$dir) if(-l
$physical);
359 return error
($config->{'errors'}->{'dir_edit'},$dir) if(-d
$physical);
360 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
361 return error
($config->{'errors'}->{'text_to_binary'},$dir) if(-e
$physical && not -T
$physical);
363 # For technical reasons, we can't use file_save() for
368 sysopen(FILE
,$physical,O_RDWR
| O_CREAT
) or return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual});
369 file_lock
(*FILE
,LOCK_EX
) or do { close(FILE
); return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual}) };
371 my $md5 = new Digest
::MD5
;
372 $md5->addfile(*FILE
);
374 my $md5file = $md5->hexdigest;
375 my $md5data = md5_hex
($content);
377 if($md5file ne $md5sum && $md5data ne $md5file && not $cgi->param('saveas'))
379 # The file changed meanwhile
381 my $tpl = new Template
;
382 $tpl->read_file($config->{'templates'}->{'editfile'});
384 $tpl->fillin('ERROR',$config->{'errors'}->{'edit_file_changed'});
386 $tpl->fillin('FILE',encode_html
($virtual));
387 $tpl->fillin('FILE_URL',escape
($virtual));
388 $tpl->fillin('DIR',encode_html
($dir));
389 $tpl->fillin('DIR_URL',escape
($dir));
390 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
391 $tpl->fillin('SCRIPT',$script);
392 $tpl->fillin('MD5SUM',$md5file);
393 $tpl->fillin('CONTENT',encode_html
($content));
395 $tpl->parse_if_block('error',1);
397 my $data = header
(-type
=> 'text/html');
398 $data .= $tpl->get_template;
404 if($md5data ne $md5file)
412 $output = devedit_reload
({command
=> 'show', file
=> $dir});
420 return devedit_reload
({command
=> 'beginedit', file
=> $virtual});
425 # Create a file and return to directory view
427 # Params: 1. Reference to user input hash
428 # 2. Reference to config hash
430 # Return: Output of the command (Scalar Reference)
434 my ($data,$config) = @_;
435 my $new_physical = $data->{'new_physical'};
436 my $new_virtual = $data->{'new_virtual'};
437 my $dir = upper_path
($new_virtual);
438 $new_virtual = encode_html
($new_virtual);
442 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
444 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
445 return devedit_reload
({command
=> 'show', file
=> $dir});
449 my $tpl = new Template
;
450 $tpl->read_file($config->{'templates'}->{'mkfile'});
452 $tpl->fillin('DIR','/');
453 $tpl->fillin('SCRIPT',$script);
455 my $output = header
(-type
=> 'text/html');
456 $output .= $tpl->get_template;
464 # Create a directory and return to directory view
466 # Params: 1. Reference to user input hash
467 # 2. Reference to config hash
469 # Return: Output of the command (Scalar Reference)
473 my ($data,$config) = @_;
474 my $new_physical = $data->{'new_physical'};
475 my $new_virtual = $data->{'new_virtual'};
476 my $dir = upper_path
($new_virtual);
477 $new_virtual = encode_html
($new_virtual);
481 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
483 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
484 return devedit_reload
({command
=> 'show', file
=> $dir});
488 my $tpl = new Template
;
489 $tpl->read_file($config->{'templates'}->{'mkdir'});
491 $tpl->fillin('DIR','/');
492 $tpl->fillin('SCRIPT',$script);
494 my $output = header
(-type
=> 'text/html');
495 $output .= $tpl->get_template;
503 # Process a file upload
505 # Params: 1. Reference to user input hash
506 # 2. Reference to config hash
508 # Return: Output of the command (Scalar Reference)
512 my ($data,$config) = @_;
513 my $physical = $data->{'physical'};
514 my $virtual = $data->{'virtual'};
515 my $cgi = $data->{'cgi'};
517 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> $virtual}) unless(-d
$physical && not -l
$physical);
518 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> $virtual}) unless(-w
$physical);
520 if(my $uploaded_file = $cgi->param('uploaded_file'))
522 # Process file upload
524 my $filename = file_name
($uploaded_file);
525 my $file_phys = $physical.'/'.$filename;
526 my $file_virt = encode_html
($virtual.$filename);
530 return error
($config->{'errors'}->{'link_replace'},$virtual) if(-l
$file_phys);
531 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
532 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
533 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
536 my $ascii = $cgi->param('ascii');
537 my $handle = $cgi->upload('uploaded_file');
539 return error
($config->{'errors'}->{'invalid_upload'},$virtual) unless($handle);
541 # Read transferred file and write it to disk
543 read($handle, my $data, -s
$handle);
544 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
545 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
547 return devedit_reload
({command
=> 'show', file
=> $virtual});
551 my $tpl = new Template
;
552 $tpl->read_file($config->{'templates'}->{'upload'});
554 $tpl->fillin('DIR',encode_html
($virtual));
555 $tpl->fillin('DIR_URL',escape
($virtual));
556 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
557 $tpl->fillin('SCRIPT',$script);
559 my $output = header
(-type
=> 'text/html');
560 $output .= $tpl->get_template;
568 # Copy a file and return to directory view
570 # Params: 1. Reference to user input hash
571 # 2. Reference to config hash
573 # Return: Output of the command (Scalar Reference)
577 my ($data,$config) = @_;
578 my $physical = $data->{'physical'};
579 my $virtual = $data->{'virtual'};
580 my $dir = upper_path
($virtual);
581 my $new_physical = $data->{'new_physical'};
583 return error
($config->{'errors'}->{'link_copy'},$dir) if(-l
$physical);
584 return error
($config->{'errors'}->{'dir_copy'},$dir) if(-d
$physical);
585 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
589 my $new_virtual = multi_string
($data->{'new_virtual'});
590 my $new_dir = upper_path
($new_virtual->{'normal'});
594 return error
($config->{'errors'}->{'link_replace'},$new_dir) if(-l
$new_physical);
595 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
596 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual->{'html'}}) unless(-w
$new_physical);
598 if(not $data->{'cgi'}->param('confirmed'))
600 my $tpl = new Template
;
601 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
603 $tpl->fillin('FILE',encode_html
($virtual));
604 $tpl->fillin('NEW_FILE',$new_virtual->{'html'});
605 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual->{'html'}));
606 $tpl->fillin('NEW_DIR',encode_html
($new_dir));
607 $tpl->fillin('DIR',encode_html
($dir));
608 $tpl->fillin('DIR_URL',escape
($dir));
610 $tpl->fillin('COMMAND','copy');
611 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
612 $tpl->fillin('SCRIPT',$script);
614 my $output = header
(-type
=> 'text/html');
615 $output .= $tpl->get_template;
621 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
622 return devedit_reload
({command
=> 'show', file
=> $new_dir});
626 my $tpl = new Template
;
627 $tpl->read_file($config->{'templates'}->{'copyfile'});
629 $tpl->fillin('FILE',encode_html
($virtual));
630 $tpl->fillin('DIR',encode_html
($dir));
631 $tpl->fillin('DIR_URL',escape
($dir));
632 $tpl->fillin('URL',equal_url
($config->{'httproot'},encode_html
($virtual)));
633 $tpl->fillin('SCRIPT',$script);
635 my $output = header
(-type
=> 'text/html');
636 $output .= $tpl->get_template;
644 # Rename/move a file and return to directory view
646 # Params: 1. Reference to user input hash
647 # 2. Reference to config hash
649 # Return: Output of the command (Scalar Reference)
653 my ($data,$config) = @_;
654 my $physical = $data->{'physical'};
655 my $virtual = $data->{'virtual'};
656 my $dir = upper_path
($virtual);
657 my $new_physical = $data->{'new_physical'};
659 return error
($config->{'errors'}->{'rename_root'},'/') if($virtual eq '/');
660 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
664 my $new_virtual = $data->{'new_virtual'};
665 my $new_dir = upper_path
($new_virtual);
666 $new_virtual = encode_html
($new_virtual);
670 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical && not -l
$new_physical);
671 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
673 if(not $data->{'cgi'}->param('confirmed'))
675 my $tpl = new Template
;
676 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
678 $tpl->fillin('FILE',$virtual);
679 $tpl->fillin('NEW_FILE',$new_virtual);
680 $tpl->fillin('NEW_FILENAME',file_name
($new_virtual));
681 $tpl->fillin('NEW_DIR',$new_dir);
682 $tpl->fillin('DIR',$dir);
684 $tpl->fillin('COMMAND','rename');
685 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
686 $tpl->fillin('SCRIPT',$script);
688 my $output = header
(-type
=> 'text/html');
689 $output .= $tpl->get_template;
695 move
($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
696 return devedit_reload
({command
=> 'show', file
=> $new_dir});
700 my $tpl = new Template
;
701 $tpl->read_file($config->{'templates'}->{'renamefile'});
703 $tpl->fillin('FILE',$virtual);
704 $tpl->fillin('DIR',encode_html
($dir));
705 $tpl->fillin('DIR_URL',escape
($dir));
706 $tpl->fillin('URL',equal_url
($config->{'httproot'},$virtual));
707 $tpl->fillin('SCRIPT',$script);
709 my $output = header
(-type
=> 'text/html');
710 $output .= $tpl->get_template;
718 # Remove a file or a directory and return to directory view
720 # Params: 1. Reference to user input hash
721 # 2. Reference to config hash
723 # Return: Output of the command (Scalar Reference)
727 my ($data,$config) = @_;
728 my $physical = $data->{'physical'};
729 my $virtual = $data->{'virtual'};
730 my $dir = upper_path
($virtual);
732 return error
($config->{'errors'}->{'remove_root'},'/') if($virtual eq '/');
733 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
735 if(-d
$physical && not -l
$physical)
739 if($data->{'cgi'}->param('confirmed'))
742 return devedit_reload
({command
=> 'show', file
=> $dir});
746 my $tpl = new Template
;
747 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
749 $tpl->fillin('DIR',encode_html
($virtual));
750 $tpl->fillin('DIR_URL',escape
($virtual));
751 $tpl->fillin('UPPER_DIR',encode_html
($dir));
752 $tpl->fillin('UPPER_DIR_URL',escape
($dir));
753 $tpl->fillin('URL',equal_url
($config->{'httproot'},encode_html
($virtual)));
754 $tpl->fillin('SCRIPT',$script);
756 my $output = header
(-type
=> 'text/html');
757 $output .= $tpl->get_template;
766 if($data->{'cgi'}->param('confirmed'))
768 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
769 return devedit_reload
({command
=> 'show', file
=> $dir});
773 my $tpl = new Template
;
774 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
776 $tpl->fillin('FILE',encode_html
($virtual));
777 $tpl->fillin('FILE_URL',escape
($virtual));
778 $tpl->fillin('DIR',encode_html
($dir));
779 $tpl->fillin('DIR_URL',escape
($dir));
780 $tpl->fillin('URL',equal_url
($config->{'httproot'},encode_html
($virtual)));
781 $tpl->fillin('SCRIPT',$script);
783 my $output = header
(-type
=> 'text/html');
784 $output .= $tpl->get_template;
793 # Change the mode and the group of a file or a directory
795 # Params: 1. Reference to user input hash
796 # 2. Reference to config hash
798 # Return: Output of the command (Scalar Reference)
802 my ($data,$config) = @_;
803 my $physical = $data->{'physical'};
804 my $virtual = $data->{'virtual'};
805 my $dir = upper_path
($virtual);
807 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> encode_html
($virtual)}) unless($users);
808 return error
($config->{'errors'}->{'chprop_root'},'/') if($virtual eq '/');
809 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> encode_html
($virtual)}) unless(-o
$physical);
810 return error
($config->{'errors'}->{'chprop_link'},$dir) if(-l
$physical);
812 my $cgi = $data->{'cgi'};
813 my $mode = $cgi->param('mode');
814 my $group = $cgi->param('group');
822 chmod(oct($mode),$physical);
827 # Change the group using the `chgrp` system command
829 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_html
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
830 system('chgrp',$group,$physical);
833 return devedit_reload
({command
=> 'show', file
=> $dir});
839 my @stat = stat($physical);
843 my $tpl = new Template
;
844 $tpl->read_file($config->{'templates'}->{'chprop'});
846 # Insert file properties into the template
848 $tpl->fillin('MODE_OCTAL',substr(sprintf('%04o',$mode),-4));
849 $tpl->fillin('MODE_STRING',mode_string
($mode));
850 $tpl->fillin('GID',$gid);
852 if(my $group = getgrgid($gid))
854 $tpl->fillin('GROUP',encode_html
($group));
855 $tpl->parse_if_block('group_detected',1);
859 $tpl->parse_if_block('group_detected',0);
862 # Insert other information
864 $tpl->fillin('FILE',encode_html
($virtual));
865 $tpl->fillin('FILE_URL',escape
($virtual));
866 $tpl->fillin('DIR',encode_html
($dir));
867 $tpl->fillin('DIR_URL',escape
($dir));
868 $tpl->fillin('URL',equal_url
($config->{'httproot'},encode_html
($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_html
($ENV{'SCRIPT_FILENAME'}));
903 $tpl->fillin('CONFIG_PATH',encode_html
($data->{'configfile'}));
904 $tpl->fillin('FILE_ROOT', encode_html
($config->{'fileroot'}));
905 $tpl->fillin('HTTP_ROOT', encode_html
($config->{'httproot'}));
909 $tpl->fillin('PERL_PROG',encode_html
($^X
));
910 $tpl->fillin('PERL_VER', sprintf('%vd',$^V
));
912 # Information about the server
914 $tpl->fillin('HTTPD',encode_html
($ENV{'SERVER_SOFTWARE'}));
915 $tpl->fillin('OS', encode_html
($^O
));
916 $tpl->fillin('TIME', encode_html
(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 # The following information is only available on systems supporting
929 # Dev-Editor is running on a system which allows users and groups
930 # So we display the user and the group of our process
932 my $uid = POSIX
::getuid
;
933 my $gid = POSIX
::getgid
;
935 $tpl->parse_if_block('users',1);
937 # ID's of user and group
939 $tpl->fillin('UID',$uid);
940 $tpl->fillin('GID',$gid);
942 # Names of user and group
944 if(my $user = getpwuid($uid))
946 $tpl->fillin('USER',encode_html
($user));
947 $tpl->parse_if_block('user_detected',1);
951 $tpl->parse_if_block('user_detected',0);
954 if(my $group = getgrgid($gid))
956 $tpl->fillin('GROUP',encode_html
($group));
957 $tpl->parse_if_block('group_detected',1);
961 $tpl->parse_if_block('group_detected',0);
966 $tpl->fillin('UMASK',sprintf('%04o',umask));
970 $tpl->parse_if_block('users',0);
973 my $output = header
(-type
=> 'text/html');
974 $output .= $tpl->get_template;
979 # it's true, baby ;-)
patrick-canterino.de