Giter VIP home page Giter VIP logo

cpanel-php's Introduction

cPanel/WHM API for PHP library

Contents

Installation Guide

To install this package, you can run this code via your terminal

	composer require gufy/cpanel-php:~2.0

Or update your composer.json by adding this line

	"gufy/cpanel-php":"~2.0"

Then, run this code

	composer update

Usage

For example, if you would like to get list accounts of your whm server, you can do this.

  <?php
  $cpanel = new \Gufy\CpanelPhp\Cpanel([
      'host'        =>  'https://123.456.789.123:2087', // ip or domain complete with its protocol and port
      'username'    =>  'root', // username of your server, it usually root.
      'auth_type'   =>  'hash', // set 'hash' or 'password'
      'password'    =>  'password', // long hash or your user's password
  ]);

  $accounts = $cpanel->listaccts(); // it will returned as array

Functions

Defining Configuration on constructor

This is the example when you want to define your configuration while creating new object

  <?php
  $cpanel = new \Gufy\CpanelPhp\Cpanel([
      'host'        =>  'https://123.456.789.123:2087', // required
      'username'    =>  'root', // required
      'auth_type'   =>  'hash', // optional, default 'hash'
      'password'    =>  'password', // required
  ]);

Usage

For example, you would like to get some list accounts from cPanel/WHM

	<?php

	$accounts = $cpanel->listaccts();

	// passing parameters
	$accounts = $cpanel->listaccts(['searchtype'=>'domain', 'search'=>'', 'exact', 'search'=>'helloworld.com']);
	
	// create account (Domain Name, Username, Password, Plan Slug)
	createAccount(www.domain_name.com.br, 'user', 'pass', 'plan_basic');

For accessing cPanel API 2, you can use this.

	<?php
	// get bandwidth data of specific cPanel's user
	$data = $cpanel->cpanel('Bandwidth', 'getbwdata', 'username');

	// removing cron line
	$data = $cpanel->cpanel('Cron', 'remove_line', 'username', ['line'=>1]);

The first parameter must be Module you would like to get, second is function name, and the third is username of cPanel's user. There is fourth arguments, when function has some additional arguments, you can pass it there.

For accessing to cPanel API 1 or cPanel API 2 or UAPI, you can use this.

	<?php
	// get bandwidth data of specific cPanel's user (using cPanel API 2)
	$data = $cpanel->execute_action('2', 'Bandwidth', 'getbwdata', 'username');

	// removing email address (using UAPI)
	$data = $cpanel->execute_action('3', 'Email', 'delete_pop', 'username', ['email'=>'[email protected]']);

This function is similar to the above, the only difference is that it has added a parameter which indicates the API you want to use (1 = cPanel API 1, 2 = cPanel API 2, 3 = UAPI), the other arguments are the same.

Overriding current configuration

Somehow, you want to override your current configuration. To do this, here is the code

  <?php
  // change username andd (password or hash)
  $cpanel->setAuthorization($username, $password);

  // change host
  $cpanel->setHost($host);

  // change authentication type
  $cpanel->setAuthType($auth_type);

Get defined configuration

After you define some of your configuration, you can get it again by calling this functions

  <?php
  // get username
  $cpanel->getUsername();

  // get password
  $cpanel->getPassword();

  // get authentication type
  $cpanel->getAuthType();

  // get host
  $cpanel->getHost();

Feedback and contribution

This package is free and open source, feel free to fork and report some issue to this package. :-). Have fun

cpanel-php's People

Contributors

arleslie avatar eugenefvdm avatar fliiiix avatar jpswade avatar max13 avatar mgufrone avatar munikes avatar sudent avatar timgws avatar twouters avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cpanel-php's Issues

A function dont work

The "delsubdomain" function is not working.
Other than that the work is very good.

However I have a project that I need to implement with this function.
Can you help me?

gufy/cpanel-php v2.0.0 requires guzzlehttp/guzzle ~6

Hi,

I'm trying to install Guzzle on my Application but it seems that this composer is requiring guzzle 6 but the latest version is 7.

