perl <<'EOF'
use cPanel::PublicAPI;
#use XML::Simple;
use JSON;
binmode STDOUT, ":encoding(UTF-8)";

sub get_accesshash {
        my $accesshash;
        if ( ! -f '/root/.accesshash' ) {
                $ENV{REMOTE_USER} = 'root';
                system('/usr/local/cpanel/bin/realmkaccesshash');
        }
        if ( -f '/root/.accesshash' ) {
                open my $hash, "<", "/root/.accesshash";
                my @accesshash = <$hash>;
                close $hash;
                foreach(@accesshash){
                        $accesshash .= $_
                }
                return $accesshash;
        }
}

my $accesshash = get_accesshash();
my $cp = cPanel::PublicAPI->new( 'user' => 'root', 'accesshash' => $accesshash, 'ssl_verify_mode' => 0 );
my $user = 'user_placeholder';
my $database_user = 'db_placeholder';
my($user2, $dbuser) = split(/\_/, $database_user);
if ( !-f "/var/cpanel/users/$user" ) {
    die "[!] User does not exist.\n";
}
if ( $user ne $user2 ) {
    die "[!] Database user does not match owner.\n";
}
my $password;
@chars = (A..Z,0..9,a..z,"#","\@");
$num = scalar(@chars);
for ($i = 15; $i >= 1; $i--) {
        $password .= @chars[rand($num)];
}
my $addsqluser = $cp->cpanel_api1_request('whostmgr',
    {   
            'module' => 'Mysql',
            'func' => 'adduser',
            'user' => $user,
    },
        [ $dbuser, $password ], 'json'
);
#my $output = XML::Simple::XMLin($addsqluser);
$output =  decode_json($addsqluser);
my $error = $output->{'error'};
if ( $error ) {
    print "[!] $error\n";
}
else {
        print "[*] Created user $dbuser with password $password\n";
}
EOF
