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.

Use API1 and API2

Discussion in 'General Discussion' started by rongup, Dec 30, 2008.

  1. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    I am a newbie,
    I read the Interested? - HOW TO: Create your own remote access features in PHP

    I understood the thing
    But now in 11.24 its mentioned that cPanel::Accounting PHP Module is deprecated and XML API is In
    I know the XML commands also by now!

    But I am confused on the following for Plugins:
    1) Should the Plugin we create be in http://WHM/frontend/x3/myplugin
    (I saw this in ROR, fantastico) or in the 3rdparty folder
    2) How to call XML API in the PHP Plugin sript ?
    - using the Web like file_get_contents()
    - OR fsockopen

    I want to make a plugin like ROR, Fantastico - I mean the way they operate in the end user CPanel.

    Please help
     
  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
    You're crossing a lot of different territory there in the post.

    Are you looking to create a plug-in? A plug-in is something like Fantastico where it is accessed via the cPanel interface. If so, then you likely will not be using the XML-API. The XML-API is designed for external scripts (e.g. billing applications) to interact with cPanel's APIs. If you are building a plug-in, your script will be running on cpsrvd, thus will not need XML-API wrappers to access API1/API2 functionality. You would simply use API1/API2 directly or use our LivePHP wrapper.
     
  3. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Thanks for clearing those confusions
    Also can you just tell me what is LivePHP wrapper and how can I access / use API1/API2 directly

    AND my files will be placed in :
    usr/local/cpanel/whostmgr/docroot/cgi/
    OR
    frontend/x3/

    Is there some detailed guide about how to make a Pluging like Fantastico or ROR
     
  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
    Just to be clear, Ruby on Rails is native functionality of cPanel/WHM - it is not a plug-in.

    There's a crash course on all of our APIs as well as LivePHP in the following presentation:

    http://www.cpanel.net/conference/08/files/APIs.pdf

    The cPanel Plugin will be stored in:

    /usr/local/cpanel/base/frontend/$themename/$somedir

    Where $themename is the name of a theme (e.g. x3) and $somedir is some directory where you're placing your plugin file(s).

    As for making a WHM plug-in, some documentation for that can be found at:

    http://www.cpanel.net/support/docs/modules/index.html
     
  5. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Thanks a million
    Just to clear my last doubts
    1) Why is Fantastico stored in /usr/local/cpanel/whostmgr/docroot/cgi(thats what i saw in its files)
    2) If the plugin is in /usr/local/cpanel/base/frontend/$themename/$somedir then what about other themes in CPanel
    Will the plugin be available then ?
    3) Cant modules be created in PHP. The above docs are for Perl Modules. But Fantastico is in PHP with just installation addon_fantastico.cgi in PERL Language !
     
    #5 rongup, Dec 30, 2008
    Last edited: Dec 30, 2008
  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
    1. I assume that would be the WHM Plug-in component of Fantastico.

    2. The plug-in installer will install an icon for your plug-in to all themes that support plug-ins, which is essentially all of them except xmail and x3mail. You could symlink or copy the plug-in directory contents for all themes in /usr/local/cpanel/base/frontend if you desire.
     
  7. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    3) Cant modules be created in PHP. The above docs are for Perl Modules. But Fantastico is in PHP with just installation addon_fantastico.cgi in PERL Language !
     
  8. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Ok, So let me just clear up what I want:
    1) I want to design a plugin that will be installable by any host and will be finally available to the End User
    2) I want to make it in PHP
    3) With PHP I want to get the END USER domains, Mysql info. I meant is that when the END USER Interacts with the PLUGIN, the PLUGIN needs the END USER domains info, Mysql info etc


    I hope I am clear enogh this time!;)

    I thought Fantastico and ROR are like this
    PLease help me by giving any tutorials and resources!
     
    #8 rongup, Dec 31, 2008
    Last edited: Dec 31, 2008
  9. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,458
    Likes Received:
    22
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    For that you will want to use one of our PHP Modules, which themselves are simple wrappers around calls to one of our APIs.
     
  10. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Any guides for that!

    Also for the third point I meant is that when the END USER Interacts with the PLUGIN the PLUGIN needs the END USER domains, Mysql info etc

    I will edit the 3rd point!
     
    #10 rongup, Dec 31, 2008
    Last edited: Dec 31, 2008
  11. cPanelKenneth

    cPanelKenneth cPanel Development
    Staff Member

    Joined:
    Apr 7, 2006
    Messages:
    4,458
    Likes Received:
    22
    Trophy Points:
    38
    cPanel Access Level:
    Root Administrator
    The modules themselves are in /usr/local/cpanel/Cpanel

    Other than that, there is the documentation DavidG posted earlier.
     
  12. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    But the guides are in Perl and nothing in PHP
     
  13. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Please help me!
     
  14. 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'm not familiar with building a WHM plug-in in PHP, but information such as the end user's domain and the ability to create MySQL users is available via API1/API2. You can view the source code for the x3 theme to become familiar with these APIs. The code is located at /usr/local/cpanel/base/frontend/x3. The x3 theme is essentially some HTML, CSS, Javascript, YUI (Javascript handling the AJAX) and some API1/API2 calls. If you need help finding a specific API call, let me know.
     
  15. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Ok i got this file test.php and it had these functions:
    <cpanel PHP="loadvars()">
    <cpanel PHP="loadparkeddomains()">
    <cpanel PHP="loadsubdomains()">
    <cpanel PHP="loaddocroots()">

    What other functions exist ?
    I want MySQL info so that I can connect to MySQL

    Also will a PHP script be allowed to open external files !
    like http://ext-url.com/file.zip

    I want to store that file in the frontend/x3/myplugin/
     
  16. 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 am not aware of any way of retrieving MySQL information for existing accounts. Typically applications will create the MySQL accounts themselves and keep track of the chosen username/passwords for whatever configuration needs to be done for scripts.

    As the PHP will be executing as root, you will be able to access external files as well as store files in frontend/x3/myplugin/

    Regarding API1/API2 functions that exist (which would typically be within <cpanel ... > tags), there are very many functions. Take a peak at the source code of the x3 theme for inspiration. If you're looking for a specific API function, please let me know.
     
  17. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Yes I am looking for some API functions:
    1) Retrieve MySQL info and
    2) Creation of MySQL Databases

    I mean creation will be allowed if its a root script or will it not be allowed ?
     
  18. 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
    PHP executes as root for WHM Plug-ins.

    If you are incorporating the creation of MySQL databases into a cPanel Plug-in (or a script that uses the XML API), you can use the following API call:

    Code:
    <cpanel Mysql="adddb(DBName)">
    Where DBName is the name of your database.


    To create a database user, you can use this API call:

    Code:
    <cpanel Mysql="adduser(user,pass)">
    To grant a database user access to a database, you would use the following API call:

    Code:
    <cpanel Mysql="adduserdb(db,user,ALTER, CREATEROUTINE, CREATETEMPORARYTABLES, CREATE, DELETE, DROP, SELECT, INSERT, UPDATE, REFERENCES, INDEX, LOCKTABLES, ALL)">
    db = the database

    user = the database user to grant access to this database

    The upper-case parameters refer to individual permissions to apply, ALL representing all permissions.
     
  19. rongup

    rongup Active Member

    Joined:
    Dec 29, 2008
    Messages:
    31
    Likes Received:
    0
    Trophy Points:
    6
    Thanks thats really awesome
    But I will have to check whether the user has not crossed the DB limit with MAXSQL right

    Also I wanted to know how should i store a file in the USERS account
    X3 is a theme and I wanted to store a file in /home/user/.userplugindata

    I know i have harassed you a lot!
     
  20. 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 may be prudent to catch all errors rather than just that possibility. You can do that by reading the contents of <result>...</result> in the XML that is returned. Details of this are in the documentation at:

    http://cpanel.net/plugins/xmlapi/cpanel.html

    That's not something that is handled via the APIs. Typically, one would have a script running with root privileges handling the storing of files into user accounts, being sure to set ownership and permissions as needed.
     
Loading...

Share This Page