blib/lib/WebDyne/Install/Apache.pm

filter: Statementstmt 56.4% 122 / 216 Branchbran 33.0% 45 / 136 Conditioncond 22.2% 14 / 63 MC/DCmcdc 11.1% 4 / 36 Subroutinesub 100% 16 / 16 Podpod 0.0% 0 / 2 totaltotal 42.8% 201 / 469 CC 98 SCAR 76.7
CC
98
Cov
44%
install
2469.2
BEGIN
1.0
BEGIN
1.0
CRAP 2141.6
↑ Summary lib/WebDyne.pm »
1  
2 #
3 # This file is part of WebDyne.
4 #
5 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
6 #
7 # This is free software; you can redistribute it and/or modify it under
8 # the same terms as the Perl 5 programming language system itself.
9 #
10 # Full license text is available at:
11 #
12 # <http://dev.perl.org/licenses/>
13 #
14 package WebDyne::Install::Apache;
15  
16  
17 # Compiler Pragma
18 #
19 6 ▶sub BEGIN {$^W=0}
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
21 6 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 6 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25  
26 # Webmod Modules
27 #
28 6 ▶use WebDyne::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30  
31 # External Modules
32 #
33 6 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 6 ▶use Text::Template;
Subroutine BEGIN: called CC=1 SCAR=0.0
35 6 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 6 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
37  
38  
39 # Base installer
40 #
41 6 ▶use WebDyne::Install qw(message);
Subroutine BEGIN: called CC=1 SCAR=0.0
42  
43  
44 # Constants
45 #
46 6 ▶use WebDyne::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
47 6 ▶use WebDyne::Install::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
48 6 ▶use WebDyne::Install::Apache::Constant;
Subroutine BEGIN: called CC=1 SCAR=0.0
49  
50  
51 # Version information
52 #
53 $VERSION='3.029';
54  
55  
56 # Debug
57 #
58 0 && debug("%s loaded, version $VERSION", __PACKAGE__);
59  
60  
61 # Uninstaller global
62 #
63 my $Uninstall_fg;
64  
65  
66 # Init done.
67 #
68 1;
69  
70  
71 #------------------------------------------------------------------------------
72  
73  
74 # Uninstall
75 #
76 2 ▶sub uninstall {
Subroutine uninstall: called CC=1 SCAR=0.0
Pod undocumented
77  
78 # Set flag and call install routine
79 #
80 2 $Uninstall_fg++;
81 2 shift()->install(@_);
82  
83 }
84  
85  
86 # Install the Apache conf params needed to run the system
87 #
88 4 ▶sub install {
Subroutine install: called CC=98 SCAR=78.1
Pod undocumented
89  
90  
91 # Get class, other paths
92 #
93 4 my ($class, $prefix, $installbin_dn, $opt_hr)=@_;
94 4 ▶ my $dry_run=$opt_hr->{'dry_run'} || $ENV{'DRY_RUN'};
Condition66%2/3
$opt_hr->{'dry_run'} || $ENV{'DRY_RUN'}
l!l&&r!l&&!r
202
MC/DC50%1/2
$opt_hr->{'dry_run'} || $ENV{'DRY_RUN'}
$opt_hr->{'dry_run'} $ENV{'DRY_RUN'}
Truth table66%2/3
A || B
A= $opt_hr->{'dry_run'}B= $ENV{'DRY_RUN'}
ABresult
1X1
011
000
95 4 local $ENV{'DRY_RUN'}=$ENV{'DRY_RUN'};
96 4 ▶ $ENV{'DRY_RUN'}=1 if $dry_run;
Branch: 1 branch
BranchTrueFalseTotal
if $dry_run 2 2 4
97  
98  
99 # Run the base install/uninstall routine to create the cache dir.
100 # In --text mode this module only renders generated config to STDOUT;
101 # cache path discovery still happens below, but no filesystem setup is
102 # performed.
103 #
104 4 ▶ unless ($Uninstall_fg || $opt_hr->{'text'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($Uninstall_fg or $opt_hr->{'text'}) { } 3 1 4
if (do { $Uninstall_fg }) 2 1 3
Condition100%3/3
$Uninstall_fg or $opt_hr->{"text"}
l!l&&r!l&&!r
211
MC/DC100%2/2
$Uninstall_fg or $opt_hr->{"text"}
$Uninstall_fg $opt_hr->{"text"}
Truth table100%3/3
A or B
A= $Uninstall_fgB= $opt_hr->{"text"}
ABresult
1X1
011
000
105 1 ▶ WebDyne::Install->install($prefix, $installbin_dn) ||
Branch: 1 branch
BranchTrueFalseTotal
"WebDyne::Install"->install($prefix, $installbin_dn) or return err() 1 0 1
106 return err();
107 }
108 0 elsif ($Uninstall_fg) {
109 2 ▶ WebDyne::Install->uninstall($prefix, $installbin_dn) ||
Branch: 1 branch
BranchTrueFalseTotal
"WebDyne::Install"->uninstall($prefix, $installbin_dn) or return err() 2 0 2
110 return err();
111 }
112  
113  
114 # Get package file name so we can look up inc for templates
115 #
116 4 (my $class_dn=$class . q(.pm))=~s/::/\//g;
117  
118  
119 # Load constants, get full path for class and constants from INC
120 #
121 4 ▶ $class_dn=$INC{$class_dn} ||
Condition50%1/2
$INC{$class_dn} || (return err("unable to find location for $class in %INC"))
l!l
40
MC/DC0%0/1
$INC{$class_dn} || (return err("unable to find location for $class in %INC"))
$INC{$class_dn}
Truth table50%1/2
A
A= $INC{$class_dn}
Aresult
11
00
122 return err("unable to find location for $class in \%INC");
123  
124  
125 # Get file name component, then cut file out to get directory,
126 # split and reverse class for later use;
127 #
128 4 my $class_fn=(File::Spec->splitpath($class_dn))[2];
129 4 $class_dn=~s/\Q$class_fn\E$//;
130 4 my @class=reverse split(/::/, $class);
131  
132  
133 # Get webdyne cache dn;
134 #
135 4 my $cache_dn=&WebDyne::Install::cache_dn($prefix);
136  
137  
138 # Get config/constant hash ref
139 #
140 4 my %constant=(
141  
142 %WebDyne::Constant::Constant,
143 %WebDyne::Install::Constant::Constant,
144 %WebDyne::Install::Apache::Constant::Constant,
145 DIR_INSTALLBIN => $installbin_dn,
146 WEBDYNE_CACHE_DN => $cache_dn,
147  
148 );
149 4 my $config_hr=\%constant;
150 4 0 && debug('config_hr %s', Dumper($config_hr));
151  
152  
153 # Cannot do anything without Apache binary
154 #
155 return err("unable to find apache binary")
156 4 ▶ unless $config_hr->{'HTTPD_BIN'};
Branch: 1 branch
BranchTrueFalseTotal
unless $config_hr->{"HTTPD_BIN"} 0 4 4
157  
158  
159 # Get template path name from module install dir.
160 #
161 4 my $template_dn=File::Spec->catdir($class_dn, $class[0]);
162 my $template_fn=File::Spec->catfile(
163 4 $template_dn, $config_hr->{'FILE_WEBDYNE_CONF_TEMPLATE'});
164  
165  
166 # Open it as a template
167 #
168 4 ▶ my $template_or=Text::Template->new(
Condition50%1/2
'Text::Template'->new('type', 'FILE', 'source', $template_fn) || (return err("unable to open template $template_fn, $!"))
l!l
40
MC/DC0%0/1
'Text::Template'->new('type', 'FILE', 'source', $template_fn) || (return err("unable to open template $template_fn, $!"))
'Text::Template'->new('type', 'FILE', 'source', $template_fn)
Truth table50%1/2
A
A= 'Text::Template'->new('type', 'FILE', 'source', $template_fn)
Aresult
11
00
169  
170 type => 'FILE',
171 source => $template_fn,
172  
173 ) || return err("unable to open template $template_fn, $!");
174  
175  
176 # Fill in with out self ref as a hash
177 #
178 4 ▶ my $webdyne_conf=$template_or->fill_in(
Condition50%1/2
$template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->']) || (return err("unable to fill in template $template_fn, $Text::Template::ERROR"))
l!l
40
MC/DC0%0/1
$template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->']) || (return err("unable to fill in template $template_fn, $Text::Template::ERROR"))
$template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->'])
Truth table50%1/2
A
A= $template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->'])
Aresult
11
00
179  
180 HASH => $config_hr,
181 DELIMITERS => ['<!--', '-->'],
182  
183 ) || return err("unable to fill in template $template_fn, $Text::Template::ERROR");
184  
185  
186 # Get apache config dir
187 #
188 4 ▶ my $apache_conf_dn=$config_hr->{'DIR_APACHE_CONF'} ||
Condition50%1/2
$config_hr->{'DIR_APACHE_CONF'} || (return err('unable to determine Apache config directory'))
l!l
40
MC/DC0%0/1
$config_hr->{'DIR_APACHE_CONF'} || (return err('unable to determine Apache config directory'))
$config_hr->{'DIR_APACHE_CONF'}
Truth table50%1/2
A
A= $config_hr->{'DIR_APACHE_CONF'}
Aresult
11
00
189 return err('unable to determine Apache config directory');
190  
191  
192 # Work out config file name
193 #
194 my $webdyne_conf_fn=File::Spec->catfile(
195 4 $apache_conf_dn, $config_hr->{'FILE_WEBDYNE_CONF'});
196  
197  
198  
199  
200 # Remove webdyne config file in uninstall mode. Install mode writes it
201 # after all generated fragments are available, so --text can print the
202 # complete Apache/WebDyne configuration.
203 #
204 4 ▶ if ($Uninstall_fg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Uninstall_fg) 2 2 4
205  
206 # In uninstall - get rid of conf file
207 #
208 2 ▶ if (-f $webdyne_conf_fn) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $webdyne_conf_fn) 2 0 2
209 2 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) { } 1 1 2
210 1 message "would remove config file $webdyne_conf_fn";
211 }
212 else {
213 1 ▶ unlink($webdyne_conf_fn) ||
Branch: 1 branch
BranchTrueFalseTotal
unlink $webdyne_conf_fn or return err("unable to remove config file $webdyne_conf_fn, $!") 1 0 1
214 return err("unable to remove config file $webdyne_conf_fn, $!");
215 1 message "remove config file $webdyne_conf_fn";
216 }
217 }
218  
219 }
220
221  
222 # Work out constants file name
223 #
224 my $webdyne_conf_pl_fn=File::Spec->catfile(
225 4 $apache_conf_dn, $config_hr->{'FILE_WEBDYNE_CONF_PL'});
226
227  
228 # Get template path name from module install dir.
229 #
230 my $template_webdyne_conf_pl_fn=File::Spec->catfile(
231 4 $template_dn, $config_hr->{'FILE_WEBDYNE_CONF_PL_TEMPLATE'});
232  
233  
234 # Open it as a template
235 #
236 4 ▶ my $template_webdyne_conf_pl_or=Text::Template->new(
Condition50%1/2
'Text::Template'->new('type', 'FILE', 'source', $template_webdyne_conf_pl_fn) || (return err("unable to open template $template_fn, $!"))
l!l
40
MC/DC0%0/1
'Text::Template'->new('type', 'FILE', 'source', $template_webdyne_conf_pl_fn) || (return err("unable to open template $template_fn, $!"))
'Text::Template'->new('type', 'FILE', 'source', $template_webdyne_conf_pl_fn)
Truth table50%1/2
A
A= 'Text::Template'->new('type', 'FILE', 'source', $template_webdyne_conf_pl_fn)
Aresult
11
00
237  
238 type => 'FILE',
239 source => $template_webdyne_conf_pl_fn
240  
241 ) || return err("unable to open template $template_fn, $!");
242  
243  
244 # Fill in with out self ref as a hash
245 #
246 4 ▶ my $webdyne_conf_pl=$template_webdyne_conf_pl_or->fill_in(
Condition50%1/2
$template_webdyne_conf_pl_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->']) || (return err("unable to fill in template $template_webdyne_conf_pl_fn, $Text::Template::ERROR"))
l!l
40
MC/DC0%0/1
$template_webdyne_conf_pl_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->']) || (return err("unable to fill in template $template_webdyne_conf_pl_fn, $Text::Template::ERROR"))
$template_webdyne_conf_pl_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->'])
Truth table50%1/2
A
A= $template_webdyne_conf_pl_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->'])
Aresult
11
00
247  
248 HASH => $config_hr,
249 DELIMITERS => ['<!--', '-->'],
250  
251 ) || return err("unable to fill in template $template_webdyne_conf_pl_fn, $Text::Template::ERROR");
252  
253  
254 # Print complete generated output if requested.
255 #
256 4 ▶ if ($opt_hr->{'text'} && !$Uninstall_fg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opt_hr->{"text"} and not $Uninstall_fg) 1 3 4
Condition66%2/3
$opt_hr->{"text"} and not $Uninstall_fg
!ll&&!rl&&r
301
MC/DC50%1/2
$opt_hr->{"text"} and not $Uninstall_fg
$opt_hr->{"text"} not $Uninstall_fg
Truth table66%2/3
A and not(B)
A= $opt_hr->{"text"}B= not $Uninstall_fg
ABresult
0X0
100
111
257 1 print "# $webdyne_conf_fn\n";
258 1 print $webdyne_conf;
259 1 print "\n# $webdyne_conf_pl_fn\n";
260 1 print $webdyne_conf_pl;
261 1 ▶ unless ($config_hr->{'HTTPD_SERVER_CONFIG_SKIP'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($config_hr->{'HTTPD_SERVER_CONFIG_SKIP'}) { } 1 0 1
if (do { my $enabled_dn = $config_hr->{"DIR_APACHE_CONF_ENABLED"} }) 1 0 1
262 my $apache_template_fn=File::Spec->catfile(
263 0 $template_dn, $config_hr->{'FILE_APACHE_CONF_TEMPLATE'});
264 0 ▶ my $apache_template_or=Text::Template->new(
Condition0%0/2
'Text::Template'->new('type', 'FILE', 'source', $apache_template_fn) || (return err("unable to open template $apache_template_fn, $!"))
l!l
00
MC/DC0%0/1
'Text::Template'->new('type', 'FILE', 'source', $apache_template_fn) || (return err("unable to open template $apache_template_fn, $!"))
'Text::Template'->new('type', 'FILE', 'source', $apache_template_fn)
Truth table0%0/2
A
A= 'Text::Template'->new('type', 'FILE', 'source', $apache_template_fn)
Aresult
11
00
265 type => 'FILE',
266 source => $apache_template_fn,
267 ) || return err("unable to open template $apache_template_fn, $!");
268 0 ▶ my $apache_conf=$apache_template_or->fill_in(
Condition0%0/2
$apache_template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->']) || (return err("unable to fill in template $apache_template_fn, $Text::Template::ERROR"))
l!l
00
MC/DC0%0/1
$apache_template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->']) || (return err("unable to fill in template $apache_template_fn, $Text::Template::ERROR"))
$apache_template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->'])
Truth table0%0/2
A
A= $apache_template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->'])
Aresult
11
00
269 HASH => $config_hr,
270 DELIMITERS => ['<!--', '-->'],
271 ) || return err("unable to fill in template $apache_template_fn, $Text::Template::ERROR");
272 0 print "\n# $apache_template_fn\n";
273 0 print $apache_conf;
274 }
275 0 elsif (my $enabled_dn=$config_hr->{'DIR_APACHE_CONF_ENABLED'}) {
276 1 my $enabled_fn=File::Spec->catfile($enabled_dn, $config_hr->{'FILE_WEBDYNE_CONF'});
277 1 print "\n# Enable by linking $enabled_fn to $webdyne_conf_fn\n";
278 }
279 1 return \undef;
280 }
281  
282  
283 # Open, write webdyne config file unless in uninstall
284 #
285 3 ▶ unless ($Uninstall_fg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Uninstall_fg) 1 2 3
286 1 message "writing Apache config file '$webdyne_conf_fn'.";
287 1 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) { } 1 0 1
288 1 message "would write Apache config file '$webdyne_conf_fn'.";
289 }
290 else {
291 0 ▶ my $webdyne_conf_fh=IO::File->new($webdyne_conf_fn, O_CREAT | O_WRONLY | O_TRUNC) ||
Condition0%0/2
'IO::File'->new($webdyne_conf_fn, 577) || (return err("unable to open file $webdyne_conf_fn, $!"))
l!l
00
MC/DC0%0/1
'IO::File'->new($webdyne_conf_fn, 577) || (return err("unable to open file $webdyne_conf_fn, $!"))
'IO::File'->new($webdyne_conf_fn, 577)
Truth table0%0/2
A
A= 'IO::File'->new($webdyne_conf_fn, 577)
Aresult
11
00
292 return err("unable to open file $webdyne_conf_fn, $!");
293 0 ▶ print $webdyne_conf_fh $webdyne_conf ||
Condition0%0/2
$webdyne_conf || (return err("unable to write file $webdyne_conf_fn, $!"))
l!l
00
MC/DC0%0/1
$webdyne_conf || (return err("unable to write file $webdyne_conf_fn, $!"))
$webdyne_conf
Truth table0%0/2
A
A= $webdyne_conf
Aresult
11
00
294 return err("unable to write file $webdyne_conf_fn, $!");
295 0 ▶ $webdyne_conf_fh->close() ||
Branch: 1 branch
BranchTrueFalseTotal
$webdyne_conf_fh->close or return err("unable to close file $webdyne_conf_fn, $!") 0 0 0
296 return err("unable to close file $webdyne_conf_fn, $!");
297 }
298 }
299  
300  
301 # Copy constants file into conf.d
302 #
303 3 ▶ unless ($Uninstall_fg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Uninstall_fg) { } 2 1 3
304  
305 1 message "writing Webdyne config file '$webdyne_conf_pl_fn'.";
306 1 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) { } 1 0 1
307 1 message "would write Webdyne config file '$webdyne_conf_pl_fn'.";
308 }
309 else {
310 0 ▶ my $webdyne_conf_pl_fh=IO::File->new($webdyne_conf_pl_fn, O_CREAT | O_WRONLY | O_TRUNC) ||
Condition0%0/2
'IO::File'->new($webdyne_conf_pl_fn, 577) || (return err("unable to open file $webdyne_conf_pl_fn, $!"))
l!l
00
MC/DC0%0/1
'IO::File'->new($webdyne_conf_pl_fn, 577) || (return err("unable to open file $webdyne_conf_pl_fn, $!"))
'IO::File'->new($webdyne_conf_pl_fn, 577)
Truth table0%0/2
A
A= 'IO::File'->new($webdyne_conf_pl_fn, 577)
Aresult
11
00
311 return err("unable to open file $webdyne_conf_pl_fn, $!");
312 0 ▶ print $webdyne_conf_pl_fh $webdyne_conf_pl ||
Condition0%0/2
$webdyne_conf_pl || (return err("unable to write file $webdyne_conf_pl_fn, $!"))
l!l
00
MC/DC0%0/1
$webdyne_conf_pl || (return err("unable to write file $webdyne_conf_pl_fn, $!"))
$webdyne_conf_pl
Truth table0%0/2
A
A= $webdyne_conf_pl
Aresult
11
00
313 return err("unable to write file $webdyne_conf_pl_fn, $!");
314 0 ▶ $webdyne_conf_pl_fh->close() ||
Branch: 1 branch
BranchTrueFalseTotal
$webdyne_conf_pl_fh->close or return err("unable to close file $webdyne_conf_pl_fn, $!") 0 0 0
315 return err("unable to close file $webdyne_conf_pl_fn, $!");
316 }
317  
318 }
319 else {
320
321 # In uninstall - get rid of conf file
322 #
323 2 ▶ if (-f $webdyne_conf_pl_fn) {
Branch: 1 branch
BranchTrueFalseTotal
if (-f $webdyne_conf_pl_fn) 2 0 2
324 2 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) { } 1 1 2
325 1 message "would remove config file $webdyne_conf_pl_fn";
326 }
327 else {
328 1 ▶ unlink($webdyne_conf_pl_fn) ||
Branch: 1 branch
BranchTrueFalseTotal
unlink $webdyne_conf_pl_fn or return err("unable to remove config file $webdyne_conf_pl_fn, $!") 1 0 1
329 return err("unable to remove config file $webdyne_conf_pl_fn, $!");
330 1 message "remove config file $webdyne_conf_pl_fn";
331 }
332 }
333  
334 }
335  
336  
337 # Debian-style Apache installs use conf-available/conf-enabled.
338 #
339 3 ▶ if (my $enabled_dn=$config_hr->{'DIR_APACHE_CONF_ENABLED'}) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $enabled_dn = $config_hr->{"DIR_APACHE_CONF_ENABLED"}) 3 0 3
340 3 my $enabled_fn=File::Spec->catfile($enabled_dn, $config_hr->{'FILE_WEBDYNE_CONF'});
341 3 ▶ if ($Uninstall_fg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Uninstall_fg) { } 2 1 3
342 2 ▶ if (-l $enabled_fn) {
Branch: 2 branches
BranchTrueFalseTotal
if (-l $enabled_fn) { } 2 0 2
elsif (-e $enabled_fn) { } 0 0 0
343 2 my $target=readlink($enabled_fn);
344 2 ▶ if ($target eq $webdyne_conf_fn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target eq $webdyne_conf_fn) { } 1 1 2
345 1 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) { } 1 0 1
346 1 message "would remove enabled Apache config link $enabled_fn";
347 }
348 else {
349 0 ▶ unlink($enabled_fn) ||
Branch: 1 branch
BranchTrueFalseTotal
unlink $enabled_fn or return err("unable to remove enabled Apache config link $enabled_fn, $!") 0 0 0
350 return err("unable to remove enabled Apache config link $enabled_fn, $!");
351 0 message "remove enabled Apache config link $enabled_fn";
352 }
353 }
354 else {
355 1 message "not removing enabled Apache config link $enabled_fn; target is $target";
356 }
357 }
358 elsif (-e $enabled_fn) {
359 0 message "not removing enabled Apache config path $enabled_fn; it is not a symlink";
360 }
361 }
362 else {
363 1 ▶ unless (-e $enabled_fn) {
Branch: 2 branches
BranchTrueFalseTotal
if (-e $enabled_fn) { } 0 1 1
if (do { -l $enabled_fn }) { } 0 0 0
364 1 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) { } 1 0 1
365 1 message "would enable Apache config link '$enabled_fn'.";
366 }
367 else {
368 0 ▶ symlink($webdyne_conf_fn, $enabled_fn) ||
Branch: 1 branch
BranchTrueFalseTotal
symlink $webdyne_conf_fn, $enabled_fn or return err("unable to enable Apache config $enabled_fn -> $webdyne_conf_fn, $!") 0 0 0
369 return err("unable to enable Apache config $enabled_fn -> $webdyne_conf_fn, $!");
370 0 message "enabled Apache config link '$enabled_fn'.";
371 }
372 }
373 elsif (-l $enabled_fn) {
374 0 my $target=readlink($enabled_fn);
375 0 ▶ return err("Apache config link $enabled_fn points to $target, expected $webdyne_conf_fn")
Branch: 1 branch
BranchTrueFalseTotal
unless $target eq $webdyne_conf_fn 0 0 0
376 unless $target eq $webdyne_conf_fn;
377 }
378 else {
379 0 return err("Apache config enable path $enabled_fn already exists and is not a symlink");
380 }
381 }
382 }
383
384  
385  
386 # Only modify config file if no conf.d dir, denoted by var below
387 #
388 3 ▶ unless ($config_hr->{'HTTPD_SERVER_CONFIG_SKIP'}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($config_hr->{'HTTPD_SERVER_CONFIG_SKIP'}) { } 3 0 3
389  
390  
391 # Get Apache config file, append root if not absolute
392 #
393 0 ▶ my $apache_conf_fn=$config_hr->{'HTTPD_SERVER_CONFIG_FILE'} ||
Condition0%0/2
$config_hr->{'HTTPD_SERVER_CONFIG_FILE'} || (return err('unable to determine main server config file'))
l!l
00
MC/DC0%0/1
$config_hr->{'HTTPD_SERVER_CONFIG_FILE'} || (return err('unable to determine main server config file'))
$config_hr->{'HTTPD_SERVER_CONFIG_FILE'}
Truth table0%0/2
A
A= $config_hr->{'HTTPD_SERVER_CONFIG_FILE'}
Aresult
11
00
394 return err("unable to determine main server config file");
395 ($apache_conf_fn=~/^\//) || (
396 $apache_conf_fn=File::Spec->catfile(
397 0 ▶ $config_hr->{'HTTPD_ROOT'}, $apache_conf_fn
Branch: 1 branch
BranchTrueFalseTotal
$apache_conf_fn =~ m[^/] or $apache_conf_fn = "File::Spec"->catfile($config_hr->{"HTTPD_ROOT"}, $apache_conf_fn) 0 0 0
398 ));
399 0 ▶ my $apache_conf_fh=$opt_hr->{'text'} ? *STDOUT : IO::File->new($apache_conf_fn, O_RDONLY) ||
Branch: 1 branch
BranchTrueFalseTotal
$opt_hr->{'text'} ? : 0 0 0
Condition0%0/2
"IO::File"->new($apache_conf_fn, 0) or return err("unable to open file $apache_conf_fn, $!")
l!l
00
MC/DC0%0/1
"IO::File"->new($apache_conf_fn, 0) or return err("unable to open file $apache_conf_fn, $!")
"IO::File"->new($apache_conf_fn, 0)
Truth table0%0/2
A
A= "IO::File"->new($apache_conf_fn, 0)
Aresult
11
00
400 return err("unable to open file $apache_conf_fn, $!");
401 0 message "Apache config file '$apache_conf_fn'";
402  
403  
404 # Setup delims looking for
405 #
406 0 my ($delim, @delim)=$config_hr->{'FILE_APACHE_CONF_DELIM'};
407  
408  
409 # Turn into array, search for delims
410 #
411 0 my ($index, @apache_conf);
412 0 ▶ while (my $line=<$apache_conf_fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $line = readline $apache_conf_fh)) 0 0 0
413 0 push @apache_conf, $line;
414 0 ▶ push(@delim, $index) if $line=~/\Q$delim\E/;
Branch: 1 branch
BranchTrueFalseTotal
if $line =~ /\Q$delim\E/ 0 0 0
415 0 $index++;
416 }
417  
418  
419 # Check found right number of delims
420 #
421 0 ▶ if (@delim != 2 and @delim != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (@delim != 2 and @delim != 0) 0 0 0
Condition0%0/3
@delim != 2 and @delim != 0
!ll&&!rl&&r
000
MC/DC0%0/2
@delim != 2 and @delim != 0
@delim != 2 @delim != 0
Truth table0%0/3
A and B
A= @delim != 2B= @delim != 0
ABresult
0X0
100
111
422  
423 0 ▶ return err(
Branch: 1 branch
BranchTrueFalseTotal
$#delim ? : 0 0 0
424 "found %s '$delim' delimiter%s in $apache_conf_fn at line%s %s, expected exactly 2 delimiters",
425 scalar @delim,
426 ($#delim ? 's' : '') x 2,
427 join(',', @delim)
428 );
429  
430 }
431  
432  
433 # Check if delim found, if not, make last line
434 #
435 0 ▶ unless (@delim) {@delim=($index, $index-1)}
Branch: 1 branch
BranchTrueFalseTotal
unless (@delim) 0 0 0
436 0 $delim[1]++;
437  
438  
439 # Close
440 #
441 0 ▶ $apache_conf_fh->close() unless ($apache_conf_fh eq '*main::STDOUT');
Branch: 1 branch
BranchTrueFalseTotal
unless $apache_conf_fh eq "*main::STDOUT" 0 0 0
442 0 ▶ exit if $opt_hr->{'text'};
Branch: 1 branch
BranchTrueFalseTotal
if $opt_hr->{"text"} 0 0 0
443  
444  
445 # Splice the lines between the delimiters out
446 #
447 0 splice(@apache_conf, $delim[0], $delim[1]-$delim[0]);
448  
449  
450 # Clean up end of conf file, remove excess CR's
451 #
452 0 my $lineno=$delim[0]-1;
453 0 ▶ for (undef; $lineno > 0; $lineno--) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lineno > 0) 0 0 0
454  
455  
456 # We are going backwards through the file, as soon as we
457 # see something we quit
458 #
459 0 my $line=$apache_conf[$lineno];
460 0 chomp($line);
461  
462  
463 # Empty
464 #
465 0 ▶ if ($line=~/^\s*$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($line =~ /^\s*$/) { } 0 0 0
466  
467  
468 # Yes, delete and continue
469 #
470 0 splice(@apache_conf, $lineno, 1);
471  
472 }
473 else {
474  
475  
476 # No, quit after rewinding lineno to last val
477 #
478 0 $lineno++;
479 0 last;
480  
481 }
482 }
483  
484  
485 # Only splice back in if not uninstalling
486 #
487 0 ▶ unless ($Uninstall_fg) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Uninstall_fg) 0 0 0
488  
489  
490 # Get template we want to include in the config file
491 #
492 $template_fn=File::Spec->catfile(
493 0 $template_dn, $config_hr->{'FILE_APACHE_CONF_TEMPLATE'});
494  
495  
496 # Open it as a template
497 #
498 0 ▶ $template_or=Text::Template->new(
Condition0%0/2
'Text::Template'->new('type', 'FILE', 'source', $template_fn) || (return err("unable to open template $template_fn, $!"))
l!l
00
MC/DC0%0/1
'Text::Template'->new('type', 'FILE', 'source', $template_fn) || (return err("unable to open template $template_fn, $!"))
'Text::Template'->new('type', 'FILE', 'source', $template_fn)
Truth table0%0/2
A
A= 'Text::Template'->new('type', 'FILE', 'source', $template_fn)
Aresult
11
00
499  
500 type => 'FILE',
501 source => $template_fn,
502  
503 ) || return err("unable to open template $template_fn, $!");
504  
505  
506 # Fill in with out self ref as a hash
507 #
508 0 ▶ my $apache_conf=$template_or->fill_in(
Condition0%0/2
$template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->']) || (return err("unable to fill in template $template_fn, $Text::Template::ERROR"))
l!l
00
MC/DC0%0/1
$template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->']) || (return err("unable to fill in template $template_fn, $Text::Template::ERROR"))
$template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->'])
Truth table0%0/2
A
A= $template_or->fill_in('HASH', $config_hr, 'DELIMITERS', ['<!--', '-->'])
Aresult
11
00
509  
510 HASH => $config_hr,
511 DELIMITERS => ['<!--', '-->'],
512  
513 ) || return err("unable to fill in template $template_fn, $Text::Template::ERROR");
514  
515  
516 # Splice in now, but write out at end of block
517 #
518 0 splice(@apache_conf, $lineno, undef, $apache_conf);
519  
520  
521 }
522  
523  
524 # Re-open httpd.conf for write out, unless uninstall and delims not found, which
525 # means nothing was changed.
526 #
527 0 ▶ unless ($Uninstall_fg && ($delim[0] == $delim[1])) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($Uninstall_fg and $delim[0] == $delim[1]) 0 0 0
Condition0%0/3
$Uninstall_fg and $delim[0] == $delim[1]
!ll&&!rl&&r
000
MC/DC0%0/2
$Uninstall_fg and $delim[0] == $delim[1]
$Uninstall_fg $delim[0] == $delim[1]
Truth table0%0/3
A and B
A= $Uninstall_fgB= $delim[0] == $delim[1]
ABresult
0X0
100
111
528 0 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) { } 0 0 0
529 0 message "would update Apache config file '$apache_conf_fn'.";
530 }
531 else {
532 0 ▶ $apache_conf_fh=IO::File->new($apache_conf_fn, O_TRUNC | O_WRONLY) ||
Condition0%0/2
'IO::File'->new($apache_conf_fn, 513) || (return err("unable to open file $apache_conf_fn, $!"))
l!l
00
MC/DC0%0/1
'IO::File'->new($apache_conf_fn, 513) || (return err("unable to open file $apache_conf_fn, $!"))
'IO::File'->new($apache_conf_fn, 513)
Truth table0%0/2
A
A= 'IO::File'->new($apache_conf_fn, 513)
Aresult
11
00
533 return err("unable to open file $apache_conf_fn, $!");
534 0 ▶ print $apache_conf_fh join('', @apache_conf) ||
Condition0%0/2
join('', @apache_conf) || (return err("unable to write file $apache_conf_fn, $!"))
l!l
00
MC/DC0%0/1
join('', @apache_conf) || (return err("unable to write file $apache_conf_fn, $!"))
join('', @apache_conf)
Truth table0%0/2
A
A= join('', @apache_conf)
Aresult
11
00
535 return err("unable to write file $apache_conf_fn, $!");
536 0 ▶ $apache_conf_fh->close() ||
Branch: 1 branch
BranchTrueFalseTotal
$apache_conf_fh->close or return err("unable to close file $apache_conf_fn, $!") 0 0 0
537 return err("unable to close file $apache_conf_fn, $!");
538 0 message "Apache config file '$apache_conf_fn' updated.";
539 }
540 }
541  
542 }
543 else {
544  
545 # No need to update Apache config file - using conf.d dir
546 #
547 3 message 'Apache uses conf.d directory - not changing httpd.conf file';
548  
549 }
550  
551  
552 # Almost done ..
553 #
554 3 ▶ unless ($Uninstall_fg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Uninstall_fg) { } 2 1 3
555  
556 # Chown cache dir unless it is the system temp dir - then don't mess with it
557 #
558 1 ▶ if ($cache_dn) {
Branch: 1 branch
BranchTrueFalseTotal
if ($cache_dn) 1 0 1
559 1 ▶ unless ($cache_dn eq File::Spec->tmpdir()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($cache_dn eq "File::Spec"->tmpdir) 1 0 1
560 1 message
561 "Granting Apache ($APACHE_UNAME.$APACHE_GNAME) ownership of cache directory '$cache_dn'.";
562 1 ▶ if ($dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($dry_run) { } 1 0 1
563 1 message "would chown $cache_dn to $APACHE_UNAME.$APACHE_GNAME";
564 }
565 else {
566 0 ▶ chown($APACHE_UID, $APACHE_GID, $cache_dn) ||
Branch: 1 branch
BranchTrueFalseTotal
chown $WebDyne::Install::Apache::APACHE_UID, $WebDyne::Install::Apache::APACHE_GID, $cache_dn or return err("unable to chown $cache_dn to $WebDyne::Install::Apache::APACHE_UNAME.$WebDyne::Install::Apache::APACHE_GNAME") 0 0 0
567 return err("unable to chown $cache_dn to $APACHE_UNAME.$APACHE_GNAME");
568 }
569  
570  
571 # Selinx fixup
572 #
573 1 ▶ if ($SELINUX_ENABLED_BIN && !$dry_run) {
Branch: 1 branch
BranchTrueFalseTotal
if ($WebDyne::Install::Apache::SELINUX_ENABLED_BIN and not $dry_run) 0 1 1
Condition33%1/3
$WebDyne::Install::Apache::SELINUX_ENABLED_BIN and not $dry_run
!ll&&!rl&&r
100
MC/DC0%0/2
$WebDyne::Install::Apache::SELINUX_ENABLED_BIN and not $dry_run
$WebDyne::Install::Apache::SELINUX_ENABLED_BIN not $dry_run
Truth table33%1/3
A and not(B)
A= $WebDyne::Install::Apache::SELINUX_ENABLED_BINB= not $dry_run
ABresult
0X0
100
111
574  
575  
576 # Run to see if SELinux enabled
577 #
578 0 ▶ if ((system($SELINUX_ENABLED_BIN) >> 8) == 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (system($WebDyne::Install::Apache::SELINUX_ENABLED_BIN) >> 8 == 0) 0 0 0
579  
580 # SELinux is enabled. chcon first
581 #
582 0 message("SELinux appears enabled - attempting to set cache directory file contexts appropriately.");
583 0 ▶ if (my $chcon_bin=$SELINUX_CHCON_BIN) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chcon_bin = $WebDyne::Install::Apache::SELINUX_CHCON_BIN) { } 0 0 0
584  
585 0 message("Adding SELinux context '$SELINUX_CONTEXT_HTTPD' to cache directory '$cache_dn' via chcon");
586 0 ▶ if (my $rc=system($chcon_bin, '-R', '-t', $SELINUX_CONTEXT_HTTPD, $cache_dn) >> 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rc = system($chcon_bin, "-R", "-t", $WebDyne::Install::Apache::SELINUX_CONTEXT_HTTPD, $cache_dn) >> 8) 0 0 0
587 0 message("WARNING: SELinux chcon of $cache_dn to $SELINUX_CONTEXT_HTTPD failed with error code $rc\n")
588 }
589  
590  
591 # Dynaloader files
592 #
593 0 my @module_so_fn;
594 0 ▶ while (my ($module_so, $module_so_fn)=each %{$SELINUX_SO_CHECK}) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %{$WebDyne::Install::Apache::SELINUX_SO_CHECK;}) 0 0 0
595 0 ▶ if (eval("require $module_so")) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval "require $module_so") 0 0 0
596 0 foreach my $symbol (keys %::) {
597 0 ▶ if ($symbol=~/^_<(.*)\/\Q$module_so_fn\E$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($symbol =~ m[^_<(.*)/\Q$module_so_fn\E$]) 0 0 0
598 0 push @module_so_fn, File::Spec->catfile($1, $module_so_fn);
599 }
600 }
601 }
602 }
603  
604 0 foreach my $module_so_fn (@module_so_fn) {
605  
606 0 ▶ my $context_ls=qx/ls -lZ $module_so_fn/ ||
Condition0%0/3
`ls -lZ $module_so_fn` || message("WARNING: unable to get context of file $module_so_fn")
l!l&&r!l&&!r
000
MC/DC0%0/2
`ls -lZ $module_so_fn` || message("WARNING: unable to get context of file $module_so_fn")
`ls -lZ $module_so_fn` message("WARNING: unable to get context of file $module_so_fn")
Truth table0%0/3
A || B
A= `ls -lZ $module_so_fn`B= message("WARNING: unable to get context of file $module_so_fn")
ABresult
1X1
011
000
607 message("WARNING: unable to get context of file $module_so_fn");
608 0 my @context_ls=split(/\s+/, $context_ls);
609 0 my $context=$context_ls[3];
610 0 my ($user, $role, $type)=split(/\:/, $context);
611 0 ▶ if (($type ne $SELINUX_CONTEXT_LIB) && !$opt_hr->{'setcontext'}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($type ne $WebDyne::Install::Apache::SELINUX_CONTEXT_LIB and not $opt_hr->{'setcontext'}) { } 0 0 0
elsif ($type ne $WebDyne::Install::Apache::SELINUX_CONTEXT_LIB and $opt_hr->{'setcontext'}) { } 0 0 0
Condition0%0/3
$type ne $WebDyne::Install::Apache::SELINUX_CONTEXT_LIB and not $opt_hr->{"setcontext"}
!ll&&!rl&&r
000
MC/DC0%0/2
$type ne $WebDyne::Install::Apache::SELINUX_CONTEXT_LIB and not $opt_hr->{"setcontext"}
$type ne $WebDyne::Install::Apache::SELINUX_CONTEXT_LIB not $opt_hr->{"setcontext"}
Truth table0%0/3
A and not(B)
A= $type ne $WebDyne::Install::Apache::SELINUX_CONTEXT_LIBB= not $opt_hr->{"setcontext"}
ABresult
0X0
100
111
612 0 message;
613 0 message("WARNING: SELinux context type of '$module_so_fn' is '$type'");
614 0 message("WARNING: file may not be loadable by Apache ! Use '$0 --setcontext' to change or fix manually");
615 0 message;
616 }
617 ▶ elsif (($type ne $SELINUX_CONTEXT_LIB) && $opt_hr->{'setcontext'}) {
Condition0%0/3
$type ne $WebDyne::Install::Apache::SELINUX_CONTEXT_LIB and $opt_hr->{"setcontext"}
!ll&&!rl&&r
000
MC/DC0%0/2
$type ne $WebDyne::Install::Apache::SELINUX_CONTEXT_LIB and $opt_hr->{"setcontext"}
$type ne $WebDyne::Install::Apache::SELINUX_CONTEXT_LIB $opt_hr->{"setcontext"}
Truth table0%0/3
A and B
A= $type ne $WebDyne::Install::Apache::SELINUX_CONTEXT_LIBB= $opt_hr->{"setcontext"}
ABresult
0X0
100
111
618  
619 0 message("Adding SELinux context '$SELINUX_CONTEXT_LIB' to module library '$module_so_fn' via chcon");
620  
621 0 ▶ if (my $rc=system($chcon_bin, '-t', $SELINUX_CONTEXT_LIB, $module_so_fn) >> 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rc = system($chcon_bin, "-t", $WebDyne::Install::Apache::SELINUX_CONTEXT_LIB, $module_so_fn) >> 8) 0 0 0
622 0 message("WARNING: SELinux chcon of '$module_so_fn' to '$SELINUX_CONTEXT_LIB' failed with error code $rc\n")
623 }
624  
625 }
626  
627 }
628  
629 }
630 else {
631 0 message(
632 'WARNING: SELinux appears enabled, but the \'chcon\' command was not found - ' .
633 "your cache directory may not be writable\n"
634 );
635 }
636  
637 # Now semanage, if we can find it
638 #
639 0 ▶ if (my $semanage_bin=$SELINUX_SEMANAGE_BIN) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $semanage_bin = $WebDyne::Install::Apache::SELINUX_SEMANAGE_BIN) { } 0 0 0
640  
641 # List
642 #
643 0 my $selist=qx/$SELINUX_SEMANAGE_BIN fcontext -l -n/;
644 0 ▶ unless ($selist=~/^\Q$cache_dn\E/m) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($selist =~ /^\Q$cache_dn\E/m) 0 0 0
645  
646 # Context not added yet
647 #
648 0 message("Adding SELinux context '$SELINUX_CONTEXT_HTTPD' to cache directory '$cache_dn' via semanage");
649 0 ▶ if (my $rc=system($semanage_bin, 'fcontext', '-a', '-t', $SELINUX_CONTEXT_HTTPD, "${cache_dn}(/.*)?") >> 8) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rc = system($semanage_bin, "fcontext", "-a", "-t", $WebDyne::Install::Apache::SELINUX_CONTEXT_HTTPD, "$cache_dn(/.*)?") >> 8) 0 0 0
650 0 message("WARNING: SELinux semanage of $cache_dn to $SELINUX_CONTEXT_HTTPD failed with error code $rc\n")
651 }
652 }
653 }
654 else {
655 0 message('WARNING: SELinux semanage utility not found - chcon changes will be lost if SELinux relabel takes place.')
656 }
657 }
658 }
659  
660  
661 # Done
662 #
663 1 message 'install completed.'
664  
665 }
666 }
667 }
668 else {
669  
670 2 message 'uninstall completed'
671  
672 }
673  
674  
675 # Finished
676 3 message;
677 3 return \undef;
678  
679  
680 }
681 __END__
↑ Summary lib/WebDyne.pm »