25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-22 16:20:52 +01:00

Add support in WebAdmin for the new listener network protocol

SVN Revision: 2462
This commit is contained in:
Badlop 2009-08-11 18:22:58 +00:00
parent 60932b67b1
commit 44ac69f8de

View File

@ -2346,13 +2346,14 @@ node_ports_to_xhtml(Ports, Lang) ->
[?XE("tr", [?XE("tr",
[?XCT("td", "Port"), [?XCT("td", "Port"),
?XCT("td", "IP"), ?XCT("td", "IP"),
?XCT("td", "Prot"),
?XCT("td", "Module"), ?XCT("td", "Module"),
?XCT("td", "Options") ?XCT("td", "Options")
])]), ])]),
?XE("tbody", ?XE("tbody",
lists:map( lists:map(
fun({PortIP, Module, Opts} = _E) -> fun({PortIP, Module, Opts} = _E) ->
{_Port, SPort, _TIP, SIP, SSPort, OptsClean} = {_Port, SPort, _TIP, SIP, SSPort, NetProt, OptsClean} =
get_port_data(PortIP, Opts), get_port_data(PortIP, Opts),
SModule = atom_to_list(Module), SModule = atom_to_list(Module),
{NumLines, SOptsClean} = term_to_paragraph(OptsClean, 40), {NumLines, SOptsClean} = term_to_paragraph(OptsClean, 40),
@ -2360,6 +2361,7 @@ node_ports_to_xhtml(Ports, Lang) ->
?XE("tr", ?XE("tr",
[?XAE("td", [{"size", "6"}], [?C(SPort)]), [?XAE("td", [{"size", "6"}], [?C(SPort)]),
?XAE("td", [{"size", "15"}], [?C(SIP)]), ?XAE("td", [{"size", "15"}], [?C(SIP)]),
?XAE("td", [{"size", "4"}], [?C(atom_to_list(NetProt))]),
?XE("td", [?INPUTS("text", "module" ++ SSPort, ?XE("td", [?INPUTS("text", "module" ++ SSPort,
SModule, "15")]), SModule, "15")]),
?XE("td", [?TEXTAREA("opts" ++ SSPort, integer_to_list(NumLines), "35", SOptsClean)]), ?XE("td", [?TEXTAREA("opts" ++ SSPort, integer_to_list(NumLines), "35", SOptsClean)]),
@ -2373,6 +2375,7 @@ node_ports_to_xhtml(Ports, Lang) ->
[?XE("tr", [?XE("tr",
[?XE("td", [?INPUTS("text", "portnew", "", "6")]), [?XE("td", [?INPUTS("text", "portnew", "", "6")]),
?XE("td", [?INPUTS("text", "ipnew", "0.0.0.0", "15")]), ?XE("td", [?INPUTS("text", "ipnew", "0.0.0.0", "15")]),
?XE("td", [make_netprot_html("tcp")]),
?XE("td", [?INPUTS("text", "modulenew", "", "15")]), ?XE("td", [?INPUTS("text", "modulenew", "", "15")]),
?XE("td", [?TEXTAREA("optsnew", "2", "35", "[]")]), ?XE("td", [?TEXTAREA("optsnew", "2", "35", "[]")]),
?XAE("td", [{"colspan", "2"}], ?XAE("td", [{"colspan", "2"}],
@ -2381,25 +2384,38 @@ node_ports_to_xhtml(Ports, Lang) ->
)] )]
)]). )]).
make_netprot_html(NetProt) ->
?XAE("select", [{"name", "netprotnew"}],
lists:map(
fun(O) ->
Sel = if
O == NetProt -> [{"selected", "selected"}];
true -> []
end,
?XAC("option",
Sel ++ [{"value", O}],
O)
end, ["tcp", "udp"])).
get_port_data(PortIP, Opts) -> get_port_data(PortIP, Opts) ->
{Port, IPT, IPS, _IPV, OptsClean} = ejabberd_listener:parse_listener_portip(PortIP, Opts), {Port, IPT, IPS, _IPV, NetProt, OptsClean} = ejabberd_listener:parse_listener_portip(PortIP, Opts),
SPort = io_lib:format("~p", [Port]), SPort = io_lib:format("~p", [Port]),
SSPort = lists:flatten( SSPort = lists:flatten(
lists:map( lists:map(
fun(N) -> io_lib:format("~.16b", [N]) end, fun(N) -> io_lib:format("~.16b", [N]) end,
binary_to_list(crypto:md5(SPort++IPS)))), binary_to_list(crypto:md5(SPort++IPS++atom_to_list(NetProt))))),
{Port, SPort, IPT, IPS, SSPort, OptsClean}. {Port, SPort, IPT, IPS, SSPort, NetProt, OptsClean}.
node_ports_parse_query(Node, Ports, Query) -> node_ports_parse_query(Node, Ports, Query) ->
lists:foreach( lists:foreach(
fun({PortIP, Module1, Opts1}) -> fun({PortIpNetp, Module1, Opts1}) ->
{Port, _SPort, TIP, _SIP, SSPort, _OptsClean} = {Port, _SPort, TIP, _SIP, SSPort, NetProt, _OptsClean} =
get_port_data(PortIP, Opts1), get_port_data(PortIpNetp, Opts1),
case lists:keysearch("add" ++ SSPort, 1, Query) of case lists:keysearch("add" ++ SSPort, 1, Query) of
{value, _} -> {value, _} ->
PortIP2 = {Port, TIP}, PortIpNetp2 = {Port, TIP, NetProt},
{{value, {_, SModule}}, {value, {_, SOpts}}} = {{value, {_, SModule}}, {value, {_, SOpts}}} =
{lists:keysearch("module" ++ SSPort, 1, Query), {lists:keysearch("module" ++ SSPort, 1, Query),
lists:keysearch("opts" ++ SSPort, 1, Query)}, lists:keysearch("opts" ++ SSPort, 1, Query)},
@ -2407,15 +2423,15 @@ node_ports_parse_query(Node, Ports, Query) ->
{ok, Tokens, _} = erl_scan:string(SOpts ++ "."), {ok, Tokens, _} = erl_scan:string(SOpts ++ "."),
{ok, Opts} = erl_parse:parse_term(Tokens), {ok, Opts} = erl_parse:parse_term(Tokens),
rpc:call(Node, ejabberd_listener, delete_listener, rpc:call(Node, ejabberd_listener, delete_listener,
[PortIP2, Module1]), [PortIpNetp2, Module1]),
R=rpc:call(Node, ejabberd_listener, add_listener, R=rpc:call(Node, ejabberd_listener, add_listener,
[PortIP2, Module, Opts]), [PortIpNetp2, Module, Opts]),
throw({is_added, R}); throw({is_added, R});
_ -> _ ->
case lists:keysearch("delete" ++ SSPort, 1, Query) of case lists:keysearch("delete" ++ SSPort, 1, Query) of
{value, _} -> {value, _} ->
rpc:call(Node, ejabberd_listener, delete_listener, rpc:call(Node, ejabberd_listener, delete_listener,
[PortIP, Module1]), [PortIpNetp, Module1]),
throw(submitted); throw(submitted);
_ -> _ ->
ok ok
@ -2426,10 +2442,12 @@ node_ports_parse_query(Node, Ports, Query) ->
{value, _} -> {value, _} ->
{{value, {_, SPort}}, {{value, {_, SPort}},
{value, {_, STIP}}, %% It is a string that may represent a tuple {value, {_, STIP}}, %% It is a string that may represent a tuple
{value, {_, SNetProt}},
{value, {_, SModule}}, {value, {_, SModule}},
{value, {_, SOpts}}} = {value, {_, SOpts}}} =
{lists:keysearch("portnew", 1, Query), {lists:keysearch("portnew", 1, Query),
lists:keysearch("ipnew", 1, Query), lists:keysearch("ipnew", 1, Query),
lists:keysearch("netprotnew", 1, Query),
lists:keysearch("modulenew", 1, Query), lists:keysearch("modulenew", 1, Query),
lists:keysearch("optsnew", 1, Query)}, lists:keysearch("optsnew", 1, Query)},
{ok, Toks, _} = erl_scan:string(SPort ++ "."), {ok, Toks, _} = erl_scan:string(SPort ++ "."),
@ -2440,12 +2458,13 @@ node_ports_parse_query(Node, Ports, Query) ->
{error, _} -> STIP {error, _} -> STIP
end, end,
Module = list_to_atom(SModule), Module = list_to_atom(SModule),
NetProt2 = list_to_atom(SNetProt),
{ok, Tokens, _} = erl_scan:string(SOpts ++ "."), {ok, Tokens, _} = erl_scan:string(SOpts ++ "."),
{ok, Opts} = erl_parse:parse_term(Tokens), {ok, Opts} = erl_parse:parse_term(Tokens),
{Port2, _SPort, IP2, _SIP, _SSPort, OptsClean} = {Port2, _SPort, IP2, _SIP, _SSPort, NetProt2, OptsClean} =
get_port_data({Port2, STIP2}, Opts), get_port_data({Port2, STIP2, NetProt2}, Opts),
R=rpc:call(Node, ejabberd_listener, add_listener, R=rpc:call(Node, ejabberd_listener, add_listener,
[{Port2, IP2}, Module, OptsClean]), [{Port2, IP2, NetProt2}, Module, OptsClean]),
throw({is_added, R}); throw({is_added, R});
_ -> _ ->
ok ok