scorpionslh/cpanel-uapi-php-class

此包最新版本(dev-master)没有可用的许可证信息。

从N1ghteyes派生的类

dev-master 2024-07-19 10:55 UTC

This package is not auto-updated.

Last update: 2024-09-29 19:49:20 UTC


README

GitHub release

PHP类,用于提供与cPanel的UAPI和API2的简单易用的接口。使用PHP魔术函数提供简单而强大的接口。

v2.0版本与v1.x版本不兼容,可能还会进行一些更改。请参阅变更日志以获取详细信息。类已重命名为cpanelAPI。需要进一步测试。

  • 注意,尽管此类尚未弃用,但现在有一个新的Agnostic API类可用,它将执行此类所做的所有操作(除了2FA),并且可以与任何RESTful / HTTP API一起工作——基本上是所有不是SOAP的东西。请参阅https://github.com/N1ghteyes/apicore

用法

如果您选择使用此类,请在GitHub上为它加星。这使我更好地了解用户数量以及更改时受影响的用户。

请参阅示例文件,但典型用法如下

实例化类

$cPanel = new cpanelAPI('user', 'password', 'cpanel.example.com');

我们想要使用的API和模块(也称为作用域)现在是受保护的,并由__get()设置。

请求布局如下:$cPanel->api->method->Module->request(args[])

应将->method部分替换为->get以进行GET请求,或替换为->post以进行POST请求,或省略以默认为GET请求。

例如,假设我们想使用UAPI调用Mysql::get_server_information函数

$response = $cPanel->uapi->Mysql->get_server_information();
var_dump($response);

现在我们已经设置了API 模块,我们可以调用此API和模块内的其他函数,而无需再次指定它们

$response = $cPanel->create_database(['name' => $cPanel->user.'_MyDatabase']);
var_dump($response);

我们还可以更改模块作用域,而无需重新指定API。请注意,模块调用是区分大小写的。

$response = $cPanel->SSL->list_certs();

文件上传示例

$cPanel = new cpanelAPI($username, $password, $hostname);
$cPanel->uapi->post->Fileman
       ->upload_files(['dir' => REMOTE_PATH_RELATIVE_TO_HOME,
                       'file-1' => new CURLFile(LOCAL_PATH_TO_FILE)
                       ]);

API2

API2的使用方法与UAPI完全相同

$cPanel = new cpanelAPI('user', 'password', 'cpanel.example.com');

例如,假设我们想使用API2添加子域名

$response = $cPanel->api2->SubDomain->addsubdomain(['rootdomain' => 'domain.com', 'domain' => 'sub']);
var_dump($response);

双因素认证

要在带有双因素认证(2FA)的cPanel实例上使用此类,您需要在类构造函数中传入密钥

$cPanel = new cpanelAPI('user', 'password', 'cpanel.example.com', 'secret');

密钥可以在2FA设置页面上找到。有关详细信息,请参阅cPanel的双因素认证 - 配置双因素认证