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

patrick-canterino.de