This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/host/classes/host/plugin/plesk/10.php

247 lines
6.7 KiB
PHP
Raw Normal View History

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides PLESK client support
*
* @package OSB
* @subpackage Plugins/Plesk
* @category Plugins
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Host_Plugin_Plesk_10 extends Host_Plugin_Plesk {
protected $protocol = '1.6.3.0';
private $_loaded = FALSE;
// @todo Get these default "templates" values out of the DB
private $_template = array(
'client'=>array(
'gen_info'=>array(),
'stat'=>array(),
),
'domain'=>array(
'gen_info'=>array(),
'hosting'=>array(),
'limits'=>array(),
'stat'=>array(),
'prefs'=>array(),
'disk_usage'=>array(),
'performance'=>array(),
'subscriptions'=>array(),
'permissions'=>array(),
#'plan-items'=>array(), // protocol 1.6.3.1
),
'reseller'=>array(
'gen-info'=>array(),
'stat'=>array(),
),
);
/**
* Get a Client Configuration
*/
public function cmd_getclient(Model_Service $so) {
$this->init();
$items = array_keys($this->_template['client']);
$client = $this->packet->add_node('customer');
$get = $client->add_node('get');
$filter = $get->add_node('filter');
$filter->add_node('login',$so->plugin()->host_account);
$dataset = $get->add_node('dataset');
foreach ($items as $k)
$dataset->add_node($k);
$result = $this->server_command($this->xml);
if (! $this->loaded())
throw new Kohana_Exception('Unable to get PLESK Client data - Error :error',array(':error'=>(string)$result));
$this->_object['id'] = $result->id->value();
foreach ($items as $k)
foreach ($result->get($k) as $a=>$b)
$this->_object[$k] = $this->collapse($b);
return $this;
}
/**
* Get a Domain Configuration
*/
public function cmd_getdomain(Model_Service $so) {
$this->init();
$items = array_keys($this->_template['domain']);
$domain = $this->packet->add_node('webspace');
$get = $domain->add_node('get');
$filter = $get->add_node('filter');
$filter->add_node('name',strtolower($so->plugin()->name()));
$dataset = $get->add_node('dataset');
foreach ($items as $k)
$dataset->add_node($k);
$result = $this->server_command($this->xml);
if (! $this->loaded())
throw new Kohana_Exception('Unable to get PLESK Domain data - Error :error',array(':error'=>(string)$result));
$this->_object['id'] = $result->id->value();
foreach ($items as $k)
foreach ($result->get($k) as $a=>$b)
$this->_object[$k] = $this->collapse($b);
return $this;
}
/**
* Get Reseller
*/
public function cmd_getreseller(Model_Service $so) {
$this->init();
$items = array_keys($this->_template['reseller']);
$hsao = ORM::factory('host_server_affiliate',array('affiliate_id'=>$so->affiliate_id,'host_server_id'=>$so->plugin()->host_server_id))->find();
if (! $hsao->loaded())
return NULL;
$domain = $this->packet->add_node('reseller');
$get = $domain->add_node('get');
$filter = $get->add_node('filter');
$filter->add_node('login',strtolower($hsao->host_username));
$dataset = $get->add_node('dataset');
foreach ($items as $k)
$dataset->add_node($k);
$result = $this->server_command($this->xml);
if (! $this->loaded())
throw new Kohana_Exception('Unable to get PLESK Reseller data - Error :error',array(':error'=>(string)$result));
$this->_object['id'] = $result->id->value();
foreach ($items as $k)
foreach ($result->get($k) as $a=>$b)
$this->_object[$k] = $this->collapse($b);
return $this;
}
/**
* Get Domain Traffic
*/
public function cmd_gettraffic(Model_Service $so) {
throw new Kohana_Exception('Not Implemented');
}
/**
* Provision a hosting service
* @todo To implement
*/
public function provision(Model_Service $so) {
/*
$ro = $this->cmd_getreseller($so);
// Make sure our reseller exists
if ($ro AND ! $ro->id)
throw new Kohana_Exception('Add Reseller - Not Implemented');
$result = $this->add_client($so);
if (! $result->loaded())
throw new Kohana_Exception('Failed to Add Client?');
*/
// Provision Domain
$result = $this->add_domain($so);
if (! $this->loaded())
throw new Kohana_Exception('Failed to Add Domain?');
print_r(array('r'=>(string)$result,'t'=>$this));
// Create Client Account
throw new Kohana_Exception('Not Implemented');
/*
// Next need to get the ID from the account call to set the IP
$result = $this->hs->setip(35); // @todo change this number
print_r((string)$result);
// Set Limits
$result = $this->hs->setlimits($so);
print_r((string)$result);
// Next need to get the ID for the domain to disable mail
$result = $this->hs->disablemail(43);
print_r((string)$result);
*/
}
public function add_client(Model_Service $so) {
$ro = $this->cmd_getreseller($so);
$this->init();
$client = $this->packet->add_node('customer');
$add = $client->add_node('add');
$gen_info = $add->add_node('gen_info');
$gen_info->add_node('cname',$so->account->company);
$gen_info->add_node('pname',sprintf('%s %s',$so->account->first_name,$so->account->last_name));
$gen_info->add_node('login',$so->plugin()->host_account);
$gen_info->add_node('passwd',$so->plugin()->host_password);
$gen_info->add_node('status',0);
$gen_info->add_node('email',$so->account->email);
if ($ro->id)
$gen_info->add_node('owner-id',$ro->id);
$result = $this->server_command($this->xml);
if (! $this->loaded())
throw new Kohana_Exception('Unable to add PLESK Client - Error :error',array(':error'=>(string)$result));
return $result;
}
public function add_domain(Model_Service $so) {
$plan = 'Default Domain';
$co = $this->cmd_getclient($so);
$ip = '223.27.16.147'; //@todo Get from other means.
if (! $co->loaded())
throw new Kohana_Exception('Unable to load Plesk Customer?');
$this->init();
$domain = $this->packet->add_node('webspace');
$add = $domain->add_node('add');
$gen_setup = $add->add_node('gen_setup');
$gen_setup->add_node('name',strtolower($so->name()));
$gen_setup->add_node('owner-id',$co->id);
$gen_setup->add_node('htype','vrt_hst');
$gen_setup->add_node('ip_address',$ip);
$gen_setup->add_node('status','0');
$hosting = $add->add_node('hosting');
$vrt_host = $hosting->add_node('vrt_hst');
$property = $vrt_host->add_node('property');
$property->add_node('name','ftp_login');
$property->add_node('value',$so->plugin()->ftp_username);
$property = $vrt_host->add_node('property');
$property->add_node('name','ftp_password');
$property->add_node('value',$so->plugin()->ftp_password);
$vrt_host->add_node('ip_address',$ip);
$add->add_node('plan-name',$plan);
$result = $this->server_command($this->xml);
if (! $this->loaded())
throw new Kohana_Exception('Unable to add PLESK Domain - Error :error',array(':error'=>(string)$result));
return $result;
}
}
?>