@@ -98,13 +98,20 @@ $options->{'thruk-libs'} = '' if $options->{'nolibs'};
98
98
99
99
# recent apaches might require the UnsafeAllow3F flag
100
100
if (!$options -> {' nounsafeallow3f' } && !$options -> {' unsafeallow3f' }) {
101
- # try to autodetect
102
- my ($os , $ver ) = _get_os();
103
- if ($os eq ' rhel' && $ver >= 8) {
104
- $options -> {' unsafeallow3f' } = 1;
105
- }
106
- if ($os eq ' debian' && ($ver eq ' sid' || $ver >= 11)) {
107
- $options -> {' unsafeallow3f' } = 1;
101
+ my ($apache_bin , $module_dir ) = _get_apache();
102
+ if ($apache_bin && $module_dir ) {
103
+ my $src = _read(' ./support/apache-test-unsafeallow.conf' );
104
+ require File::Temp;
105
+ my ($fh , $tmpfile ) = File::Temp::tempfile();
106
+ $src =~ s % ###APACHE_MODULE_DIR###% $module_dir % g ;
107
+ print $fh $src ;
108
+ close ($fh );
109
+ my $cmd = " $apache_bin -t -f $tmpfile 2>&1" ;
110
+ ` $cmd 2>&1` ;
111
+ if ($? == 0) {
112
+ $options -> {' unsafeallow3f' } = 1;
113
+ }
114
+ unlink ($tmpfile );
108
115
}
109
116
}
110
117
if ($options -> {' nounsafeallow3f' }) {
@@ -201,53 +208,34 @@ EOT
201
208
202
209
exit ;
203
210
204
- # try to detect os and version
205
- sub _get_os {
206
- my ($os , $version ) = (" " , 0);
207
- local $/ = undef ;
211
+ # try to detect apache
212
+ sub _get_apache {
213
+ my ($apache_bin , $module_dir );
208
214
209
- # right now, we only need rhel/rocky/alma
210
- if (-e ' /etc/redhat-release' ) {
211
- my $release_file = ' /etc/redhat-release' ;
212
- open (my $fh , ' <' , $release_file ) or die (" cannot read $release_file : $! " );
213
- my $release_info = <$fh >;
214
- close $fh ;
215
-
216
- if ($release_info =~ / ^(.*?)(?: release)? ([\d .]+)/ ) {
217
- my $version = $2 ;
218
- $version =~ s /\. .*$// gmx ; # we only need the major number
219
- return (" rhel" , 0+$version );
220
- } else {
221
- die (sprintf (" Unable to detect distribution and version from %s :\n %s " , $release_file , $release_info ));
222
- }
223
- } elsif (-e ' /etc/os-release' ) {
224
- my $release_file = ' /etc/os-release' ;
225
- open (my $fh , ' <' , $release_file ) or die (" cannot read $release_file : $! " );
226
- my $release_info = <$fh >;
227
- close $fh ;
228
-
229
- for my $line (split /\n/mx, $release_info ) {
230
- if ($line =~ / ^ID="?(.*?)"?$ /mx ) {
231
- $os = $1 ;
232
- }
233
- if ($line =~ / ^VERSION_ID="?(.*?)"?$ /mx ) {
234
- $version = $1 ;
235
- $version =~ s /\. .*$// gmx ; # we only need the major number
236
- }
237
- if ($line =~ / ^PRETTY_NAME=.*\/ sid\" $ /mx ) {
238
- $version = " sid" ;
239
- }
215
+ for my $bin (qw( /sbin/apache2 /usr/sbin/apache2 /usr/sbin/httpd usr/sbin/httpd2-prefork) ) {
216
+ if (-x $bin ) {
217
+ $apache_bin = $bin ;
218
+ last ;
240
219
}
220
+ }
241
221
242
- if ($os && $version ) {
243
- return ($os , $version ) if $version eq ' sid' ;
244
- return ($os , 0+$version );
245
- } else {
246
- die (sprintf (" Unable to detect distribution and version from %s :\n %s " , $release_file , $release_info ));
222
+ for my $dir (qw( /usr/lib64/httpd/modules /usr/lib/apache2/modules /usr/lib64/apache2-prefork /usr/lib64/httpd/modules) ) {
223
+ if (-x $dir ) {
224
+ $module_dir = $dir ;
225
+ last ;
247
226
}
248
227
}
249
228
250
- return ($os , $version );
229
+ return ($apache_bin , $module_dir );
230
+ }
231
+
232
+ sub _read {
233
+ my ($file ) = @_ ;
234
+ local $/ = undef ;
235
+ open (my $fh , ' <' , $file ) or die (" cannot read file: $file : $! " );
236
+ my $data = <$fh >;
237
+ close ($fh );
238
+ return $data ;
251
239
}
252
240
253
241
1;
0 commit comments