2012-06-26 14:28:18 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides PLESK client support
|
|
|
|
*
|
2013-03-19 22:35:19 +00:00
|
|
|
* @package Host
|
2012-06-26 14:28:18 +00:00
|
|
|
* @category Plugins
|
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
2012-06-26 14:28:18 +00:00
|
|
|
*/
|
|
|
|
class Host_Plugin_Plesk_10 extends Host_Plugin_Plesk {
|
|
|
|
protected $protocol = '1.6.3.0';
|
|
|
|
|
|
|
|
// @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');
|
2012-07-12 11:18:22 +00:00
|
|
|
$filter->add_node('login',$so->plugin()->host_username);
|
2012-06-26 14:28:18 +00:00
|
|
|
$dataset = $get->add_node('dataset');
|
|
|
|
foreach ($items as $k)
|
|
|
|
$dataset->add_node($k);
|
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
return $this->server_command($this->xml);
|
2012-06-26 14:28:18 +00:00
|
|
|
}
|
|
|
|
|
2012-07-03 13:05:08 +00:00
|
|
|
/**
|
|
|
|
* Get a DNS Configuration
|
|
|
|
*/
|
2012-07-12 05:10:53 +00:00
|
|
|
public function cmd_getdns(Model_Service $so) {
|
|
|
|
$do = clone $this->cmd_getdomain($so);
|
2012-07-03 13:05:08 +00:00
|
|
|
|
|
|
|
$this->init();
|
|
|
|
$domain = $this->packet->add_node('dns');
|
|
|
|
$get = $domain->add_node('get_rec');
|
|
|
|
$filter = $get->add_node('filter');
|
2012-07-12 05:10:53 +00:00
|
|
|
$filter->add_node('site-id',$do->id->value());
|
2012-07-03 13:05:08 +00:00
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
return $this->server_command($this->xml);
|
2012-07-03 13:05:08 +00:00
|
|
|
}
|
|
|
|
|
2012-07-23 12:21:13 +00:00
|
|
|
/**
|
|
|
|
* Get Mail Configuration
|
|
|
|
*/
|
|
|
|
public function cmd_getmail(Model_Service $so) {
|
|
|
|
$do = clone $this->cmd_getdomain($so);
|
|
|
|
|
|
|
|
$this->init();
|
|
|
|
$domain = $this->packet->add_node('mail');
|
|
|
|
$get = $domain->add_node('get_prefs');
|
|
|
|
$filter = $get->add_node('filter');
|
|
|
|
$filter->add_node('site-id',$do->id->value());
|
|
|
|
|
|
|
|
return $this->server_command($this->xml);
|
|
|
|
}
|
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
/**
|
|
|
|
* 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);
|
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
return $this->server_command($this->xml);
|
2012-06-26 14:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Reseller
|
|
|
|
*/
|
|
|
|
public function cmd_getreseller(Model_Service $so) {
|
|
|
|
$this->init();
|
|
|
|
$items = array_keys($this->_template['reseller']);
|
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
$hsao = ORM::factory('Host_Server_Affiliate',array('affiliate_id'=>$so->affiliate_id,'host_server_id'=>$so->plugin()->host_server_id))->find();
|
2012-06-26 14:28:18 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
return $this->server_command($this->xml);
|
2012-06-26 14:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get Domain Traffic
|
|
|
|
*/
|
|
|
|
public function cmd_gettraffic(Model_Service $so) {
|
|
|
|
throw new Kohana_Exception('Not Implemented');
|
|
|
|
}
|
|
|
|
|
2012-07-23 12:21:13 +00:00
|
|
|
/**
|
|
|
|
* Disable Mail
|
|
|
|
*/
|
|
|
|
public function cmd_disablemail(Model_Service $so) {
|
|
|
|
$do = clone $this->cmd_getdomain($so);
|
|
|
|
|
|
|
|
$this->init();
|
|
|
|
$domain = $this->packet->add_node('mail');
|
|
|
|
$disable = $domain->add_node('disable');
|
|
|
|
$disable->add_node('site-id',$do->id->value());
|
|
|
|
|
|
|
|
return $this->server_command($this->xml);
|
|
|
|
}
|
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
/**
|
|
|
|
* Provision a hosting service
|
|
|
|
* @todo To implement
|
|
|
|
*/
|
|
|
|
public function provision(Model_Service $so) {
|
2012-07-12 05:10:53 +00:00
|
|
|
$ro = clone $this->cmd_getreseller($so);
|
2012-06-26 14:28:18 +00:00
|
|
|
|
|
|
|
// Make sure our reseller exists
|
2012-07-12 05:10:53 +00:00
|
|
|
if ($ro AND ! $ro->id->value())
|
2012-06-26 14:28:18 +00:00
|
|
|
throw new Kohana_Exception('Add Reseller - Not Implemented');
|
|
|
|
|
2012-07-23 08:26:14 +00:00
|
|
|
// @todo If client already exists, skip this part...
|
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
$result = $this->add_client($so);
|
2012-07-23 08:26:14 +00:00
|
|
|
if (! $result->loaded()) {
|
|
|
|
print_r(array('x'=>(string)$result->_xml,'o'=>(string)$result->_object));
|
2012-06-26 14:28:18 +00:00
|
|
|
throw new Kohana_Exception('Failed to Add Client?');
|
2012-07-23 08:26:14 +00:00
|
|
|
}
|
2012-06-26 14:28:18 +00:00
|
|
|
|
|
|
|
// Provision Domain
|
|
|
|
$result = $this->add_domain($so);
|
2012-07-23 08:26:14 +00:00
|
|
|
if (! $result->loaded()) {
|
|
|
|
print_r(array('x'=>(string)$result->_xml,'o'=>(string)$result->_object));
|
2012-06-26 14:28:18 +00:00
|
|
|
throw new Kohana_Exception('Failed to Add Domain?');
|
2012-07-23 08:26:14 +00:00
|
|
|
}
|
2012-06-26 14:28:18 +00:00
|
|
|
|
2012-07-23 08:26:14 +00:00
|
|
|
echo (string)$result->_object;
|
2012-06-26 14:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function add_client(Model_Service $so) {
|
2012-07-12 05:10:53 +00:00
|
|
|
$ro = clone $this->cmd_getreseller($so);
|
2012-06-26 14:28:18 +00:00
|
|
|
|
|
|
|
$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));
|
|
|
|
|
2012-07-12 11:18:22 +00:00
|
|
|
$gen_info->add_node('login',$so->plugin()->host_username);
|
2012-06-26 14:28:18 +00:00
|
|
|
$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)
|
2012-07-12 05:10:53 +00:00
|
|
|
$gen_info->add_node('owner-id',$ro->id->value());
|
2012-06-26 14:28:18 +00:00
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
return $this->server_command($this->xml);
|
|
|
|
}
|
2012-06-26 14:28:18 +00:00
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
public function add_dnsdata(Model_Service $so,XML $dns) {
|
|
|
|
$this->init();
|
|
|
|
$this->packet->import($dns);
|
2012-06-26 14:28:18 +00:00
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
return $this->server_command($this->xml);
|
2012-06-26 14:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function add_domain(Model_Service $so) {
|
2012-07-12 05:10:53 +00:00
|
|
|
$plan = 'Default Domain'; //@todo Get from other means.
|
|
|
|
$co = clone $this->cmd_getclient($so);
|
2012-06-26 14:28:18 +00:00
|
|
|
$ip = '223.27.16.147'; //@todo Get from other means.
|
|
|
|
|
|
|
|
if (! $co->loaded())
|
|
|
|
throw new Kohana_Exception('Unable to load Plesk Customer?');
|
|
|
|
|
2012-07-23 08:26:14 +00:00
|
|
|
if (! $so->plugin()->ftp_username)
|
|
|
|
throw new KOhana_Exception('FTP Username cannot be blank');
|
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
$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()));
|
2012-07-12 05:10:53 +00:00
|
|
|
$gen_setup->add_node('owner-id',$co->id->value());
|
2012-06-26 14:28:18 +00:00
|
|
|
$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);
|
2012-07-23 08:26:14 +00:00
|
|
|
if ($so->plugin()->ftp_password) {
|
|
|
|
$property = $vrt_host->add_node('property');
|
|
|
|
$property->add_node('name','ftp_password');
|
|
|
|
$property->add_node('value',$so->plugin()->ftp_password);
|
|
|
|
}
|
2012-06-26 14:28:18 +00:00
|
|
|
$vrt_host->add_node('ip_address',$ip);
|
|
|
|
|
|
|
|
$add->add_node('plan-name',$plan);
|
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
return $this->server_command($this->xml);
|
|
|
|
}
|
2012-06-26 14:28:18 +00:00
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
public function newitem(Model_Service $so,$type) {
|
|
|
|
$this->init();
|
2012-06-26 14:28:18 +00:00
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
return $this->packet->add_node($type);
|
2012-06-26 14:28:18 +00:00
|
|
|
}
|
2012-07-12 11:18:22 +00:00
|
|
|
|
2012-07-13 04:24:15 +00:00
|
|
|
public function setexpire(Model_Service $so,$date=NULL) {
|
|
|
|
// @todo This should be a config item
|
|
|
|
$expbuffer = 14;
|
|
|
|
$this->init();
|
|
|
|
|
|
|
|
$site = $this->packet->add_node('webspace');
|
|
|
|
$set = $site->add_node('set');
|
|
|
|
$filter = $set->add_node('filter');
|
|
|
|
$filter->add_node('name',strtolower($so->plugin()->name()));
|
|
|
|
$values = $set->add_node('values');
|
|
|
|
$limits = $values->add_node('limits');
|
|
|
|
$limit = $limits->add_node('limit');
|
|
|
|
$limit->add_node('name','expiration');
|
|
|
|
$limit->add_node('value',(is_null($date) ? $so->plugin()->host_expire+$expbuffer*86400 : $date));
|
|
|
|
|
|
|
|
return $this->server_command($this->xml);
|
|
|
|
}
|
|
|
|
|
2012-07-12 11:18:22 +00:00
|
|
|
public function setpasswd(Model_Service $so,$pw) {
|
|
|
|
$this->init();
|
|
|
|
|
|
|
|
$client = $this->packet->add_node('customer');
|
|
|
|
$set = $client->add_node('set');
|
|
|
|
$filter = $set->add_node('filter');
|
|
|
|
$filter->add_node('login',$so->plugin()->host_username);
|
|
|
|
$values = $set->add_node('values');
|
|
|
|
$gen_info = $values->add_node('gen_info');
|
|
|
|
$gen_info->add_node('passwd',$pw);
|
|
|
|
|
|
|
|
return $this->server_command($this->xml);
|
|
|
|
}
|
2012-06-26 14:28:18 +00:00
|
|
|
}
|
|
|
|
?>
|