Giter VIP home page Giter VIP logo

cpanel-uapi-php-class's Introduction

cPanel UAPI and API2 PHP class

GitHub release

PHP class to provide an easy-to-use interface with cPanel's UAPI and API2. Uses PHP magic functions to provide a simple and powerful interface.

v2.0 is not backwards compatible with v1.x, and will likley undergo a few more changes. See the changelog for details. The class has been renamed to cpanelAPI. Some more testing is required.

  • Note while this class is not depricated, there is a new Agnostic API class available which will do everything this class does (except 2FA) and works with any RESTful / HTTP API - basically anything thats not SOAP. https://github.com/N1ghteyes/apicore

Usage

If you choose to use this class, please Star it in Github. This gives me a better idea of the number of users and those effected when changes are made.

See the example files, but typical usage takes the form of:

Instantiate the class

$cPanel = new cpanelAPI('user', 'password', 'cpanel.example.com');

The API we want to use and the Module (also called Scope) are now protected and are set by __get().

The request layout looks like this: $cPanel->api->method->Module->request(args[])

The ->method part should be replaced with ->get for GET requests and ->post for POST requests, or omitted to default to GET requests.

As an example, suppose we want to use the UAPI to call the Mysql::get_server_information function:

$response = $cPanel->uapi->Mysql->get_server_information();
var_dump($response);

Now that we have set both the API and the Module, we can call other functions within this API and Module without specifying them again:

$response = $cPanel->create_database(['name' => $cPanel->user.'_MyDatabase']);
var_dump($response);

We can also change the Module scope without respecifying the API. Note that the Module call is case-sensitive.

$response = $cPanel->SSL->list_certs();

File upload example

$cPanel = new cpanelAPI($username, $password, $hostname);
$cPanel->uapi->post->Fileman
       ->upload_files(['dir' => REMOTE_PATH_RELATIVE_TO_HOME,
                       'file-1' => new CURLFile(LOCAL_PATH_TO_FILE)
                       ]);

API2

API2 is used in exactly the same way as the UAPI

$cPanel = new cpanelAPI('user', 'password', 'cpanel.example.com');

For example, suppose we want to use the API2 to add a subdomain:

$response = $cPanel->api2->SubDomain->addsubdomain(['rootdomain' => 'domain.com', 'domain' => 'sub']);
var_dump($response);

Two-Factor Authentication

To use this class on a cPanel instance with two-factor authentication (2FA), you need to pass the secret into the class constructor:

$cPanel = new cpanelAPI('user', 'password', 'cpanel.example.com', 'secret');

The secret can be found on the 2FA setup page. See Two-Factor Authentication for cPanel โ€“ Configure two-factor authentication for details.

cpanel-uapi-php-class's People

Contributors

n1ghteyes avatar marcuspmd avatar deltik avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.