如何从外部服务器使用 WHM API
How to use WHM API's from external server
我的服务器 "A" 运行 在 ruby 上 rails。
我的托管服务器 "B" 上安装了 WHM。
如何使用 WHM 的 API 获取有关托管服务器的一些数据。
例如,我想列出每个用户的所有域和子域。
可能吗?如果是那么怎么办?
任何建议。
这是 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
获得域和用户名后,您可以使用用户名获取其子域:将[USERNAME_HERE]
替换为cPanel用户名。
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"
}
}
我的服务器 "A" 运行 在 ruby 上 rails。 我的托管服务器 "B" 上安装了 WHM。
如何使用 WHM 的 API 获取有关托管服务器的一些数据。
例如,我想列出每个用户的所有域和子域。
可能吗?如果是那么怎么办?
任何建议。
这是 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
获得域和用户名后,您可以使用用户名获取其子域:将[USERNAME_HERE]
替换为cPanel用户名。
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"
}
}