Edit File: ensure_apache_local_config_has_defaults
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - scripts/ensure_apache_local_config_has_defaults Copyright 2017 cPanel, Inc. # All rights reserved. # copyright@cpanel.net http://cpanel.net # This code is subject to the cPanel license. Unauthorized copying is prohibited package scripts::ensure_apache_local_config_has_defaults; =encoding utf-8 =head1 NAME ensure_apache_local_config_has_defaults =head1 USAGE ensure_apache_local_config_has_defaults =head1 DESCRIPTION This script verifies that the defaults are not missing from /var/cpanel/conf/apache/local if it exists. If the defaults are missing, it will add them. =cut use strict; use warnings; use Try::Tiny; use Cpanel::AdvConfig::apache (); use Whostmgr::TweakSettings (); use Cpanel::AdvConfig::apache (); use Cpanel::ServerTasks (); use Cpanel::HttpUtils::Version (); our $LOCAL_CONFIG_PATH = '/var/cpanel/conf/apache/local'; exit( __PACKAGE__->run() ) if !caller; sub run { my ($self) = @_; # Only run when Apache is installed, to avoid warnings on new installations. return 1 unless Cpanel::HttpUtils::Version::get_httpd_version(); require Whostmgr::TweakSettings::Apache; my ( $local_config_settings_are_missing, $settings ) = $self->_local_configuration_settings_are_partial(); if ($local_config_settings_are_missing) { print "The Apache local configuration settings are missing the defaults.\n"; if ( !$self->_save_apache_local_configuration_settings_and_add_missing_defaults($settings) ) { print "The system failed to save the Apache local configuration settings.\n"; return 1; } my ($local_config_settings_are_missing_after_update) = $self->_local_configuration_settings_are_partial(); if ( !$local_config_settings_are_missing_after_update ) { Cpanel::ServerTasks::queue_task( ['ApacheTasks'], 'build_apache_conf', 'apache_restart' ); print "The system successfully restored the missing Apache local settings.\n"; return 0; } print "The system failed to restore the missing Apache local settings.\n"; return 1; } print "The Apache local configuration settings are correct.\n"; return 0; } sub _local_config_exists { return -e $LOCAL_CONFIG_PATH ? 1 : 0; } sub _local_configuration_settings_are_partial { my ($self) = @_; if ( !$self->_local_config_exists() ) { return ( 0, undef ); } my $current_settings = Cpanel::AdvConfig::apache::get_config( { 'skip_vhosts' => 1 } ); my $settings = Whostmgr::TweakSettings::Apache::convert_stored_apache_tweak_settings($current_settings); my @enabled_root_options; if ( $settings->{'root_options'} && ref $settings->{'root_options'} ) { @enabled_root_options = grep { $settings->{'root_options'}{$_} } keys %{ $settings->{'root_options'} }; } # # If all options are 0 and startservers is missing # than we tried likely saved when the configuration # was missing so we need to reload defaults # if ( !@enabled_root_options && !$settings->{'startservers'} ) { return ( 1, $settings ); } return ( 0, undef ); } sub _save_apache_local_configuration_settings_and_add_missing_defaults { my ( $self, $settings ) = @_; # We want fill_missing_defaults to fill in root_options # since they were zeroed out due the the missing configuration file delete $settings->{'root_options'}; # Whostmgr::TweakSettings::fill_missing_defaults( 'Apache', $settings ); # my ( $new_tweak_settings, $reject ) = Whostmgr::TweakSettings::process_input_values( "Apache", $settings ); return Cpanel::AdvConfig::apache::save_main_item(%$new_tweak_settings); } 1;