]>
git.p6c8.net - devedit.git/blob - devedit.pl
d9e146ea01a11be8a2d128002f1fe2f4b63637c8
1 #!C:/Programme/Perl/bin/perl.exe -w
6 # Dev-Editor's main program
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2004-11-26
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
56 # This section has to be optimized - ugh!
58 my $new_physical = '';
61 if($newfile ne '' && $newfile !~ /^\s+$/)
63 $curdir = upper_path($file) if($curdir eq '');
64 my $path = clean_path($curdir.$newfile);
66 # Extract file and directory name...
68 my $file = file_name($path);
69 my $dir = upper_path($path);
71 # ... check if the directory exists ...
73 unless(-d clean_path($config->{'fileroot'}."/".$dir))
75 abort($config->{'errors'}->{'dir_not_exist'},"/");
78 # ... and check if the path is above the root directory
80 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
82 abort($config->{'errors'}->{'create_ar'},"/");
85 # Check if we have enough permissions to create a file
88 unless(-r $new_physical && -w $new_physical && -x $new_physical)
90 abort($config->{'errors'}->{'dir_no_create'},"/",{DIR => $new_virtual});
93 # Create the physical and the virtual path
95 $new_physical = File::Spec->canonpath($new_physical."/".$file);
96 $new_virtual .= $file;
99 # This check has to be performed first or abs_path() will be confused
101 if(-e clean_path($config->{'fileroot'}."/".$file))
103 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
105 # Create a File::UseList object and load the list
107 my $uselist = new File::UseList(listfile => $config->{'uselist_file'},
108 lockfile => $config->{'lock_file'},
109 timeout => $config->{'lock_timeout'});
111 $uselist->lock or abort($config->{'errors'}->{'lock_failed'},undef,{USELIST => $config->{'uselist_file'}, LOCK_FILE => $config->{'lock_file'}});
114 # Create a hash with data submitted by user
115 # (some other necessary information will also be included)
117 my %data = (physical => $physical,
119 new_physical => $new_physical,
120 new_virtual => $new_virtual,
124 configfile => CONFIGFILE);
126 my $output = exec_command($command,\%data,$config); # Execute the command...
128 $uselist->unlock; # ... unlock the list with files in use...
129 print $$output; # ... and show the output of the command
133 abort($config->{'errors'}->{'above_root'},"/");
138 abort($config->{'errors'}->{'not_exist'},"/");
patrick-canterino.de