1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
<?php
define("HOST", "ton.plesk.com");
define("PORT", 8443);
define("PATH", "enterprise/control/agent.php");
define("LOGIN", "ton_log");
define("PASSWD", "ton_pass");
define("PROTO_VER", "1.3.1.0");
$proto = PROTO_VER;
$bbn =<<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<packet version="$proto">
<mail>
<update>
<set>
<filter>
<domain_id>4</domain_id>
<mailname>
<name>nico</name>
<password>plop1234</password>
<password_type>plain</password_type>
</mailname>
</filter>
</set>
</update>
</mail>
</packet>
EOF;
function write_callback($ch, $bbn)
{
echo $bbn;
return strlen($bbn);
}
function sendCommand()
{
$url = "https://" . HOST . ":" . PORT . "/" . PATH;
$headers = array(
"HTTP_AUTH_LOGIN: " . LOGIN,
"HTTP_AUTH_PASSWD: " . PASSWD,
"HTTP_PRETTY_PRINT: TRUE",
"Content-Type: text/xml",
);
// Initalize the curl engine
$ch = curl_init();
// Set the curl options
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
// this line makes it work under https
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_HTTPHEADER, &$headers);
// Set the URL to be processed
curl_setopt($ch, CURLOPT_URL, $url);
// Set the callback functions
curl_setopt($ch, CURLOPT_WRITEFUNCTION, write_callback);
// Set the data to be send
global $bbn;
curl_setopt($ch, CURLOPT_POSTFIELDS, $bbn);
// Debug, however...
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$result = curl_exec($ch);
if ($result == CURL_OK) {
print_r(curl_getinfo($ch));
} else {
echo "\n\n-------------------------\n" .
"cURL error number:" .
curl_errno($ch);
echo "\n\ncURL error:" . curl_error($ch);
}
curl_close($ch);
return;
}
sendCommand();
?> |