]> git.p6c8.net - devedit.git/blob - devedit.pl
If the user wants to view/edit a file larger than a defined size, Dev-Editor
[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-04-25
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->{'templates'}->{'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->{'errors'}->{'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->{'errors'}->{'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->{'errors'}->{'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->{'errors'}->{'above_root'});
115 }
116 }
117 else
118 {
119 abort($config->{'errors'}->{'not_exist'});
120 }
121
122 #
123 ### End ###

patrick-canterino.de