Implement PLESK, SSL Services

This commit is contained in:
Deon George
2011-12-17 10:31:35 +11:00
parent cb18209369
commit c8fd44f844
29 changed files with 1038 additions and 438 deletions

View File

@@ -0,0 +1,123 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides Host Server functions
*
* @package OSB
* @subpackage HostServer
* @category Controllers/Task
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Controller_Task_Host extends Controller_Task {
// Host Server Object
private $hs;
public function __construct(Request $request, Response $response) {
parent::__construct($request,$response);
// To make it easy for some methods, we'll load our service here
switch (Request::current()->action()) {
case 'getclient':
case 'getservice':
case 'provision':
$sid = $this->request->param('id');
$hso = ORM::factory('service',$sid)->plugin()->host_server;
require Kohana::find_file('vendor',$hso->provision_plugin);
$this->hs = new $hso->provision_plugin($hso);
break;
}
}
/**
* Get Client Details from Host Server
*/
public function action_getclient() {
$sid = $this->request->param('id');
print_r((string)$this->hs->get_client(ORM::factory('service',$sid)));
}
/**
* Get Client Details from Host Server
*/
public function action_getservice() {
$sid = $this->request->param('id');
print_r((string)$this->hs->get_service(ORM::factory('service',$sid)));
}
/**
* List services that need to be provisioned
*/
public function action_provisionlist() {
$mode = $this->request->param('id');
$cats = array();
if ($mode)
$cats = ORM::factory('product_category')->list_bylistgroup($mode);
foreach (ORM::Factory('service')->list_provision()->find_all() as $so) {
$pc = array();
// Limit to show only those by the requested category.
if ($cats) {
if (! $so->product->avail_category_id OR ! preg_match('/^a:/',$so->product->avail_category_id))
continue;
$pc = unserialize($so->product->avail_category_id);
if (! array_intersect($pc,array_keys($cats)))
continue;
}
echo $so->id();
switch ($mode) {
case 'host':
printf(' %s %s %s',$so->plugin(),$so->plugin()->host_server->name,$so->service_name());
break;
default:
}
echo "\n";
}
}
/**
* Add a domain for the client
*
* @param int $id Hosting ID (in OSB)
* @return unknown_type
*/
public function action_provision() {
$sid = $this->request->param('id');
$so = ORM::factory('service',$sid);
// Provision Account
// @todo Need a test to see if an account alerady exists.
/*
$result = $this->hs->add_client($so);
print_r((string)$result);
// 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);
// Provision Domain
$result = $this->hs->add_service($so);
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);
*/
}
}
?>

View File

