2012-06-26 14:28:18 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides PLESK 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
|
|
|
*/
|
|
|
|
abstract class Host_Plugin_Plesk extends Host_Plugin {
|
|
|
|
// Service Object
|
|
|
|
protected $protocol = '1.6.0.0';
|
|
|
|
protected $path = 'enterprise/control/agent.php';
|
|
|
|
protected $packet;
|
|
|
|
protected $xml;
|
2012-07-12 05:10:53 +00:00
|
|
|
protected $_loaded = FALSE;
|
2012-06-26 14:28:18 +00:00
|
|
|
|
|
|
|
// Manage UI Login Attributes
|
|
|
|
protected $url = 'login_up.php3';
|
|
|
|
protected $login_acnt_field = '';
|
|
|
|
protected $login_user_field = 'login_name';
|
|
|
|
protected $login_pass_field = 'passwd';
|
|
|
|
|
|
|
|
// Our required abstract classes
|
2012-07-12 05:10:53 +00:00
|
|
|
public function serialize() {
|
|
|
|
return (string)$this->_object;
|
|
|
|
}
|
|
|
|
public function unserialize($s) {
|
|
|
|
$this->_object = XML::factory(NULL,NULL,$s);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __get($index) {
|
|
|
|
// We need to find out the command key, so we can get the status result.
|
|
|
|
if (count($a=array_keys($this->xml->packet->as_array())) != 1)
|
|
|
|
throw new Kohana_Exception('XML command malformed? :xml',array(':xml'=>(string)$this->xml));
|
|
|
|
$key = array_shift($a);
|
|
|
|
if (count($a=array_keys($this->xml->packet->$key->as_array())) != 1)
|
|
|
|
throw new Kohana_Exception('XML command malformed? :xml',array(':xml'=>(string)$this->xml));
|
|
|
|
$get = array_shift($a);
|
|
|
|
|
|
|
|
if ($index == '_object')
|
2012-07-13 04:24:15 +00:00
|
|
|
return (! $this->_loaded OR $this->_object->$key->$get->result->status->value() != 'ok' ) ? $this->_object : $this->_object->$key->$get;
|
|
|
|
elseif ($index == '_xml')
|
|
|
|
return $this->xml;
|
2012-07-12 05:10:53 +00:00
|
|
|
else
|
|
|
|
return is_object($this->_object->$key->$get->result->$index) ? $this->_object->$key->$get->result->$index : NULL;
|
|
|
|
}
|
|
|
|
|
2012-06-26 14:28:18 +00:00
|
|
|
public function admin_update() {
|
|
|
|
return View::factory('host/admin/plugin/plesk')
|
|
|
|
->set('o',$this);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function manage_button(Model_Service_Plugin_Host $spho,$t) {
|
|
|
|
return $this->render_button($t,$spho->service_id,$spho->username_value(),substr(md5($spho->password_value()),0,8));
|
|
|
|
}
|
|
|
|
public function admin_manage_button(Model_Host_Server $hso,$t) {
|
|
|
|
return $this->render_button($t,$hso->id,substr(md5($hso->manage_username),0,8),substr(md5($hso->manage_password),0,8));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function render_button($t,$sid,$u,$p) {
|
|
|
|
$debug = FALSE;
|
|
|
|
$output = '';
|
|
|
|
|
|
|
|
$output .= Form::open(
|
|
|
|
$debug ? 'debug/site' : sprintf('%s/%s',$this->hso->manage_url,$this->url),
|
|
|
|
array('target'=>'w24','method'=>'post','id'=>sprintf('id_%s_%s',$sid,$t))
|
|
|
|
);
|
|
|
|
$output .= Form::input($this->login_user_field,$u,array('type'=>'hidden','id'=>sprintf('u_%s_%s',$sid,$t)));
|
|
|
|
$output .= Form::input($this->login_pass_field,$p,array('type'=>'hidden','id'=>sprintf('p_%s_%s',$sid,$t)));
|
|
|
|
$output .= Form::close();
|
|
|
|
$output .= Form::button('submit',_('Manage'),array('class'=>'form_button','value'=>sprintf('%s:%s',$sid,$t)));
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function init() {
|
|
|
|
$this->_loaded = FALSE;
|
2012-07-12 05:10:53 +00:00
|
|
|
$this->_object = XML::factory(NULL,'plesk');
|
2012-07-05 03:06:17 +00:00
|
|
|
$this->xml = XML::factory(NULL,'plesk');
|
2012-06-26 14:28:18 +00:00
|
|
|
$this->packet = $this->xml->add_node('packet','',array('version'=>$this->protocol));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function server_command(XML $xml) {
|
|
|
|
$request = Request::factory(sprintf('%s/%s',$this->hso->manage_url,$this->path))
|
|
|
|
->method('POST');
|
|
|
|
|
2012-11-09 23:13:57 +00:00
|
|
|
$request->client()->options(Arr::merge($this->curlopts,array(
|
2012-06-26 14:28:18 +00:00
|
|
|
CURLOPT_HTTPHEADER => array(
|
|
|
|
'HTTP_AUTH_LOGIN: '.$this->hso->manage_username,
|
|
|
|
'HTTP_AUTH_PASSWD: '.$this->hso->manage_password,
|
|
|
|
'Content-Type: text/xml',
|
|
|
|
),
|
|
|
|
CURLOPT_POSTFIELDS => $this->render($xml),
|
|
|
|
)));
|
|
|
|
|
|
|
|
$response = $request->execute();
|
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
$this->_object = XML::factory(NULL,'plesk',$response->body());
|
2012-06-26 14:28:18 +00:00
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
if ($this->_object->status->value() == 'ok')
|
2012-06-26 14:28:18 +00:00
|
|
|
$this->_loaded = TRUE;
|
|
|
|
|
2012-07-12 05:10:53 +00:00
|
|
|
return $this;
|
2012-06-26 14:28:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function loaded() {
|
|
|
|
return $this->_loaded;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function render(XML $xml) {
|
|
|
|
return preg_replace('/<\/?plesk>/','',(string)$xml->render(FALSE));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|