X-Git-Url: https://git.p6c8.net/devedit.git/blobdiff_plain/1fbf10bec35aeb289a9cf3e1c65a826883bffdea..3b69a56ae05c5a9f8de83528657cefd784c95a8f:/modules/Config/DevEdit.pm?ds=sidebyside diff --git a/modules/Config/DevEdit.pm b/modules/Config/DevEdit.pm index c387514..e851ee8 100644 --- a/modules/Config/DevEdit.pm +++ b/modules/Config/DevEdit.pm @@ -6,7 +6,15 @@ package Config::DevEdit; # Read and parse the configuration files # # Author: Patrick Canterino -# Last modified: 2005-06-09 +# Last modified: 2010-12-24 +# +# Copyright (C) 1999-2000 Roland Bluethgen, Frank Schoenmann +# Copyright (C) 2003-2011 Patrick Canterino +# All Rights Reserved. +# +# This file can be distributed and/or modified under the terms of +# of the Artistic License 1.0 (see also the LICENSE file found at +# the top level of the Dev-Editor distribution). # use strict; @@ -22,6 +30,15 @@ use base qw(Exporter); @EXPORT = qw(read_config); +# This variable contains some dependencies for the "disable_commands" +# configuration option. +# The Hash key defines a command, the value is an Array Reference or String +# defining the commands that will also be disabled. + +my %disable_dependency = ('beginedit' => 'endedit', + 'remove' => 'remove_multi', + '@write' => ['beginedit','endedit','copy','rename','remove','remove_multi','mkdir','mkfile','upload','chprop']); + # read_config() # # Read the configuration files of Dev-Editor @@ -39,6 +56,46 @@ sub read_config($) $config->{'errors'} = parse_config($config->{'error_file'}); $config->{'templates'} = parse_config($config->{'template_file'}); + # Check if we have to parse the user config file + + if($ENV{'REMOTE_USER'} && $config->{'userconf_file'} && -f $config->{'userconf_file'}) + { + my $userconf = parse_config($config->{'userconf_file'}); + + # Parse aliases (we use references, so we won't get a memory + # problem so soon...) + + foreach my $user(keys(%$userconf)) + { + if(my $aliases = $userconf->{$user}->{'aliases'}) + { + foreach my $alias(parse_line('\s+',0,$aliases)) + { + $userconf->{$alias} = $userconf->{$user} unless($userconf->{$alias}); + } + } + } + + if($userconf->{$ENV{'REMOTE_USER'}}) + { + # The current HTTP Auth user has got an individual configuration + # Overwrite the default values + + my $new_conf = $userconf->{$ENV{'REMOTE_USER'}}; + + $config->{'fileroot'} = $new_conf->{'fileroot'} if($new_conf->{'fileroot'}); + $config->{'httproot'} = $new_conf->{'httproot'} if($new_conf->{'httproot'}); + $config->{'startdir'} = $new_conf->{'startdir'} if($new_conf->{'startdir'}); + + $config->{'forbidden'} = $new_conf->{'forbidden'} if(defined $new_conf->{'forbidden'}); + $config->{'disable_commands'} = $new_conf->{'disable_commands'} if(defined $new_conf->{'disable_commands'}); + + $config->{'hide_dot_files'} = $new_conf->{'hide_dot_files'} if(defined $new_conf->{'hide_dot_files'}); + + $config->{'user_config'} = 1; + } + } + # Parse list of forbidden files if($config->{'forbidden'}) @@ -57,6 +114,40 @@ sub read_config($) $config->{'forbidden'} = \@files; } + else + { + $config->{'forbidden'} = []; + } + + # Parse list of disabled commands (we need some universal code!) + + if($config->{'disable_commands'}) + { + my @commands; + + foreach my $command(parse_line('\s+',0,$config->{'disable_commands'})) + { + push(@commands,$command) unless(substr($command,0,1) eq '@'); + + if(exists($disable_dependency{$command}) && $disable_dependency{$command}) + { + if(ref($disable_dependency{$command}) eq 'ARRAY') + { + push(@commands,@{$disable_dependency{$command}}); + } + else + { + push(@commands,$disable_dependency{$command}); + } + } + } + + $config->{'disable_commands'} = \@commands; + } + else + { + $config->{'disable_commands'} = []; + } return $config; } @@ -81,26 +172,48 @@ sub parse_config($) my @lines = split(/\015\012|\012|\015/,$data); my $config = {}; my $count = 0; + my $sect; foreach my $line(@lines) { $count++; next if($line =~ /^\s*#/); - next if($line !~ /^\s*\S+\s*=.*$/); - my ($key,$value) = split(/=/,$line,2); + if($line =~ /^\s*\[(\S+)\]\s*$/) + { + # Switch to new section + + $sect = $1; + } + elsif($line =~ /^\s*\S+\s*=.*$/) + { + # A normal "key = value" line + + my ($key,$value) = split(/=/,$line,2); + + # Remove whitespaces at the beginning and at the end - # Remove whitespaces at the beginning and at the end + $key =~ s/^\s+//g; + $key =~ s/\s+$//g; + $value =~ s/^\s+//g; + $value =~ s/\s+$//g; - $key =~ s/^\s+//g; - $key =~ s/\s+$//g; - $value =~ s/^\s+//g; - $value =~ s/\s+$//g; + if($sect) + { + $config->{$sect} = {} if(ref($config->{$sect}) ne 'HASH'); - croak "Configuration option '$key' defined twice in line $count of configuration file '$file'" if($config->{$key}); + croak "Configuration option '$key' of section '$sect' defined twice in line $count of configuration file '$file'" if($config->{$sect}->{$key}); - $config->{$key} = $value; + $config->{$sect}->{$key} = $value; + } + else + { + croak "Configuration option '$key' defined twice in line $count of configuration file '$file'" if($config->{$key}); + + $config->{$key} = $value; + } + } } return $config;