]> git.p6c8.net - devedit.git/blob - devedit.pl
- There is no need to load the POSIX module twice
[devedit.git] / devedit.pl
1 #!C:/Programme/Perl/bin/perl.exe -w
2
3 #
4 # Dev-Editor 2.1a
5 #
6 # Dev-Editor's main program
7 #
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2004-10-04
10 #
11
12 use strict;
13 use CGI::Carp qw(fatalsToBrowser);
14
15 use vars qw($VERSION);
16 use lib 'modules';
17
18 use CGI;
19 use Config::DevEdit;
20 use File::UseList;
21
22 use Command;
23 use Output;
24 use Tool;
25
26 $VERSION = '2.1a';
27
28 # Path to configuration file
29 # Change if necessary!
30
31 use constant CONFIGFILE => 'devedit.dat';
32
33 # Read the configuration file
34
35 my $config = read_config(CONFIGFILE);
36 error_template($config->{'templates'}->{'error'}); # Yes, I'm lazy...
37
38 # Read the most important form data
39
40 my $cgi = new CGI;
41
42 my $command = $cgi->param('command') || 'show';
43 my $file = $cgi->param('file') || '/';
44 my $curdir = $cgi->param('curdir') || '';
45 my $newfile = $cgi->param('newfile') || '';
46
47 # Create physical and virtual path for the new file
48 # This section has to be optimized - ugh!
49
50 my $new_physical = '';
51 my $new_virtual = '';
52
53 if($newfile ne '' && $newfile !~ /^\s+$/)
54 {
55 $curdir = upper_path($file) if($curdir eq '');
56 my $path = clean_path($curdir.$newfile);
57
58 # Extract file and directory name...
59
60 my $file = file_name($path);
61 my $dir = upper_path($path);
62
63 # ... check if the directory exists ...
64
65 unless(-d clean_path($config->{'fileroot'}."/".$dir))
66 {
67 abort($config->{'errors'}->{'dir_not_exist'});
68 }
69
70 # ... and check if the path is above the root directory
71
72 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
73 {
74 abort($config->{'errors'}->{'create_ar'});
75 }
76
77 # Create the physical and the virtual path
78
79 $new_physical = File::Spec->canonpath($new_physical."/".$file);
80 $new_virtual .= $file;
81 }
82
83 # This check has to be performed first or abs_path() will be confused
84
85 if(-e clean_path($config->{'fileroot'}."/".$file))
86 {
87 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
88 {
89 # Create a File::UseList object and load the list
90
91 my $uselist = new File::UseList(listfile => $config->{'uselist_file'},
92 lockfile => $config->{'lock_file'},
93 timeout => $config->{'lock_timeout'});
94
95 $uselist->lock or abort($config->{'errors'}->{'lock_failed'},{USELIST => $config->{'uselist_file'}, LOCK_FILE => $config->{'lock_file'}});
96 $uselist->load;
97
98 # Create a hash with data submitted by user
99 # (some other necessary information will also be included)
100
101 my %data = (physical => $physical,
102 virtual => $virtual,
103 new_physical => $new_physical,
104 new_virtual => $new_virtual,
105 uselist => $uselist,
106 cgi => $cgi,
107 version => $VERSION,
108 configfile => CONFIGFILE);
109
110 my $output = exec_command($command,\%data,$config); # Execute the command...
111
112 $uselist->unlock; # ... unlock the list with files in use...
113 print $$output; # ... and show the output of the command
114 }
115 else
116 {
117 abort($config->{'errors'}->{'above_root'});
118 }
119 }
120 else
121 {
122 abort($config->{'errors'}->{'not_exist'});
123 }
124
125 #
126 ### End ###

patrick-canterino.de