]>
git.p6c8.net - devedit.git/blob - modules/Command.pm
0b39533af424012dd0f4ac1bb23d8f580cac65c4
4 # Dev-Editor - Module Command
6 # Execute Dev-Editor's commands
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2004-12-28
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 $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'},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'},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);
215 return error
($config->{'errors'}->{'no_view'},$upper_path) unless(-r
$physical);
217 # Check on binary files
218 # We have to do it in this way or empty files will be recognized
221 return error
($config->{'errors'}->{'binary'},$upper_path) unless(-T
$physical);
223 # Is the file too large?
225 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'});
229 my $content = file_read
($physical);
230 $$content =~ s/\015\012|\012|\015/\n/g;
232 $tpl->read_file($config->{'templates'}->{'viewfile'});
234 $tpl->fillin("FILE",encode_entities
($virtual));
235 $tpl->fillin("DIR",$upper_path);
236 $tpl->fillin("URL",encode_entities
(equal_url
($config->{'httproot'},$virtual)));
237 $tpl->fillin("SCRIPT",$script);
239 $tpl->parse_if_block("editable",-w
$physical && $uselist->unused($virtual));
241 $tpl->fillin("CONTENT",encode_entities
($$content));
244 my $output = header
(-type
=> "text/html");
245 $output .= $tpl->get_template;
252 # Lock a file and display a form to edit it
254 # Params: 1. Reference to user input hash
255 # 2. Reference to config hash
257 # Return: Output of the command (Scalar Reference)
259 sub exec_beginedit
($$)
261 my ($data,$config) = @_;
262 my $physical = $data->{'physical'};
263 my $virtual = $data->{'virtual'};
264 my $dir = upper_path
($virtual);
265 my $uselist = $data->{'uselist'};
267 return error
($config->{'errors'}->{'editdir'},$dir) if(-d
$physical);
268 return error
($config->{'errors'}->{'in_use'}, $dir,{FILE
=> $virtual}) if($uselist->in_use($virtual));
269 return error
($config->{'errors'}->{'no_edit'},$dir) unless(-r
$physical && -w
$physical);
271 # Check on binary files
273 return error
($config->{'errors'}->{'binary'},$dir) unless(-T
$physical);
275 # Is the file too large?
277 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}}) if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'});
281 $uselist->add_file($virtual);
284 # ... and show the editing form
286 my $content = file_read
($physical);
287 $$content =~ s/\015\012|\012|\015/\n/g;
289 my $tpl = new Template
;
290 $tpl->read_file($config->{'templates'}->{'editfile'});
292 $tpl->fillin("FILE",$virtual);
293 $tpl->fillin("DIR",$dir);
294 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
295 $tpl->fillin("SCRIPT",$script);
296 $tpl->fillin("CONTENT",encode_entities
($$content));
298 my $output = header
(-type
=> "text/html");
299 $output .= $tpl->get_template;
308 # Params: 1. Reference to user input hash
309 # 2. Reference to config hash
311 # Return: Output of the command (Scalar Reference)
313 sub exec_canceledit
($$)
315 my ($data,$config) = @_;
316 my $virtual = $data->{'virtual'};
318 file_unlock
($data->{'uselist'},$virtual);
319 return devedit_reload
({command
=> 'show', file
=> upper_path
($virtual)});
324 # Save a file, unlock it and return to directory view
326 # Params: 1. Reference to user input hash
327 # 2. Reference to config hash
329 # Return: Output of the command (Scalar Reference)
333 my ($data,$config) = @_;
334 my $physical = $data->{'physical'};
335 my $virtual = $data->{'virtual'};
336 my $dir = upper_path
($virtual);
337 my $content = $data->{'cgi'}->param('filecontent');
338 my $uselist = $data->{'uselist'};
340 # We already unlock the file at the beginning of the subroutine,
341 # because if we have to abort this routine, the file keeps locked.
342 # No other user of Dev-Editor will access the file during this
343 # routine because of the concept of File::UseList.
345 file_unlock
($uselist,$virtual);
349 $content =~ s/\015\012|\012|\015/\n/g;
351 if($data->{'cgi'}->param('encode_iso'))
353 # Encode all ISO-8859-1 special chars
355 $content = encode_entities
($content,"\200-\377");
358 if($data->{'cgi'}->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
360 # Create the new filename
362 $physical = $data->{'new_physical'};
363 $virtual = $data->{'new_virtual'};
365 # Check if someone else is editing the new file
367 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($uselist->in_use($virtual));
370 return error
($config->{'errors'}->{'editdir'},$dir) if(-d
$physical);
371 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
372 return error
($config->{'errors'}->{'text_to_binary'},$dir) unless(-T
$physical);
374 if(file_save
($physical,\
$content))
376 # Saving of the file was successful!
378 return devedit_reload
({command
=> 'show', file
=> $dir});
382 return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual});
388 # Create a file and return to directory view
390 # Params: 1. Reference to user input hash
391 # 2. Reference to config hash
393 # Return: Output of the command (Scalar Reference)
397 my ($data,$config) = @_;
398 my $new_physical = $data->{'new_physical'};
399 my $new_virtual = $data->{'new_virtual'};
400 my $dir = upper_path
($new_virtual);
401 $new_virtual = encode_entities
($new_virtual);
405 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
407 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
408 return devedit_reload
({command
=> 'show', file
=> $dir});
412 my $tpl = new Template
;
413 $tpl->read_file($config->{'templates'}->{'mkfile'});
415 $tpl->fillin("DIR","/");
416 $tpl->fillin("SCRIPT",$script);
418 my $output = header
(-type
=> "text/html");
419 $output .= $tpl->get_template;
427 # Create a directory and return to directory view
429 # Params: 1. Reference to user input hash
430 # 2. Reference to config hash
432 # Return: Output of the command (Scalar Reference)
436 my ($data,$config) = @_;
437 my $new_physical = $data->{'new_physical'};
438 my $new_virtual = $data->{'new_virtual'};
439 my $dir = upper_path
($new_virtual);
440 $new_virtual = encode_entities
($new_virtual);
442 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
446 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
447 return devedit_reload
({command
=> 'show', file
=> $dir});
451 my $tpl = new Template
;
452 $tpl->read_file($config->{'templates'}->{'mkdir'});
454 $tpl->fillin("DIR","/");
455 $tpl->fillin("SCRIPT",$script);
457 my $output = header
(-type
=> "text/html");
458 $output .= $tpl->get_template;
468 # Params: 1. Reference to user input hash
469 # 2. Reference to config hash
471 # Return: Output of the command (Scalar Reference)
475 my ($data,$config) = @_;
476 my $physical = $data->{'physical'};
477 my $virtual = $data->{'virtual'};
478 my $cgi = $data->{'cgi'};
480 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> $virtual}) unless(-d
$physical);
481 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> $virtual}) unless(-w
$physical);
483 if(my $uploaded_file = $cgi->param('uploaded_file'))
485 # Process file upload
487 my $filename = file_name
($uploaded_file);
488 my $file_phys = $physical."/".$filename;
489 my $file_virt = $virtual.$filename;
491 return error
($config->{'errors'}->{'in_use'},$virtual,{FILE
=> $file_virt}) if($data->{'uselist'}->in_use($file_virt));
495 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
496 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
497 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
500 my $ascii = $cgi->param('ascii');
501 my $handle = $cgi->upload('uploaded_file');
503 # Read transferred file and write it to disk
505 read($handle, my $data, -s
$handle);
506 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
507 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
509 return devedit_reload
({command
=> "show", file
=> $virtual});
513 my $tpl = new Template
;
514 $tpl->read_file($config->{'templates'}->{'upload'});
516 $tpl->fillin("DIR",$virtual);
517 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
518 $tpl->fillin("SCRIPT",$script);
520 my $output = header
(-type
=> "text/html");
521 $output .= $tpl->get_template;
529 # Copy a file and return to directory view
531 # Params: 1. Reference to user input hash
532 # 2. Reference to config hash
534 # Return: Output of the command (Scalar Reference)
538 my ($data,$config) = @_;
539 my $physical = $data->{'physical'};
540 my $virtual = encode_entities
($data->{'virtual'});
541 my $dir = upper_path
($virtual);
542 my $new_physical = $data->{'new_physical'};
544 return error
($config->{'errors'}->{'dircopy'},$dir) if(-d
$physical);
545 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
549 my $new_virtual = $data->{'new_virtual'};
550 my $new_dir = upper_path
($new_virtual);
551 $new_virtual = encode_entities
($new_virtual);
555 return error
($config->{'errors'}->{'exist_edited'},$new_dir,{FILE
=> $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
556 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
557 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
559 if(not $data->{'cgi'}->param('confirmed'))
561 my $tpl = new Template
;
562 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
564 $tpl->fillin("FILE",$virtual);
565 $tpl->fillin("NEW_FILE",$new_virtual);
566 $tpl->fillin("NEW_FILENAME",file_name
($new_virtual));
567 $tpl->fillin("NEW_DIR",$new_dir);
568 $tpl->fillin("DIR",$dir);
570 $tpl->fillin("COMMAND","copy");
571 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
572 $tpl->fillin("SCRIPT",$script);
574 my $output = header
(-type
=> "text/html");
575 $output .= $tpl->get_template;
581 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
582 return devedit_reload
({command
=> 'show', file
=> $new_dir});
586 my $tpl = new Template
;
587 $tpl->read_file($config->{'templates'}->{'copyfile'});
589 $tpl->fillin("FILE",$virtual);
590 $tpl->fillin("DIR",$dir);
591 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
592 $tpl->fillin("SCRIPT",$script);
594 my $output = header
(-type
=> "text/html");
595 $output .= $tpl->get_template;
603 # Rename/move a file and return to directory view
605 # Params: 1. Reference to user input hash
606 # 2. Reference to config hash
608 # Return: Output of the command (Scalar Reference)
612 my ($data,$config) = @_;
613 my $physical = $data->{'physical'};
614 my $virtual = $data->{'virtual'};
615 my $dir = upper_path
($virtual);
616 my $new_physical = $data->{'new_physical'};
618 return error
($config->{'errors'}->{'rename_root'},"/") if($virtual eq "/");
619 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
620 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
624 my $new_virtual = $data->{'new_virtual'};
625 my $new_dir = upper_path
($new_virtual);
626 $new_virtual = encode_entities
($new_virtual);
630 return error
($config->{'errors'}->{'exist_edited'},$new_dir,{FILE
=> $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
631 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
632 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
634 if(not $data->{'cgi'}->param('confirmed'))
636 my $tpl = new Template
;
637 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
639 $tpl->fillin("FILE",$virtual);
640 $tpl->fillin("NEW_FILE",$new_virtual);
641 $tpl->fillin("NEW_FILENAME",file_name
($new_virtual));
642 $tpl->fillin("NEW_DIR",$new_dir);
643 $tpl->fillin("DIR",$dir);
645 $tpl->fillin("COMMAND","rename");
646 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
647 $tpl->fillin("SCRIPT",$script);
649 my $output = header
(-type
=> "text/html");
650 $output .= $tpl->get_template;
656 rename($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
657 return devedit_reload
({command
=> 'show', file
=> $new_dir});
661 my $tpl = new Template
;
662 $tpl->read_file($config->{'templates'}->{'renamefile'});
664 $tpl->fillin("FILE",$virtual);
665 $tpl->fillin("DIR",$dir);
666 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
667 $tpl->fillin("SCRIPT",$script);
669 my $output = header
(-type
=> "text/html");
670 $output .= $tpl->get_template;
678 # Remove a file or a directory and return to directory view
680 # Params: 1. Reference to user input hash
681 # 2. Reference to config hash
683 # Return: Output of the command (Scalar Reference)
687 my ($data,$config) = @_;
688 my $physical = $data->{'physical'};
689 my $virtual = $data->{'virtual'};
690 my $dir = upper_path
($virtual);
692 return error
($config->{'errors'}->{'remove_root'},"/") if($virtual eq "/");
693 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
699 if($data->{'cgi'}->param('confirmed'))
702 return devedit_reload
({command
=> 'show', file
=> $dir});
706 my $tpl = new Template
;
707 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
709 $tpl->fillin("DIR",$virtual);
710 $tpl->fillin("UPPER_DIR",$dir);
711 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
712 $tpl->fillin("SCRIPT",$script);
714 my $output = header
(-type
=> "text/html");
715 $output .= $tpl->get_template;
724 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
726 if($data->{'cgi'}->param('confirmed'))
728 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
729 return devedit_reload
({command
=> 'show', file
=> $dir});
733 my $tpl = new Template
;
734 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
736 $tpl->fillin("FILE",$virtual);
737 $tpl->fillin("DIR",$dir);
738 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
739 $tpl->fillin("SCRIPT",$script);
741 my $output = header
(-type
=> "text/html");
742 $output .= $tpl->get_template;
751 # Change the mode and the group of a file or a directory
753 # Params: 1. Reference to user input hash
754 # 2. Reference to config hash
756 # Return: Output of the command (Scalar Reference)
760 my ($data,$config) = @_;
761 my $physical = $data->{'physical'};
762 my $virtual = $data->{'virtual'};
763 my $dir = upper_path
($virtual);
765 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> $virtual}) unless($users);
766 return error
($config->{'errors'}->{'chprop_root'},"/") if($virtual eq "/");
767 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> $virtual}) unless(-o
$physical);
768 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
770 my $cgi = $data->{'cgi'};
771 my $mode = $cgi->param('mode');
772 my $group = $cgi->param('group');
780 chmod(oct($mode),$physical);
785 # Change the group using the `chgrp` system command
787 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_entities
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
788 system("chgrp",$group,$physical);
791 return devedit_reload
({command
=> 'show', file
=> $dir});
797 my @stat = stat($physical);
801 my $tpl = new Template
;
802 $tpl->read_file($config->{'templates'}->{'chprop'});
804 # Insert file properties into the template
806 $tpl->fillin("MODE_OCTAL",substr(sprintf("%04o",$mode),-4));
807 $tpl->fillin("MODE_STRING",mode_string
($mode));
808 $tpl->fillin("GID",$gid);
810 if(my $group = getgrgid($gid))
812 $tpl->fillin("GROUP",encode_entities
($group));
813 $tpl->parse_if_block("group_detected",1);
817 $tpl->parse_if_block("group_detected",0);
820 # Insert other information
822 $tpl->fillin("FILE",$virtual);
823 $tpl->fillin("DIR",$dir);
824 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
825 $tpl->fillin("SCRIPT",$script);
827 my $output = header
(-type
=> "text/html");
828 $output .= $tpl->get_template;
836 # Remove a file from the list of used files and
837 # return to directory view
839 # Params: 1. Reference to user input hash
840 # 2. Reference to config hash
842 # Return: Output of the command (Scalar Reference)
846 my ($data,$config) = @_;
847 my $virtual = $data->{'virtual'};
848 my $uselist = $data->{'uselist'};
849 my $dir = upper_path
($virtual);
851 return devedit_reload
({command
=> 'show', file
=> $dir}) if($uselist->unused($virtual));
853 if($data->{'cgi'}->param('confirmed'))
855 file_unlock
($uselist,$virtual);
856 return devedit_reload
({command
=> 'show', file
=> $dir});
860 my $tpl = new Template
;
861 $tpl->read_file($config->{'templates'}->{'confirm_unlock'});
863 $tpl->fillin("FILE",$virtual);
864 $tpl->fillin("DIR",$dir);
865 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
866 $tpl->fillin("SCRIPT",$script);
868 my $output = header
(-type
=> "text/html");
869 $output .= $tpl->get_template;
877 # Display some information about Dev-Editor
879 # Params: 1. Reference to user input hash
880 # 2. Reference to config hash
882 # Return: Output of the command (Scalar Reference)
886 my ($data,$config) = @_;
888 my $tpl = new Template
;
889 $tpl->read_file($config->{'templates'}->{'about'});
891 $tpl->fillin("SCRIPT",$script);
893 # Dev-Editor's version number
895 $tpl->fillin("VERSION",$data->{'version'});
897 # Some path information
899 $tpl->fillin("SCRIPT_PHYS",encode_entities
($ENV{'SCRIPT_FILENAME'}));
900 $tpl->fillin("CONFIG_PATH",encode_entities
($data->{'configfile'}));
901 $tpl->fillin("FILE_ROOT", encode_entities
($config->{'fileroot'}));
902 $tpl->fillin("HTTP_ROOT", encode_entities
($config->{'httproot'}));
906 $tpl->fillin("PERL_PROG",encode_entities
($^X
));
907 $tpl->fillin("PERL_VER", sprintf("%vd",$^V
));
909 # Information about the server
911 $tpl->fillin("HTTPD",encode_entities
($ENV{'SERVER_SOFTWARE'}));
912 $tpl->fillin("OS", encode_entities
($^O
));
913 $tpl->fillin("TIME", encode_entities
(strftime
($config->{'timeformat'},localtime)));
915 # Process information
917 $tpl->fillin("PID",$$);
919 # Check if the functions getpwuid() and getgrgid() are available
923 # Dev-Editor is running on a system which allows users and groups
924 # So we display the user and the group of our process
926 my $uid = POSIX
::getuid
;
927 my $gid = POSIX
::getgid
;
929 $tpl->parse_if_block("users",1);
931 # ID's of user and group
933 $tpl->fillin("UID",$uid);
934 $tpl->fillin("GID",$gid);
936 # Names of user and group
938 if(my $user = getpwuid($uid))
940 $tpl->fillin("USER",encode_entities
($user));
941 $tpl->parse_if_block("user_detected",1);
945 $tpl->parse_if_block("user_detected",0);
948 if(my $group = getgrgid($gid))
950 $tpl->fillin("GROUP",encode_entities
($group));
951 $tpl->parse_if_block("group_detected",1);
955 $tpl->parse_if_block("group_detected",0);
960 $tpl->fillin("UMASK",sprintf("%04o",umask));
964 $tpl->parse_if_block("users",0);
967 my $output = header
(-type
=> "text/html");
968 $output .= $tpl->get_template;
973 # it's true, baby ;-)
patrick-canterino.de