]> git.p6c8.net - devedit.git/blob - devedit.pl
c29c22e702e08f3e7df5d407e302561133ee42dc
[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-11-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 # Check if we are able to access the root directory
39
40 abort($config->{'errors'}->{'no_root_access'}) unless(-r $config->{'fileroot'} && -x $config->{'fileroot'});
41
42 # Read the most important form data
43
44 my $cgi = new CGI;
45
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') || '';
50
51 # Create physical and virtual path for the new file
52 # This section has to be optimized - ugh!
53
54 my $new_physical = '';
55 my $new_virtual = '';
56
57 if($newfile ne '' && $newfile !~ /^\s+$/)
58 {
59 $curdir = upper_path($file) if($curdir eq '');
60 my $path = clean_path($curdir.$newfile);
61
62 # Extract file and directory name...
63
64 my $file = file_name($path);
65 my $dir = upper_path($path);
66
67 # ... check if the directory exists ...
68
69 unless(-d clean_path($config->{'fileroot'}."/".$dir))
70 {
71 abort($config->{'errors'}->{'dir_not_exist'});
72 }
73
74 # ... and check if the path is above the root directory
75
76 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
77 {
78 abort($config->{'errors'}->{'create_ar'});
79 }
80
81 # Create the physical and the virtual path
82
83 $new_physical = File::Spec->canonpath($new_physical."/".$file);
84 $new_virtual .= $file;
85 }
86
87 # This check has to be performed first or abs_path() will be confused
88
89 if(-e clean_path($config->{'fileroot'}."/".$file))
90 {
91 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
92 {
93 # Create a File::UseList object and load the list
94
95 my $uselist = new File::UseList(listfile => $config->{'uselist_file'},
96 lockfile => $config->{'lock_file'},
97 timeout => $config->{'lock_timeout'});
98
99 $uselist->lock or abort($config->{'errors'}->{'lock_failed'},{USELIST => $config->{'uselist_file'}, LOCK_FILE => $config->{'lock_file'}});
100 $uselist->load;
101
102 # Create a hash with data submitted by user
103 # (some other necessary information will also be included)
104
105 my %data = (physical => $physical,
106 virtual => $virtual,
107 new_physical => $new_physical,
108 new_virtual => $new_virtual,
109 uselist => $uselist,
110 cgi => $cgi,
111 version => $VERSION,
112 configfile => CONFIGFILE);
113
114 my $output = exec_command($command,\%data,$config); # Execute the command...
115
116 $uselist->unlock; # ... unlock the list with files in use...
117 print $$output; # ... and show the output of the command
118 }
119 else
120 {
121 abort($config->{'errors'}->{'above_root'});
122 }
123 }
124 else
125 {
126 abort($config->{'errors'}->{'not_exist'});
127 }
128
129 #
130 ### End ###

patrick-canterino.de