Bobcares

For every $500 you spend, we will provide you with a $500 credit on your account*

BLACK FRIDAY SPECIAL EXTENSION

*The maximum is $4000 in credits, Offer valid till December 6th, 2024, New Customers Only, Credit will be applied after purchase and expires after six (6) months

For every $500 you spend, we will provide you with a $500 credit on your account*

BLACK FRIDAY SPECIAL EXTENSION

*The maximum is $4000 in credits, Offer valid till December 6th, 2024, New Customers Only, Credit will be applied after purchase and expires after six (6) months

How to use cPanel APIs to automate tasks

by | Jul 12, 2012

Through your code in languages such as PHP and Perl, you can access cPanel’s APIs to integrate billing solutions and applications, mass deploy and automate installations, and administer your client licenses.

Numerous developers have successfully integrated their applications with cPanel & WHM. From Auto­Installers to Security Tools, there is a way for your application to integrate seamlessly with the features of cPanel & WHM.

 

Hire Bobcares cPanel Server Administrators
Get super reliable servers and delighted customers

See how we do it!

 

 

Why Integrate Your Application With cPanel & WHM?


1.Integrate Billing and Support Software

Whether you’re developing or integrating a custom or commercial billing platform, by using the APIs, you have access to all of the account functions in WHM, including adding and removing accounts, setting up email piping for support, generating SSL signing requests, installing certificates, plus much more, all without logging in through WHM or cPanel.
Since the APIs on your cPanel & WHM server can also be accessed remotely, your software can be installed locally on the server or interact remotely to perform your necessary accounting and support functions, making the ability to serve your customers’ needs more centralized and streamlined.

2. Administrate Licenses With Manage2 Billing API

The Manage2 billing API, available exclusively to partners, is an easy way to maintain your cPanel licenses. Using the Manage2 API, you can perform maintenance tasks such as automatic provisioning and deprovisioning of licenses as servers are provisioned and deprovisioned, change license’s IP addresses, list license information, and more.

3.Daily Automation

One of the key features to cPanel & WHM is the use of hooks to automate daily tasks. Using the hooks system, you can automate the creation of various items within your server, such as MySQL
databases, user accounts, and more.

Example: cPanel::PublicAPI Perl module.

This is a set of perl modules that allows for easy access into cPanel’s APIs from a simple object interface. This module offers several great features:
* Auto­detection of credentials (when available)
* Support for cPanel’s DNS Clustering API
* Support for: cPanel, WHM, webmail and non­cPanel services.
* Minimal dependencies
* BSD Licensed

 

 

Installation

Installation of the module can be done via the cpan program.
For example:

 

# cpanp install cPanel::PublicAPI

 

 

Usage

This short example shows how to retrieve a list of users from a remote server using a simple 20 line Perl code. It assumes you have the remote server’s access hash stored locally.

 

01 #!/usr/bin/env perl
02 use warnings;
03 use strict;
04 use 5.010;
05 use cPanel::PublicAPI;
06
07 my $ah = `cat /path/to/server.accesshash`;
08
09 my $cp = cPanel::PublicAPI­->new(
10 user => ‘root’,
11 host => ‘server’,
12 accesshash => $ah,
13 );
14
15 my $users = $cp-­>whm_api(‘listaccts’);
16
17 for my $user ( @{ $users­->{acct} } ) {
18 say $user-­>{user};
19 }


As you can see, API access can now be complete in as little as two lines of code: server authentication and API call.

 

Conclusion

If you maintain more than one cPanel server, the cPanel API is an invaluable resource for centralized management. The new cPanel Perl module greatly simplifies API­based Perl scripts.

 

WHM Integration

To integrate with WHM, you will have to write a CGI plugin script that contains a few special comments that control how the plugin is displayed in the WHM interface. With this CGI application, you can redirect users to an external source or an internal source written in Perl/PHP.

 

 

The above is a very rough outline of the cPanel APIs , if you have any questions, we would be happy to talk to you! 🙂


About the Author :

Abhilash MB works as a Software Engineer in Bobcares. He joined Bobcares in June 2011. He loves reading books and listening to music in his free time.



Blog edited by :

Appu Joseph Xavier works as a Software Engineer in Bobcares. He joined Bobcares in April 2012. He loves to watch movies in his free time.


 

 

 

 

0 Comments

Never again lose customers to poor
server speed! Let us help you.