perl<<'EOF'
use strict;
use XML::Simple;
if (eval {require cPanel::PublicAPI;}) {
        require cPanel::PublicAPI;
} else {
        print "[!] Failed to load the necessary modules for this script to function properly. Are you running this on a shared server?'\n";
        exit();
}
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;

my $user = 'user_placeholder';
my $ticketid = 'ticket_placeholder';
my $unique = $ticketid . '_' . time();
chomp(my $server = `hostname`);

if ( ! -s "/root/.accesshash" ) {
        $ENV{'REMOTE_USER'} = 'root';
        system('/usr/local/cpanel/bin/realmkaccesshash');
}
my $apic = cPanel::PublicAPI->new();
my $response = $apic->cpanel_api2_request('whostmgr', { 'module' => 'StatsBar', 'func' => 'stat', 'user' => $user, }, { 'display' => 'diskusage'}, 'xml');
my $output = XMLin($response);
if ( $output->{'data'}->{'result'} ) {
    print "[!] Failed to fetch information for $user out of cPanel. Please escalate\n";
    exit();
}
my $units = $output->{'data'}->{'units'};
my ($size) = split(/\./, $output->{'data'}->{'count'});
$size =~ s/\,//g;

if ( $units eq 'GB' ) {
    $size = ( $size * 1024 );
}
if ( $size > 10240 ) {
    print "[!] Account is over 10GB. Please escalate this to have the backup created manually.\n";
    exit();
}

if ( ! -f '/root/bin/suspbackup' ) {
    print "[!] /root/bin/suspbackup is not found on this server. Please escalate this to have the backup created manually.\n";
    exit();
}

print "[*] Account is under size limit, generating backup...\n";

system("/root/bin/suspbackup $user -t $ticketid");
EOF
