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

patrick-canterino.de