Update mod_shcommands to work with ejabberd git master
This commit is contained in:
parent
350d4d3884
commit
4b117b5fe5
|
@ -2,7 +2,7 @@
|
||||||
mod_shcommands - Execute shell commands
|
mod_shcommands - Execute shell commands
|
||||||
|
|
||||||
Author: Badlop
|
Author: Badlop
|
||||||
http://ejabberd.jabber.ru/mod_shcommands
|
http://ejabberd.im/mod_shcommands
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -63,9 +63,5 @@ administrators.
|
||||||
===================
|
===================
|
||||||
|
|
||||||
Add the module to your ejabberd.cfg, on the modules section:
|
Add the module to your ejabberd.cfg, on the modules section:
|
||||||
{modules, [
|
modules:
|
||||||
...
|
mod_shcommands: {}
|
||||||
{mod_shcommands, []},
|
|
||||||
...
|
|
||||||
]}.
|
|
||||||
|
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
-include("jlib.hrl").
|
||||||
-include("web/ejabberd_http.hrl").
|
-include("ejabberd_http.hrl").
|
||||||
-include("web/ejabberd_web_admin.hrl").
|
-include("ejabberd_web_admin.hrl").
|
||||||
|
|
||||||
%%-------------------
|
%%-------------------
|
||||||
%% gen_mod functions
|
%% gen_mod functions
|
||||||
|
@ -112,10 +112,10 @@ parse_and_execute(Query, Node) ->
|
||||||
|
|
||||||
get_val(Val, Query) ->
|
get_val(Val, Query) ->
|
||||||
{value, {_, R}} = lists:keysearch(Val, 1, Query),
|
{value, {_, R}} = lists:keysearch(Val, 1, Query),
|
||||||
R.
|
binary_to_list(R).
|
||||||
|
|
||||||
parse1_command(<<"executectl">>, {Command, _, _}, Node) ->
|
parse1_command(<<"executectl">>, {Command, _, _}, Node) ->
|
||||||
Command2 = string:tokens(Command, <<" ">>),
|
Command2 = string:tokens(Command, " "),
|
||||||
{_E, Efile} = execute(ctl, Node, Command2),
|
{_E, Efile} = execute(ctl, Node, Command2),
|
||||||
io_lib:format("ejabberdctl ~p ~s~n~s", [Node, Command, Efile]);
|
io_lib:format("ejabberdctl ~p ~s~n~s", [Node, Command, Efile]);
|
||||||
|
|
||||||
|
@ -129,13 +129,13 @@ parse1_command(<<"executeshe">>, {_, _, Command}, Node) ->
|
||||||
E = rpc:call(Node, os, cmd, [Command]),
|
E = rpc:call(Node, os, cmd, [Command]),
|
||||||
C1 = lists:map(
|
C1 = lists:map(
|
||||||
fun(C) -> string:strip(os:cmd(C), right, $\n) end,
|
fun(C) -> string:strip(os:cmd(C), right, $\n) end,
|
||||||
[<<"whoami">>, <<"hostname -s">>, <<"pwd">>]),
|
["whoami", "hostname -s", "pwd"]),
|
||||||
io_lib:format("~s@~s:~s$ ~s~n~s", C1 ++ [Command, E]).
|
io_lib:format("~s@~s:~s$ ~s~n~s", C1 ++ [Command, E]).
|
||||||
|
|
||||||
|
|
||||||
execute(Type, Node, C) ->
|
execute(Type, Node, C) ->
|
||||||
GL = group_leader(),
|
GL = group_leader(),
|
||||||
Filename = <<"temp">> ++ io_lib:format("~p", [random:uniform()*10000]),
|
Filename = "temp" ++ io_lib:format("~p", [random:uniform()*10000]),
|
||||||
{ok, File} = file:open(Filename, [write]),
|
{ok, File} = file:open(Filename, [write]),
|
||||||
group_leader(File, self()),
|
group_leader(File, self()),
|
||||||
Res = case Type of
|
Res = case Type of
|
||||||
|
@ -152,6 +152,6 @@ execute(Type, Node, C) ->
|
||||||
file:delete(Filename),
|
file:delete(Filename),
|
||||||
E2 = case binary_to_list(B) of
|
E2 = case binary_to_list(B) of
|
||||||
[] -> [];
|
[] -> [];
|
||||||
List -> <<"\n">>++List
|
List -> "\n"++List
|
||||||
end,
|
end,
|
||||||
{E, E2}.
|
{E, E2}.
|
||||||
|
|
Loading…
Reference in New Issue