322 lines
8.7 KiB
PHP
322 lines
8.7 KiB
PHP
<?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 {
|
|
// @todo - need to get this value from the DB.
|
|
private $admin_id = 'jd-admin';
|
|
private $password = 'jd3550lp';
|
|
|
|
private $protocol = '1.6.0.1';
|
|
private $path = 'enterprise/control/agent.php';
|
|
|
|
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,
|
|
);
|
|
|
|
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,
|
|
);
|
|
|
|
private $ippool = array(
|
|
'111.67.13.20'=>'shared',
|
|
);
|
|
|
|
public function addclient($account) {
|
|
// @todo Remove this static definition
|
|
$reseller_id = 'gtc-admin';
|
|
$client_template = 'DefaultClient';
|
|
|
|
$xml = XML::factory(null,'plesk');
|
|
$packet = $xml->add_node('packet','',array('version'=>$this->protocol));
|
|
|
|
// Client Details
|
|
$client = $packet->add_node('client');
|
|
$add = $client->add_node('add');
|
|
$gen_info = $add->add_node('gen_info');
|
|
$gen_info->add_node('cname',$account->company);
|
|
$gen_info->add_node('pname',sprintf('%s %s',$account->first_name,$account->last_name));
|
|
|
|
$gen_info->add_node('login',$this->admin_id);
|
|
$gen_info->add_node('passwd',$this->password);
|
|
|
|
$gen_info->add_node('status',0);
|
|
$gen_info->add_node('email',$account->email);
|
|
|
|
if ($reseller_id)
|
|
$gen_info->add_node('owner-login',$reseller_id);
|
|
|
|
return $this->server_command($xml);
|
|
}
|
|
|
|
// @not developed
|
|
public function setlimits() {
|
|
$xml = XML::factory(null,'plesk');
|
|
$packet = $xml->add_node('packet','',array('version'=>$this->protocol));
|
|
|
|
$client = $packet->add_node('client');
|
|
|
|
// Permissions
|
|
$set = $client->add_node('set');
|
|
$filter = $set->add_node('filter');
|
|
$filter->add_node('login',$this->admin_id);
|
|
$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',$this->admin_id);
|
|
$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($xml);
|
|
}
|
|
|
|
public function setip($id) {
|
|
$xml = XML::factory(null,'plesk');
|
|
$packet = $xml->add_node('packet','',array('version'=>$this->protocol));
|
|
|
|
// IP Address
|
|
$client = $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($xml);
|
|
}
|
|
|
|
public function disablemail($id) {
|
|
$xml = XML::factory(null,'plesk');
|
|
$packet = $xml->add_node('packet','',array('version'=>$this->protocol));
|
|
|
|
// IP Address
|
|
$client = $packet->add_node('mail');
|
|
$disable = $client->add_node('disable');
|
|
$disable->add_node('domain_id',$id);
|
|
|
|
echo (string)$xml;
|
|
return $this->server_command($xml);
|
|
}
|
|
|
|
public function adddomain($service) {
|
|
$host_ip = '111.67.13.20';
|
|
$domain_template = 'Default Domain';
|
|
|
|
$xml = XML::factory(null,'plesk');
|
|
$packet = $xml->add_node('packet','',array('version'=>$this->protocol));
|
|
|
|
// Domain Details
|
|
$domain = $packet->add_node('domain');
|
|
$add = $domain->add_node('add');
|
|
$gen_setup = $add->add_node('gen_setup');
|
|
$gen_setup->add_node('name',$service->domain_name);
|
|
$gen_setup->add_node('owner-login',$this->admin_id);
|
|
$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',$service->host_username);
|
|
$property = $vrt_host->add_node('property');
|
|
$property->add_node('name','ftp_password');
|
|
$property->add_node('value',$service->host_password);
|
|
$vrt_host->add_node('ip_address',$host_ip);
|
|
|
|
$add->add_node('template-name',$domain_template);
|
|
|
|
return $this->server_command($xml);
|
|
}
|
|
|
|
private function render(XML $xml) {
|
|
return preg_replace('/<\/?plesk>/','',(string)$xml->render(FALSE));
|
|
}
|
|
|
|
public function addclienttohost() {
|
|
$LOGIN = 'admin';
|
|
$PASSWD = 'w243550lp';
|
|
|
|
$header = array(
|
|
"HTTP_AUTH_LOGIN: " . $LOGIN,
|
|
"HTTP_AUTH_PASSWD: " . $PASSWD,
|
|
"HTTP_PRETTY_PRINT: TRUE",
|
|
"Content-Type: text/xml",
|
|
);
|
|
|
|
return Remote::get(sprintf('https://%s/%s','w24-1-1.gthost.net:8443',$this->path),array(
|
|
CURLOPT_SSL_VERIFYHOST => 0,
|
|
CURLOPT_SSL_VERIFYPEER => FALSE,
|
|
CURLOPT_HTTPHEADER => $header,
|
|
CURLOPT_VERBOSE => TRUE,
|
|
CURLOPT_POSTFIELDS => $this->render(),
|
|
CURLOPT_RETURNTRANSFER => TRUE));
|
|
}
|
|
|
|
public function adddomaintohost($id) {
|
|
$this->domain = ORM::factory('hostserver',$id);
|
|
$this->domain_xml();
|
|
|
|
}
|
|
|
|
public function get_client($account) {
|
|
$xml = XML::factory(null,'plesk');
|
|
$packet = $xml->add_node('packet','',array('version'=>$this->protocol));
|
|
|
|
$client = $packet->add_node('client');
|
|
$get = $client->add_node('get');
|
|
$filter = $get->add_node('filter');
|
|
$filter->add_node('login',$this->admin_id);
|
|
$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($xml);
|
|
}
|
|
|
|
public function get_service($service) {
|
|
$xml = XML::factory(null,'plesk');
|
|
$packet = $xml->add_node('packet','',array('version'=>$this->protocol));
|
|
|
|
$client = $packet->add_node('domain');
|
|
$get = $client->add_node('get');
|
|
$filter = $get->add_node('filter');
|
|
// @todo this should not be required
|
|
if ($service->domain_tld)
|
|
$filter->add_node('domain-name',sprintf('%s.%s',$service->domain_name,$service->domain_tld));
|
|
else
|
|
$filter->add_node('domain-name',$service->domain_name);
|
|
$dataset = $get->add_node('dataset');
|
|
$dataset->add_node('hosting');
|
|
$dataset->add_node('limits');
|
|
|
|
return $this->server_command($xml);
|
|
}
|
|
|
|
private function server_command(XML $xml) {
|
|
// @todo Configure this in OSB
|
|
$LOGIN = 'admin';
|
|
$PASSWD = 'w243550lp';
|
|
$SERVER = 'w24-1-1.gthost.net';
|
|
$PORT = 8443;
|
|
$PROTO = 'https';
|
|
|
|
$header = array(
|
|
'HTTP_AUTH_LOGIN: '.$LOGIN,
|
|
'HTTP_AUTH_PASSWD: '.$PASSWD,
|
|
'HTTP_PRETTY_PRINT: TRUE',
|
|
'Content-Type: text/xml',
|
|
);
|
|
|
|
//echo (string)$xml;
|
|
//die();
|
|
return XML::factory(null,'plesk',Remote::get(sprintf('%s://%s:%s/%s',$PROTO,$SERVER,$PORT,$this->path),array(
|
|
CURLOPT_SSL_VERIFYHOST => 0,
|
|
CURLOPT_SSL_VERIFYPEER => FALSE,
|
|
CURLOPT_HTTPHEADER => $header,
|
|
CURLOPT_VERBOSE => TRUE,
|
|
CURLOPT_TIMEOUT => 40,
|
|
CURLOPT_CONNECTTIMEOUT => 20,
|
|
CURLOPT_POSTFIELDS => $this->render($xml),
|
|
CURLOPT_RETURNTRANSFER => TRUE)));
|
|
}
|
|
|
|
public function set_traffic() {
|
|
$xml = XML::factory(null,'plesk');
|
|
$packet = $xml->add_node('packet','',array('version'=>$this->protocol));
|
|
|
|
$domain = $packet->add_node('domain');
|
|
$set = $domain->add_node('set');
|
|
$filter = $set->add_node('filter');
|
|
|
|
# foreach (array(
|
|
# 'absmotorcycles.com.au'
|
|
# ) as $domain) {
|
|
# $filter->add_node('domain-name',$domain);
|
|
# }
|
|
|
|
$values = $set->add_node('values');
|
|
|
|
// Limits
|
|
$x = $values->add_node('limits');
|
|
#foreach ($this->limits as $k=>$v) {
|
|
$l = $x->add_node('limit');
|
|
$l->add_node('name','max_traffic');
|
|
$l->add_node('value',1500*1024*1024);
|
|
$l = $x->add_node('limit');
|
|
$l->add_node('name','max_traffic_soft');
|
|
$l->add_node('value',1300*1024*1024);
|
|
#}
|
|
|
|
//echo (string)$xml;die();
|
|
return $this->server_command($xml);
|
|
}
|
|
}
|