]> git.p6c8.net - devedit.git/blob - modules/Command.pm
0c2caf05dab1655b6fa5411ae887ccbdf7a7a261
[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-04
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'}->{'editdir'},upper_path($virtual)) if(-d $physical);
358 return error($config->{'errors'}->{'noedit'}, upper_path($virtual)) if(-e $physical && !(-r $physical && -w $physical));
359
360 if(file_save($physical,\$content))
361 {
362 # Saving of the file was successful - so unlock it!
363
364 file_unlock($uselist,$data->{'virtual'});
365 # ^^^^^^^^^^^^^^^^^^
366 # Maybe the user saved the file using another filename...
367 # But we have to unlock the original file!
368
369 return devedit_reload({command => 'show', file => upper_path($virtual)});
370 }
371 else
372 {
373 return error($config->{'errors'}->{'edit_failed'},upper_path($virtual),{FILE => $virtual});
374 }
375 }
376
377 # exec_mkfile()
378 #
379 # Create a file and return to directory view
380 #
381 # Params: 1. Reference to user input hash
382 # 2. Reference to config hash
383 #
384 # Return: Output of the command (Scalar Reference)
385
386 sub exec_mkfile($$)
387 {
388 my ($data,$config) = @_;
389 my $new_physical = $data->{'new_physical'};
390 my $new_virtual = $data->{'new_virtual'};
391 my $dir = upper_path($new_virtual);
392 $new_virtual = encode_entities($new_virtual);
393
394 if($new_physical)
395 {
396 return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical);
397
398 file_create($new_physical) or return error($config->{'errors'}->{'mkfile_failed'},$dir,{FILE => $new_virtual});
399 return devedit_reload({command => 'show', file => $dir});
400 }
401 else
402 {
403 my $tpl = new Template;
404 $tpl->read_file($config->{'templates'}->{'mkfile'});
405
406 $tpl->fillin("DIR","/");
407 $tpl->fillin("SCRIPT",$script);
408
409 my $output = header(-type => "text/html");
410 $output .= $tpl->get_template;
411
412 return \$output;
413 }
414 }
415
416 # exec_mkdir()
417 #
418 # Create a directory and return to directory view
419 #
420 # Params: 1. Reference to user input hash
421 # 2. Reference to config hash
422 #
423 # Return: Output of the command (Scalar Reference)
424
425 sub exec_mkdir($$)
426 {
427 my ($data,$config) = @_;
428 my $new_physical = $data->{'new_physical'};
429 my $new_virtual = $data->{'new_virtual'};
430 my $dir = upper_path($new_virtual);
431 $new_virtual = encode_entities($new_virtual);
432
433 return error($config->{'errors'}->{'file_exists'},$dir,{FILE => $new_virtual}) if(-e $new_physical);
434
435 if($new_physical)
436 {
437 mkdir($new_physical,0777) or return error($config->{'errors'}->{'mkdir_failed'},$dir,{DIR => $new_virtual});
438 return devedit_reload({command => 'show', file => $dir});
439 }
440 else
441 {
442 my $tpl = new Template;
443 $tpl->read_file($config->{'templates'}->{'mkdir'});
444
445 $tpl->fillin("DIR","/");
446 $tpl->fillin("SCRIPT",$script);
447
448 my $output = header(-type => "text/html");
449 $output .= $tpl->get_template;
450
451 return \$output;
452 }
453 }
454
455 # exec_upload()
456 #
457 # Upload a file
458 #
459 # Params: 1. Reference to user input hash
460 # 2. Reference to config hash
461 #
462 # Return: Output of the command (Scalar Reference)
463
464 sub exec_upload($$)
465 {
466 my ($data,$config) = @_;
467 my $physical = $data->{'physical'};
468 my $virtual = $data->{'virtual'};
469 my $cgi = $data->{'cgi'};
470
471 if(my $uploaded_file = $cgi->param('uploaded_file'))
472 {
473 # Process file upload
474
475 my $filename = file_name($uploaded_file);
476 my $file_phys = $physical."/".$filename;
477 my $file_virt = $virtual."".$filename;
478
479 return error($config->{'errors'}->{'file_exists'},$virtual,{FILE => $file_virt}) if(-e $file_phys && not $cgi->param('overwrite'));
480
481 my $ascii = $cgi->param('ascii');
482 my $handle = $cgi->upload('uploaded_file');
483
484 local *FILE;
485
486 open(FILE,">$file_phys") or return error($config->{'errors'}->{'mkfile_failed'},$virtual,{FILE => $file_virt});
487 binmode(FILE) unless($ascii);
488
489 # Read transferred file and write it to disk
490
491 read($handle, my $data, -s $handle);
492 $data =~ s/\015\012|\012|\015/\n/g if($ascii); # Replace line separators if transferring in ASCII mode
493 print FILE $data;
494
495 close(FILE);
496
497 return devedit_reload({command => "show", file => $virtual});
498 }
499 else
500 {
501 my $tpl = new Template;
502 $tpl->read_file($config->{'templates'}->{'upload'});
503
504 $tpl->fillin("DIR",$virtual);
505 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
506 $tpl->fillin("SCRIPT",$script);
507
508 my $output = header(-type => "text/html");
509 $output .= $tpl->get_template;
510
511 return \$output;
512 }
513 }
514
515 # exec_copy()
516 #
517 # Copy a file and return to directory view
518 #
519 # Params: 1. Reference to user input hash
520 # 2. Reference to config hash
521 #
522 # Return: Output of the command (Scalar Reference)
523
524 sub exec_copy($$)
525 {
526 my ($data,$config) = @_;
527 my $physical = $data->{'physical'};
528 my $virtual = encode_entities($data->{'virtual'});
529 my $new_physical = $data->{'new_physical'};
530
531 return error($config->{'errors'}->{'dircopy'}) if(-d $physical);
532 return error($config->{'errors'}->{'nocopy'}) unless(-r $physical);
533
534 if($new_physical)
535 {
536 my $new_virtual = $data->{'new_virtual'};
537 my $dir = upper_path($new_virtual);
538 $new_virtual = encode_entities($new_virtual);
539
540 if(-e $new_physical)
541 {
542 return error($config->{'errors'}->{'exist_edited'},$dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
543
544 if(-d $new_physical)
545 {
546 return error($config->{'errors'}->{'dir_replace'},$dir);
547 }
548 elsif(not $data->{'cgi'}->param('confirmed'))
549 {
550 my $tpl = new Template;
551 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
552
553 $tpl->fillin("FILE",$virtual);
554 $tpl->fillin("NEW_FILE",$new_virtual);
555 $tpl->fillin("NEW_FILENAME",file_name($new_virtual));
556 $tpl->fillin("NEW_DIR",$dir);
557 $tpl->fillin("DIR",upper_path($virtual));
558
559 $tpl->fillin("COMMAND","copy");
560 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
561 $tpl->fillin("SCRIPT",$script);
562
563 my $output = header(-type => "text/html");
564 $output .= $tpl->get_template;
565
566 return \$output;
567 }
568 }
569
570 copy($physical,$new_physical) or return error($config->{'errors'}->{'copy_failed'},upper_path($virtual),{FILE => $virtual, NEW_FILE => $new_virtual});
571 return devedit_reload({command => 'show', file => $dir});
572 }
573 else
574 {
575 my $tpl = new Template;
576 $tpl->read_file($config->{'templates'}->{'copyfile'});
577
578 $tpl->fillin("FILE",$virtual);
579 $tpl->fillin("DIR",upper_path($virtual));
580 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
581 $tpl->fillin("SCRIPT",$script);
582
583 my $output = header(-type => "text/html");
584 $output .= $tpl->get_template;
585
586 return \$output;
587 }
588 }
589
590 # exec_rename()
591 #
592 # Rename/move a file and return to directory view
593 #
594 # Params: 1. Reference to user input hash
595 # 2. Reference to config hash
596 #
597 # Return: Output of the command (Scalar Reference)
598
599 sub exec_rename($$)
600 {
601 my ($data,$config) = @_;
602 my $physical = $data->{'physical'};
603 my $virtual = $data->{'virtual'};
604 my $new_physical = $data->{'new_physical'};
605
606 return error($config->{'errors'}->{'rename_root'},"/") if($virtual eq "/");
607 return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual));
608
609 if($new_physical)
610 {
611 my $new_virtual = $data->{'new_virtual'};
612 my $dir = upper_path($new_virtual);
613 $new_virtual = encode_entities($new_virtual);
614
615 if(-e $new_physical)
616 {
617 return error($config->{'errors'}->{'exist_edited'},$dir,{FILE => $new_virtual}) if($data->{'uselist'}->in_use($data->{'new_virtual'}));
618
619 if(-d $new_physical)
620 {
621 return error($config->{'errors'}->{'dir_replace'},$dir);
622 }
623 elsif(not $data->{'cgi'}->param('confirmed'))
624 {
625 my $tpl = new Template;
626 $tpl->read_file($config->{'templates'}->{'confirm_replace'});
627
628 $tpl->fillin("FILE",$virtual);
629 $tpl->fillin("NEW_FILE",$new_virtual);
630 $tpl->fillin("NEW_FILENAME",file_name($new_virtual));
631 $tpl->fillin("NEW_DIR",$dir);
632 $tpl->fillin("DIR",upper_path($virtual));
633
634 $tpl->fillin("COMMAND","rename");
635 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
636 $tpl->fillin("SCRIPT",$script);
637
638 my $output = header(-type => "text/html");
639 $output .= $tpl->get_template;
640
641 return \$output;
642 }
643 }
644
645 rename($physical,$new_physical) or return error($config->{'errors'}->{'rename_failed'},upper_path($virtual),{FILE => $virtual, NEW_FILE => $new_virtual});
646 return devedit_reload({command => 'show', file => $dir});
647 }
648 else
649 {
650 my $tpl = new Template;
651 $tpl->read_file($config->{'templates'}->{'renamefile'});
652
653 $tpl->fillin("FILE",$virtual);
654 $tpl->fillin("DIR",upper_path($virtual));
655 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
656 $tpl->fillin("SCRIPT",$script);
657
658 my $output = header(-type => "text/html");
659 $output .= $tpl->get_template;
660
661 return \$output;
662 }
663 }
664
665 # exec_remove()
666 #
667 # Remove a file or a directory and return to directory view
668 #
669 # Params: 1. Reference to user input hash
670 # 2. Reference to config hash
671 #
672 # Return: Output of the command (Scalar Reference)
673
674 sub exec_remove($$)
675 {
676 my ($data,$config) = @_;
677 my $physical = $data->{'physical'};
678 my $virtual = $data->{'virtual'};
679
680 return error($config->{'errors'}->{'remove_root'},"/") if($virtual eq "/");
681
682 if(-d $physical)
683 {
684 # Remove a directory
685
686 if($data->{'cgi'}->param('confirmed'))
687 {
688 rmtree($physical);
689 return devedit_reload({command => 'show', file => upper_path($virtual)});
690 }
691 else
692 {
693 my $tpl = new Template;
694 $tpl->read_file($config->{'templates'}->{'confirm_rmdir'});
695
696 $tpl->fillin("DIR",$virtual);
697 $tpl->fillin("UPPER_DIR",upper_path($virtual));
698 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
699 $tpl->fillin("SCRIPT",$script);
700
701 my $output = header(-type => "text/html");
702 $output .= $tpl->get_template;
703
704 return \$output;
705 }
706 }
707 else
708 {
709 # Remove a file
710
711 return error($config->{'errors'}->{'in_use'},upper_path($virtual),{FILE => $virtual}) if($data->{'uselist'}->in_use($virtual));
712
713 if($data->{'cgi'}->param('confirmed'))
714 {
715 unlink($physical) or return error($config->{'errors'}->{'delete_failed'},upper_path($virtual),{FILE => $virtual});
716 return devedit_reload({command => 'show', file => upper_path($virtual)});
717 }
718 else
719 {
720 my $tpl = new Template;
721 $tpl->read_file($config->{'templates'}->{'confirm_rmfile'});
722
723 $tpl->fillin("FILE",$virtual);
724 $tpl->fillin("DIR",upper_path($virtual));
725 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
726 $tpl->fillin("SCRIPT",$script);
727
728 my $output = header(-type => "text/html");
729 $output .= $tpl->get_template;
730
731 return \$output;
732 }
733 }
734 }
735
736 # exec_chprop()
737 #
738 # Change the mode and the group of a file or a directory
739 #
740 # Params: 1. Reference to user input hash
741 # 2. Reference to config hash
742 #
743 # Return: Output of the command (Scalar Reference)
744
745 sub exec_chprop($$)
746 {
747 my ($data,$config) = @_;
748 my $physical = $data->{'physical'};
749 my $virtual = $data->{'virtual'};
750 my $dir = upper_path($virtual);
751 my $cgi = $data->{'cgi'};
752 my $mode = $cgi->param('mode');
753 my $group = $cgi->param('group');
754
755 if($users)
756 {
757 if(-o $physical)
758 {
759 if($mode || $group)
760 {
761 if($mode)
762 {
763 my $oct_mode = $mode;
764 $oct_mode = "0".$oct_mode if(length($oct_mode) == 3);
765 $oct_mode = oct($oct_mode);
766
767 chmod($oct_mode,$physical);
768 }
769
770 chgrp($group,$physical) if($group);
771
772 return devedit_reload({command => 'show', file => $dir});
773 }
774 else
775 {
776 my @stat = stat($physical);
777
778 my $mode = $stat[2];
779 my $mode_oct = substr(sprintf("%04o",$mode),-4);
780 my $gid = $stat[5];
781 my $group = getgrgid($gid);
782
783 my $tpl = new Template;
784 $tpl->read_file($config->{'templates'}->{'chprop'});
785
786 $tpl->fillin("MODE_OCTAL",$mode_oct);
787 $tpl->fillin("MODE_STRING",mode_string($mode));
788 $tpl->fillin("GID",$gid);
789 $tpl->fillin("GROUP",$group);
790
791 $tpl->fillin("FILE",$virtual);
792 $tpl->fillin("DIR",$dir);
793 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
794 $tpl->fillin("SCRIPT",$script);
795
796 my $output = header(-type => "text/html");
797 $output .= $tpl->get_template;
798
799 return \$output;
800 }
801 }
802 else
803 {
804 return error($config->{'errors'}->{'not_owner'},$dir,{FILE => $virtual});
805 }
806 }
807 else
808 {
809 return error($config->{'errors'}->{'no_users'},$dir,{FILE => $virtual});
810 }
811 }
812
813 # exec_unlock()
814 #
815 # Remove a file from the list of used files and
816 # return to directory view
817 #
818 # Params: 1. Reference to user input hash
819 # 2. Reference to config hash
820 #
821 # Return: Output of the command (Scalar Reference)
822
823 sub exec_unlock($$)
824 {
825 my ($data,$config) = @_;
826 my $virtual = $data->{'virtual'};
827
828 if($data->{'cgi'}->param('confirmed'))
829 {
830 file_unlock($data->{'uselist'},$virtual);
831 return devedit_reload({command => 'show', file => upper_path($virtual)});
832 }
833 else
834 {
835 my $tpl = new Template;
836 $tpl->read_file($config->{'templates'}->{'confirm_unlock'});
837
838 $tpl->fillin("FILE",$virtual);
839 $tpl->fillin("DIR",upper_path($virtual));
840 $tpl->fillin("URL",equal_url($config->{'httproot'},$virtual));
841 $tpl->fillin("SCRIPT",$script);
842
843 my $output = header(-type => "text/html");
844 $output .= $tpl->get_template;
845
846 return \$output;
847 }
848 }
849
850 # exec_about()
851 #
852 # Display some information about Dev-Editor
853 #
854 # Params: 1. Reference to user input hash
855 # 2. Reference to config hash
856 #
857 # Return: Output of the command (Scalar Reference)
858
859 sub exec_about($$)
860 {
861 my ($data,$config) = @_;
862
863 my $tpl = new Template;
864 $tpl->read_file($config->{'templates'}->{'about'});
865
866 $tpl->fillin("SCRIPT",$script);
867
868 # Dev-Editor's version number
869
870 $tpl->fillin("VERSION",$data->{'version'});
871
872 # Some path information
873
874 $tpl->fillin("SCRIPT_PHYS",$ENV{'SCRIPT_FILENAME'});
875 $tpl->fillin("CONFIG_PATH",$data->{'configfile'});
876 $tpl->fillin("FILE_ROOT",$config->{'fileroot'});
877 $tpl->fillin("HTTP_ROOT",$config->{'httproot'});
878
879 # Perl
880
881 $tpl->fillin("PERL_PROG",$^X);
882 $tpl->fillin("PERL_VER",sprintf("%vd",$^V));
883
884 # Information about the server
885
886 $tpl->fillin("HTTPD",$ENV{'SERVER_SOFTWARE'});
887 $tpl->fillin("OS",$^O);
888 $tpl->fillin("TIME",strftime($config->{'timeformat'},localtime));
889
890 # Process information
891
892 $tpl->fillin("PID",$$);
893
894 # Check if the functions getpwuid() and getgrgid() are available
895
896 if($users)
897 {
898 # Dev-Editor is running on a system which allows users and groups
899 # So we display the user and the group of our process
900
901 $tpl->parse_if_block("users",1);
902
903 # ID's of user and group
904
905 $tpl->fillin("UID",$<);
906 $tpl->fillin("GID",$();
907
908 # Names of user and group
909
910 $tpl->fillin("USER",getpwuid($<));
911 $tpl->fillin("GROUP",getgrgid($());
912 }
913 else
914 {
915 $tpl->parse_if_block("users",0);
916 }
917
918 my $output = header(-type => "text/html");
919 $output .= $tpl->get_template;
920
921 return \$output;
922 }
923
924 # it's true, baby ;-)
925
926 1;
927
928 #
929 ### End ###

patrick-canterino.de