unsupported
  )   �Zƒ›Ù«{‹„„-i[D<†ªo_’I|¥‰ÓMjqØ‚¦ð¬÷ÃÂ  $    ‹      sËÌIUÈË/QHË/ÍKÑã +�©!        �À¿¾ÃÂ  $    ‹      sËÌIUÈË/QHË/ÍKÑã +�©!     :   	ˆl–äY>”Šn-je@ã@¸&ÔÅ£Å„Ž¼a–Ãa¾”J_)â�zãN\må1hßÄ ?÷     	#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/fixrndc                         Copyright 2022 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

######[ This script will rebuild the rndc.key and rndc.conf files unless ]######
######[ an existing, working config is found                             ]######

use strict;
use Cpanel::Config::LoadCpConf   ();
use Cpanel::StringFunc::Count    ();
use Cpanel::CommentKiller        ();
use Cpanel::SafetyBits           ();
use Cpanel::PwCache              ();
use Cpanel::SafeRun::Errors      ();
use Cpanel::SafeRun::Simple      ();
use Cpanel::FileUtils::TouchFile ();
use Cpanel::FindBin              ();

use Getopt::Long ();

umask 0022;

######[ declare globals ]##########################################################################

# default location of named.conf
my $def_namedconf = '/etc/named.conf';

my $needrndckey = 0;

my $options = {};

Getopt::Long::Configure("bundling");
Getopt::Long::GetOptions(
    'force|f'   => \$options->{force},
    'verbose|v' => \$options->{verbose},

    # If -s is passed as an arg, it's saying that fixrndc was started by rebuilddnsconfig and should not reinvoke its parent.
    'rebuilddnsconfig|s' => \$options->{rebuilddnsconfig},
    'html|h'             => \$options->{html},
);

# Verbose variable, if set to "1" actions are reported to STDOUT.
my $cpverbose                    = $options->{verbose}          || 0;
my $called_from_rebuilddnsconfig = $options->{rebuilddnsconfig} || 0;

if ( !-e $def_namedconf || -z _ ) {
    if ( !$called_from_rebuilddnsconfig ) {
        print "The named configuration file is missing, running /usr/local/cpanel/scripts/rebuilddnsconfig to repair it.\n" if $cpverbose;
        my $opts = $cpverbose ? '-fv' : '-f';
        exec( '/usr/local/cpanel/scripts/rebuilddnsconfig', $opts );
        exit 0;    #unreached
    }
    else {
        print "WARNING: $def_namedconf appears to be invalid but the problem could not be corrected automatically!\n";
        exit 1;
    }
}

my $local_nameserver_type = Cpanel::Config::LoadCpConf::loadcpconf_not_copy()->{'local_nameserver_type'};
if ( $local_nameserver_type ne 'bind' ) {
    print "$local_nameserver_type is configured as the local nameserver.  RNDC key is not in use.\n" if $cpverbose;
    exit;
}

require Cpanel::Services::Enabled;
unless ( Cpanel::Services::Enabled::is_enabled('dns') ) {
    print "Named is currently disabled.\n" if $cpverbose;
    exit;
}

require Cpanel::DNSLib;
my $dnslib = Cpanel::DNSLib->new( 'force' => ( $options->{'force'} ? 1 : 0 ) );

######[ try to ensure named is actually running, fixrndc will always fail if not.                           ]######
######[ try starting named, but always allow it to continue and try to force new keys even if we can't test ]######
######[ this all does basically the same thing, but gives a little more information about problem so techs  ]######
######[ can know where to start ]##################################################################################

my @html_args = $options->{html} ? ('--html') : ();

my $check_output = Cpanel::SafeRun::Errors::saferunallerrors( '/usr/local/cpanel/scripts/restartsrv_named', '--check', @html_args );
my $status_code  = $?;

# Try to restart
if ( $status_code != 0 ) {
    print "Named looks down but should be up.  Attempting restart...\n" if $cpverbose;
    $check_output = Cpanel::SafeRun::Errors::saferunallerrors( '/usr/local/cpanel/scripts/restartsrv_named', @html_args );
    print $check_output if $cpverbose;
    for ( 1 .. 10 ) {
        $check_output = Cpanel::SafeRun::Errors::saferunallerrors( '/usr/local/cpa