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.

Basic Questions about cPanel Features

Discussion in 'cPanel Developers' started by ManXP, Apr 22, 2009.

  1. ManXP

    ManXP Well-Known Member

    Joined:
    Feb 3, 2005
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    I just started looking at cPanel API and have some questions...


    I'm planning to use PHP to write a script which will:

    1. Upload files to user account and chmod some files (it will be done via curl, so I guess cPanel API is not needed here).

    2. Create new MySQL database/username and add username to database with all permissions

    3. Setup new cronjob for user.


    Question: Can I do it without having access to WHM (and WITHOUT remote access key)? I want person to provide his cPanel login URL/username/password and everything should be done automatically. Is it possible?


    I'm asking this, because I plan to host this script on MY server, and user should be able to use script uploading files/creating databases/adding cronjobs on cPanel accounts hosted on DIFFERENT servers.
     
    #1 ManXP, Apr 22, 2009
    Last edited: Apr 22, 2009
  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
    Yes, you can use the XML API while logged in as the individual cPanel user. They just wont have the ability to use hash authentication in place of password authentication. Just use port 2082 instead of 2086 (or 2083 instead of 2087 if you're using SSL) for your XML API calls.

    You may find it easier to upload the files and chmod them via FTP than using our APIs.

    Here's the API functions for manipulating MySQL databases and users:

    Raw API1 code for adding a MySQL database:
    Code:
    <cpanel Mysql="adddb($FORM{'db'})">
    Raw API1 code for removing a MySQL database:
    Code:
    <cpanel Mysql="deldb($FORM{'db'})">
    Raw API1 code for creating a MySQL user:
    Code:
    cpanel Mysql="adduser($FORM{'user'},$FORM{'pass'})">
    Raw API1 code for deleting a MySQL user:
    Code:
    <cpanel Mysql="deluser($FORM{'user'})">
    Raw API1 code for adding a MySQL user to a MySQL Database with Permissions:
    Code:
    <cpanel Mysql="adduserdb($FORM{'db'},$FORM{'user'},$FORM{'ALTER'} $FORM{'CREATEROUTINE'} $FORM{'CREATETEMPORARYTABLES'} $FORM{'CREATE'} $FORM{'DELETE'} $FORM{'DROP'} $FORM{'SELECT'} $FORM{'INSERT'} $FORM{'UPDATE'} $FORM{'REFERENCES'} $FORM{'INDEX'} $FORM{'LOCKTABLES'} $FORM{'ALL'})"> 
    Edit a database user by re-adding an existing user.

    A method of creating cron jobs is not available via the APIs at this time. There's some more information on this specific topic at: http://forums.cpanel.net/showthread.php?t=103661

    Information on how to call these APIs via the XML API is available at:

    http://twiki.cpanel.net/twiki/bin/view/AllDocumentation/AutomationIntegration/CallingAPIFunctions

    Or if you prefer to use a pre-assembled PHP class, I recommend using Matt's PHP 5 class for the XML API posted at: http://forums.cpanel.net/showthread.php?p=504913
     
  3. ManXP

    ManXP Well-Known Member

    Joined:
    Feb 3, 2005
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    6
    Thanks so much. I'll start playing on this tomorrow...
     
Loading...

Share This Page