3.1. PHP script, using Plesk RPC API
<?php
define("HOST", "pl1.demo.sw-soft.com");
define("PORT", 8443);
define("PATH", "enterprise/control/agent.php");
define("LOGIN", "admin");
define("PASSWD", "setup");
define("PROTO_VER", "1.3.1.0");
$proto = PROTO_VER;
$data =<<<EOF
<?xml version="1.0" encoding="UTF-8" standalone="no"
?>
<packet version="$proto">
<server>
<get>
<gen_info/>
</get>
</server>
</packet>
EOF;
function write_callback($ch, $data)
{
echo $data;
return strlen($data);
}
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 $data;
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
// 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();
?>
2.2. Perl script, using Plesk RPC API
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use Net::SSLeay qw(get_https make_form make_headers post_https);
$Net::SSLeay::ssl_version = 3;
use constant HOST => "pl1.demo.sw-soft.com";
use constant PORT => 8443;
use constant PATH => "/enterprise/control/agent.php";
use constant LOGIN => "admin";
use constant PASSWD => "setup";
use constant PROTO_VER => "1.3.1.0";
my $request = <<EOL;
<?xml version="1.0" encoding="UTF-8" standalone="no"
?>
<packet version="@{[PROTO_VER]}">
<server>
<get>
<gen_info/>
</get>
</server>
</packet>
EOL
my $headers = make_headers(
'HTTP_AUTH_LOGIN' => LOGIN,
'HTTP_AUTH_PASSWD' => PASSWD,
'HTTP_PRETTY_PRINT' => "TRUE",
'Content-Type' =>'text/xml' ,
);
print "----- REQUEST ---------------------\n";
print "REQUEST_HEADERS=" . Dumper($headers) . "\n";
print "REQUEST DATA\n" . $request . "\n";
print "----- RESULT ------------------------\n";
my ($reply_data, $reply_type, %reply_headers) =
post_https(HOST, PORT, PATH, $headers, $request);
print "REPLY_HEADERS=" . Dumper(\%reply_headers) . "\n";
print "REPLY_TYPE=" . $reply_type . "\n";
print "REPLY_DATA:\n" . $reply_data . "";