gufy / cpanel-php
此包已被弃用,不再维护。未建议替代包。
PHP 的 Cpanel/WHM API
v2.0.0
2020-02-13 08:53 UTC
Requires
- php: >=5.6.0
- guzzlehttp/guzzle: ~6
Requires (Dev)
- phpunit/phpunit: ^4.8
README
内容
安装指南
要安装此包,您可以通过终端运行此代码
composer require gufy/cpanel-php:~2.0
或更新您的 composer.json
并添加此行
"gufy/cpanel-php":"~2.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']); // create account (Domain Name, Username, Password, Plan Slug) createAccount(www.domain_name.com.br, 'user', 'pass', 'plan_basic');
要访问 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();
反馈与贡献
此包是免费和开源的,欢迎您分叉并为此包报告一些问题。:-)。祝您玩得开心