Open handokochen opened 8 years ago
hello, im running ejabberd 15.11 and have the same problem, server throws the warning on startup, and all requests end up with 401 unauthorized and the server throws the proccessing error.
heres my request:
POST /api/admin HTTP/1.1
Host: 10.0.0.72:8088
Authorization: Basic YWRtaW5Aa2Fib28tcGMtNC5sb2NhbDprb3NpY2U=
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: c1fc543c-cf26-7d80-25fd-a33ddca93386
{"command":"status"}
configuration:
listen:
-
port: 8088
ip: "::" ## also tried "0.0.0.0"
module: ejabberd_http
request_handlers:
"/api": mod_restful
modules:
mod_restful:
api:
- path: ["admin"]
module: mod_restful_admin
params:
allowed_commands: [status] ## also tried with ["status"]
and the error:
18:27:51.753 [error] Processing throwed error {badmatch,false}
trace: [{mod_restful,handle_request,3,[{file,"src/mod_restful.erl"},{line,179}]},{mod_restful,process,2,[{file,"src/mod_restful.erl"},{line,161}]},{ejabberd_http,process,5,[{file,"src/ejabberd_http.erl"},{line,360}]},{ejabberd_http,process_request,1,[{file,"src/ejabberd_http.erl"},{line,448}]},{ejabberd_http,process_header,2,[{file,"src/ejabberd_http.erl"},{line,290}]},{ejabberd_http,parse_headers,1,[{file,"src/ejabberd_http.erl"},{line,210}]},{ejabberd_http,init,2,[{file,"src/ejabberd_http.erl"},{line,163}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]
finally got it working, it looks like you have to send empty args parameter to commands that dont require any, like status
for example.
so long story short, here are request and configuration examples that work with ejabberd 15.11 config:
listen:
-
port: 8088
ip: "::"
module: ejabberd_http
request_handlers:
"/api": mod_restful
modules:
mod_restful:
api:
-
path: ["admin"]
module: mod_restful_admin
params:
key: "secret" ## if you want to use basic auth, you need to remove this line
allowed_commands: [srg_create, srg_user_add, status, registered_users]
request without args:
POST /api/admin HTTP/1.1
Host: localhost:8088
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: ef2fb0d4-34e5-890c-39b5-6f7a524c4353
{"key":"secret", "command":"status", "args":[]}
response:
{
"ok": "The node ejabberd@localhost is started. Status: startedejabberd 15.11 is running in that node"
}
request with args:
POST /api/admin HTTP/1.1
Host: localhost:8088
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: 6a6d90d6-dd3b-5932-3c59-5cc89e8af4d2
{"key":"secret", "command":"srg-create", "args":["a", "localhost", "b", "c", "a"]}
response:
"ok"
but there is some issue with command registered_users
because the response i get is 400 bad request
and the server throws following error: ('123456admin' is the name of first user, theres 118 users in total)
Processing throwed error badarg
trace: [{erlang,list_to_binary,[<<"123456admin">>],[]},{mod_restful_admin,format_result_json,2,[{file,"src/mod_restful_admin.erl"},{line,188}]},{mod_restful_admin,format_result_json,2,[{file,"src/mod_restful_admin.erl"},{line,196}]},{mod_restful_admin,format_result,3,[{file,"src/mod_restful_admin.erl"},{line,176}]},{mod_restful_admin,do_process,1,[{file,"src/mod_restful_admin.erl"},{line,89}]},{mod_restful,handle_rest_request,5,[{file,"src/mod_restful.erl"},{line,193}]},{mod_restful,process,2,[{file,"src/mod_restful.erl"},{line,161}]},{ejabberd_http,process,5,[{file,"src/ejabberd_http.erl"},{line,360}]}]
heres the request for reference:
POST /api/admin HTTP/1.1
Host: localhost:8088
Content-Type: application/json
Cache-Control: no-cache
Postman-Token: c333d3a6-8b07-e13c-5607-1ef97ca9cf23
{"key":"secret", "command":"registered_users", "args":["kaboo-pc-4.local"]}
Hi,
I installed the ejabberd 15.09 via the osx installer and installed the mod_restful module via ejabberdctl module_install.
Warnings on module_install: src/mod_restful_admin.erl:63: Warning: behaviour gen_restful_api undefined src/mod_restful_register.erl:32: Warning: behaviour gen_restful_api undefined
Here's my yml: mod_restful: api:
Warning on ejabberd start up: 2015-10-05 13:02:30.594 [warning] <0.37.0>@gen_mod:validate_opts:255 module 'mod_restful' doesn't export mod_opt_type/1
Here's the error I got: 2015-10-05 13:24:30.118 [debug] <0.470.0>@ejabberd_http:process_header:283 (#Port<0.4074>) http query: 'GET' <<"/api/register/is_registered?username=admin&host=chat.myhost.com&key=secret">> 2015-10-05 13:24:30.118 [debug] <0.470.0>@ejabberd_http:process:361 [<<"api">>,<<"register">>,<<"is_registered">>] matches [<<"api">>] 2015-10-05 13:24:30.119 [error] <0.470.0> Processing throwed error {badmatch,false} trace: [{mod_restful,handle_request,3,[{file,"src/mod_restful.erl"},{line,179}]},{mod_restful,process,2,[{file,"src/mod_restful.erl"},{line,161}]},{ejabberd_http,process,5,[{file,"src/ejabberd_http.erl"},{line,371}]},{ejabberd_http,process_request,1,[{file,"src/ejabberd_http.erl"},{line,459}]},{ejabberd_http,process_header,2,[{file,"src/ejabberd_http.erl"},{line,293}]},{ejabberd_http,parse_headers,1,[{file,"src/ejabberd_http.erl"},{line,209}]},{ejabberd_http,init,2,[{file,"src/ejabberd_http.erl"},{line,163}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,237}]}]
I'm pretty new at ejabberd, so any help is appreciated.