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.

Beginner's Question

Discussion in 'cPanel Developers' started by Ricardo-san, Apr 7, 2009.

  1. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Hi all,
    I'm currently developing an external cPanel plugin using the API that will allow my staff to create accounts.
    Anyway, I'm just wondering how I would login as a reseller?
    I downloaded the API zip, and if I put:
    PHP:
    $alpha_pass "alpha";
    Alpha as username, and alpha as password. Would it work? Or must it be root?
     
  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
    Are you referring to the code we have posted at: http://forums.cpanel.net/showthread.php?t=111897 or something that is not from cPanel directly?

    I know there's an outdated third party zip archive of code that calls itself "cPanel API" that is not related to our APIs, hence my question.
     
  3. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Hi David, thanks for your reply.
    Right now, I am using Matt's XML API that you linked. I'm just wondering how can I output the rawout data?
    When I execute createaccount_example.php, I get a whole block of XML. Is there any way I can just display what's in <rawout> with XHTML?
     
  4. 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
    Actually, the function returns a XML object by means of calling simplexml_load_string on the raw XML.

    If you are familiar with associative arrays in PHP, you will find this much easier to use than trying to parse the XML manually. You can find some related PHP documentation for this at: http://php.net/simplexml_load_string
     
  5. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Any idea why this code doesn't work?
    Code:
    <?php
    # cpanel12 - createacct_example.php                Copyright(c) 1997-2009 cPanel, Inc.
    #                                                           All Rights Reserved.
    # copyright@cpanel.net                                         http://cpanel.net
    
    include("xmlapi.php.inc");
    
    $ip = "127.0.0.1";
    $reseller_pass = "***********";
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("reseller",$reseller_pass);
    
    $xmlapi->set_debug(1);
    
    $acct = array( username => "someuser", password => "pass123", domain => "thisdomain.com");
    print $xmlapi->createacct($acct);
    
    $rawout = simplexml_load_string(1636);
    print $rawout;
    ?>
    EDIT: This is what the XML output looks like.
    Code:
    
    QUERY:
    https://127.0.0.1:2087/xml-api/createacct?username=someuser&password=pass123&domain=thisdomain.com
    
    RAW XML:
    
    <createacct>
      <result>
        <options>
          <ip>174.132.240.50</ip>
          <nameserver>ns1.kh3.us</nameserver>
          <nameserver2>ns2.kh3.us</nameserver2>
          <nameserver3></nameserver3>
          <nameserver4></nameserver4>
          <nameservera></nameservera>
          <nameservera2></nameservera2>
          <nameservera3></nameservera3>
          <nameservera4></nameservera4>
          <nameserverentry></nameserverentry>
          <nameserverentry2></nameserverentry2>
          <nameserverentry3></nameserverentry3>
          <nameserverentry4></nameserverentry4>
          <package>default</package>
        </options>
        <rawout>Checking input data...System has 0 free ips.
    ...DoneWWWAcct 12.1.0 (c) 1997-2008 cPanel, Inc....
    
    Dns Zone check is enabled.
    +===================================+
    | New Account Info                  |
    +===================================+
    | Domain: thisdomain.com
    | Ip: 174.132.240.50 (n)
    | HasCgi: y
    | UserName: someuser
    | PassWord: pass123
    | CpanelMod: x3
    | HomeRoot: /home
    | Quota: 0 Meg
    | NameServer1: ns1.xxx.xx
    | NameServer2: ns2.xxx.xx
    | NameServer3: 
    | NameServer4: 
    | Contact Email: 
    | Package: default
    | Feature List: default
    | Language: english
    +===================================+
    ...DoneRunning pre creation script (/scripts/prewwwacct)......DoneAdding User...Removing Shell Access (n)
    ...DoneCopying skel files from /home/kh3us/cpanel3-skel/ to /home/someuser/......DoneAdding Entries to httpd.conf......DoneSetting up Mail &amp; Local Domains...localdomains...valiases ...vdomainaliases...vfilters......DoneConfiguring DNS......DoneRestarting apache......DoneChanging password for someuser
    Password for someuser has been changed
    Updating Authentication Databases...Updating ftp passwords for someuser
    Ftp password files updated.
    Ftp vhost passwords synced
    ...DoneVerifying MX Records and Setting up Databases......DoneSetting up Proxy Subdomains......DoneBind reconfiguring on sapphire using rndc
    Sending Account Information......DoneSystem has 0 free ips.
    Running post creation scripts (/scripts/legacypostwwwacct, /scripts/postwwwacct, /scripts/postwwwacctuser)......Donewwwacct creation finished
    Setting up Domain Pointers......DoneSetting Reseller Privs......DoneAccount Creation Complete!!!...Account Creation Ok...Done</rawout>
        <status>1</status>
        <statusmsg>Account Creation Ok</statusmsg>
      </result>
    </createacct>
    
    <!-- Web Host Manager  (c) cPanel, Inc. 2008 http://cpanel.net/  Unauthorized copying is prohibited. -->
    
    
    object(SimpleXMLElement)#2 (1) {
      ["result"]=>
      object(SimpleXMLElement)#3 (4) {
        ["options"]=>
        object(SimpleXMLElement)#4 (14) {
          ["ip"]=>
          string(14) "174.132.240.50"
          ["nameserver"]=>
          string(10) "ns1.kh3.us"
          ["nameserver2"]=>
          string(10) "ns2.kh3.us"
          ["nameserver3"]=>
          object(SimpleXMLElement)#5 (0) {
          }
          ["nameserver4"]=>
          object(SimpleXMLElement)#6 (0) {
          }
          ["nameservera"]=>
          object(SimpleXMLElement)#7 (0) {
          }
          ["nameservera2"]=>
          object(SimpleXMLElement)#8 (0) {
          }
          ["nameservera3"]=>
          object(SimpleXMLElement)#9 (0) {
          }
          ["nameservera4"]=>
          object(SimpleXMLElement)#10 (0) {
          }
          ["nameserverentry"]=>
          object(SimpleXMLElement)#11 (0) {
          }
          ["nameserverentry2"]=>
          object(SimpleXMLElement)#12 (0) {
          }
          ["nameserverentry3"]=>
          object(SimpleXMLElement)#13 (0) {
          }
          ["nameserverentry4"]=>
          object(SimpleXMLElement)#14 (0) {
          }
          ["package"]=>
          string(7) "default"
        }
        ["rawout"]=>
        string(1636) "Checking input data...System has 0 free ips.
    ...DoneWWWAcct 12.1.0 (c) 1997-2008 cPanel, Inc....
    
    Dns Zone check is enabled.
    +===================================+
    | New Account Info                  |
    +===================================+
    | Domain: thisdomain.com
    | Ip: 174.132.240.50 (n)
    | HasCgi: y
    | UserName: someuser
    | PassWord: pass123
    | CpanelMod: x3
    | HomeRoot: /home
    | Quota: 0 Meg
    | NameServer1: ns1.xxx.xx
    | NameServer2: ns2.xxx.xx
    | NameServer3: 
    | NameServer4: 
    | Contact Email: 
    | Package: default
    | Feature List: default
    | Language: english
    +===================================+
    ...DoneRunning pre creation script (/scripts/prewwwacct)......DoneAdding User...Removing Shell Access (n)
    ...DoneCopying skel files from /home/kh3us/cpanel3-skel/ to /home/someuser/......DoneAdding Entries to httpd.conf......DoneSetting up Mail & Local Domains...localdomains...valiases ...vdomainaliases...vfilters......DoneConfiguring DNS......DoneRestarting apache......DoneChanging password for someuser
    Password for someuser has been changed
    Updating Authentication Databases...Updating ftp passwords for someuser
    Ftp password files updated.
    Ftp vhost passwords synced
    ...DoneVerifying MX Records and Setting up Databases......DoneSetting up Proxy Subdomains......DoneBind reconfiguring on sapphire using rndc
    Sending Account Information......DoneSystem has 0 free ips.
    Running post creation scripts (/scripts/legacypostwwwacct, /scripts/postwwwacct, /scripts/postwwwacctuser)......Donewwwacct creation finished
    Setting up Domain Pointers......DoneSetting Reseller Privs......DoneAccount Creation Complete!!!...Account Creation Ok...Done"
        ["status"]=>
        string(1) "1"
        ["statusmsg"]=>
        string(19) "Account Creation Ok"
      }
    }
    SIMPLEXML OBJ:
    
    
    
      
    <br />
    <b>Warning</b>:  simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: Entity: line 1: parser error : Start tag expected, '&lt;' not found in <b>/home/kh3us/public_html/testing/cpanel/createacct_example.php</b> on line <b>19</b><br />
    <br />
    <b>Warning</b>:  simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: 1636 in <b>/home/kh3us/public_html/testing/cpanel/createacct_example.php</b> on line <b>19</b><br />
    <br />
    <b>Warning</b>:  simplexml_load_string() [<a href='function.simplexml-load-string'>function.simplexml-load-string</a>]: ^ in <b>/home/kh3us/public_html/testing/cpanel/createacct_example.php</b> on line <b>19</b><br />
     
    #5 Ricardo-san, Apr 8, 2009
    Last edited: Apr 8, 2009
  6. 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
    It seems your problematic code is:

    PHP:
    $rawout simplexml_load_string(1636);
    print 
    $rawout;
    You can only use simplexml_load_string on a string that is formatted in XML. It cannot be used on numbers.
     
  7. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Ok. I worked that one out.
    PHP:
    <?php
    # cpanel12 - createacct_example.php                Copyright(c) 1997-2009 cPanel, Inc.
    #                                                           All Rights Reserved.
    # copyright@cpanel.net                                         http://cpanel.net

    include("xmlapi.php.inc");

    $ip "127.0.0.1";
    $kh3us_pass "*********";

    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("kh3us",$kh3us_pass);

    $xmlapi->set_debug(1);

    $acct = array( username => "someuser"password => "pass123"domain => "thisdomain.com");
    print 
    $xmlapi->createacct($acct);

    print 
    $xmlobj->result->rawout;
    ?>
    Only problem is, rawout is printed twice.
    Is there any way to use XHTML with the data...currently it shows up like:
    http://img99.imageshack.us/img99/3567/picture1qgf.png
    And it's difficult to read.
     
    #7 Ricardo-san, Apr 8, 2009
    Last edited: Apr 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
    I recommend turning off debugging mode. That will curb the extraneous printing.

    Also, you may want to assign $xmlobj->result->rawout to a variable and use that associative array instead to print only the data you wish to display.
     
    #8 cPanelDavidG, Apr 8, 2009
    Last edited: Apr 8, 2009
  9. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    After disabling Debugging mode, nothing shows up again. Using this XML:
    Code:
    object(SimpleXMLElement)#2 (1) {
      ["result"]=>
      object(SimpleXMLElement)#3 (4) {
        ["options"]=>
        object(SimpleXMLElement)#4 (14) {
          ["ip"]=>
          string(14) "174.132.240.50"
          ["nameserver"]=>
          string(10) "ns1.kh3.us"
          ["nameserver2"]=>
          string(10) "ns2.kh3.us"
          ["nameserver3"]=>
          object(SimpleXMLElement)#5 (0) {
          }
          ["nameserver4"]=>
          object(SimpleXMLElement)#6 (0) {
          }
          ["nameservera"]=>
          object(SimpleXMLElement)#7 (0) {
          }
          ["nameservera2"]=>
          object(SimpleXMLElement)#8 (0) {
          }
          ["nameservera3"]=>
          object(SimpleXMLElement)#9 (0) {
          }
          ["nameservera4"]=>
          object(SimpleXMLElement)#10 (0) {
          }
          ["nameserverentry"]=>
          object(SimpleXMLElement)#11 (0) {
          }
          ["nameserverentry2"]=>
          object(SimpleXMLElement)#12 (0) {
          }
          ["nameserverentry3"]=>
          object(SimpleXMLElement)#13 (0) {
          }
          ["nameserverentry4"]=>
          object(SimpleXMLElement)#14 (0) {
          }
          ["package"]=>
          string(7) "default"
        }
        ["rawout"]=>
        string(1636) "Checking input data...System has 0 free ips.
    ...DoneWWWAcct 12.1.0 (c) 1997-2008 cPanel, Inc....
    
    Dns Zone check is enabled.
    +===================================+
    | New Account Info                  |
    +===================================+
    | Domain: thisdomain.com
    | Ip: 174.132.240.50 (n)
    | HasCgi: y
    | UserName: someuser
    | PassWord: pass123
    | CpanelMod: x3
    | HomeRoot: /home
    | Quota: 0 Meg
    | NameServer1: ns1.kh3.us
    | NameServer2: ns2.kh3.us
    | NameServer3: 
    | NameServer4: 
    | Contact Email: 
    | Package: default
    | Feature List: default
    | Language: english
    +===================================+
    ...DoneRunning pre creation script (/scripts/prewwwacct)......DoneAdding User...Removing Shell Access (n)
    ...DoneCopying skel files from /home/kh3us/cpanel3-skel/ to /home/someuser/......DoneAdding Entries to httpd.conf......DoneSetting up Mail & Local Domains...localdomains...valiases ...vdomainaliases...vfilters......DoneConfiguring DNS......DoneRestarting apache......DoneChanging password for someuser
    Password for someuser has been changed
    Updating Authentication Databases...Updating ftp passwords for someuser
    Ftp password files updated.
    Ftp vhost passwords synced
    ...DoneVerifying MX Records and Setting up Databases......DoneSetting up Proxy Subdomains......DoneBind reconfiguring on sapphire using rndc
    Sending Account Information......DoneSystem has 0 free ips.
    Running post creation scripts (/scripts/legacypostwwwacct, /scripts/postwwwacct, /scripts/postwwwacctuser)......Donewwwacct creation finished
    Setting up Domain Pointers......DoneSetting Reseller Privs......DoneAccount Creation Complete!!!...Account Creation Ok...Done"
        ["status"]=>
    Why wouldn't this work?
    Code:
    <?php
    header('Content-Type: text/xml');
    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>";
    echo "<?xml-stylesheet type=\"text/xsl\" href=\"style.xsl\"?>";
    
    # cpanel12 - createacct_example.php                Copyright(c) 1997-2009 cPanel, Inc.
    #                                                           All Rights Reserved.
    # copyright@cpanel.net                                         http://cpanel.net
    
    include("xmlapi.php.inc");
    
    $ip = "127.0.0.1";
    $kh3us_pass = "********";
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("kh3us",$kh3us_pass);
    
    $xmlapi->set_debug(1);
    
    $acct = array( username => "someuser", password => "pass123", domain => "thisdomain.com");
    print $xmlapi->createacct($acct);
    
    print $result->rawout;
    ?>
    Still using Matt's API...
     
  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
    $rawout is a private variable, you may want to read up on variable scope in PHP for more information about that.
     
  11. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    How would I display this simpleXML object?
     
  12. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    Code:
    print $xmlapi->createacct($acct);
    print $result->rawout;
    
    needs to be

    Code:
    $result = $xmlapi->createacct($acct);
    print $result->result->rawout
    
    all of the commands in here will return either a SimpleXML object or an XML string depending on how it is configured to return based upon the return_xml value (set via $xmlapi->return_xml() )
     
  13. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Ok. That seems to work..
    This part is being outputted twice though?
    Code:
    Checking input data...System has 0 free ips.
    ...DoneWWWAcct 12.1.0 (c) 1997-2008 cPanel, Inc....
    
    Dns Zone check is enabled.
    +===================================+
    | New Account Info                  |
    +===================================+
    | Domain: thasdomain.com
    | Ip: 174.132.240.50 (n)
    | HasCgi: y
    | UserName: suser
    | PassWord: pass123
    | CpanelMod: x3
    | HomeRoot: /home
    | Quota: 0 Meg
    | NameServer1: ns1.kh3.us
    | NameServer2: ns2.kh3.us
    | NameServer3: 
    | NameServer4: 
    | Contact Email: 
    | Package: default
    | Feature List: default
    | Language: english
    +===================================+
    ...DoneRunning pre creation script (/scripts/prewwwacct)......DoneAdding User...Removing Shell Access (n)
    ...DoneCopying skel files from /home/kh3us/cpanel3-skel/ to /home/suser/......DoneAdding Entries to httpd.conf......DoneSetting up Mail & Local Domains...localdomains...valiases ...vdomainaliases...vfilters......DoneConfiguring DNS......DoneRestarting apache......DoneChanging password for suser
    Password for suser has been changed
    Updating Authentication Databases...Updating ftp passwords for suser
    Ftp password files updated.
    Ftp vhost passwords synced
    ...DoneVerifying MX Records and Setting up Databases......DoneSetting up Proxy Subdomains......DoneBind reconfiguring on sapphire using rndc
    Sending Account Information......DoneSystem has 0 free ips.
    Running post creation scripts (/scripts/legacypostwwwacct, /scripts/postwwwacct, /scripts/postwwwacctuser)......Donewwwacct creation finished
    Setting up Domain Pointers......DoneSetting Reseller Privs......DoneAccount Creation Complete!!!...Account Creation Ok...Done
    Also, how do I disable debugging mode? So QUERY and RAW XML doesn't show up...
    EDIT: Ok, after I disabled debugging mode now NOTHING shows up...absolutely blank.
    EDIT2: Thank you God. It works.
    Last thing to do...
    In my browser, it shows up like:
    http://img99.imageshack.us/img99/3567/picture1qgf.png
    But I want it to show up like it does in the source:
    http://img27.imageshack.us/img27/2354/picture2kew.png
    Thank you!
     
    #13 Ricardo-san, Apr 9, 2009
    Last edited: Apr 9, 2009
  14. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    can I see the code you are using?
     
  15. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    createacct.php
    Code:
    <?php
    # cpanel12 - createacct_example.php                Copyright(c) 1997-2009 cPanel, Inc.
    #                                                           All Rights Reserved.
    # copyright@cpanel.net                                         http://cpanel.net
    
    include("xmlapi.php.inc");
    
    $ip = "127.0.0.1";
    $kh3us_pass = "*************";
    
    $xmlapi = new xmlapi($ip);
    $xmlapi->password_auth("kh3us",$kh3us_pass);
    
    $xmlapi->set_debug(0);
    
    $acct = array( username => "sxuser", password => "pass123", domain => "thaxsdomain.com");
    $result = $xmlapi->createacct($acct);
    print $result->result->rawout
    ?>
    Then the regular xmlapi.php.inc
     
  16. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    You may want to try printing $result->result->statusmsg as well.

    This is working for me, however that variable will not be populated if the account exists for some reason, statusmsg will always exist however and may return something like:

     
  17. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    Well, I get the account info alright...
    But how would I format the output?
    It's not XML...
     
  18. MattDees

    MattDees cPanel Product Owner
    Staff Member

    Joined:
    Apr 29, 2005
    Messages:
    417
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    it returns simple xml so you just take the variables and put them where needed, if you want rawxml output, you simply set $xmlapi->return_xml(1); somewhere inside the script before the createacct call is run.
     
  19. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    I'm not sure I understand...I don't see any simpleXML output, just the content in rawout. :confused:
     
  20. Ricardo-san

    Ricardo-san Member

    Joined:
    Apr 7, 2009
    Messages:
    23
    Likes Received:
    0
    Trophy Points:
    1
    You see, when I just printed rawout there was no variable output or arrays so I couldn't format it.
    I'm kinda scrapping that idea now...is there any way to just print the username, password, plan, and domain?
    This doesn't seem to work:
    Code:
    echo $acctinfo['username'];
     
Loading...

Share This Page