Hey - So this script works great. Sometimes. About 50% of the time it does not make the database. All the accounts it was tested on are members of the same package
I am at a loss for what the problem is. I would guess it is something to do with cpanel/whm and whmcs being stupid but, I just want to run this by people who know more about this sort of than than myself.
Also: Maybe the code can help someone trying to figure out what to do with the xmlapi.php class (Call me slow but I had no idea what to do with it at first)
NOTE: This is a partial class but, all the stuff relating to the database creation is shown. The rest is just custom stuff relating to my application
PHP Code:
require("xmlapi.php");
$installer = new installer();
if ($installer->pageCheck() != "1") {
die("URL not authorized.");
}
$installer->makeDatabase(); // Creates the database. -> Disabled for testing so the db info remains constant.
$installer->writeDatabase(); // Makes the database.
$installer->makeconfig(); // Writes the config file.
class installer {
var $ip = "127.0.0.1";
var $root_pass = "*****";
var $database = "cs2";
var $username;
var $password;
var $sqluser;
var $sqldir = "sql/";
var $domain;
function __construct() {
/*
* Constructor!
*/
$this->makeUser(); // Create the user!
$this->makePassword(); // Create the password!
}
public function pageCheck() {
/*
* pageCheck checks if it is a valid account to run the install on.
*/
$xmlapi = new xmlapi($this->ip);
$xmlapi->password_auth("root",$this->root_pass);
$xmlapi->return_xml(1);
$xmlapi->set_debug(1);
$domain = $_SERVER['HTTP_HOST'];
$pieces = explode(".", $domain);
if ($pieces[0] == "www") {
unset($pieces[0]);
$domain = implode("", $pieces);
} else {
$domain = implode("", $pieces);
}
$username = substr($domain, 0, 7);
$this->username = $username; // this field is now the first 7 characters of the URL it is the username.
$status = "0"; // Default of status
// get list of accounts
$accounts = $xmlapi->listaccts();
// create SimpleXML object to loop through later
$xml2 = new SimpleXMLElement($accounts);
foreach ($xml2->acct as $account) {
$myuser = $account->user;
// echo $myuser."<br />";
if ($myuser == $this->username) { // This is to see if the username matchs a real account
$status = "1"; // valid account.
}
}
return "1";
}
public function makeDatabase() {
/*
* this is the database making stuff
*/
$xmlapi = new xmlapi($this->ip);
$xmlapi->password_auth("root",$this->root_pass);
$xmlapi->return_xml(1);
$xmlapi->set_debug(1);
$xmlapi->api1_query("$this->username", "Mysql", "adddb", array($this->database) );
$xmlapi->api1_query("$this->username", "Mysql", "adduser", array( $this->sqluser, $this->password ) );
$xmlapi->api1_query("$this->username", "Mysql", "adduserdb", array($this->database, $this->sqluser, 'ALL' ));
}
}


LinkBack URL
About LinkBacks
Reply With Quote