phasehosting/php-cpanel-api

PHP 的 Cpanel/WHM API

v1.0.0 2016-11-05 13:11 UTC

This package is not auto-updated.

Last update: 2024-09-18 20:19:47 UTC


README

内容

安装指南

要安装此软件包,您可以在终端运行此代码

	composer require phasehosting/cpanel-whm

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

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

然后,运行此代码

	composer update

使用

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

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

反馈和贡献

此软件包是免费和开源的,您可以自由地进行分支和报告一些问题。:-)。祝您玩得开心