"install", "background" => "yes",//execute as a background process "application" => "phpbb", "url" => "http://".$vars["params"]["domain"]."/forum", ); } //@todo Add more packages else if ()s here! //else if ( intval($vars["params"]["packageid"]) === 3 ) //{ //} // The default case. For any other PackageId we want to automatically install a copy of WordPress to the root http directory. else { // Build Installatron API query to do the install: $query = array( "cmd" => "install", "background" => "yes", "application" => "wordpress", "url" => "http://".$vars["params"]["domain"], ); } $response = _installatron_call_whmcs($vars, $query); if ( $response["result"] === false ) { error_log("Installatron API Error: ".var_export($response,true)."\nRequest: ".var_export($vars["params"],true), 3, "/tmp/whmcs_installatron_error_log"); return; } // Success! //echo $response["message"]; } function _installatron_call_whmcs($vars, $query, $useBinary = false) { #$qid = mysql_query("SELECT h.username, h.password, s.type AS servertype, s.ipaddress AS serverip, s.username AS serverusername, s.password AS serverpassword, s.accesshash AS serveraccesshash FROM tblhosting h, tblservers s WHERE s.id=h.server AND h.id='".intval($vars["params"]["serviceid"])."' LIMIT 1"); #$qid = mysql_query("SELECT h.username, h.password, s.type AS servertype, s.ipaddress AS serverip, s.username AS serverusername, s.password AS serverpassword, s.accesshash AS serveraccesshash FROM tblhosting h, tblservers s WHERE s.id=h.server AND h.userid='".intval($vars["params"]["clientsdetails"]["userid"])."' AND s.username!='' LIMIT 1"); #$qid = mysql_query(" ='".intval($vars["params"]["serverid"])."' LIMIT 1"); // if $query["user"] was set, use that value to look up the server id rather than the actual server id by WHMCS (which may be incorrect). if (isset($query["user"])) { $qid = mysql_query("SELECT h.username, h.password, s.type AS servertype, s.ipaddress AS serverip, s.username AS serverusername, s.password AS serverpassword, s.accesshash AS serveraccesshash FROM tblservers s, tblhosting h WHERE s.id=h.server AND h.username='".addslashes($query["user"])."' LIMIT 1"); } else { // look up server info from request $qid = mysql_query("SELECT s.type AS servertype, s.ipaddress AS serverip, s.username AS serverusername, s.password AS serverpassword, s.accesshash AS serveraccesshash FROM tblservers s WHERE s.id='".intval($vars["params"]["serverid"])."' LIMIT 1"); } $server_data = mysql_fetch_assoc($qid); $server_data["serverpassword"] = decrypt($server_data["serverpassword"]); $server_data["servertype"] = rtrim($server_data["servertype"],"0123456789");// sometimes it's "plesk8" or whatever if (isset($query["user"])) { $user_data = array( "username" => $server_data["username"], "password" => $server_data["password"] ); } else { $qid = mysql_query("SELECT h.username, h.password FROM tblhosting h WHERE h.id='".intval($vars["params"]["serviceid"])."' LIMIT 1"); $user_data = mysql_fetch_assoc($qid); if (empty($user_data["username"])) { $qid = mysql_query("SELECT h.username, h.password FROM tblhosting h WHERE h.userid='".intval($vars["params"]["clientsdetails"]["userid"])."' AND h.server='".intval($vars["params"]["serverid"])."' AND s.username!='' LIMIT 1"); $user_data = mysql_fetch_assoc($qid); } } $user_data["password"] = decrypt($user_data["password"]); // Find the correct Installatron HTTP server URL. We'll connect to this URL using CURL to instruct the Installatron Automation API. switch ($server_data["servertype"]) { case "cpanelExtended": case "cpanel": $url = "https://".$server_data["serverip"].":2087/installatron/index.cgi"; break; case "directadminExtended": case "directadmin": $url = "http://".$server_data["serverip"].":".( isset($vars["serverport"]) ? $vars["serverport"] : "2222" )."/CMD_PLUGINS/installatron/index.raw"; break; case "pleskExtended": case "plesk": $url = "https://".$server_data["serverip"].":8443/modules/installatron/index.php"; break; default: // An unsupported server. The API has no limitations, so feel free to add support for more control panels. We'll add more panels as testing permits. return array( "result" => false, "message" => "Unknown module type: ".$server_data["servertype"] ); } $url .= "?api=json"; // Plesk $sid = null; if ( $server_data["servertype"] === "plesk" ) { // Plesk also requires the domain be set $query["user"] = $vars["params"]["domain"]; $tryCount = 0; while (true) { $curl = curl_init(); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_HEADER, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_URL, "https://".$server_data["serverip"].":8443/login_up.php3?login_name=".urlencode($server_data["serverusername"])."&passwd=".urlencode($server_data["serverpassword"])); $response = curl_exec($curl); curl_close($curl); if ( $response !== false && preg_match("/PHPSESSID\=([^\s;]+)/", $response, $m) ) { $sid = $m[1]; } else if ( $tryCount <= 2 ) { sleep(1); ++$tryCount; continue; } break; } } else if (!isset($query["user"])) { $query["user"] = $user_data["username"]; } // requirec by DA: if ( $server_data["servertype"] === "directadmin" ) { $query["cp-username"] = $server_data["serverusername"]; $query["cp-password"] = $server_data["serverpassword"]; } // so it retrys a couple of times if it's taking a long time to create the account $query["retry"] = "yes"; foreach ( $query as $key => $value ) { $url .= "&$key=".rawurlencode($value); } if ( $useBinary === false ) { $tryCount = 0; while (true) { $curl = curl_init(); curl_setopt($curl, CURLOPT_TIMEOUT, 9999); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); if ( $sid === null ) { if (empty($server_data["serverpassword"])) { curl_setopt($curl, CURLOPT_HTTPHEADER, array( "Authorization: WHM ".$server_data["serverusername"].":".preg_replace("'(\r|\n)'","",$server_data["serveraccesshash"]) )); } else { curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Basic ".base64_encode($server_data["serverusername"].":".$server_data["serverpassword"]) )); } } else { curl_setopt($curl, CURLOPT_COOKIE, "PHPSESSID=$sid; psaContext=dashboard; BarExpanded=True"); } curl_setopt($curl, CURLOPT_URL, $url); $response = curl_exec($curl); if ( $response === false ) { if ( $tryCount > 2 ) { return array( "result" => false, "message" => "curl_exec threw error `".curl_error($curl)."` for `$url` (after 3 tries)" ); } sleep(1); ++$tryCount; continue; } break; } } else { if ( $useBinary === true ) { $useBinary = "curl"; } $response = shell_exec($useBinary." -k --basic -u ".escapeshellarg($server_data["serverusername"].":".$server_data["serverpassword"])." ".escapeshellarg($url)." 2>&1"); } if (( $p = strpos($response,'