Basic Questions about cPanel Features

ManXP

Well-Known Member
Feb 3, 2005
62
0
156
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.
 
Last edited:

cPanelDavidG

Technical Product Specialist
Nov 29, 2006
11,216
13
313
Houston, TX
cPanel Access Level
Root Administrator
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.
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