<?php


// cPanel username (you use to login to cPanel)
$cpanel_user = "user";

// cPanel password (you use to login to cPanel)
$cpanel_password = "password";

// cPanel domain (example: mysite.com)
$cpanel_host = "host";

// cPanel theme/skin, usually "x"

// to know it for sure
$cpanel_skin = "x";

// Script will add user to database if these values are not empty
// User wil have ALL permissions
$db_username = &#39;&#39;;
$db_userpass = &#39;&#39;;

// Update this only if you are experienced user or if script does not work
// Path to cURL on your server. Usually /usr/bin/curl
$curl_path = "";

//////////////////////////////////////
/* Code below should not be changed */
//////////////////////////////////////

function execCommand($command) {
global $curl_path;

if (!empty($curl_path)) {
return exec("$curl_path &#39;$command&#39;");
}
else {
return file_get_contents($command);
}
}

if(isset($_GET[&#39;db&#39;]) && !empty($_GET[&#39;db&#39;])) {
// escape db name
$db_name = escapeshellarg($_GET[&#39;db&#39;]);

// will return empty string on success, error message on error
$result = execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/sql/adddb.html?db=$db_name");

if(isset($_GET[&#39;user&#39;]) && !empty($_GET[&#39;user&#39;])) {
$db_username = $_GET[&#39;user&#39;];
$db_userpass = $_GET[&#39;pass&#39;];
}

if (!empty($db_username)) {
// create user
$result .= execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/sql/adduser.html?user={$db_username}&pass={$db_userpas s}");
// assign user to database
$result .= execCommand("http://$cpanel_user:$cpanel_password@$cpanel_host:2082/frontend/$cpanel_skin/sql/addusertodb.html?user={$cpanel_user}_{$db_username }&db={$cpanel_user}_{$db_name}&ALL=ALL");
}

// output result
echo $result;
}
else {
echo "Usage: cpanel_create_db.php?db=databasename&user=username &pass=password";
}

?>