Generate Domains through plesk: Update & Alias Domains


15 Jan 2006

Update: I tested the script in my previous post to generate domains on an alternative server and it worked flawlessly (Not quite sure why, and I need to test further). However, one of the features that are missing from Plesk is to create aliases of domains. Through the Plesk API, you can create a redirect on a domain (HTTP Redirect) or a Frameset for example…

<packet version="">

Although thats not quite what I desired, anyway heres a quick modifcation to the PleskDomainsCommand class. There are a few limitations, the first being that it needs to write to vhost.conf file in “/home/httpd/vhosts/” and that open_basedir allows access to that file.

  class PleskDomainsCommand extends PleskObjectCommand {

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

    function addAliasDomain($AliasedDomain, $ActualDomain) {
      $FileName= '/home/httpd/vhosts/'.$ActualDomain.'/conf/vhost.conf';
      $ServerAlias = 'ServerAlias '.$AliasedDomain."\r\n";

      if (is_writable($FileName)) {
        if (!$Handle = fopen($FileName, 'a'))        trigger_error("Cannot open file: ({$FileName})", E_USER_ERROR);
        if (fwrite($Handle, $ServerAlias) === FALSE) trigger_error("Cannot write to file: ({$FileName})", E_USER_ERROR);
      } else { trigger_error("The file ({$FileName}) is not writable", E_USER_ERROR); }

      $Data = "<packet version=\"{$this->Version}\"><server><get><services_state   /></get></server></packet>";
      //restart server id = web
      $Data = "<packet version=\"{$this->Version}\"><server><get><srv_man><id>web</id><operation>restart</operation></srv_man></get></server></packet>";

  $Domains = new PleskDomainsCommand($Data);
  $Domains->addAliasDomain('', '');

Comment Form

About this blog

I have been a developer for roughly 10 years and have worked with an extensive range of technologies. Whilst working for relatively small companies, I have worked with all aspects of the development life cycle, which has given me a broad and in-depth experience.