65536
     ˆÂÌ„Ž	¯ÁÉ ?÷     #!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/xfertool                        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

package scripts::xfertool;

use cPstrict;

=encoding utf-8

=head1 USAGE

    xfertool ( --help | <COMMAND> <USERNAME> [ARGS..] )

=head1 DESCRIPTION

This script is part of an automated process that WHM uses for account
transfers.

We B<do> B<not> recommend calling this script manually.

Possible COMMAND values are:

=over

=item * C<allowlogins> and C<disallowlogins>

Control the userâ€™s ability to log in.

=item * C<blockdynamiccontent> and C<unblockdynamiccontent>

Control httpdâ€™s handling of files with certain well-known extensions
that correlate with dynamic web content. For example, after
C<blockdynamiccontent>, C<.php> files will no longer function normally.

=item * C<setupmaildest>

Sets the userâ€™s mail routing. Takes an additional argument that
can be C<primary>, C<secondary>, or C<remote>.

Example:

    xfertool setupmaildest howard primary

=item * C<swapip>

Replaces one IP address for another in the userâ€™s DNS zones. Takes
the source & target IP addresses as additional arguments.

Example:

    xfertool swapip howard  1.2.3.4  2.3.4.5

=item * C<changenameservers>

Sets the userâ€™s nameservers, given as additional arguments.

Example:

    xfertool changenameservers howard  ns1.myhost.com ns2.myhost.com

(As many nameservers can be given as needed.)

=back

=cut

#----------------------------------------------------------------------

use parent 'Cpanel::HelpfulScript';

use Cpanel::DnsUtils::Fetch                 ();
use Cpanel::Hostname                        ();
use Cpanel::Encoder::URI                    ();
use Cpanel::DnsUtils::Stream                ();
use Cpanel::DnsUtils::AskDnsAdmin           ();
use Cpanel::ZoneFile                        ();
use Cpanel::OS                              ();
use Cpanel::PwCache                         ();
use Cpanel::Config                          ();
use Cpanel::Config::CpUserGuard             ();
use Cpanel::ConfigFiles                     ();
use Cpanel::AccessIds::ReducedPrivileges    ();
use Cpanel::Config::WebVhosts               ();
use Cpanel::Config::userdata::Load          ();
use Cpanel::AcctUtils::Domain               ();
use Cpanel::AcctUtils::Owner                ();
use Cpanel::AcctUtils::DomainOwner::Tiny    ();
use Cpanel::MailTools::DBS                  ();
use Cpanel::Config::HasCpUserFile           ();
use Cpanel::Team::Config                    ();
use Cpanel::Team::Constants                 ();
use Whostmgr::Transfers::Session::Constants ();

use constant {
    _ENOENT => 2,

    _ACCEPT_UNNAMED => 1,
};

use constant _OPTIONS => ();

#----------------------------------------------------------------------

__PACKAGE__->new(@ARGV)->script() if !caller;

sub script ($self) {

    my @args = $self->getopt_unnamed();

    my $opt  = shift(@args) or die $self->help('Need a COMMAND.');
    my $user = shift(@args) or die $self->help('Need a USERNAME.');

    my @DOMAINS;
    if ( !Cpanel::PwCache::getpwnam($user) ) {

        # check if user looks like a valid domain
        if ( $user !~ /.\../ ) {
            print "Supplied user '$user' is not found.\n";
            exit 1;
        }

        @DOMAINS = ($user);

        # can return 'root' if no other owner found
        $user = Cpanel::AcctUtils::DomainOwner::Tiny::getdomainowner( $DOMAINS[0] );
        if ( $user eq 'root' ) {
            print "Domain '$DOMAINS[0]' cannot be transferred.\n";
            exit;
        }
    }
    elsif ( Cpanel::Config::HasCpUserFile::has_cpuser_file($user) ) {
        my $cpu_ref = Cpanel::Config::loadcpuserfile($user);
        @DOMAINS = ( $cpu_ref->{'DOMAIN'} );
        if ( ref $cpu_ref->{'DOMAINS'} ) {
            push @DOMAINS, @{ $cpu_ref->{'DOMAINS'}