When the Plesk API RPC packet is ready, it should be wrapped into the HTTP header and sent to the specified server. To perform these tasks, we suggest using any HTTP/FTP client library. This topic demonstrates how this can be done in PHP using the CURL engine - a free and open client-side URL transfer library supported in PHP 4.0.2 and higher.
To form the HTTP header, the CURL engine requires the following parameters:
define ('HOST', '10.58.97.81');
define ('PORT', 8443);
define ('PATH', 'enterprise/control/agent.php');
…
$url = 'https://' . HOST . ':' . PORT . '/' . PATH;
$headers = array(
'HTTP_AUTH_LOGIN: admin',
'HTTP_AUTH_PASSWD: setup',
'Content-Type: text/xml'
);
Then the CURL engine is initialized and set to use HTTPS, and all parameters required for the HTTP header are passed in to it:
// initialize the curl engine
$ch = curl_init();
// set the curl options:
// do not check the name of SSL certificate of the remote server
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
// do not check up the remote server certificate
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// pass in the header elements
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
// pass in the url of the target server
curl_setopt($ch, CURLOPT_URL, $url);
One more parameter required by the CURL engine is the Plesk API RPC packet. Assume that the packet is formed as follows:
$packet = <<<EOP
<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.4.0.0">
<client>
<add>
<gen_info>
<cname>LogicSoft Ltd.</cname>
<pname>Stephen Lowell</pname>
<login>stevelow</login>
<passwd>steve78</passwd>
<status>0</status>
<phone>416 907 9944</phone>
<fax>928 752 3905</fax>
<email>host@logicsoft.net</email>
<address>105 Brisbane Road, Unit 2</address>
<city>Toronto</city>
<state/>
<pcode/>
<country>CA</country>
</gen_info>
<limits>
<disk_space>100000</disk_space>
<max_dom>50</max_dom>
<max_subdom>250</max_subdom>
<max_webapps>30</max_webapps>
<max_traffic>50000</max_traffic>
<max_db>200</max_db>
<mysql_dbase_space>50000</mysql_dbase_space>
<max_shared_ssl_links>50</max_shared_ssl_links>
<expiration>1134616208</expiration>
</limits>
<permissions>
<create_domains>true</create_domains>
<manage_phosting>true</manage_phosting>
<manage_quota>false</manage_quota>
<manage_subdomains>true</manage_subdomains>
<change_limits>true</change_limits>
<manage_dns>true</manage_dns>
<manage_log>true</manage_log>
<manage_anonftp>true</manage_anonftp>
<manage_webapps>true</manage_webapps>
<manage_sh_access>true</manage_sh_access>
<manage_maillists>true</manage_maillists>
<make_dumps>true</make_dumps>
<remote_access_interface>true</remote_access_interface>
<cp_access>true</cp_access>
<manage_domain_aliases>true </manage_domain_aliases>
</permissions>
</add>
</client>
</packet>
EOP;
Now let us tell the CURL engine that we expect a request from the server, pass in the packet to deliver, and trigger the transfer:
// tell CURL to return the result rather than to load it to the browser
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// pass in the packet to deliver
curl_setopt($ch, CURLOPT_POSTFIELDS, $packet);
// perform the CURL request and return the result
$retval = curl_exec($ch);
// close the CURL session
curl_close($ch);
Once the request is performed, CURL obtains the resulting HTTP packet on the client side, removes the HTTP header, and the $retval variable gets the pure XML part of the 'response' packet.