25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-28 16:34:13 +01:00

* src/ejabberd_local.erl: Added support for announce/online

messages

* src/ejabberd.cfg.example: Updated

* src/mod_register.erl: Added support for sending registration
notifications

SVN Revision: 154
This commit is contained in:
Alexey Shchepin 2003-10-19 16:19:55 +00:00
parent a704f9760d
commit f594dd0746
5 changed files with 79 additions and 19 deletions

View File

@ -1,3 +1,13 @@
2003-10-19 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_local.erl: Added support for announce/online
messages
* src/ejabberd.cfg.example: Updated
* src/mod_register.erl: Added support for sending registration
notifications
2003-10-18 Alexey Shchepin <alexey@sevcom.net> 2003-10-18 Alexey Shchepin <alexey@sevcom.net>
* src/ejabberd_service.erl: Added supports for multiple hosts per * src/ejabberd_service.erl: Added supports for multiple hosts per

View File

@ -452,7 +452,7 @@ except admins have traffic limit 1000\,b/s.
{ssl, [{certfile, "/path/to/ssl.pem"}]}]}, {ssl, [{certfile, "/path/to/ssl.pem"}]}]},
{5269, ejabberd_s2s_in, []}, {5269, ejabberd_s2s_in, []},
{8888, ejabberd_service, {8888, ejabberd_service,
[{host, "conference.example.org", [{password, "secret"}]}]} [{hosts, ["conference.example.org"], [{password, "secret"}]}]}
]}. ]}.
\end{verbatim} \end{verbatim}

View File

@ -33,6 +33,13 @@
% Replace them with 'none' if you don't want to send such message: % Replace them with 'none' if you don't want to send such message:
%{welcome_message, none}. %{welcome_message, none}.
% List of people who will get notifications about registered users
%{registration_watchers, ["admin1@localhost",
% "admin2@localhost"]}.
% Only admins can send announcement messages:
{access, announce, [{allow, admin}]}.
% Only non-blocked users can use c2s connections: % Only non-blocked users can use c2s connections:
{access, c2s, [{deny, blocked}, {access, c2s, [{deny, blocked},
@ -58,12 +65,13 @@
{5223, ejabberd_c2s, [{access, c2s}, {5223, ejabberd_c2s, [{access, c2s},
{ssl, [{certfile, "./ssl.pem"}]}]}, {ssl, [{certfile, "./ssl.pem"}]}]},
{5269, ejabberd_s2s_in, []}, {5269, ejabberd_s2s_in, []},
{8888, ejabberd_service, [{host, {8888, ejabberd_service, [{hosts,
"conference.e.localhost", ["conference.e.localhost",
[{password, "asdqwe"}]}]} "muc.e.localhost"],
[{password, "secret"}]}]}
]}. ]}.
% If SRV lookup fails, then port 5269 used to communicate with other servers % If SRV lookup fails, then port 5269 is used to communicate with remote server
{outgoing_s2s_port, 5269}. {outgoing_s2s_port, 5269}.

View File

