singh.indolia
singh.indolia

Reputation: 1291

Commands need to be run with admin privilege Ejabberd Rest Api?

I am configuring Ejabberd Rest API on ejabberd 16.09. TO configure it i am just following ejabberd Document (https://docs.ejabberd.im/developer/ejabberd-api/simple-configuration/). So when i am going to hit http://localhost:5280/api/change_password url from postman with body:

{
      "user": "123",
      "host": "TT_CPU_076",
      "newpass": "blank"
    }

and header: Content-Type: application/json. I am getting an error like:

{
    "status": "error",
    "code": 31,
    "message": "Command need to be run with admin priviledge."
}

my ejabberd.yml file configuration like:

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"

Any solution to achieve Rest Api configuration with ejabberd will be appreciate.

Upvotes: 0

Views: 331

Answers (1)

Badlop
Badlop

Reputation: 4120

I cannot reproduce that problem with a recent ejabberd 18.04. I set in ejabberd.yml:

hosts:
  - "localhost"
  - "TT_CPU_076"

api_permissions:
  "public commands":
    who:
      - ip: "127.0.0.1/8"
    what:
      - "*"
      - "status"
      - "connected_users_number"

Then I register that account:

$ ejabberdctl register 123 TT_CPU_076 pass11
User 123@TT_CPU_076 successfully registered

I write a simple API client:

<?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);
?>

Then I execute it:

$ php test.php 
0

This is logged in 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

And finally, I check the database, and the password has changed

Upvotes: 2

Related Questions