Edit File: helper.automation.php
<?php function _installatron_call($servertype, $serverip, $query, $user, $pass = null, $wait = true, $curlpath = null) { $sid = null; $servertype = rtrim($servertype,"0123456789");// sometimes it's "plesk8" or whatever // Find the correct Installatron HTTP server URL. We'll connect to this URL using CURL to instruct the Installatron Automation API. switch ($servertype) { case "cpanelExtended": case "cpanel": $url = "https://".$serverip.":2083/3rdparty/installatron/index.cgi"; break; case "directadminExtended": case "directadmin": $url = "http://".$serverip.":2222/CMD_PLUGINS/installatron/index.raw"; break; case "pleskExtended": case "plesk": $url = "https://".$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: $servertype" ); } $url .= "?api=json"; foreach ( $query as $key => $value ) { $url .= "&$key=".rawurlencode($value); } // Extra crap devised for Plesk. Why not use standard authentication protocols? if ( $servertype === "plesk" ) { $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://".$serverip.":8443/login_up.php3?login_name=".urlencode($user)."&passwd=".urlencode($pass)); $response = curl_exec($curl); curl_close($curl); if ( $response !== false && preg_match("/PHPSESSID\=([^\s;]+)/", $response, $m) ) { $sid = $m[1]; $curlpath = null; } } if ( $curlpath === null ) { $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 ( $servertype === "enkompass" && strlen($pass) > 400 ) { curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: WHM ".$user.":".preg_replace("'(\r|\n)'","",$pass))); } else { curl_setopt($curl, CURLOPT_HTTPHEADER, array("Authorization: Basic ".base64_encode($user.":".$pass)."\n\r")); } } 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 ) { return array( "result" => false, "message" => "curl_exec threw error `".curl_error($curl)."` for `$url`" ); } } else { # error_log( $curlpath." -k --basic -u ".escapeshellarg($user.":".$pass)." ".escapeshellarg($url) ); $response = shell_exec($curlpath." -k --basic -u ".escapeshellarg($user.":".$pass)." ".escapeshellarg($url).( $wait ? "" : " > /dev/null &" )); } # error_log("CURL Response: ".var_export($response,true), 3, "/home/portal2/public_html/log.txt"); if (( $p = strpos($response,'<div id="whm_content"><div id="whm_content_main">') )!== false ) { $response = substr($response, $p+49, strpos($response, "</div></div>", $p)-$p-49 ); } if ( strpos(ltrim($response),"{") !== 0 ) { return array( "result" => false, "message" => "Server response malformed. Likely account creation and/or authentication failed. Full response: ".$response ); } if (!$wait) { return array( "result" => true, "message" => "Task is processing in the background.", "data" => array() ); } // We got a response. Check it for errors. if ( strpos($response,"result") === false || strpos($response,".php on line ") !== false ) { return array( "result" => false, "message" => "malformed response for `$url`: ".$response ); } return json_decode($response, true); } ?>
Back to File Manager