@ -72,7 +72,7 @@ do_route(State, From, To, Packet) ->
[From, To, Packet, 8]), [From, To, Packet, 8]),
case To of case To of
#jid{luser = "", lresource = ""} -> #jid{luser = "", lresource = ""} ->
{xmlelement, Name, Attrs, Els} = Packet, {xmlelement, Name, Attrs, _Els} = Packet,
case Name of case Name of
"iq" -> "iq" ->
process_iq(State, From, To, Packet); process_iq(State, From, To, Packet);
@ -83,15 +83,20 @@ do_route(State, From, To, Packet) ->
_ -> _ ->
ok ok
end; end;
#jid{luser = ""} -> #jid{luser = "", lresource = Res} ->
{xmlelement, _Name, Attrs, _Els} = Packet, {xmlelement, Name, Attrs, _Els} = Packet,
case xml:get_attr_s("type", Attrs) of case xml:get_attr_s("type", Attrs) of
"error" -> ok; "error" -> ok;
"result" -> ok; "result" -> ok;
_ -> _ ->
Err = jlib:make_error_reply(Packet, ?ERR_ITEM_NOT_FOUND), case {Res, Name} of
ejabberd_router:route( {"announce/online", "message"} ->
jlib:make_jid("", State#state.mydomain, ""), From, Err) announce_online(From, To, Packet);
_ ->
Err = jlib:make_error_reply(
Packet, ?ERR_ITEM_NOT_FOUND),
ejabberd_router:route(To, From, Err)
end
end; end;
_ -> _ ->
ejabberd_sm ! {route, From, To, Packet} ejabberd_sm ! {route, From, To, Packet}
@ -100,7 +105,7 @@ do_route(State, From, To, Packet) ->
process_iq(State, From, To, Packet) -> process_iq(State, From, To, Packet) ->
IQ = jlib:iq_query_info(Packet), IQ = jlib:iq_query_info(Packet),
case IQ of case IQ of
{iq, ID, Type, XMLNS, SubEl} -> {iq, _ID, Type, XMLNS, _SubEl} ->
case jlib:is_iq_request_type(Type) of case jlib:is_iq_request_type(Type) of
true -> true ->
case ets:lookup(State#state.iqtable, XMLNS) of case ets:lookup(State#state.iqtable, XMLNS) of
@ -121,10 +126,7 @@ process_iq(State, From, To, Packet) ->
[] -> [] ->
Err = jlib:make_error_reply( Err = jlib:make_error_reply(
Packet, ?ERR_FEATURE_NOT_IMPLEMENTED), Packet, ?ERR_FEATURE_NOT_IMPLEMENTED),
ejabberd_router ! {route, ejabberd_router:route(To, From, Err)
{"", State#state.mydomain, ""},
From,
Err}
end; end;
_ -> _ ->
ok ok
@ -133,8 +135,7 @@ process_iq(State, From, To, Packet) ->
ok; ok;
_ -> _ ->
Err = jlib:make_error_reply(Packet, ?ERR_BAD_REQUEST), Err = jlib:make_error_reply(Packet, ?ERR_BAD_REQUEST),
ejabberd_router ! {route, ejabberd_router:route(To, From, Err),
{"", State#state.mydomain, ""}, From, Err},
ok ok
end. end.
@ -147,3 +148,18 @@ register_iq_handler(XMLNS, Module, Fun, Opts) ->
unregister_iq_handler(XMLNS) -> unregister_iq_handler(XMLNS) ->
ejabberd_local ! {unregister_iq_handler, XMLNS}. ejabberd_local ! {unregister_iq_handler, XMLNS}.
announce_online(From, To, Packet) ->
case acl:match_rule(announce, From) of
deny ->
Err = jlib:make_error_reply(Packet, ?ERR_NOT_ALLOWED),
ejabberd_router:route(To, From, Err);
allow ->
Local = jlib:make_jid("", ?MYNAME, ""),
lists:foreach(
fun({U, R}) ->
Dest = jlib:make_jid(U, ?MYNAME, R),
ejabberd_router:route(Local, Dest, Packet)
end, ejabberd_sm:dirty_get_sessions_list())
end.

View File

@ -28,7 +28,7 @@ start(Opts) ->
init() -> init() ->
ok. ok.
process_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) -> process_iq(From, _To, {iq, ID, Type, XMLNS, SubEl}) ->
case Type of case Type of
set -> set ->
UTag = xml:get_subtag(SubEl, "username"), UTag = xml:get_subtag(SubEl, "username"),
@ -124,6 +124,7 @@ try_register(User, Password) ->
case ejabberd_auth:try_register(User, Password) of case ejabberd_auth:try_register(User, Password) of
{atomic, ok} -> {atomic, ok} ->
send_welcome_message(JID), send_welcome_message(JID),
send_registration_notifications(JID),
ok; ok;
{atomic, exists} -> {atomic, exists} ->
{error, ?ERR_CONFLICT}; {error, ?ERR_CONFLICT};
@ -149,3 +150,28 @@ send_welcome_message(JID) ->
ok ok
end. end.
send_registration_notifications(UJID) ->
case ejabberd_config:get_local_option(registration_watchers) of
[] -> ok;
JIDs when is_list(JIDs) ->
Body = lists:flatten(
io_lib:format(
"The user '~s' was just created on node ~w.",
[jlib:jid_to_string(UJID), node()])),
lists:foreach(
fun(S) ->
case jlib:string_to_jid(S) of
error -> ok;
JID ->
ejabberd_router:route(
jlib:make_jid("", ?MYNAME, ""),
JID,
{xmlelement, "message", [{"type", "chat"}],
[{xmlelement, "body", [],
[{xmlcdata, Body}]}]})
end
end, JIDs);
_ ->
ok
end.