Today I was trying to generate domains through Plesk with the RPC API, the following actually creates the domain, despite throwing the following error. Looking at the domain in plesks admin it states “Hosting (Domain has no hosting configured)”. Once configuring the domain through the “Physical hosting setup page for domain testdomaingeneration3.waidev6.com” interface page successfully added the domain. Although I still need to find out why “<htype>vrt_hst</htype>” and the rest of the “vrt_hst” information is not being set correctly. There also seems to be very little information that I could find on actually using the API besides the schema info generated by Xml Spy, which is quite strange.

Include /home/httpd/vhosts/testdomaingeneration3.waidev6.com/conf/httpd.include

<virtualhost 192.168.1.22:80>
        ServerName testdomaingeneration3.waidev6.com:80
        ServerAlias www.testdomaingeneration3.waidev6.com
        UseCanonicalName Off
...
</virtualhost>

Error response on domain creation.

<?xml version="1.0" encoding="UTF-8"?>
<packet version="1.3.1.0">
  <domain>
    <add>
      <result>
        <status>error</status>
        <errcode>2307</errcode>
        <errtext>Domain adding was failed. Error: Can`t resolve ID for IP ()</errtext>
      </result>
    </add>
  </domain>
</packet>

Anyway, its still very much incomplete as I was running out of time to complete it.

<?php
  define('DEBUG',1);

  class PleskSocketRequest {

    var $Configuration = array(
      'HOST'=>null,
      'PORT'=>null,
      'PATH'=>null,
      'USER'=>null,
      'PASS'=>null
    );

    var $Version   = null;
    var $URIScheme = null;
    var $CR        = null; //Curl Resource

    function buildHeaders() {
      $Headers = array(
        'HTTP_AUTH_LOGIN: '  . $this->get('USER'),
        'HTTP_AUTH_PASSWD: ' . $this->get('PASS'),
        'HTTP_PRETTY_PRINT: TRUE',
        'Content-Type: text/xml',
      );
      return $Headers;
    }

    function setOpt() {
      curl_setopt($this->CR, CURLOPT_SSL_VERIFYHOST, 0);
      curl_setopt($this->CR, CURLOPT_SSL_VERIFYPEER, FALSE);
      curl_setopt($this->CR, CURLOPT_HTTPHEADER, $this->buildHeaders() );
      curl_setopt($this->CR, CURLOPT_URL, $this->URIScheme);
      curl_setopt($this->CR, CURLOPT_VERBOSE, 1);

      curl_setopt($this->CR, CURLOPT_WRITEFUNCTION, array(&$this,CallBack));
      curl_setopt($this->CR, CURLOPT_POSTFIELDS, $this->Data);
    }

    function CallBack($CR, $Data) {
      echo '<pre>'.htmlentities($Data).'</pre>';
      return strlen($Data);
    }

    function connect() {
      $this->URIScheme =  $this->get('SCHEME') . '://' . $this->get('HOST').':'. $this->get('PORT'). $this->get('PATH');
      $this->CR = curl_init();

      $this->setOpt();

      curl_setopt($this->CR, CURLOPT_POSTFIELDS, $this->Data);

      $result = curl_exec($this->CR);

      if ($result == CURL_OK) {
        if (DEBUG) { print '<pre>';print_r(curl_getinfo($this->CR));print '</pre>'; }
      } else {
        if (DEBUG) { print '<pre>';print_r(curl_getinfo($this->CR));echo "nn-------------------------n" ."cURL error number:" .curl_errno($this->CR);echo "nncURL error:" . curl_error($this->CR);print '</pre>'; }
      }
      curl_close($this->CR);
      return;
    }

    function get($Key) {
      return $this->Configuration[$Key];
    }
  }
  class PleskObjectCommand  extends PleskSocketRequest {

    var $Data=null;

    function PleskObjectCommand($Data=null) { $this->Data=$Data; }
    function Command()                      { die('Not Implemented');  }

    function setOptions($Option) {
      $Options = (is_array($Option))? $Option : parse_url($Option);
      foreach($Options AS $Key=>$Value) $this->Configuration[strtoupper($Key)]=$Value;
      //print_r($this->Configuration);
    }
  }

  class PleskDomainsCommand extends PleskObjectCommand {

    function PleskDomainsCommand($Data=null) { parent::PleskObjectCommand($Data);  }

    function Command() {
      $this->connect();
      die('exec');
    }

  }
  class PleskClientCommand   extends PleskObjectCommand {}
  class PleskDNSCommands     extends PleskObjectCommand {}
  class PleskIPCommands      extends PleskObjectCommand {}
  class PleskeventsCommands  extends PleskObjectCommand {}

$Data =<<<EOF
<packet version="1.3.1.0">
  <domain>
    <add>
      <gen_setup>
        <name>testdomaingeneration5.example.com</name>
        <client_id>1</client_id>
        <status>0</status>
        <ip_address>192.168.1.22</ip_address>
        <vrt_hst>
          <ftp_login>catalina0</ftp_login>
          <ftp_password>057177a</ftp_password>
          <ftp_quota>0</ftp_quota>
          <fp>false</fp>
          <fp_ssl>false</fp_ssl>
          <fp_auth>false</fp_auth>
          <fp_admin_login>miaumiaul</fp_admin_login>
          <fp_admin_password>lalalalallaa</fp_admin_password>
          <ssl>false</ssl>
          <shell>/bin/false</shell>
          <php>true</php>
          <ssi>false</ssi>
          <cgi>false</cgi>
          <mod_perl>false</mod_perl>
          <mod_python>false</mod_python>
          <asp>false</asp>
          <asp_dot_net>false</asp_dot_net>
          <coldfusion>false</coldfusion>
          <webstat>awstats</webstat>
          <errdocs>false</errdocs>
          <at_domains>true</at_domains>
        </vrt_hst>
        <htype>vrt_hst</htype>
      </gen_setup>
      <hosting>
        <vrt_hst>
          <ftp_login>catalina0</ftp_login>
          <ftp_password>057177a</ftp_password>
          <ftp_quota>0</ftp_quota>
          <fp>false</fp>
          <fp_ssl>false</fp_ssl>
          <fp_auth>false</fp_auth>
          <fp_admin_login>miaumiaul</fp_admin_login>
          <fp_admin_password>lalalalallaa</fp_admin_password>
          <ssl>false</ssl>
          <shell>/bin/false</shell>
          <php>true</php>
          <ssi>false</ssi>
          <cgi>false</cgi>
          <mod_perl>false</mod_perl>
          <mod_python>false</mod_python>
          <asp>false</asp>
          <asp_dot_net>false</asp_dot_net>
          <coldfusion>false</coldfusion>
          <webstat>awstats</webstat>
          <errdocs>false</errdocs>
          <at_domains>true</at_domains>
        </vrt_hst>
        <htype>vrt_hst</htype>
      </hosting>
      <prefs>
        <www>true</www>
      </prefs>
    </add>
  </domain>
</packet>
EOF;

  $Domains = new PleskDomainsCommand($Data);
  $Domains->setOptions('https://root:***@localhost:8443/enterprise/control/agent.php');
  $Domains->Command();

?>