Adding user using mod_rest and by sending iq

I have installed ejabberd 2.1.4, with mod_rest support and configured them
Now what am trying to do is to add user using mod_rest, i tried all the possible ways but nothing worked!!

1- i tried sending iq stanza, i sent the following

and i can see the following in ejabberd log:

=INFO REPORT==== 2010-09-29 14:03:39 ===
I(<0.361.0>:ejabberd_listener:232) : (#Port<0.1932>) Accepted connection { {my, ip, address,here} , port} -> {{chat,ip,address,here},5280}

=INFO REPORT==== 2010-09-29 14:03:39 ===
I(<0.1863.0>:ejabberd_http:137) : started: {gen_tcp,#Port<0.1932>}

=INFO REPORT==== 2010-09-29 14:03:39 ===
I(<0.1863.0>:mod_rest:74) : Got valid request from user@chat.mysite.com
with IP {{my, ip, address,here} , port}
to chat,ip,address,here:
{xmlelement,"iq",
[{"from","user@chat.mysite.com"},
{"id","add-user-1"},
{"to","chat,ip,address,here"},
{"type","set"},
{"xml:lang","en"}],
[{xmlelement,"command",
[{"xmlns","http://jabber.org/protocol/commands"},
{"action","execute"},
{"node",
"http://jabber.org/protocol/admin#add-user"}],
[]}]}

And OK is returned to me, while i cant see any user added.

2- Also in mod_rest documentation it says :
"If you configure access_commands in mod_rest, you need to provide information
about a local Jabber account with enough privileges according to your option:
--auth robot localhost pass0011 registered_users localhost"

I tried sending the following command:

But all i see in ejabberd log is :
=INFO REPORT==== 2010-09-29 14:09:16 ===
I(<0.361.0>:ejabberd_listener:232) : (#Port<0.1945>) Accepted connection {{user@chat.mysite.com},port} -> {{chat,ip,address,here},5280}

=INFO REPORT==== 2010-09-29 14:09:16 ===
I(<0.1866.0>:ejabberd_http:137) : started: {gen_tcp,#Port<0.1945>}

=INFO REPORT==== 2010-09-29 14:09:16 ===
I(<0.1866.0>:mod_rest:92) : Data: "register user chat.mysite.com password"

i also tried sending
"--auth username myHost password registered_users myHost"

Simply No command is working with me..

Can anyone tell me what am doing wrong? i started to get depressed :(

P.S: sorry for the long message

Try a simple module

Try a simple module configuration, without access restrictions:

  {mod_rest, []},

Execute a simple call, for example this python file:

import urllib2

server_url = 'http://localhost:5280/rest/'

call = 'register user1 localhost pass123'
resp = urllib2.urlopen(server_url, call)
result = resp.read()
print result

Execute it and you should get a valid response, and the account is registered

$ python aa.py
User user1@localhost successfully registered

$ ejabberdctl registered_users localhost
admin
user1

Once this simple configuration works, you can try to configure the access option and provide the access parameter in the call.

I am a newbie to ejabberd..

I removed all the restrictions from mod_rest configurations,
Sent : "registered_users chat.mydomain.com"

still i get the following in log :
=INFO REPORT==== 2010-10-05 14:15:22 ===
I(<0.355.0>:ejabberd_listener:232) : (#Port<0.443>) Accepted connection {{my,ip_address,here},34149} -> {{my,server,ip,here},5280}

=INFO REPORT==== 2010-10-05 14:15:22 ===
D(<0.370.0>:ejabberd_http:135) : S: [{["web"],mod_http_fileserver},
{["rest"],mod_rest},
{["admin"],ejabberd_web_admin},
{["http-bind"],mod_http_bind},
{["http-poll"],ejabberd_http_poll}]

=INFO REPORT==== 2010-10-05 14:15:22 ===
I(<0.370.0>:ejabberd_http:137) : started: {gen_tcp,#Port<0.443>}

=INFO REPORT==== 2010-10-05 14:15:22 ===
D(<0.370.0>:ejabberd_http:254) : (#Port<0.443>) http query: 'POST' /rest

=INFO REPORT==== 2010-10-05 14:15:22 ===
D(<0.370.0>:ejabberd_http:420) : client data: "registered_users chat.mydomain.com"

=INFO REPORT==== 2010-10-05 14:15:22 ===
D(<0.370.0>:ejabberd_http:323) : ["rest"] matches ["rest"]

=INFO REPORT==== 2010-10-05 14:15:22 ===
I(<0.370.0>:mod_rest:92) : Data: "registered_users chat.mydomain.com"

=INFO REPORT==== 2010-10-05 14:15:22 ===
D(<0.370.0>:mod_rest:58) : Error when processing REST request:
Data: "registered_users chat.mydomain.com"
Error: {badmatch,false}

Another thing i need to verify, i read that i can query for all online users, so i send the following command:

i can see that the command is parsed and executed correctly, but how can i use this info? i mean i am supposed to receive it somewhere in the response , right? because i dont get anything except "OK", can i get it as xml? or response? or anything i can parse and use?

Thanks a lot!

mod_rest not running

nouralk wrote:

=INFO REPORT==== 2010-10-05 14:15:22 ===
D(<0.370.0>:mod_rest:58) : Error when processing REST request:
Data: "registered_users chat.mydomain.com"
Error: {badmatch,false}

That strange error report probably indicates that you don't have mod_rest running in the vhost chat.mydomain.com.

You must have something like this in your ejabberd.cfg

{modules, [
  {mod_rest, []},
  ...
]}.

Go to ejabberd Web Admin -> Nodes -> your node -> Vhosts -> chat.mydomain.com -> Modules -> check that mod_rest is mentioned in that list.

My configurations are

i do have it active, and when i already iq stanze sent to http://chat.mydomain.com:5280/rest to register and unregister users... but using a command in the format:

register user domain password
registered_users ....

Such commands give me this error...

My configurations for modules are as follwoing :

{modules,
[
{mod_adhoc, []},
{mod_announce, [{access, announce}]}, % requires mod_adhoc
{mod_caps, []},
{mod_configure,[]}, % requires mod_adhoc
{mod_disco, []},
%%{mod_echo, [{host, "echo.im.bayt.com"}]},
{mod_http_bind,[]},
{mod_http_fileserver, [
{docroot, "/var/www"},
{accesslog, "/opt/ejabberd-2.0.0/var/log/ejabberd/access.log"}
]},
{mod_irc, []},
{mod_last_odbc, []},
{mod_muc, [
%%{host, "conference.@HOST@"},
{access, muc},
{access_create, muc_create},
{access_persistent, muc_create},
{access_admin, muc_admin}
]},
%%{mod_muc_log,[]},
{mod_offline_odbc, []},
{mod_privacy_odbc, []},
{mod_private_odbc, []},
%%{mod_proxy65,[]},
{mod_pubsub_odbc, [ % requires mod_caps
{access_createnode, pubsub_createnode},
{ignore_pep_from_offline, true},
{last_item_cache, false},
{plugins, ["flat_odbc", "hometree_odbc", "pep_odbc"]}
]},
{mod_register, [
%%
%% After successful registration, the user receives
%% a message with this subject and body.
%%
{welcome_message, {"Welcome!",
"Welcome to this Jabber server."}},

%%
%% When a user registers, send a notification to
%% these Jabber accounts.
%%
%%{registration_watchers, ["admin1@example.org"]},
{registration_timeout, infinity},
{access, register}
]},
{mod_roster_odbc,[]},
%%{mod_service_log,[]},
{mod_shared_roster,[]},
%%{mod_stats,[]},
{mod_time,[]},
{mod_vcard_odbc,[{search, false}]},
{mod_version,[]},
{mod_rest, [
{allowed_ips, [ {127,0,0,1}]}
]}
]}.

I need help in my second question please.. how can i receive all the users registered to my server? i send an iq to get all users and i can see in the log that it listed all my registered users jid's but how can i use them? can't i receive them in xml format? or as a response for the request?

Thanks for your awesome fast reply :)

Re:

nouralk wrote:

when i already iq stanze sent to http://chat.mydomain.com:5280/rest to register and unregister users... but

i send an iq to get all users and i can see in the log that it listed all my registered users jid's but how can i use them? can't i receive them in xml format? or as a response for the request?

mod_rest can send XMPP stanzas, but not receive them.

mod_rest can execute commands, receive a response and show it in the shell.

Another way to execute ejabberd commands and receive responses in your Python program is to install ejabberd_xmlrpc listener, and make XMLRPC calls instead of REST calls.

nouralk wrote:

using a command in the format:

register user domain password
registered_users ....

Such commands give me this error...

My configurations for modules are as follwoing :

With that configuration, those commands work for me correctly.

Try to update mod_rest of SVN. I added some more detailed error reports, maybe they clarify what is your problem.

Hi Badlop, is there any way

Hi Badlop,

is there any way to receive the stanza result from mod_rest?

is this an easy modify? or we can't because of an async process of stanzas... ?

another question:
is there a way to send 2 or more stanzas to mod_rest without open another connection?
A single mod_rest request takes 1 msec with PHP, if i have to do 10 request it takes too much for a realtime purpose... maybe that with only 1 connection and many stanzas it will be faster.

thanks

PS:
i know about xmlrpc but mod_rest is more efficent and i have to handle pubsub

meblabs wrote: is there any

meblabs wrote:

is there any way to receive the stanza result from mod_rest?

is this an easy modify? or we can't because of an async process of stanzas... ?

Not implemented, and it seems difficult to implement.

meblabs wrote:

another question:
is there a way to send 2 or more stanzas to mod_rest without open another connection?
A single mod_rest request takes 1 msec with PHP, if i have to do 10 request it takes too much for a realtime purpose... maybe that with only 1 connection and many stanzas it will be faster.

It would be nice, but it is'nt immediately implementable, either.

Hi Again!

Hi Badlop,
thanks for your prompt response, i took you advice in consideration, and i installed ejabberd_xmlrpc with all its dependences, and i checked that am listening on the port 4560, but each time i submit a request i get the following:

=ERROR REPORT==== 2010-10-26 07:41:10 ===
{tcp_serv,139,{xmlrpc_http,handler,timeout}}

i checked my configurations and its all okay, i looked into the community but haven't found anyone in my case, how can i know if am sending the right command?
i tried sending many commands like:

xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, user_resources, [{struct, [{user, "testuser"}, {host, "localhost"}]}]}).

but i get the same result, the connection is not even accepted in the log.

No idea, just some tests

Make sure you don't have any error message when ejabberd starts.

I configure loglevel to 5, and perform those tests in the same machine that has ejabberd installed.

$ cd ejabberd/src

$ erl
Erlang R13B04 (erts-5.7.5) [source] [smp:2:2] [rq:2] [async-threads:0] [kernel-poll:false]

Eshell V5.7.5  (abort with ^G)

1> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, user_resources, 
[{struct, [{user, "testuser"}, {host, "localhost"}]}]}).
{ok,{response,[{struct,[{resources,{array,[]}}]}]}}

2> xmlrpc:call({127, 0, 0, 1}, 4560, "/", {call, user_resourcessssssss, 
[{struct, [{user, "testuser"}, {host, "localhost"}]}]}).
{ok,{response,{fault,-112,
"Error -112\nUnknown call: {call,user_resourcessssssss,\n
[{struct,[{user,\"testuser\"},{host,\"localhost\"}]}]}"}}}

3> xmlrpc:call({127, 0, 0, 1}, 6666, "/", {call, user_resources,
 [{struct, [{user, "testuser"}, {host, "localhost"}]}]}).
{error,econnrefused}

ejabberd.log only shows those messages, for command 1 and 2:

(ejabberd@localhost)1>
=INFO REPORT==== 28-Oct-2010::00:01:51 ===
D(<0.399.0>:ejabberd_commands:314) : Executing command ejabberd_sm:user_resources
 with Args=["testuser", "localhost"]

=WARNING REPORT==== 28-Oct-2010::00:03:37 ===
W(<0.401.0>:ejabberd_xmlrpc:328) : Error -112
Unknown call: {call,user_resourcessssssss,
                    [{struct,[{user,"testuser"},{host,"localhost"}]}]}

Then I try:

$ telnet 127.0.0.1 4560
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.

aaaaaaaaa

HTTP/1.1 400 Bad Request
Content-Length: 0
Server: Erlang/1.13
Content-Type: text/xml

Connection closed by foreign host.

And ejabberd.log shows:

=ERROR REPORT==== 28-Oct-2010::00:08:03 ===
{tcp_serv,139,{xmlrpc_http,handler,timeout}}
Syndicate content