`composer require guzzlehttp/guzzle
Using version ^7.0 for guzzlehttp/guzzle
./composer.json has been updated
Loading composer repositories with package information
Updating dependencies (including require-dev)
Your requirements could not be resolved to an installable set of packages.

Problem 1
- Installation request for guzzlehttp/guzzle ^7.0 -> satisfiable by guzzlehttp/guzzle[7.0.0, 7.0.0-beta.1, 7.0.0-beta.2, 7.0.0-rc.1, 7.0.1, 7.0.x-dev, 7.1.x-dev].
- gufy/cpanel-php v2.0.0 requires guzzlehttp/guzzle ~6 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- gufy/cpanel-php v2.0.0 requires guzzlehttp/guzzle ~6 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- gufy/cpanel-php v2.0.0 requires guzzlehttp/guzzle ~6 -> satisfiable by guzzlehttp/guzzle[6.5.x-dev].
- Conclusion: don't install guzzlehttp/guzzle 6.5.x-dev
- Installation request for gufy/cpanel-php ~2.0 -> satisfiable by gufy/cpanel-php[v2.0.0].

Installation failed, reverting ./composer.json to its original content.`

There is any plans to update this to allow the latest version of guzzle or is there a work around?

Thanks
James

Error access.

hello , i use this code.

   <?php
   require_once("vendor/autoload.php");
   $cpanel = new \Gufy\CpanelPhp\Cpanel([
       'host'        =>  'https://server01.nubewww.tech:2087', // ip or domain complete with its protocol and port
       'username'    =>  'xxxxxxxxx', // username of your server, it usually root.
       'auth_type'   =>  'xxxxxxxxxxx', // set 'hash' or 'password'
     'password'    =>  'xxxxxxxxxxxxxxxx', // long hash or your user's password
  ]);

  $accounts = $cpanel->listaccts(); // it will returned as array
  print_r($accounts);

and when i call from browser i recive this error.

Client error:POST https://server01.nubewww.tech:2087/json-api/listaccts` resulted in a 403 Forbidden Access denied response: {"cpanelresult":{"apiversion":"2","error":"Access denied","data":{"reason":"Access denied","result":"0"},"type":"text"}} (truncated...) `

Not work example listaccts

Write a pice of code with example on Laravel 5.3

...
use Gufy\CpanelPhp\Cpanel;

...
$whmuser = 'root';
$hash    = $this->hash;  // hash on one line and correct hash
$host    = $this->host;  // my cpanel host
$port    = $this->port; // port 2087

$cpanel = new Cpanel([
            'host'      => $this->host.':'.$port:,
            'username'  => 'root',
            'auth_type' => 'hash',
            'password'  => $this->hash,
        ]);
        // @todo refactor for errors
       var_dump($cpanel->listaccts());

Result not json listaccts ->>

<!DOCTYPE html>\n
<html dir="ltr">\n
<head>\n
<title>hq &ndash; WebHost Manager</title>\n
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">\n
<link rel="shortcut icon" href="/cPanel_magic_revision_1448314783/favicon.ico" type="image/x-icon">\n
\n
<script src="/cPanel_magic_revision_1448314781/yui-gen/utilities_json/utilities_json.js"></script>\n
<script>\n
top._LOADAVG_TIMEOUT = 5 * 60 * 1000;   //5 minutes\n
function set_last_activity() {\n
    top._LAST_ACTIVITY = new Date();\n
}\n
set_last_activity();\n
\n
YAHOO.util.Event.onDOMReady( function() {\n
    var these_frames = top.document.getElementsByTagName("frame");\n
    for (var f=these_frames.length-1; f>-1; f--) {\n
        var the_frame = these_frames[f];\n
        YAHOO.util.Event.addListener( the_frame.contentWindow, "load", function() {\n
            YAHOO.util.Event.addListener(this.document.body, "mousemove", set_last_activity);\n
            YAHOO.util.Event.addListener(this.document.body, "keyup", set_last_activity);\n
            YAHOO.util.Event.addListener(this.document.body, "keydown", set_last_activity);\n
        } );\n
    }\n
} );\n
</script>\n
</head>\n
\n
<frameset cols="*" frameborder="NO" border="0" framespacing="0" rows="78,*">\n
    <frame src="/scripts/command?PFILE=topframe" name="topFrame" frameborder="no" scrolling="no" noresize id="topFrame"/>\n
                \n
        <frameset rows="*" cols="217,556*" framespacing="0" frameborder="no" border="0">\n
            <frame src="/scripts/command?PFILE=command" name="commander" frameborder="no" scrolling="no" id="commander" />\n
            <frame src="/scripts/command?PFILE=main" name="mainFrame" id="mainFrame" frameborder="no"/>\n
        </frameset>\n
        \n
    \n
</frameset>\n
<noframes>WebHost Manager requires frames, but your browser does not support them.</noframes>\n
</html>\n
<!-- Web Host Manager 11.58.0.32 [10] (c) cPanel, Inc. 2016\n
            http://cpanel.net/  Unauthorized copying is prohibited -->\n


