]> git.p6c8.net - devedit.git/blob - modules/Command.pm
6db5d07b5429b8dc83d8da99dd9f4d6d87a7f64e
[devedit.git] / modules / Command.pm
1 package Command;
2
3 #
4 # Dev-Editor - Module Command
5 #
6 # Execute Dev-Editor's commands
7 #
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2004-07-11
10 #
11
12 use strict;
13
14 use vars qw(@EXPORT);
15
16 use File::Access;
17 use File::Copy;
18 use File::Path;
19
20 use POSIX qw(strftime);
21 use Tool;
22
23 use CGI qw(header);
24 use HTML::Entities;
25 use Output;
26 use Template;
27
28 my $script = $ENV{'SCRIPT_NAME'};
29
30 my %dispatch = ('show' => \&exec_show,
31 'beginedit' => \&exec_beginedit,
32 'canceledit' => \&exec_canceledit,
33 'endedit' => \&exec_endedit,
34 'mkdir' => \&exec_mkdir,
35 'mkfile' => \&exec_mkfile,
36 'upload' => \&exec_upload,
37 'copy' => \&exec_copy,
38 'rename' => \&exec_rename,
39 'remove' => \&exec_remove,
40 'unlock' => \&exec_unlock,
41 'about' => \&exec_about
42 );
43
44 ### Export ###
45
46 use base qw(Exporter);
47
48 @EXPORT = qw(exec_command);
49
50 # exec_command()
51 #
52 # Execute the specified command
53 #
54 # Params: 1. Command to execute
55 # 2. Reference to user input hash
56 # 3. Reference to config hash
57 #
58 # Return: Output of the command (Scalar Reference)
59
60 sub exec_command($$$)
61 {
62 my ($command,$data,$config) = @_;
63
64 return error($config->{'errors'}->{'cmd_unknown'},'/',{COMMAND => $command}) unless($dispatch{$command});
65
66 my $output = &{$dispatch{$command}}($data,$config);
67 return $output;
68 }
69
70 # exec_show()
71 #
72 # View a directory or a file
73 #
74 # Params: 1. Reference to user input hash
75 # 2. Reference to config hash
76 #
77 # Return: Output of the command (Scalar Reference)
78
79 sub exec_show($$)
80 {
81 my ($data,$config) = @_;
82 my $physical = $data->{'physical'};
83 my $virtual = $data->{'virtual'};
84
85 my $tpl = new Template;
86
87 if(-d $physical)
88 {
89 # Create directory listing
90
91 my $direntries = dir_read($physical);
92 return error($config->{'dir_read_failed'},upper_path($virtual),{DIR => '$virtual'}) unless($direntries);
93
94 my $files = $direntries->{'files'};
95 my $dirs = $direntries->{'dirs'};
96
97 my $dirlist = "";
98
99 # Create the link to the upper directory
100 # (only if we are not in the root directory)
101
102 unless($virtual eq "/")
103 {
104 my @stat = stat($physical."/..");
105
106 my $udtpl = new Template;
107 $udtpl->read_file($config->{'templates'}->{'dirlist_up'});
108
109 $udtpl->fillin("UPPER_DIR",encode_entities(upper_path($virtual)));
110 $udtpl->fillin("DATE",strftime($config->{'timeformat'},localtime($stat[9])));
111
112 $dirlist .= $udtpl->get_template;
113 }
114
115 # Directories
116
117 foreach my $dir(@$dirs)
118 {
119 my @stat = stat($physical."/".$dir);
120 my $virt_path = encode_entities($virtual.$dir."/");
121
122 my $dtpl = new Template;
123 $dtpl->read_file($config->{'templates'}->{'dirlist_dir'});
124
125 $dtpl->fillin("DIR",$virt_path);
126 $dtpl->fillin("DIR_NAME",$dir);
127 $dtpl->fillin("DATE",strftime($config->{'timeformat'},localtime($stat[9])));
128 $dtpl->fillin("URL",equal_url($config->{'httproot'},$virt_path));
129
130 $dirlist .= $dtpl->get_template;
131 }
132
133 # Files
134
135 foreach my $file(@$files)
136 {
137 my $phys_path = $physical."/".$file;
138 my $virt_path = encode_entities($virtual.$file);
139
140 my @stat = stat($phys_path);
141 my $in_use = $data->{'uselist'}->in_use($virtual.$file);
142
143 my $ftpl = new Template;
144 $ftpl->read_file($config->{'templates'}->{'dirlist_file'});
145
146 $ftpl->fillin("FILE",$virt_path);
147 $ftpl->fillin("FILE_NAME",$file);
148 $ftpl->fillin("SIZE",$stat[7]);
149 $ftpl->fillin("DATE",strftime($config->{'timeformat'},localtime($stat[9])));
150 $ftpl->fillin("URL",equal_url($config->{'httproot'},$virt_path));
151
152 $ftpl->parse_if_block("not_readable",not -r $phys_path);
153 $ftpl->parse_if_block("binary",-B $phys_path);
154 $ftpl->parse_if_block("readonly",not -w $phys_path);
155
156 $ftpl->parse_if_block("viewable",-r $phys_path && -T $phys_path && not ($config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'}));
157
158 $ftpl->parse_if_block("editable",-r $phys_path && -w $phys_path && -T $phys_path && not ($config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'}) && not $in_use);
159
160 $ftpl->parse_if_block("in_use",$in_use);
161 $ftpl->parse_if_block("unused",not $in_use);
162
163 $ftpl->parse_if_block("too_large",$config->{'max_file_size'} && $stat[7] > $config->{'max_file_size'});
164
165 $dirlist .= $ftpl->get_template;
166 }
167
168 $tpl->read_file($config->{'templates'}->{'dirlist'});
169
170 $tpl->fillin("DIRLIST",$dirlist);
171 $tpl->fillin("DIR",$virtual);
172 $tpl->fillin("SCRIPT",$script);
173 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
174 }
175 else
176 {
177 # View a file
178
179 return error($config->{'errors'}->{'noview'},upper_path($virtual)) unless(-r $physical);
180
181 # Check on binary files
182 # We have to do it in this way, or empty files
183 # will be recognized as binary files
184
185 unless(-T $physical)
186 {
187 # Binary file
188
189 return error($config->{'errors'}->{'binary'},upper_path($virtual));
190 }
191 else
192 {
193 # Text file
194
195 if($config->{'max_file_size'} && (stat($physical))[7] > $config->{'max_file_size'})
196 {
197 return error($config->{'errors'}->{'file_too_large'},upper_path($virtual),{SIZE => $config->{'max_file_size'}})
198 }
199 else
200 {
201 my $content = file_read($physical);
202 $$content =~ s/\015\012|\012|\015/\n/g;
203
204 $tpl->read_file($config->{'templates'}->{'viewfile'});
205
206 $tpl->fillin("FILE",$virtual);
207 $tpl->fillin("DIR",upper_path($virtual));
208 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
209 $tpl->fillin("SCRIPT",$script);
210 $tpl->fillin("CONTENT",encode_entities($$content));
211 }
212 }
213 }
214
215 my $output = header(-type => "text/html");
216 $output .= $tpl->get_template;
217
218 return \$output;
219 }
220
221 # exec_beginedit
222 #
223 # Lock a file and display a form to edit it
224 #
225 # Params: 1. Reference to user input hash
226 # 2. Reference to config hash
227 #
228 # Return: Output of the command (Scalar Reference)
229
230 sub exec_beginedit($$)
231 {
232 my ($data,$config) = @_;
233 my $physical = $data->{'physical'};
234 my $virtual = $data->{'virtual'};
235 my $uselist = $data->{'uselist'};
236
237 return error($config->{'errors'}->{'editdir'},upper_path($virtual)) if(-d $physical);
238 return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($uselist->in_use($virtual));
239 return error($config->{'errors'}->{'noedit'},upper_path($virtual)) unless(-r $physical && -w $physical);
240
241 # Check on binary files
242
243 unless(-T $physical)
244 {
245 # Binary file
246
247 return error($config->{'errors'}->{'binary'},upper_path($virtual));
248 }
249 else
250 {
251 if($config->{'max_file_size'} && (stat($physical))[7] > $config->{'max_file_size'})
252 {
253 return error($config->{'errors'}->{'file_too_large'},upper_path($virtual),{SIZE => $config->{'max_file_size'}})
254 }
255 else
256 {
257 # Text file
258
259 $uselist->add_file($virtual);
260 $uselist->save;
261
262 my $content = file_read($physical);
263 $$content =~ s/\015\012|\012|\015/\n/g;
264
265 my $tpl = new Template;
266 $tpl->read_file($config->{'templates'}->{'editfile'});
267
268 $tpl->fillin("FILE",$virtual);
269 $tpl->fillin("DIR",upper_path($virtual));
270 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
271 $tpl->fillin("SCRIPT",$script);
272 $tpl->fillin("CONTENT",encode_entities($$content));
273
274 my $output = header(-type => "text/html");
275 $output .= $tpl->get_template;
276
277 return \$output;
278 }
279 }
280 }
281
282 # exec_canceledit()
283 #
284 # Abort file editing
285 #
286 # Params: 1. Reference to user input hash
287 # 2. Reference to config hash
288 #
289 # Return: Output of the command (Scalar Reference)
290
291 sub exec_canceledit($$)
292 {
293 my ($data,$config) = @_;
294 my $virtual = $data->{'virtual'};
295
296 file_unlock($data->{'uselist'},$virtual);
297 return devedit_reload({command => 'show', file => upper_path($virtual)});
298 }
299
300 # exec_endedit()
301 #
302 # Save a file, unlock it and return to directory view
303 #
304 # Params: 1. Reference to user input hash
305 # 2. Reference to config hash
306 #
307 # Return: Output of the command (Scalar Reference)
308
309 sub exec_endedit($$)
310 {
311 my ($data,$config) = @_;
312 my $physical = $data->{'physical'};
313 my $virtual = $data->{'virtual'};
314 my $content = $data->{'cgi'}->param('filecontent');
315 my $uselist = $data->{'uselist'};
316
317 # Normalize newlines
318
319 $content =~ s/\015\012|\012|\015/\n/g;
320
321 if($data->{'cgi'}->param('encode_iso'))
322 {
323 # Encode all ISO-8859-1 special chars
324
325 $content = encode_entities($content,"\200-\377");
326 }
327
328 if($data->{'cgi'}->param('saveas'))
329 {
330 # Create the new filename
331
332 $physical = $data->{'new_physical'};
333 $virtual = $data->{'new_virtual'};
334
335 # Check if someone else is editing the new file
336
337 return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($uselist->in_use($virtual));
338 }
339
340 return error($config->{'errors'}->{'editdir'},upper_path($virtual)) if(-d $physical);
341 return error($config->{'errors'}->{'noedit'}, upper_path($virtual)) unless(-r $physical && -w $physical);
342
343 if(file_save($physical,\$content))
344 {
345 # Saving of the file was successful - so unlock it!
346
347 file_unlock($uselist,$data->{'virtual'});
348 # ^^^^^^^^^^^^^^^^^^
349 # Maybe the user saved the file using another filename...
350 # But we have to unlock the original file!
351
352 return devedit_reload({command => 'show', file => upper_path($virtual)});
353 }
354 else
355 {
356 return error($config->{'errors'}->{'edit_failed'},upper_path($virtual),{FILE => $virtual});
357 }
358 }
359
360 # exec_mkfile()
361 #
362 # Create a file and return to directory view
363 #
364 # Params: 1. Reference to user input hash
365 # 2. Reference to config hash
366 #
367 # Return: Output of the command (Scalar Reference)
368
369 sub exec_mkfile($$)
370 {
371 my ($data,$config) = @_;
372 my $new_physical = $data->{'new_physical'};
373 my $new_virtual = $data->{'new_virtual'};
374 my $dir = upper_path($new_virtual);
375 $new_virtual = encode_entities($new_virtual);
376
377 if($new_physical)
378 {
379 return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical);
380
381 file_create($new_physical) or return error($config->{'errors'}->{'mkfile_failed'},$dir,{FILE => $new_virtual});
382 return devedit_reload({command => 'show', file => $dir});
383 }
384 else
385 {
386 my $tpl = new Template;
387 $tpl->read_file($config->{'templates'}->{'mkfile'});
388
389 $tpl->fillin("DIR","/");
390 $tpl->fillin("SCRIPT",$script);
391
392 my $output = header(-type => "text/html");
393 $output .= $tpl->get_template;
394
395 return \$output;
396 }
397 }
398
399 # exec_mkdir()
400 #
401 # Create a directory and return to directory view
402 #
403 # Params: 1. Reference to user input hash
404 # 2. Reference to config hash
405 #
406 # Return: Output of the command (Scalar Reference)
407
408 sub exec_mkdir($$)
409 {
410 my ($data,$config) = @_;
411 my $new_physical = $data->{'new_physical'};
412 my $new_virtual = $data->{'new_virtual'};
413 my $dir = upper_path($new_virtual);
414 $new_virtual = encode_entities($new_virtual);
415
416 return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical);
417
418 if($new_physical)
419 {
420 mkdir($new_physical,0777) or return error($config->{'errors'}->{'mkdir_failed'},$dir,{DIR => $new_virtual});
421 return devedit_reload({command => 'show', file => $dir});
422 }
423 else
424 {
425 my $tpl = new Template;
426 $tpl->read_file($config->{'templates'}->{'mkdir'});
427
428 $tpl->fillin("DIR","/");
429 $tpl->fillin("SCRIPT",$script);
430
431 my $output = header(-type => "text/html");
432 $output .= $tpl->get_template;
433
434 return \$output;
435 }
436 }
437
438 # exec_upload()
439 #
440 # Upload a file
441 #
442 # Params: 1. Reference to user input hash
443 # 2. Reference to config hash
444 #
445 # Return: Output of the command (Scalar Reference)
446
447 sub exec_upload($$)
448 {
449 my ($data,$config) = @_;
450 my $physical = $data->{'physical'};
451 my $virtual = $data->{'virtual'};
452 my $cgi = $data->{'cgi'};
453
454 if(my $uploaded_file = $cgi->param('uploaded_file'))
455 {
456 # Process file upload
457
458 my $filename = file_name($uploaded_file);
459 my $file_phys = $physical."/".$filename;
460 my $file_virt = $virtual."".$filename;
461
462 return error($config->{'errors'}->{'file_exists'},$virtual,{FILE => $file_virt}) if(-e $file_phys);
463
464 my $ascii = $cgi->param('ascii');
465 my $handle = $cgi->upload('uploaded_file');
466
467 local *FILE;
468
469 open(FILE,">$file_phys") or return error($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE => $file_virt});
470 binmode(FILE) unless($ascii);
471
472 # Read transferred file and write it to disk
473
474 read($handle, my $data, -s $handle);
475 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
476 print FILE $data;
477
478 close(FILE);
479
480 return devedit_reload({command => "show", file => $virtual});
481 }
482 else
483 {
484 my $tpl = new Template;
485 $tpl->read_file($config->{'templates'}->{'upload'});
486
487 $tpl->fillin("DIR",$virtual);
488 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
489 $tpl->fillin("SCRIPT",$script);
490
491 my $output = header(-type => "text/html");
492 $output .= $tpl->get_template;
493
494 return \$output;
495 }
496 }
497
498 # exec_copy()
499 #
500 # Copy a file and return to directory view
501 #
502 # Params: 1. Reference to user input hash
503 # 2. Reference to config hash
504 #
505 # Return: Output of the command (Scalar Reference)
506
507 sub exec_copy($$)
508 {
509 my ($data,$config) = @_;
510 my $physical = $data->{'physical'};
511 my $virtual = encode_entities($data->{'virtual'});
512 my $new_physical = $data->{'new_physical'};
513
514 return error($config->{'errors'}->{'nocopy'}) unless(-r $physical);
515
516 if($new_physical)
517 {
518 my $new_virtual = $data->{'new_virtual'};
519 my $dir = upper_path($new_virtual);
520 $new_virtual = encode_entities($new_virtual);
521
522 if(-e $new_physical)
523 {
524 return error($config->{'errors'}->{'exist_edited'},$dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
525
526 if(-d $new_physical)
527 {
528 return error($config->{'errors'}->{'dircopy'});
529 }
530 elsif(not $data->{'cgi'}->param('confirmed'))
531 {
532 my $tpl = new Template;
533 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
534
535 $tpl->fillin("FILE",$virtual);
536 $tpl->fillin("NEW_FILE",$new_virtual);
537 $tpl->fillin("NEW_FILENAME",file_name($new_virtual));
538 $tpl->fillin("NEW_DIR",$dir);
539 $tpl->fillin("DIR",upper_path($virtual));
540
541 $tpl->fillin("COMMAND","copy");
542 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
543 $tpl->fillin("SCRIPT",$script);
544
545 my $output = header(-type => "text/html");
546 $output .= $tpl->get_template;
547
548 return \$output;
549 }
550 }
551
552 copy($physical,$new_physical) or return error($config->{'errors'}->{'copy_failed'},upper_path($virtual),{FILE => $virtual, NEW_FILE => $new_virtual});
553 return devedit_reload({command => 'show', file => $dir});
554 }
555 else
556 {
557 my $tpl = new Template;
558 $tpl->read_file($config->{'templates'}->{'copyfile'});
559
560 $tpl->fillin("FILE",$virtual);
561 $tpl->fillin("DIR",upper_path($virtual));
562 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
563 $tpl->fillin("SCRIPT",$script);
564
565 my $output = header(-type => "text/html");
566 $output .= $tpl->get_template;
567
568 return \$output;
569 }
570 }
571
572 # exec_rename()
573 #
574 # Rename/move a file and return to directory view
575 #
576 # Params: 1. Reference to user input hash
577 # 2. Reference to config hash
578 #
579 # Return: Output of the command (Scalar Reference)
580
581 sub exec_rename($$)
582 {
583 my ($data,$config) = @_;
584 my $physical = $data->{'physical'};
585 my $virtual = $data->{'virtual'};
586 my $new_physical = $data->{'new_physical'};
587
588 return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual));
589
590 if($new_physical)
591 {
592 my $new_virtual = $data->{'new_virtual'};
593 my $dir = upper_path($new_virtual);
594 $new_virtual = encode_entities($new_virtual);
595
596 if(-e $new_physical)
597 {
598 return error($config->{'errors'}->{'exist_edited'},$dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
599
600 if(-d $new_physical)
601 {
602 return error($config->{'errors'}->{'dircopy'});
603 }
604 elsif(not $data->{'cgi'}->param('confirmed'))
605 {
606 my $tpl = new Template;
607 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
608
609 $tpl->fillin("FILE",$virtual);
610 $tpl->fillin("NEW_FILE",$new_virtual);
611 $tpl->fillin("NEW_FILENAME",file_name($new_virtual));
612 $tpl->fillin("NEW_DIR",$dir);
613 $tpl->fillin("DIR",upper_path($virtual));
614
615 $tpl->fillin("COMMAND","rename");
616 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
617 $tpl->fillin("SCRIPT",$script);
618
619 my $output = header(-type => "text/html");
620 $output .= $tpl->get_template;
621
622 return \$output;
623 }
624 }
625
626 rename($physical,$new_physical) or return error($config->{'errors'}->{'rename_failed'},upper_path($virtual),{FILE => $virtual, NEW_FILE => $new_virtual});
627 return devedit_reload({command => 'show', file => $dir});
628 }
629 else
630 {
631 my $tpl = new Template;
632 $tpl->read_file($config->{'templates'}->{'renamefile'});
633
634 $tpl->fillin("FILE",$virtual);
635 $tpl->fillin("DIR",upper_path($virtual));
636 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
637 $tpl->fillin("SCRIPT",$script);
638
639 my $output = header(-type => "text/html");
640 $output .= $tpl->get_template;
641
642 return \$output;
643 }
644 }
645
646 # exec_remove()
647 #
648 # Remove a file or a directory and return to directory view
649 #
650 # Params: 1. Reference to user input hash
651 # 2. Reference to config hash
652 #
653 # Return: Output of the command (Scalar Reference)
654
655 sub exec_remove($$)
656 {
657 my ($data,$config) = @_;
658 my $physical = $data->{'physical'};
659 my $virtual = $data->{'virtual'};
660
661 if(-d $physical)
662 {
663 # Remove a directory
664
665 if($data->{'cgi'}->param('confirmed'))
666 {
667 rmtree($physical);
668 return devedit_reload({command => 'show', file => upper_path($virtual)});
669 }
670 else
671 {
672 my $tpl = new Template;
673 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
674
675 $tpl->fillin("DIR",$virtual);
676 $tpl->fillin("UPPER_DIR",upper_path($virtual));
677 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
678 $tpl->fillin("SCRIPT",$script);
679
680 my $output = header(-type => "text/html");
681 $output .= $tpl->get_template;
682
683 return \$output;
684 }
685 }
686 else
687 {
688 # Remove a file
689
690 return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual));
691
692 if($data->{'cgi'}->param('confirmed'))
693 {
694 unlink($physical) or return error($config->{'errors'}->{'delete_failed'},upper_path($virtual),{FILE => $virtual});
695 return devedit_reload({command => 'show', file => upper_path($virtual)});
696 }
697 else
698 {
699 my $tpl = new Template;
700 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
701
702 $tpl->fillin("FILE",$virtual);
703 $tpl->fillin("DIR",upper_path($virtual));
704 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
705 $tpl->fillin("SCRIPT",$script);
706
707 my $output = header(-type => "text/html");
708 $output .= $tpl->get_template;
709
710 return \$output;
711 }
712 }
713 }
714
715 # exec_unlock()
716 #
717 # Remove a file from the list of used files and
718 # return to directory view
719 #
720 # Params: 1. Reference to user input hash
721 # 2. Reference to config hash
722 #
723 # Return: Output of the command (Scalar Reference)
724
725 sub exec_unlock($$)
726 {
727 my ($data,$config) = @_;
728 my $virtual = $data->{'virtual'};
729
730 if($data->{'cgi'}->param('confirmed'))
731 {
732 file_unlock($data->{'uselist'},$virtual);
733 return devedit_reload({command => 'show', file => upper_path($virtual)});
734 }
735 else
736 {
737 my $tpl = new Template;
738 $tpl->read_file($config->{'templates'}->{'confirm_unlock'});
739
740 $tpl->fillin("FILE",$virtual);
741 $tpl->fillin("DIR",upper_path($virtual));
742 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
743 $tpl->fillin("SCRIPT",$script);
744
745 my $output = header(-type => "text/html");
746 $output .= $tpl->get_template;
747
748 return \$output;
749 }
750 }
751
752 # exec_about()
753 #
754 # Display some information about Dev-Editor
755 #
756 # Params: 1. Reference to user input hash
757 # 2. Reference to config hash
758 #
759 # Return: Output of the command (Scalar Reference)
760
761 sub exec_about($$)
762 {
763 my ($data,$config) = @_;
764
765 my $tpl = new Template;
766 $tpl->read_file($config->{'templates'}->{'about'});
767
768 $tpl->fillin("SCRIPT",$script);
769
770 # Dev-Editor's version number
771
772 $tpl->fillin("VERSION",$data->{'version'});
773
774 # Some path information
775
776 $tpl->fillin("SCRIPT_PHYS",$ENV{'SCRIPT_FILENAME'});
777 $tpl->fillin("CONFIG_PATH",$data->{'configfile'});
778 $tpl->fillin("FILE_ROOT",$config->{'fileroot'});
779 $tpl->fillin("HTTP_ROOT",$config->{'httproot'});
780
781 # Perl
782
783 $tpl->fillin("PERL_PROG",$^X);
784 $tpl->fillin("PERL_VER",sprintf("%vd",$^V));
785
786 # Information about the server
787
788 $tpl->fillin("HTTPD",$ENV{'SERVER_SOFTWARE'});
789 $tpl->fillin("OS",$^O);
790 $tpl->fillin("TIME",strftime($config->{'timeformat'},localtime));
791
792 # Process information
793
794 $tpl->fillin("PID",$$);
795
796 # Check if the functions getpwuid() and getgrgid() are available
797
798 if(eval("getpwuid(0)") && eval("getgrgid(0)"))
799 {
800 # Dev-Editor is running on a system which allows users and groups
801 # So we display the user and the group of our process
802
803 $tpl->parse_if_block("users",1);
804
805 # ID's of user and group
806
807 $tpl->fillin("UID",$<);
808 $tpl->fillin("GID",$();
809
810 # Names of user and group
811
812 $tpl->fillin("USER",getpwuid($<));
813 $tpl->fillin("GROUP",getgrgid($());
814 }
815 else
816 {
817 $tpl->parse_if_block("users",0);
818 }
819
820 my $output = header(-type => "text/html");
821 $output .= $tpl->get_template;
822
823 return \$output;
824 }
825
826 # it's true, baby ;-)
827
828 1;
829
830 #
831 ### End ###

patrick-canterino.de