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

patrick-canterino.de