]>
git.p6c8.net - devedit.git/blob - devedit.pl
a868428e730dc72ca3836938bb175450e4474142
1 #!C:/Programme/Perl/bin/perl.exe -w
6 # Dev-Editor's main program
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2010-12-23
11 # Copyright (C) 1999-2000 Roland Bluethgen, Frank Schoenmann
12 # Copyright (C) 2003-2009 Patrick Canterino
13 # All Rights Reserved.
15 # This file can be distributed and/or modified under the terms of
16 # of the Artistic License 1.0 (see also the LICENSE file found at
17 # the top level of the Dev-Editor distribution).
21 use CGI
::Carp
qw(fatalsToBrowser);
23 use vars
qw($VERSION);
35 # Path to configuration file
36 # Change if necessary!
38 use constant CONFIGFILE => 'devedit.conf';
40 # Read the configuration file
42 my $config = read_config(CONFIGFILE);
43 error_template($config->{'templates'}->{'error'}); # Yes, I'm lazy...
45 # Check if the root directory exists
47 abort($config->{'errors'}->{'no_root_dir'}) unless(-d $config->{'fileroot'} && not -l $config->{'fileroot'});
49 # Check if we are able to access the root directory
51 abort($config->{'errors'}->{'no_root_access'}) unless(-r $config->{'fileroot'} && -x $config->{'fileroot'});
53 # Read the most important form data
57 my $command = $cgi->param('command') || 'show';
58 my $file = $cgi->param('file') || '/';
59 my $curdir = $cgi->param('curdir') || '';
60 my $newfile = $cgi->param('newfile') || '';
62 # Check if the command is disabled
64 if(is_disabled_command($config->{'disable_commands'},$command))
66 abort($config->{'errors'}->{'command_disabled'},'/',{COMMAND => encode_html($command)});
69 # Create physical and virtual path for the new file
71 my $new_physical = '';
74 if($newfile ne '' && $newfile !~ /^\s+$/)
76 my $path = $curdir.'/'.$newfile;
78 # Extract file and directory name...
80 my $file = file_name($path);
81 my $dir = upper_path($path);
83 # ... check if the directory exists ...
85 my $temp_path = clean_path($config->{'fileroot'}.'/'.$dir);
87 unless(-d $temp_path && not -l $temp_path)
89 abort($config->{'errors'}->{'dir_not_exist'},'/');
92 # ... and check if the path is above the root directory
94 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
96 abort($config->{'errors'}->{'create_above_root'},'/');
99 # Check if we have enough permissions to create a file
102 unless(-r $new_physical && -w $new_physical && -x $new_physical)
104 abort($config->{'errors'}->{'dir_no_create'},'/',{DIR => encode_html($new_virtual)});
107 # Create the physical and the virtual path
109 $new_physical = File::Spec->canonpath($new_physical.'/'.$file);
110 $new_virtual .= $file;
112 # Check if accessing this file is forbidden
114 if(is_forbidden_file($config->{'forbidden'},$new_virtual))
116 abort($config->{'errors'}->{'forbidden_file'},'/');
120 # This check has to be performed first or abs_path() will be confused
122 my $temp_path = clean_path($config->{'fileroot'}.'/'.$file);
124 if(-e $temp_path || -l $temp_path)
126 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
128 if(is_forbidden_file($config->{'forbidden'},$virtual))
130 abort($config->{'errors'}->{'forbidden_file'},'/');
134 # Create a hash containing data submitted by the user
135 # (some other necessary information are also included)
137 my %data = (physical => $physical,
139 new_physical => $new_physical,
140 new_virtual => $new_virtual,
143 configfile => CONFIGFILE);
145 # Execute the command...
147 my $output = exec_command($command,\%data,$config);
149 # ... and show its output
156 abort($config->{'errors'}->{'above_root'},'/');
161 abort($config->{'errors'}->{'not_found'},'/');
patrick-canterino.de