furkankulaber/cpanel-php

PHP 的 Cpanel/WHM API

dev-master 2018-01-01 19:10 UTC

This package is auto-updated.

Last update: 2024-09-21 05:40:21 UTC


README

内容

安装指南

要安装此包,您可以通过终端运行此代码

	composer require furkankulaber/cpanel-php:dev-master

或者通过更新您的 composer.json 文件添加以下行

	"furkankulaber/cpanel-php":"~1.0"

然后,运行此代码

	composer update

用法

例如,如果您想获取 WHM 服务器的账户列表,可以这样做。

  <?php
  $cpanel = new \Clemury\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 \Clemury\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();

反馈和贡献

此包是免费和开源的,请随意分支并报告一些问题给此包。:-)。祝您玩得开心