PHP Classes

using cPanel API2 functions

Recommend this page to a friend!

      WHM XML API  >  All threads  >  using cPanel API2 functions  >  (Un) Subscribe thread alerts  
Subject:using cPanel API2 functions
Summary:This is the way you can use Cpanel API2 functions
Messages:2
Author:Arash Hemmat
Date:2007-09-29 19:33:45
Update:2011-02-16 18:46:30
 

  1. using cPanel API2 functions   Reply   Report abuse  
Picture of Arash Hemmat Arash Hemmat - 2007-09-29 19:33:45
Hi
If you need to use the Cpanel API2 functions you can make a function like the one below and add it to the class:

<?php
/*
* cPanel API2 Cpanel::Email::listpopswithdisk
* This function lists all email accounts for a domain, along with their disk space quota and disk space usage.
*/
function Email_listpopswithdisk($user,$domain)
{
//connect using prpoer xml api address
$this->connect("/xml-api/cpanel?user=$user&xmlin=<cpanelaction><module>Email</module><func>listpopswithdisk</func><args><domain>$domain</domain></args></cpanelaction>");
//get the output
$xmlstr=$this->getOutput();
if($xmlstr=='')
{
$this->errors[]='No output.';
return false;
}
//disconnect
$this->disconnect();

if($xmlstr)
{
//get the output xml as an array using simple xml
$xml = new SimpleXMLElement($xmlstr);
$i=0;
foreach($xml->data as $entry)
{
$result[$i]['domain']=htmlentities((string) $entry->domain);
$result[$i]['user']=htmlentities((string) $entry->user);
$result[$i]['login']=htmlentities((string) $entry->login);
$result[$i]['email']=htmlentities((string) $entry->email);
$result[$i]['_diskquota']=htmlentities((string) $entry->_diskquota);
$result[$i]['_diskused']=htmlentities((string) $entry->_diskused);
$result[$i]['diskquota']=htmlentities((string) $entry->diskquota);
$result[$i]['diskused']=htmlentities((string) $entry->diskused);
$result[$i]['diskusedpercent']=htmlentities((string) $entry->diskusedpercent);
$result[$i]['diskusedpercent20']=htmlentities((string) $entry->diskusedpercent20);
$result[$i]['humandiskquota']=htmlentities((string) $entry->humandiskquota);
$result[$i]['humandiskused']=htmlentities((string) $entry->humandiskused);
$result[$i]['txtdiskquota']=htmlentities((string) $entry->txtdiskquota);
$i++;
}
return $result;
}
else
{
$this->errors[]='Some errors occured.';
return false;
}
}
?>

Usage:
Usage of this function is just like the other functions in class:


<?php
//include the whm class file.
require_once('whm.php');

// create a new instance of whm class
$test= new whm;

//initilize the whm object
//you can use you hostname or an IP below
//you can find you whm hash when yopu login into your whm account clickong on "Setup Remote Access Key" link.
$test->init('whm_host','whm_user','whm_hash');

$result=$test->Email_listpopswithdisk('user','domain.tld');
print_r($result);
?>

  2. Re: using cPanel API2 functions   Reply   Report abuse  
Picture of ratul kislaya ratul kislaya - 2011-02-16 18:46:31 - In reply to message 1 from Arash Hemmat
Hi,

I am sending this in a big hope for a solution from you :)

I have two problems and searched everywhere in google and the forums I couldn't find an answer. However this seems pretty basic so I must be doing something wrong or thinking something wrong. Please guide.

Problems:
1. What is the API to create a feature list on WHM (preferably API2)
2. While creating a Package, the addpkg API call, refers to an input variable 'featurelist (string) — Name of the feature list to be used for the package.'. In the example I see that the word 'Default' is passed indicating that a featurelist name has to be passed, which matches the documentation description. How to get this featurelist string names???

The API Listed at getfeaturelist does not help.


Please help