#1 (permalink)  
Old 07-07-2009, 05:22 AM
Registered User
 
Join Date: Jul 2009
Posts: 19
paulipv is on a distinguished road
WHM / cPanel API

Hello,

We are working to a PHP API Class for WHM and cPanel.
We are going to include all functions.

Structure will be something like:
WHM.php => main class
Account.php => accounting class
Reseller.php => reseller class
Dns.php => dns class
Ssl.php => ssl class
Package.php => package class
Serverinfo.php => server information class
Serveradmin.php => server administration class


================================================
An example of use:

We need to call only WHM.php

$config['whm_user'] = 'user_here';
$config['whm_user'] = 'url_here';
$config['whm_hash'] = 'hash_generated_from_whm';

$whm = new WHM('account' , $config);

first parameter 'account' is the action.
you need to create a dns? just replace is with "dns"




creating an account;
$prepare = $whm->do->createacct('user','domain','email',$extraoption s)

$extraoptions is array (ex;
$extraoptions['plan'] = 'planname';
$extraoptions['reseller'] = '1';

$prepare is the query string;
to finish the account creation you will only need to run

$result = $whm->exec($prepare);

Where the $result is the array of xml response

example to view the status
echo $result['status'];
================================================== ====
All functions names will be as WHM
"createacct,listaccts,modifyacc,addzonerecord, etc"


Any ideas are welcome
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 07-07-2009, 11:09 AM
cPanelDavidG's Avatar
cPanel Technical Sales
 
Join Date: Nov 2006
Location: Houston, TX
Posts: 7,995
cPanelDavidG is on a distinguished road
Will this class be based off the XML API and utilize API1 and API2 for cPanel functionality (if you're offering any)? I ask because this is the recommended way of interfacing with our software and is more reliable than screen scraping and operate independently of whatever themes servers are utilizing.

If you need help interfacing with anything, just let us know .
__________________
Want our technical analysts to login to your server to assist you? You can contact our technical analysts at: http://tickets.cPanel.net/submit
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 07-08-2009, 03:47 AM
Registered User
 
Join Date: Jul 2009
Posts: 19
paulipv is on a distinguished road
Yes David,
Is based on XML-API and we are using API1 and API2.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 07-08-2009, 04:15 AM
Registered User
 
Join Date: Jul 2009
Posts: 19
paulipv is on a distinguished road
I've changed the structure.

There will be a WHM Loader class.

So will working something like this.

$conn = array (define the WHM connection);


$loader = new WHM_Loader();
$loader->setPath('path_to_whmclasses_folder');

// example;

$accouting = $loader->load('accouting' , $conn);
$accouting->create_acct( .... )
$accouting->modifyacct( .... )

$dns = $loader->load('dns' , $conn);
$dns->editzonerecord('domain_name','host' , $options=array());

// improved dns options
$dns->editArecord('domain_name','current_host',$options =array());

available options for function editArecord
new_ip
new_host
ttl

So will be very easy for people who wanna make a DNS manager interface.

$dns->editCNAMERecord( ... )
$dns->editMXRecord( ...)

// for cpanel.


$email = $loader->loadcp('email' , $conn);
$email->addforward( ... );
$email->listmxs( ... )

$ftp = $loader->loadcp('ftp' , $conn);
$ftp->listftpsessions( ... )
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 07-08-2009, 04:34 AM
Registered User
 
Join Date: Jul 2009
Posts: 19
paulipv is on a distinguished road
Update.

How easy is to create an account.

$new_account['user'] = 'user_here';
$new_account['pass'] = 'pass_here'; // leave empty class will generate automatic a password
$new_account['domain'] = 'domain_name';
$new_account['email'] = 'customer_email_address';
$new_account['plan'] = 'your_hosting_plan';
$new_account['reseller'] = 0 or 1

$response = $accounting->createacct($new_account);

$response is an array and looks like:

$response['action'] = 'createacct';
$response['set'] is an array with data configured by you, example:
$reponse['set']['user'] will return the user configured by you.

$response['get'] is the array with data returned by XML-API


$response['result] is:
1 - ok
0 - not ok

$reponse['resultmsg'] = the error
$response['data'] = return a storable representation of all data.


// changing the primary domain;
$result = $accounting->changePrimaryDomain($user , $newdomain);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 07-08-2009, 05:41 AM
Registered User
 
Join Date: Jul 2009
Posts: 19
paulipv is on a distinguished road
So i need your opinion about structure:

-> WHM_loader (loading WHM/cPanel functions)
-> WHM (main class, handle connection, query builder, etc)
classes( ::: API1 :::
-> Accounting (implements WHM, handle account functions
-> Dns (implements WHM, handle dns functions)
-> Package (implements WHM, handle package functions)
-> Reseller Functions (implements WHM, handle reseller functions)
-> Server Informations (implements WHM, handle server informations)
-> Server administration (implements WHM, handle server administration functions)
-> Service functions (implements WHM , handle service functions)
-> SSL functions (implements WHM , handle service functions)

::: API2 ::: (same as API1) implements WHM and handle all operations listed on ApiTwo < AllDocumentation/AutomationIntegration < TWiki

WHM_Loader will be only need to be included and working as:

PHP Code:
    include("WHM_Loader");
   
   
// Using the loader ...
   
$whm_loader = new WHM_Loader();

   
// 1.
   
$result $whm_loader->accounting($conn)->createacct($data);
   
// 2.
   
$accounting $whm->load('accounting',$conn);
   
$result $accouting->createacct($data);
   
    

   
// Accounting class example:
   
class Accounting extends WHM {
 
    function 
Accounting($conn) {
      
$this->conn($conn);
   }

   public function 
createacct() {
   }

  
// etc...
    
   


if you want to add something to this, please let me know.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 07-08-2009, 07:32 AM
Registered User
 
Join Date: Jul 2009
Posts: 19
paulipv is on a distinguished road
Array result for account creation.

PHP Code:
Array
(
    [
action] => createacct
    
[time] => 1247052671
    
[date] => 2009-07-08 14:31:11
    
[remote_addr] => 192.168.0.1
    
[set] => Array
        (
            [
username] => myacc
            
[domain] => mydomainname.com
            
[email] => myname@myemail.com
            
[plan] => WHM-IPV
            
[pass] => mypassword
        
)

    [
get] => Array
        (
            [
ip] => 188.40.64.208
            
[nameserver] => ns1.hoster.com
            
[nameserver2] => ns2.hoster.com
            
[nameserver3] => 
            [
nameserver4] => 
            [
nameservera] => 
            [
nameservera2] => 
            [
nameservera3] => 
            [
nameservera4] => 
            [
nameserverentry] => 
            [
nameserverentry2] => 
            [
nameserverentry3] => 
            [
nameserverentry4] => 
            [
package] => WHM-IPV
        
)

    [
status] => 1
    
[statusmsg] => Account Creation Ok
    
[storage] => a:8:{s:6:"action";s:10:"createacct";s:4:"time";i:1247052671;s:4:"date";s:19:"2009-07-08 14:31:11";s:11:"remote_addr";s:11:"192.168.0.1";s:3:"set";a:5:{s:8:"username";s:5:"myacc";s:6:"domain";s:16:"mydomainname.com";s:5:"email";s:18:"myname@myemail.com";s:4:"plan";s:7:"WHM-IPV";s:4:"pass";s:10:"mypassword";}s:3:"get";a:14:{s:2:"ip";s:13:"188.40.64.208";s:10:"nameserver";s:13:"ns.ipvhost.ro";s:11:"nameserver2";s:14:"ns0.ipvhost.ro";s:11:"nameserver3";s:0:"";s:11:"nameserver4";s:0:"";s:11:"nameservera";s:0:"";s:12:"nameservera2";s:0:"";s:12:"nameservera3";s:0:"";s:12:"nameservera4";s:0:"";s:15:"nameserverentry";s:0:"";s:16:"nameserverentry2";s:0:"";s:16:"nameserverentry3";s:0:"";s:16:"nameserverentry4";s:0:"";s:7:"package";s:7:"WHM-IPV";}s:6:"status";i:1;s:9:"statusmsg";s:19:"Account Creation Ok";}
)


 
// COMMAND

     
$path app_lib 'hosting-automation/WHM/';
      
     
$whm = new WHM_Loader($config);
     
$whm->setPath($path);
     
     
$new_acc['username']   = 'myacc';
     
$new_acc['domain']     = 'mydomainname.com';
     
$new_acc['email']      = 'myname@myemail.com';
     
$new_acc['plan']       = 'WHM-IPV';
     
$new_acc['pass']       = 'mypassword';
      
     
$acc $whm->accounting()->createacct($new_acc); 
What are you thinking?
To convert the array into XML and add in array $result['xml_data'] = XML ?

will look something like
<WHM>
<createacct>
<set>
<username>user</username>
</set>

<get>
<ip>1.1.1.1</ip>
</get>

<action>createacct</action>
<date>date</date>
<time>time</time>
<result>1</result>
<resultmsg>restult msg </resultmsg>
</createacct>
</WHM>

Last edited by paulipv; 07-08-2009 at 07:39 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 07-08-2009, 12:12 PM
cPanelDavidG's Avatar
cPanel Technical Sales
 
Join Date: Nov 2006
Location: Houston, TX
Posts: 7,995
cPanelDavidG is on a distinguished road
Quote:
Originally Posted by paulipv View Post
Yes David,
Is based on XML-API and we are using API1 and API2.
Sounds great! Let us know if you need anything.
__________________
Want our technical analysts to login to your server to assist you? You can contact our technical analysts at: http://tickets.cPanel.net/submit
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 07-09-2009, 03:51 AM
Registered User
 
Join Date: Jul 2009
Posts: 19
paulipv is on a distinguished road
David,
This is the XML/Array result generated by our class for account domain modification.

How looks to you?
PHP Code:
Array
(
    [
obj] => modifyacctdomain
    
[server] => central.ipvhost.ro
    
[time] => 1247125858
    
[date] => 2009-07-09 10:50:58
    
[remote_addr] => 192.168.0.1
    
[set] => Array
        (
            [
username] => myacc
        
)

    [
get] => Array
        (
            [
messages] => Shell already set to /usr/local/cpanel/bin/noshell

            
[bwlimit] => unlimited
            
[contactemail] => myacc@mydomainname.com
            
[contactemail2] => 
            [
demo] => 0
            
[domain] => mydomain1.com
            
[featurelist] => default
            [
hascgi] => 1
            
[ip] => 188.40.64.208
            
[lang] => english-utf8
            
[maxaddon] => unlimited
            
[maxftp] => unlimited
            
[maxlst] => unlimited
            
[maxpark] => unlimited
            
[maxpop] => unlimited
            
[maxsql] => unlimited
            
[maxsub] => unlimited
            
[owner] => root
            
[plan] => WHM-IPV
            
[rs] => x3
            
[startdate] => 1247124329
            
[user] => myacc
            
[cpuser] => 
            [
setshell] => noshell
            
[newcfg] => 
            [
status] => 1
            
[statusmsg] => Account Modified
            
[result] => 
        )

    [
status] => 1
    
[statusmsg] => Account Modified

PHP Code:
 <modifyacctdomain>
  <
obj>modifyacctdomain</obj
  <
server>1.1.1.1</server
  <
time>1247125654</time
  <
date>2009-07-09 10:47:34</date
  <
remoteaddr>192.168.0.1</remoteaddr
 <
set>
  <
username>myacc</username
  </
set>
 <
get>
  <
messages>Shell already set to /usr/local/cpanel/bin/noshell</messages
  <
bwlimit>unlimited</bwlimit
  <
contactemail>myacc@mydomainname.com</contactemail
  <
contactemail /> 
  <
demo>0</demo
  <
domain>mydomain1.com</domain
  <
featurelist>default</featurelist
  <
hascgi>1</hascgi
  <
ip>2.2.2.2</ip
  <
lang>english-utf8</lang
  <
maxaddon>unlimited</maxaddon
  <
maxftp>unlimited</maxftp
  <
maxlst>unlimited</maxlst
  <
maxpark>unlimited</maxpark
  <
maxpop>unlimited</maxpop
  <
maxsql>unlimited</maxsql
  <
maxsub>unlimited</maxsub
  <
owner>root</owner
  <
plan>WHM-IPV</plan
  <
rs>x3</rs
  <
startdate>1247124329</startdate
  <
user>myacc</user
  <
cpuser /> 
  <
setshell>noshell</setshell
  <
newcfg /> 
  <
status>1</status
  <
statusmsg>Account Modified</statusmsg
  <
result /> 
  </
get>
  <
status>1</status
  <
statusmsg>Account Modified</statusmsg
  </
modifyacctdomain
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 07-09-2009, 03:30 PM
cPanelDavidG's Avatar
cPanel Technical Sales
 
Join Date: Nov 2006
Location: Houston, TX
Posts: 7,995
cPanelDavidG is on a distinguished road
Taking a quick glance, it's an interesting alternative implementation .
__________________
Want our technical analysts to login to your server to assist you? You can contact our technical analysts at: http://tickets.cPanel.net/submit
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
cPanel/WHM API? hb-travisbell cPanel and WHM Discussions 2 11-26-2006 06:42 PM
cPanel / WHM API for PHP5 Spiral cPanel and WHM Discussions 4 10-18-2006 02:54 PM
cPanel/WHM API help webadpro cPanel and WHM Discussions 5 03-02-2006 03:18 PM
CpanelAppz.com WHM/cpanel API anand Developer Discussions 27 02-10-2005 09:13 AM
Cpanel/Whm API farshad_s3 cPanel and WHM Discussions 17 09-17-2004 01:14 PM


All times are GMT -5. The time now is 05:58 PM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© cPanel Inc