processone / ejabberd-contrib

Growing and curated ejabberd contributions repository - PR or ask to join !
http://ejabberd.im
250 stars 137 forks source link

IS mod_rest compatible with ejabberd 24.2.0? #334

Closed AlanChatflix closed 3 months ago

AlanChatflix commented 5 months ago

I installed the new ejabberd 24.2.0, then installed mod_rest. It installed correctly. But whenever I try to add it on ejabberd.yml: modules: mod_rest: {}

it fails. doesn't matter how I add it, it fails to reload or restart ejabberd. Why?

badlop commented 5 months ago

Yes, it should work. It works compiling ejabberd manualy, and also using a container image:

For this test, I'll use the `ejabberd` container image. I'll start it in interactive mode so I get log messages immediately: ```bash $ podman run --name ejabberd -it -p 5222:5222 -p 5285:5285 ghcr.io/processone/ejabberd:24.02 live ``` In another terminal, I had to edit the file `.ejabberd-modules/sources/ejabberd-contrib/mod_rest/conf/mod_rest.yml` because it has the option `allowed_ips` with an IP address that my container didn't use. ```bash podman exec -it --user root ejabberd vi .ejabberd-modules/sources/ejabberd-contrib/mod_rest/conf/mod_rest.yml ``` Then install the module and register a destination user: ```bash $ podman exec -it ejabberd ejabberdctl module_install mod_rest Module mod_rest has been installed and started. It's configured in the file: /opt/ejabberd/.ejabberd-modules/mod_rest/conf/mod_rest.yml Configure the module in that file, or remove it and configure in your main ejabberd.yml $ podman exec -it ejabberd ejabberdctl register nolan localhost asd User nolan@localhost successfully registered ``` Finally, check the offline messages of that user, send a stanza and check it was received: ```bash $ podman exec -it ejabberd ejabberdctl get_offline_count nolan localhost 0 $ wget http://localhost:5285/rest/ --server-response --post-data 'World' --2024-04-29 13:38:15-- http://localhost:5285/rest/ Resolving localhost (localhost)... ::1, 127.0.0.1 Connecting to localhost (localhost)|::1|:5285... connected. HTTP request sent, awaiting response... HTTP/1.1 200 OK Content-Type: text/html; charset=utf-8 Content-Length: 2 Length: 2 [text/html] Saving to: 'index.html' index.html 100%[=========================================>] 2 --.-KB/s in 0s 2024-04-29 13:38:15 (369 KB/s) - 'index.html' saved [2/2] $ cat index.html Ok $ podman exec -it ejabberd ejabberdctl get_offline_count nolan localhost 1 ```
AlanChatflix commented 5 months ago

I'm using Ubuntu with NGINX. I just followed the directions from git:

sudo ejabberdctl module_install mod_rest

And it says it was installed correctly. When I execute the command to list all the mods installed, it shows mod_rest.

But when I added to ejabberd.yml:

modules:
   mod_rest: {}

It fails if I try to reload ejabberd. If I remove it it works, if I add any mod_rest it fails. If it's correctly installed with "sudo ejabberdctl module_install mod_red" and I successfully reloaded ejabberd, shouldn't that be enough? Do I need to execute any other command after "sudo ejabberdctl module_install mod_red" ?

AlanChatflix commented 5 months ago

Yes, it should work. It works compiling ejabberd manualy, and also using a container image:

For this test, I'll use the ejabberd container image. I'll start it in interactive mode so I get log messages immediately:

$ podman run --name ejabberd -it -p 5222:5222 -p 5285:5285 ghcr.io/processone/ejabberd:24.02 live

In another terminal, I had to edit the file .ejabberd-modules/sources/ejabberd-contrib/mod_rest/conf/mod_rest.yml because it has the option allowed_ips with an IP address that my container didn't use.

podman exec -it --user root ejabberd vi .ejabberd-modules/sources/ejabberd-contrib/mod_rest/conf/mod_rest.yml

Then install the module and register a destination user:

$ podman exec -it ejabberd ejabberdctl module_install mod_rest
Module mod_rest has been installed and started.
It's configured in the file:
  /opt/ejabberd/.ejabberd-modules/mod_rest/conf/mod_rest.yml
