]>
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 <patshaping@gmx.net>
9 # Last modified: 2004-11-04
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 we are able to access the root directory
40 abort($config->{'errors'}->{'no_root_access'}) unless(-r $config->{'fileroot'} && -x $config->{'fileroot'});
42 # Read the most important form data
46 my $command = $cgi->param('command') || 'show';
47 my $file = $cgi->param('file') || '/';
48 my $curdir = $cgi->param('curdir') || '';
49 my $newfile = $cgi->param('newfile') || '';
51 # Create physical and virtual path for the new file
52 # This section has to be optimized - ugh!
54 my $new_physical = '';
57 if($newfile ne '' && $newfile !~ /^\s+$/)
59 $curdir = upper_path($file) if($curdir eq '');
60 my $path = clean_path($curdir.$newfile);
62 # Extract file and directory name...
64 my $file = file_name($path);
65 my $dir = upper_path($path);
67 # ... check if the directory exists ...
69 unless(-d clean_path($config->{'fileroot'}."/".$dir))
71 abort($config->{'errors'}->{'dir_not_exist'});
74 # ... and check if the path is above the root directory
76 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
78 abort($config->{'errors'}->{'create_ar'});
81 # Create the physical and the virtual path
83 $new_physical = File::Spec->canonpath($new_physical."/".$file);
84 $new_virtual .= $file;
87 # This check has to be performed first or abs_path() will be confused
89 if(-e clean_path($config->{'fileroot'}."/".$file))
91 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
93 # Create a File::UseList object and load the list
95 my $uselist = new File::UseList(listfile => $config->{'uselist_file'},
96 lockfile => $config->{'lock_file'},
97 timeout => $config->{'lock_timeout'});
99 $uselist->lock or abort($config->{'errors'}->{'lock_failed'},{USELIST => $config->{'uselist_file'}, LOCK_FILE => $config->{'lock_file'}});
102 # Create a hash with data submitted by user
103 # (some other necessary information will also be included)
105 my %data = (physical => $physical,
107 new_physical => $new_physical,
108 new_virtual => $new_virtual,
112 configfile => CONFIGFILE);
114 my $output = exec_command($command,\%data,$config); # Execute the command...
116 $uselist->unlock; # ... unlock the list with files in use...
117 print $$output; # ... and show the output of the command
121 abort($config->{'errors'}->{'above_root'});
126 abort($config->{'errors'}->{'not_exist'});
patrick-canterino.de