Add option to mod_ctlextra, something get wrong ?

hi all,

I tryed to add an option to mod_ctlextra to get the password of a user. SO i tryed this

in mod_ctlextra I added these few lines of code.

{"get-password user server", "get password to user@server"},

and

ctl_process(_Val, ["get-password", User, Server]) ->
    {ok, Res} = ejabberd_auth:get_password(User, Server),
    io:format("~s~n", [Res]),
    ?STATUS_SUCCESS;

when I try to use ejabberdctl get-password xxx myserver , I got the error "unknow command", I restarted the server but no change :/

I only want to get 2 things:
* user password
here in the db :
{passwd,{"johnny","myserver .com"},"12345"}.

*user group from shared roster group
here in the db:
{sr_user,{"johnny","myserver .com"},
{"newbies_group","myserver .com"}}.

actually I'm doing a dump of the DB the use some php to digg in and found the infos, but the db is getting big and it takes lot of time to find the infos.

anyway a small piece of code to explain how to connect to ejabber mnesia db from an erl module woudl be really helpfull. Then I can use a php exec command to get back the value.

Any help would be greatlly apreciated.

Best regards,
kollo

Try this patch

Try this patch:

--- src/mod_ctlextra.erl        (revisión: 873)
+++ src/mod_ctlextra.erl        (copia de trabajo)
@@ -49,6 +49,7 @@
      {"delete-older-users days", "delete users that have not logged in the last 'days'"},
      {"delete-older-users-vhost host days", "delete users that not logged in last 'days' in 'host'"},
      {"set-password user server password", "set password to user@server"},
+     {"get-password user server", "get password of user@server"},

      %% ejd2odbc
      {"export2odbc server output", "export Mnesia tables on server to files on output directory"},
@@ -143,6 +144,18 @@
     ejabberd_auth:set_password(User, Server, Password),
     ?STATUS_SUCCESS;

+ctl_process(_Val, ["get-password", User, Server]) ->
+    case ejabberd_auth:get_password(User, Server) of
+       false ->
+           Res = "Account does not exist",
+           io:format("~s~n", [Res]),
+           ?STATUS_ERROR;
+       Password when is_list(Password) ->
+           Res = Password,
+           io:format("~s~n", [Res]),
+           ?STATUS_SUCCESS
+    end;
+
 ctl_process(_Val, ["vcard-get", User, Server, Data]) ->
     {ok, Res} = vcard_get(User, Server, [Data]),
     io:format("~s~n", [Res]),

working :)

thanks badlop, you are the king :)

I did something a bit similar but without the check. thanks again, I get your code.

regards,
kollo

Syndicate content