Undefined offset: 0

I has get error when dumpzone.

in Cpanel.php line 343
at HandleExceptions->handleError('8', 'Undefined offset: 0', '/home/nginx/domains/xxx/public/vendor/gufy/cpanel-php/src/Gufy/CpanelPhp/Cpanel.php', '343', array('action' => 'dumpzone', 'arguments' => array('domain' => 'xxx.com'), 'host' => 'https://10.0.0.3:2087', 'client' => object(Client))) in Cpanel.php line 343

Resolve:
change
'query' => count($arguments) > 1 ? $arguments : $arguments[0],
to
'query' => $arguments,

Please check it :)

Create User Session 'create-user-session'

I want to create the security token for a cpanel user token "cpsessXXXXXXXXXX" using the WHM API Token.
The API token privilege many operation and on of the Operation is, "create-user-session".
Is this Repo has any way to do this?

Uncaught Error: Class 'Gufy\CpanelPhp\Cpanel' not found

hi I just new bee here I wanted know how to use it I hit command for composer n files were get downloaded in my localhost xampp
in winodws C:\xampp\htdocs\cpanel\vendor\gufy\cpanel-php\src\Gufy\CpanelPhp this is my path to Cpanel.php

in C:\xampp\htdocs\cpanel I wrote index.php with code

'https://123.456.789.123:2087', // ip or domain complete with its protocol and port 'username' => 'root', // username of your server, it usually root. 'auth_type' => 'hash', // set 'hash' or 'password' 'password' => 'password', // long hash or your user's password ]); $accounts = $cpanel->listaccts(); // it will returned as array I gives me error Fatal error: Uncaught Error: Class 'Gufy\CpanelPhp\Cpanel' not found in C:\xampp\htdocs\cpanel\index.php:2 Stack trace: #0 {main} thrown in C:\xampp\htdocs\cpanel\index.php on line 2 how I can give reference to the CPanel.php file I tried to give full path by require once but it still gives error.

How To Export All Domain

Hi,

I want only export list of all domain on whm, can someone guide me how to use?

Tanks very much..

Forbidden Access denied error

Hello,
I am trying the example:

$cpanel = new \Gufy\CpanelPhp\Cpanel([
'host' => 'https://xx.xx.xx.xx:2087', // ip or domain complete with its protocol and port
'username' => 'root', // username of your server, it usually root.
'auth_type' => 'password', // set 'hash' or 'password'
'password' => 'my_password', // long hash or your user's password
]);

$accounts = $cpanel->listaccts(); // it will returned as array

when i var_dump the $accounts i get the following:
Client error response [url] https://xx.xx.xx.xx:2087/json-api/listaccts [status code] 403 [reason phrase] Forbidden Access denied

What am i doing wrong?
Is there something else i should do?

Thanks

Readme is wrong

you should replace

composer require gufy/cpanel-whm:dev-master

with

composer require gufy/cpanel-php:dev-master

Error loading accounts

