Skip Menu |

This queue is for tickets about the Config-General CPAN distribution.

Report information
The Basics
Id: 107108
Status: resolved
Priority: 0/
Queue: Config-General

People
Owner: Nobody in particular
Requestors: mario [...] prezent.nl
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Bug with UseApacheInclude for > apache 2.2 (in anyway apache 2.4)
Date: Tue, 15 Sep 2015 17:47:31 +0200
To: bug-Config-General [...] rt.cpan.org
From: Mario Jansen <mario [...] prezent.nl>
Hi, The virtualhosts of sites-enabled are not included anymore, since the new option includeoptional is used instead of include. Can you include the code below for making this to work. I tested it, it works but it is possible maybe to do it in one regular expression instead of two extra if's?. # bugfix rt.cpan.org#38635: support quoted filenames if ($this->{UseApacheInclude}) { if (/^s*includes*(["'])(.*?)(?<!\)1$/i) { $incl_file = $2; } elsif (/^s*includes+(.+?)s*$/i) { $incl_file = $1; } elsif (/^s*includeoptionals*(["'])(.*?)(?<!\)1$/i) { $incl_file = $2; } elsif (/^s*includeoptionals+(.+?)s*$/i) { $incl_file = $1; } Thanks in Advance. Regards, Mario Jansen
Hi, I could add this, but I'll not implement the apache behavior. That is, the statement would behave like a normal include: a glob may match zero files without an error, a fully specified filename would cause an error if it doesn't exist (in contrast to apache's IncludeOptional). - Tom
Subject: Re: [rt.cpan.org #107108] Bug with UseApacheInclude for > apache 2.2 (in anyway apache 2.4)
Date: Tue, 6 Oct 2015 10:12:28 +0200
To: bug-Config-General [...] rt.cpan.org
From: Mario Jansen <mario [...] prezent.nl>
Tom, I do not fully understand what you mean. How apache works with include optional is described here : http://httpd.apache.org/docs/2.4/mod/core.html#includeoptional. If apache does not find any matching config files, it will skip the entry and not read in the config files (as well as your module will and supposed to do). I can add as extra information, that above code I implemented on top of your module, which I already use in production in my script. We run this script and module with apache 2.2 as well on apache 2.4. Regards, Mario On 10/05/2015 05:54 PM, T. Linden via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=107108 > > > Hi, > > I could add this, but I'll not implement the apache behavior. That is, the statement would behave like a normal include: a glob may match zero files without an error, a fully specified filename would cause an error if it doesn't exist (in contrast to apache's IncludeOptional). > > > - Tom
Well, the module aims to *understand* apache configs (if enabled), not to *behave* like apache. So, Sys Cmd Result ------+---------------------------------+---------- C::G include /doesnt/exist fail Ap Include /doesnt/exist fail C::G include /etc/conf/*.cfg pass Ap Include /etc/conf/*.cfg pass C::G includeoptional /doesnt/exist fail <= ! Ap IncludeOptional /doesnt/exist pass C::G includeoptional /etc/conf/*.cfg pass Ap IncludeOptional /etc/conf/*.cfg pass That is, optional configs would be optional for apache, but not for C::G unless it's a glob. - Tom
Subject: Re: [rt.cpan.org #107108] Bug with UseApacheInclude for > apache 2.2 (in anyway apache 2.4)
Date: Tue, 6 Oct 2015 16:33:16 +0200
To: bug-Config-General [...] rt.cpan.org
From: Mario Jansen <mario [...] prezent.nl>
I see. I only tested with the globs indeed (this is the default in the config for /etc/apache2/sites-enabled/*.conf now). However it fails also when you load an /doesnt/exist in apache: # apache2 -v Server version: Apache/2.4.10 (Debian) Server built: Aug 28 2015 16:28:08 # ls /etc/apache2/sites-enabled/blabla.conf ls: cannot access /etc/apache2/sites-enabled/blabla.conf: No such file or directory apachectl configtest apache2: Syntax error on line 220 of /etc/apache2/apache2.conf: Could not open configuration file /etc/apache2/sites-enabled/blabla.conf: No such file or directory Action 'configtest' failed. The Apache error log may have more information. So it is consistent with the behaviour for apache for now. Mario On 10/06/2015 01:29 PM, T. Linden via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=107108 > > > Well, the module aims to *understand* apache configs (if enabled), not to *behave* like apache. > > So, > > Sys Cmd Result > ------+---------------------------------+---------- > C::G include /doesnt/exist fail > Ap Include /doesnt/exist fail > C::G include /etc/conf/*.cfg pass > Ap Include /etc/conf/*.cfg pass > C::G includeoptional /doesnt/exist fail <= ! > Ap IncludeOptional /doesnt/exist pass > C::G includeoptional /etc/conf/*.cfg pass > Ap IncludeOptional /etc/conf/*.cfg pass > > That is, optional configs would be optional for apache, but not for C::G unless it's a glob. > > > - Tom
Mario, so I re-considered the issue and came up with the patch following (attached): now, if -UseApacheInclude is enabled, "IncludeOptional" is supported. In this case the behavior would be as described earlier. However, if -IncludeGlob is enabled as well, then the behavior will be that of Apache. That is, if the file included with "IncludeOptional" does not exist, no error will be thrown. I achieved this with a little dirty hack: in such a case I just convert the filename into a glob which only matches this file, e.g.: "dir/file" => "dir/[f][i][l][e]" So, this makes "dir/file" optional, since now it is a glob, which are always optional. I'd appreciate it if you could apply the patch to the latest unmodified General.pm (best would be to use the version in SVN revision 103) and test it a little bit. Thanks in advance, Tom
Subject: include-optional-patch-103-to-104.diff
Index: General.pm =================================================================== --- General.pm (revision 103) +++ General.pm (working copy) @@ -432,13 +432,13 @@ # applied patch by AlexK fixing rt.cpan.org#41030 if ( !@include && defined $this->{ConfigPath} ) { - foreach my $dir (@{$this->{ConfigPath}}) { - my ($volume, $path, undef) = splitpath($basefile); - if ( -d catfile( $dir, $path ) ) { - push @include, grep { -f $_ } bsd_glob(catfile($dir, $basefile), GLOB_BRACE | GLOB_QUOTE); - last; - } - } + foreach my $dir (@{$this->{ConfigPath}}) { + my ($volume, $path, undef) = splitpath($basefile); + if ( -d catfile( $dir, $path ) ) { + push @include, grep { -f $_ } bsd_glob(catfile($dir, $basefile), GLOB_BRACE | GLOB_QUOTE); + last; + } + } } if (@include == 1) { @@ -722,12 +722,29 @@ # bugfix rt.cpan.org#38635: support quoted filenames if ($this->{UseApacheInclude}) { - if (/^\s*include\s*(["'])(.*?)(?<!\\)\1$/i) { - $incl_file = $2; - } - elsif (/^\s*include\s+(.+?)\s*$/i) { - $incl_file = $1; - } + my $opt = ''; + if (/^\s*(include|includeoptional)\s*(["'])(.*?)(?<!\\)\2$/i) { + $incl_file = $3; + $opt = $1; + } + elsif (/^\s*(include|includeoptional)\s+(.+?)\s*$/i) { + $incl_file = $2; + $opt = $1; + } + if ($incl_file) { + if ($this->{IncludeGlob} && $opt =~ /opt/i && $incl_file !~ /[*?\[\{\\]/) { + # fix rt#107108 + # glob enabled && optional include && file is not already a glob: + # turn it into a singular matching glob, like: + # "file" => "[f][i][l][e]" and: + # "dir/file" => "dir/[f][i][l][e]" + # which IS a glob but only matches that particular file. if it + # doesn't exist, it will be ignored by _open(), just what + # we'd like to have when using IncludeOptional. + my ($vol,$dirs,$file) = splitpath( $incl_file ); + $incl_file = catpath($vol, $dirs, join '', map { "[$_]" } split //, $file); + } + } } else { if (/^\s*<<include\s+(["'])(.+?)>>\\s*$/i) {
Subject: Re: [rt.cpan.org #107108] Bug with UseApacheInclude for > apache 2.2 (in anyway apache 2.4)
Date: Fri, 09 Oct 2015 08:39:28 +0200
To: bug-Config-General [...] rt.cpan.org
From: Mario Jansen <mario [...] prezent.nl>
It works. I tried to read the config in my script and dumped the content, it shows the vhosts of apache2.4 now. <test code> my $conf = new Config::General( -ConfigFile => "/etc/apache2/apache2.conf", -ApacheCompatible => 1, -LowerCaseNames => 1, ); print Dumper $conf; exit 0; </test code> With in the config file : IncludeOptional sites-enabled/*.conf IncludeOptional sites-enabled/doesnotexist.conf It will show all entries under sites-enabled and will not fail over doesnotexist.conf (it does not load it and will throw no error). On 2015-10-08 22:26, T. Linden via RT wrote: Show quoted text
> <URL: https://rt.cpan.org/Ticket/Display.html?id=107108 [1] > > > Mario, > > so I re-considered the issue and came up with the patch following (attached): > > now, if -UseApacheInclude is enabled, "IncludeOptional" is supported. In this case the behavior would be as described earlier. However, if -IncludeGlob is enabled as well, then the behavior will be that of Apache. That is, if the file included with "IncludeOptional" does not exist, no error will be thrown. > > I achieved this with a little dirty hack: in such a case I just convert the filename into a glob which only matches this file, e.g.: > > "dir/file" => "dir/[f][i][l][e]" > > So, this makes "dir/file" optional, since now it is a glob, which are always optional. > > I'd appreciate it if you could apply the patch to the latest unmodified General.pm (best would be to use the version in SVN revision 103) and test it a little bit. > > Thanks in advance, > Tom
-- Met vriendelijke groet, Mario Jansen Links: ------ [1] https://rt.cpan.org/Ticket/Display.html?id=107108
Thanks. So I'll put this into production.