]> git.p6c8.net - devedit.git/blob - devedit.pl
*wargl*
[devedit.git] / devedit.pl
1 #!C:/Programme/Perl/bin/perl.exe -w
2
3 #
4 # Dev-Editor 3.0 (CVS)
5 #
6 # Dev-Editor's main program
7 #
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2005-06-14
10 #
11
12 use strict;
13 use CGI::Carp qw(fatalsToBrowser);
14
15 use vars qw($VERSION);
16 use lib 'modules';
17
18 use CGI;
19 use Config::DevEdit;
20
21 use Command;
22 use Output;
23 use Tool;
24
25 $VERSION = '3.0 (CVS)';
26
27 # Path to configuration file
28 # Change if necessary!
29
30 use constant CONFIGFILE => 'devedit.conf';
31
32 # Read the configuration file
33
34 my $config = read_config(CONFIGFILE);
35 error_template($config->{'templates'}->{'error'}); # Yes, I'm lazy...
36
37 # Check if the root directory exists
38
39 abort($config->{'errors'}->{'no_root_dir'}) unless(-d $config->{'fileroot'} && not -l $config->{'fileroot'});
40
41 # Check if we are able to access the root directory
42
43 abort($config->{'errors'}->{'no_root_access'}) unless(-r $config->{'fileroot'} && -x $config->{'fileroot'});
44
45 # Read the most important form data
46
47 my $cgi = new CGI;
48
49 my $command = $cgi->param('command') || 'show';
50 my $file = $cgi->param('file') || '/';
51 my $curdir = $cgi->param('curdir') || '';
52 my $newfile = $cgi->param('newfile') || '';
53
54 # Create physical and virtual path for the new file
55
56 my $new_physical = '';
57 my $new_virtual = '';
58
59 if($newfile ne '' && $newfile !~ /^\s+$/)
60 {
61 $curdir = upper_path($file) if($curdir eq '');
62 my $path = $curdir.'/'.$newfile;
63
64 # Extract file and directory name...
65
66 my $file = file_name($path);
67 my $dir = upper_path($path);
68
69 # ... check if the directory exists ...
70
71 my $temp_path = clean_path($config->{'fileroot'}.'/'.$dir);
72
73 unless(-d $temp_path && not -l $temp_path)
74 {
75 abort($config->{'errors'}->{'dir_not_exist'},'/');
76 }
77
78 # ... and check if the path is above the root directory
79
80 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
81 {
82 abort($config->{'errors'}->{'create_above_root'},'/');
83 }
84
85 # Check if we have enough permissions to create a file
86 # in this directory
87
88 unless(-r $new_physical && -w $new_physical && -x $new_physical)
89 {
90 abort($config->{'errors'}->{'dir_no_create'},'/',{DIR => encode_html($new_virtual)});
91 }
92
93 # Create the physical and the virtual path
94
95 $new_physical = File::Spec->canonpath($new_physical.'/'.$file);
96 $new_virtual .= $file;
97
98 # Check if accessing this file is forbidden
99
100 if(is_forbidden_file($config->{'forbidden'},$new_virtual))
101 {
102 abort($config->{'errors'}->{'forbidden_file'},'/');
103 }
104 }
105
106 # This check has to be performed first or abs_path() will be confused
107
108 my $temp_path = clean_path($config->{'fileroot'}.'/'.$file);
109
110 if(-e $temp_path || -l $temp_path)
111 {
112 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
113 {
114 if(is_forbidden_file($config->{'forbidden'},$virtual))
115 {
116 abort($config->{'errors'}->{'forbidden_file'},'/');
117 }
118 else
119 {
120 # Create a hash containing data submitted by the user
121 # (some other necessary information are also included)
122
123 my %data = (physical => $physical,
124 virtual => $virtual,
125 new_physical => $new_physical,
126 new_virtual => $new_virtual,
127 cgi => $cgi,
128 version => $VERSION,
129 configfile => CONFIGFILE);
130
131 # Execute the command...
132
133 my $output = exec_command($command,\%data,$config);
134
135 # ... and show its output
136
137 print $$output;
138 }
139 }
140 else
141 {
142 abort($config->{'errors'}->{'above_root'},'/');
143 }
144 }
145 else
146 {
147 abort($config->{'errors'}->{'not_found'},'/');
148 }
149
150 #
151 ### End ###

patrick-canterino.de