【问题标题】:Commands need to be run with admin privilege Ejabberd Rest Api?命令需要以管理员权限 Ejabberd Rest Api 运行?
【发布时间】:2018-11-03 07:56:18
【问题描述】:

我在ejabberd 16.09 上配置Ejabberd Rest API。要配置它,我只是关注 ejabberd 文档 (https://docs.ejabberd.im/developer/ejabberd-api/simple-configuration/)。所以当我要用body: 打邮递员的http://localhost:5280/api/change_password url 时

{
      "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 配置的解决方案都将不胜感激。

【问题讨论】:

    标签: rest ejabberd ejabberd-auth


    【解决方案1】:

    我无法用最近的 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
    

    最后,我检查了数据库,密码已更改

    【讨论】:

    • 非常感谢@Badlop 的回答,但您的回答是 ejabberd 18 版本,但我要求 16 个版本。我已经在 18 日检查过,但我需要 16 日。
    猜你喜欢
    • 1970-01-01
    • 2019-10-15
    • 1970-01-01
    • 2022-08-20
    • 1970-01-01
    • 2013-03-04
    • 2013-03-07
    • 2013-07-24
    • 1970-01-01
    相关资源
    最近更新 更多