]> git.p6c8.net - devedit.git/blob - devedit.pl
Now, we are using an extern configuration file.
[devedit.git] / devedit.pl
1 #!C:/Programme/Perl/bin/perl.exe -w
2
3 #
4 # Dev-Editor 1.2
5 #
6 # Dev-Editor's main program
7 #
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2004-01-16
10 #
11
12 use strict;
13 use CGI::Carp qw(fatalsToBrowser);
14
15 use lib 'modules';
16
17 use CGI;
18 use Config::DevEdit;
19 use File::UseList;
20
21 use Command;
22 use Output;
23 use Tool;
24
25 use constant CONFIGFILE => 'devedit.dat';
26
27 # Read the configuration file
28
29 my $config = read_config(CONFIGFILE);
30
31 # Read the most important form data
32
33 my $cgi = new CGI;
34
35 my $command = $cgi->param('command') || 'show';
36 my $file = $cgi->param('file') || '/';
37 my $curdir = $cgi->param('curdir') || '';
38 my $newfile = $cgi->param('newfile') || '';
39
40 # Create physical and virtual path for the new file
41 # This section has to be optimized - ugh!
42
43 my $new_physical = '';
44 my $new_virtual = '';
45
46 if($newfile ne '')
47 {
48 $curdir = upper_path($file) if($curdir eq '');
49 my $path = clean_path($curdir.$newfile);
50
51 # Extract file and directory name...
52
53 my $file = file_name($path);
54 my $dir = upper_path($path);
55
56 # ... check if the directory exists ...
57
58 unless(-d clean_path($config->{'fileroot'}."/".$dir))
59 {
60 abort("The directory where you want to create this file or directory doesn't exist.");
61 }
62
63 # ... and check if the path is above the root directory
64
65 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
66 {
67 abort("You aren't allowed to create files and directories above the virtual root directory.");
68 }
69
70 # Create the physical and the virtual path
71
72 $new_physical = File::Spec->canonpath($new_physical."/".$file);
73 $new_virtual .= $file;
74 }
75
76 # This check has to be performed first, or abs_path() will be confused
77
78 if(-e clean_path($config->{'fileroot'}."/".$file))
79 {
80 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
81 {
82 # Create a File::UseList object and load the list
83
84 my $uselist = new File::UseList(listfile => $config->{'uselist_file'},
85 lockfile => $config->{'lock_file'},
86 timeout => $config->{'lock_timeout'});
87
88 $uselist->lock or abort("Locking of $config->{'uselist_file'} failed. Try it again in a moment. If the problem persists, ask someone to recreate the lock file ($config->{'lock_file'}).");
89 $uselist->load;
90
91 # Create a hash with data submitted by user
92 # (the CGI and the File::UseList object will also be included)
93
94 my %data = (physical => $physical,
95 virtual => $virtual,
96 new_physical => $new_physical,
97 new_virtual => $new_virtual,
98 uselist => $uselist,
99 cgi => $cgi);
100
101 my $output = exec_command($command,\%data,$config); # Execute the command...
102
103 $uselist->unlock; # ... unlock the list with files in use...
104 print $$output; # ... and print the output of the command
105 }
106 else
107 {
108 abort("Accessing files and directories above the virtual root directory is forbidden.");
109 }
110 }
111 else
112 {
113 abort("File/directory does not exist.");
114 }
115
116 #
117 ### End ###

patrick-canterino.de