connected_users_number/0,
user_resources/2,
kick_user/2,
+ kick_user/3,
get_session_pid/3,
get_session_sid/3,
get_session_sids/2,
Resources = get_user_resources(User, Server),
lists:sort(Resources).
+-spec kick_user(binary(), binary()) -> non_neg_integer().
kick_user(User, Server) ->
Resources = get_user_resources(User, Server),
- lists:foreach(
- fun(Resource) ->
- PID = get_session_pid(User, Server, Resource),
- ejabberd_c2s:route(PID, kick)
- end, Resources),
- length(Resources).
+ lists:foldl(
+ fun(Resource, Acc) ->
+ case kick_user(User, Server, Resource) of
+ false -> Acc;
+ true -> Acc + 1
+ end
+ end, 0, Resources).
+
+-spec kick_user(binary(), binary(), binary()) -> boolean().
+kick_user(User, Server, Resource) ->
+ case get_session_pid(User, Server, Resource) of
+ none -> false;
+ Pid -> ejabberd_c2s:route(Pid, kick)
+ end.
make_sid() ->
{p1_time_compat:unique_timestamp(), self()}.
|| {User, Server} <- ASL2],
{result, undefined};
set_form(From, Host, ?NS_ADMINL(<<"end-user-session">>),
- Lang, XData) ->
+ _Lang, XData) ->
AccountString = get_value(<<"accountjid">>, XData),
JID = jid:decode(AccountString),
- LUser = JID#jid.luser,
LServer = JID#jid.lserver,
true = LServer == Host orelse
get_permission_level(From) == global,
- Xmlelement = xmpp:serr_policy_violation(<<"has been kicked">>, Lang),
case JID#jid.lresource of
- <<>> ->
- SIs = mnesia:dirty_select(session,
- [{#session{usr = {LUser, LServer, '_'},
- sid = '$1',
- info = '$2',
- _ = '_'},
- [], [{{'$1', '$2'}}]}]),
- Pids = [P || {{_, P}, Info} <- SIs,
- not proplists:get_bool(offline, Info)],
- lists:foreach(fun(Pid) ->
- Pid ! {kick, kicked_by_admin, Xmlelement}
- end, Pids);
- R ->
- [{{_, Pid}, Info}] = mnesia:dirty_select(
- session,
- [{#session{usr = {LUser, LServer, R},
- sid = '$1',
- info = '$2',
- _ = '_'},
- [], [{{'$1', '$2'}}]}]),
- case proplists:get_bool(offline, Info) of
- true -> ok;
- false -> Pid ! {kick, kicked_by_admin, Xmlelement}
- end
+ <<>> ->
+ ejabberd_sm:kick_user(JID#jid.luser, JID#jid.lserver);
+ R ->
+ ejabberd_sm:kick_user(JID#jid.luser, JID#jid.lserver, R)
end,
{result, undefined};
set_form(From, Host,