2003-01-01 20:54:44 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_disco.erl
|
|
|
|
%%% Author : Alexey Shchepin <alexey@sevcom.net>
|
2003-01-28 20:45:13 +01:00
|
|
|
%%% Purpose : Service Discovery (JEP-0030) support
|
2003-01-02 22:01:12 +01:00
|
|
|
%%% Created : 1 Jan 2003 by Alexey Shchepin <alexey@sevcom.net>
|
2003-01-01 20:54:44 +01:00
|
|
|
%%% Id : $Id$
|
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_disco).
|
|
|
|
-author('alexey@sevcom.net').
|
|
|
|
-vsn('$Revision$ ').
|
|
|
|
|
2003-01-24 21:18:33 +01:00
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2003-01-22 21:40:40 +01:00
|
|
|
-export([start/1,
|
2003-01-29 18:12:23 +01:00
|
|
|
stop/0,
|
2003-01-01 20:54:44 +01:00
|
|
|
process_local_iq_items/3,
|
|
|
|
process_local_iq_info/3,
|
|
|
|
process_sm_iq_items/3,
|
|
|
|
process_sm_iq_info/3,
|
2003-01-29 18:12:23 +01:00
|
|
|
register_feature/1,
|
|
|
|
unregister_feature/1]).
|
2003-01-01 20:54:44 +01:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
2003-03-09 21:46:47 +01:00
|
|
|
-include("jlib.hrl").
|
2003-01-01 20:54:44 +01:00
|
|
|
|
|
|
|
-define(EMPTY_INFO_RESULT,
|
|
|
|
{iq, ID, result, XMLNS, [{xmlelement, "query",
|
2003-09-16 20:12:44 +02:00
|
|
|
[{"xmlns", ?NS_DISCO_INFO},
|
|
|
|
{"node", SNode}], []}]}).
|
2003-01-01 20:54:44 +01:00
|
|
|
|
2003-01-24 21:18:33 +01:00
|
|
|
start(Opts) ->
|
|
|
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
2003-01-22 21:40:40 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, ?NS_DISCO_ITEMS,
|
2003-01-24 21:18:33 +01:00
|
|
|
?MODULE, process_local_iq_items, IQDisc),
|
2003-01-22 21:40:40 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, ?NS_DISCO_INFO,
|
2003-01-24 21:18:33 +01:00
|
|
|
?MODULE, process_local_iq_info, IQDisc),
|
2003-01-22 21:40:40 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_sm, ?NS_DISCO_ITEMS,
|
2003-01-24 21:18:33 +01:00
|
|
|
?MODULE, process_sm_iq_items, IQDisc),
|
2003-01-22 21:40:40 +01:00
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_sm, ?NS_DISCO_INFO,
|
2003-01-24 21:18:33 +01:00
|
|
|
?MODULE, process_sm_iq_info, IQDisc),
|
2003-01-01 20:54:44 +01:00
|
|
|
register_feature("iq"),
|
|
|
|
register_feature("presence"),
|
|
|
|
register_feature("presence-invisible"),
|
|
|
|
ok.
|
|
|
|
|
2003-01-29 18:12:23 +01:00
|
|
|
stop() ->
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, ?NS_DISCO_ITEMS),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, ?NS_DISCO_INFO),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, ?NS_DISCO_ITEMS),
|
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, ?NS_DISCO_INFO).
|
|
|
|
|
|
|
|
|
2003-01-01 20:54:44 +01:00
|
|
|
register_feature(Feature) ->
|
|
|
|
catch ets:new(disco_features, [named_table, ordered_set, public]),
|
|
|
|
ets:insert(disco_features, {Feature}).
|
|
|
|
|
2003-01-29 18:12:23 +01:00
|
|
|
unregister_feature(Feature) ->
|
|
|
|
catch ets:new(disco_features, [named_table, ordered_set, public]),
|
|
|
|
ets:delete(disco_features, Feature).
|
|
|
|
|
2003-01-01 20:54:44 +01:00
|
|
|
process_local_iq_items(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
|
2003-01-06 20:57:05 +01:00
|
|
|
Lang = xml:get_tag_attr_s("xml:lang", SubEl),
|
2003-01-01 20:54:44 +01:00
|
|
|
case Type of
|
|
|
|
set ->
|
2003-03-09 21:46:47 +01:00
|
|
|
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
|
2003-01-01 20:54:44 +01:00
|
|
|
get ->
|
2003-09-16 20:12:44 +02:00
|
|
|
SNode = xml:get_tag_attr_s("node", SubEl),
|
|
|
|
Node = string:tokens(SNode, "/"),
|
2003-01-18 20:42:48 +01:00
|
|
|
|
2003-09-16 20:12:44 +02:00
|
|
|
case acl:match_rule(configure, From) of
|
|
|
|
deny when Node /= [] ->
|
|
|
|
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
|
|
|
|
deny ->
|
2003-01-10 20:44:35 +01:00
|
|
|
{iq, ID, result, XMLNS,
|
2003-09-16 20:12:44 +02:00
|
|
|
[{xmlelement, "query",
|
|
|
|
[{"xmlns", ?NS_DISCO_ITEMS}],
|
|
|
|
get_services_only()
|
2003-01-10 20:44:35 +01:00
|
|
|
}]};
|
2003-09-16 20:12:44 +02:00
|
|
|
_ ->
|
|
|
|
case get_local_items(Node, jlib:jid_to_string(To), Lang) of
|
|
|
|
{result, Res} ->
|
|
|
|
{iq, ID, result, XMLNS,
|
|
|
|
[{xmlelement, "query",
|
|
|
|
[{"xmlns", ?NS_DISCO_ITEMS},
|
|
|
|
{"node", SNode}],
|
|
|
|
Res
|
|
|
|
}]};
|
|
|
|
{error, Error} ->
|
|
|
|
{iq, ID, error, XMLNS, [SubEl, Error]}
|
|
|
|
end
|
2003-01-01 20:54:44 +01:00
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
process_local_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
|
|
|
|
case Type of
|
|
|
|
set ->
|
2003-03-09 21:46:47 +01:00
|
|
|
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
|
2003-01-01 20:54:44 +01:00
|
|
|
get ->
|
2003-09-16 20:12:44 +02:00
|
|
|
SNode = xml:get_tag_attr_s("node", SubEl),
|
|
|
|
Node = string:tokens(SNode, "/"),
|
|
|
|
case {acl:match_rule(configure, From), Node} of
|
|
|
|
{_, []} ->
|
2003-01-01 20:54:44 +01:00
|
|
|
Features = lists:map(fun feature_to_xml/1,
|
|
|
|
ets:tab2list(disco_features)),
|
|
|
|
{iq, ID, result, XMLNS, [{xmlelement,
|
|
|
|
"query",
|
|
|
|
[{"xmlns", ?NS_DISCO_INFO}],
|
|
|
|
[{xmlelement, "identity",
|
|
|
|
[{"category", "service"},
|
2003-09-19 20:22:44 +02:00
|
|
|
{"type", "im"},
|
2003-01-01 20:54:44 +01:00
|
|
|
{"name", "ejabberd"}], []}] ++
|
|
|
|
Features
|
|
|
|
}]};
|
2003-09-16 20:12:44 +02:00
|
|
|
{deny, _} ->
|
|
|
|
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
|
|
|
|
{allow, ["config"]} -> ?EMPTY_INFO_RESULT;
|
|
|
|
{allow, ["online users"]} -> ?EMPTY_INFO_RESULT;
|
|
|
|
{allow, ["all users"]} -> ?EMPTY_INFO_RESULT;
|
|
|
|
{allow, ["all users", [$@ | _]]} -> ?EMPTY_INFO_RESULT;
|
|
|
|
{allow, ["outgoing s2s" | _]} -> ?EMPTY_INFO_RESULT;
|
|
|
|
{allow, ["running nodes"]} -> ?EMPTY_INFO_RESULT;
|
|
|
|
{allow, ["stopped nodes"]} -> ?EMPTY_INFO_RESULT;
|
|
|
|
{allow, ["running nodes", ENode]} ->
|
2003-01-18 20:42:48 +01:00
|
|
|
{iq, ID, result, XMLNS, [{xmlelement,
|
|
|
|
"query",
|
2003-09-16 20:12:44 +02:00
|
|
|
[{"xmlns", XMLNS},
|
|
|
|
{"node", SNode}],
|
2003-01-18 20:42:48 +01:00
|
|
|
[{xmlelement, "identity",
|
|
|
|
[{"category", "ejabberd"},
|
|
|
|
{"type", "node"},
|
|
|
|
{"name", ENode}], []},
|
|
|
|
feature_to_xml({?NS_STATS})
|
|
|
|
]
|
|
|
|
}]};
|
2003-09-16 20:12:44 +02:00
|
|
|
{allow, ["running nodes", ENode, "DB"]} ->
|
2003-01-19 21:17:56 +01:00
|
|
|
{iq, ID, result, XMLNS, [{xmlelement,
|
|
|
|
"query",
|
2003-09-16 20:12:44 +02:00
|
|
|
[{"xmlns", XMLNS},
|
|
|
|
{"node", SNode}],
|
|
|
|
[feature_to_xml({?NS_IQDATA})]}]};
|
|
|
|
{allow, ["running nodes", ENode, "modules"]} ->
|
|
|
|
?EMPTY_INFO_RESULT;
|
|
|
|
{allow, ["running nodes", ENode, "modules", _]} ->
|
2003-01-28 20:45:13 +01:00
|
|
|
{iq, ID, result, XMLNS,
|
2003-09-16 20:12:44 +02:00
|
|
|
[{xmlelement, "query",
|
|
|
|
[{"xmlns", XMLNS},
|
|
|
|
{"node", SNode}],
|
2003-02-23 21:13:39 +01:00
|
|
|
[feature_to_xml({?NS_IQDATA})]}]};
|
2003-09-16 20:12:44 +02:00
|
|
|
{allow, ["running nodes", ENode, "backup"]} ->
|
|
|
|
?EMPTY_INFO_RESULT;
|
|
|
|
{allow, ["running nodes", ENode, "backup", _]} ->
|
2003-02-22 20:11:00 +01:00
|
|
|
{iq, ID, result, XMLNS,
|
2003-09-16 20:12:44 +02:00
|
|
|
[{xmlelement, "query",
|
|
|
|
[{"xmlns", XMLNS},
|
|
|
|
{"node", SNode}],
|
2003-02-23 21:13:39 +01:00
|
|
|
[feature_to_xml({?NS_IQDATA})]}]};
|
2003-09-16 20:12:44 +02:00
|
|
|
{allow, ["running nodes", ENode, "import"]} ->
|
|
|
|
?EMPTY_INFO_RESULT;
|
|
|
|
{allow, ["running nodes", ENode, "import", _]} ->
|
2003-02-04 21:45:23 +01:00
|
|
|
{iq, ID, result, XMLNS,
|
2003-09-16 20:12:44 +02:00
|
|
|
[{xmlelement, "query",
|
|
|
|
[{"xmlns", XMLNS},
|
|
|
|
{"node", SNode}],
|
2003-02-23 21:13:39 +01:00
|
|
|
[feature_to_xml({?NS_IQDATA})]}]};
|
2003-09-16 20:12:44 +02:00
|
|
|
{allow, ["config", _]} ->
|
2003-01-21 21:36:55 +01:00
|
|
|
{iq, ID, result, XMLNS,
|
2003-09-16 20:12:44 +02:00
|
|
|
[{xmlelement, "query",
|
|
|
|
[{"xmlns", XMLNS},
|
|
|
|
{"node", SNode}],
|
2003-02-23 21:13:39 +01:00
|
|
|
[feature_to_xml({?NS_IQDATA})]}]};
|
2003-01-01 20:54:44 +01:00
|
|
|
_ ->
|
|
|
|
{iq, ID, error, XMLNS,
|
2003-09-16 20:12:44 +02:00
|
|
|
[SubEl, ?ERR_ITEM_NOT_FOUND]}
|
2003-01-01 20:54:44 +01:00
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
feature_to_xml({Feature}) ->
|
|
|
|
{xmlelement, "feature", [{"var", Feature}], []}.
|
|
|
|
|
2003-01-02 22:01:12 +01:00
|
|
|
domain_to_xml(Domain) ->
|
|
|
|
{xmlelement, "item", [{"jid", Domain}], []}.
|
|
|
|
|
2003-01-01 20:54:44 +01:00
|
|
|
|
2003-01-19 21:17:56 +01:00
|
|
|
-define(NODE(Name, Node),
|
2003-01-18 20:42:48 +01:00
|
|
|
{xmlelement, "item",
|
|
|
|
[{"jid", Server},
|
|
|
|
{"name", translate:translate(Lang, Name)},
|
|
|
|
{"node", Node}], []}).
|
|
|
|
|
|
|
|
|
2003-09-16 20:12:44 +02:00
|
|
|
get_services_only() ->
|
|
|
|
lists:map(fun domain_to_xml/1,
|
|
|
|
ejabberd_router:dirty_get_all_routes()).
|
|
|
|
|
2003-01-18 20:42:48 +01:00
|
|
|
get_local_items([], Server, Lang) ->
|
|
|
|
Domains =
|
|
|
|
lists:map(fun domain_to_xml/1,
|
|
|
|
ejabberd_router:dirty_get_all_routes()),
|
|
|
|
{result,
|
2003-01-21 21:36:55 +01:00
|
|
|
Domains ++
|
|
|
|
[?NODE("Configuration", "config"),
|
|
|
|
?NODE("Online Users", "online users"),
|
|
|
|
?NODE("All Users", "all users"),
|
|
|
|
?NODE("Outgoing S2S connections", "outgoing s2s"),
|
|
|
|
?NODE("Running Nodes", "running nodes"),
|
|
|
|
?NODE("Stopped Nodes", "stopped nodes")
|
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(["config"], Server, Lang) ->
|
|
|
|
{result,
|
2003-01-22 21:40:40 +01:00
|
|
|
[?NODE("Host Name", "config/hostname"),
|
|
|
|
?NODE("ACLs", "config/acls"),
|
|
|
|
?NODE("Access Rules", "config/access"),
|
2003-01-26 21:16:53 +01:00
|
|
|
?NODE("Remove Users", "config/remusers")
|
2003-01-21 21:36:55 +01:00
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(["config", _], Server, Lang) ->
|
|
|
|
{result, []};
|
2003-01-18 20:42:48 +01:00
|
|
|
|
|
|
|
get_local_items(["online users"], Server, Lang) ->
|
|
|
|
{result, get_online_users()};
|
|
|
|
|
|
|
|
get_local_items(["all users"], Server, Lang) ->
|
|
|
|
{result, get_all_users()};
|
|
|
|
|
2003-02-07 20:31:00 +01:00
|
|
|
get_local_items(["all users", [$@ | Diap]], Server, Lang) ->
|
|
|
|
case catch ejabberd_auth:dirty_get_registered_users() of
|
|
|
|
{'EXIT', Reason} ->
|
2003-03-09 21:46:47 +01:00
|
|
|
?ERR_INTERNAL_SERVER_ERROR;
|
2003-02-07 20:31:00 +01:00
|
|
|
Users ->
|
|
|
|
SUsers = lists:sort(Users),
|
|
|
|
case catch begin
|
|
|
|
{ok, [S1, S2]} = regexp:split(Diap, "-"),
|
|
|
|
N1 = list_to_integer(S1),
|
|
|
|
N2 = list_to_integer(S2),
|
|
|
|
Sub = lists:sublist(SUsers, N1, N2 - N1 + 1),
|
|
|
|
lists:map(fun(U) ->
|
|
|
|
{xmlelement, "item",
|
|
|
|
[{"jid", U ++ "@" ++ ?MYNAME},
|
|
|
|
{"name", U}], []}
|
|
|
|
end, Sub)
|
|
|
|
end of
|
|
|
|
{'EXIT', Reason} ->
|
2003-03-09 21:46:47 +01:00
|
|
|
% TODO: must be "not acceptable"
|
|
|
|
?ERR_BAD_REQUEST;
|
2003-02-07 20:31:00 +01:00
|
|
|
Res ->
|
|
|
|
{result, Res}
|
|
|
|
end
|
|
|
|
end;
|
|
|
|
|
2003-01-18 20:42:48 +01:00
|
|
|
get_local_items(["outgoing s2s"], Server, Lang) ->
|
|
|
|
{result, get_outgoing_s2s(Lang)};
|
|
|
|
|
2003-01-22 21:40:40 +01:00
|
|
|
get_local_items(["outgoing s2s", To], Server, Lang) ->
|
|
|
|
{result, get_outgoing_s2s(Lang, To)};
|
|
|
|
|
2003-01-18 20:42:48 +01:00
|
|
|
get_local_items(["running nodes"], Server, Lang) ->
|
|
|
|
{result, get_running_nodes(Lang)};
|
|
|
|
|
|
|
|
get_local_items(["stopped nodes"], Server, Lang) ->
|
|
|
|
{result, get_stopped_nodes(Lang)};
|
|
|
|
|
2003-01-19 21:17:56 +01:00
|
|
|
get_local_items(["running nodes", ENode], Server, Lang) ->
|
|
|
|
{result,
|
2003-01-28 20:45:13 +01:00
|
|
|
[?NODE("DB", "running nodes/" ++ ENode ++ "/DB"),
|
2003-02-04 21:45:23 +01:00
|
|
|
?NODE("Modules", "running nodes/" ++ ENode ++ "/modules"),
|
2003-02-22 20:11:00 +01:00
|
|
|
?NODE("Backup Management", "running nodes/" ++ ENode ++ "/backup"),
|
2003-02-04 21:45:23 +01:00
|
|
|
?NODE("Import users from jabberd1.4 spool files",
|
|
|
|
"running nodes/" ++ ENode ++ "/import")
|
2003-01-28 20:45:13 +01:00
|
|
|
]};
|
2003-01-19 21:17:56 +01:00
|
|
|
|
|
|
|
get_local_items(["running nodes", ENode, "DB"], Server, Lang) ->
|
2003-01-18 20:42:48 +01:00
|
|
|
{result, []};
|
|
|
|
|
2003-01-28 20:45:13 +01:00
|
|
|
get_local_items(["running nodes", ENode, "modules"], Server, Lang) ->
|
|
|
|
{result,
|
|
|
|
[?NODE("Start Modules", "running nodes/" ++ ENode ++ "/modules/start"),
|
|
|
|
?NODE("Stop Modules", "running nodes/" ++ ENode ++ "/modules/stop")
|
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(["running nodes", ENode, "modules", _], Server, Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
2003-02-22 20:11:00 +01:00
|
|
|
get_local_items(["running nodes", ENode, "backup"], Server, Lang) ->
|
|
|
|
{result,
|
|
|
|
[?NODE("Backup", "running nodes/" ++ ENode ++ "/backup/backup"),
|
|
|
|
?NODE("Restore", "running nodes/" ++ ENode ++ "/backup/restore"),
|
|
|
|
?NODE("Dump to Text File",
|
|
|
|
"running nodes/" ++ ENode ++ "/backup/textfile")
|
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(["running nodes", ENode, "backup", _], Server, Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
2003-02-04 21:45:23 +01:00
|
|
|
get_local_items(["running nodes", ENode, "import"], Server, Lang) ->
|
|
|
|
{result,
|
|
|
|
[?NODE("Import File", "running nodes/" ++ ENode ++ "/import/file"),
|
|
|
|
?NODE("Import Directory", "running nodes/" ++ ENode ++ "/import/dir")
|
|
|
|
]};
|
|
|
|
|
|
|
|
get_local_items(["running nodes", ENode, "import", _], Server, Lang) ->
|
|
|
|
{result, []};
|
|
|
|
|
2003-01-18 20:42:48 +01:00
|
|
|
get_local_items(_, _, _) ->
|
2003-03-09 21:46:47 +01:00
|
|
|
{error, ?ERR_FEATURE_NOT_IMPLEMENTED}.
|
2003-01-18 20:42:48 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-01-01 20:54:44 +01:00
|
|
|
get_online_users() ->
|
|
|
|
case catch ejabberd_sm:dirty_get_sessions_list() of
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
[];
|
|
|
|
URs ->
|
|
|
|
lists:map(fun({U, R}) ->
|
|
|
|
{xmlelement, "item",
|
|
|
|
[{"jid", U ++ "@" ++ ?MYNAME ++ "/" ++ R},
|
|
|
|
{"name", U}], []}
|
|
|
|
end, lists:sort(URs))
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_all_users() ->
|
|
|
|
case catch ejabberd_auth:dirty_get_registered_users() of
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
[];
|
|
|
|
Users ->
|
2003-02-07 20:31:00 +01:00
|
|
|
SUsers = lists:sort(Users),
|
|
|
|
case length(SUsers) of
|
|
|
|
N when N =< 100 ->
|
|
|
|
lists:map(fun(U) ->
|
|
|
|
{xmlelement, "item",
|
|
|
|
[{"jid", U ++ "@" ++ ?MYNAME},
|
|
|
|
{"name", U}], []}
|
|
|
|
end, SUsers);
|
|
|
|
N ->
|
|
|
|
NParts = trunc(math:sqrt(N * 0.618)) + 1,
|
|
|
|
M = trunc(N / NParts) + 1,
|
|
|
|
lists:map(fun(K) ->
|
|
|
|
L = K + M - 1,
|
|
|
|
Node =
|
|
|
|
"@" ++ integer_to_list(K) ++
|
|
|
|
"-" ++ integer_to_list(L),
|
|
|
|
Last = if L < N -> lists:nth(L, SUsers);
|
|
|
|
true -> lists:last(SUsers)
|
|
|
|
end,
|
|
|
|
Name =
|
|
|
|
lists:nth(K, SUsers) ++ " -- " ++
|
|
|
|
Last,
|
|
|
|
{xmlelement, "item",
|
|
|
|
[{"jid", ?MYNAME},
|
|
|
|
{"node", "all users/" ++ Node},
|
|
|
|
{"name", Name}], []}
|
|
|
|
end, lists:seq(1, N, M))
|
|
|
|
end
|
2003-01-01 20:54:44 +01:00
|
|
|
end.
|
|
|
|
|
2003-01-10 20:44:35 +01:00
|
|
|
get_outgoing_s2s(Lang) ->
|
|
|
|
case catch ejabberd_s2s:dirty_get_connections() of
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
[];
|
|
|
|
Connections ->
|
|
|
|
lists:map(
|
|
|
|
fun({F, T}) ->
|
|
|
|
{xmlelement, "item",
|
|
|
|
[{"jid", ?MYNAME},
|
|
|
|
{"node", "outgoing s2s/" ++ T},
|
|
|
|
{"name",
|
|
|
|
lists:flatten(
|
|
|
|
io_lib:format(
|
|
|
|
translate:translate(Lang, "To ~s"), [T]))}],
|
|
|
|
[]}
|
|
|
|
end, lists:keysort(2, Connections))
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_outgoing_s2s(Lang, To) ->
|
|
|
|
case catch ejabberd_s2s:dirty_get_connections() of
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
[];
|
|
|
|
Connections ->
|
|
|
|
lists:map(
|
|
|
|
fun({F, T}) ->
|
|
|
|
{xmlelement, "item",
|
|
|
|
[{"jid", ?MYNAME},
|
|
|
|
{"node", "outgoing s2s/" ++ To ++ "/" ++ F},
|
|
|
|
{"name",
|
|
|
|
lists:flatten(
|
|
|
|
io_lib:format(
|
|
|
|
translate:translate(Lang, "From ~s"), [F]))}],
|
|
|
|
[]}
|
|
|
|
end, lists:keysort(1, lists:filter(fun(E) ->
|
|
|
|
element(2, E) == To
|
|
|
|
end, Connections)))
|
|
|
|
end.
|
|
|
|
|
2003-01-01 20:54:44 +01:00
|
|
|
|
2003-01-18 20:42:48 +01:00
|
|
|
get_running_nodes(Lang) ->
|
|
|
|
case catch mnesia:system_info(running_db_nodes) of
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
[];
|
|
|
|
DBNodes ->
|
|
|
|
lists:map(
|
|
|
|
fun(N) ->
|
|
|
|
S = atom_to_list(N),
|
|
|
|
{xmlelement, "item",
|
|
|
|
[{"jid", ?MYNAME},
|
|
|
|
{"node", "running nodes/" ++ S},
|
|
|
|
{"name", S}],
|
|
|
|
[]}
|
|
|
|
end, lists:sort(DBNodes))
|
|
|
|
end.
|
|
|
|
|
|
|
|
get_stopped_nodes(Lang) ->
|
|
|
|
case catch (lists:usort(mnesia:system_info(db_nodes) ++
|
|
|
|
mnesia:system_info(extra_db_nodes)) --
|
|
|
|
mnesia:system_info(running_db_nodes)) of
|
|
|
|
{'EXIT', Reason} ->
|
|
|
|
[];
|
|
|
|
DBNodes ->
|
|
|
|
lists:map(
|
|
|
|
fun(N) ->
|
|
|
|
S = atom_to_list(N),
|
|
|
|
{xmlelement, "item",
|
|
|
|
[{"jid", ?MYNAME},
|
|
|
|
{"node", "stopped nodes/" ++ S},
|
|
|
|
{"name", S}],
|
|
|
|
[]}
|
|
|
|
end, lists:sort(DBNodes))
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
|
|
|
|
2003-01-01 20:54:44 +01:00
|
|
|
process_sm_iq_items(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
|
|
|
|
{User, _, _} = To,
|
2003-09-16 20:12:44 +02:00
|
|
|
case {acl:match_rule(configure, From), Type} of
|
|
|
|
{deny, _} ->
|
2003-03-09 21:46:47 +01:00
|
|
|
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
|
2003-09-16 20:12:44 +02:00
|
|
|
{allow, set} ->
|
|
|
|
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
|
|
|
|
{allow, get} ->
|
2003-01-01 20:54:44 +01:00
|
|
|
case xml:get_tag_attr_s("node", SubEl) of
|
|
|
|
"" ->
|
|
|
|
{iq, ID, result, XMLNS,
|
|
|
|
[{xmlelement, "query", [{"xmlns", ?NS_DISCO_ITEMS}],
|
|
|
|
get_user_resources(User)
|
|
|
|
}]};
|
|
|
|
_ ->
|
|
|
|
{iq, ID, error, XMLNS,
|
2003-09-16 20:12:44 +02:00
|
|
|
[SubEl, ?ERR_ITEM_NOT_FOUND]}
|
2003-01-01 20:54:44 +01:00
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
process_sm_iq_info(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
|
2003-09-16 20:12:44 +02:00
|
|
|
case {acl:match_rule(configure, From), Type} of
|
|
|
|
{deny, _} ->
|
2003-03-09 21:46:47 +01:00
|
|
|
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
|
2003-09-16 20:12:44 +02:00
|
|
|
{allow, set} ->
|
|
|
|
{iq, ID, error, XMLNS, [SubEl, ?ERR_NOT_ALLOWED]};
|
|
|
|
{allow, get} ->
|
2003-01-01 20:54:44 +01:00
|
|
|
case xml:get_tag_attr_s("node", SubEl) of
|
2003-01-21 21:36:55 +01:00
|
|
|
"" ->
|
|
|
|
{iq, ID, result, XMLNS,
|
|
|
|
[{xmlelement, "query", [{"xmlns", XMLNS}],
|
2003-02-23 21:13:39 +01:00
|
|
|
[feature_to_xml({?NS_IQDATA})]}]};
|
2003-01-01 20:54:44 +01:00
|
|
|
_ ->
|
|
|
|
{iq, ID, error, XMLNS,
|
2003-03-09 21:46:47 +01:00
|
|
|
[SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]}
|
2003-01-01 20:54:44 +01:00
|
|
|
end
|
|
|
|
end.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
get_user_resources(User) ->
|
|
|
|
Rs = ejabberd_sm:get_user_resources(User),
|
|
|
|
lists:map(fun(R) ->
|
|
|
|
{xmlelement, "item",
|
|
|
|
[{"jid", User ++ "@" ++ ?MYNAME ++ "/" ++ R},
|
|
|
|
{"name", User}], []}
|
|
|
|
end, lists:sort(Rs)).
|
|
|
|
|