rest - 命令需要以管理员权限 Ejabberd Rest Api 运行?
问题描述
我Ejabberd
在ejabberd 16.09
. 要配置它,我只是关注 ejabberd 文档(https://docs.ejabberd.im/developer/ejabberd-api/simple-configuration/)。所以当我要从邮递员那里点击http://localhost:5280/api/change_password urlbody:
{
"user": "123",
"host": "TT_CPU_076",
"newpass": "blank"
}
我header:
Content-Type: application/json.
收到如下错误:
{
"status": "error",
"code": 31,
"message": "Command need to be run with admin priviledge."
}
我的 ejabberd.yml 文件配置如下:
port: 5280
module: ejabberd_http
ip: "127.0.0.1"
request_handlers:
"/websocket": ejabberd_http_ws
"/api": mod_http_api
## "/pub/archive": mod_http_fileserver
web_admin: true
http_bind: true
## register: true
captcha: false
api_permissions:
"API used from localhost allows all calls":
- who:
- ip: "127.0.0.1/8"
- what:
- "*"
- "!stop"
- "!start"
任何使用 ejabberd 实现 Rest Api 配置的解决方案都将不胜感激。
解决方案
我无法用最近的 ejabberd 18.04 重现该问题。我在 ejabberd.yml 中设置:
hosts:
- "localhost"
- "TT_CPU_076"
api_permissions:
"public commands":
who:
- ip: "127.0.0.1/8"
what:
- "*"
- "status"
- "connected_users_number"
然后我注册该帐户:
$ ejabberdctl register 123 TT_CPU_076 pass11
User 123@TT_CPU_076 successfully registered
我编写了一个简单的 API 客户端:
<?php
$url='localhost:5280/api/change_password/';
$info=array("user"=>"123",
"host"=>"TT_CPU_076",
"newpass"=>"mypass22"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($info));
$output=curl_exec($ch);
curl_close($ch);
print_r($output);
?>
然后我执行它:
$ php test.php
0
这是在 ejabberd 中登录的:
11:39:18.646 [info] API call change_password
[{<<"user">>,<<"123">>},
{<<"host">>,<<"TT_CPU_076">>},
{<<"newpass">>,<<"mypass22">>}]
from ::ffff:127.0.0.1:46778
最后,我检查了数据库,密码已更改
推荐阅读
- python - 动作和击键之间的延迟
- flutter - 如何按值将变量传递给 Flutter MaterialPageRoute?
- java - 如何在 spring-boot 框架中验证 wsdl
- vue.js - 如何动态更改 vuex-persist 键选项?
- c - c语言中的fflush(stdout)有什么用,怎么用?
- django - 错误:无法打开需求文件:[Errno 2] 没有这样的文件或目录:Jenkins 中的“requirements.txt”
- python-3.x - 使用机器人框架的python测试
- javascript - 对象数组 - 如何找到共同值
- reactjs - ant-design 崩溃,一次只能显示一个面板及其内容
- go - 我在哪里可以找到 gcloud 调用的 API?