24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-06 21:37:17 +02:00

* src/mod_disco.erl: Now only admin can discovery some nodes,

fixed "node" attribute in replies

SVN Revision: 139
This commit is contained in:
Alexey Shchepin 2003-09-16 18:12:44 +00:00
parent ea59447230
commit 3df8ed2cc1
2 changed files with 86 additions and 44 deletions

View File

@ -1,3 +1,8 @@
2003-09-16 Alexey Shchepin <alexey@sevcom.net>
* src/mod_disco.erl: Now only admin can discovery some nodes,
fixed "node" attribute in replies
2003-09-10 Alexey Shchepin <alexey@sevcom.net> 2003-09-10 Alexey Shchepin <alexey@sevcom.net>
* examples/mtr/ejabberd.cfg: Updated (thanks to Marshall T. Rose) * examples/mtr/ejabberd.cfg: Updated (thanks to Marshall T. Rose)

View File

@ -26,7 +26,8 @@
-define(EMPTY_INFO_RESULT, -define(EMPTY_INFO_RESULT,
{iq, ID, result, XMLNS, [{xmlelement, "query", {iq, ID, result, XMLNS, [{xmlelement, "query",
[{"xmlns", ?NS_DISCO_INFO}], []}]}). [{"xmlns", ?NS_DISCO_INFO},
{"node", SNode}], []}]}).
start(Opts) -> start(Opts) ->
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue), IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
@ -64,17 +65,30 @@ process_local_iq_items(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
set -> set ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]}; {iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
get -> get ->
Node = string:tokens(xml:get_tag_attr_s("node", SubEl), "/"), SNode = xml:get_tag_attr_s("node", SubEl),
Node = string:tokens(SNode, "/"),
case get_local_items(Node, jlib:jid_to_string(To), Lang) of case acl:match_rule(configure, From) of
{result, Res} -> deny when Node /= [] ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
deny ->
{iq, ID, result, XMLNS, {iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", ?NS_DISCO_ITEMS}], [{xmlelement, "query",
Res [{"xmlns", ?NS_DISCO_ITEMS}],
get_services_only()
}]}; }]};
{error, Error} -> _ ->
{iq, ID, error, XMLNS, case get_local_items(Node, jlib:jid_to_string(To), Lang) of
[SubEl, Error]} {result, Res} ->
{iq, ID, result, XMLNS,
[{xmlelement, "query",
[{"xmlns", ?NS_DISCO_ITEMS},
{"node", SNode}],
Res
}]};
{error, Error} ->
{iq, ID, error, XMLNS, [SubEl, Error]}
end
end end
end. end.
@ -84,8 +98,10 @@ process_local_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
set -> set ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]}; {iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
get -> get ->
case string:tokens(xml:get_tag_attr_s("node", SubEl), "/") of SNode = xml:get_tag_attr_s("node", SubEl),
[] -> Node = string:tokens(SNode, "/"),
case {acl:match_rule(configure, From), Node} of
{_, []} ->
Features = lists:map(fun feature_to_xml/1, Features = lists:map(fun feature_to_xml/1,
ets:tab2list(disco_features)), ets:tab2list(disco_features)),
{iq, ID, result, XMLNS, [{xmlelement, {iq, ID, result, XMLNS, [{xmlelement,
@ -97,17 +113,20 @@ process_local_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
{"name", "ejabberd"}], []}] ++ {"name", "ejabberd"}], []}] ++
Features Features
}]}; }]};
["config"] -> ?EMPTY_INFO_RESULT; {deny, _} ->
["online users"] -> ?EMPTY_INFO_RESULT; {iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
["all users"] -> ?EMPTY_INFO_RESULT; {allow, ["config"]} -> ?EMPTY_INFO_RESULT;
["all users", [$@ | _]] -> ?EMPTY_INFO_RESULT; {allow, ["online users"]} -> ?EMPTY_INFO_RESULT;
["outgoing s2s" | _] -> ?EMPTY_INFO_RESULT; {allow, ["all users"]} -> ?EMPTY_INFO_RESULT;
["running nodes"] -> ?EMPTY_INFO_RESULT; {allow, ["all users", [$@ | _]]} -> ?EMPTY_INFO_RESULT;
["stopped nodes"] -> ?EMPTY_INFO_RESULT; {allow, ["outgoing s2s" | _]} -> ?EMPTY_INFO_RESULT;
["running nodes", ENode] -> {allow, ["running nodes"]} -> ?EMPTY_INFO_RESULT;
{allow, ["stopped nodes"]} -> ?EMPTY_INFO_RESULT;
{allow, ["running nodes", ENode]} ->
{iq, ID, result, XMLNS, [{xmlelement, {iq, ID, result, XMLNS, [{xmlelement,
"query", "query",
[{"xmlns", XMLNS}], [{"xmlns", XMLNS},
{"node", SNode}],
[{xmlelement, "identity", [{xmlelement, "identity",
[{"category", "ejabberd"}, [{"category", "ejabberd"},
{"type", "node"}, {"type", "node"},
@ -115,35 +134,45 @@ process_local_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
feature_to_xml({?NS_STATS}) feature_to_xml({?NS_STATS})
] ]
}]}; }]};
["running nodes", ENode, "DB"] -> {allow, ["running nodes", ENode, "DB"]} ->
{iq, ID, result, XMLNS, [{xmlelement, {iq, ID, result, XMLNS, [{xmlelement,
"query", "query",
[{"xmlns", XMLNS}], [{"xmlns", XMLNS},
[feature_to_xml({?NS_IQDATA}) {"node", SNode}],
] [feature_to_xml({?NS_IQDATA})]}]};
}]}; {allow, ["running nodes", ENode, "modules"]} ->
["running nodes", ENode, "modules"] -> ?EMPTY_INFO_RESULT; ?EMPTY_INFO_RESULT;
["running nodes", ENode, "modules", _] -> {allow, ["running nodes", ENode, "modules", _]} ->
{iq, ID, result, XMLNS, {iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", XMLNS}], [{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]}; [feature_to_xml({?NS_IQDATA})]}]};
["running nodes", ENode, "backup"] -> ?EMPTY_INFO_RESULT; {allow, ["running nodes", ENode, "backup"]} ->
["running nodes", ENode, "backup", _] -> ?EMPTY_INFO_RESULT;
{allow, ["running nodes", ENode, "backup", _]} ->
{iq, ID, result, XMLNS, {iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", XMLNS}], [{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]}; [feature_to_xml({?NS_IQDATA})]}]};
["running nodes", ENode, "import"] -> ?EMPTY_INFO_RESULT; {allow, ["running nodes", ENode, "import"]} ->
["running nodes", ENode, "import", _] -> ?EMPTY_INFO_RESULT;
{allow, ["running nodes", ENode, "import", _]} ->
{iq, ID, result, XMLNS, {iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", XMLNS}], [{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]}; [feature_to_xml({?NS_IQDATA})]}]};
["config", _] -> {allow, ["config", _]} ->
{iq, ID, result, XMLNS, {iq, ID, result, XMLNS,
[{xmlelement, "query", [{"xmlns", XMLNS}], [{xmlelement, "query",
[{"xmlns", XMLNS},
{"node", SNode}],
[feature_to_xml({?NS_IQDATA})]}]}; [feature_to_xml({?NS_IQDATA})]}]};
_ -> _ ->
{iq, ID, error, XMLNS, {iq, ID, error, XMLNS,
[SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]} [SubEl, ?ERR_ITEM_NOT_FOUND]}
end end
end. end.
@ -162,6 +191,10 @@ domain_to_xml(Domain) ->
{"node", Node}], []}). {"node", Node}], []}).
get_services_only() ->
lists:map(fun domain_to_xml/1,
ejabberd_router:dirty_get_all_routes()).
get_local_items([], Server, Lang) -> get_local_items([], Server, Lang) ->
Domains = Domains =
lists:map(fun domain_to_xml/1, lists:map(fun domain_to_xml/1,
@ -404,10 +437,12 @@ get_stopped_nodes(Lang) ->
process_sm_iq_items(From, To, {iq, ID, Type, XMLNS, SubEl}) -> process_sm_iq_items(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
{User, _, _} = To, {User, _, _} = To,
case Type of case {acl:match_rule(configure, From), Type} of
set -> {deny, _} ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]}; {iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
get -> {allow, set} ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
{allow, get} ->
case xml:get_tag_attr_s("node", SubEl) of case xml:get_tag_attr_s("node", SubEl) of
"" -> "" ->
{iq, ID, result, XMLNS, {iq, ID, result, XMLNS,
@ -416,16 +451,18 @@ process_sm_iq_items(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
}]}; }]};
_ -> _ ->
{iq, ID, error, XMLNS, {iq, ID, error, XMLNS,
[SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]} [SubEl, ?ERR_ITEM_NOT_FOUND]}
end end
end. end.
process_sm_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) -> process_sm_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
case Type of case {acl:match_rule(configure, From), Type} of
set -> {deny, _} ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]}; {iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
get -> {allow, set} ->
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
{allow, get} ->
case xml:get_tag_attr_s("node", SubEl) of case xml:get_tag_attr_s("node", SubEl) of
"" -> "" ->
{iq, ID, result, XMLNS, {iq, ID, result, XMLNS,