Configure the module in that file, or remove it
and configure in your main ejabberd.yml

$ podman exec -it ejabberd ejabberdctl register nolan localhost asd
User nolan@localhost successfully registered

Finally, check the offline messages of that user, send a stanza and check it was received:

$ podman exec -it ejabberd ejabberdctl get_offline_count nolan localhost
0

$ wget http://localhost:5285/rest/ --server-response --post-data '<message to="nolan@localhost" from="localhost/rest"><body>World</body></message>'
--2024-04-29 13:38:15--  http://localhost:5285/rest/
Resolving localhost (localhost)... ::1, 127.0.0.1
Connecting to localhost (localhost)|::1|:5285... connected.
HTTP request sent, awaiting response...
  HTTP/1.1 200 OK
  Content-Type: text/html; charset=utf-8
  Content-Length: 2
Length: 2 [text/html]
Saving to: 'index.html'

index.html                  100%[=========================================>]       2  --.-KB/s    in 0s      

2024-04-29 13:38:15 (369 KB/s) - 'index.html' saved [2/2]

$ cat index.html
Ok

$ podman exec -it ejabberd ejabberdctl get_offline_count nolan localhost
1

I'm using Ubuntu with NGINX. I just followed the directions from git:

sudo ejabberdctl module_install mod_rest

And it says it was installed correctly. When I execute the command to list all the mods installed, it shows mod_rest.

But when I added to ejabberd.yml:

modules:
   mod_rest: {}

It fails if I try to reload ejabberd. If I remove it it works, if I add any mod_rest it fails. If it's correctly installed with "sudo ejabberdctl module_install mod_red" and I successfully reloaded ejabberd, shouldn't that be enough? Do I need to execute any other command after "sudo ejabberdctl module_install mod_red" ?

badlop commented 5 months ago

But when I added to ejabberd.yml:

When running module_install, it also copies the default module configuration, and gets enabled by default. Didn't you get an explanation similar to this?

$ podman exec -it ejabberd ejabberdctl module_install mod_rest
Module mod_rest has been installed and started.
It's configured in the file:
  /opt/ejabberd/.ejabberd-modules/mod_rest/conf/mod_rest.yml
Configure the module in that file, or remove it
and configure in your main ejabberd.yml

If it's correctly installed with "sudo ejabberdctl module_install mod_red"

Please notice that "module_install" performs many tasks:

So you just need to execute "module_install", as I demonstrated in my example setup guide.

AlanChatflix commented 5 months ago

I didn't use "podman exec -it " . It's Ubuntu. I just did "sudo ejabberdctl module_install mod_red" and that was enough to return that it was installed and active. That's all. Shouldn't that be enough for me to just edit ejabberd.yml with mod_rest: {} then reload ejabberd service?

badlop commented 5 months ago

"sudo ejabberdctl module_install mod_red" and that was enough to return that it was installed and active. That's all.

Thisenables the module, as I said and I demonstrated previously. NO NEED TO EDIT ejabberd.yml, it's already enabled.

me to just edit ejabberd.yml with mod_rest: {} then reload ejabberd service?

I'll repeat again: the module is already enabled. It is mentioned in the command response, did you read it? No need to enable it again in ejabberd.yml, and no need to reload ejabberd service.

AlanChatflix commented 5 months ago

YES I got it but i WANT TO CONFIG my ejabberd.yml with custom stuff like this:

mod_rest:
    allowed_ips:
      - "127.0.0.1"

and:

-
    port: MY_PORT_BUMBER
    module: ejabberd_http
    request_handlers:
           /rest: mod_rest

etc.. So it should be working LIKE IT DID WITH PREVIOUS EJABBERD, correct? I had it before. The latest version of eJabberd isn't working with this.

AlanChatflix commented 5 months ago

@badlop ?

badlop commented 5 months ago

Aha: If you want to configure some options in your main ejabberd.yml file, you can:

  1. remove the module configuration that is in .ejabberd-modules/mod_rest/conf/mod_rest.yml (either remove the content, or remove the file completely)

  2. Then you can add it as usual in your main ejabberd.yml

AlanChatflix commented 4 months ago

Thanks. Your tips really helped.