From dabdad91792a510ba3f29d3c779e299496e1da2e Mon Sep 17 00:00:00 2001 From: Deon George Date: Fri, 13 Jul 2012 14:24:15 +1000 Subject: [PATCH] Added service expiry to plesk --- modules/host/classes/controller/task/host.php | 10 ++++++++++ modules/host/classes/host/plugin/plesk.php | 15 +++------------ modules/host/classes/host/plugin/plesk/10.php | 18 ++++++++++++++++++ modules/host/classes/host/plugin/plesk/9.php | 18 ++++++++++++++++++ 4 files changed, 49 insertions(+), 12 deletions(-) diff --git a/modules/host/classes/controller/task/host.php b/modules/host/classes/controller/task/host.php index 2b7f5c50..40debabf 100644 --- a/modules/host/classes/controller/task/host.php +++ b/modules/host/classes/controller/task/host.php @@ -26,6 +26,7 @@ class Controller_Task_Host extends Controller_Task { case 'migrate': case 'provision': case 'resetpw': + case 'setexpire': $this->so = ORM::factory('service',$this->request->param('id')); if (! $this->so->loaded()) @@ -265,5 +266,14 @@ class Controller_Task_Host extends Controller_Task { echo _('Password Reset Success'); } + + public function action_setexpire() { + if (! ($result = $this->hpo->setexpire($this->so)) OR ! $result->loaded()) { + echo ('Unable to set expire date.'); + echo (string)$result->_xml; + echo (string)$result->_object; + } else + echo (string)$result->_object; + } } ?> diff --git a/modules/host/classes/host/plugin/plesk.php b/modules/host/classes/host/plugin/plesk.php index 58e96ab0..58d97e81 100644 --- a/modules/host/classes/host/plugin/plesk.php +++ b/modules/host/classes/host/plugin/plesk.php @@ -41,11 +41,10 @@ abstract class Host_Plugin_Plesk extends Host_Plugin { throw new Kohana_Exception('XML command malformed? :xml',array(':xml'=>(string)$this->xml)); $get = array_shift($a); - if (! $this->_loaded OR $this->_object->$key->$get->result->status->value() != 'ok' ) - return $this->_object; - if ($index == '_object') - return $this->_object->$key->$get; + return (! $this->_loaded OR $this->_object->$key->$get->result->status->value() != 'ok' ) ? $this->_object : $this->_object->$key->$get; + elseif ($index == '_xml') + return $this->xml; else return is_object($this->_object->$key->$get->result->$index) ? $this->_object->$key->$get->result->$index : NULL; } @@ -86,14 +85,6 @@ abstract class Host_Plugin_Plesk extends Host_Plugin { } protected function server_command(XML $xml) { - // We need to find out the command key, so we can get the status result. - if (count($a=array_keys($xml->packet->as_array())) != 1) - throw new Kohana_Exception('XML command malformed? :xml',array(':xml'=>(string)$xml)); - $key = array_shift($a); - if (count($a=array_keys($xml->packet->$key->as_array())) != 1) - throw new Kohana_Exception('XML command malformed? :xml',array(':xml'=>(string)$xml)); - $get = array_shift($a); - $request = Request::factory(sprintf('%s/%s',$this->hso->manage_url,$this->path)) ->method('POST'); diff --git a/modules/host/classes/host/plugin/plesk/10.php b/modules/host/classes/host/plugin/plesk/10.php index 30a51327..caa0e7b7 100644 --- a/modules/host/classes/host/plugin/plesk/10.php +++ b/modules/host/classes/host/plugin/plesk/10.php @@ -230,6 +230,24 @@ class Host_Plugin_Plesk_10 extends Host_Plugin_Plesk { return $this->packet->add_node($type); } + 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); + } + public function setpasswd(Model_Service $so,$pw) { $this->init(); diff --git a/modules/host/classes/host/plugin/plesk/9.php b/modules/host/classes/host/plugin/plesk/9.php index c61bc59a..cffcfbff 100644 --- a/modules/host/classes/host/plugin/plesk/9.php +++ b/modules/host/classes/host/plugin/plesk/9.php @@ -304,6 +304,24 @@ class Host_Plugin_Plesk_9 extends Host_Plugin_Plesk { */ } + public function setexpire(Model_Service $so,$date=NULL) { + // @todo This should be a config item + $expbuffer = 14; + $this->init(); + + $domain = $this->packet->add_node('domain'); + $set = $domain->add_node('set'); + $filter = $set->add_node('filter'); + $filter->add_node('domain-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); + } + public function setpasswd(Model_Service $so,$pw) { $this->init();