]> git.p6c8.net - devedit.git/blob - devedit.pl
543d2203cf188eddb930dc7a203bedc4a834e948
[devedit.git] / devedit.pl
1 #!C:/Programme/Perl/bin/perl.exe -w
2
3 #
4 # Dev-Editor 2.0 (CVS)
5 #
6 # Dev-Editor's main program
7 #
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2004-03-06
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.0 (CVS)';
27
28 use constant CONFIGFILE => 'devedit.dat';
29
30 # Read the configuration file
31
32 my $config = read_config(CONFIGFILE);
33 error_template($config->{'tpl_error'}); # Yes, I'm lazy...
34
35 # Read the most important form data
36
37 my $cgi = new CGI;
38
39 my $command = $cgi->param('command') || 'show';
40 my $file = $cgi->param('file') || '/';
41 my $curdir = $cgi->param('curdir') || '';
42 my $newfile = $cgi->param('newfile') || '';
43
44 # Create physical and virtual path for the new file
45 # This section has to be optimized - ugh!
46
47 my $new_physical = '';
48 my $new_virtual = '';
49
50 if($newfile ne '')
51 {
52 $curdir = upper_path($file) if($curdir eq '');
53 my $path = clean_path($curdir.$newfile);
54
55 # Extract file and directory name...
56
57 my $file = file_name($path);
58 my $dir = upper_path($path);
59
60 # ... check if the directory exists ...
61
62 unless(-d clean_path($config->{'fileroot'}."/".$dir))
63 {
64 abort($config->{'err_dir_not_exist'});
65 }
66
67 # ... and check if the path is above the root directory
68
69 unless(($new_physical,$new_virtual) = check_path($config->{'fileroot'},$dir))
70 {
71 abort($config->{'err_create_ar'});
72 }
73
74 # Create the physical and the virtual path
75
76 $new_physical = File::Spec->canonpath($new_physical."/".$file);
77 $new_virtual .= $file;
78 }
79
80 # This check has to be performed first, or abs_path() will be confused
81
82 if(-e clean_path($config->{'fileroot'}."/".$file))
83 {
84 if(my ($physical,$virtual) = check_path($config->{'fileroot'},$file))
85 {
86 # Create a File::UseList object and load the list
87
88 my $uselist = new File::UseList(listfile => $config->{'uselist_file'},
89 lockfile => $config->{'lock_file'},
90 timeout => $config->{'lock_timeout'});
91
92 $uselist->lock or abort($config->{'err_lock_failed'},{USELIST => $config->{'uselist_file'}, LOCK_FILE => $config->{'lock_file'}});
93 $uselist->load;
94
95 # Create a hash with data submitted by user
96 # (some other necessary information will also be included)
97
98 my %data = (physical => $physical,
99 virtual => $virtual,
100 new_physical => $new_physical,
101 new_virtual => $new_virtual,
102 uselist => $uselist,
103 cgi => $cgi,
104 version => $VERSION,
105 configfile => CONFIGFILE);
106
107 my $output = exec_command($command,\%data,$config); # Execute the command...
108
109 $uselist->unlock; # ... unlock the list with files in use...
110 print $$output; # ... and print the output of the command
111 }
112 else
113 {
114 abort($config->{'err_above_root'});
115 }
116 }
117 else
118 {
119 abort($config->{'err_not_exist'});
120 }
121
122 #
123 ### End ###

patrick-canterino.de