perl <<'EOF'
use LWP::UserAgent;
use XML::Simple;
$domain = "domain_placeholder";
$userinfo = `egrep ^$domain:.+\$ /etc/userdomains | cut -d: -f2`;
chomp($userinfo);
$userinfo =~ s/^\s+//;
if ( $userinfo eq "" ) {
        print "[*] Couldn't find this user. Aborting.\n";
        exit;
}
@suspendedusers = </var/cpanel/suspended/*>;
foreach (@suspendedusers) {
        if ( $_ !~ /^.*\.lock$/ ) {
                (undef,undef,undef,undef,$suspuser) = split('/', $_);
                if ( $userinfo eq $suspuser ) {
                        print "[*] This user is suspended. Aborting.\n";
                        exit;
                }
        }
}
print "\n[*] NOTE: inode count is listed under \"files\"\n";
print "[*] NOTE: if there is a * next to the blocks count, the user is over quota.\n\n";
system("quota -u $userinfo -sv");
print "\n[*] Email usage summary:\n\n";

sub convertbytes {
     my $bytes = shift;
     if ($bytes < 1024)  {
        $bytes =~ s/\..*//;
        return $bytes . " bytes";
     }
     $bytes = $bytes / 1024;
     if ($bytes < 1024)
     {
        $bytes =~ s/\..*//;
        return $bytes . "K";
     }
     $bytes = $bytes / 1024;
     if ($bytes < 1024)
     {
        #$bytes =~ s/\..*//;
        return $bytes . "M";
     }
     $bytes = $bytes / 1024;
     if ($bytes < 1024)
     {
        #$bytes =~ s/\..*//;
        return $bytes . "G";
     }
     $bytes = $bytes / 1024;
     if ($bytes < 1024)
     {
        #$bytes =~ s/\..*//;
        return $bytes . "T";
     }
     $bytes =~ s/\..*//;
     return $bytes . "T";
}

if ( -e "/home/$userinfo/etc/$domain/quota") {
        open(DAT, "/home/$userinfo/etc/$domain/quota");
        @origfile = <DAT>;
        close(DAT);

        foreach my $thisline (@origfile) {
                chomp($thisline);
                if ($thisline !~ /^[a-z0-9]+/) { next };
                ($username, $rawusage) = split(':',$thisline);
		$rawusage = ($rawusage / 1024 / 1024);
                chomp($realusage = `du -mcs /home/$userinfo/mail/$domain/$username/ | head -1 | awk '{print \$1}'`);
                $percentage = $realusage / $rawusage;
                $percentage = $percentage * 100;
		$percentage =~ s/\..*//;
		$realusage = $realusage . "M";
		$rawusage = $rawusage . "M";
                if ($percentage >= 100) {
                        print "[ $percentage\% ] $username\@$domain is using $realusage of $rawusage.  ***OVER QUOTA***\n";
                } else {
                        print "[ $percentage\% ] $username\@$domain is using $realusage of $rawusage.\n";
                }
        }
        print "\n";
}

my $ip = '127.0.0.1';

if ( -f "/var/cpanel/resellers") {
	open(my $DAT, "<", "/var/cpanel/resellers");
		while(<$DAT>) {
			if ( /^$userinfo:/ ) {
				print "[*] Reseller stats:\n";
				my $url = "http://$ip:2086/xml-api/resellerstats?reseller=$userinfo";
				open(my $DAT, "<", "/root/.accesshash");
					my @hashdump = <$DAT>;
				close($DAT);
				my $hash = join("\n", @hashdump);
				$hash =~ s/\n//g;
				my $auth = "WHM root:" . $hash;
				my $ua = LWP::UserAgent->new;
				my $request = HTTP::Request->new(GET =>"$url");
				$request->header( Authorization => $auth );
				my $response = $ua->request($request);
				my $xml = XML::Simple->new;
				my $data = $xml->XMLin($response->content);
				$data = $data->{result};
				my $disk = $data->{diskused};
				my $bw = $data->{totalbwused};
				print "\tTotal Disk Usage : " . $disk . "MB\n";
				print "\tTotal Band Usage : " . $bw . "MB\n";
				print "\n";
				last;
			}
		}
	close($DAT);
}
EOF
