Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 10 of 10
  1. #1
    Member
    Join Date
    Jul 2009
    Posts
    19

    Default 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',$extraoptions)

    $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

  2. #2
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    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 .

  3. #3
    Member
    Join Date
    Jul 2009
    Posts
    19

    Default

    Yes David,
    Is based on XML-API and we are using API1 and API2.

  4. #4
    Member
    Join Date
    Jul 2009
    Posts
    19

    Default

    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( ... )

  5. #5
    Member
    Join Date
    Jul 2009
    Posts
    19

    Default

    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);

  6. #6
    Member
    Join Date
    Jul 2009
    Posts
    19

    Default

    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.

  7. #7
    Member
    Join Date
    Jul 2009
    Posts
    19

    Default

    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 06:39 AM.

  8. #8
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    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.

  9. #9
    Member
    Join Date
    Jul 2009
    Posts
    19

    Default

    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

  10. #10
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    Taking a quick glance, it's an interesting alternative implementation .

Similar Threads & Tags
Similar threads

  1. cpanel api from WHM
    By broncha in forum cPanel Developers
    Replies: 13
    Last Post: 07-20-2009, 03:59 PM
  2. cPanel/WHM API?
    By hb-travisbell in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 11-26-2006, 05:42 PM
  3. cPanel / WHM API for PHP5
    By Spiral in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 10-18-2006, 01:54 PM
  4. cPanel/WHM API help
    By webadpro in forum cPanel and WHM Discussions
    Replies: 5
    Last Post: 03-02-2006, 02:18 PM
  5. Cpanel/Whm API
    By farshad_s3 in forum cPanel and WHM Discussions
    Replies: 17
    Last Post: 09-17-2004, 12:14 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube