]>
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: 2004-12-26
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
219 # will be recognized as binary files
225 return error
($config->{'errors'}->{'binary'},$upper_path);
231 if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'})
233 return error
($config->{'errors'}->{'file_too_large'},$upper_path,{SIZE
=> $config->{'max_file_size'}})
237 my $content = file_read
($physical);
238 $$content =~ s/\015\012|\012|\015/\n/g;
240 $tpl->read_file($config->{'templates'}->{'viewfile'});
242 $tpl->fillin("FILE",encode_entities
($virtual));
243 $tpl->fillin("DIR",$upper_path);
244 $tpl->fillin("URL",encode_entities
(equal_url
($config->{'httproot'},$virtual)));
245 $tpl->fillin("SCRIPT",$script);
247 $tpl->parse_if_block("editable",-w
$physical && $uselist->unused($virtual));
249 $tpl->fillin("CONTENT",encode_entities
($$content));
254 my $output = header
(-type
=> "text/html");
255 $output .= $tpl->get_template;
262 # Lock a file and display a form to edit it
264 # Params: 1. Reference to user input hash
265 # 2. Reference to config hash
267 # Return: Output of the command (Scalar Reference)
269 sub exec_beginedit
($$)
271 my ($data,$config) = @_;
272 my $physical = $data->{'physical'};
273 my $virtual = $data->{'virtual'};
274 my $dir = upper_path
($virtual);
275 my $uselist = $data->{'uselist'};
277 return error
($config->{'errors'}->{'editdir'},$dir) if(-d
$physical);
278 return error
($config->{'errors'}->{'in_use'}, $dir,{FILE
=> $virtual}) if($uselist->in_use($virtual));
279 return error
($config->{'errors'}->{'no_edit'},$dir) unless(-r
$physical && -w
$physical);
281 # Check on binary files
287 return error
($config->{'errors'}->{'binary'},$dir);
291 if($config->{'max_file_size'} && -s
$physical > $config->{'max_file_size'})
293 return error
($config->{'errors'}->{'file_too_large'},$dir,{SIZE
=> $config->{'max_file_size'}})
299 $uselist->add_file($virtual);
302 my $content = file_read
($physical);
303 $$content =~ s/\015\012|\012|\015/\n/g;
305 my $tpl = new Template
;
306 $tpl->read_file($config->{'templates'}->{'editfile'});
308 $tpl->fillin("FILE",$virtual);
309 $tpl->fillin("DIR",$dir);
310 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
311 $tpl->fillin("SCRIPT",$script);
312 $tpl->fillin("CONTENT",encode_entities
($$content));
314 my $output = header
(-type
=> "text/html");
315 $output .= $tpl->get_template;
326 # Params: 1. Reference to user input hash
327 # 2. Reference to config hash
329 # Return: Output of the command (Scalar Reference)
331 sub exec_canceledit
($$)
333 my ($data,$config) = @_;
334 my $virtual = $data->{'virtual'};
336 file_unlock
($data->{'uselist'},$virtual);
337 return devedit_reload
({command
=> 'show', file
=> upper_path
($virtual)});
342 # Save a file, unlock it and return to directory view
344 # Params: 1. Reference to user input hash
345 # 2. Reference to config hash
347 # Return: Output of the command (Scalar Reference)
351 my ($data,$config) = @_;
352 my $physical = $data->{'physical'};
353 my $virtual = $data->{'virtual'};
354 my $dir = upper_path
($virtual);
355 my $content = $data->{'cgi'}->param('filecontent');
356 my $uselist = $data->{'uselist'};
358 # We already unlock the file at the beginning of the subroutine,
359 # because if we have to abort this routine, the file keeps locked.
360 # No other user of Dev-Editor will access the file during this
361 # routine because of the concept of File::UseList.
363 file_unlock
($uselist,$virtual);
367 $content =~ s/\015\012|\012|\015/\n/g;
369 if($data->{'cgi'}->param('encode_iso'))
371 # Encode all ISO-8859-1 special chars
373 $content = encode_entities
($content,"\200-\377");
376 if($data->{'cgi'}->param('saveas') && $data->{'new_physical'} ne '' && $data->{'new_virtual'} ne '')
378 # Create the new filename
380 $physical = $data->{'new_physical'};
381 $virtual = $data->{'new_virtual'};
383 # Check if someone else is editing the new file
385 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($uselist->in_use($virtual));
388 return error
($config->{'errors'}->{'editdir'},$dir) if(-d
$physical);
389 return error
($config->{'errors'}->{'no_edit'},$dir) if(-e
$physical && !(-r
$physical && -w
$physical));
390 return error
($config->{'errors'}->{'text_to_binary'},$dir) unless(-T
$physical);
392 if(file_save
($physical,\
$content))
394 # Saving of the file was successful!
396 return devedit_reload
({command
=> 'show', file
=> $dir});
400 return error
($config->{'errors'}->{'edit_failed'},$dir,{FILE
=> $virtual});
406 # Create a file and return to directory view
408 # Params: 1. Reference to user input hash
409 # 2. Reference to config hash
411 # Return: Output of the command (Scalar Reference)
415 my ($data,$config) = @_;
416 my $new_physical = $data->{'new_physical'};
417 my $new_virtual = $data->{'new_virtual'};
418 my $dir = upper_path
($new_virtual);
419 $new_virtual = encode_entities
($new_virtual);
423 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
425 file_create
($new_physical) or return error
($config->{'errors'}->{'mkfile_failed'},$dir,{FILE
=> $new_virtual});
426 return devedit_reload
({command
=> 'show', file
=> $dir});
430 my $tpl = new Template
;
431 $tpl->read_file($config->{'templates'}->{'mkfile'});
433 $tpl->fillin("DIR","/");
434 $tpl->fillin("SCRIPT",$script);
436 my $output = header
(-type
=> "text/html");
437 $output .= $tpl->get_template;
445 # Create a directory and return to directory view
447 # Params: 1. Reference to user input hash
448 # 2. Reference to config hash
450 # Return: Output of the command (Scalar Reference)
454 my ($data,$config) = @_;
455 my $new_physical = $data->{'new_physical'};
456 my $new_virtual = $data->{'new_virtual'};
457 my $dir = upper_path
($new_virtual);
458 $new_virtual = encode_entities
($new_virtual);
460 return error
($config->{'errors'}->{'file_exists'},$dir,{FILE
=> $new_virtual}) if(-e
$new_physical);
464 mkdir($new_physical,0777) or return error
($config->{'errors'}->{'mkdir_failed'},$dir,{DIR
=> $new_virtual});
465 return devedit_reload
({command
=> 'show', file
=> $dir});
469 my $tpl = new Template
;
470 $tpl->read_file($config->{'templates'}->{'mkdir'});
472 $tpl->fillin("DIR","/");
473 $tpl->fillin("SCRIPT",$script);
475 my $output = header
(-type
=> "text/html");
476 $output .= $tpl->get_template;
486 # Params: 1. Reference to user input hash
487 # 2. Reference to config hash
489 # Return: Output of the command (Scalar Reference)
493 my ($data,$config) = @_;
494 my $physical = $data->{'physical'};
495 my $virtual = $data->{'virtual'};
496 my $cgi = $data->{'cgi'};
498 return error
($config->{'errors'}->{'no_directory'},upper_path
($virtual),{FILE
=> $virtual}) unless(-d
$physical);
499 return error
($config->{'errors'}->{'dir_no_create'},$virtual,{DIR
=> $virtual}) unless(-w
$physical);
501 if(my $uploaded_file = $cgi->param('uploaded_file'))
503 # Process file upload
505 my $filename = file_name
($uploaded_file);
506 my $file_phys = $physical."/".$filename;
507 my $file_virt = $virtual.$filename;
509 return error
($config->{'errors'}->{'in_use'},$virtual,{FILE
=> $file_virt}) if($data->{'uselist'}->in_use($file_virt));
513 return error
($config->{'errors'}->{'dir_replace'},$virtual) if(-d
$file_phys);
514 return error
($config->{'errors'}->{'exist_no_write'},$virtual,{FILE
=> $file_virt}) unless(-w
$file_phys);
515 return error
($config->{'errors'}->{'file_exists'},$virtual,{FILE
=> $file_virt}) unless($cgi->param('overwrite'));
518 my $ascii = $cgi->param('ascii');
519 my $handle = $cgi->upload('uploaded_file');
521 # Read transferred file and write it to disk
523 read($handle, my $data, -s
$handle);
524 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
525 file_save
($file_phys,\
$data,not $ascii) or return error
($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE
=> $file_virt});
527 return devedit_reload
({command
=> "show", file
=> $virtual});
531 my $tpl = new Template
;
532 $tpl->read_file($config->{'templates'}->{'upload'});
534 $tpl->fillin("DIR",$virtual);
535 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
536 $tpl->fillin("SCRIPT",$script);
538 my $output = header
(-type
=> "text/html");
539 $output .= $tpl->get_template;
547 # Copy a file and return to directory view
549 # Params: 1. Reference to user input hash
550 # 2. Reference to config hash
552 # Return: Output of the command (Scalar Reference)
556 my ($data,$config) = @_;
557 my $physical = $data->{'physical'};
558 my $virtual = encode_entities
($data->{'virtual'});
559 my $dir = upper_path
($virtual);
560 my $new_physical = $data->{'new_physical'};
562 return error
($config->{'errors'}->{'dircopy'},$dir) if(-d
$physical);
563 return error
($config->{'errors'}->{'no_copy'},$dir) unless(-r
$physical);
567 my $new_virtual = $data->{'new_virtual'};
568 my $new_dir = upper_path
($new_virtual);
569 $new_virtual = encode_entities
($new_virtual);
573 return error
($config->{'errors'}->{'exist_edited'},$new_dir,{FILE
=> $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
574 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
575 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
577 if(not $data->{'cgi'}->param('confirmed'))
579 my $tpl = new Template
;
580 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
582 $tpl->fillin("FILE",$virtual);
583 $tpl->fillin("NEW_FILE",$new_virtual);
584 $tpl->fillin("NEW_FILENAME",file_name
($new_virtual));
585 $tpl->fillin("NEW_DIR",$new_dir);
586 $tpl->fillin("DIR",$dir);
588 $tpl->fillin("COMMAND","copy");
589 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
590 $tpl->fillin("SCRIPT",$script);
592 my $output = header
(-type
=> "text/html");
593 $output .= $tpl->get_template;
599 copy
($physical,$new_physical) or return error
($config->{'errors'}->{'copy_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
600 return devedit_reload
({command
=> 'show', file
=> $new_dir});
604 my $tpl = new Template
;
605 $tpl->read_file($config->{'templates'}->{'copyfile'});
607 $tpl->fillin("FILE",$virtual);
608 $tpl->fillin("DIR",$dir);
609 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
610 $tpl->fillin("SCRIPT",$script);
612 my $output = header
(-type
=> "text/html");
613 $output .= $tpl->get_template;
621 # Rename/move a file and return to directory view
623 # Params: 1. Reference to user input hash
624 # 2. Reference to config hash
626 # Return: Output of the command (Scalar Reference)
630 my ($data,$config) = @_;
631 my $physical = $data->{'physical'};
632 my $virtual = $data->{'virtual'};
633 my $dir = upper_path
($virtual);
634 my $new_physical = $data->{'new_physical'};
636 return error
($config->{'errors'}->{'rename_root'},"/") if($virtual eq "/");
637 return error
($config->{'errors'}->{'no_rename'},$dir) unless(-w upper_path
($physical));
638 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
642 my $new_virtual = $data->{'new_virtual'};
643 my $new_dir = upper_path
($new_virtual);
644 $new_virtual = encode_entities
($new_virtual);
648 return error
($config->{'errors'}->{'exist_edited'},$new_dir,{FILE
=> $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
649 return error
($config->{'errors'}->{'dir_replace'},$new_dir) if(-d
$new_physical);
650 return error
($config->{'errors'}->{'exist_no_write'},$new_dir,{FILE
=> $new_virtual}) unless(-w
$new_physical);
652 if(not $data->{'cgi'}->param('confirmed'))
654 my $tpl = new Template
;
655 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
657 $tpl->fillin("FILE",$virtual);
658 $tpl->fillin("NEW_FILE",$new_virtual);
659 $tpl->fillin("NEW_FILENAME",file_name
($new_virtual));
660 $tpl->fillin("NEW_DIR",$new_dir);
661 $tpl->fillin("DIR",$dir);
663 $tpl->fillin("COMMAND","rename");
664 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
665 $tpl->fillin("SCRIPT",$script);
667 my $output = header
(-type
=> "text/html");
668 $output .= $tpl->get_template;
674 rename($physical,$new_physical) or return error
($config->{'errors'}->{'rename_failed'},$dir,{FILE
=> $virtual, NEW_FILE
=> $new_virtual});
675 return devedit_reload
({command
=> 'show', file
=> $new_dir});
679 my $tpl = new Template
;
680 $tpl->read_file($config->{'templates'}->{'renamefile'});
682 $tpl->fillin("FILE",$virtual);
683 $tpl->fillin("DIR",$dir);
684 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
685 $tpl->fillin("SCRIPT",$script);
687 my $output = header
(-type
=> "text/html");
688 $output .= $tpl->get_template;
696 # Remove a file or a directory and return to directory view
698 # Params: 1. Reference to user input hash
699 # 2. Reference to config hash
701 # Return: Output of the command (Scalar Reference)
705 my ($data,$config) = @_;
706 my $physical = $data->{'physical'};
707 my $virtual = $data->{'virtual'};
708 my $dir = upper_path
($virtual);
710 return error
($config->{'errors'}->{'remove_root'},"/") if($virtual eq "/");
711 return error
($config->{'errors'}->{'no_delete'},$dir) unless(-w upper_path
($physical));
717 if($data->{'cgi'}->param('confirmed'))
720 return devedit_reload
({command
=> 'show', file
=> $dir});
724 my $tpl = new Template
;
725 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
727 $tpl->fillin("DIR",$virtual);
728 $tpl->fillin("UPPER_DIR",$dir);
729 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
730 $tpl->fillin("SCRIPT",$script);
732 my $output = header
(-type
=> "text/html");
733 $output .= $tpl->get_template;
742 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
744 if($data->{'cgi'}->param('confirmed'))
746 unlink($physical) or return error
($config->{'errors'}->{'delete_failed'},$dir,{FILE
=> $virtual});
747 return devedit_reload
({command
=> 'show', file
=> $dir});
751 my $tpl = new Template
;
752 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
754 $tpl->fillin("FILE",$virtual);
755 $tpl->fillin("DIR",$dir);
756 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
757 $tpl->fillin("SCRIPT",$script);
759 my $output = header
(-type
=> "text/html");
760 $output .= $tpl->get_template;
769 # Change the mode and the group of a file or a directory
771 # Params: 1. Reference to user input hash
772 # 2. Reference to config hash
774 # Return: Output of the command (Scalar Reference)
778 my ($data,$config) = @_;
779 my $physical = $data->{'physical'};
780 my $virtual = $data->{'virtual'};
781 my $dir = upper_path
($virtual);
783 return error
($config->{'errors'}->{'no_users'},$dir,{FILE
=> $virtual}) unless($users);
784 return error
($config->{'errors'}->{'chprop_root'},"/") if($virtual eq "/");
785 return error
($config->{'errors'}->{'not_owner'},$dir,{FILE
=> $virtual}) unless(-o
$physical);
786 return error
($config->{'errors'}->{'in_use'},$dir,{FILE
=> $virtual}) if($data->{'uselist'}->in_use($virtual));
788 my $cgi = $data->{'cgi'};
789 my $mode = $cgi->param('mode');
790 my $group = $cgi->param('group');
798 chmod(oct($mode),$physical);
803 # Change the group using the `chgrp` system command
805 return error
($config->{'errors'}->{'invalid_group'},$dir,{GROUP
=> encode_entities
($group)}) unless($group =~ /^[a-z0-9_]+[a-z0-9_-]*$/i);
806 system("chgrp",$group,$physical);
809 return devedit_reload
({command
=> 'show', file
=> $dir});
815 my @stat = stat($physical);
819 my $tpl = new Template
;
820 $tpl->read_file($config->{'templates'}->{'chprop'});
822 # Insert file properties into the template
824 $tpl->fillin("MODE_OCTAL",substr(sprintf("%04o",$mode),-4));
825 $tpl->fillin("MODE_STRING",mode_string
($mode));
826 $tpl->fillin("GID",$gid);
828 if(my $group = getgrgid($gid))
830 $tpl->fillin("GROUP",encode_entities
($group));
831 $tpl->parse_if_block("group_detected",1);
835 $tpl->parse_if_block("group_detected",0);
838 # Insert other information
840 $tpl->fillin("FILE",$virtual);
841 $tpl->fillin("DIR",$dir);
842 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
843 $tpl->fillin("SCRIPT",$script);
845 my $output = header
(-type
=> "text/html");
846 $output .= $tpl->get_template;
854 # Remove a file from the list of used files and
855 # return to directory view
857 # Params: 1. Reference to user input hash
858 # 2. Reference to config hash
860 # Return: Output of the command (Scalar Reference)
864 my ($data,$config) = @_;
865 my $virtual = $data->{'virtual'};
866 my $uselist = $data->{'uselist'};
867 my $dir = upper_path
($virtual);
869 return devedit_reload
({command
=> 'show', file
=> $dir}) if($uselist->unused($virtual));
871 if($data->{'cgi'}->param('confirmed'))
873 file_unlock
($uselist,$virtual);
874 return devedit_reload
({command
=> 'show', file
=> $dir});
878 my $tpl = new Template
;
879 $tpl->read_file($config->{'templates'}->{'confirm_unlock'});
881 $tpl->fillin("FILE",$virtual);
882 $tpl->fillin("DIR",$dir);
883 $tpl->fillin("URL",equal_url
($config->{'httproot'},$virtual));
884 $tpl->fillin("SCRIPT",$script);
886 my $output = header
(-type
=> "text/html");
887 $output .= $tpl->get_template;
895 # Display some information about Dev-Editor
897 # Params: 1. Reference to user input hash
898 # 2. Reference to config hash
900 # Return: Output of the command (Scalar Reference)
904 my ($data,$config) = @_;
906 my $tpl = new Template
;
907 $tpl->read_file($config->{'templates'}->{'about'});
909 $tpl->fillin("SCRIPT",$script);
911 # Dev-Editor's version number
913 $tpl->fillin("VERSION",$data->{'version'});
915 # Some path information
917 $tpl->fillin("SCRIPT_PHYS",encode_entities
($ENV{'SCRIPT_FILENAME'}));
918 $tpl->fillin("CONFIG_PATH",encode_entities
($data->{'configfile'}));
919 $tpl->fillin("FILE_ROOT", encode_entities
($config->{'fileroot'}));
920 $tpl->fillin("HTTP_ROOT", encode_entities
($config->{'httproot'}));
924 $tpl->fillin("PERL_PROG",encode_entities
($^X
));
925 $tpl->fillin("PERL_VER", sprintf("%vd",$^V
));
927 # Information about the server
929 $tpl->fillin("HTTPD",encode_entities
($ENV{'SERVER_SOFTWARE'}));
930 $tpl->fillin("OS", encode_entities
($^O
));
931 $tpl->fillin("TIME", encode_entities
(strftime
($config->{'timeformat'},localtime)));
933 # Process information
935 $tpl->fillin("PID",$$);
937 # Check if the functions getpwuid() and getgrgid() are available
941 # Dev-Editor is running on a system which allows users and groups
942 # So we display the user and the group of our process
944 my $uid = POSIX
::getuid
;
945 my $gid = POSIX
::getgid
;
947 $tpl->parse_if_block("users",1);
949 # ID's of user and group
951 $tpl->fillin("UID",$uid);
952 $tpl->fillin("GID",$gid);
954 # Names of user and group
956 if(my $user = getpwuid($uid))
958 $tpl->fillin("USER",encode_entities
($user));
959 $tpl->parse_if_block("user_detected",1);
963 $tpl->parse_if_block("user_detected",0);
966 if(my $group = getgrgid($gid))
968 $tpl->fillin("GROUP",encode_entities
($group));
969 $tpl->parse_if_block("group_detected",1);
973 $tpl->parse_if_block("group_detected",0);
978 $tpl->fillin("UMASK",sprintf("%04o",umask));
982 $tpl->parse_if_block("users",0);
985 my $output = header
(-type
=> "text/html");
986 $output .= $tpl->get_template;
991 # it's true, baby ;-)
patrick-canterino.de