I'm setting up a ejabberd-19.02 server on windows 10, configuring it to call admin commands through rest-api. I have followed the documentation as in ejabberd-doc. I am also able to generate oauth token.
http://localhost:5443/oauth/authorization_token?access_token=0GXCPVJa0l3jFH3Yrn9dIZFMftrNTBFa&token_type=bearer&expires_in=31536000&scope=ejabberd:admin&state=
But on calling rest-api method, using curl command as in documentation:
curl -v -X POST -H "X-Admin: true" -H "Authorization: Bearer 0GXCPVJa0l3jFH3Yrn9dIZFMftrNTBFa" http://localhost:5443/api/get_roster -d '{"user": "anas", "server": "localhost"}'
I am getting message as:
Note: Unnecessary use of -X or --request, POST is already inferred.
* Trying ::1...
* TCP_NODELAY set
* Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 5443 (#0)
> POST /api/get_roster HTTP/1.1
> Host: localhost:5443
> User-Agent: curl/7.55.1
> Accept: */*
> X-Admin: true
> Authorization: Bearer 0GXCPVJa0l3jFH3Yrn9dIZFMftrNTBFa
> Content-Length: 7
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 7 out of 7 bytes
< HTTP/1.1 400 Bad Request
< Content-Length: 20
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Content-Type, Authorization, X-Admin
<
"Invalid JSON input"* Connection #0 to host localhost left intact
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: anas,/
* Could not resolve host: anas,
* Closing connection 1
curl: (6) Could not resolve host: anas,
Note: Unnecessary use of -X or --request, POST is already inferred.
* Rebuilt URL to: server:/
* Could not resolve host: server
* Closing connection 2
curl: (6) Could not resolve host: server
curl: (3) [globbing] unmatched close brace/bracket in column 10
ejabberd.log says:
2019-08-07 13:52:08.201 [debug] <0.841.0>#ejabberd_http:init:151 S: [{[<<"api">>],mod_http_api},{[<<"bosh">>],mod_bosh},{[<<"upload">>],mod_http_upload},{[<<"ws">>],ejabberd_http_ws},{[<<"oauth">>],ejabberd_oauth},{[<<"admin">>],ejabberd_web_admin}]
2019-08-07 13:52:08.202 [info] <0.695.0>#ejabberd_listener:accept:238 (<0.841.0>) Accepted connection 127.0.0.1:59208 -> 127.0.0.1:5443
2019-08-07 13:52:08.203 [debug] <0.841.0>#ejabberd_http:process_header:307 (#Port<0.54>) http query: 'POST' <<"/api/get_roster">>
2019-08-07 13:52:08.203 [debug] <0.841.0>#ejabberd_http:process:394 [<<"api">>,<<"get_roster">>] matches [<<"api">>]
2019-08-07 13:52:08.203 [debug] <0.841.0>#mod_http_api:process:198 Bad Request: {error,{1,invalid_json}}
I have tried ejabberd version 19.06 and 19.08.
ejabberd.yml
language: "en"
hosts:
- "localhost"
loglevel: 4
log_rotate_size: 10485760
log_rotate_date: ""
log_rotate_count: 1
log_rate_limit: 100
sql_type: mysql
sql_server: "localhost"
sql_database: "ejabberd"
sql_username: "ejabberd"
sql_password: "#######"
## If you want to specify the port:
sql_port: 3306
default_db: sql
auth_method: sql
certfiles:
- "C:/ProgramData/ejabberd/conf/server.pem"
## - "/etc/letsencrypt/live/localhost/fullchain.pem"
## - "/etc/letsencrypt/live/localhost/privkey.pem"
ca_file: "C:/ProgramData/ejabberd/conf/cacert.pem"
listen:
-
port: 5222
module: ejabberd_c2s
max_stanza_size: 262144
shaper: c2s_shaper
access: c2s
starttls_required: true
-
port: 5269
module: ejabberd_s2s_in
max_stanza_size: 524288
-
port: 5443
module: ejabberd_http
request_handlers:
"/api": mod_http_api
"/bosh": mod_bosh
"/upload": mod_http_upload
"/ws": ejabberd_http_ws
"/oauth": ejabberd_oauth
web_admin: true
captcha: false
tls: false
-
port: 5280
module: ejabberd_http
web_admin: true
-
port: 1883
module: mod_mqtt
backlog: 1000
s2s_use_starttls: optional
acl:
local:
user_regexp: ""
loopback:
ip:
- "127.0.0.0/8"
admin:
user:
- "admin#localhost"
access_rules:
local:
- allow: local
c2s:
- deny: blocked
- allow
announce:
- allow: admin
configure:
- allow: admin
muc_create:
- allow: local
pubsub_createnode:
- allow: local
register:
- allow
trusted_network:
- allow: loopback
api_permissions:
"console commands":
from:
- ejabberd_ctl
who: all
what: "*"
"admin access":
who:
- access:
- allow:
- acl: loopback
- acl: admin
- oauth:
- scope: "ejabberd:admin"
- access:
- allow:
- acl: loopback
- acl: admin
what:
- "*"
- "!stop"
- "!start"
"public commands":
who:
- ip: "127.0.0.1/8"
what:
- "status"
- "connected_users_number"
commands_admin_access:
- allow:
- user: "admin#localhost"
commands:
- add_commands: [user, admin, open]
oauth_expire: 31536000
oauth_access:
- allow:
- user: "admin#localhost"
shaper:
normal: 1000
fast: 50000
shaper_rules:
max_user_sessions: 10
max_user_offline_messages:
- 5000: admin
- 100
c2s_shaper:
- none: admin
- normal
s2s_shaper: fast
max_fsm_queue: 10000
acme:
contact: "mailto:admin#localhost"
ca_url: "https://acme-v01.api.letsencrypt.org"
modules:
mod_adhoc: {}
mod_admin_extra: {}
mod_announce:
access: announce
mod_avatar: {}
mod_blocking: {}
mod_bosh: {}
mod_caps: {}
mod_carboncopy: {}
mod_client_state: {}
mod_configure: {}
mod_disco: {}
mod_fail2ban: {}
mod_http_api: {}
mod_http_upload:
put_url: "https://#HOST#:5443/upload"
mod_last: {}
## mod_mam:
## Mnesia is limited to 2GB, better to use an SQL backend
## For small servers SQLite is a good fit and is very easy
## to configure. Uncomment this when you have SQL configured:
## db_type: sql
## assume_mam_usage: true
## default: always
mod_mqtt: {}
mod_muc:
access:
- allow
access_admin:
- allow: admin
access_create: muc_create
access_persistent: muc_create
default_room_options:
allow_subscription: true # enable MucSub
## mam: true
mod_muc_admin: {}
mod_offline:
access_max_user_messages: max_user_offline_messages
mod_ping: {}
mod_privacy: {}
mod_private: {}
mod_proxy65:
access: local
max_connections: 5
mod_pubsub:
access_createnode: pubsub_createnode
plugins:
- "flat"
- "pep"
force_node_config:
## Change from "whitelist" to "open" to enable OMEMO support
## See https://github.com/processone/ejabberd/issues/2425
"eu.siacs.conversations.axolotl.*":
access_model: whitelist
## Avoid buggy clients to make their bookmarks public
"storage:bookmarks":
access_model: whitelist
mod_push: {}
mod_push_keepalive: {}
mod_register:
## Only accept registration requests from the "trusted"
## network (see access_rules section above).
## Think twice before enabling registration from any
## address. See the Jabber SPAM Manifesto for details:
## https://github.com/ge0rg/jabber-spam-fighting-manifesto
ip_access: trusted_network
mod_roster:
versioning: true
mod_s2s_dialback: {}
mod_shared_roster: {}
mod_stream_mgmt:
resend_on_timeout: if_offline
mod_vcard: {}
mod_vcard_xupdate: {}
mod_version:
show_os: false
You attempt to provide JSON data, but as you can see, curl sends only 7 bytes of content. 7 bytes are only 7 characters, see this example:
$ curl -v -X POST -H "X-Admin: true" -H "Authorization: Bearer UsGV4Ap1zHaaNxJNLiYncn9QG5TRXfEW" http://localhost:5443/api/get_roster -d '{"abcde'
.....
> Content-Length: 7
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 7 out of 7 bytes
....
So there must be some problem in the console or program you use to run curl, which cuts the command line. In this example, as you can see, a good JSON data takes 40 bytes (in my case the problem is that I didn't set admin rights):
$ curl -v -X POST -H "X-Admin: true" -H "Authorization: Bearer UsGV4Ap1zHaaNxJNLiYncn9QG5TRXfEW" http://localhost:5443/api/get_roster -d '{"user": "user1", "server": "localhost"}'
Note: Unnecessary use of -X or --request, POST is already inferred.
* Expire in 1 ms for 1 (transfer 0x557900f65a30)
* Trying 127.0.0.1...
* TCP_NODELAY set
* Expire in 200 ms for 4 (transfer 0x557900f65a30)
* Connected to localhost (127.0.0.1) port 5443 (#0)
> POST /api/get_roster HTTP/1.1
> Host: localhost:5443
> User-Agent: curl/7.64.0
> Accept: */*
> X-Admin: true
> Authorization: Bearer UsGV4Ap1zHaaNxJNLiYncn9QG5TRXfEW
> Content-Length: 40
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 40 out of 40 bytes
< HTTP/1.1 403 Forbidden
< Content-Length: 111
< Content-Type: application/json
< Access-Control-Allow-Origin: *
< Access-Control-Allow-Headers: Content-Type, Authorization, X-Admin
<
* Connection #0 to host localhost left intact
{"status":"error","code":32,"message":"AccessRules: Account does not have the right to perform the operation."}
Related
I've found this: https://docs.ejabberd.im/admin/configuration/modules/#mod-muc
And this: https://docs.ejabberd.im/admin/ejabberdctl/muc-admin/#prerequisite
What are the steps I need to do to setup MUC from a fresh install? mod_muc is already in the ejabberd.yml file, and so is mod_muc_admin. I've also added myself as an admin.
Here is my ejabberd.yml file:
ubuntu#ip-10-0-1-208:/opt/ejabberd/conf$ cat ejabberd.yml
###
###' ejabberd configuration file
###
### The parameters used in this configuration file are explained at
###
### https://docs.ejabberd.im/admin/configuration
###
### The configuration file is written in YAML.
### *******************************************************
### ******* !!! WARNING !!! *******
### ******* YAML IS INDENTATION SENSITIVE *******
### ******* MAKE SURE YOU INDENT SECTIONS CORRECTLY *******
### *******************************************************
### Refer to http://en.wikipedia.org/wiki/YAML for the brief description.
###
hosts:
- ip-10-0-1-208.us-west-1.compute.internal
- xmpp.ughstudios.com
loglevel: info
certfiles:
- "/opt/ejabberd/conf/server.pem"
## - "/etc/letsencrypt/live/localhost/fullchain.pem"
## - "/etc/letsencrypt/live/localhost/privkey.pem"
ca_file: "/opt/ejabberd/conf/cacert.pem"
listen:
-
port: 5222
ip: "::"
module: ejabberd_c2s
max_stanza_size: 262144
shaper: c2s_shaper
access: c2s
starttls_required: true
-
port: 5269
ip: "::"
module: ejabberd_s2s_in
max_stanza_size: 524288
-
port: 5443
ip: "::"
module: ejabberd_http
tls: true
request_handlers:
"/admin": ejabberd_web_admin
"/api": mod_http_api
"/bosh": mod_bosh
"/captcha": ejabberd_captcha
"/upload": mod_http_upload
"/ws": ejabberd_http_ws
"/oauth": ejabberd_oauth
-
port: 5280
ip: "::"
module: ejabberd_http
request_handlers:
"/admin": ejabberd_web_admin
-
port: 1883
ip: "::"
module: mod_mqtt
backlog: 1000
s2s_use_starttls: optional
acl:
local:
user_regexp: ""
loopback:
ip:
- 127.0.0.0/8
- ::1/128
- ::FFFF:127.0.0.1/128
admin:
user:
- daniel#xmpp.ughstudios.com
auth_method: [external]
extauth_program: /opt/ejabberd_auth_bridge.py
extauth_instances: 3
auth_use_cache: true
access_rules:
local:
allow: local
c2s:
deny: blocked
allow: all
announce:
allow: admin
configure:
allow: admin
muc_create:
allow: local
pubsub_createnode:
allow: local
trusted_network:
allow: loopback
api_permissions:
"console commands":
from:
- ejabberd_ctl
who: all
what: "*"
"admin access":
who:
access:
allow:
acl: loopback
acl: admin
oauth:
scope: "ejabberd:admin"
access:
allow:
acl: loopback
acl: admin
what:
- "*"
- "!stop"
- "!start"
"public commands":
who:
ip: 127.0.0.1/8
what:
- status
- connected_users_number
shaper:
normal: 1000
fast: 50000
shaper_rules:
max_user_sessions: 10
max_user_offline_messages:
5000: admin
100: all
c2s_shaper:
none: admin
normal: all
s2s_shaper: fast
max_fsm_queue: 10000
acme:
contact: "mailto:admin#ip-10-0-1-208.us-west-1.compute.internal"
ca_url: "https://acme-v02.api.letsencrypt.org"
modules:
mod_adhoc: {}
mod_admin_extra: {}
mod_announce:
access: announce
mod_avatar: {}
mod_blocking: {}
mod_bosh: {}
mod_caps: {}
mod_carboncopy: {}
mod_client_state: {}
mod_configure: {}
mod_disco: {}
mod_fail2ban: {}
mod_http_api: {}
mod_http_upload:
put_url: https://#HOST#:5443/upload
mod_last: {}
mod_mam:
## Mnesia is limited to 2GB, better to use an SQL backend
## For small servers SQLite is a good fit and is very easy
## to configure. Uncomment this when you have SQL configured:
## db_type: sql
assume_mam_usage: true
default: never
mod_mqtt: {}
mod_muc:
access:
- allow
access_admin:
- allow: admin
- allow: daniel
- allow: david
#access_create: all
#access_persistent: all
access_mam:
- allow
default_room_options:
allow_subscription: true # enable MucSub
mam: false
mod_muc_admin: {}
mod_offline:
access_max_user_messages: max_user_offline_messages
mod_ping: {}
mod_privacy: {}
mod_private: {}
mod_proxy65:
access: local
max_connections: 5
mod_pubsub:
access_createnode: pubsub_createnode
plugins:
- flat
- pep
force_node_config:
## Avoid buggy clients to make their bookmarks public
storage:bookmarks:
access_model: whitelist
mod_push: {}
mod_push_keepalive: {}
mod_register:
## Only accept registration requests from the "trusted"
## network (see access_rules section above).
## Think twice before enabling registration from any
## address. See the Jabber SPAM Manifesto for details:
## https://github.com/ge0rg/jabber-spam-fighting-manifesto
ip_access: trusted_network
mod_roster:
versioning: true
mod_s2s_dialback: {}
mod_shared_roster: {}
mod_stream_mgmt:
resend_on_timeout: if_offline
mod_vcard: {}
mod_vcard_xupdate: {}
mod_version:
show_os: false
### Local Variables:
### mode: yaml
### End:
### vim: set filetype=yaml tabstop=8
What are the steps I need to do to setup MUC from a fresh install?
Usually mod_muc is already configured and enabled by default. Of course, if ejabberd is installed in a remote server, you will need to setup DNS for the MUC service, similar to what you may want to do for any other services that have their specific domain, like pubsub.example.org
I downloaded the XAMPP server which has Apache and MySQL in it. link: https://www.apachefriends.org/download.html
I downloaded the 20.01 version of the ejabberd installer for windows 10 OS. After that, I run the installer and installed the ejabberd in my Program files folder.
I created the ejabberd database in http://localhost/phpmyadmin/index.php and imported all the tables from mysql.sql file using C:\Program Files\ejabberd-20.01\lib\ejabberd-20.01\priv\sql folder.
Database setup completed. After that,
I configured the ejabberd.yml file.
After that, I installed the Pidgin Client for a chat then I started the ejabberd node.
According to the below ejabberd.yml configuration, The ejabberd node is running fine and I am able to chat with users in the Pidgin client.
I registered a new user in the ejabberd dashboard But I am not getting the message data and registered user data (username and password) into the PHPMyAdmin MySQL database.
My purpose for this issue is to use the ejabberd MySQL database which is already created by me in PHPMyAdmin. I want to store chat messages in the ejabberd MySQL database.
ejabberd.yml file:
hosts:
- "localhost"
loglevel: 4
log_rotate_size: 10485760
log_rotate_date: ""
log_rotate_count: 1
log_rate_limit: 100
certfiles:
- "C:/ProgramData/ejabberd/conf/server.pem"
## - "/etc/letsencrypt/live/localhost/fullchain.pem"
## - "/etc/letsencrypt/live/localhost/privkey.pem"
ca_file: "C:/ProgramData/ejabberd/conf/cacert.pem"
listen:
-
port: 5222
module: ejabberd_c2s
max_stanza_size: 262144
shaper: c2s_shaper
access: c2s
starttls_required: true
-
port: 5269
module: ejabberd_s2s_in
max_stanza_size: 524288
-
port: 5443
module: ejabberd_http
tls: true
request_handlers:
"/admin": ejabberd_web_admin
"/api": mod_http_api
"/bosh": mod_bosh
"/captcha": ejabberd_captcha
"/upload": mod_http_upload
"/ws": ejabberd_http_ws
"/oauth": ejabberd_oauth
-
port: 5280
module: ejabberd_http
request_handlers:
"/admin": ejabberd_web_admin
-
port: 1883
module: mod_mqtt
backlog: 1000
s2s_use_starttls: optional
acl:
local:
user_regexp: ""
loopback:
ip:
- 127.0.0.0/8
admin:
user:
- "admin#localhost"
sql_type: mysql
sql_server: "localhost"
sql_database: "ejabberd"
sql_username: "root"
sql_password: ""
access_rules:
local:
allow: local
c2s:
deny: blocked
allow: all
announce:
allow: admin
configure:
allow: admin
muc_create:
allow: local
pubsub_createnode:
allow: local
trusted_network:
allow: loopback
api_permissions:
"console commands":
from:
- ejabberd_ctl
who: all
what: "*"
"admin access":
who:
access:
allow:
acl: loopback
acl: admin
oauth:
scope: "ejabberd:admin"
access:
allow:
acl: loopback
acl: admin
what:
- "*"
- "!stop"
- "!start"
"public commands":
who:
ip: 127.0.0.1/8
what:
- status
- connected_users_number
shaper:
normal: 1000
fast: 50000
shaper_rules:
max_user_sessions: 10
max_user_offline_messages:
5000: admin
100: all
c2s_shaper:
none: admin
normal: all
s2s_shaper: fast
max_fsm_queue: 10000
acme:
contact: "mailto:admin#localhost"
ca_url: "https://acme-v01.api.letsencrypt.org"
modules:
mod_adhoc: {}
mod_admin_extra: {}
mod_announce:
access: announce
mod_avatar: {}
mod_blocking: {}
mod_bosh: {}
mod_caps: {}
mod_carboncopy: {}
mod_client_state: {}
mod_configure: {}
mod_disco: {}
mod_fail2ban: {}
mod_http_api: {}
mod_http_upload:
put_url: https://#HOST#:5443/upload
mod_last: {}
mod_mam:
## Mnesia is limited to 2GB, better to use an SQL backend
## For small servers SQLite is a good fit and is very easy
## to configure. Uncomment this when you have SQL configured:
## db_type: sql
assume_mam_usage: true
default: never
mod_mqtt: {}
mod_muc:
access:
- allow
access_admin:
- allow: admin
access_create: muc_create
access_persistent: muc_create
access_mam:
- allow
default_room_options:
allow_subscription: true # enable MucSub
mam: false
mod_muc_admin: {}
mod_offline:
access_max_user_messages: max_user_offline_messages
mod_ping: {}
mod_privacy: {}
mod_private: {}
mod_proxy65:
access: local
max_connections: 5
mod_pubsub:
access_createnode: pubsub_createnode
plugins:
- flat
- pep
force_node_config:
## Avoid buggy clients to make their bookmarks public
storage:bookmarks:
access_model: whitelist
mod_push: {}
mod_push_keepalive: {}
mod_register:
## Only accept registration requests from the "trusted"
## network (see access_rules section above).
## Think twice before enabling registration from any
## address. See the Jabber SPAM Manifesto for details:
## https://github.com/ge0rg/jabber-spam-fighting-manifesto
ip_access: trusted_network
mod_roster:
versioning: true
mod_s2s_dialback: {}
mod_shared_roster: {}
mod_stream_mgmt:
resend_on_timeout: if_offline
mod_vcard: {}
mod_vcard_xupdate: {}
mod_version:
show_os: false
### Local Variables:
### mode: yaml
### End:
### vim: set filetype=yaml tabstop=8
I registered a new user in the ejabberd dashboard But I am not getting the message data and registered user data (username and password) into the PHPMyAdmin MySQL database.
If you login in ejabberd WebAdmin with an admin account, and go to -> Nodes -> your node -> Database, you will see that the internal Mnesia table "passwd" has 1 Element. That means one account is registered in ejabberd, and stored in the Mnesia database. That's the internal database used by default.
ejabberd.yml file:
sql_type: mysql
sql_server: "localhost"
sql_database: "ejabberd"
sql_username: "root"
sql_password: ""
Ok, those options tell ejabberd what SQL database you want to use, and how to connect to it.
I want to store chat messages in the ejabberd MySQL database.
Then, tell ejabberd to use sql for the tasks that you want. For example, add also those options to your config:
auth_method: sql
default_db: sql
See:
https://docs.ejabberd.im/admin/configuration/toplevel/#auth-method
https://docs.ejabberd.im/admin/configuration/toplevel/#default-db
I'm trying to follow API Permissions | ejabberd Docs and Configuring ejabberd | ejabberd Docs.
yet while trying to register a user:
# curl -sk -d '{"user":"test", "password":"testing", "host":"localhost"}' -H 'Content-Type: application/json' https://localhost:5443/api/register
I get following in ejabberd.log:
# tail -2 ./home/ejabberd/logs/ejabberd.log
2019-10-04 21:41:47.079 [info] <0.663.0>#mod_http_api:log:509 API call register [{<<"user">>,<<"test">>},{<<"password">>,<<"testing">>},{<<"host">>,<<"localhost">>}] from ::ffff:172.19.0.1:53740
2019-10-04 21:41:47.079 [info] <0.521.0>#ejabberd_listener:accept:256 (<0.663.0>) Accepted connection [::ffff:172.19.0.1]:53740 -> [::ffff:172.19.0.6]:5443
#
ejabberd.yml' acl&api_permissions blocks:
acl:
local:
user_regexp: ""
loopback:
ip:
- 127.0.0.0/8
- ::1/128
- ::FFFF:127.0.0.1/128
admin:
user:
- "admin#localhost"
ip:
- ::/0
- ::FFFF:10.0.0.0/8
- ::FFFF:172.16.0.0/12
- ::FFFF:172.19.0.0/12
- ::FFFF:192.168.0.0/16
&
api_permissions:
"console commands":
from:
- ejabberd_ctl
who: all
what: "*"
"admin access":
who:
access:
allow:
acl: loopback
acl: admin
ip:
- ::/0
- ::FFFF:10.0.0.0/8
- ::FFFF:172.16.0.0/12
- ::FFFF:172.19.0.0/12
- ::FFFF:192.168.0.0/16
oauth:
scope: "ejabberd:admin"
access:
allow:
acl: loopback
acl: admin
what:
- "*"
- "!stop"
- "!start"
"public commands":
who:
ip: 127.0.0.1/8
what:
- status
- connected_users_number
Please advise.
I added my ip/range to admin AND loopback block:
acl:
local:
user_regexp: ""
loopback:
ip:
- 127.0.0.0/8
- ::1/128
- ::FFFF:127.0.0.1/128
- ::FFFF:172.19.0.0/16
admin:
user:
- "admin#localhost"
ip:
- ::FFFF:172.19.0.0/16
and the error went away)
With this minimal configuration:
listen:
-
port: 5443
ip: "::"
module: ejabberd_http
tls: true
request_handlers:
"/api": mod_http_api
acl:
admin:
ip:
- "127.0.0.1"
api_permissions:
"admin commands":
who: admin
what:
- register
If I execute this in machine 127.0.0.1, it works:
$ curl -sk -d '{"user":"test", "password":"testing", "host":"localhost"}' -H 'Content-Type: application/json' https://localhost:5443/api/register
"User test#localhost successfully registered"
I have my rails app. And whenever user registers, I want to register user on ejabberd node as well. But, whenever i call register API using curl request, it gives be following error:
{"status":"error","code":32,"message":"AccessRules: Account does not have the right to perform the operation."}
My curl request is:
curl -X POST --data '{"user": "bob", "host": "localhost", "password": "password"}' http://localhost:5443/api/register
My ejabberd.yml file is as below:
hosts:
- "localhost"
loglevel: 5
log_rotate_size: 10485760
log_rotate_date: ""
log_rotate_count: 1
log_rate_limit: 100
certfiles:
- "/etc/letsencrypt/live/localhost/fullchain.pem"
- "/etc/letsencrypt/live/localhost/privkey.pem"
listen:
-
port: 5222
ip: "::"
module: ejabberd_c2s
max_stanza_size: 262144
shaper: c2s_shaper
access: c2s
starttls_required: false
-
port: 5269
ip: "::"
module: ejabberd_s2s_in
max_stanza_size: 524288
-
port: 5443
ip: "0.0.0.0"
module: ejabberd_http
request_handlers:
"/api": mod_http_api
"/bosh": mod_bosh
"/upload": mod_http_upload
"/ws": ejabberd_http_ws
"/oauth": ejabberd_oauth
web_admin: true
captcha: true
tls: false
commands_admin_access: configure
commands:
- add_commands: [user, admin, open]
oauth_expire: 3600
oauth_access: all
s2s_use_starttls: optional
acl:
admin:
user:
- "admin#localhost"
local:
user_regexp: ""
loopback:
ip:
- "127.0.0.0/8"
- "::1/128"
- "::FFFF:127.0.0.1/128"
access_rules:
local:
- allow: local
c2s:
- deny: blocked
- allow
announce:
- allow: admin
configure:
- allow: admin
muc_create:
- allow: local
pubsub_createnode:
- allow: local
register:
- allow
trusted_network:
- allow: loopback
oauth:
- scope: "ejabberd:admin"
- allow: admin
api_permissions:
"console commands":
from:
- ejabberd_ctl
who: all
what: "*"
"admin access":
who:
- access:
- allow:
- acl: admin#localhost
- oauth:
- scope: "ejabberd:admin"
- access:
- allow:
- acl: admin#localhost
what:
- "*"
- "!stop"
- "!start"
"public commands":
who:
- ip: "0.0.0.0"
what:
- "register"
- "status"
- "connected_users_number"
shaper:
normal: 1000
fast: 50000
shaper_rules:
max_user_sessions: 10
max_user_offline_messages:
- 5000: admin
- 100
c2s_shaper:
- none: admin
- normal
s2s_shaper: fast
modules:
mod_adhoc: {}
mod_admin_extra: {}
mod_announce:
access: announce
mod_avatar: {}
mod_blocking: {}
mod_bosh: {}
mod_caps: {}
mod_carboncopy: {}
mod_client_state: {}
mod_configure: {}
mod_disco: {}
mod_fail2ban: {}
mod_http_api: {}
mod_http_upload:
put_url: "https://#HOST#:5443/upload"
mod_last: {}
mod_mam:
## Mnesia is limited to 2GB, better to use an SQL backend
## For small servers SQLite is a good fit and is very easy
## to configure. Uncomment this when you have SQL configured:
## db_type: sql
assume_mam_usage: true
default: always
mod_muc:
access:
- allow
access_admin:
- allow: admin
access_create: muc_create
access_persistent: muc_create
default_room_options:
mam: true
mod_muc_admin: {}
mod_offline:
access_max_user_messages: max_user_offline_messages
mod_ping: {}
mod_privacy: {}
mod_private: {}
mod_proxy65:
ip: "localhost"
access: local
max_connections: 5
mod_pubsub:
access_createnode: pubsub_createnode
plugins:
- "flat"
- "pep"
force_node_config:
## Change from "whitelist" to "open" to enable OMEMO support
## See https://github.com/processone/ejabberd/issues/2425
"eu.siacs.conversations.axolotl.*":
access_model: whitelist
## Avoid buggy clients to make their bookmarks public
"storage:bookmarks":
access_model: whitelist
mod_push: {}
mod_push_keepalive: {}
mod_register:
## Only accept registration requests from the "trusted"
## network (see access_rules section above).
## Think twice before enabling registration from any
## address. See the Jabber SPAM Manifesto for details:
## https://github.com/ge0rg/jabber-spam-fighting-manifesto
ip_access: trusted_network
mod_roster:
versioning: true
mod_s2s_dialback: {}
mod_shared_roster: {}
mod_stream_mgmt:
resend_on_timeout: if_offline
mod_vcard: {}
mod_vcard_xupdate: {}
mod_version:
show_os: false
Can someone point me where exactly I might be wrong?
Thanks in advance.
If you want to use mod_http_api from localhost to register accounts, you can grant it permission in this way:
api_permissions:
"http_api commands":
who:
- ip: "127.0.0.1"
from:
- mod_http_api
what:
- "register"
See https://docs.ejabberd.im/developer/ejabberd-api/permissions/
Are you logged in before requesting this? or r u using any kind of authentication mechanism?
If you r requesting without this try adding the ip from which you are requesting insode
"public commands":
who:
- ip: "0.0.0.0"
what:
- "register"
- "status"
- "connected_users_number"
part.
Else try adding allow all under register in api_permission section
I want my users to be able to block each other. So I did some research and figured out that it can be done with privacy_set.
So I added mod_privacy and mod_blocking in config file.
The problem is when I run the following command nothing is getting inserted in mysql.
I copied xml from here.
ejabberdctl privacy_set userA localhost "<iq from='userA#localhost/l' type='set' id='block1'> <block xmlns='urn:xmpp:blocking'> <item jid='userB#montague.net'/> </block> </iq>"
I also tied this one, still no luck:
Copied from here
ejabberdctl privacy_set userA localhost "<iq from='userA#localhost/l' type='set' id='iq1'> <query xmlns='jabber:iq:privacy'> <list name='iq-jid-example'> <item type='jid' value='userB#localhost' action='deny' order='29'> <iq/> </item> </list> </query> </iq>"
This is the content of my ejabberd yml file:
loglevel: 5
log_rotate_size: 10485760
log_rotate_date: ""
log_rotate_count: 1
log_rate_limit: 100
watchdog_admins:
- "admin#localhost"
acl:
admin:
user:
- "admin": "localhost"
access:
configure:
admin: allow
webadmin_view:
viewers: allow
hosts:
- "localhost"
listen:
-
port: 5222
module: ejabberd_c2s
max_stanza_size: 65536
shaper: c2s_shaper
access: c2s
-
port: 5281
module: ejabberd_http
request_handlers:
## "/oauth": ejabberd_oauth
"/api": mod_http_api
web_admin: true
http_bind: true
http_poll: true
captcha: false
commands_admin_access:
- allow:
- user: "admin#localhost"
commands:
- add_commands: [send_stanza, destroy_room, connected_users_info, get_room_options, user, admin, open, status, stats, connecteo_users, get_vcard, change_password, check_account, register, create_room, create_room_with_opts, send_direct_invitation]
oauth_access: all
modules:
mod_vcard: {}
mod_ping: {}
mod_admin_extra: {}
mod_mam: {}
mod_roster: {}
mod_shared_roster: {}
mod_stats: {}
mod_offline: {}
mod_privacy:
db_type: sql
mod_blocking: {}
api_permissions:
"console commands":
from:
- ejabberd_ctl
who: all
what: "*"
"admin access":
who:
- admin
- oauth:
- scope: "ejabberd:admin"
- admin
what:
- "*"
- "!stop"
- "!start"
shaper_rules:
max_user_sessions: 10
max_user_offline_messages:
- 5000: admin
- 100
c2s_shaper:
- none: admin
- normal
s2s_shaper: fast
access_rules:
local:
- allow: local
c2s:
- deny: blocked
- allow
announce:
- allow: admin
configure:
- allow: all
register:
- allow
trusted_network:
- allow: loopback
auth_password_format: scram
auth_method: sql
default_db: sql
sql_type: mysql
sql_server: "localhost"
sql_database: "ejabberd"
sql_username: "ejabberd"
sql_password: "123456"
## If you want to specify the port:
sql_port: 3306
Any help would be appreciated.
I found the answer with the help from a console based XMPP client called Profanity
This is how it can be done:
ejabberdctl send_stanza_c2s userA localhost l '<iq id="1212" type="set"><block xmlns="urn:xmpp:blocking"><item jid="userB#localhost"/></block></iq>'