mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-24 16:23:40 +01:00
Convert to exmpp.
SVN Revision: 1492
This commit is contained in:
parent
adaf392156
commit
70956ece12
@ -1,3 +1,8 @@
|
|||||||
|
2008-07-25 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
|
* src/adhoc.erl, src/mod_configure.erl, src/mod_announce.erl,
|
||||||
|
src/mod_adhoc.erl, src/gen_iq_handler.erl: Convert to exmpp.
|
||||||
|
|
||||||
2008-07-22 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
2008-07-22 Jean-Sébastien Pédron <js.pedron@meetic-corp.com>
|
||||||
|
|
||||||
* src/mod_disco.erl, src/gen_iq_handler.erl: Convert to exmpp.
|
* src/mod_disco.erl, src/gen_iq_handler.erl: Convert to exmpp.
|
||||||
|
@ -31,19 +31,25 @@
|
|||||||
produce_response/2,
|
produce_response/2,
|
||||||
produce_response/1]).
|
produce_response/1]).
|
||||||
|
|
||||||
|
-include_lib("exmpp/include/exmpp.hrl").
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
|
||||||
-include("adhoc.hrl").
|
-include("adhoc.hrl").
|
||||||
|
|
||||||
%% Parse an ad-hoc request. Return either an adhoc_request record or
|
%% Parse an ad-hoc request. Return either an adhoc_request record or
|
||||||
%% an {error, ErrorType} tuple.
|
%% an {error, ErrorType} tuple.
|
||||||
parse_request(#iq{type = set, lang = Lang, sub_el = SubEl, xmlns = ?NS_COMMANDS}) ->
|
parse_request(IQ) ->
|
||||||
|
try
|
||||||
|
SubEl = exmpp_iq:get_request(IQ),
|
||||||
|
case {exmpp_iq:get_type(IQ), SubEl#xmlel.ns} of
|
||||||
|
{set, ?NS_ADHOC} ->
|
||||||
?DEBUG("entering parse_request...", []),
|
?DEBUG("entering parse_request...", []),
|
||||||
Node = xml:get_tag_attr_s("node", SubEl),
|
Lang = exmpp_stanza:get_lang(IQ),
|
||||||
SessionID = xml:get_tag_attr_s("sessionid", SubEl),
|
Node = exmpp_xml:get_attribute(SubEl, 'node'),
|
||||||
Action = xml:get_tag_attr_s("action", SubEl),
|
SessionID = exmpp_xml:get_attribute(SubEl, 'sessionid'),
|
||||||
|
Action = exmpp_xml:get_attribute(SubEl, 'action'),
|
||||||
XData = find_xdata_el(SubEl),
|
XData = find_xdata_el(SubEl),
|
||||||
{xmlelement, _, _, AllEls} = SubEl,
|
AllEls = SubEl#xmlel.ns,
|
||||||
if XData ->
|
if XData ->
|
||||||
Others = lists:delete(XData, AllEls);
|
Others = lists:delete(XData, AllEls);
|
||||||
true ->
|
true ->
|
||||||
@ -56,22 +62,22 @@ parse_request(#iq{type = set, lang = Lang, sub_el = SubEl, xmlns = ?NS_COMMANDS}
|
|||||||
action = Action,
|
action = Action,
|
||||||
xdata = XData,
|
xdata = XData,
|
||||||
others = Others};
|
others = Others};
|
||||||
parse_request(_) ->
|
_ ->
|
||||||
{error, ?ERR_BAD_REQUEST}.
|
{error, 'bad-request'}
|
||||||
|
end
|
||||||
|
catch
|
||||||
|
_ ->
|
||||||
|
{error, 'bad-request'}
|
||||||
|
end.
|
||||||
|
|
||||||
%% Borrowed from mod_vcard.erl
|
%% Borrowed from mod_vcard.erl
|
||||||
find_xdata_el({xmlelement, _Name, _Attrs, SubEls}) ->
|
find_xdata_el(#xmlel{children = SubEls}) ->
|
||||||
find_xdata_el1(SubEls).
|
find_xdata_el1(SubEls).
|
||||||
|
|
||||||
find_xdata_el1([]) ->
|
find_xdata_el1([]) ->
|
||||||
false;
|
false;
|
||||||
find_xdata_el1([{xmlelement, Name, Attrs, SubEls} | Els]) ->
|
find_xdata_el1([#xmlel{ns = ?NS_DATA_FORMS} = El | _Els]) ->
|
||||||
case xml:get_attr_s("xmlns", Attrs) of
|
El;
|
||||||
?NS_XDATA ->
|
|
||||||
{xmlelement, Name, Attrs, SubEls};
|
|
||||||
_ ->
|
|
||||||
find_xdata_el1(Els)
|
|
||||||
end;
|
|
||||||
find_xdata_el1([_ | Els]) ->
|
find_xdata_el1([_ | Els]) ->
|
||||||
find_xdata_el1(Els).
|
find_xdata_el1(Els).
|
||||||
|
|
||||||
@ -109,20 +115,19 @@ produce_response(#adhoc_response{lang = _Lang,
|
|||||||
"" ->
|
"" ->
|
||||||
ActionsElAttrs = [];
|
ActionsElAttrs = [];
|
||||||
_ ->
|
_ ->
|
||||||
ActionsElAttrs = [{"execute", DefaultAction}]
|
ActionsElAttrs = [#xmlattr{name = 'execute', value = DefaultAction}]
|
||||||
end,
|
end,
|
||||||
ActionsEls = [{xmlelement, "actions",
|
ActionsEls = [#xmlel{ns = ?NS_ADHOC, name = 'actions', attrs =
|
||||||
ActionsElAttrs,
|
ActionsElAttrs, children =
|
||||||
[{xmlelement, Action, [], []} || Action <- Actions]}]
|
[#xmlel{ns = ?NS_ADHOC, name = Action} || Action <- Actions]}]
|
||||||
end,
|
end,
|
||||||
NotesEls = lists:map(fun({Type, Text}) ->
|
NotesEls = lists:map(fun({Type, Text}) ->
|
||||||
{xmlelement, "note",
|
#xmlel{ns = ?NS_ADHOC, name = 'note', attrs =
|
||||||
[{"type", Type}],
|
[#xmlattr{name = 'type', value = Type}],
|
||||||
[{xmlcdata, Text}]}
|
children = [#xmlcdata{cdata = list_to_binary(Text)}]}
|
||||||
end, Notes),
|
end, Notes),
|
||||||
{xmlelement, "command",
|
#xmlel{ns = ?NS_ADHOC, name = 'command', attrs =
|
||||||
[{"xmlns", ?NS_COMMANDS},
|
[#xmlattr{name = 'sessionid', value = SessionID},
|
||||||
{"sessionid", SessionID},
|
#xmlattr{name = 'node', value = Node},
|
||||||
{"node", Node},
|
#xmlattr{name = 'status', value = atom_to_list(Status)}], children =
|
||||||
{"status", atom_to_list(Status)}],
|
|
||||||
ActionsEls ++ NotesEls ++ Elements}.
|
ActionsEls ++ NotesEls ++ Elements}.
|
||||||
|
@ -59,7 +59,10 @@
|
|||||||
% XXX OLD FORMAT: modules not in the following list will receive
|
% XXX OLD FORMAT: modules not in the following list will receive
|
||||||
% old format strudctures.
|
% old format strudctures.
|
||||||
-define(CONVERTED_MODULES, [
|
-define(CONVERTED_MODULES, [
|
||||||
|
mod_adhoc,
|
||||||
|
mod_annouce,
|
||||||
mod_caps,
|
mod_caps,
|
||||||
|
mod_configure,
|
||||||
mod_disco,
|
mod_disco,
|
||||||
mod_roster,
|
mod_roster,
|
||||||
mod_vcard
|
mod_vcard
|
||||||
|
@ -42,16 +42,17 @@
|
|||||||
ping_item/4,
|
ping_item/4,
|
||||||
ping_command/4]).
|
ping_command/4]).
|
||||||
|
|
||||||
|
-include_lib("exmpp/include/exmpp.hrl").
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
|
||||||
-include("adhoc.hrl").
|
-include("adhoc.hrl").
|
||||||
|
|
||||||
start(Host, Opts) ->
|
start(Host, Opts) ->
|
||||||
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
IQDisc = gen_mod:get_opt(iqdisc, Opts, one_queue),
|
||||||
|
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_COMMANDS,
|
gen_iq_handler:add_iq_handler(ejabberd_local, Host, ?NS_ADHOC_s,
|
||||||
?MODULE, process_local_iq, IQDisc),
|
?MODULE, process_local_iq, IQDisc),
|
||||||
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_COMMANDS,
|
gen_iq_handler:add_iq_handler(ejabberd_sm, Host, ?NS_ADHOC_s,
|
||||||
?MODULE, process_sm_iq, IQDisc),
|
?MODULE, process_sm_iq, IQDisc),
|
||||||
|
|
||||||
ejabberd_hooks:add(disco_local_identity, Host, ?MODULE, get_local_identity, 99),
|
ejabberd_hooks:add(disco_local_identity, Host, ?MODULE, get_local_identity, 99),
|
||||||
@ -73,12 +74,12 @@ stop(Host) ->
|
|||||||
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, get_local_features, 99),
|
ejabberd_hooks:delete(disco_local_features, Host, ?MODULE, get_local_features, 99),
|
||||||
ejabberd_hooks:delete(disco_local_identity, Host, ?MODULE, get_local_identity, 99),
|
ejabberd_hooks:delete(disco_local_identity, Host, ?MODULE, get_local_identity, 99),
|
||||||
|
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_COMMANDS),
|
gen_iq_handler:remove_iq_handler(ejabberd_sm, Host, ?NS_ADHOC_s),
|
||||||
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_COMMANDS).
|
gen_iq_handler:remove_iq_handler(ejabberd_local, Host, ?NS_ADHOC_s).
|
||||||
|
|
||||||
%-------------------------------------------------------------------------
|
%-------------------------------------------------------------------------
|
||||||
|
|
||||||
get_local_commands(Acc, _From, #jid{server = Server, lserver = LServer} = _To, "", Lang) ->
|
get_local_commands(Acc, _From, #jid{domain = Server, ldomain = LServer} = _To, "", Lang) ->
|
||||||
Display = gen_mod:get_module_opt(LServer, ?MODULE, report_commands_node, false),
|
Display = gen_mod:get_module_opt(LServer, ?MODULE, report_commands_node, false),
|
||||||
case Display of
|
case Display of
|
||||||
false ->
|
false ->
|
||||||
@ -88,17 +89,20 @@ get_local_commands(Acc, _From, #jid{server = Server, lserver = LServer} = _To, "
|
|||||||
{result, I} -> I;
|
{result, I} -> I;
|
||||||
_ -> []
|
_ -> []
|
||||||
end,
|
end,
|
||||||
Nodes = [{xmlelement,
|
Nodes = [#xmlel{ns = ?NS_DISCO_ITEMS,
|
||||||
"item",
|
name = 'item', attrs =
|
||||||
[{"jid", Server},
|
[#xmlattr{name = 'jid', value = Server},
|
||||||
{"node", ?NS_COMMANDS},
|
#xmlattr{name = 'node', value = ?NS_ADHOC_s},
|
||||||
{"name", translate:translate(Lang, "Commands")}],
|
#xmlattr{name = 'name', value = translate:translate(Lang, "Commands")}]
|
||||||
[]}],
|
}],
|
||||||
{result, Items ++ Nodes}
|
{result, Items ++ Nodes}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
get_local_commands(_Acc, From, #jid{lserver = LServer} = To, ?NS_COMMANDS, Lang) ->
|
get_local_commands(_Acc, From, #jid{ldomain = LServer} = To, ?NS_ADHOC_s, Lang) ->
|
||||||
ejabberd_hooks:run_fold(adhoc_local_items, LServer, {result, []}, [From, To, Lang]);
|
% XXX OLD FORMAT: From, To.
|
||||||
|
FromOld = jlib:to_old_jid(From),
|
||||||
|
ToOld = jlib:to_old_jid(To),
|
||||||
|
ejabberd_hooks:run_fold(adhoc_local_items, LServer, {result, []}, [FromOld, ToOld, Lang]);
|
||||||
|
|
||||||
get_local_commands(_Acc, _From, _To, "ping", _Lang) ->
|
get_local_commands(_Acc, _From, _To, "ping", _Lang) ->
|
||||||
{result, []};
|
{result, []};
|
||||||
@ -108,7 +112,7 @@ get_local_commands(Acc, _From, _To, _Node, _Lang) ->
|
|||||||
|
|
||||||
%-------------------------------------------------------------------------
|
%-------------------------------------------------------------------------
|
||||||
|
|
||||||
get_sm_commands(Acc, _From, #jid{lserver = LServer} = To, "", Lang) ->
|
get_sm_commands(Acc, _From, #jid{ldomain = LServer} = To, "", Lang) ->
|
||||||
Display = gen_mod:get_module_opt(LServer, ?MODULE, report_commands_node, false),
|
Display = gen_mod:get_module_opt(LServer, ?MODULE, report_commands_node, false),
|
||||||
case Display of
|
case Display of
|
||||||
false ->
|
false ->
|
||||||
@ -118,17 +122,20 @@ get_sm_commands(Acc, _From, #jid{lserver = LServer} = To, "", Lang) ->
|
|||||||
{result, I} -> I;
|
{result, I} -> I;
|
||||||
_ -> []
|
_ -> []
|
||||||
end,
|
end,
|
||||||
Nodes = [{xmlelement,
|
Nodes = [#xmlel{ns = ?NS_DISCO_ITEMS,
|
||||||
"item",
|
name = 'item', attrs =
|
||||||
[{"jid", jlib:jid_to_string(To)},
|
[#xmlattr{name = 'jid', value = exmpp_jid:jid_to_string(To)},
|
||||||
{"node", ?NS_COMMANDS},
|
#xmlattr{name = 'node', value = ?NS_ADHOC_s},
|
||||||
{"name", translate:translate(Lang, "Commands")}],
|
#xmlattr{name = 'name', value = translate:translate(Lang, "Commands")}]
|
||||||
[]}],
|
}],
|
||||||
{result, Items ++ Nodes}
|
{result, Items ++ Nodes}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
get_sm_commands(_Acc, From, #jid{lserver = LServer} = To, ?NS_COMMANDS, Lang) ->
|
get_sm_commands(_Acc, From, #jid{ldomain = LServer} = To, ?NS_ADHOC_s, Lang) ->
|
||||||
ejabberd_hooks:run_fold(adhoc_sm_items, LServer, {result, []}, [From, To, Lang]);
|
% XXX OLD FORMAT: From, To.
|
||||||
|
FromOld = jlib:to_old_jid(From),
|
||||||
|
ToOld = jlib:to_old_jid(To),
|
||||||
|
ejabberd_hooks:run_fold(adhoc_sm_items, LServer, {result, []}, [FromOld, ToOld, Lang]);
|
||||||
|
|
||||||
get_sm_commands(Acc, _From, _To, _Node, _Lang) ->
|
get_sm_commands(Acc, _From, _To, _Node, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
@ -136,17 +143,17 @@ get_sm_commands(Acc, _From, _To, _Node, _Lang) ->
|
|||||||
%-------------------------------------------------------------------------
|
%-------------------------------------------------------------------------
|
||||||
|
|
||||||
%% On disco info request to the ad-hoc node, return automation/command-list.
|
%% On disco info request to the ad-hoc node, return automation/command-list.
|
||||||
get_local_identity(Acc, _From, _To, ?NS_COMMANDS, Lang) ->
|
get_local_identity(Acc, _From, _To, ?NS_ADHOC_s, Lang) ->
|
||||||
[{xmlelement, "identity",
|
[#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs =
|
||||||
[{"category", "automation"},
|
[#xmlattr{name = 'category', value = "automation"},
|
||||||
{"type", "command-list"},
|
#xmlattr{name = 'type', value = "command-list"},
|
||||||
{"name", translate:translate(Lang, "Commands")}], []} | Acc];
|
#xmlattr{name = 'name', value = translate:translate(Lang, "Commands")}]} | Acc];
|
||||||
|
|
||||||
get_local_identity(Acc, _From, _To, "ping", Lang) ->
|
get_local_identity(Acc, _From, _To, "ping", Lang) ->
|
||||||
[{xmlelement, "identity",
|
[#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs =
|
||||||
[{"category", "automation"},
|
[#xmlattr{name = 'category', value = "automation"},
|
||||||
{"type", "command-node"},
|
#xmlattr{name = 'type', value = "command-node"},
|
||||||
{"name", translate:translate(Lang, "Ping")}], []} | Acc];
|
#xmlattr{name = 'name', value = translate:translate(Lang, "Ping")}]} | Acc];
|
||||||
|
|
||||||
get_local_identity(Acc, _From, _To, _Node, _Lang) ->
|
get_local_identity(Acc, _From, _To, _Node, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
@ -154,11 +161,11 @@ get_local_identity(Acc, _From, _To, _Node, _Lang) ->
|
|||||||
%-------------------------------------------------------------------------
|
%-------------------------------------------------------------------------
|
||||||
|
|
||||||
%% On disco info request to the ad-hoc node, return automation/command-list.
|
%% On disco info request to the ad-hoc node, return automation/command-list.
|
||||||
get_sm_identity(Acc, _From, _To, ?NS_COMMANDS, Lang) ->
|
get_sm_identity(Acc, _From, _To, ?NS_ADHOC_s, Lang) ->
|
||||||
[{xmlelement, "identity",
|
[#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs =
|
||||||
[{"category", "automation"},
|
[#xmlattr{name = 'category', value = "automation"},
|
||||||
{"type", "command-list"},
|
#xmlattr{name = 'type', value = "command-list"},
|
||||||
{"name", translate:translate(Lang, "Commands")}], []} | Acc];
|
#xmlattr{name = 'name', value = translate:translate(Lang, "Commands")}]} | Acc];
|
||||||
|
|
||||||
get_sm_identity(Acc, _From, _To, _Node, _Lang) ->
|
get_sm_identity(Acc, _From, _To, _Node, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
@ -170,15 +177,15 @@ get_local_features(Acc, _From, _To, "", _Lang) ->
|
|||||||
{result, I} -> I;
|
{result, I} -> I;
|
||||||
_ -> []
|
_ -> []
|
||||||
end,
|
end,
|
||||||
{result, Feats ++ [?NS_COMMANDS]};
|
{result, Feats ++ [?NS_ADHOC_s]};
|
||||||
|
|
||||||
get_local_features(_Acc, _From, _To, ?NS_COMMANDS, _Lang) ->
|
get_local_features(_Acc, _From, _To, ?NS_ADHOC_s, _Lang) ->
|
||||||
%% override all lesser features...
|
%% override all lesser features...
|
||||||
{result, []};
|
{result, []};
|
||||||
|
|
||||||
get_local_features(_Acc, _From, _To, "ping", _Lang) ->
|
get_local_features(_Acc, _From, _To, "ping", _Lang) ->
|
||||||
%% override all lesser features...
|
%% override all lesser features...
|
||||||
{result, [?NS_COMMANDS]};
|
{result, [?NS_ADHOC_s]};
|
||||||
|
|
||||||
get_local_features(Acc, _From, _To, _Node, _Lang) ->
|
get_local_features(Acc, _From, _To, _Node, _Lang) ->
|
||||||
Acc.
|
Acc.
|
||||||
@ -190,9 +197,9 @@ get_sm_features(Acc, _From, _To, "", _Lang) ->
|
|||||||
{result, I} -> I;
|
{result, I} -> I;
|
||||||
_ -> []
|
_ -> []
|
||||||
end,
|
end,
|
||||||
{result, Feats ++ [?NS_COMMANDS]};
|
{result, Feats ++ [?NS_ADHOC_s]};
|
||||||
|
|
||||||
get_sm_features(_Acc, _From, _To, ?NS_COMMANDS, _Lang) ->
|
get_sm_features(_Acc, _From, _To, ?NS_ADHOC_s, _Lang) ->
|
||||||
%% override all lesser features...
|
%% override all lesser features...
|
||||||
{result, []};
|
{result, []};
|
||||||
|
|
||||||
@ -209,39 +216,41 @@ process_sm_iq(From, To, IQ) ->
|
|||||||
process_adhoc_request(From, To, IQ, adhoc_sm_commands).
|
process_adhoc_request(From, To, IQ, adhoc_sm_commands).
|
||||||
|
|
||||||
|
|
||||||
process_adhoc_request(From, To, #iq{sub_el = SubEl} = IQ, Hook) ->
|
process_adhoc_request(From, To, IQ, Hook) ->
|
||||||
?DEBUG("About to parse ~p...", [IQ]),
|
?DEBUG("About to parse ~p...", [IQ]),
|
||||||
case adhoc:parse_request(IQ) of
|
case adhoc:parse_request(IQ) of
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
IQ#iq{type = error, sub_el = [SubEl, Error]};
|
exmpp_iq:error(IQ, Error);
|
||||||
#adhoc_request{} = AdhocRequest ->
|
#adhoc_request{} = AdhocRequest ->
|
||||||
Host = To#jid.lserver,
|
Host = To#jid.ldomain,
|
||||||
|
% XXX OLD FORMAT: From, To.
|
||||||
|
FromOld = jlib:to_old_jid(From),
|
||||||
|
ToOld = jlib:to_old_jid(To),
|
||||||
case ejabberd_hooks:run_fold(Hook, Host, empty,
|
case ejabberd_hooks:run_fold(Hook, Host, empty,
|
||||||
[From, To, AdhocRequest]) of
|
[FromOld, ToOld, AdhocRequest]) of
|
||||||
ignore ->
|
ignore ->
|
||||||
ignore;
|
ignore;
|
||||||
empty ->
|
empty ->
|
||||||
IQ#iq{type = error, sub_el = [SubEl, ?ERR_ITEM_NOT_FOUND]};
|
exmpp_iq:error(IQ, 'item-not-found');
|
||||||
{error, Error} ->
|
{error, Error} ->
|
||||||
IQ#iq{type = error, sub_el = [SubEl, Error]};
|
exmpp_iq:error(IQ, Error);
|
||||||
Command ->
|
Command ->
|
||||||
IQ#iq{type = result, sub_el = [Command]}
|
exmpp_iq:result(IQ, Command)
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
ping_item(Acc, _From, #jid{server = Server} = _To, Lang) ->
|
ping_item(Acc, _From, #jid{domain = Server} = _To, Lang) ->
|
||||||
Items = case Acc of
|
Items = case Acc of
|
||||||
{result, I} ->
|
{result, I} ->
|
||||||
I;
|
I;
|
||||||
_ ->
|
_ ->
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
Nodes = [{xmlelement, "item",
|
Nodes = [#xmlel{ns = ?NS_DISCO_INFO, name = 'item', attrs =
|
||||||
[{"jid", Server},
|
[#xmlattr{name = 'jid', value = Server},
|
||||||
{"node", "ping"},
|
#xmlattr{name = 'node', value = "ping"},
|
||||||
{"name", translate:translate(Lang, "Ping")}],
|
#xmlattr{name = 'name', value = translate:translate(Lang, "Ping")}]}],
|
||||||
[]}],
|
|
||||||
{result, Items ++ Nodes}.
|
{result, Items ++ Nodes}.
|
||||||
|
|
||||||
|
|
||||||
@ -259,7 +268,7 @@ ping_command(_Acc, _From, _To,
|
|||||||
Lang,
|
Lang,
|
||||||
"Pong")}]});
|
"Pong")}]});
|
||||||
true ->
|
true ->
|
||||||
{error, ?ERR_BAD_REQUEST}
|
{error, 'bad-request'}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
ping_command(Acc, _From, _To, _Request) ->
|
ping_command(Acc, _From, _To, _Request) ->
|
||||||
|
@ -43,8 +43,9 @@
|
|||||||
announce_commands/4,
|
announce_commands/4,
|
||||||
announce_items/4]).
|
announce_items/4]).
|
||||||
|
|
||||||
|
-include_lib("exmpp/include/exmpp.hrl").
|
||||||
|
|
||||||
-include("ejabberd.hrl").
|
-include("ejabberd.hrl").
|
||||||
-include("jlib.hrl").
|
|
||||||
-include("adhoc.hrl").
|
-include("adhoc.hrl").
|
||||||
|
|
||||||
-record(motd, {server, packet}).
|
-record(motd, {server, packet}).
|
||||||
@ -52,6 +53,8 @@
|
|||||||
|
|
||||||
-define(PROCNAME, ejabberd_announce).
|
-define(PROCNAME, ejabberd_announce).
|
||||||
|
|
||||||
|
-define(NS_ADMIN_s, "http://jabber.org/protocol/admin").
|
||||||
|
|
||||||
-define(NS_ADMINL(Sub), ["http:","jabber.org","protocol","admin", Sub]).
|
-define(NS_ADMINL(Sub), ["http:","jabber.org","protocol","admin", Sub]).
|
||||||
tokenize(Node) -> string:tokens(Node, "/#").
|
tokenize(Node) -> string:tokens(Node, "/#").
|
||||||
|
|
||||||
@ -129,38 +132,38 @@ stop(Host) ->
|
|||||||
%% Announcing via messages to a custom resource
|
%% Announcing via messages to a custom resource
|
||||||
announce(From, To, Packet) ->
|
announce(From, To, Packet) ->
|
||||||
case To of
|
case To of
|
||||||
#jid{luser = "", lresource = Res} ->
|
#jid{lnode = undefined, lresource = Res} ->
|
||||||
{xmlelement, Name, _Attrs, _Els} = Packet,
|
Name = Packet#xmlel.name,
|
||||||
Proc = gen_mod:get_module_proc(To#jid.lserver, ?PROCNAME),
|
Proc = gen_mod:get_module_proc(To#jid.ldomain, ?PROCNAME),
|
||||||
case {Res, Name} of
|
case {Res, Name} of
|
||||||
{"announce/all", "message"} ->
|
{"announce/all", 'message'} ->
|
||||||
Proc ! {announce_all, From, To, Packet},
|
Proc ! {announce_all, From, To, Packet},
|
||||||
stop;
|
stop;
|
||||||
{"announce/all-hosts/all", "message"} ->
|
{"announce/all-hosts/all", 'message'} ->
|
||||||
Proc ! {announce_all_hosts_all, From, To, Packet},
|
Proc ! {announce_all_hosts_all, From, To, Packet},
|
||||||
stop;
|
stop;
|
||||||
{"announce/online", "message"} ->
|
{"announce/online", 'message'} ->
|
||||||
Proc ! {announce_online, From, To, Packet},
|
Proc ! {announce_online, From, To, Packet},
|
||||||
stop;
|
stop;
|
||||||
{"announce/all-hosts/online", "message"} ->
|
{"announce/all-hosts/online", 'message'} ->
|
||||||
Proc ! {announce_all_hosts_online, From, To, Packet},
|
Proc ! {announce_all_hosts_online, From, To, Packet},
|
||||||
stop;
|
stop;
|
||||||
{"announce/motd", "message"} ->
|
{"announce/motd", 'message'} ->
|
||||||
Proc ! {announce_motd, From, To, Packet},
|
Proc ! {announce_motd, From, To, Packet},
|
||||||
stop;
|
stop;
|
||||||
{"announce/all-hosts/motd", "message"} ->
|
{"announce/all-hosts/motd", 'message'} ->
|
||||||
Proc ! {announce_all_hosts_motd, From, To, Packet},
|
Proc ! {announce_all_hosts_motd, From, To, Packet},
|
||||||
stop;
|
stop;
|
||||||
{"announce/motd/update", "message"} ->
|
{"announce/motd/update", 'message'} ->
|
||||||
Proc ! {announce_motd_update, From, To, Packet},
|
Proc ! {announce_motd_update, From, To, Packet},
|
||||||
stop;
|
stop;
|
||||||
{"announce/all-hosts/motd/update", "message"} ->
|
{"announce/all-hosts/motd/update", 'message'} ->
|
||||||
Proc ! {announce_all_hosts_motd_update, From, To, Packet},
|
Proc ! {announce_all_hosts_motd_update, From, To, Packet},
|
||||||
stop;
|
stop;
|
||||||
{"announce/motd/delete", "message"} ->
|
{"announce/motd/delete", 'message'} ->
|
||||||
Proc ! {announce_motd_delete, From, To, Packet},
|
Proc ! {announce_motd_delete, From, To, Packet},
|
||||||
stop;
|
stop;
|
||||||
{"announce/all-hosts/motd/delete", "message"} ->
|
{"announce/all-hosts/motd/delete", 'message'} ->
|
||||||
Proc ! {announce_all_hosts_motd_delete, From, To, Packet},
|
Proc ! {announce_all_hosts_motd_delete, From, To, Packet},
|
||||||
stop;
|
stop;
|
||||||
_ ->
|
_ ->
|
||||||
@ -173,10 +176,10 @@ announce(From, To, Packet) ->
|
|||||||
%%-------------------------------------------------------------------------
|
%%-------------------------------------------------------------------------
|
||||||
%% Announcing via ad-hoc commands
|
%% Announcing via ad-hoc commands
|
||||||
-define(INFO_COMMAND(Lang, Node),
|
-define(INFO_COMMAND(Lang, Node),
|
||||||
[{xmlelement, "identity",
|
[#xmlel{ns = ?NS_DISCO_INFO, name = 'identity', attrs =
|
||||||
[{"category", "automation"},
|
[#xmlattr{name = 'category', value = "automation"},
|
||||||
{"type", "command-node"},
|
#xmlattr{name = 'type', value = "command-node"},
|
||||||
{"name", get_title(Lang, Node)}], []}]).
|
#xmlattr{name = 'name', value = get_title(Lang, Node)}]}]).
|
||||||
|
|
||||||
disco_identity(Acc, _From, _To, Node, Lang) ->
|
disco_identity(Acc, _From, _To, Node, Lang) ->
|
||||||
LNode = tokenize(Node),
|
LNode = tokenize(Node),
|
||||||
@ -210,12 +213,12 @@ disco_identity(Acc, _From, _To, Node, Lang) ->
|
|||||||
-define(INFO_RESULT(Allow, Feats),
|
-define(INFO_RESULT(Allow, Feats),
|
||||||
case Allow of
|
case Allow of
|
||||||
deny ->
|
deny ->
|
||||||
{error, ?ERR_FORBIDDEN};
|
{error, 'forbidden'};
|
||||||
allow ->
|
allow ->
|
||||||
{result, Feats}
|
{result, Feats}
|
||||||
end).
|
end).
|
||||||
|
|
||||||
disco_features(Acc, From, #jid{lserver = LServer} = _To,
|
disco_features(Acc, From, #jid{ldomain = LServer} = _To,
|
||||||
"announce", _Lang) ->
|
"announce", _Lang) ->
|
||||||
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
||||||
false ->
|
false ->
|
||||||
@ -226,13 +229,13 @@ disco_features(Acc, From, #jid{lserver = LServer} = _To,
|
|||||||
case {acl:match_rule(LServer, Access1, From),
|
case {acl:match_rule(LServer, Access1, From),
|
||||||
acl:match_rule(global, Access2, From)} of
|
acl:match_rule(global, Access2, From)} of
|
||||||
{deny, deny} ->
|
{deny, deny} ->
|
||||||
{error, ?ERR_FORBIDDEN};
|
{error, 'forbidden'};
|
||||||
_ ->
|
_ ->
|
||||||
{result, []}
|
{result, []}
|
||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
disco_features(Acc, From, #jid{lserver = LServer} = _To,
|
disco_features(Acc, From, #jid{ldomain = LServer} = _To,
|
||||||
Node, _Lang) ->
|
Node, _Lang) ->
|
||||||
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
||||||
false ->
|
false ->
|
||||||
@ -243,26 +246,26 @@ disco_features(Acc, From, #jid{lserver = LServer} = _To,
|
|||||||
AccessGlobal = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
AccessGlobal = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
||||||
AllowGlobal = acl:match_rule(global, AccessGlobal, From),
|
AllowGlobal = acl:match_rule(global, AccessGlobal, From),
|
||||||
case Node of
|
case Node of
|
||||||
?NS_ADMIN ++ "#announce" ->
|
?NS_ADMIN_s ++ "#announce" ->
|
||||||
?INFO_RESULT(Allow, [?NS_COMMANDS]);
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
||||||
?NS_ADMIN ++ "#announce-all" ->
|
?NS_ADMIN_s ++ "#announce-all" ->
|
||||||
?INFO_RESULT(Allow, [?NS_COMMANDS]);
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
||||||
?NS_ADMIN ++ "#set-motd" ->
|
?NS_ADMIN_s ++ "#set-motd" ->
|
||||||
?INFO_RESULT(Allow, [?NS_COMMANDS]);
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
||||||
?NS_ADMIN ++ "#edit-motd" ->
|
?NS_ADMIN_s ++ "#edit-motd" ->
|
||||||
?INFO_RESULT(Allow, [?NS_COMMANDS]);
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
||||||
?NS_ADMIN ++ "#delete-motd" ->
|
?NS_ADMIN_s ++ "#delete-motd" ->
|
||||||
?INFO_RESULT(Allow, [?NS_COMMANDS]);
|
?INFO_RESULT(Allow, [?NS_ADHOC_s]);
|
||||||
?NS_ADMIN ++ "#announce-allhosts" ->
|
?NS_ADMIN_s ++ "#announce-allhosts" ->
|
||||||
?INFO_RESULT(AllowGlobal, [?NS_COMMANDS]);
|
?INFO_RESULT(AllowGlobal, [?NS_ADHOC_s]);
|
||||||
?NS_ADMIN ++ "#announce-all-allhosts" ->
|
?NS_ADMIN_s ++ "#announce-all-allhosts" ->
|
||||||
?INFO_RESULT(AllowGlobal, [?NS_COMMANDS]);
|
?INFO_RESULT(AllowGlobal, [?NS_ADHOC_s]);
|
||||||
?NS_ADMIN ++ "#set-motd-allhosts" ->
|
?NS_ADMIN_s ++ "#set-motd-allhosts" ->
|
||||||
?INFO_RESULT(AllowGlobal, [?NS_COMMANDS]);
|
?INFO_RESULT(AllowGlobal, [?NS_ADHOC_s]);
|
||||||
?NS_ADMIN ++ "#edit-motd-allhosts" ->
|
?NS_ADMIN_s ++ "#edit-motd-allhosts" ->
|
||||||
?INFO_RESULT(AllowGlobal, [?NS_COMMANDS]);
|
?INFO_RESULT(AllowGlobal, [?NS_ADHOC_s]);
|
||||||
?NS_ADMIN ++ "#delete-motd-allhosts" ->
|
?NS_ADMIN_s ++ "#delete-motd-allhosts" ->
|
||||||
?INFO_RESULT(AllowGlobal, [?NS_COMMANDS]);
|
?INFO_RESULT(AllowGlobal, [?NS_ADHOC_s]);
|
||||||
_ ->
|
_ ->
|
||||||
Acc
|
Acc
|
||||||
end
|
end
|
||||||
@ -271,21 +274,20 @@ disco_features(Acc, From, #jid{lserver = LServer} = _To,
|
|||||||
%%-------------------------------------------------------------------------
|
%%-------------------------------------------------------------------------
|
||||||
|
|
||||||
-define(NODE_TO_ITEM(Lang, Server, Node),
|
-define(NODE_TO_ITEM(Lang, Server, Node),
|
||||||
{xmlelement, "item",
|
#xmlel{ns = ?NS_DISCO_ITEMS, name = 'item', attrs =
|
||||||
[{"jid", Server},
|
[#xmlattr{name = 'jid', value = Server},
|
||||||
{"node", Node},
|
#xmlattr{name = 'node', value = Node},
|
||||||
{"name", get_title(Lang, Node)}],
|
#xmlattr{name = 'name', value = get_title(Lang, Node)}]}).
|
||||||
[]}).
|
|
||||||
|
|
||||||
-define(ITEMS_RESULT(Allow, Items),
|
-define(ITEMS_RESULT(Allow, Items),
|
||||||
case Allow of
|
case Allow of
|
||||||
deny ->
|
deny ->
|
||||||
{error, ?ERR_FORBIDDEN};
|
{error, 'forbidden'};
|
||||||
allow ->
|
allow ->
|
||||||
{result, Items}
|
{result, Items}
|
||||||
end).
|
end).
|
||||||
|
|
||||||
disco_items(Acc, From, #jid{lserver = LServer, server = Server} = _To,
|
disco_items(Acc, From, #jid{ldomain = LServer, domain = Server} = _To,
|
||||||
"", Lang) ->
|
"", Lang) ->
|
||||||
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
||||||
false ->
|
false ->
|
||||||
@ -307,7 +309,7 @@ disco_items(Acc, From, #jid{lserver = LServer, server = Server} = _To,
|
|||||||
end
|
end
|
||||||
end;
|
end;
|
||||||
|
|
||||||
disco_items(Acc, From, #jid{lserver = LServer} = To, "announce", Lang) ->
|
disco_items(Acc, From, #jid{ldomain = LServer} = To, "announce", Lang) ->
|
||||||
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
||||||
false ->
|
false ->
|
||||||
Acc;
|
Acc;
|
||||||
@ -315,7 +317,7 @@ disco_items(Acc, From, #jid{lserver = LServer} = To, "announce", Lang) ->
|
|||||||
announce_items(Acc, From, To, Lang)
|
announce_items(Acc, From, To, Lang)
|
||||||
end;
|
end;
|
||||||
|
|
||||||
disco_items(Acc, From, #jid{lserver = LServer} = _To, Node, _Lang) ->
|
disco_items(Acc, From, #jid{ldomain = LServer} = _To, Node, _Lang) ->
|
||||||
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
case gen_mod:is_loaded(LServer, mod_adhoc) of
|
||||||
false ->
|
false ->
|
||||||
Acc;
|
Acc;
|
||||||
@ -325,25 +327,25 @@ disco_items(Acc, From, #jid{lserver = LServer} = _To, Node, _Lang) ->
|
|||||||
AccessGlobal = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
AccessGlobal = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
||||||
AllowGlobal = acl:match_rule(global, AccessGlobal, From),
|
AllowGlobal = acl:match_rule(global, AccessGlobal, From),
|
||||||
case Node of
|
case Node of
|
||||||
?NS_ADMIN ++ "#announce" ->
|
?NS_ADMIN_s ++ "#announce" ->
|
||||||
?ITEMS_RESULT(Allow, []);
|
?ITEMS_RESULT(Allow, []);
|
||||||
?NS_ADMIN ++ "#announce-all" ->
|
?NS_ADMIN_s ++ "#announce-all" ->
|
||||||
?ITEMS_RESULT(Allow, []);
|
?ITEMS_RESULT(Allow, []);
|
||||||
?NS_ADMIN ++ "#set-motd" ->
|
?NS_ADMIN_s ++ "#set-motd" ->
|
||||||
?ITEMS_RESULT(Allow, []);
|
?ITEMS_RESULT(Allow, []);
|
||||||
?NS_ADMIN ++ "#edit-motd" ->
|
?NS_ADMIN_s ++ "#edit-motd" ->
|
||||||
?ITEMS_RESULT(Allow, []);
|
?ITEMS_RESULT(Allow, []);
|
||||||
?NS_ADMIN ++ "#delete-motd" ->
|
?NS_ADMIN_s ++ "#delete-motd" ->
|
||||||
?ITEMS_RESULT(Allow, []);
|
?ITEMS_RESULT(Allow, []);
|
||||||
?NS_ADMIN ++ "#announce-allhosts" ->
|
?NS_ADMIN_s ++ "#announce-allhosts" ->
|
||||||
?ITEMS_RESULT(AllowGlobal, []);
|
?ITEMS_RESULT(AllowGlobal, []);
|
||||||
?NS_ADMIN ++ "#announce-all-allhosts" ->
|
?NS_ADMIN_s ++ "#announce-all-allhosts" ->
|
||||||
?ITEMS_RESULT(AllowGlobal, []);
|
?ITEMS_RESULT(AllowGlobal, []);
|
||||||
?NS_ADMIN ++ "#set-motd-allhosts" ->
|
?NS_ADMIN_s ++ "#set-motd-allhosts" ->
|
||||||
?ITEMS_RESULT(AllowGlobal, []);
|
?ITEMS_RESULT(AllowGlobal, []);
|
||||||
?NS_ADMIN ++ "#edit-motd-allhosts" ->
|
?NS_ADMIN_s ++ "#edit-motd-allhosts" ->
|
||||||
?ITEMS_RESULT(AllowGlobal, []);
|
?ITEMS_RESULT(AllowGlobal, []);
|
||||||
?NS_ADMIN ++ "#delete-motd-allhosts" ->
|
?NS_ADMIN_s ++ "#delete-motd-allhosts" ->
|
||||||
?ITEMS_RESULT(AllowGlobal, []);
|
?ITEMS_RESULT(AllowGlobal, []);
|
||||||
_ ->
|
_ ->
|
||||||
Acc
|
Acc
|
||||||
@ -352,26 +354,26 @@ disco_items(Acc, From, #jid{lserver = LServer} = _To, Node, _Lang) ->
|
|||||||
|
|
||||||
%%-------------------------------------------------------------------------
|
%%-------------------------------------------------------------------------
|
||||||
|
|
||||||
announce_items(Acc, From, #jid{lserver = LServer, server = Server} = _To, Lang) ->
|
announce_items(Acc, From, #jid{ldomain = LServer, domain = Server} = _To, Lang) ->
|
||||||
Access1 = gen_mod:get_module_opt(LServer, ?MODULE, access, none),
|
Access1 = gen_mod:get_module_opt(LServer, ?MODULE, access, none),
|
||||||
Nodes1 = case acl:match_rule(LServer, Access1, From) of
|
Nodes1 = case acl:match_rule(LServer, Access1, From) of
|
||||||
allow ->
|
allow ->
|
||||||
[?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN ++ "#announce"),
|
[?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_s ++ "#announce"),
|
||||||
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN ++ "#announce-all"),
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_s ++ "#announce-all"),
|
||||||
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN ++ "#set-motd"),
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_s ++ "#set-motd"),
|
||||||
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN ++ "#edit-motd"),
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_s ++ "#edit-motd"),
|
||||||
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN ++ "#delete-motd")];
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_s ++ "#delete-motd")];
|
||||||
deny ->
|
deny ->
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
Access2 = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
Access2 = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
||||||
Nodes2 = case acl:match_rule(global, Access2, From) of
|
Nodes2 = case acl:match_rule(global, Access2, From) of
|
||||||
allow ->
|
allow ->
|
||||||
[?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN ++ "#announce-allhosts"),
|
[?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_s ++ "#announce-allhosts"),
|
||||||
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN ++ "#announce-all-allhosts"),
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_s ++ "#announce-all-allhosts"),
|
||||||
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN ++ "#set-motd-allhosts"),
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_s ++ "#set-motd-allhosts"),
|
||||||
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN ++ "#edit-motd-allhosts"),
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_s ++ "#edit-motd-allhosts"),
|
||||||
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN ++ "#delete-motd-allhosts")];
|
?NODE_TO_ITEM(Lang, Server, ?NS_ADMIN_s ++ "#delete-motd-allhosts")];
|
||||||
deny ->
|
deny ->
|
||||||
[]
|
[]
|
||||||
end,
|
end,
|
||||||
@ -391,13 +393,13 @@ announce_items(Acc, From, #jid{lserver = LServer, server = Server} = _To, Lang)
|
|||||||
commands_result(Allow, From, To, Request) ->
|
commands_result(Allow, From, To, Request) ->
|
||||||
case Allow of
|
case Allow of
|
||||||
deny ->
|
deny ->
|
||||||
{error, ?ERR_FORBIDDEN};
|
{error, 'forbidden'};
|
||||||
allow ->
|
allow ->
|
||||||
announce_commands(From, To, Request)
|
announce_commands(From, To, Request)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
|
||||||
announce_commands(Acc, From, #jid{lserver = LServer} = To,
|
announce_commands(Acc, From, #jid{ldomain = LServer} = To,
|
||||||
#adhoc_request{ node = Node} = Request) ->
|
#adhoc_request{ node = Node} = Request) ->
|
||||||
LNode = tokenize(Node),
|
LNode = tokenize(Node),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
@ -453,7 +455,7 @@ announce_commands(From, To,
|
|||||||
#adhoc_response{status = canceled});
|
#adhoc_response{status = canceled});
|
||||||
XData == false, ActionIsExecute ->
|
XData == false, ActionIsExecute ->
|
||||||
%% User requests form
|
%% User requests form
|
||||||
Elements = generate_adhoc_form(Lang, Node, To#jid.lserver),
|
Elements = generate_adhoc_form(Lang, Node, To#jid.ldomain),
|
||||||
adhoc:produce_response(
|
adhoc:produce_response(
|
||||||
Request,
|
Request,
|
||||||
#adhoc_response{status = executing,
|
#adhoc_response{status = executing,
|
||||||
@ -462,26 +464,26 @@ announce_commands(From, To,
|
|||||||
%% User returns form.
|
%% User returns form.
|
||||||
case jlib:parse_xdata_submit(XData) of
|
case jlib:parse_xdata_submit(XData) of
|
||||||
invalid ->
|
invalid ->
|
||||||
{error, ?ERR_BAD_REQUEST};
|
{error, 'bad-request'};
|
||||||
Fields ->
|
Fields ->
|
||||||
handle_adhoc_form(From, To, Request, Fields)
|
handle_adhoc_form(From, To, Request, Fields)
|
||||||
end;
|
end;
|
||||||
true ->
|
true ->
|
||||||
{error, ?ERR_BAD_REQUEST}
|
{error, 'bad-request'}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-define(VVALUE(Val),
|
-define(VVALUE(Val),
|
||||||
{xmlelement, "value", [], [{xmlcdata, Val}]}).
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children = [#xmlcdata{cdata = list_to_binary(Val)}]}).
|
||||||
-define(VVALUEL(Val),
|
-define(VVALUEL(Val),
|
||||||
case Val of
|
case Val of
|
||||||
"" -> [];
|
"" -> [];
|
||||||
_ -> [?VVALUE(Val)]
|
_ -> [?VVALUE(Val)]
|
||||||
end).
|
end).
|
||||||
-define(TVFIELD(Type, Var, Val),
|
-define(TVFIELD(Type, Var, Val),
|
||||||
{xmlelement, "field", [{"type", Type},
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs = [#xmlattr{name = 'type', value = Type},
|
||||||
{"var", Var}],
|
#xmlattr{name = 'var', value = Var}], children =
|
||||||
?VVALUEL(Val)}).
|
?VVALUEL(Val)}).
|
||||||
-define(HFIELD(), ?TVFIELD("hidden", "FORM_TYPE", ?NS_ADMIN)).
|
-define(HFIELD(), ?TVFIELD("hidden", "FORM_TYPE", ?NS_ADMIN_s)).
|
||||||
|
|
||||||
generate_adhoc_form(Lang, Node, ServerHost) ->
|
generate_adhoc_form(Lang, Node, ServerHost) ->
|
||||||
LNode = tokenize(Node),
|
LNode = tokenize(Node),
|
||||||
@ -491,31 +493,29 @@ generate_adhoc_form(Lang, Node, ServerHost) ->
|
|||||||
true ->
|
true ->
|
||||||
{[], []}
|
{[], []}
|
||||||
end,
|
end,
|
||||||
{xmlelement, "x",
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'x', attrs =
|
||||||
[{"xmlns", ?NS_XDATA},
|
[#xmlattr{name = 'type', value = "form"}], children =
|
||||||
{"type", "form"}],
|
|
||||||
[?HFIELD(),
|
[?HFIELD(),
|
||||||
{xmlelement, "title", [], [{xmlcdata, get_title(Lang, Node)}]}]
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'title', children = [#xmlcdata{cdata = list_to_binary(get_title(Lang, Node))}]}]
|
||||||
++
|
++
|
||||||
if (LNode == ?NS_ADMINL("delete-motd"))
|
if (LNode == ?NS_ADMINL("delete-motd"))
|
||||||
or (LNode == ?NS_ADMINL("delete-motd-allhosts")) ->
|
or (LNode == ?NS_ADMINL("delete-motd-allhosts")) ->
|
||||||
[{xmlelement, "field",
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
||||||
[{"var", "confirm"},
|
[#xmlattr{name = 'var', value = "confirm"},
|
||||||
{"type", "boolean"},
|
#xmlattr{name = 'type', value = "boolean"},
|
||||||
{"label", translate:translate(Lang, "Really delete message of the day?")}],
|
#xmlattr{name = 'label', value = translate:translate(Lang, "Really delete message of the day?")}], children =
|
||||||
[{xmlelement, "value",
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'value', children =
|
||||||
[],
|
[#xmlcdata{cdata = <<"true">>}]}]}];
|
||||||
[{xmlcdata, "true"}]}]}];
|
|
||||||
true ->
|
true ->
|
||||||
[{xmlelement, "field",
|
[#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
||||||
[{"var", "subject"},
|
[#xmlattr{name = 'var', value = "subject"},
|
||||||
{"type", "text-single"},
|
#xmlattr{name = 'type', value = "text-single"},
|
||||||
{"label", translate:translate(Lang, "Subject")}],
|
#xmlattr{name = 'label', value = translate:translate(Lang, "Subject")}], children =
|
||||||
?VVALUEL(OldSubject)},
|
?VVALUEL(OldSubject)},
|
||||||
{xmlelement, "field",
|
#xmlel{ns = ?NS_DATA_FORMS, name = 'field', attrs =
|
||||||
[{"var", "body"},
|
[#xmlattr{name = 'var', value = "body"},
|
||||||
{"type", "text-multi"},
|
#xmlattr{name = 'type', value = "text-multi"},
|
||||||
{"label", translate:translate(Lang, "Message body")}],
|
#xmlattr{name = 'label', value = translate:translate(Lang, "Message body")}], children =
|
||||||
?VVALUEL(OldBody)}]
|
?VVALUEL(OldBody)}]
|
||||||
end}.
|
end}.
|
||||||
|
|
||||||
@ -529,7 +529,7 @@ join_lines([], Acc) ->
|
|||||||
%% Remove last newline
|
%% Remove last newline
|
||||||
lists:flatten(lists:reverse(tl(Acc))).
|
lists:flatten(lists:reverse(tl(Acc))).
|
||||||
|
|
||||||
handle_adhoc_form(From, #jid{lserver = LServer} = To,
|
handle_adhoc_form(From, #jid{ldomain = LServer} = To,
|
||||||
#adhoc_request{lang = Lang,
|
#adhoc_request{lang = Lang,
|
||||||
node = Node,
|
node = Node,
|
||||||
sessionid = SessionID},
|
sessionid = SessionID},
|
||||||
@ -560,30 +560,30 @@ handle_adhoc_form(From, #jid{lserver = LServer} = To,
|
|||||||
node = Node,
|
node = Node,
|
||||||
sessionid = SessionID,
|
sessionid = SessionID,
|
||||||
status = completed},
|
status = completed},
|
||||||
Packet = {xmlelement, "message", [{"type", "normal"}],
|
Packet = #xmlel{ns = ?NS_JABBER_CLIENT, name = 'message', attrs = [#xmlattr{name = 'type', value = "normal"}], children =
|
||||||
if Subject /= [] ->
|
if Subject /= [] ->
|
||||||
[{xmlelement, "subject", [],
|
[#xmlel{ns = ?NS_JABBER_CLIENT, name = 'subject', children =
|
||||||
[{xmlcdata, Subject}]}];
|
[#xmlcdata{cdata = list_to_binary(Subject)}]}];
|
||||||
true ->
|
true ->
|
||||||
[]
|
[]
|
||||||
end ++
|
end ++
|
||||||
if Body /= [] ->
|
if Body /= [] ->
|
||||||
[{xmlelement, "body", [],
|
[#xmlel{ns = ?NS_JABBER_CLIENT, name = 'body', children =
|
||||||
[{xmlcdata, Body}]}];
|
[#xmlcdata{cdata = list_to_binary(Body)}]}];
|
||||||
true ->
|
true ->
|
||||||
[]
|
[]
|
||||||
end},
|
end},
|
||||||
|
|
||||||
Proc = gen_mod:get_module_proc(LServer, ?PROCNAME),
|
Proc = gen_mod:get_module_proc(LServer, ?PROCNAME),
|
||||||
case {Node, Body} of
|
case {Node, Body} of
|
||||||
{?NS_ADMIN ++ "#delete-motd", _} ->
|
{?NS_ADMIN_s ++ "#delete-motd", _} ->
|
||||||
if Confirm ->
|
if Confirm ->
|
||||||
Proc ! {announce_motd_delete, From, To, Packet},
|
Proc ! {announce_motd_delete, From, To, Packet},
|
||||||
adhoc:produce_response(Response);
|
adhoc:produce_response(Response);
|
||||||
true ->
|
true ->
|
||||||
adhoc:produce_response(Response)
|
adhoc:produce_response(Response)
|
||||||
end;
|
end;
|
||||||
{?NS_ADMIN ++ "#delete-motd-allhosts", _} ->
|
{?NS_ADMIN_s ++ "#delete-motd-allhosts", _} ->
|
||||||
if Confirm ->
|
if Confirm ->
|
||||||
Proc ! {announce_all_hosts_motd_delete, From, To, Packet},
|
Proc ! {announce_all_hosts_motd_delete, From, To, Packet},
|
||||||
adhoc:produce_response(Response);
|
adhoc:produce_response(Response);
|
||||||
@ -593,79 +593,78 @@ handle_adhoc_form(From, #jid{lserver = LServer} = To,
|
|||||||
{_, []} ->
|
{_, []} ->
|
||||||
%% An announce message with no body is definitely an operator error.
|
%% An announce message with no body is definitely an operator error.
|
||||||
%% Throw an error and give him/her a chance to send message again.
|
%% Throw an error and give him/her a chance to send message again.
|
||||||
{error, ?ERRT_NOT_ACCEPTABLE(
|
{error, exmpp_stanza:error(?NS_JABBER_CLIENT, 'not-acceptable',
|
||||||
Lang,
|
{"en", "No body provided for announce message"})};
|
||||||
"No body provided for announce message")};
|
|
||||||
%% Now send the packet to ?PROCNAME.
|
%% Now send the packet to ?PROCNAME.
|
||||||
%% We don't use direct announce_* functions because it
|
%% We don't use direct announce_* functions because it
|
||||||
%% leads to large delay in response and <iq/> queries processing
|
%% leads to large delay in response and <iq/> queries processing
|
||||||
{?NS_ADMIN ++ "#announce", _} ->
|
{?NS_ADMIN_s ++ "#announce", _} ->
|
||||||
Proc ! {announce_online, From, To, Packet},
|
Proc ! {announce_online, From, To, Packet},
|
||||||
adhoc:produce_response(Response);
|
adhoc:produce_response(Response);
|
||||||
{?NS_ADMIN ++ "#announce-allhosts", _} ->
|
{?NS_ADMIN_s ++ "#announce-allhosts", _} ->
|
||||||
Proc ! {announce_all_hosts_online, From, To, Packet},
|
Proc ! {announce_all_hosts_online, From, To, Packet},
|
||||||
adhoc:produce_response(Response);
|
adhoc:produce_response(Response);
|
||||||
{?NS_ADMIN ++ "#announce-all", _} ->
|
{?NS_ADMIN_s ++ "#announce-all", _} ->
|
||||||
Proc ! {announce_all, From, To, Packet},
|
Proc ! {announce_all, From, To, Packet},
|
||||||
adhoc:produce_response(Response);
|
adhoc:produce_response(Response);
|
||||||
{?NS_ADMIN ++ "#announce-all-allhosts", _} ->
|
{?NS_ADMIN_s ++ "#announce-all-allhosts", _} ->
|
||||||
Proc ! {announce_all_hosts_all, From, To, Packet},
|
Proc ! {announce_all_hosts_all, From, To, Packet},
|
||||||
adhoc:produce_response(Response);
|
adhoc:produce_response(Response);
|
||||||
{?NS_ADMIN ++ "#set-motd", _} ->
|
{?NS_ADMIN_s ++ "#set-motd", _} ->
|
||||||
Proc ! {announce_motd, From, To, Packet},
|
Proc ! {announce_motd, From, To, Packet},
|
||||||
adhoc:produce_response(Response);
|
adhoc:produce_response(Response);
|
||||||
{?NS_ADMIN ++ "#set-motd-allhosts", _} ->
|
{?NS_ADMIN_s ++ "#set-motd-allhosts", _} ->
|
||||||
Proc ! {announce_all_hosts_motd, From, To, Packet},
|
Proc ! {announce_all_hosts_motd, From, To, Packet},
|
||||||
adhoc:produce_response(Response);
|
adhoc:produce_response(Response);
|
||||||
{?NS_ADMIN ++ "#edit-motd", _} ->
|
{?NS_ADMIN_s ++ "#edit-motd", _} ->
|
||||||
Proc ! {announce_motd_update, From, To, Packet},
|
Proc ! {announce_motd_update, From, To, Packet},
|
||||||
adhoc:produce_response(Response);
|
adhoc:produce_response(Response);
|
||||||
{?NS_ADMIN ++ "#edit-motd-allhosts", _} ->
|
{?NS_ADMIN_s ++ "#edit-motd-allhosts", _} ->
|
||||||
Proc ! {announce_all_hosts_motd_update, From, To, Packet},
|
Proc ! {announce_all_hosts_motd_update, From, To, Packet},
|
||||||
adhoc:produce_response(Response);
|
adhoc:produce_response(Response);
|
||||||
_ ->
|
_ ->
|
||||||
%% This can't happen, as we haven't registered any other
|
%% This can't happen, as we haven't registered any other
|
||||||
%% command nodes.
|
%% command nodes.
|
||||||
{error, ?ERR_INTERNAL_SERVER_ERROR}
|
{error, 'internal-server-error'}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
get_title(Lang, "announce") ->
|
get_title(Lang, "announce") ->
|
||||||
translate:translate(Lang, "Announcements");
|
translate:translate(Lang, "Announcements");
|
||||||
get_title(Lang, ?NS_ADMIN ++ "#announce-all") ->
|
get_title(Lang, ?NS_ADMIN_s ++ "#announce-all") ->
|
||||||
translate:translate(Lang, "Send announcement to all users");
|
translate:translate(Lang, "Send announcement to all users");
|
||||||
get_title(Lang, ?NS_ADMIN ++ "#announce-all-allhosts") ->
|
get_title(Lang, ?NS_ADMIN_s ++ "#announce-all-allhosts") ->
|
||||||
translate:translate(Lang, "Send announcement to all users on all hosts");
|
translate:translate(Lang, "Send announcement to all users on all hosts");
|
||||||
get_title(Lang, ?NS_ADMIN ++ "#announce") ->
|
get_title(Lang, ?NS_ADMIN_s ++ "#announce") ->
|
||||||
translate:translate(Lang, "Send announcement to all online users");
|
translate:translate(Lang, "Send announcement to all online users");
|
||||||
get_title(Lang, ?NS_ADMIN ++ "#announce-allhosts") ->
|
get_title(Lang, ?NS_ADMIN_s ++ "#announce-allhosts") ->
|
||||||
translate:translate(Lang, "Send announcement to all online users on all hosts");
|
translate:translate(Lang, "Send announcement to all online users on all hosts");
|
||||||
get_title(Lang, ?NS_ADMIN ++ "#set-motd") ->
|
get_title(Lang, ?NS_ADMIN_s ++ "#set-motd") ->
|
||||||
translate:translate(Lang, "Set message of the day and send to online users");
|
translate:translate(Lang, "Set message of the day and send to online users");
|
||||||
get_title(Lang, ?NS_ADMIN ++ "#set-motd-allhosts") ->
|
get_title(Lang, ?NS_ADMIN_s ++ "#set-motd-allhosts") ->
|
||||||
translate:translate(Lang, "Set message of the day on all hosts and send to online users");
|
translate:translate(Lang, "Set message of the day on all hosts and send to online users");
|
||||||
get_title(Lang, ?NS_ADMIN ++ "#edit-motd") ->
|
get_title(Lang, ?NS_ADMIN_s ++ "#edit-motd") ->
|
||||||
translate:translate(Lang, "Update message of the day (don't send)");
|
translate:translate(Lang, "Update message of the day (don't send)");
|
||||||
get_title(Lang, ?NS_ADMIN ++ "#edit-motd-allhosts") ->
|
get_title(Lang, ?NS_ADMIN_s ++ "#edit-motd-allhosts") ->
|
||||||
translate:translate(Lang, "Update message of the day on all hosts (don't send)");
|
translate:translate(Lang, "Update message of the day on all hosts (don't send)");
|
||||||
get_title(Lang, ?NS_ADMIN ++ "#delete-motd") ->
|
get_title(Lang, ?NS_ADMIN_s ++ "#delete-motd") ->
|
||||||
translate:translate(Lang, "Delete message of the day");
|
translate:translate(Lang, "Delete message of the day");
|
||||||
get_title(Lang, ?NS_ADMIN ++ "#delete-motd-allhosts") ->
|
get_title(Lang, ?NS_ADMIN_s ++ "#delete-motd-allhosts") ->
|
||||||
translate:translate(Lang, "Delete message of the day on all hosts").
|
translate:translate(Lang, "Delete message of the day on all hosts").
|
||||||
|
|
||||||
%%-------------------------------------------------------------------------
|
%%-------------------------------------------------------------------------
|
||||||
|
|
||||||
announce_all(From, To, Packet) ->
|
announce_all(From, To, Packet) ->
|
||||||
Host = To#jid.lserver,
|
Host = To#jid.ldomain,
|
||||||
Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
|
Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
|
||||||
case acl:match_rule(Host, Access, From) of
|
case acl:match_rule(Host, Access, From) of
|
||||||
deny ->
|
deny ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
|
Err = exmpp_stanza:reply_with_error(Packet, 'forbidden'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
allow ->
|
allow ->
|
||||||
Local = jlib:make_jid("", To#jid.server, ""),
|
Local = exmpp_jid:make_jid(To#jid.domain),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({User, Server}) ->
|
fun({User, Server}) ->
|
||||||
Dest = jlib:make_jid(User, Server, ""),
|
Dest = exmpp_jid:make_jid(User, Server),
|
||||||
ejabberd_router:route(Local, Dest, Packet)
|
ejabberd_router:route(Local, Dest, Packet)
|
||||||
end, ejabberd_auth:get_vh_registered_users(Host))
|
end, ejabberd_auth:get_vh_registered_users(Host))
|
||||||
end.
|
end.
|
||||||
@ -674,27 +673,27 @@ announce_all_hosts_all(From, To, Packet) ->
|
|||||||
Access = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
Access = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
||||||
case acl:match_rule(global, Access, From) of
|
case acl:match_rule(global, Access, From) of
|
||||||
deny ->
|
deny ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
|
Err = exmpp_stanza:reply_with_error(Packet, 'forbidden'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
allow ->
|
allow ->
|
||||||
Local = jlib:make_jid("", To#jid.server, ""),
|
Local = exmpp_jid:make_jid(To#jid.domain),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({User, Server}) ->
|
fun({User, Server}) ->
|
||||||
Dest = jlib:make_jid(User, Server, ""),
|
Dest = exmpp_jid:make_jid(User, Server),
|
||||||
ejabberd_router:route(Local, Dest, Packet)
|
ejabberd_router:route(Local, Dest, Packet)
|
||||||
end, ejabberd_auth:dirty_get_registered_users())
|
end, ejabberd_auth:dirty_get_registered_users())
|
||||||
end.
|
end.
|
||||||
|
|
||||||
announce_online(From, To, Packet) ->
|
announce_online(From, To, Packet) ->
|
||||||
Host = To#jid.lserver,
|
Host = To#jid.ldomain,
|
||||||
Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
|
Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
|
||||||
case acl:match_rule(Host, Access, From) of
|
case acl:match_rule(Host, Access, From) of
|
||||||
deny ->
|
deny ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
|
Err = exmpp_stanza:reply_with_error(Packet, 'forbidden'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
allow ->
|
allow ->
|
||||||
announce_online1(ejabberd_sm:get_vh_session_list(Host),
|
announce_online1(ejabberd_sm:get_vh_session_list(Host),
|
||||||
To#jid.server,
|
To#jid.domain,
|
||||||
Packet)
|
Packet)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
@ -702,28 +701,28 @@ announce_all_hosts_online(From, To, Packet) ->
|
|||||||
Access = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
Access = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
||||||
case acl:match_rule(global, Access, From) of
|
case acl:match_rule(global, Access, From) of
|
||||||
deny ->
|
deny ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
|
Err = exmpp_stanza:reply_with_error(Packet, 'forbidden'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
allow ->
|
allow ->
|
||||||
announce_online1(ejabberd_sm:dirty_get_sessions_list(),
|
announce_online1(ejabberd_sm:dirty_get_sessions_list(),
|
||||||
To#jid.server,
|
To#jid.domain,
|
||||||
Packet)
|
Packet)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
announce_online1(Sessions, Server, Packet) ->
|
announce_online1(Sessions, Server, Packet) ->
|
||||||
Local = jlib:make_jid("", Server, ""),
|
Local = exmpp_jid:make_jid(Server),
|
||||||
lists:foreach(
|
lists:foreach(
|
||||||
fun({U, S, R}) ->
|
fun({U, S, R}) ->
|
||||||
Dest = jlib:make_jid(U, S, R),
|
Dest = exmpp_jid:make_jid(U, S, R),
|
||||||
ejabberd_router:route(Local, Dest, Packet)
|
ejabberd_router:route(Local, Dest, Packet)
|
||||||
end, Sessions).
|
end, Sessions).
|
||||||
|
|
||||||
announce_motd(From, To, Packet) ->
|
announce_motd(From, To, Packet) ->
|
||||||
Host = To#jid.lserver,
|
Host = To#jid.ldomain,
|
||||||
Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
|
Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
|
||||||
case acl:match_rule(Host, Access, From) of
|
case acl:match_rule(Host, Access, From) of
|
||||||
deny ->
|
deny ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
|
Err = exmpp_stanza:reply_with_error(Packet, 'forbidden'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
allow ->
|
allow ->
|
||||||
announce_motd(Host, Packet)
|
announce_motd(Host, Packet)
|
||||||
@ -733,7 +732,7 @@ announce_all_hosts_motd(From, To, Packet) ->
|
|||||||
Access = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
Access = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
||||||
case acl:match_rule(global, Access, From) of
|
case acl:match_rule(global, Access, From) of
|
||||||
deny ->
|
deny ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
|
Err = exmpp_stanza:reply_with_error(Packet, 'forbidden'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
allow ->
|
allow ->
|
||||||
Hosts = ?MYHOSTS,
|
Hosts = ?MYHOSTS,
|
||||||
@ -753,11 +752,11 @@ announce_motd(Host, Packet) ->
|
|||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
|
|
||||||
announce_motd_update(From, To, Packet) ->
|
announce_motd_update(From, To, Packet) ->
|
||||||
Host = To#jid.lserver,
|
Host = To#jid.ldomain,
|
||||||
Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
|
Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
|
||||||
case acl:match_rule(Host, Access, From) of
|
case acl:match_rule(Host, Access, From) of
|
||||||
deny ->
|
deny ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
|
Err = exmpp_stanza:reply_with_error(Packet, 'forbidden'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
allow ->
|
allow ->
|
||||||
announce_motd_update(Host, Packet)
|
announce_motd_update(Host, Packet)
|
||||||
@ -767,7 +766,7 @@ announce_all_hosts_motd_update(From, To, Packet) ->
|
|||||||
Access = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
Access = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
||||||
case acl:match_rule(global, Access, From) of
|
case acl:match_rule(global, Access, From) of
|
||||||
deny ->
|
deny ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
|
Err = exmpp_stanza:reply_with_error(Packet, 'forbidden'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
allow ->
|
allow ->
|
||||||
Hosts = ?MYHOSTS,
|
Hosts = ?MYHOSTS,
|
||||||
@ -782,11 +781,11 @@ announce_motd_update(LServer, Packet) ->
|
|||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
|
|
||||||
announce_motd_delete(From, To, Packet) ->
|
announce_motd_delete(From, To, Packet) ->
|
||||||
Host = To#jid.lserver,
|
Host = To#jid.ldomain,
|
||||||
Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
|
Access = gen_mod:get_module_opt(Host, ?MODULE, access, none),
|
||||||
case acl:match_rule(Host, Access, From) of
|
case acl:match_rule(Host, Access, From) of
|
||||||
deny ->
|
deny ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
|
Err = exmpp_stanza:reply_with_error(Packet, 'forbidden'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
allow ->
|
allow ->
|
||||||
announce_motd_delete(Host)
|
announce_motd_delete(Host)
|
||||||
@ -796,7 +795,7 @@ announce_all_hosts_motd_delete(From, To, Packet) ->
|
|||||||
Access = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
Access = gen_mod:get_module_opt(global, ?MODULE, access, none),
|
||||||
case acl:match_rule(global, Access, From) of
|
case acl:match_rule(global, Access, From) of
|
||||||
deny ->
|
deny ->
|
||||||
Err = jlib:make_error_reply(Packet, ?ERR_FORBIDDEN),
|
Err = exmpp_stanza:reply_with_error(Packet, 'forbidden'),
|
||||||
ejabberd_router:route(To, From, Err);
|
ejabberd_router:route(To, From, Err);
|
||||||
allow ->
|
allow ->
|
||||||
Hosts = ?MYHOSTS,
|
Hosts = ?MYHOSTS,
|
||||||
@ -818,7 +817,7 @@ announce_motd_delete(LServer) ->
|
|||||||
end,
|
end,
|
||||||
mnesia:transaction(F).
|
mnesia:transaction(F).
|
||||||
|
|
||||||
send_motd(#jid{luser = LUser, lserver = LServer} = JID) ->
|
send_motd(#jid{lnode = LUser, ldomain = LServer} = JID) ->
|
||||||
case catch mnesia:dirty_read({motd, LServer}) of
|
case catch mnesia:dirty_read({motd, LServer}) of
|
||||||
[#motd{packet = Packet}] ->
|
[#motd{packet = Packet}] ->
|
||||||
US = {LUser, LServer},
|
US = {LUser, LServer},
|
||||||
@ -826,7 +825,7 @@ send_motd(#jid{luser = LUser, lserver = LServer} = JID) ->
|
|||||||
[#motd_users{}] ->
|
[#motd_users{}] ->
|
||||||
ok;
|
ok;
|
||||||
_ ->
|
_ ->
|
||||||
Local = jlib:make_jid("", LServer, ""),
|
Local = exmpp_jid:make_jid(LServer),
|
||||||
ejabberd_router:route(Local, JID, Packet),
|
ejabberd_router:route(Local, JID, Packet),
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
mnesia:write(#motd_users{us = US})
|
mnesia:write(#motd_users{us = US})
|
||||||
@ -840,8 +839,8 @@ send_motd(#jid{luser = LUser, lserver = LServer} = JID) ->
|
|||||||
get_stored_motd(LServer) ->
|
get_stored_motd(LServer) ->
|
||||||
case catch mnesia:dirty_read({motd, LServer}) of
|
case catch mnesia:dirty_read({motd, LServer}) of
|
||||||
[#motd{packet = Packet}] ->
|
[#motd{packet = Packet}] ->
|
||||||
{xml:get_subtag_cdata(Packet, "subject"),
|
{exmpp_xml:get_cdata_as_list(exmpp_xml:get_element_by_name(Packet, 'subject')),
|
||||||
xml:get_subtag_cdata(Packet, "body")};
|
exmpp_xml:get_cdata_as_list(exmpp_xml:get_element_by_name(Packet, 'body'))};
|
||||||
_ ->
|
_ ->
|
||||||
{"", ""}
|
{"", ""}
|
||||||
end.
|
end.
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user