]>
git.p6c8.net - devedit.git/blob - devedit.pl
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
13 use CGI
::Carp
qw(fatalsToBrowser);
15 use vars
qw($VERSION);
27 # Path to configuration file
28 # Change if necessary!
30 use constant CONFIGFILE => 'devedit.conf';
32 # Read the configuration file
34 my $config = read_config(CONFIGFILE);
35 error_template($config->{'templates'}->{'error'}); # Yes, I'm lazy...
37 # Check if the root directory exists
39 abort($config->{'errors'}->{'no_root_dir'}) unless(-d $config->{'fileroot'} && not -l $config->{'fileroot'});
41 # Check if we are able to access the root directory
43 abort($config->{'errors'}->{'no_root_access'}) unless(-r $config->{'fileroot'} && -x $config->{'fileroot'});
45 # Read the most important form data
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') || '';
54 # Create physical and virtual path for the new file
56 my $new_physical = '';
59 if($newfile ne '' && $newfile !~ /^\s+$/)
61 my $path = $curdir.'/'.$newfile;
63 # Extract file and directory name...
65 my $file = file_name($path);
66 my $dir = upper_path($path);
68 # ... check if the directory exists ...
70 my $temp_path = clean_path($config->{'fileroot'}.'/'.$dir);
72 unless(-d $temp_path && not -l $temp_path)
74 abort($config->{'errors'}->{'dir_not_exist'},'/');
77 # ... and check if the path is above the root directory
79 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
81 abort($config->{'errors'}->{'create_above_root'},'/');
84 # Check if we have enough permissions to create a file
87 unless(-r $new_physical && -w $new_physical && -x $new_physical)
89 abort($config->{'errors'}->{'dir_no_create'},'/',{DIR => encode_html($new_virtual)});
92 # Create the physical and the virtual path
94 $new_physical = File::Spec->canonpath($new_physical.'/'.$file);
95 $new_virtual .= $file;
97 # Check if accessing this file is forbidden
99 if(is_forbidden_file($config->{'forbidden'},$new_virtual))
101 abort($config->{'errors'}->{'forbidden_file'},'/');
105 # This check has to be performed first or abs_path() will be confused
107 my $temp_path = clean_path($config->{'fileroot'}.'/'.$file);
109 if(-e $temp_path || -l $temp_path)
111 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
113 if(is_forbidden_file($config->{'forbidden'},$virtual))
115 abort($config->{'errors'}->{'forbidden_file'},'/');
119 # Create a hash containing data submitted by the user
120 # (some other necessary information are also included)
122 my %data = (physical => $physical,
124 new_physical => $new_physical,
125 new_virtual => $new_virtual,
128 configfile => CONFIGFILE);
130 # Execute the command...
132 my $output = exec_command($command,\%data,$config);
134 # ... and show its output
141 abort($config->{'errors'}->{'above_root'},'/');
146 abort($config->{'errors'}->{'not_found'},'/');
patrick-canterino.de