]> git.p6c8.net - devedit.git/blob - devedit.pl
Removed the $VERSION variable. The version number of Dev-Editor is now found in the...
[devedit.git] / devedit.pl
1 #!C:/Programme/Perl/bin/perl.exe -w
2
3 #
4 # Dev-Editor 1.1
5 #
6 # Dev-Editor's main program
7 #
8 # Author: Patrick Canterino <patshaping@gmx.net>
9 # Last modified: 2003-10-18
10 #
11
12 use strict;
13 use CGI::Carp qw(fatalsToBrowser);
14
15 use vars qw(%config);
16
17 use lib 'modules';
18
19 use CGI;
20 use Command;
21 use File::UseList;
22 use Output;
23 use Tool;
24
25 ### Settings ###
26
27 %config = (
28 fileroot => 'D:/Server/WWW/dokumente/devedit-test',
29 httproot => '/devedit-test/',
30 timeformat => '%d.%m.%Y %H:%M',
31 uselist_file => 'uselist',
32 lock_file => 'uselist.lock',
33 lock_timeout => '10'
34 );
35
36 ### End Settings ###
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 '')
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("The directory where you want to create this file or directory doesn't 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("You aren't allowed to create files and directories above the virtual root directory.");
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 # Copied from old Dev-Editor (great idea)
90
91 my %dispatch = ('show' => \&exec_show,
92 'beginedit' => \&exec_beginedit,
93 'canceledit' => \&exec_unlock,
94 'endedit' => \&exec_endedit,
95 'mkdir' => \&exec_mkdir,
96 'mkfile' => \&exec_mkfile,
97 'workwithfile' => \&exec_workwithfile,
98 'copy' => \&exec_copy,
99 'rename' => \&exec_rename,
100 'remove' => \&exec_remove,
101 'unlock' => \&exec_unlock
102 );
103
104 # Create a File::UseList object and load the list
105
106 my $uselist = new File::UseList(listfile => $config{'uselist_file'},
107 lockfile => $config{'lock_file'},
108 timeout => $config{'lock_timeout'});
109
110 $uselist->lock or abort("Locking of $config{'uselist_file'} failed. Try it again in a moment. If the problem persists, ask someone to recreate the lock file ($config{'lock_file'}).");
111 $uselist->load;
112
113 # Create a hash with data submitted by user
114 # (the CGI and the File::UseList object will also be included)
115
116 my %data = (physical => $physical,
117 virtual => $virtual,
118 new_physical => $new_physical,
119 new_virtual => $new_virtual,
120 uselist => $uselist,
121 cgi => $cgi);
122
123 unless($dispatch{$command})
124 {
125 $uselist->unlock;
126 abort("Unknown command: $command");
127 }
128
129 my $output = &{$dispatch{$command}}(\%data,\%config); # Execute the command...
130
131 $uselist->unlock; # ... unlock the list with files in use...
132 print $$output; # ... and print the output of the command
133 }
134 else
135 {
136 abort("Accessing files and directories above the virtual root directory is forbidden.");
137 }
138 }
139 else
140 {
141 abort("File/directory does not exist.");
142 }
143
144 #
145 ### End ###

patrick-canterino.de