#!/usr/local/cpanel/3rdparty/bin/perl

package bin::chmodhttpdconf;

# cpanel - bin/chmodhttpdconf                          Copyright 2019 cPanel L.L.C.
#                                                           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::ConfigFiles::Apache ();

__PACKAGE__->script() unless caller();

sub script {

    # TODO: This modulino needs to have its core functionality moved to
    # a module and have its test coverage improved.  Once done the
    # install/* scripts should call the module directly instead of
    # loading this modulino.
    my $apacheconf = Cpanel::ConfigFiles::Apache->new();

    my $httpconf = $apacheconf->file_conf();
    my (@HTDIR) = split( m{/}, $httpconf );
    pop(@HTDIR);
    my $htdir = join( "/", @HTDIR );

    opendir( my $httpd_dh, $htdir );
    while ( my $conf = readdir($httpd_dh) ) {
        if ( index( $conf, 'httpd.conf' ) > -1 ) {
            chmod( 0600, $htdir . '/' . $conf );
        }
    }
    closedir($httpd_dh);
    return;
}
