0

Please bear with me if my wording is a little off. What I'm basically trying to do is write a script that runs on the server the ejabberd service is running on. This script is supposed to create a chat room and automatically subscribe users to it.

I am aware that this is possible through the REST API but I don't want to trigger this through a connection from the outside but from within the same physical server.

Or would the goto method then be to run the API calls through localhost?

UPDATE: As suspected I can simply call the REST API through localhost. But I'm still stuck. It's probably some typo in my config or the calls so I'll share what I tried here:

hey thanks for your response. I got this far myself but I'm not getting the expected result.

So i configured the necessary part in my yml file like so:

listen:
    -
        port: 5285
        module: ejabberd_http
        request_handlers:
          "/rest": mod_rest

and added localhost to the hosts. I then tried to access a REST function like this:

curl -X POST -i -H "Content-type: application/json"  http://localhost:5285/rest/create_room -d 
'
  {
    "name":"testroom",
    "service":"mychatservice.host.com",
    "host":"host.com"
  }
'

And I got this response:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 21

Try POSTing a stanza.

I thought the 200 code meant I did right but when I checked with "ejabberdctl muc_online_rooms global" it didn't list a single one. Also any wrong command after the base url returned the same response to me. So what am I doing wrong?

edit: I did of course also include the rest module itself:

mod_rest:
  allowed_ips:
    - "127.0.0.1"
Jeffrey
  • 189
  • 1
  • 8

1 Answers1

1

ejabberd is listening for connections, and the default configuration doesn't restrict from where do they come. So yes, you can send the REST API queries from localhost.

In fact, once you get this working, you can configure that listener to accept connections only from localhost.

Badlop
  • 3,840
  • 1
  • 8
  • 9
  • Did you read the module documentation before writting your client? And did you read that documentation after seeing something strange in its behavior? And... can you read it now? More precisely, see the example clients. – Badlop Feb 04 '19 at 14:01
  • I'm really just trying to post through console from the server itself. That is all I need to get working. No client will ever need to execute those commands – Jeffrey Feb 08 '19 at 15:27
  • I looked through the module documentation as well as the rest api documentation and some other questions on here asking something similar. I followed everything that was suggested. What am I missing? – Jeffrey Feb 08 '19 at 15:36
  • I've just added a new example of how to call commands using curl and mod_rest, see https://github.com/processone/ejabberd-contrib/tree/master/mod_rest – Badlop Feb 11 '19 at 14:42
  • Thanks a lot for all that time and effort. I was actually able to resolve the issue but now I have another problem. I get the error "subscriptions are not allowed" although I set "allow_subscriptions" to true in the "default_room_options" I am running 16.09 by the way – Jeffrey Feb 11 '19 at 22:23
  • And you plan to keep adding problems here, one after another, making impossible to know what is going on? Mark this problem as solved, and create a new one, indicating the new scenario (server version, relevant configuration, etc) – Badlop Feb 12 '19 at 15:04
  • I'm sorry. You're right I thought with the context of my previous question it would make sense to ask it here but I posted a [new question](https://stackoverflow.com/questions/54673217/ejabberd-trying-to-subscribe-a-user-through-api) with all the relevant info now. – Jeffrey Feb 13 '19 at 15:04