@@ -11,6 +11,9 @@
* @license http://dev.osbill.net/license.html
*/
class Model_Host_Server extends ORMOSB {
// Host Server doesnt use the update column
protected $_updated_column = FALSE;
public function manage_button($u,$p,$d) {
$c = sprintf('Service_Host_%s',$this->provision_plugin);
if (! class_exists($c))
@@ -20,5 +23,12 @@ class Model_Host_Server extends ORMOSB {
return $po->manage_button($u,$p,$d);
}
public function config() {
if (! $this->provision_plugin_data)
throw new Kohana_Exception('No plugin configuration data');
return unserialize($this->provision_plugin_data);
}
}
?>

View File

@@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class supports affiliates Host Server Configuration
*
* @package OSB
* @subpackage HostServer/Affiliate
* @category Models
* @author Deon George
* @copyright (c) 2010 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Model_Host_Server_Affiliate extends ORMOSB {
}
?>

View File

@@ -51,6 +51,10 @@ class Model_Service_Plugin_Host extends Model_Service_Plugin {
* to manage the domain.
*/
public function manage_button() {
// @todo Convert this to a Static_List display
if ($this->service->queue == 'PROVISION')
return _('To Be Provisioned');
return ($this->host_username AND $this->host_password) ? $this->host_server->manage_button($this->host_username,$this->host_password,$this->name()) : '';
}
}

258
modules/host/vendor/plesk.php vendored Normal file
View File

@@ -0,0 +1,258 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides PLESK support
*
* @package OSB
* @subpackage Plugins/Plesk
* @category Plugins
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Plesk {
private $protocol = '1.6.0.1';
private $path = 'enterprise/control/agent.php';
// Service Object
private $hso;
private $packet;
private $xml;
// @todo Get this out of the DB
private $permissions = array(
'cp_access'=>TRUE,
'create_domains'=>FALSE,
'manage_phosting'=>FALSE,
'manage_php_safe_mode'=>FALSE,
'manage_sh_access'=>FALSE,
'manage_not_chroot_shell'=>FALSE,
'manage_quota'=>TRUE,
'manage_subdomains'=>TRUE,
'manage_domain_aliases'=>FALSE,
'manage_log'=>TRUE,
'manage_anonftp'=>FALSE,
'manage_crontab'=>FALSE,
'change_limits'=>FALSE,
'manage_dns'=>TRUE,
'manage_webapps'=>FALSE,
'manage_webstat'=>TRUE,
'manage_maillists'=>TRUE,
'manage_spamfilter'=>FALSE,
'manage_virusfilter'=>FALSE,
'allow_local_backups'=>FALSE,
'allow_ftp_backups'=>TRUE,
'remote_access_interface'=>FALSE,
'site_builder'=>FALSE,
'manage_performance'=>FALSE,
'manage_dashboard'=>TRUE,
'select_db_server'=>FALSE,
);
// @todo Get this out of the DB
private $limits = array(
'resource-policy'=>'notify',
'max_dom'=>-1,
'max_subdom'=>-1,
'max_dom_aliases'=>-1,
'disk_space_soft'=>-1,
'disk_space'=>-1,
'max_traffic_soft'=>-1,
'max_traffic'=>-1,
'max_wu'=>-1,
'max_db'=>-1,
'max_box'=>-1,
'mbox_quota'=>51200000,
'max_redir'=>-1,
'max_mg'=>-1,
'max_resp'=>-1,
'max_maillists'=>-1,
'max_webapps'=>0,
'expiration'=>-1,
);
// @todo Get this out of the DB
private $ippool = array(
'111.67.13.20'=>'shared',
);
private $curlopts = array(
CURLOPT_CONNECTTIMEOUT => 60,
CURLOPT_FAILONERROR => TRUE,
CURLOPT_FOLLOWLOCATION => FALSE,
CURLOPT_HEADER => FALSE,
CURLOPT_HTTPPROXYTUNNEL => FALSE,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 30,
CURLOPT_SSL_VERIFYHOST => FALSE,
CURLOPT_SSL_VERIFYPEER => FALSE,
CURLOPT_VERBOSE => TRUE,
);
public function __construct(Model_Host_Server $hso) {
$this->hso = $hso;
$this->xml = XML::factory(null,'plesk');
$this->packet = $this->xml->add_node('packet','',array('version'=>$this->protocol));
}
private function server_command(XML $xml) {
$hs = $this->hso->config();
$request = Request::factory(sprintf('%s/%s',$this->hso->manage_url,$this->path))
->method('POST');
$request->get_client()->options(Arr::merge($this->curlopts,array(
CURLOPT_HTTPHEADER => array(
'HTTP_AUTH_LOGIN: '.$hs['user'],
'HTTP_AUTH_PASSWD: '.$hs['pass'],
'Content-Type: text/xml',
),
CURLOPT_POSTFIELDS => $this->render($xml),
)));
$response = $request->execute();
return XML::factory(null,'plesk',$response->body());
}
/**
* Get a Client Configuration
*/
public function get_client(Model_Service $so) {
$client = $this->packet->add_node('client');
$get = $client->add_node('get');
$filter = $get->add_node('filter');
$filter->add_node('login',$so->plugin()->host_username);
$dataset = $get->add_node('dataset');
$dataset->add_node('gen_info');
$dataset->add_node('stat');
$dataset->add_node('permissions');
$dataset->add_node('limits');
$dataset->add_node('ippool');
return $this->server_command($this->xml);
}
/**
* Get a Server Configuration
*/
public function get_service(Model_Service $so) {
$client = $this->packet->add_node('domain');
$get = $client->add_node('get');
$filter = $get->add_node('filter');
$filter->add_node('domain-name',strtolower($so->name()));
$dataset = $get->add_node('dataset');
$dataset->add_node('hosting');
$dataset->add_node('limits');
return $this->server_command($this->xml);
}
/**
* Add a new client to the host server
*/
public function add_client(Model_Service $so) {
$client_template = 'DefaultClient';
$reseller_id = $so->affiliate->host_server_affiliate->host_username;
$client = $this->packet->add_node('client');
$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_username);
$gen_info->add_node('passwd',$so->plugin()->host_password);
$gen_info->add_node('status',0);
$gen_info->add_node('email',$so->account->email);
if ($reseller_id)
$gen_info->add_node('owner-login',$reseller_id);
return $this->server_command($this->xml);
}
public function add_service(Model_Service $so) {
// @todo This should come from the DB.
$host_ip = '111.67.13.20';
$domain_template = 'Default Domain';
$domain = $this->packet->add_node('domain');
$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-login',$so->plugin()->host_username);
$gen_setup->add_node('htype','vrt_hst');
$gen_setup->add_node('ip_address',$host_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',$host_ip);
$add->add_node('template-name',$domain_template);
return $this->server_command($this->xml);
}
// @todo not sure if this is actually working as desired
public function setlimits(Model_Service $so) {
$client = $this->packet->add_node('client');
// Permissions
$set = $client->add_node('set');
$filter = $set->add_node('filter');
$filter->add_node('login',$so->plugin()->host_username);
$values = $set->add_node('values');
$x = $values->add_node('permissions');
foreach ($this->permissions as $k=>$v) {
$l = $x->add_node('permission');
$l->add_node('name',$k);
$l->add_node('value',$v==TRUE?'true':'false');
}
// Limits
$set = $client->add_node('set');
$filter = $set->add_node('filter');
$filter->add_node('login',$so->plugin()->host_username);
$values = $set->add_node('values');
$x = $values->add_node('limits');
foreach ($this->limits as $k=>$v) {
$l = $x->add_node('limit');
$l->add_node('name',$k);
$l->add_node('value',$v);
}
return $this->server_command($this->xml);
}
public function setip($id) {
$client = $this->packet->add_node('client');
$ip = $client->add_node('ippool_add_ip');
$ip->add_node('client_id',$id);
foreach ($this->ippool as $k=>$v)
$ip->add_node('ip_address',$k);
return $this->server_command($this->xml);
}
public function disablemail($id) {
$client = $this->packet->add_node('mail');
$disable = $client->add_node('disable');
$disable->add_node('domain_id',$id);
return $this->server_command($this->xml);
}
private function render(XML $xml) {
return preg_replace('/<\/?plesk>/','',(string)$xml->render(FALSE));
}
}
?>