2003-11-02 18:16:28 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
%%% File : mod_configure2.erl
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Author : Alexey Shchepin <alexey@process-one.net>
|
2003-11-02 18:16:28 +01:00
|
|
|
%%% Purpose : Support for online configuration of ejabberd
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% Created : 26 Oct 2003 by Alexey Shchepin <alexey@process-one.net>
|
|
|
|
%%%
|
|
|
|
%%%
|
2013-01-24 15:25:13 +01:00
|
|
|
%%% ejabberd, Copyright (C) 2002-2013 ProcessOne
|
2007-12-24 12:41:41 +01:00
|
|
|
%%%
|
|
|
|
%%% This program is free software; you can redistribute it and/or
|
|
|
|
%%% modify it under the terms of the GNU General Public License as
|
|
|
|
%%% published by the Free Software Foundation; either version 2 of the
|
|
|
|
%%% License, or (at your option) any later version.
|
|
|
|
%%%
|
|
|
|
%%% This program is distributed in the hope that it will be useful,
|
|
|
|
%%% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
%%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
%%% General Public License for more details.
|
2009-01-12 15:44:42 +01:00
|
|
|
%%%
|
2007-12-24 12:41:41 +01:00
|
|
|
%%% You should have received a copy of the GNU General Public License
|
|
|
|
%%% along with this program; if not, write to the Free Software
|
|
|
|
%%% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|
|
|
%%% 02111-1307 USA
|
|
|
|
%%%
|
2003-11-02 18:16:28 +01:00
|
|
|
%%%----------------------------------------------------------------------
|
|
|
|
|
|
|
|
-module(mod_configure2).
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2007-12-24 12:41:41 +01:00
|
|
|
-author('alexey@process-one.net').
|
2003-11-02 18:16:28 +01:00
|
|
|
|
|
|
|
-behaviour(gen_mod).
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-export([start/2, stop/1, process_local_iq/3]).
|
2003-11-02 18:16:28 +01:00
|
|
|
|
|
|
|
-include("ejabberd.hrl").
|
2013-04-08 11:12:54 +02:00
|
|
|
-include("logger.hrl").
|
2013-03-14 10:33:02 +01:00
|
|
|
|
2003-11-02 18:16:28 +01:00
|
|
|
-include("jlib.hrl").
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
-define(NS_ECONFIGURE,
|
|
|
|
<<"http://ejabberd.jabberstudio.org/protocol/con"
|
|
|
|
"figure">>).
|
2003-11-02 18:16:28 +01:00
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
start(Host, Opts) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, fun gen_iq_handler:check_type/1,
|
|
|
|
one_queue),
|
|
|
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host,
|
|
|
|
?NS_ECONFIGURE, ?MODULE, process_local_iq,
|
|
|
|
IQDisc),
|
2003-11-02 18:16:28 +01:00
|
|
|
ok.
|
|
|
|
|
2005-06-20 05:18:13 +02:00
|
|
|
stop(Host) ->
|
2013-03-14 10:33:02 +01:00
|
|
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host,
|
|
|
|
?NS_ECONFIGURE).
|
2003-11-02 18:16:28 +01:00
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
process_local_iq(From, To,
|
|
|
|
#iq{type = Type, lang = _Lang, sub_el = SubEl} = IQ) ->
|
2005-06-20 05:18:13 +02:00
|
|
|
case acl:match_rule(To#jid.lserver, configure, From) of
|
2013-03-14 10:33:02 +01:00
|
|
|
deny ->
|
|
|
|
IQ#iq{type = error, sub_el = [SubEl, ?ERR_NOT_ALLOWED]};
|
|
|
|
allow ->
|
|
|
|
case Type of
|
|
|
|
set ->
|
|
|
|
IQ#iq{type = error,
|
|
|
|
sub_el = [SubEl, ?ERR_FEATURE_NOT_IMPLEMENTED]};
|
|
|
|
%%case xml:get_tag_attr_s("type", SubEl) of
|
|
|
|
%% "cancel" ->
|
|
|
|
%% IQ#iq{type = result,
|
|
|
|
%% sub_el = [{xmlelement, "query",
|
|
|
|
%% [{"xmlns", XMLNS}], []}]};
|
|
|
|
%% "submit" ->
|
|
|
|
%% XData = jlib:parse_xdata_submit(SubEl),
|
|
|
|
%% case XData of
|
|
|
|
%% invalid ->
|
|
|
|
%% IQ#iq{type = error,
|
|
|
|
%% sub_el = [SubEl, ?ERR_BAD_REQUEST]};
|
|
|
|
%% _ ->
|
|
|
|
%% Node =
|
|
|
|
%% string:tokens(
|
|
|
|
%% xml:get_tag_attr_s("node", SubEl),
|
|
|
|
%% "/"),
|
|
|
|
%% case set_form(Node, Lang, XData) of
|
|
|
|
%% {result, Res} ->
|
|
|
|
%% IQ#iq{type = result,
|
|
|
|
%% sub_el = [{xmlelement, "query",
|
|
|
|
%% [{"xmlns", XMLNS}],
|
|
|
|
%% Res
|
|
|
|
%% }]};
|
|
|
|
%% {error, Error} ->
|
|
|
|
%% IQ#iq{type = error,
|
|
|
|
%% sub_el = [SubEl, Error]}
|
|
|
|
%% end
|
|
|
|
%% end;
|
|
|
|
%% _ ->
|
|
|
|
%% IQ#iq{type = error,
|
|
|
|
%% sub_el = [SubEl, ?ERR_NOT_ALLOWED]}
|
|
|
|
%%end;
|
|
|
|
get ->
|
|
|
|
case process_get(SubEl) of
|
|
|
|
{result, Res} -> IQ#iq{type = result, sub_el = [Res]};
|
|
|
|
{error, Error} ->
|
|
|
|
IQ#iq{type = error, sub_el = [SubEl, Error]}
|
|
|
|
end
|
|
|
|
end
|
2003-11-02 18:16:28 +01:00
|
|
|
end.
|
|
|
|
|
2013-03-14 10:33:02 +01:00
|
|
|
process_get(#xmlel{name = <<"info">>}) ->
|
2003-11-06 21:35:10 +01:00
|
|
|
S2SConns = ejabberd_s2s:dirty_get_connections(),
|
|
|
|
TConns = lists:usort([element(2, C) || C <- S2SConns]),
|
2013-03-14 10:33:02 +01:00
|
|
|
Attrs = [{<<"registered-users">>,
|
|
|
|
iolist_to_binary(integer_to_list(mnesia:table_info(passwd,
|
|
|
|
size)))},
|
|
|
|
{<<"online-users">>,
|
|
|
|
iolist_to_binary(integer_to_list(mnesia:table_info(presence,
|
|
|
|
size)))},
|
|
|
|
{<<"running-nodes">>,
|
|
|
|
iolist_to_binary(integer_to_list(length(mnesia:system_info(running_db_nodes))))},
|
|
|
|
{<<"stopped-nodes">>,
|
|
|
|
iolist_to_binary(integer_to_list(length(lists:usort(mnesia:system_info(db_nodes)
|
|
|
|
++
|
|
|
|
mnesia:system_info(extra_db_nodes))
|
|
|
|
--
|
|
|
|
mnesia:system_info(running_db_nodes))))},
|
|
|
|
{<<"outgoing-s2s-servers">>,
|
|
|
|
iolist_to_binary(integer_to_list(length(TConns)))}],
|
|
|
|
{result,
|
|
|
|
#xmlel{name = <<"info">>,
|
|
|
|
attrs = [{<<"xmlns">>, ?NS_ECONFIGURE} | Attrs],
|
|
|
|
children = []}};
|
|
|
|
process_get(#xmlel{name = <<"welcome-message">>,
|
|
|
|
attrs = Attrs}) ->
|
2013-08-12 14:25:05 +02:00
|
|
|
{Subj, Body} = ejabberd_config:get_option(
|
2013-03-14 10:33:02 +01:00
|
|
|
welcome_message,
|
|
|
|
fun({Subj, Body}) ->
|
|
|
|
{iolist_to_binary(Subj),
|
|
|
|
iolist_to_binary(Body)}
|
|
|
|
end,
|
|
|
|
{<<"">>, <<"">>}),
|
|
|
|
{result,
|
|
|
|
#xmlel{name = <<"welcome-message">>, attrs = Attrs,
|
|
|
|
children =
|
|
|
|
[#xmlel{name = <<"subject">>, attrs = [],
|
|
|
|
children = [{xmlcdata, Subj}]},
|
|
|
|
#xmlel{name = <<"body">>, attrs = [],
|
|
|
|
children = [{xmlcdata, Body}]}]}};
|
|
|
|
process_get(#xmlel{name = <<"registration-watchers">>,
|
|
|
|
attrs = Attrs}) ->
|
2013-08-12 14:25:05 +02:00
|
|
|
SubEls = ejabberd_config:get_option(
|
2013-03-14 10:33:02 +01:00
|
|
|
registration_watchers,
|
|
|
|
fun(JIDs) when is_list(JIDs) ->
|
|
|
|
lists:map(
|
|
|
|
fun(J) ->
|
|
|
|
#xmlel{name = <<"jid">>, attrs = [],
|
|
|
|
children = [{xmlcdata,
|
|
|
|
iolist_to_binary(J)}]}
|
|
|
|
end, JIDs)
|
|
|
|
end, []),
|
|
|
|
{result,
|
|
|
|
#xmlel{name = <<"registration_watchers">>,
|
|
|
|
attrs = Attrs, children = SubEls}};
|
|
|
|
process_get(#xmlel{name = <<"acls">>, attrs = Attrs}) ->
|
|
|
|
Str = iolist_to_binary(io_lib:format("~p.",
|
|
|
|
[ets:tab2list(acl)])),
|
|
|
|
{result,
|
|
|
|
#xmlel{name = <<"acls">>, attrs = Attrs,
|
|
|
|
children = [{xmlcdata, Str}]}};
|
|
|
|
process_get(#xmlel{name = <<"access">>,
|
|
|
|
attrs = Attrs}) ->
|
|
|
|
Str = iolist_to_binary(io_lib:format("~p.",
|
2013-07-27 14:49:52 +02:00
|
|
|
[ets:select(local_config,
|
|
|
|
[{{local_config, {access, '$1'},
|
2013-03-14 10:33:02 +01:00
|
|
|
'$2'},
|
|
|
|
[],
|
|
|
|
[{{access, '$1',
|
|
|
|
'$2'}}]}])])),
|
|
|
|
{result,
|
|
|
|
#xmlel{name = <<"access">>, attrs = Attrs,
|
|
|
|
children = [{xmlcdata, Str}]}};
|
|
|
|
process_get(#xmlel{name = <<"last">>, attrs = Attrs}) ->
|
|
|
|
case catch mnesia:dirty_select(last_activity,
|
|
|
|
[{{last_activity, '_', '$1', '_'}, [],
|
|
|
|
['$1']}])
|
|
|
|
of
|
|
|
|
{'EXIT', _Reason} ->
|
|
|
|
{error, ?ERR_INTERNAL_SERVER_ERROR};
|
|
|
|
Vals ->
|
|
|
|
{MegaSecs, Secs, _MicroSecs} = now(),
|
|
|
|
TimeStamp = MegaSecs * 1000000 + Secs,
|
|
|
|
Str = list_to_binary(
|
|
|
|
[[jlib:integer_to_binary(TimeStamp - V),
|
|
|
|
<<" ">>] || V <- Vals]),
|
|
|
|
{result,
|
|
|
|
#xmlel{name = <<"last">>, attrs = Attrs,
|
|
|
|
children = [{xmlcdata, Str}]}}
|
2003-11-02 18:16:28 +01:00
|
|
|
end;
|
2007-12-07 01:09:48 +01:00
|
|
|
%%process_get({xmlelement, Name, Attrs, SubEls}) ->
|
|
|
|
%% {result, };
|
2013-03-14 10:33:02 +01:00
|
|
|
process_get(_) -> {error, ?ERR_BAD_REQUEST}.
|