<?php
class Kloxo extends HostingModule {
//Version
protected $version ='1.00';
//Description
protected $description='Kloxo provisioning module';
//Enable AJAX
protected $ajaxLoadValues=true;
//End INIT
//Translations
protected $lang=array(
'english'=>array(
'acc-type'=>'Account Type',
'resource-plan'=>'Plan Name',
'dns-template'=>'DNS Template',
),
'german'=>array(
'acc-type'=>'Account-Typ',
'resource-plan'=>'Plannamen',
'dns-template'=>'DNS Schablone',
)
);
//End Translations
//Server Settings APPprotected $options = array(
'option1' =>array (
'name'=> 'acc-type',
'value' =>false,
'type'=> 'select',
'default'=> array("customer","reseller"),
),
'option2' =>array (
'name'=> 'resource-plan',
'value' => false,
'type'=> 'input',
'default'=>false,
),
'option3' =>array (
'name'=> 'dns-template',
'value' => false,
'type'=> 'input',
'default'=>false,
),
);
//account specific stuff below
protected $details = array(
'option6' =>array (
'name'=> 'domain',
'value' => false,
'type'=> 'input',
'default'=>false
),
'option1' =>array (
'name'=> 'username',
'value' => false,
'type'=> 'input',
'default'=>false
),
'option2' =>array (
'name'=> 'password',
'value' => false,
'type'=> 'input',
'default'=>false
),
);
//End User Specifics
//Start Action Handler
protected $commands = array(
'Suspend','Terminate','ChangePackage','ChangePassword','Create','Unsuspend'//,'getResourcePlansInfo'
);
//connection
private $server_username;
private $server_password;
private $server_hostname;
private $server_ip;
public function connect($connect) {
$this->server_username = $connect['username'];
$this->server_password = $connect['password'];
$this->server_hostname = $connect['hostname'];
$this->server_ip = $connect['ip'];
if($connect['secure']) {
$this->port = 7777;
$this->http = "https";
}
else {
$this->port = 7778;
$this->http = "http";
}
}//endconnection
//Default Kloxo JSON Processing
public function lxlabs_get_via_json($protocol, $server, $port, $param) {
$param = "login-class=client&login-name=admin&login-password=pass&output-type=json&$param";
$url = "$protocol://$server:$port/webcommand.php";
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, $param);
$totalout = curl_exec($ch);
$totalout = trim($totalout);
//Replace require JSON.php START X0001
require_once('JSON.php');
//end Replace X0001
$json = new Services_JSON();
$object = $json->decode($totalout);
if (!is_object($object)) {
print("Fatal Error. Got a non-object from the server: $totalout\n");
exit;
}
return $object;
}//end Kloxo's JSON
private function Send($type, $param) {
$http = "http";
if ( $http == "http" ) {
$port = '7778';
}
else {
$port = '7777';
}//end SetDefaultPort
$adminpassword = $this->server_password;
$adminuser = $this->server_username;
$serverloc = $this->server_ip;
$builtparameter = "login-class=client&login-name=$adminuser&login-password=$adminpassword&output-type=json&". $param;
$get = $this->lxlabs_get_via_json($this->http, $serverloc, $this->port, $builtparameter);
return array(
'success'=>true,
);
}//End Send
//CreateServer
public function Create() {
//Build the string
$string = "action=add";
$string .= "&class=client";
$string .= "&v-plan_name=". $this->options['option2']['value'] ."";
$string .= "&v-type=". $this->options['option1']['value'];
$string .= "&v-contactemail=". $this->client_data['email'];
$string .= "&send_welcome_f=off";
$string .= "&v-domain_name=". $this->details['option6']['value'];
$string .= "&v-dnstemplate_name=". $this->options['option3']['value'];
$string .= "&v-password=". $this->details['option2']['value'];
$string .= "&name=". $this->details['option1']['value'];
//Finish building string $string
//send data
$type = null;
$senddata = $this->Send($type, $string);
if ($senddata['success']) {
$this->addInfo('Account has been created');
return true;
}
else {
return false;
}
}//End Create Server
//Suspend
public function Suspend() {
//Prepare string
$string = "class=client";
$string .= "&name=". $this->details['option1'];
$string .= "&action=update";
$string .= "&subaction=disable";
//End Prepare String
$type = null;
//Send Data
$senddata = $this->Send($type, $string);
if ($senddata['success']) {
$this->addinfo('Account Suspended');
return true;
}
else {
return false;
}
}
//End Suspend
//Unsuspend
public function Unsuspend() {
//Prepare string
$string = "class=client";
$string .= "&name=". $this->details['option1'];
$string .= "&action=update";
$string .= "&subaction=enable";
//End Prepare String
$type = null;
//Send Data
$senddata = $this->Send($type, $string);
if ($senddata['success']) {
$this->addInfo('Account has been unSuspended.');
return true;
}
else {
return false;
}
}
//End Suspend
//Kill Account
public function Terminate() {
$string = "action=delete";
$string .= "class=client";
$string .= "name=". $this->details['option1']['value'];
$type = null;
//Send Data
$senddata = $this->Send($type, $string);
if ($senddata['success']) {
return true;
}
else {
return false;
}
}
//Finish the murder
}//End Extension
?>