chrisbjr / cpanel-php
PHP的Cpanel/WHM API
v1.0.5
2015-07-01 01:33 UTC
Requires
- php: >=5.3.7
- guzzlehttp/guzzle: ~5
Requires (Dev)
- phpunit/phpunit: 4.7.*@dev
This package is not auto-updated.
Last update: 2024-09-14 18:04:19 UTC
README
内容
安装指南
要安装此包,您可以在终端运行以下代码
composer require gufy/cpanel-whm:dev-master
或者更新您的 composer.json
文件,添加以下行
"gufy/cpanel-php":"~1.0"
然后,运行以下代码
composer update
用法
例如,如果您想获取WHM服务器的账户列表,可以这样做。
<?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
函数
在构造函数中定义配置
这是当您在创建新对象时定义配置的示例
<?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 ]);
用法
例如,您想从cPanel/WHM获取一些账户列表
<?php $accounts = $cpanel->listaccts(); // passing parameters $accounts = $cpanel->listaccts(['searchtype'=>'domain', 'search'=>'', 'exact', 'search'=>'helloworld.com']);
要访问cPanel API 2,您可以使用这个。
<?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]);
第一个参数必须是您想获取的模块,第二个是函数名,第三个是cPanel用户的用户名。还有第四个参数,当函数有一些额外的参数时,您可以将其传递到那里。
要访问cPanel API 1或cPanel API 2或UAPI,您可以使用这个。
<?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'=>'peter@griffin.com']);
此函数与上面的类似,唯一的不同是它添加了一个参数,表示您想使用的API(1 = cPanel API 1,2 = cPanel API 2,3 = UAPI),其他参数相同。
覆盖当前配置
不知何故,您想覆盖当前配置。为此,以下是代码
<?php // change username andd (password or hash) $cpanel->setAuthorization($username, $password); // change host $cpanel->setHost($host); // change authentication type $cpanel->setAuthType($auth_type);
获取定义的配置
您定义了一些配置后,可以通过调用此函数再次获取它们
<?php // get username $cpanel->getUsername(); // get password $cpanel->getPassword(); // get authentication type $cpanel->getAuthType(); // get host $cpanel->getHost();
反馈和贡献
此包是免费和开源的,请随意分支并报告此包的一些问题。:-)。祝您玩得开心