]>
git.p6c8.net - devedit.git/blob - devedit.pl
2f9c9184cf9a17cc1198103c60a57c95235dec02
1 #!C:/Programme/Perl/bin/perl.exe -w
6 # Dev-Editor's main program
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2005-02-13
13 use CGI
::Carp
qw(fatalsToBrowser);
15 use vars
qw($VERSION);
28 # Path to configuration file
29 # Change if necessary!
31 use constant CONFIGFILE => 'devedit.dat';
33 # Read the configuration file
35 my $config = read_config(CONFIGFILE);
36 error_template($config->{'templates'}->{'error'}); # Yes, I'm lazy...
38 # Check if the root directory exists
40 abort($config->{'errors'}->{'no_root_dir'}) unless(-d $config->{'fileroot'});
42 # Check if we are able to access the root directory
44 abort($config->{'errors'}->{'no_root_access'}) unless(-r $config->{'fileroot'} && -x $config->{'fileroot'});
46 # Read the most important form data
50 my $command = $cgi->param('command') || 'show';
51 my $file = $cgi->param('file') || '/';
52 my $curdir = $cgi->param('curdir') || '';
53 my $newfile = $cgi->param('newfile') || '';
55 # Create physical and virtual path for the new file
57 my $new_physical = '';
60 if($newfile ne '' && $newfile !~ /^\s+$/)
62 $curdir = upper_path($file) if($curdir eq '');
63 my $path = $curdir.'/'.$newfile;
65 # Extract file and directory name...
67 my $file = file_name($path);
68 my $dir = upper_path($path);
70 # ... check if the directory exists ...
72 unless(-d clean_path($config->{'fileroot'}.'/'.$dir))
74 abort($config->{'errors'}->{'dir_not_exist'},'/');
77 # (don't know, why this test has to be done separately)
79 if(-l clean_path($config->{'fileroot'}.'/'.$dir))
81 abort($config->{'errors'}->{'dir_not_exist'},'/');
84 # ... and check if the path is above the root directory
86 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
88 abort($config->{'errors'}->{'create_ar'},'/');
91 # Check if we have enough permissions to create a file
94 unless(-r $new_physical && -w $new_physical && -x $new_physical)
96 abort($config->{'errors'}->{'dir_no_create'},'/',{DIR => $new_virtual});
99 # Create the physical and the virtual path
101 $new_physical = File::Spec->canonpath($new_physical.'/'.$file);
102 $new_virtual .= $file;
105 # This check has to be performed first or abs_path() will be confused
107 if(-e clean_path($config->{'fileroot'}.'/'.$file) || -l clean_path($config->{'fileroot'}.'/'.$file))
109 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
111 # Create a File::UseList object and load the list
113 my $uselist = new File::UseList(listfile => $config->{'uselist_file'},
114 lockfile => $config->{'lock_file'},
115 timeout => $config->{'lock_timeout'});
117 $uselist->lock or abort($config->{'errors'}->{'lock_failed'},undef,{USELIST => $uselist->{'listfile'}, LOCK_FILE => $uselist->{'lockfile'}});
120 # Create a hash containing data submitted by the user
121 # (some other necessary information are also included)
123 my %data = (physical => $physical,
125 new_physical => $new_physical,
126 new_virtual => $new_virtual,
130 configfile => CONFIGFILE);
132 # Execute the command...
134 my $output = exec_command($command,\%data,$config);
136 # ... unlock the list with files in use and show the output of the command
138 $uselist->unlock or abort($config->{'errors'}->{'unlock_failed'},undef,{USELIST => $uselist->{'listfile'}, LOCK_FILE => $uselist->{'lockfile'}});
143 abort($config->{'errors'}->{'above_root'},'/');
148 abort($config->{'errors'}->{'not_exist'},'/');
patrick-canterino.de