lib/WebDyne/Install/Apache/Constant.pm

filter: Statementstmt 0.0% 0 / 216 Branchbran 0.0% 0 / 98 Conditioncond 0.0% 0 / 36 MC/DCmcdc 0.0% 0 / 20 Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 394 CC 76 SCAR 46.2
CC
76
Cov
0%
httpd_config
182.0
httpd_bin
132.0
mp2_installed
132.0
CRAP 101.3
« blib/lib/WebDyne/Util.pm ↑ Summary blib/lib/WebDyne.pm »
1 #
2 # This file is part of WebDyne.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package WebDyne::Install::Apache::Constant;
14  
15  
16 # Pragma
17 #
18 use strict qw(vars);
19 use vars qw($VERSION @ISA %Constant);
20 use warnings;
21 no warnings qw(uninitialized);
22  
23  
24 # Does the heavy liftying of importing into caller namespace
25 #
26 require WebDyne::Constant;
27 @ISA=qw(WebDyne::Constant);
28  
29  
30  
31 # External modules
32 #
33 use File::Find;
34 use File::Spec;
35 use IO::File;
36 use Cwd qw(realpath);
37 use Env::Path;
38 use WebDyne::Util;
39 use Data::Dumper;
40  
41  
42 # Constants for our Constants module. PATH is only used as last resort
43 #
44 use constant PATH => [qw(
45 /sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin /opt/sbin /opt/bin)
46 ];
47  
48  
49 # Need to null out some Fcntl functions under Win32
50 #
51 #use Fcntl;
52 #sub Fcntl::O_NONBLOCK { 0 }
53 #sub Fcntl::O_NOCTTY { 0 }
54  
55  
56 # Local constants
57 #
58 our $Httpd_Bin=&httpd_bin();
59 our $Apachectl_Bin=&apachectl_bin();
60 our $Httpd_Config_hr=&httpd_config();
61 our $Apxs_Bin=&apxs_bin();
62 our $Apxs_Config_hr=&apxs_config($Apxs_Bin);
63 my $ServerRoot;
64  
65  
66 # Version information
67 #
68 $VERSION='3.029';
69  
70  
71 #------------------------------------------------------------------------------
72  
73 # Name of user httpd runs under
74 #
75 my ($apache_uname, $apache_gname, $apache_uid, $apache_gid);
76 my @apache_uname=$ENV{'APACHE_UNAME'} ||
77 qw(apache apache2 www wwwrun httpd httpd2 www-data webservd);
78 foreach my $name (@apache_uname) {
79 unless ($apache_uid || $^O=~/MSWin[32|64]/) {
80 if ($apache_uid=getpwnam($name)) {$apache_uname=$name; last}
81 }
82 }
83 my @apache_gname=$ENV{'APACHE_GNAME'} ||
84 qw(apache apache2 www wwwrun httpd httpd2 www-data webservd);
85 foreach my $name (@apache_gname) {
86 unless ($apache_gid || $^O=~/MSWin[32|64]/) {
87 if ($apache_gid=getgrnam($name)) {$apache_gname=$name; last}
88 }
89 }
90 debug("apache_uid: $apache_uid, apache_gid: $apache_gid");
91  
92  
93 # Check we have something for Apache uname etc.
94 #
95 unless ($apache_uid || $^O=~/MSWin[32|64]/) {
96 warn('unable to determine Apache uname - please supply via APACHE_UNAME environment variable')
97 }
98 unless ($apache_gid || $^O=~/MSWin[32|64]/) {
99 warn('unable to determine Apache gname - please supply via APACHE_GNAME environment variable')
100 }
101  
102  
103 # Get mod_perl file and modules library location
104 #
105 my $dir_apache_modules=&dir_apache_modules();
106 my $file_mod_perl_lib=&file_mod_perl_lib($dir_apache_modules);
107  
108  
109 # Is mod_perl2/1 installed
110 #
111 my $mp2_installed=&mp2_installed();
112  
113  
114 # Real deal
115 #
116 %Constant=(
117  
118  
119 # Mod_perl1/2 installed
120 #
121 MP2_INSTALLED => $mp2_installed,
122  
123  
124 # Binary
125 #
126 HTTPD_BIN => $Httpd_Bin,
127 APACHECTL_BIN => $Apachectl_Bin,
128 APXS_BIN => $Apxs_Bin,
129  
130  
131 # Config file templates and final names, delimiter if inserted into master httpd.conf
132 #
133 FILE_WEBDYNE_CONF_TEMPLATE => 'webdyne.conf.inc',
134 FILE_WEBDYNE_CONF => 'webdyne.conf',
135 FILE_WEBDYNE_CONF_PL_TEMPLATE => 'webdyne_conf.pl.inc',
136 FILE_WEBDYNE_CONF_PL => 'webdyne_conf.pl',
137 FILE_APACHE_CONF_TEMPLATE => 'apache.conf.inc',
138 FILE_APACHE_CONF_DELIM => '#*WebDyne*',
139 FILE_MOD_PERL_1_99_COMPAT => 'webdyne-mod_perl-1_99-compat.pl',
140  
141  
142 # Get apache directory name
143 #
144 DIR_APACHE_CONF => &dir_apache_conf(),
145 DIR_APACHE_MODULES => $dir_apache_modules,
146  
147  
148 # Mod_perl library name
149 #
150 FILE_MOD_PERL_LIB => $file_mod_perl_lib,
151  
152  
153 # Need apache uid and gid, as some dirs will be chowned to this
154 # at install time
155 #
156 APACHE_UNAME => $apache_uname,
157 APACHE_GNAME => $apache_gname,
158 APACHE_UID => $apache_uid,
159 APACHE_GID => $apache_gid,
160  
161  
162 # SELinux context for cache directory
163 #
164 SELINUX_CONTEXT_HTTPD => 'httpd_sys_content_t',
165 SELINUX_CONTEXT_LIB => 'lib_t',
166 SELINUX_ENABLED_BIN => &find_bin('selinuxenabled'),
167 SELINUX_CHCON_BIN => &find_bin('chcon'),
168 SELINUX_SEMANAGE_BIN => &find_bin('semanage'),
169  
170  
171 # Perl shared lib files that need to be checked for SELinux context
172 #
173 SELINUX_SO_CHECK => {
174  
175 IO => 'IO/IO.so',
176 'Digest::MD5' => 'Digest/MD5/MD5.so',
177 Fcntl => 'Fcntl/Fcntl.so',
178 'Time::HiRes' => 'Time/HiRes/HiRes.so',
179 Storable => 'Storable/Storable.so',
180 'File::Glob' => 'File/Glob/Glob.so',
181 Opcode => 'Opcode/Opcode.so',
182 'Data::Dumper' => 'Dumper/Dumper.so'
183  
184 },
185  
186  
187 # Server config
188 #
189 %{$Apxs_Config_hr || {}},
190 %{$Httpd_Config_hr},
191  
192  
193 );
194  
195  
196 # Get absolute binary file location
197 #
198 sub httpd_bin {
199  
200  
201 # If in Win32 need to get location of Apache from reg. Not much error checking
202 # because not fatal if reg key not found etc.
203 #
204 0 ▶ debug();
Subroutine httpd_bin: not called CC=11 SCAR=48.8
Pod undocumented
205 0 my ($path, @name_bin);
206 0 ▶ if ($^O=~/MSWin[32|64]/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O =~ /MSWin[32|64]/) { } 0 0 0
207  
208 # Windows
209 #
210 0 debug("detected MS Win: $^O");
211 0 require Win32::TieRegistry;
212 0 my $reg_ix=tie(
213 my %reg, 'Win32::TieRegistry', 'HKEY_LOCAL_MACHINE\Software\Apache Group\Apache'
214 );
215 0 my $version=(sort {$b cmp $a} keys %reg)[0];
216 0 ▶ unless ($version) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($version) 0 0 0
217 0 $reg_ix=tie(
218 %reg, 'Win32::TieRegistry', 'HKEY_LOCAL_MACHINE\Software\Apache Software Foundation\Apache'
219 );
220 0 $version=(sort {$b cmp $a} keys %reg)[0];
221 }
222 0 debug("registry says version: $version");
223 0 $path=($ServerRoot=$reg{$version}->{'ServerRoot'}); #||
224 # last resorts. blech
225 #'C:\Apache;C:\Apache~1;C:\Apache2;C:\Apache2.2;C:\Progra~1\Apache;C:\Progra~1\Apache2;C:\Progra~1\Apache~1;'.
226 #'D:\Apache;D:\Apache~1;D:\Apache2;D:\Apache2.2;D:\Progra~1\Apache;D:\Progra~1\Apache2;D:\Progra~1\Apache~1;'.
227 #'E:\Apache;E:\Apache~1;E:\Apache2;E:\Apache2.2;E:\Progra~1\Apache;E:\Progra~1\Apache2;E:\Progra~1\Apache~1;';
228  
229 # Some Apache distro's use '/bin/' after ServerRoot
230 #
231 0 ▶ if ($path) {$path=join(Env::Path->PathSeparator, File::Spec->catdir($path, 'bin'))}
Branch: 1 branch
BranchTrueFalseTotal
if ($path) 0 0 0
232  
233 # Various names for Apache under Windows
234 #
235 0 @name_bin=qw(Apache.exe Apache2.exe httpd.exe httpd2.exe);
236 }
237 else {
238  
239 # Add some hard coded paths as last resort options, will work if su'd to root
240 # without getting root's path
241 #
242 0 $path=join(Env::Path->PathSeparator, $ENV{'PATH'}, @{+PATH});
243 0 @name_bin=qw(httpd httpd2 httpd2.2 httpd2.4 apache apache2 apache2.2 apache2.4);
244 }
245 0 debug("apache final search path: '$path'");
246 0 debug('apache names %s', Dumper(\@name_bin));
247  
248  
249 # Find the httpd bin file
250 #
251 0 my $httpd_bin;
252 0 ▶ unless ($httpd_bin=$ENV{'HTTPD_BIN'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($httpd_bin = $ENV{"HTTPD_BIN"}) 0 0 0
253  
254 0 my @dir=grep {-d $_} split(Env::Path->PathSeparator, $path);
255 0 my %dir=map {$_ => 1} @dir;
256 0 DIR: foreach my $dir (@dir) {
257 0 ▶ next unless delete $dir{$dir};
Branch: 1 branch
BranchTrueFalseTotal
unless delete $dir{$dir} 0 0 0
258 0 ▶ next unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
259 0 debug("searching dir: $dir");
260 0 foreach my $name_bin (@name_bin) {
261 0 ▶ if (-f File::Spec->catfile($dir, $name_bin)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "File::Spec"->catfile($dir, $name_bin)) 0 0 0
262 0 $httpd_bin=File::Spec->catfile($dir, $name_bin);
263 0 last DIR;
264 }
265 }
266 }
267 }
268 0 debug("httpd_bin returning: $httpd_bin");
269  
270  
271 # Warn if unable to find
272 #
273 0 ▶ unless (-f $httpd_bin) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $httpd_bin) 0 0 0
274 0 warn('unable to find/determine Apache binary location - please supply via HTTPD_BIN environment variable');
275 }
276  
277  
278 # Return
279 #
280 0 return File::Spec->canonpath($httpd_bin);
281  
282 }
283  
284  
285 sub find_bin {
286  
287 0 ▶ my $bin=shift();
Subroutine find_bin: not called CC=7 SCAR=40.3
Pod undocumented
288 0 my $path=join(Env::Path->PathSeparator, $ENV{'PATH'}, @{+PATH});
289 0 debug("find_bin $bin, path: $path");
290 0 my $fn;
291 0 ▶ unless ($fn=$ENV{"${bin}_BIN"}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($fn = $ENV{"${bin}_BIN"}) 0 0 0
292 0 my @dir=grep {-d $_} split(Env::Path->PathSeparator, $path);
293 0 my %dir=map {$_ => 1} @dir;
294 0 foreach my $dir (@dir) {
295 0 ▶ next unless delete $dir{$dir};
Branch: 1 branch
BranchTrueFalseTotal
unless delete $dir{$dir} 0 0 0
296 0 ▶ next unless -d $dir;
Branch: 1 branch
BranchTrueFalseTotal
unless -d $dir 0 0 0
297 0 debug("searching dir: $dir");
298 0 ▶ if (-f File::Spec->catfile($dir, $bin)) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f "File::Spec"->catfile($dir, $bin)) 0 0 0
299 0 $fn=File::Spec->catfile($dir, $bin); last;
300 }
301 }
302 }
303  
304  
305 # Return
306 #
307 0 debug("find_bin returning: $fn");
308 0 ▶ return $fn ? File::Spec->canonpath($fn) : undef;
Branch: 1 branch
BranchTrueFalseTotal
$fn ? : 0 0 0
309  
310 }
311  
312  
313 sub find_first_bin {
314  
315 0 ▶ my ($env_ar, $name_ar)=@_;
Subroutine find_first_bin: not called CC=10 SCAR=47.0
Pod undocumented
316 0 ▶ foreach my $env (@{$env_ar || []}) {
Condition0%0/2
$env_ar || []
l!l
00
MC/DC0%0/1
$env_ar || []
$env_ar
Truth table0%0/2
A
A= $env_ar
Aresult
11
00
317 0 ▶ next unless $ENV{$env};
Branch: 1 branch
BranchTrueFalseTotal
unless $ENV{$env} 0 0 0
318 0 ▶ return File::Spec->canonpath($ENV{$env}) if -f $ENV{$env};
Branch: 1 branch
BranchTrueFalseTotal
if -f $ENV{$env} 0 0 0
319 }
320 0 my $path=join(Env::Path->PathSeparator, $ENV{'PATH'}, @{+PATH});
321 0 my @dir=grep {-d $_} split(Env::Path->PathSeparator, $path);
322 0 my %dir=map {$_ => 1} @dir;
323 0 foreach my $dir (@dir) {
324 0 ▶ next unless delete $dir{$dir};
Branch: 1 branch
BranchTrueFalseTotal
unless delete $dir{$dir} 0 0 0
325 0 ▶ foreach my $name (@{$name_ar || []}) {
Condition0%0/2
$name_ar || []
l!l
00
MC/DC0%0/1
$name_ar || []
$name_ar
Truth table0%0/2
A
A= $name_ar
Aresult
11
00
326 0 my $fn=File::Spec->catfile($dir, $name);
327 0 ▶ return File::Spec->canonpath($fn) if -f $fn;
Branch: 1 branch
BranchTrueFalseTotal
if -f $fn 0 0 0
328 }
329 }
330 0 return;
331  
332 }
333  
334  
335 sub command_output {
336  
337 0 ▶ my ($bin, @arg)=@_;
Subroutine command_output: not called CC=5 SCAR=34.0
Pod undocumented
338 0 ▶ return unless $bin && -f $bin;
Branch: 1 branch
BranchTrueFalseTotal
unless $bin and -f $bin 0 0 0
Condition0%0/3
$bin and -f $bin
!ll&&!rl&&r
000
MC/DC0%0/2
$bin and -f $bin
$bin -f $bin
Truth table0%0/3
A and B
A= $binB= -f $bin
ABresult
0X0
100
111
339 0 my @out;
340 0 open(my $stderr_save, '>&', \*STDERR);
341 0 open(STDERR, '>', File::Spec->devnull());
342 0 ▶ if (open(my $fh, '-|', $bin, @arg)) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $fh, "-|", $bin, @arg) 0 0 0
343 0 @out=<$fh>;
344 0 close($fh);
345 }
346 0 ▶ open(STDERR, '>&', $stderr_save) if $stderr_save;
Branch: 1 branch
BranchTrueFalseTotal
if $stderr_save 0 0 0
347 0 return @out;
348  
349 }
350  
351  
352 sub apachectl_bin {
353  
354 0 ▶ my $apachectl_bin=find_first_bin(
Subroutine apachectl_bin: not called CC=1 SCAR=6.9
Pod undocumented
355 [qw(APACHECTL_BIN APACHECTL APACHE2CTL)],
356 [qw(apachectl apache2ctl)]
357 );
358 0 debug("apachectl_bin returning: $apachectl_bin");
359 0 return $apachectl_bin;
360  
361 }
362  
363  
364 sub apxs_bin {
365  
366 0 ▶ my $apxs_bin=find_first_bin(
Subroutine apxs_bin: not called CC=1 SCAR=6.9
Pod undocumented
367 [qw(APXS_BIN APXS APACHE_TEST_APXS)],
368 [qw(apxs apxs2 apxs2.4)]
369 );
370 0 debug("apxs_bin returning: $apxs_bin");
371 0 return $apxs_bin;
372  
373 }
374  
375  
376 sub apxs_config {
377  
378 0 ▶ my $apxs_bin=shift() || return {};
Subroutine apxs_config: not called CC=6 SCAR=37.4
Pod undocumented
Condition0%0/2
shift() || (return {})
l!l
00
MC/DC0%0/1
shift() || (return {})
shift()
Truth table0%0/2
A
A= shift()
Aresult
11
00
379 0 my %config;
380 0 foreach my $key (qw(LIBEXECDIR SYSCONFDIR HTTPD_ROOT SERVER_CONFIG_FILE)) {
381 0 my @out=command_output($apxs_bin, '-q', $key);
382 0 ▶ next unless @out;
Branch: 1 branch
BranchTrueFalseTotal
unless @out 0 0 0
383 0 chomp(my $value=$out[0]);
384 0 ▶ next unless defined($value) && length($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value and length $value 0 0 0
Condition0%0/3
defined $value and length $value
!ll&&!rl&&r
000
MC/DC0%0/2
defined $value and length $value
defined $value length $value
Truth table0%0/3
A and B
A= defined $valueB= length $value
ABresult
0X0
100
111
385 0 $config{"APXS_$key"}=$value;
386 }
387 0 debug('apxs_config: %s', Dumper(\%config));
388 0 return \%config;
389  
390 }
391  
392  
393 sub httpd_config {
394  
395  
396 # Return if neither httpd nor apachectl was found.
397 #
398 0 ▶ debug();
Subroutine httpd_config: not called CC=13 SCAR=52.0
Pod undocumented
399 0 ▶ return unless $Httpd_Bin || $Apachectl_Bin;
Branch: 1 branch
BranchTrueFalseTotal
unless $WebDyne::Install::Apache::Constant::Httpd_Bin or $WebDyne::Install::Apache::Constant::Apachectl_Bin 0 0 0
Condition0%0/3
$WebDyne::Install::Apache::Constant::Httpd_Bin or $WebDyne::Install::Apache::Constant::Apachectl_Bin
l!l&&r!l&&!r
000
MC/DC0%0/2
$WebDyne::Install::Apache::Constant::Httpd_Bin or $WebDyne::Install::Apache::Constant::Apachectl_Bin
$WebDyne::Install::Apache::Constant::Httpd_Bin $WebDyne::Install::Apache::Constant::Apachectl_Bin
Truth table0%0/3
A or B
A= $WebDyne::Install::Apache::Constant::Httpd_BinB= $WebDyne::Install::Apache::Constant::Apachectl_Bin
ABresult
1X1
011
000
400  
401  
402 # Need to get httpd config as series of key/val pairs
403 #
404 0 my %config;
405 0 my $devnull=File::Spec->devnull();
406 0 my @httpd_config=command_output($Httpd_Bin, '-V');
407 0 ▶ @httpd_config=command_output($Apachectl_Bin, '-V') unless @httpd_config;
Branch: 1 branch
BranchTrueFalseTotal
unless @httpd_config 0 0 0
408 0 debug('httpd_config: %s', Dumper(\@httpd_config));
409  
410  
411 # Go through
412 #
413 0 foreach my $httpd_config (@httpd_config) {
414  
415 0 ▶ if ($httpd_config=~/Apache\/(\d+\.\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($httpd_config =~ m[Apache/(\d+\.\d+)]) 0 0 0
416 0 $config{'HTTPD_VER'}=$1;
417 0 next;
418 }
419 0 ▶ next unless ($httpd_config=~/\s*\-D\s*(.*)/);
Branch: 1 branch
BranchTrueFalseTotal
unless $httpd_config =~ /\s*\-D\s*(.*)/ 0 0 0
420 0 my ($key, $value)=split(/\=/, $1);
421 0 $key=~s/\s+.*$//g;
422 0 ▶ $value ||= '';
Condition0%0/2
$value ||= ""
l!l
00
MC/DC0%0/1
$value ||= ""
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
423 0 $value=~s/^\"//;
424 0 $value=~s/\"$//;
425 0 ▶ $key=~/^HTTPD/ || ($key="HTTPD_${key}");
Branch: 1 branch
BranchTrueFalseTotal
$key =~ /^HTTPD/ or $key = "HTTPD_$key" 0 0 0
426 0 ▶ $config{$key}=$value || 1;
Condition0%0/2
$value || 1
l!l
00
MC/DC0%0/1
$value || 1
$value
Truth table0%0/2
A
A= $value
Aresult
11
00
427  
428 }
429  
430  
431 # In windows HTTPD_ROOT does not always match actual installed root path,
432 # so override if possible
433 #
434 0 ▶ my $httpd_dn=($config{'HTTPD_ROOT'}=$ServerRoot || $config{'HTTPD_ROOT'});
Condition0%0/3
$ServerRoot || $config{'HTTPD_ROOT'}
l!l&&r!l&&!r
000
MC/DC0%0/2
$ServerRoot || $config{'HTTPD_ROOT'}
$ServerRoot $config{'HTTPD_ROOT'}
Truth table0%0/3
A || B
A= $ServerRootB= $config{'HTTPD_ROOT'}
ABresult
1X1
011
000
435  
436  
437 # Last resort - if does not exist use apache bin location as ref for
438 # HTTPD_ROOT
439 #
440 0 ▶ unless (-d $httpd_dn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $httpd_dn) 0 0 0
441 0 debug('using last resort to find httpd_dn');
442 0 $config{'HTTPD_ROOT'}=do {
443 0 my $dn=File::Spec->catdir(
444 (File::Spec->splitpath($Httpd_Bin))[1],
445 File::Spec->updir());
446 0 ▶ (-d $dn) && ($dn=realpath($dn));
Branch: 1 branch
BranchTrueFalseTotal
-d $dn and $dn = realpath($dn) 0 0 0
447 0 $dn;
448 };
449 }
450 0 debug('httpd_dn set to: %s', $config{'HTTPD_ROOT'});
451  
452  
453 # And return the config
454 #
455 0 return \%config;
456  
457 }
458  
459  
460 sub dir_apache_conf {
461  
462  
463 # Get Apache config dir, ensure is absolute
464 #
465 0 ▶ debug();
Subroutine dir_apache_conf: not called CC=10 SCAR=47.0
Pod undocumented
466 0 my $apache_conf_dn;
467 0 ▶ unless ($apache_conf_dn=$ENV{'DIR_APACHE_CONF'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($apache_conf_dn = $ENV{'DIR_APACHE_CONF'}) { } 0 0 0
468  
469 0 ▶ if (my $sysconf_dn=$Apxs_Config_hr->{'APXS_SYSCONFDIR'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $sysconf_dn = $WebDyne::Install::Apache::Constant::Apxs_Config_hr->{'APXS_SYSCONFDIR'}) { } 0 0 0
470 0 $apache_conf_dn=$sysconf_dn;
471 }
472 else {
473 0 $apache_conf_dn=$Httpd_Config_hr->{'HTTPD_SERVER_CONFIG_FILE'};
474 }
475 0 my $apache_conf_fn=(File::Spec->splitpath($apache_conf_dn))[2];
476 0 ▶ $apache_conf_dn=~s/\Q$apache_conf_fn\E$// if $apache_conf_fn=~/\.conf$/;
Branch: 1 branch
BranchTrueFalseTotal
if $apache_conf_fn =~ /\.conf$/ 0 0 0
477  
478 #$apache_conf_dn=(File::Spec->splitpath(
479 # $Httpd_Config_hr->{'HTTPD_SERVER_CONFIG_FILE'}))[1];
480 0 debug("apache_conf_fn initital value: $apache_conf_dn");
481 0 ▶ unless ($apache_conf_dn=~/^\//) {
Branch: 1 branch
BranchTrueFalseTotal
if ($apache_conf_dn =~ m[^/]) { } 0 0 0
482  
483 0 debug("apache_conf_dn path appears relative - prepending HTTPD_ROOT");
484 $apache_conf_dn=File::Spec->catdir(
485 0 $Httpd_Config_hr->{'HTTPD_ROOT'}, $apache_conf_dn
486 );
487  
488 }
489 else {
490 0 debug('apache_conf_dn appears fully qualified - leaving intact');
491 }
492  
493  
494 # Prefer distro include directories when available. Debian-style
495 # systems keep the source file in conf-available and enable it through
496 # conf-enabled; Fedora/RHEL-style systems commonly include conf.d.
497 #
498 0 my @include_dn=(
499 [ 'conf.d' ],
500 [ File::Spec->catdir(File::Spec->updir(), 'conf.d') ],
501 [ 'conf-available', 'conf-enabled' ],
502 [ File::Spec->catdir(File::Spec->updir(), 'conf-available'), File::Spec->catdir(File::Spec->updir(), 'conf-enabled') ],
503 );
504 0 foreach my $dn_ar (@include_dn) {
505 0 my ($dn, $enabled_dn)=@{$dn_ar};
506 0 debug("looking for conf.d path: $dn");
507 0 my $test_dn=File::Spec->canonpath(
508 File::Spec->catdir($apache_conf_dn, $dn));
509 0 debug("testing: $test_dn");
510 0 ▶ if (-d $test_dn) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $test_dn) { } 0 0 0
511 0 ▶ if ($enabled_dn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($enabled_dn) 0 0 0
512 0 my $test_enabled_dn=File::Spec->canonpath(
513 File::Spec->catdir($apache_conf_dn, $enabled_dn));
514 0 ▶ $Httpd_Config_hr->{'DIR_APACHE_CONF_ENABLED'}=realpath($test_enabled_dn)
Branch: 1 branch
BranchTrueFalseTotal
if -d $test_enabled_dn 0 0 0
515 if -d $test_enabled_dn;
516 }
517 0 $apache_conf_dn=realpath($test_dn);
518 0 debug("found, setting apache_conf_dn: $apache_conf_dn");
519 0 $Httpd_Config_hr->{'HTTPD_SERVER_CONFIG_SKIP'}=1;
520 0 last;
521 }
522 else {
523 0 debug('not found');
524 }
525 }
526 }
527 else {
528 0 debug('setting apache_conf_dn from %ENV');
529 }
530 0 debug("apache_conf_dn set to: $apache_conf_dn");
531  
532  
533 # Warn if not found
534 #
535 0 ▶ unless (-d $apache_conf_dn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-d $apache_conf_dn) 0 0 0
536 0 warn('unable to find/determine Apache conf directory - please supply via DIR_APACHE_CONF environment variable');
537 }
538  
539  
540 # Return it
541 #
542 0 return $apache_conf_dn;
543  
544 }
545  
546  
547 sub dir_apache_modules {
548  
549  
550 # Get Apache config dir, ensure is absolute
551 #
552 0 ▶ debug();
Subroutine dir_apache_modules: not called CC=5 SCAR=34.0
Pod undocumented
553 my @dn=(
554 $Apxs_Config_hr->{'APXS_LIBEXECDIR'},
555 File::Spec->catdir(
556 $Httpd_Config_hr->{'HTTPD_ROOT'}, 'modules'
557 ),
558 File::Spec->catdir(
559 0 $Httpd_Config_hr->{'HTTPD_ROOT'}, 'libexec'
560 ),
561  
562 # last resorts, blech
563 '/usr/lib/apache2/modules',
564 '/usr/lib/apache2.2/modules',
565 '/usr/lib/httpd/modules',
566 '/usr/lib/apache2',
567 '/usr/lib/apache2.2',
568 '/usr/local/lib',
569 '/usr/local/lib64',
570 '/usr/lib',
571 '/usr/lib64'
572 );
573  
574  
575 # Check for modules
576 #
577 0 my $apache_modules_dn;
578 0 ▶ unless ($apache_modules_dn=$ENV{'DIR_APACHE_MODULES'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($apache_modules_dn = $ENV{'DIR_APACHE_MODULES'}) { } 0 0 0
579 0 foreach my $dn (@dn) {
580 0 debug("looking for path: $dn");
581 0 ▶ if (-d $dn) {
Branch: 1 branch
BranchTrueFalseTotal
if (-d $dn) 0 0 0
582 0 $apache_modules_dn=$dn;
583 0 debug("found, setting apache_modules_dn to: $dn");
584 0 last;
585 }
586 }
587 0 ▶ $apache_modules_dn ||= 'modules';
Condition0%0/2
$apache_modules_dn ||= "modules"
l!l
00
MC/DC0%0/1
$apache_modules_dn ||= "modules"
$apache_modules_dn
Truth table0%0/2
A
A= $apache_modules_dn
Aresult
11
00
588 }
589 else {
590 0 debug('setting apache_modules_dn from %ENV');
591 }
592 0 debug("apache_modules_dn set to: $apache_modules_dn");
593  
594  
595 # Warn if not found. Update - don't do this anymore, just warn later if mod_perl lib not found, which
596 # used this routine to find potential module storage dir.
597 #
598 #unless (-d $apache_modules_dn) {
599 #warn('unable to find/determine Apache modules directory - please supply via DIR_APACHE_MODULES environment variable');
600 #}
601  
602  
603 # Return it
604 #
605 0 return $apache_modules_dn;
606  
607 }
608  
609  
610 sub file_mod_perl_lib {
611  
612  
613 # Get the name of the mod_perl library
614 #
615 0 ▶ my $dn=shift();
Subroutine file_mod_perl_lib: not called CC=7 SCAR=40.3
Pod undocumented
616 0 debug("looking for mod_perl dn: $dn");
617 0 my $mod_perl_cn;
618 0 ▶ unless ($mod_perl_cn=$ENV{'FILE_MOD_PERL_LIB'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mod_perl_cn = $ENV{'FILE_MOD_PERL_LIB'}) { } 0 0 0
619 0 foreach my $fn (qw(libperl mod_perl mod_perl2 mod_perl2.2 mod_perl-2 mod_perl-2.2)) {
620 0 foreach my $ext (qw(so dll)) {
621 0 my $cn=File::Spec->catfile($dn, "$fn.$ext");
622 0 debug("looking for cn: $cn");
623 0 ▶ if (-f $cn) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $cn) { } 0 0 0
624 0 $mod_perl_cn=$cn;
625 0 last;
626 }
627 else {
628 0 debug('not found');
629 }
630 }
631 0 ▶ last if $mod_perl_cn;
Branch: 1 branch
BranchTrueFalseTotal
if $mod_perl_cn 0 0 0
632 }
633 }
634 else {
635 0 debug("setting mod_perl_cn from %ENV")
636 }
637 0 debug("mod_perl_cn set to: $mod_perl_cn");
638  
639  
640 0 ▶ unless (-f $mod_perl_cn) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $mod_perl_cn) 0 0 0
641 0 warn('unable to find/determine mod_perl library - please supply via FILE_MOD_PERL_LIB environment variable');
642 }
643 0 return $mod_perl_cn;
644  
645 }
646  
647  
648 sub mp2_installed {
649  
650 0 ▶ local $SIG{__DIE__};
Subroutine mp2_installed: not called CC=11 SCAR=48.8
Pod undocumented
651 0 eval {require Apache2};
652 0 eval {require mod_perl};
653 0 eval {require mod_perl2};
654 0 ▶ eval {undef} if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
655 0 my $mp2_installed;
656 0 ▶ if (($mod_perl::VERSION || $mod_perl2::VERSION || $ENV{MOD_PERL_API_VERSION}) >= 1.99) {
Branch: 3 branches
BranchTrueFalseTotal
if (($mod_perl::VERSION || $mod_perl2::VERSION || $ENV{'MOD_PERL_API_VERSION'}) >= 1.99) { } 0 0 0
elsif (($mod_perl::VERSION || $mod_perl2::VERSION || $ENV{'MOD_PERL_API_VERSION'}) >= 1) { } 0 0 0
elsif ($file_mod_perl_lib) { } 0 0 0
Condition0%0/6
$mod_perl::VERSION || $mod_perl2::VERSION || $ENV{'MOD_PERL_API_VERSION'}
l!l&&r!l&&!r
000
$mod_perl::VERSION or $mod_perl2::VERSION
l!l&&r!l&&!r
000
MC/DC0%0/3
$mod_perl::VERSION || $mod_perl2::VERSION || $ENV{'MOD_PERL_API_VERSION'}
$mod_perl::VERSION $mod_perl2::VERSION $ENV{'MOD_PERL_API_VERSION'}
Truth table0%0/4
A or B || C
A= $mod_perl::VERSIONB= $mod_perl2::VERSIONC= $ENV{'MOD_PERL_API_VERSION'}
ABCresult
1XX1
01X1
0011
0000
657 0 $mp2_installed=1;
658 }
659 ▶ elsif (($mod_perl::VERSION || $mod_perl2::VERSION || $ENV{MOD_PERL_API_VERSION}) >= 1) {
Condition0%0/6
$mod_perl::VERSION || $mod_perl2::VERSION || $ENV{'MOD_PERL_API_VERSION'}
l!l&&r!l&&!r
000
$mod_perl::VERSION or $mod_perl2::VERSION
l!l&&r!l&&!r
000
MC/DC0%0/3
$mod_perl::VERSION || $mod_perl2::VERSION || $ENV{'MOD_PERL_API_VERSION'}
$mod_perl::VERSION $mod_perl2::VERSION $ENV{'MOD_PERL_API_VERSION'}
Truth table0%0/4
A or B || C
A= $mod_perl::VERSIONB= $mod_perl2::VERSIONC= $ENV{'MOD_PERL_API_VERSION'}
ABCresult
1XX1
01X1
0011
0000
660 0 $mp2_installed=0
661 }
662 elsif ($file_mod_perl_lib) {
663  
664 # Last resort - mod_perl libary exists, but we couldn't load
665 #
666 0 $mp2_installed=0;
667 0 my $version=qx($Httpd_Bin -v);
668 0 ▶ if ($version=~/(\d+)\.(\d+)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version =~ /(\d+)\.(\d+)/) 0 0 0
669 0 $version=$1 . $2;
670 0 ▶ if ($version >= 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($version >= 2) 0 0 0
671 0 $mp2_installed=1;
672 }
673 }
674 }
675 0 debug("mp2_installed: $mp2_installed");
676  
677 0 return $mp2_installed;
678  
679 }
680  
681  
682 # Done
683 #
684 1;
685 __END__
« blib/lib/WebDyne/Util.pm ↑ Summary blib/lib/WebDyne.pm »