Edit File: buildhttpdconf
#!/usr/local/cpanel/3rdparty/bin/perl # cpanel - bin/build_apache_conf 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 BuildHttpdConf; use strict; use warnings; use Cpanel::AdvConfig (); #issafe use Cpanel::AdvConfig::apache (); #issafe use Cpanel::ConfigFiles::Apache (); use Cpanel::Config::Httpd::EA4 (); #issafe use Cpanel::Config::Httpd::EA3 (); #issafe use Cpanel::Rand (); our $apache_conf; our $data_store_dir = '/var/cpanel/conf/apache/'; my $apacheconf = Cpanel::ConfigFiles::Apache->new(); sub run { my (@args) = @_; $apache_conf = $apacheconf->file_conf(); if ( grep( /^--preview$/, @args ) ) { $apache_conf =~ s/httpd\.conf/httpd-preview.conf/; } my $force = @args && grep( /^--force$/, @args ) ? 1 : 0; if ( !-e $data_store_dir . '/success' || !-e $data_store_dir . '/main' ) { if ( !Cpanel::Config::Httpd::EA4::is_ea4() ) { print <<'EOM'; Sorry, configuration data has not been successfully stored. Please execute: /usr/local/cpanel/bin/apache_conf_distiller <type flag> Where <type flag> is one of the following: --reset Reset configuration data base upon current configuration. --update Read current configuration and merge results with saved configuration, giving precedence to newer data Execute the apache_conf_distiller without any flags to see its full usage. EOM exit 1; } else { print <<'EOM'; Sorry, configuration data has not been successfully stored. Please execute the following commands: /usr/local/cpanel/bin/apache_conf_distiller --store-data --defaults touch /var/cpanel/conf/apache/success Execute the apache_conf_distiller without any flags to see its full usage. EOM exit 1; } } if ( !Cpanel::Config::Httpd::EA3::is_ea3() && !Cpanel::Config::Httpd::EA4::is_ea4() ) { die 'This tool unavailable until Apache is installed by EasyApache'; } my $test_httpd_conf = Cpanel::Rand::get_tmp_file_by_name($apache_conf); die 'Failed to get a temporary working file!' if ( $test_httpd_conf eq '/dev/null' ); # Force doesn't do anything yet my ( $returnval, $message ) = Cpanel::AdvConfig::generate_config_file( { 'service' => 'apache', 'force' => $force, '_target_conf_file' => $test_httpd_conf } ); # issafe if ( !$returnval ) { print "Failed to build $apache_conf\n$message\n"; unlink $test_httpd_conf; exit 1; } ( $returnval, $message ) = Cpanel::AdvConfig::apache::check_syntax($test_httpd_conf) if Cpanel::Config::Httpd::EA3::is_ea3() or Cpanel::Config::Httpd::EA4::is_ea4(); # issafe if ( !$returnval ) { # issafe print <<"EOM"; Initial configuration generation failed with the following message: $message Rebuilding configuration without any local modifications. EOM ( $returnval, $message ) = Cpanel::AdvConfig::generate_config_file( { 'service' => 'apache', 'force' => $force, '_target_conf_file' => $test_httpd_conf, 'skip_local' => 1, } ); # issafe if ( !$returnval ) { print "Failed to build $apache_conf\n$message\n"; unlink $test_httpd_conf; exit 1; } ( $returnval, $message ) = Cpanel::AdvConfig::apache::check_syntax($test_httpd_conf); # issafe if ( !$returnval ) { print <<"EOM"; Failed to generate a syntactically correct Apache configuration. Bad configuration file located at ${test_httpd_conf} Error: $message EOM #unlink $test_httpd_conf; exit 1; } } rename $test_httpd_conf, $apache_conf; unlink $apache_conf . '.datastore'; # Just in case return; } unless (caller) { exit if -e '/var/cpanel/dnsonly'; run(@ARGV); print "Built $apache_conf OK\n"; exit; } 1;