eugenevdm / whm-api
PHP的WHM/cPanel API
v0.0.1
2023-05-09 13:55 UTC
Requires
- php: >=8.1.0
- guzzlehttp/guzzle: ^7.5
Requires (Dev)
- phpunit/phpunit: ^10.1
This package is auto-updated.
Last update: 2024-09-09 17:14:48 UTC
README
内容
安装指南
要安装此软件包,您可以在终端运行以下代码:
composer require eugenevdm/whm-api
用法
如果您想获取WHM服务器的账户列表,可以这样做:
<?php require_once __DIR__ . '/vendor/autoload.php'; use Eugenevdm\WhmApi\Cpanel; $cpanel = new src\Cpanel([ 'host' => 'https://1.2.3.4:2087', // ip or domain complete with its protocol and port 'username' => 'root', // username of your server, it is usually root 'auth_type' => 'hash', // set 'hash' or 'password' 'password' => 'password', // long hash or your user's password ]); $accounts = $cpanel->listaccts(); // results returned as an array echo print_r($accounts, true);
函数
在构造函数中定义配置
以下是在创建新对象时定义配置的示例
<?php $cpanel = new src\Cpanel([ 'host' => 'https://1.2.3.4:2087', // required 'username' => 'root', // required 'auth_type' => 'hash', // optional, default 'hash' 'password' => 'password', // required ]);
用法
例如,您想从WHM/cPanel获取一些账户列表
<?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 and (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();
反馈与贡献
欢迎提交拉取请求 :-)