Accessing the API with PHP

Requirements

WSAccess class

The WSAccess class allows you to establish a connection with the Cube Panel in order to obtain other user's credentials. The definitions of the class constructor are as follows:

WSAccess(user_name, password, host, port, id_language)

The user assigned as the constructor of the function is who shall determine the applicable maximum privileges in using the WebServices. If the user is "admin", it may access any WebService of any client or domain. If user is a client, it may only act within its client services and domains.

Obtaining credentials

Before using any WebServices, the user needs to obtain user credentials with which it will access the WebServices. For this, the WSAccess class uses the getUser method that receives a request from a WSUser, which is necessary to use the WebServices. The function has the following definitions:

WSUser getUser(effective_user)

The effective_user parameter corresponds to the username of whoever is interested in the access.

Using WebServices

With WSUser any WebService can be accessed with the execute method:

mixed execute(method_name, params)

Example of using WebServices

The following example demonstrates how to access the WebServices as administrator or as client:

                

                // Init access object

                $access = new WSAccess('admin', 'admin_pass', 'server', 25112);                

                // Get admin user

                $admin_user = $access->getUser('admin');

                // Get one client user

                $client_user = $access->getUser('client1');

                // Get one domain user

                $domain_user = $access->getUser('domain-cubews.com');

                // Get server client list

                $clients_list = $admin_user->execute('ADMINCLIENTS_getClients',array());

                // Get server domain list

                $domains_list = $client_user->execute('DOMAINS_getDomains',array());

                // Get ftp accounts of domain-cubews.com

                $ftp_accounts = $domain_user->execute('FTP_listUsers',array());