Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
kloxo api lib
<?php
class Kloxo
{
public $CI;
public $KloxoCore;
public $helper;
public function __construct()
{
$this->CI =& get_instance();
$this->CI->load->library('json');
$this->CI->load->library('KloxoCore');
$this->CI->load->library('Kloxohelper');
$this->KloxoCore = $this->CI->kloxocore;
$this->helper = $this->CI->kloxohelper;
}
public function getResourcePlans()
{
$action = "action=simplelist&resource=resourceplan";
return $this->KloxoCore->callApi($action);
}
public function getDnsTemplates()
{
$action = "action=simplelist&resource=dnstemplate";
return $this->KloxoCore->callApi($action);
}
public function getServers()
{
$action = "action=simplelist&resource=pserver";
return $this->KloxoCore->callApi($action);
}
public function getInternalResourceName($object, $name)
{
foreach ($object as $key => $value) {
if ($value != $name) {
continue;
}
return $key;
}
}
public function createAccount($params)
{
$domain = $params['domain'];
$username = $params['username'];
$password = $params['password'];
$clientsdetails = $params['clientsdetails'];
$email = $clientsdetails['email'];
$resourcePlan = $params['resourcePlan'];
$dnsTemplate = $params['dnsTemplate'];
$webServer = $params['webServer'];
$mailServer = $params['mailServer'];
$mysqlServer = $params['mysqlServer'];
$dnsServers = $params['dnsServers'];
$json = $this->KloxoCore->getResourcePlans();
if ($json->return === "error") {
return $json->message;
}
$resourcePlanInternal = $this->KloxoCore->getinternalresourcename($json->result, $resourcePlan);
$json = $this->KloxoCore->callApi("action=add&class=client&name=" . $username . "&v-password=" . $password . "&v-plan_name=" . $resourcePlanInternal . "&v-type=customer" . "&v-contactemail=" . $email . "&v-send_welcome_f=off" . "&v-domain_name=" . $domain . "&v-dnstemplate_name=" . $dnsTemplate . "&v-websyncserver" . $webServer . "&v-mmailsyncserver=" . $mailServer . "&v-mysqldbsyncserver=" . $mysqlServer . "&v-dnssyncserver_list=" . $dnsServers);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function terminateAccount($params)
{
$username = $params['username'];
$json = $this->KloxoCore->callApi("action=delete&class=client&name=" . $username);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json->message;
} else {
return true;
}
}
public function suspendAccount($params)
{
$username = $params['username'];
$json = $this->KloxoCore->callApi("action=update&subaction=disable&class=client&name=" . $username);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function unsuspendAccount($params)
{
$username = $params['username'];
$json = $this->KloxoCore->callApi("action=update&subaction=enable&class=client&name=" . $username);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function changePassword($params)
{
$username = $params['username'];
$password = $params['password'];
$json = $this->KloxoCore->callApi("action=update&subaction=password&class=client&name=" . $username . "&v-password=" . $password);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function updateClientLimit($params)
{
$username = $params['username'];
$haystack = $params['action'];
$value = $params['value'];
$needle = $this->helper->getLimitParams($haystack);
var_dump($needle);
$action = $needle['command'];
$options = $needle['options'];
var_dump($this->helper->getLimitParams($haystack));
if ($this->helper->checkLimitOptions($options, $value)) {
$json = $this->KloxoCore->callApi("action=update&subaction=limit&class=client&name=" . $username . "&" . $action . $value);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
} else {
$error = "values don`t match";
return $error;
}
}
public function changePackage($params)
{
$username = $params['username'];
$resourcePlan = $params['resourcePlan'];
$json = $this->KloxoCore->getResourcePlans();
if ($json->return === "error") {
return $json->message;
}
$resourcePlanInternal = $this->KloxoCore->getinternalresourcename($this->CI->json->result, $resourcePlan);
$json = $this->KloxoCore->callApi("action=update&subaction=change_plan&class=client&name=" . $username . "&v-resourceplan_name=" . $resourcePlanInternal);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function loginLink($params)
{
$serverip = $params['serverip'];
$username = $params['username'];
$password = $params['password'];
$serversecure = $params['serversecure'];
if ($serversecure) {
$protocol = "https://";
$port = ":7777";
} else {
$protocol = "http://";
$port = ":7778";
}
$url = $protocol . $serverip . $port . "/htmllib/phplib/?frm_clientname=" . $username . "&frm_password=" . $password;
return $url;
}
public function usedResources()
{
$json = $this->KloxoCore->callApi("action=getproperty&v-used=");
$json = $this->helper->checkJsonReturn($json, true);
if (!$json) {
return $json;
} else {
return $json;
}
}
public function massMail($params)
{
$from = $params['from'];
$subject = $params['subject'];
$message = $params['message'];
$json = $this->KloxoCore->callApi("action=update&subaction=wall&wall_from_f=" . $from . "&wall_subject_f" . $subject . "=&wall_message_f=" . $message);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function changeOwner($params)
{
$parent = $params['parent'];
$name = $params['name'];
$type = $params['type'];
$json = $this->KloxoCore->callApi("action=update&subaction=changeowner&parent_name_change=" . $parent . "&class=" . $type . "&name=" . $name);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function disabledurl($params)
{
$url = $params['url'];
$json = $this->KloxoCore->callApi("action=update&subaction=disable_url&disable_url=" . $url);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function forceDeleteServer($params)
{
if ($params['really']) {
$server = $params['server'];
$json = $this->KloxoCore->callApi("action=update&subaction=forcedeletepserver&pserver_delete_f=" . $server);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
}
public function cronMailto($params)
{
$name = $params['name'];
$to = $params['to'];
$json = $this->KloxoCore->callApi("action=update&subaction=cron_mailto&nname=" . $name . "&cron_mailto=" . $to);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function defaultDomain($params)
{
$domain = $params['domain'];
if ($domain == null) {
$domain = "--Disabled--";
}
$json = $this->KloxoCore->callApi("action=update&subaction=default_domain&default_domain=" . $domain);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function updateInstallatron()
{
$json = $this->KloxoCore->callApi("action=update&subaction=installatron&update_installatron=");
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function addParkedDomain($parentDomain, $pakedName, $enableMail = true)
{
if ($enableMail) {
$toCall = "action=add&parent-class=domain&parent-name=" . $parentDomain . "&class=addondomain&name=" . $pakedName . "&v-ttype=parked&v-mail_flag=on";
} else {
$toCall = "action=add&parent-class=domain&parent-name=" . $parentDomain . "&class=addondomain&name=" . $pakedName . "&v-ttype=parked";
}
$json = $this->KloxoCore->callApi($toCall);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function addDomain($client, $domainName, $dnsTemplate = false)
{
if (!$dnsTemplate) {
$dnsTemplate = "main.dnst";
}
$json = $this->KloxoCore->callApi("action=add&class=client&cname=domain&name=" . $client . "&nname=" . $domainName . "&v-docroot=" . $domainName . "&v-password=password&v-dnstemplate_name=" . $dnsTemplate);
$json = $this->helper->checkJsonReturn($json);
if (!$json) {
return $json;
} else {
return true;
}
}
public function serverStatus()
{
$json = $this->KloxoCore->callApi("action=getproperty&class=pserver&name=localhost");
$json = $this->helper->checkJsonReturn($json, true, true);
if (!$json) {
return $json;
} else {
return $json;
}
}
public function getDomainResourceInfo($domain, $return = "used")
{
$toCall = '';
$toCall .= "action=getproperty&class=domain&name=" . $domain;
switch ($return) {
case "priv":
$toCall .= "&v-priv=";
break;
case "used":
$toCall .= "&v-used=";
break;
default:
return false;
break;
}
$json = $this->KloxoCore->callApi($toCall);
$json = $this->helper->checkJsonReturn($json, true, true);
if (!$json) {
return $json;
} else {
return $json;
}
}
public function getClientResourceInfo($client, $return = "used")
{
$toCall = '';
$toCall .= "action=getproperty&class=client&name=" . $client;
switch ($return) {
case "priv":
$toCall .= "&v-priv=";
break;
case "used":
$toCall .= "&v-used=";
break;
}
$json = $this->KloxoCore->callApi($toCall);
$json = $this->helper->checkJsonReturn($json, true, true);
if (!$json) {
return $json;
} else {
return $json;
}
}
public function getClientServers($client)
{
$json = $this->KloxoCore->callApi("action=getproperty&resource=web_server&class=client&name=tomis");
$json = $this->helper->checkJsonReturn($json, true, true);
if (!$json) {
return $json;
} else {
return $json;
}
}
public function getAllClients()
{
$json = $this->KloxoCore->callApi("action=simplelist&resource=all_client");
$json = $this->helper->checkJsonReturn($json, true, true);
if (!$json) {
return $json;
} else {
return $json;
}
}
public function getAllDomains()
{
$json = $this->KloxoCore->callApi("action=simplelist&resource=all_domain");
$json = $this->helper->checkJsonReturn($json, true, true);
if (!$json) {
return $json;
} else {
return $json;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment