]>
git.p6c8.net - devedit.git/blob - modules/Config/DevEdit.pm
1 package Config
::DevEdit
;
4 # Dev-Editor - Module Config::DevEdit
6 # Read and parse the configuration files
8 # Author: Patrick Canterino <patrick@patshaping.de>
9 # Last modified: 2010-12-24
11 # Copyright (C) 1999-2000 Roland Bluethgen, Frank Schoenmann
12 # Copyright (C) 2003-2009 Patrick Canterino
13 # All Rights Reserved.
15 # This file can be distributed and/or modified under the terms of
16 # of the Artistic License 1.0 (see also the LICENSE file found at
17 # the top level of the Dev-Editor distribution).
29 use base
qw(Exporter);
31 @EXPORT = qw(read_config);
33 # This variable contains some dependencies for the "disable_commands"
34 # configuration option.
35 # The Hash key defines a command, the value is an Array Reference or String
36 # defining the commands that will also be disabled.
38 my %disable_dependency = ('beginedit' => 'endedit',
39 'remove' => 'remove_multi',
40 '@write' => ['beginedit','endedit','copy','rename','remove','remove_multi','mkdir','mkfile','upload','chprop']);
44 # Read the configuration files of Dev-Editor
46 # Params: Path to main configuration file
48 # Return: Configuration (Hash Reference)
54 my $config = parse_config
($file);
56 $config->{'errors'} = parse_config
($config->{'error_file'});
57 $config->{'templates'} = parse_config
($config->{'template_file'});
59 # Check if we have to parse the user config file
61 if($ENV{'REMOTE_USER'} && $config->{'userconf_file'} && -f
$config->{'userconf_file'})
63 my $userconf = parse_config
($config->{'userconf_file'});
65 # Parse aliases (we use references, so we won't get a memory
68 foreach my $user(keys(%$userconf))
70 if(my $aliases = $userconf->{$user}->{'aliases'})
72 foreach my $alias(parse_line
('\s+',0,$aliases))
74 $userconf->{$alias} = $userconf->{$user} unless($userconf->{$alias});
79 if($userconf->{$ENV{'REMOTE_USER'}})
81 # The current HTTP Auth user has got an individual configuration
82 # Overwrite the default values
84 my $new_conf = $userconf->{$ENV{'REMOTE_USER'}};
86 $config->{'fileroot'} = $new_conf->{'fileroot'} if($new_conf->{'fileroot'});
87 $config->{'httproot'} = $new_conf->{'httproot'} if($new_conf->{'httproot'});
88 $config->{'startdir'} = $new_conf->{'startdir'} if($new_conf->{'startdir'});
90 $config->{'forbidden'} = $new_conf->{'forbidden'} if(defined $new_conf->{'forbidden'});
91 $config->{'disable_commands'} = $new_conf->{'disable_commands'} if(defined $new_conf->{'disable_commands'});
93 $config->{'hide_dot_files'} = $new_conf->{'hide_dot_files'} if(defined $new_conf->{'hide_dot_files'});
95 $config->{'user_config'} = 1;
99 # Parse list of forbidden files
101 if($config->{'forbidden'})
105 foreach my $file(parse_line
('\s+',0,$config->{'forbidden'}))
109 $file = '/'.$file unless($file =~ m
!^/!);
115 $config->{'forbidden'} = \
@files;
119 $config->{'forbidden'} = [];
122 # Parse list of disabled commands (we need some universal code!)
124 if($config->{'disable_commands'})
128 foreach my $command(parse_line
('\s+',0,$config->{'disable_commands'}))
130 push(@commands,$command) unless(substr($command,0,1) eq '@');
132 if(exists($disable_dependency{$command}) && $disable_dependency{$command})
134 if(ref($disable_dependency{$command}) eq 'ARRAY')
136 push(@commands,@
{$disable_dependency{$command}});
140 push(@commands,$disable_dependency{$command});
145 $config->{'disable_commands'} = \
@commands;
149 $config->{'disable_commands'} = [];
157 # Parse a configuration file
159 # Params: Path to configuration file
161 # Return: Configuration (Hash Reference)
168 open(CF
,'<'.$file) or croak
("Open $file: $!");
169 read(CF
, my $data, -s
$file);
172 my @lines = split(/\015\012|\012|\015/,$data);
177 foreach my $line(@lines)
181 next if($line =~ /^\s*#/);
183 if($line =~ /^\s*\[(\S+)\]\s*$/)
185 # Switch to new section
189 elsif($line =~ /^\s*\S+\s*=.*$/)
191 # A normal "key = value" line
193 my ($key,$value) = split(/=/,$line,2);
195 # Remove whitespaces at the beginning and at the end
204 $config->{$sect} = {} if(ref($config->{$sect}) ne 'HASH');
206 croak
"Configuration option '$key' of section '$sect' defined twice in line $count of configuration file '$file'" if($config->{$sect}->{$key});
208 $config->{$sect}->{$key} = $value;
212 croak
"Configuration option '$key' defined twice in line $count of configuration file '$file'" if($config->{$key});
214 $config->{$key} = $value;
222 # it's true, baby ;-)
patrick-canterino.de