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

patrick-canterino.de