]>
git.p6c8.net - devedit.git/blob - devedit.pl
d74a1bce0716a3e8f91ef9bd08c79af9164befde
1 #!C:/Programme/Perl/bin/perl.exe -w
6 # Dev-Editor's main program
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2006-08-24
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 # Create physical and virtual path for the new file
64 my $new_physical = '';
67 if($newfile ne '' && $newfile !~ /^\s+$/)
69 my $path = $curdir.'/'.$newfile;
71 # Extract file and directory name...
73 my $file = file_name($path);
74 my $dir = upper_path($path);
76 # ... check if the directory exists ...
78 my $temp_path = clean_path($config->{'fileroot'}.'/'.$dir);
80 unless(-d $temp_path && not -l $temp_path)
82 abort($config->{'errors'}->{'dir_not_exist'},'/');
85 # ... and check if the path is above the root directory
87 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
89 abort($config->{'errors'}->{'create_above_root'},'/');
92 # Check if we have enough permissions to create a file
95 unless(-r $new_physical && -w $new_physical && -x $new_physical)
97 abort($config->{'errors'}->{'dir_no_create'},'/',{DIR => encode_html($new_virtual)});
100 # Create the physical and the virtual path
102 $new_physical = File::Spec->canonpath($new_physical.'/'.$file);
103 $new_virtual .= $file;
105 # Check if accessing this file is forbidden
107 if(is_forbidden_file($config->{'forbidden'},$new_virtual))
109 abort($config->{'errors'}->{'forbidden_file'},'/');
113 # This check has to be performed first or abs_path() will be confused
115 my $temp_path = clean_path($config->{'fileroot'}.'/'.$file);
117 if(-e $temp_path || -l $temp_path)
119 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
121 if(is_forbidden_file($config->{'forbidden'},$virtual))
123 abort($config->{'errors'}->{'forbidden_file'},'/');
127 # Create a hash containing data submitted by the user
128 # (some other necessary information are also included)
130 my %data = (physical => $physical,
132 new_physical => $new_physical,
133 new_virtual => $new_virtual,
136 configfile => CONFIGFILE);
138 # Execute the command...
140 my $output = exec_command($command,\%data,$config);
142 # ... and show its output
149 abort($config->{'errors'}->{'above_root'},'/');
154 abort($config->{'errors'}->{'not_found'},'/');
patrick-canterino.de