The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WHM / cPanel API

Discussion in 'cPanel Developers' started by paulipv, Jul 7, 2009.

  1. paulipv

    paulipv Member

    Joined:
    Jul 2, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    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. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    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. paulipv

    paulipv Member

    Joined:
    Jul 2, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    Yes David,
    Is based on XML-API and we are using API1 and API2.
     
  4. paulipv

    paulipv Member

    Joined:
    Jul 2, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    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. paulipv

    paulipv Member

    Joined:
    Jul 2, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    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. paulipv

    paulipv Member

    Joined:
    Jul 2, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    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:
        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. paulipv

    paulipv Member

    Joined:
    Jul 2, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    Array result for account creation.

    PHP:
    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>
     
    #7 paulipv, Jul 8, 2009
    Last edited: Jul 8, 2009
  8. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Sounds great! Let us know if you need anything.
     
  9. paulipv

    paulipv Member

    Joined:
    Jul 2, 2009
    Messages:
    19
    Likes Received:
    0
    Trophy Points:
    1
    David,
    This is the XML/Array result generated by our class for account domain modification.

    How looks to you?
    PHP:
    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:
     <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. cPanelDavidG

    cPanelDavidG Technical Product Specialist

    Joined:
    Nov 29, 2006
    Messages:
    11,279
    Likes Received:
    8
    Trophy Points:
    38
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Taking a quick glance, it's an interesting alternative implementation :).
     
Loading...

Share This Page