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.

Full doc on XML-API?

Discussion in 'cPanel Developers' started by mstuebner, Aug 1, 2007.

  1. mstuebner

    mstuebner Well-Known Member

    Joined:
    May 13, 2007
    Messages:
    50
    Likes Received:
    0
    Trophy Points:
    6
    Hello all,

    yesterday I made some progress writing my hooks with postwwwacct, but only shortly...

    After creating the account I would like to continue to create a mysql db, using username and pwd of the acount. Shouldn't be a big deal, but documentation (http://www.cpanel.net/plugins/api2/index.html) doesn't shown any function to create mysql database.

    So, David: How is it with your loved XML-API? Is the doc far from beeing complete, or does the XML-way not allow such basic tasks?
     
  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
    Don't worry, I'm constantly nagging the documentation folks for better documentation since some of the most useful functions of the APIs remain undocumented.
     
  3. mstuebner

    mstuebner Well-Known Member

    Joined:
    May 13, 2007
    Messages:
    50
    Likes Received:
    0
    Trophy Points:
    6
    What does that mean in question of shedule? Could you push a complete list of functions and parameters as a list? The resturn data I can read myself until the documentation is there.

    But actually I cannot do anything.

    So does that mean that functions to handle mysql extist? I have an urgent need on how to call them. Can you help out?
     
  4. mstuebner

    mstuebner Well-Known Member

    Joined:
    May 13, 2007
    Messages:
    50
    Likes Received:
    0
    Trophy Points:
    6
    Let me push this one again...

    I would like to use the XML-API, but how if not documented. Any hint how to get this information out of the given scripts?
     
  5. 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
    XML API documentation has been available at http://www.cpanel.net/plugins/xmlapi/index.html for some time now.
     
  6. mstuebner

    mstuebner Well-Known Member

    Joined:
    May 13, 2007
    Messages:
    50
    Likes Received:
    0
    Trophy Points:
    6
    Maybe you re-read the thread, including your former post? Or would you pls. show me the function call to create a Mysql db with those functions? Youself agreed to that this information is still missing.
     
  7. dom974

    dom974 Active Member

    Joined:
    Jun 24, 2007
    Messages:
    41
    Likes Received:
    0
    Trophy Points:
    6
    it's described in the xml-api doc page.

    you access the function by visiting an url like this :

    http://user:pass@host:2086/xml-api/function?parameter1=&paramerer2=

    you get an xml stream that you can use for example with the file open functions of php.

    Dominique
     
  8. webdes03

    webdes03 Member

    Joined:
    Nov 24, 2004
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    I've found the MySQL functions...

    They're actually not on the XMLAPI docs, but in the cPanel API2 docs (http://www.cpanel.net/plugins/api2/index.html)

    But that said, I do not see how to create a db or a user, only how to pull a list of current ones...
     
  9. mstuebner

    mstuebner Well-Known Member

    Joined:
    May 13, 2007
    Messages:
    50
    Likes Received:
    0
    Trophy Points:
    6
    Thanx for that statement, otherwise I was close to think I would be blind....
     
  10. TheIdeaMan

    TheIdeaMan Member

    Joined:
    Apr 25, 2005
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    MySQL XML API access info

    This thread has information on where to find API information for yet undocumented functions (like creating databases, db users, and adding privileges).

    Basically, you open the x3 theme and dig through the files. Most of the functions in there are implemented via the XML API 1 scheme.

    To save you some time, here are the few XML requests you need:

    add database user
    Code:
    <cpanelaction>
      <module>Mysql</module>
      <func>adduser</func>
      <apiversion>1</apiversion>
      <args>{database_user}</args>
      <args>{password}</args>
    </cpanelaction>
    add database
    Code:
    <cpanelaction>
      <module>Mysql</module>
      <func>adddb</func>
      <apiversion>1</apiversion>
      <args>{database}</args>
    </cpanelaction>
    grant privileges to user for database
    Code:
    <cpanelaction>
      <module>Mysql</module>
      <func>adduserdb</func>
      <apiversion>1</apiversion>
      <args>{cpanel_user}_{database}</args>
      <args>{cpanel_user}_{database_user}</args>
      <args>ALL</args>
    </cpanelaction>
    Note: The above code presents granting "ALL" privileges on a database. To grant specific privileges, use several <args></args> each containing the specific privilege to add. Privilege options (for MySQL 5) are: ALTER, CREATEROUTINE, CREATETEMPORARYTABLES, CREATE, DELETE, DROP, SELECT, INSERT, UPDATE, REFERENCES, INDEX, LOCKTABLES, ALL​

    Hope that helps.
     
  11. neo4242002

    neo4242002 Well-Known Member

    Joined:
    Jun 28, 2005
    Messages:
    119
    Likes Received:
    0
    Trophy Points:
    16
    Hi TheIdeaMan, Great stuffs.

    However would you mind sharing the full code? I know its XML. But How do I call it from server? do I have to pass these XML data to specific function or URL? and how it be look like?

    Thanks in advance
     
  12. brianoz

    brianoz Well-Known Member

    Joined:
    Mar 13, 2004
    Messages:
    1,146
    Likes Received:
    6
    Trophy Points:
    38
    Location:
    Melbourne, Australia
    cPanel Access Level:
    Root Administrator
    If you're doing this from within postwwwacct, it's probably easier and quicker to do it using the mysql command:

    Code:
    ME=${0##*/}
    fatal() { echo "$ME: $*" 1>&2 ; exit 1 ; }
    # ...
    
    passcode=$(grep pass= /root/.my.cnf)
    eval $passcode
    [ "$pass" = "" ] && fatal abort - no mysql password from /root/.my.cnf
    
    dbpass=$(dd 2>/dev/null if=/dev/random count=2 | od -d |head -1 | sed -e s/^........// -e 's/ //g' | cut -c1-8)
    [ "$dbpass" = "" ] && fatal could not work out a password
    
    DB=${USER}_sope1
    
    mysql -u root -p$pass <<!
    create database ${DB};
    grant all privileges on ${DB}.* to ${DB}@localhost
    identified by '$dbpass' with grant option;
    !
    
    
    The "$dbpass" variable contains the database password used, which should for security's sake NOT be the same as the cpanel password.

    The "$DB" variable is the database name used, which must be prefixed by the username. "$USER" is the username of the target user and can be set from cp_user.

    This is a fragment of working code I've got working from a much larger script; anything broken is because I had to extract the fragment...
     
  13. TheIdeaMan

    TheIdeaMan Member

    Joined:
    Apr 25, 2005
    Messages:
    9
    Likes Received:
    0
    Trophy Points:
    1
    neo4242002,

    You can find information on how to use cPanel functions via the XML API described on the cPanel XMLAPI page.

    brianoz,

    That's some seriously frightening code! ;) Personally, I'd stick with using API's as their less volatile (or should be) and certainly more readable. :) For myself, I write my postwwwacct script in PHP, so your code wouldn't work for me.
     
Loading...

Share This Page