GuzzleHttp\Ring\Exception\RingException: cURL error 3: in /home/bastify/public_html/clientarea/vendor/guzzlehttp/ringphp/src/Client/CurlFactory.php:127
Stack trace:
#0 /home/bastify/public_html/clientarea/vendor/guzzlehttp/ringphp/src/Client/CurlFactory.php(91): GuzzleHttp\Ring\Client\CurlFactory::createErrorResponse(Array, Array, Array)
#1 /home/bastify/public_html/clientarea/vendor/guzzlehttp/ringphp/src/Client/CurlHandler.php(96): GuzzleHttp\Ring\Client\CurlFactory::createResponse(Array, Array, Array, Array, Resource id #501)
#2 /home/bastify/public_html/clientarea/vendor/guzzlehttp/ringphp/src/Client/CurlHandler.php(68): GuzzleHttp\Ring\Client\CurlHandler->_invokeAsArray(Array)
#3 /home/bastify/public_html/clientarea/vendor/guzzlehttp/ringphp/src/Client/Middleware.php(54): GuzzleHttp\Ring\Client\CurlHandler->__invoke(Array)
#4 /home/bastify/public_html/clientarea/vendor/guzzlehttp/ringphp/src/Client/Middleware.php(30): GuzzleHttp\Ring\Client\Middleware::GuzzleHttp\Ring\Client{closure}(Array)
#5 /home/bastify/public_html/clientarea/vendor/guzzlehttp/guzzle/src/RequestFsm.php(129): GuzzleHttp\Ring\Client\Middleware::GuzzleHttp\Ring\Client{closure}(Array)
#6 /home/bastify/public_html/clientarea/vendor/guzzlehttp/guzzle/src/Client.php(165): GuzzleHttp\RequestFsm->__invoke(Object(GuzzleHttp\Transaction))
#7 /home/bastify/public_html/clientarea/vendor/guzzlehttp/guzzle/src/Client.php(150): GuzzleHttp\Client->send(Object(GuzzleHttp\Message\Request))
#8 /home/bastify/public_html/clientarea/vendor/whmapi/src/Gufy/CpanelPhp/Cpanel.php(349): GuzzleHttp\Client->post('/json-api/lista...', Array)
#9 /home/bastify/public_html/clientarea/vendor/whmapi/src/Gufy/CpanelPhp/Cpanel.php(105): Gufy\CpanelPhp\Cpanel->runQuery('listaccts', Array)
#10 /home/bastify/public_html/clientarea/dedicated_list.php(44): Gufy\CpanelPhp\Cpanel->__call('listaccts', Array)
#11 {main}
Next GuzzleHttp\Exception\RequestException: cURL error 3: in /home/bastify/public_html/clientarea/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php:51
Stack trace:
#0 /home/bastify/public_html/clientarea/vendor/guzzlehttp/guzzle/src/RequestFsm.php(103): GuzzleHttp\Exception\RequestException::wrapException(Object(GuzzleHttp\Message\Request), Object(GuzzleHttp\Ring\Exception\RingException))
#1 /home/bastify/public_html/clientarea/vendor/guzzlehttp/guzzle/src/RequestFsm.php(132): GuzzleHttp\RequestFsm->__invoke(Object(GuzzleHttp\Transaction))
#2 /home/bastify/public_html/clientarea/vendor/react/promise/src/FulfilledPromise.php(25): GuzzleHttp\RequestFsm->GuzzleHttp{closure}(Array)
#3 /home/bastify/public_html/clientarea/vendor/guzzlehttp/ringphp/src/Future/CompletedFutureValue.php(55): React\Promise\FulfilledPromise->then(Object(Closure), NULL, NULL)
#4 /home/bastify/public_html/clientarea/vendor/guzzlehttp/guzzle/src/Message/FutureResponse.php(43): GuzzleHttp\Ring\Future\CompletedFutureValue->then(Object(Closure), NULL, NULL)
#5 /home/bastify/public_html/clientarea/vendor/guzzlehttp/guzzle/src/RequestFsm.php(134): GuzzleHttp\Message\FutureResponse::proxy(Object(GuzzleHttp\Ring\Future\CompletedFutureArray), Object(Closure))
#6 /home/bastify/public_html/clientarea/vendor/guzzlehttp/guzzle/src/Client.php(165): GuzzleHttp\RequestFsm->__invoke(Object(GuzzleHttp\Transaction))
#7 /home/bastify/public_html/clientarea/vendor/guzzlehttp/guzzle/src/Client.php(150): GuzzleHttp\Client->send(Object(GuzzleHttp\Message\Request))
#8 /home/bastify/public_html/clientarea/vendor/whmapi/src/Gufy/CpanelPhp/Cpanel.php(349): GuzzleHttp\Client->post('/json-api/lista...', Array)
#9 /home/bastify/public_html/clientarea/vendor/whmapi/src/Gufy/CpanelPhp/Cpanel.php(105): Gufy\CpanelPhp\Cpanel->runQuery('listaccts', Array)
#10 /home/bastify/public_html/clientarea/dedicated_list.php(44): Gufy\CpanelPhp\Cpanel->__call('listaccts', Array)
#11 {main}

cPanel fileman module mkfile function (api) not working.

i am calling the cPanel mkfile api but every time it throws some errors like cURL error 28: Operation timed out after 0 milliseconds with 0 out of 0 bytes received (see http://curl.haxx.se/libcurl/c/libcurl-errors.html).

I am calling simple package functions but it throws curl errors so not getting where it comes from?

source code
$cPanel = new Cpanel([
'host' => $hostUrl ,
'username' => $username,
'auth_type' => 'hash',
'password' => $password
]);

    $data = $cPanel->cpanel('Fileman', 'mkfile', $username, [
        'name'        => 'new_file.txt',
        'path'        => '/home/myfolder/public_html/',
        'permissions' => '0777',
    ]);
    print_r($data);

Please help me to resolve or any correction?

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.