Edit File: ensure_includes
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - scripts/ensure_includes Copyright 2014 cPanel, Inc. # All Rights Reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited use strict; use warnings; use Cpanel::Config::Httpd::EA3 (); use Cpanel::Config::Httpd::EA4 (); use Cpanel::ConfigFiles::Apache (); use Cpanel::Exception (); use Cpanel::Logger (); use Cpanel::Transaction (); use Cpanel::HttpUtils::Version (); use Cpanel::SafeRun::Errors (); my $logger = Cpanel::Logger->new(); if ( Cpanel::Config::Httpd::EA4::is_ea4() && caller() ) { die Cpanel::Exception::create( 'Services::Deprecated', [ service => 'ensure_includes' ] ); } elsif ( Cpanel::Config::Httpd::EA4::is_ea4() ) { $logger->warn("ensure_includes is not supported for EasyApache 4, please edit config files as detailed in the EasyApache 4 documentation."); exit 1; } my $apacheconf = Cpanel::ConfigFiles::Apache->new(); __PACKAGE__->script(@ARGV) unless caller(); sub script { my ( $class, @argv ) = @_; my $needs_rebuild = 0; my $apv = Cpanel::HttpUtils::Version::get_current_apache_version_key(); die 'Could not determine apache version' if !$apv; if ( $apv =~ m/2/ ) { $apv = 2; } my ( $ok, $trans ) = Cpanel::Transaction::get_httpd_conf(); if ($ok) { my $httpd_conf_sr = $trans->get_data(); my ( $ok, $err ) = $trans->close(); warn $err if !$ok; # The only system still calling ensure_includes is install/Apache.pm and in that module the files below are # created, so they SHOULD exist. But, just in case this is called directly we'll test for them. my @include_files_and_tests = ( [ $apacheconf->dir_conf_includes() . '/pre_main_global.conf', qr/\n\s*Include.*?pre_main_global.*?\n/si ], [ $apacheconf->dir_conf_includes() . "/pre_main_$apv.conf", qr/\n\s*Include.*?pre_main_\Q$apv\E.*?\n/si ], [ $apacheconf->dir_conf_includes() . '/pre_virtualhost_global.conf', qr/\n\s*Include.*?pre_virtualhost_global.*?\n/si ], [ $apacheconf->dir_conf_includes() . "/pre_virtualhost_$apv.conf", qr/\n\s*Include.*?pre_virtualhost_\Q$apv\E.*?\n/si ], [ $apacheconf->dir_conf_includes() . '/post_virtualhost_global.conf', qr/\n\s*Include.*?post_virtualhost_global.*?\n/si ], [ $apacheconf->dir_conf_includes() . "/post_virtualhost_$apv.conf", qr/\n\s*Include.*?post_virtualhost_\Q$apv\E.*?\n/si ], [ $apacheconf->dir_conf_includes() . '/account_suspensions.conf', qr/\n\s*Include.*?account_suspensions\.conf.*?\n/si ], ); foreach my $include_file_and_test (@include_files_and_tests) { if ( -e $include_file_and_test->[0] && $$httpd_conf_sr !~ $include_file_and_test->[1] ) { $needs_rebuild = 1; print "Missing include file: " . $include_file_and_test->[0] . "\n"; # It only takes one include file missing from the httpd.conf to need a rebuild last; } } } else { $needs_rebuild = 1; } if ($needs_rebuild) { print "Rebuilding httpd.conf to add missing include file.\n"; if ( Cpanel::Config::Httpd::EA3::is_ea3() ) { Cpanel::SafeRun::Errors::saferunallerrors( '/usr/local/cpanel/bin/apache_conf_distiller', '--update' ); } my $output = Cpanel::SafeRun::Errors::saferunallerrors('/usr/local/cpanel/bin/build_apache_conf'); if ( $output !~ /OK$/ ) { print STDERR "Error rebuilding the apache configuration: $output\n"; } } return; }