input:b0010v001Fp0001e0100-e0,12,kramls1,2,fw
     �Èa–Ü4ý()¨‰P@ŠË€fãl©‹FÿÇ      File not found.
     !ˆÁÅƒd-¹¾Ç T    !#!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/transfer_in_progress            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::transfer_in_progress;

=encoding utf-8

=head1 NAME

transfer_in_progress

=head1 SYNOPSIS

    transfer_in_progress ( --serialize_output | --help )

This script will check if there is an active transfer session.

 Options:
    --help                      brief help message
    --serialize_output          encode output as JSON

=cut

use strict;

use Getopt::Long ();

use Cpanel::Exception              ();
use Cpanel::JSON                   ();
use Cpanel::LoadModule             ();
use Whostmgr::Transfers::SessionDB ();

use Try::Tiny;

if ( !caller() ) {
    my $serialize_output;
    my $help;

    Getopt::Long::Configure('pass_through');
    Getopt::Long::GetOptionsFromArray(
        [@ARGV],
        serialize_output => \$serialize_output,
        help             => \$help,
    );

    if ($help) {
        print _help();
        exit 0;
    }

    my $script_obj = scripts::transfer_in_progress->new();

    try {
        my $transfer_exists = $script_obj->active_transfer_exists();
        $script_obj->_handle_output( $transfer_exists, $serialize_output );
    }
    catch {
        die Cpanel::Exception::get_string($_) . "\n";
    };

    exit 0;
}

sub new {
    my $self = bless {}, __PACKAGE__;

    return $self;
}

=head1 METHODS

=over 4

=item B<active_transfer_exists>

A function that indicates if there is an active transfer session (one that is RUNNING or PAUSING).

This function returns 1 if there is an active transfer session and 0 if there isn't.

This function may die if there is any issue connecting to the database or getting the data
from the database.

=back

=cut

sub active_transfer_exists {
    my ($self) = @_;

    my $session_db = Whostmgr::Transfers::SessionDB->new();

    my $sessions = $session_db->list_session_details( [ 'RUNNING', 'PAUSING' ] );
    return 0 if !$sessions || !keys %$sessions;

    return 1;
}

sub _handle_output {
    my ( $self, $transfer_exists, $serialize_output ) = @_;

    if ($serialize_output) {
        print Cpanel::JSON::Dump(
            {
                transfer_exists => $transfer_exists,
            }
        ) . "\n";
    }
    else {
        if ($transfer_exists) {
            print "An active transfer exists.\n";
        }
        else {
            print "An active transfer does not exist.\n";
        }
    }

    return 1;
}

sub _help {
    my $msg = shift;

    my $val;
    open my $wfh, '>', \$val or die "Failed to open to a scalar: $!";

    Cpanel::LoadModule::load_perl_module('Pod::Usage');
    Pod::Usage::pod2usage(
        -exitval   => 'NOEXIT',
        -message   => $msg,
        -verbose   => 1,
        -noperldoc => 1,
        -output    => $wfh,
        -input     => '/usr/local/cpanel/scripts/transfer_in_progress.pod',
    );

    return $val;

}

1;
  "   #ˆl–ß=¿J•4Å6 ¸î61hßÆƒ­;¿È Ó    ## Map all characters with high bit set to <none>
# Internal value	Output character
0x80    0x00
0x81    0x00
0x82    0x00
0x83    0x00
0x84    0x00
0x85    0x00
0x86    0x00
0x87    0x00
0x88    0x00
0x89    0x00
0x8A    0x00
0x8B    0x00
0x8C    0x00
0x8D    0x00
0x8E    0x00
0x8F    0x00
0x90    0x00
0x91    0x00
0x92    0x00
0x93    0x00
0x94    0x00
0x95    0x00
0x96    0x00
0x97    0x00
0x98    0x00
0x99    0x00
0x9A    0x00
0x9B    0x00
0x9C    0x00
0x9D    0x00
0x9E    0x00
0x9F    0x00
0xA0    0x00
0xA1    0x00
0xA2    0x00
0xA3    0x00
0xA4    0x00
0xA5    0x00
0xA6    0x00
0xA7    0x00
0xA8    0x00
0xA9    0x00
0xAA    0x00
0xAB    0x00
0xAC    0x00
0xAD    0x00
0xAE    0x00
0xAF    0x00
0xB0    0x00
0xB1    0x00
0xB2    0x00
0xB3  