mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
* src/ejabberd_sm.erl: Updated the session table to store
additional session info * src/ejabberd_c2s.erl: Report IP address to ejabberd_sm (thanks to Christophe Romain) SVN Revision: 772
This commit is contained in:
parent
06320f429a
commit
9a6e8e3c55
@ -1,3 +1,10 @@
|
|||||||
|
2007-05-21 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
|
* src/ejabberd_sm.erl: Updated the session table to store
|
||||||
|
additional session info
|
||||||
|
* src/ejabberd_c2s.erl: Report IP address to ejabberd_sm (thanks
|
||||||
|
to Christophe Romain)
|
||||||
|
|
||||||
2007-05-18 Alexey Shchepin <alexey@sevcom.net>
|
2007-05-18 Alexey Shchepin <alexey@sevcom.net>
|
||||||
|
|
||||||
* src/msgs/zh.msg: New chinese translation (thanks to Shelley
|
* src/msgs/zh.msg: New chinese translation (thanks to Shelley
|
||||||
|
@ -64,6 +64,7 @@
|
|||||||
pres_timestamp,
|
pres_timestamp,
|
||||||
pres_invis = false,
|
pres_invis = false,
|
||||||
privacy_list = none,
|
privacy_list = none,
|
||||||
|
ip,
|
||||||
lang}).
|
lang}).
|
||||||
|
|
||||||
%-define(DBGFSM, true).
|
%-define(DBGFSM, true).
|
||||||
@ -136,6 +137,7 @@ init([{SockMod, Socket}, Opts]) ->
|
|||||||
TLSOpts = lists:filter(fun({certfile, _}) -> true;
|
TLSOpts = lists:filter(fun({certfile, _}) -> true;
|
||||||
(_) -> false
|
(_) -> false
|
||||||
end, Opts),
|
end, Opts),
|
||||||
|
IP = peerip(SockMod, Socket),
|
||||||
Socket1 =
|
Socket1 =
|
||||||
if
|
if
|
||||||
TLSEnabled ->
|
TLSEnabled ->
|
||||||
@ -154,7 +156,8 @@ init([{SockMod, Socket}, Opts]) ->
|
|||||||
tls_options = TLSOpts,
|
tls_options = TLSOpts,
|
||||||
streamid = new_id(),
|
streamid = new_id(),
|
||||||
access = Access,
|
access = Access,
|
||||||
shaper = Shaper}}.
|
shaper = Shaper,
|
||||||
|
ip = IP}}.
|
||||||
|
|
||||||
|
|
||||||
%%----------------------------------------------------------------------
|
%%----------------------------------------------------------------------
|
||||||
@ -386,8 +389,9 @@ wait_for_auth({xmlstreamelement, El}, StateData) ->
|
|||||||
[StateData#state.socket,
|
[StateData#state.socket,
|
||||||
jlib:jid_to_string(JID)]),
|
jlib:jid_to_string(JID)]),
|
||||||
SID = {now(), self()},
|
SID = {now(), self()},
|
||||||
|
IP = StateData#state.ip,
|
||||||
ejabberd_sm:open_session(
|
ejabberd_sm:open_session(
|
||||||
SID, U, StateData#state.server, R),
|
SID, U, StateData#state.server, R, IP),
|
||||||
Res1 = jlib:make_result_iq_reply(El),
|
Res1 = jlib:make_result_iq_reply(El),
|
||||||
Res = setelement(4, Res1, []),
|
Res = setelement(4, Res1, []),
|
||||||
send_element(StateData, Res),
|
send_element(StateData, Res),
|
||||||
@ -717,8 +721,9 @@ wait_for_session({xmlstreamelement, El}, StateData) ->
|
|||||||
[StateData#state.socket,
|
[StateData#state.socket,
|
||||||
jlib:jid_to_string(JID)]),
|
jlib:jid_to_string(JID)]),
|
||||||
SID = {now(), self()},
|
SID = {now(), self()},
|
||||||
|
IP = StateData#state.ip,
|
||||||
ejabberd_sm:open_session(
|
ejabberd_sm:open_session(
|
||||||
SID, U, StateData#state.server, R),
|
SID, U, StateData#state.server, R, IP),
|
||||||
Res = jlib:make_result_iq_reply(El),
|
Res = jlib:make_result_iq_reply(El),
|
||||||
send_element(StateData, Res),
|
send_element(StateData, Res),
|
||||||
change_shaper(StateData, JID),
|
change_shaper(StateData, JID),
|
||||||
@ -1323,7 +1328,8 @@ presence_update(From, Packet, StateData) ->
|
|||||||
StateData#state.user,
|
StateData#state.user,
|
||||||
StateData#state.server,
|
StateData#state.server,
|
||||||
StateData#state.resource,
|
StateData#state.resource,
|
||||||
Status),
|
Status,
|
||||||
|
StateData#state.ip),
|
||||||
presence_broadcast(StateData, From, StateData#state.pres_a, Packet),
|
presence_broadcast(StateData, From, StateData#state.pres_a, Packet),
|
||||||
presence_broadcast(StateData, From, StateData#state.pres_i, Packet),
|
presence_broadcast(StateData, From, StateData#state.pres_i, Packet),
|
||||||
StateData#state{pres_last = undefined,
|
StateData#state{pres_last = undefined,
|
||||||
@ -1654,7 +1660,8 @@ update_priority(Priority, Packet, StateData) ->
|
|||||||
StateData#state.server,
|
StateData#state.server,
|
||||||
StateData#state.resource,
|
StateData#state.resource,
|
||||||
Priority,
|
Priority,
|
||||||
Packet).
|
Packet,
|
||||||
|
StateData#state.ip).
|
||||||
|
|
||||||
get_priority_from_presence(PresencePacket) ->
|
get_priority_from_presence(PresencePacket) ->
|
||||||
case xml:get_subtag(PresencePacket, "priority") of
|
case xml:get_subtag(PresencePacket, "priority") of
|
||||||
@ -1795,3 +1802,12 @@ process_unauthenticated_stanza(StateData, El) ->
|
|||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
peerip(SockMod, Socket) ->
|
||||||
|
IP = case SockMod of
|
||||||
|
gen_tcp -> inet:peername(Socket);
|
||||||
|
_ -> SockMod:peername(Socket)
|
||||||
|
end,
|
||||||
|
case IP of
|
||||||
|
{ok, IPOK} -> IPOK;
|
||||||
|
_ -> undefined
|
||||||
|
end.
|
||||||
|
@ -14,13 +14,13 @@
|
|||||||
%% API
|
%% API
|
||||||
-export([start_link/0,
|
-export([start_link/0,
|
||||||
route/3,
|
route/3,
|
||||||
open_session/4, close_session/4,
|
open_session/5, close_session/4,
|
||||||
check_in_subscription/6,
|
check_in_subscription/6,
|
||||||
bounce_offline_message/3,
|
bounce_offline_message/3,
|
||||||
disconnect_removed_user/2,
|
disconnect_removed_user/2,
|
||||||
get_user_resources/2,
|
get_user_resources/2,
|
||||||
set_presence/6,
|
set_presence/7,
|
||||||
unset_presence/5,
|
unset_presence/6,
|
||||||
close_session_unset_presence/5,
|
close_session_unset_presence/5,
|
||||||
dirty_get_sessions_list/0,
|
dirty_get_sessions_list/0,
|
||||||
dirty_get_my_sessions_list/0,
|
dirty_get_my_sessions_list/0,
|
||||||
@ -28,7 +28,8 @@
|
|||||||
register_iq_handler/4,
|
register_iq_handler/4,
|
||||||
register_iq_handler/5,
|
register_iq_handler/5,
|
||||||
unregister_iq_handler/2,
|
unregister_iq_handler/2,
|
||||||
ctl_process/2
|
ctl_process/2,
|
||||||
|
get_user_ip/3
|
||||||
]).
|
]).
|
||||||
|
|
||||||
%% gen_server callbacks
|
%% gen_server callbacks
|
||||||
@ -39,7 +40,7 @@
|
|||||||
-include("jlib.hrl").
|
-include("jlib.hrl").
|
||||||
-include("ejabberd_ctl.hrl").
|
-include("ejabberd_ctl.hrl").
|
||||||
|
|
||||||
-record(session, {sid, usr, us, priority}).
|
-record(session, {sid, usr, us, priority, info}).
|
||||||
-record(state, {}).
|
-record(state, {}).
|
||||||
|
|
||||||
%% default value for the maximum number of user connections
|
%% default value for the maximum number of user connections
|
||||||
@ -64,8 +65,8 @@ route(From, To, Packet) ->
|
|||||||
ok
|
ok
|
||||||
end.
|
end.
|
||||||
|
|
||||||
open_session(SID, User, Server, Resource) ->
|
open_session(SID, User, Server, Resource, IP) ->
|
||||||
set_session(SID, User, Server, Resource, undefined),
|
set_session(SID, User, Server, Resource, undefined, IP),
|
||||||
check_for_sessions_to_replace(User, Server, Resource),
|
check_for_sessions_to_replace(User, Server, Resource),
|
||||||
JID = jlib:make_jid(User, Server, Resource),
|
JID = jlib:make_jid(User, Server, Resource),
|
||||||
ejabberd_hooks:run(sm_register_connection_hook, JID#jid.lserver,
|
ejabberd_hooks:run(sm_register_connection_hook, JID#jid.lserver,
|
||||||
@ -80,7 +81,7 @@ close_session(SID, User, Server, Resource) ->
|
|||||||
ejabberd_hooks:run(sm_remove_connection_hook, JID#jid.lserver,
|
ejabberd_hooks:run(sm_remove_connection_hook, JID#jid.lserver,
|
||||||
[SID, JID]).
|
[SID, JID]).
|
||||||
|
|
||||||
check_in_subscription(Acc, User, Server, JID, Type, Reason) ->
|
check_in_subscription(Acc, User, Server, _JID, _Type, _Reason) ->
|
||||||
case ejabberd_auth:is_user_exists(User, Server) of
|
case ejabberd_auth:is_user_exists(User, Server) of
|
||||||
true ->
|
true ->
|
||||||
Acc;
|
Acc;
|
||||||
@ -110,13 +111,27 @@ get_user_resources(User, Server) ->
|
|||||||
[element(3, S#session.usr) || S <- clean_session_list(Ss)]
|
[element(3, S#session.usr) || S <- clean_session_list(Ss)]
|
||||||
end.
|
end.
|
||||||
|
|
||||||
set_presence(SID, User, Server, Resource, Priority, Presence) ->
|
get_user_ip(User, Server, Resource) ->
|
||||||
set_session(SID, User, Server, Resource, Priority),
|
LUser = jlib:nodeprep(User),
|
||||||
|
LServer = jlib:nameprep(Server),
|
||||||
|
LResource = jlib:resourceprep(Resource),
|
||||||
|
USR = {LUser, LServer, LResource},
|
||||||
|
case mnesia:dirty_index_read(session, USR, #session.usr) of
|
||||||
|
[] ->
|
||||||
|
undefined;
|
||||||
|
Ss ->
|
||||||
|
Session = lists:max(Ss),
|
||||||
|
proplists:get_value(ip, Session#session.info)
|
||||||
|
end.
|
||||||
|
|
||||||
|
|
||||||
|
set_presence(SID, User, Server, Resource, Priority, Presence, IP) ->
|
||||||
|
set_session(SID, User, Server, Resource, Priority, IP),
|
||||||
ejabberd_hooks:run(set_presence_hook, jlib:nameprep(Server),
|
ejabberd_hooks:run(set_presence_hook, jlib:nameprep(Server),
|
||||||
[User, Server, Resource, Presence]).
|
[User, Server, Resource, Presence]).
|
||||||
|
|
||||||
unset_presence(SID, User, Server, Resource, Status) ->
|
unset_presence(SID, User, Server, Resource, Status, IP) ->
|
||||||
set_session(SID, User, Server, Resource, undefined),
|
set_session(SID, User, Server, Resource, undefined, IP),
|
||||||
ejabberd_hooks:run(unset_presence_hook, jlib:nameprep(Server),
|
ejabberd_hooks:run(unset_presence_hook, jlib:nameprep(Server),
|
||||||
[User, Server, Resource, Status]).
|
[User, Server, Resource, Status]).
|
||||||
|
|
||||||
@ -275,17 +290,19 @@ code_change(_OldVsn, State, _Extra) ->
|
|||||||
%%% Internal functions
|
%%% Internal functions
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
|
|
||||||
set_session(SID, User, Server, Resource, Priority) ->
|
set_session(SID, User, Server, Resource, Priority, IP) ->
|
||||||
LUser = jlib:nodeprep(User),
|
LUser = jlib:nodeprep(User),
|
||||||
LServer = jlib:nameprep(Server),
|
LServer = jlib:nameprep(Server),
|
||||||
LResource = jlib:resourceprep(Resource),
|
LResource = jlib:resourceprep(Resource),
|
||||||
US = {LUser, LServer},
|
US = {LUser, LServer},
|
||||||
USR = {LUser, LServer, LResource},
|
USR = {LUser, LServer, LResource},
|
||||||
|
Info = [{ip, IP}],
|
||||||
F = fun() ->
|
F = fun() ->
|
||||||
mnesia:write(#session{sid = SID,
|
mnesia:write(#session{sid = SID,
|
||||||
usr = USR,
|
usr = USR,
|
||||||
us = US,
|
us = US,
|
||||||
priority = Priority})
|
priority = Priority,
|
||||||
|
info = Info})
|
||||||
end,
|
end,
|
||||||
mnesia:sync_dirty(F).
|
mnesia:sync_dirty(F).
|
||||||
|
|
||||||
@ -617,6 +634,8 @@ update_tables() ->
|
|||||||
[usr, us, pid] ->
|
[usr, us, pid] ->
|
||||||
mnesia:delete_table(session);
|
mnesia:delete_table(session);
|
||||||
[sid, usr, us, priority] ->
|
[sid, usr, us, priority] ->
|
||||||
|
mnesia:delete_table(session);
|
||||||
|
[sid, usr, us, priority, info] ->
|
||||||
ok;
|
ok;
|
||||||
{'EXIT', _} ->
|
{'EXIT', _} ->
|
||||||
ok
|
ok
|
||||||
|
Loading…
Reference in New Issue
Block a user