25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-10-03 14:45:16 +02: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>
* 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"}]}]},
{5269, ejabberd_s2s_in, []},
{8888, ejabberd_service,
[{host, "conference.example.org", [{password, "secret"}]}]}
[{hosts, ["conference.example.org"], [{password, "secret"}]}]}
]}.
\end{verbatim}

View File

@ -33,6 +33,13 @@
% Replace them with 'none' if you don't want to send such message:
%{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:
{access, c2s, [{deny, blocked},
@ -58,12 +65,13 @@
{5223, ejabberd_c2s, [{access, c2s},
{ssl, [{certfile, "./ssl.pem"}]}]},
{5269, ejabberd_s2s_in, []},
{8888, ejabberd_service, [{host,
"conference.e.localhost",
[{password, "asdqwe"}]}]}
{8888, ejabberd_service, [{hosts,
["conference.e.localhost",
"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}.

View File

@ -72,7 +72,7 @@ do_route(State, From, To, Packet) ->
[From, To, Packet, 8]),
case To of
#jid{luser = "", lresource = ""} ->
{xmlelement, Name, Attrs, Els} = Packet,
{xmlelement, Name, Attrs, _Els} = Packet,
case Name of
"iq" ->
process_iq(State, From, To, Packet);
@ -83,15 +83,20 @@ do_route(State, From, To, Packet) ->
_ ->
ok
end;
#jid{luser = ""} ->
{xmlelement, _Name, Attrs, _Els} = Packet,
#jid{luser = "", lresource = Res} ->
{xmlelement, Name, Attrs, _Els} = Packet,
case xml:get_attr_s("type", Attrs) of
"error" -> ok;
"result" -> ok;
_ ->
Err = jlib:make_error_reply(Packet, ?ERR_ITEM_NOT_FOUND),
ejabberd_router:route(
jlib:make_jid("", State#state.mydomain, ""), From, Err)
case {Res, Name} of
{"announce/online", "message"} ->
announce_online(From, To, Packet);
_ ->
Err = jlib:make_error_reply(
Packet, ?ERR_ITEM_NOT_FOUND),
ejabberd_router:route(To, From, Err)
end
end;
_ ->
ejabberd_sm ! {route, From, To, Packet}
@ -100,7 +105,7 @@ do_route(State, From, To, Packet) ->
process_iq(State, From, To, Packet) ->
IQ = jlib:iq_query_info(Packet),
case IQ of
{iq, ID, Type, XMLNS, SubEl} ->
{iq, _ID, Type, XMLNS, _SubEl} ->
case jlib:is_iq_request_type(Type) of
true ->
case ets:lookup(State#state.iqtable, XMLNS) of
@ -121,10 +126,7 @@ process_iq(State, From, To, Packet) ->
[] ->
Err = jlib:make_error_reply(
Packet, ?ERR_FEATURE_NOT_IMPLEMENTED),
ejabberd_router ! {route,
{"", State#state.mydomain, ""},
From,
Err}
ejabberd_router:route(To, From, Err)
end;
_ ->
ok
@ -133,8 +135,7 @@ process_iq(State, From, To, Packet) ->
ok;
_ ->
Err = jlib:make_error_reply(Packet, ?ERR_BAD_REQUEST),
ejabberd_router ! {route,
{"", State#state.mydomain, ""}, From, Err},
ejabberd_router:route(To, From, Err),
ok
end.
@ -147,3 +148,18 @@ register_iq_handler(XMLNS, Module, Fun, Opts) ->
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() ->
ok.
process_iq(From, To, {iq, ID, Type, XMLNS, SubEl}) ->
process_iq(From, _To, {iq, ID, Type, XMLNS, SubEl}) ->
case Type of
set ->
UTag = xml:get_subtag(SubEl, "username"),
@ -124,6 +124,7 @@ try_register(User, Password) ->
case ejabberd_auth:try_register(User, Password) of
{atomic, ok} ->
send_welcome_message(JID),
send_registration_notifications(JID),
ok;
{atomic, exists} ->
{error, ?ERR_CONFLICT};
@ -149,3 +150,28 @@ send_welcome_message(JID) ->
ok
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.