Some more binary conversions in mod_muc_admin, mod_rest, and mod_shcommands
mod_rest may still need more work
This commit is contained in:
parent
c331365b97
commit
da98b215a9
|
@ -170,9 +170,9 @@ muc_online_rooms(ServerHost) ->
|
|||
fun({_, {Roomname, Host}, _}, Results) ->
|
||||
case MUCHost of
|
||||
global ->
|
||||
[str:join([Roomname, Host], "@") | Results];
|
||||
[Roomname, <<"@">>, Host | Results];
|
||||
Host ->
|
||||
[str:join([Roomname, Host], "@") | Results];
|
||||
[Roomname, <<"@">>, Host | Results];
|
||||
_ ->
|
||||
Results
|
||||
end
|
||||
|
@ -258,7 +258,7 @@ get_sort_query(Q) ->
|
|||
end.
|
||||
|
||||
get_sort_query2(Q) ->
|
||||
{value, {_, String}} = lists:keysearch("sort", 1, Q),
|
||||
{value, {_, String}} = lists:keysearch(<<"sort">>, 1, Q),
|
||||
Integer = list_to_integer(String),
|
||||
case Integer >= 0 of
|
||||
true -> {ok, {normal, Integer}};
|
||||
|
@ -631,7 +631,7 @@ find_serverhost(Host, ServerHosts) ->
|
|||
|
||||
act_on_room(destroy, {N, H, Pid}, SH) ->
|
||||
gen_fsm:send_all_state_event(
|
||||
Pid, {destroy, "Room destroyed by rooms_unused_destroy."}),
|
||||
Pid, {destroy, <<"Room destroyed by rooms_unused_destroy.">>}),
|
||||
mod_muc:room_destroyed(H, N, Pid, SH),
|
||||
mod_muc:forget_room(SH, H, N);
|
||||
|
||||
|
@ -697,18 +697,18 @@ get_users_to_invite(RoomJid, UsersString) ->
|
|||
build_invitation(Password, Reason, RoomString) ->
|
||||
PasswordAttrList = case Password of
|
||||
"none" -> [];
|
||||
_ -> [{"password", Password}]
|
||||
_ -> [{<<"password">>, Password}]
|
||||
end,
|
||||
ReasonAttrList = case Reason of
|
||||
"none" -> [];
|
||||
_ -> [{"reason", Reason}]
|
||||
_ -> [{<<"reason">>, Reason}]
|
||||
end,
|
||||
XAttrs = [{"xmlns", ?NS_XCONFERENCE},
|
||||
{"jid", RoomString}]
|
||||
XAttrs = [{<<"xmlns">>, ?NS_XCONFERENCE},
|
||||
{<<"jid">>, RoomString}]
|
||||
++ PasswordAttrList
|
||||
++ ReasonAttrList,
|
||||
XEl = {xmlelement, "x", XAttrs, []},
|
||||
{xmlelement, "message", [], [XEl]}.
|
||||
XEl = {xmlelement, <<"x">>, XAttrs, []},
|
||||
{xmlelement, <<"message">>, [], [XEl]}.
|
||||
|
||||
send_direct_invitation(FromJid, UserJid, XmlEl) ->
|
||||
ejabberd_router:route(FromJid, UserJid, XmlEl).
|
||||
|
@ -796,7 +796,7 @@ get_room_affiliations(Name, Service) ->
|
|||
fun({{Uname, Domain, _Res}, {Aff, Reason}}) when is_atom(Aff)->
|
||||
{Uname, Domain, Aff, Reason};
|
||||
({{Uname, Domain, _Res}, Aff}) when is_atom(Aff)->
|
||||
{Uname, Domain, Aff, ""}
|
||||
{Uname, Domain, Aff, <<>>}
|
||||
end, Affiliations);
|
||||
[] ->
|
||||
throw({error, "The room does not exist."})
|
||||
|
|
|
@ -56,11 +56,11 @@ process([], #request{method = 'POST',
|
|||
catch
|
||||
error:{badmatch, _} = Error ->
|
||||
?DEBUG("Error when processing REST request: ~nData: ~p~nError: ~p", [Data, Error]),
|
||||
{406, [], "Error: REST request is rejected by service."}
|
||||
{406, [], <<"Error: REST request is rejected by service.">>}
|
||||
end;
|
||||
process(Path, Request) ->
|
||||
?DEBUG("Got request to ~p: ~p", [Path, Request]),
|
||||
{200, [], "Try POSTing a stanza."}.
|
||||
{200, [], <<"Try POSTing a stanza.">>}.
|
||||
|
||||
|
||||
%% If the first character of Data is <, it is considered a stanza to deliver.
|
||||
|
@ -68,8 +68,8 @@ process(Path, Request) ->
|
|||
maybe_post_request([$< | _ ] = Data, Host, ClientIp) ->
|
||||
try
|
||||
Stanza = xml_stream:parse_element(Data),
|
||||
From = jlib:string_to_jid(xml:get_tag_attr_s("from", Stanza)),
|
||||
To = jlib:string_to_jid(xml:get_tag_attr_s("to", Stanza)),
|
||||
From = jlib:string_to_jid(xml:get_tag_attr_s(<<"from">>, Stanza)),
|
||||
To = jlib:string_to_jid(xml:get_tag_attr_s(<<"to">>, Stanza)),
|
||||
allowed = check_stanza(Stanza, From, To, Host),
|
||||
?INFO_MSG("Got valid request from ~s~nwith IP ~p~nto ~s:~n~p",
|
||||
[jlib:jid_to_string(From),
|
||||
|
@ -129,8 +129,8 @@ check_member_option(Host, Element, Option) ->
|
|||
|
||||
post_request(Stanza, From, To) ->
|
||||
case ejabberd_router:route(From, To, Stanza) of
|
||||
ok -> {200, [], "Ok"};
|
||||
_ -> {500, [], "Error"}
|
||||
ok -> {200, [], <<"Ok">>};
|
||||
_ -> {500, [], <<"Error">>}
|
||||
end.
|
||||
|
||||
%% Split a line into args. Args are splitted by blankspaces. Args can be enclosed in "".
|
||||
|
@ -142,7 +142,7 @@ post_request(Stanza, From, To) ->
|
|||
%% 32 is the integer that represents the blankspace
|
||||
%% 34 is the integer that represents the double quotes: "
|
||||
%% 92 is the integer that represents the backslash: \
|
||||
split_line(Line) -> split(Line, "", []).
|
||||
split_line(Line) -> list_to_binary(split(binary_to_list(Line), "", [])).
|
||||
split("", "", Args) -> lists:reverse(Args);
|
||||
split("", Arg, Args) -> split("", "", [lists:reverse(Arg) | Args]);
|
||||
split([32 | Line], "", Args) -> split(Line, [], Args);
|
||||
|
|
|
@ -37,14 +37,14 @@ stop(_Host) ->
|
|||
%%-------------------
|
||||
|
||||
web_menu_node(Acc, _Node, Lang) ->
|
||||
Acc ++ [{"shcommands", ?T("Shell Commands")}].
|
||||
Acc ++ [{<<"shcommands">>, ?T(<<"Shell Commands">>)}].
|
||||
|
||||
%%-------------------
|
||||
%% Web Admin Page
|
||||
%%-------------------
|
||||
|
||||
web_page_node(_, Node, ["shcommands"], Query, Lang) ->
|
||||
Res = [?XC("h1", "Shell Commands") | get_content(Node, Query, Lang)],
|
||||
web_page_node(_, Node, [<<"shcommands">>], Query, Lang) ->
|
||||
Res = [?XC(<<"h1">>, <<"Shell Commands">>) | get_content(Node, Query, Lang)],
|
||||
{stop, Res};
|
||||
web_page_node(Acc, _, _, _, _) -> Acc.
|
||||
|
||||
|
@ -53,46 +53,46 @@ web_page_node(Acc, _, _, _, _) -> Acc.
|
|||
%%-------------------
|
||||
|
||||
get_content(Node, Query, Lang) ->
|
||||
Instruct = ?T("Type a command in a textbox and click Execute."),
|
||||
Instruct = ?T(<<"Type a command in a textbox and click Execute.">>),
|
||||
{{CommandCtl, CommandErl, CommandShell}, Res} = case catch parse_and_execute(Query, Node) of
|
||||
{'EXIT', _} -> {{"", "", ""}, Instruct};
|
||||
{'EXIT', _} -> {{<<"">>, <<"">>, <<"">>}, Instruct};
|
||||
Result_tuple -> Result_tuple
|
||||
end,
|
||||
TitleHTML = [
|
||||
?XC("p", Instruct++" "++?T("Use only commands which immediately return a result.")),
|
||||
?XC("p", ?T("WARNING: Use this only if you know what you are doing."))
|
||||
?XC(<<"p">>, ?T(<<"Type a command in a textbox and click Execute. Use only commands which immediately return a result.">>)),
|
||||
?XC(<<"p">>, ?T(<<"WARNING: Use this only if you know what you are doing.">>))
|
||||
],
|
||||
CommandHTML =
|
||||
[?XAE("form", [{"method", "post"}],
|
||||
[?XAE("table", [],
|
||||
[?XE("tbody",
|
||||
[?XE("tr",
|
||||
[?X("td"),
|
||||
?XCT("td", "ejabberd_ctl"),
|
||||
?XE("td", [?INPUTS("text", "commandctl", CommandCtl, "70"),
|
||||
?INPUTT("submit", "executectl", "Execute")])
|
||||
CommandHTML =
|
||||
[?XAE(<<"form">>, [{<<"method">>, <<"post">>}],
|
||||
[?XAE(<<"table">>, [],
|
||||
[?XE(<<"tbody">>,
|
||||
[?XE(<<"tr">>,
|
||||
[?X(<<"td">>),
|
||||
?XCT(<<"td">>, <<"ejabberd_ctl">>),
|
||||
?XE(<<"td">>, [?INPUTS(<<"text">>, <<"commandctl">>, CommandCtl, <<"70">>),
|
||||
?INPUTT(<<"submit">>, <<"executectl">>, <<"Execute">>)])
|
||||
]
|
||||
),
|
||||
?XE("tr",
|
||||
[?X("td"),
|
||||
?XCT("td", "erlang shell"),
|
||||
?XE("td", [?INPUTS("text", "commanderl", CommandErl, "70"),
|
||||
?INPUTT("submit", "executeerl", "Execute")])
|
||||
?XE(<<"tr">>,
|
||||
[?X(<<"td">>),
|
||||
?XCT(<<"td">>, <<"erlang shell">>),
|
||||
?XE(<<"td">>, [?INPUTS(<<"text">>, <<"commanderl">>, CommandErl, <<"70">>),
|
||||
?INPUTT(<<"submit">>, <<"executeerl">>, <<"Execute">>)])
|
||||
]
|
||||
),
|
||||
?XE("tr",
|
||||
[?X("td"),
|
||||
?XCT("td", "system shell"),
|
||||
?XE("td", [?INPUTS("text", "commandshe", CommandShell, "70"),
|
||||
?INPUTT("submit", "executeshe", "Execute")])
|
||||
?XE(<<"tr">>,
|
||||
[?X(<<"td">>),
|
||||
?XCT(<<"td">>, <<"system shell">>),
|
||||
?XE(<<"td">>, [?INPUTS(<<"text">>, <<"commandshe">>, CommandShell, <<"70">>),
|
||||
?INPUTT(<<"submit">>, <<"executeshe">>, <<"Execute">>)])
|
||||
]
|
||||
)
|
||||
]
|
||||
)])]
|
||||
)],
|
||||
ResHTML =
|
||||
[?XAC("textarea", [{"wrap", "off"}, {"style", "font-family:monospace;"},
|
||||
{"name", "result"}, {"rows", "30"}, {"cols", "80"}],
|
||||
ResHTML =
|
||||
[?XAC(<<"textarea">>, [{<<"wrap">>, <<"off">>}, {<<"style">>, <<"font-family:monospace;">>},
|
||||
{<<"name">>, <<"result">>}, {<<"rows">>, <<"30">>}, {<<"cols">>, <<"80">>}],
|
||||
Res)
|
||||
],
|
||||
TitleHTML ++ CommandHTML ++ ResHTML.
|
||||
|
@ -102,10 +102,10 @@ parse_and_execute(Query, Node) ->
|
|||
fun(ExType) ->
|
||||
lists:keymember(ExType, 1, Query)
|
||||
end,
|
||||
["executectl", "executeerl", "executeshe"]),
|
||||
Commands = {get_val("commandctl", Query),
|
||||
get_val("commanderl", Query),
|
||||
get_val("commandshe", Query)},
|
||||
[<<"executectl">>, <<"executeerl">>, <<"executeshe">>]),
|
||||
Commands = {get_val(<<"commandctl">>, Query),
|
||||
get_val(<<"commanderl">>, Query),
|
||||
get_val(<<"commandshe">>, Query)},
|
||||
R = parse1_command(Exec, Commands, Node),
|
||||
{Commands, R}.
|
||||
|
||||
|
@ -113,28 +113,28 @@ get_val(Val, Query) ->
|
|||
{value, {_, R}} = lists:keysearch(Val, 1, Query),
|
||||
R.
|
||||
|
||||
parse1_command("executectl", {Command, _, _}, Node) ->
|
||||
Command2 = string:tokens(Command, " "),
|
||||
parse1_command(<<"executectl">>, {Command, _, _}, Node) ->
|
||||
Command2 = string:tokens(Command, <<" ">>),
|
||||
{_E, Efile} = execute(ctl, Node, Command2),
|
||||
io_lib:format("ejabberdctl ~p ~s~n~s", [Node, Command, Efile]);
|
||||
|
||||
parse1_command("executeerl", {_, Command, _}, Node) ->
|
||||
parse1_command(<<"executeerl">>, {_, Command, _}, Node) ->
|
||||
{ok, A2, _} = erl_scan:string(Command),
|
||||
{ok, A3} = erl_parse:parse_exprs(A2),
|
||||
{E, Efile} = execute(erl, Node, A3),
|
||||
io_lib:format("(~p)1> ~s~s~n~p", [Node, Command, Efile, E]);
|
||||
|
||||
parse1_command("executeshe", {_, _, Command}, Node) ->
|
||||
parse1_command(<<"executeshe">>, {_, _, Command}, Node) ->
|
||||
E = rpc:call(Node, os, cmd, [Command]),
|
||||
C1 = lists:map(
|
||||
fun(C) -> string:strip(os:cmd(C), right, $\n) end,
|
||||
["whoami", "hostname -s", "pwd"]),
|
||||
fun(C) -> string:strip(os:cmd(C), right, $\n) end,
|
||||
[<<"whoami">>, <<"hostname -s">>, <<"pwd">>]),
|
||||
io_lib:format("~s@~s:~s$ ~s~n~s", C1 ++ [Command, E]).
|
||||
|
||||
|
||||
execute(Type, Node, C) ->
|
||||
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]),
|
||||
group_leader(File, self()),
|
||||
Res = case Type of
|
||||
|
@ -151,6 +151,6 @@ execute(Type, Node, C) ->
|
|||
file:delete(Filename),
|
||||
E2 = case binary_to_list(B) of
|
||||
[] -> [];
|
||||
List -> "\n"++List
|
||||
List -> <<"\n">>++List
|
||||
end,
|
||||
{E, E2}.
|
||||
|
|
Loading…
Reference in New Issue