如何从外部服务器使用WHM API

时间:2016-11-21 04:59:21

标签: whm

我有我的服务器" A"在轨道上的红宝石上运行。 我的托管服务器" B"安装了WHM。

如何使用WHM的API获取有关托管服务器的一些数据。

例如,我想列出每个用户的所有域和子域。

有可能吗?如果是,那怎么样?

任何建议。

1 个答案:

答案 0 :(得分:1)

以下是WHM API文档:

  

https://documentation.cpanel.net/display/SDK/Guide+to+WHM+API+1

要使用WHM API,您首先需要了解以下内容:

  

https://documentation.cpanel.net/display/SDK/Use+WHM+API+to+Call+cPanel+API+and+UAPI

列出服务器上的所有用户名和域:(可选搜索参数)

  

https://documentation.cpanel.net/display/SDK/WHM+API+1+Functions+-+listaccts

以下来电将列出您的所有帐户及其详细信息:

https://hostname.example.com:2087/cpsess##########/json-api/listaccts?api.version=1

上述电话会议的响应示例:

{
  "data": {
    "acct": [
      {
        "mailbox_format":"mdbox"
        "inodesused":"1",
        "inodeslimit":"unlimited",
        "maxaddons": "1",
        "ip": "192.168.0.20",
        "ipv6": ["0101:ca75:0101:ca75:0101:ca75:0101:ca77"],
        "outgoing_mail_suspended": 0,
        "outgoing_mail_hold": 0,
        "min_defer_fail_to_trigger_protection": 5,
        "legacy_backup": 0,
        "diskused": "0M",
        "maxftp": "2",
        "startdate": "13 Jul 08 14:33",
        "max_defer_fail_percentage": "10",
        "disklimit": "100M",
        "is_locked": "0",
        "suspendtime": null,
        "email": "",
        "domain": "example.com",
        "unix_startdate": 1373312011,
        "user": "example",
        "plan": "plan9",
        "shell": "\/bin\/bash",
        "maxpop": "20",
        "backup": 0,
        "theme": "paper_lantern",
        "owner": "root",
        "max_email_per_hour": "100",
        "suspendreason": "not suspended",
        "maxlst": "5",
        "suspended": 0,
        "maxsql": "1",
        "maxparked": "1",
        "partition": "home",
        "maxsub": "5"
      },
    ]
  },
  "metadata": {
    "version": 1,
    "reason": "OK",
    "result": 1,
    "command": "listaccts"
  }
}

但是要列出子域,您需要使用cPanel API。

  

https://documentation.cpanel.net/display/SDK/cPanel+API+2+Functions+-+SubDomain%3A%3Alistsubdomains

获得域名和用户名后,您可以使用用户名获取其子域名:使用cPanel用户名替换[USERNAME_HERE]

https://hostname.example.com:2087/cpsess###########/json-api/cpanel?cpanel_jsonapi_user=[USERNAME_HERE]&cpanel_jsonapi_apiversion=2&cpanel_jsonapi_module=SubDomain&cpanel_jsonapi_func=listsubdomains

上述电话会议的响应示例:

{
  "cpanelresult": {
    "apiversion": 2,
    "func": "listsubdomains",
    "data": [
      {
        "domainkey": "subdomain_example.com",
        "rootdomain": "example.com",
        "status": "not redirected",
        "subdomain": "subdomain",
        "reldir": "home:public_html\/subdomain",
        "basedir": "public_html\/subdomain",
        "dir": "\/home\/example\/public_html\/subdomain",
        "domain": "subdomain.example.com"
        "web_subdomain_aliases": "1"
      }
    ],
    "event": {
      "result": 1
    },
    "module": "SubDomain"
  }
}