25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-12-26 17:38:45 +01:00

Implement Get List of Registered/Online Users from XEP-0133

This commit is contained in:
Badlop 2022-02-07 19:37:09 +01:00
parent 9661d06334
commit dda60fcf0d

View File

@ -171,9 +171,14 @@ get_local_identity(Acc, _From, _To, Node, Lang) ->
?INFO_COMMAND(?T("Get User Last Login Time"), Lang); ?INFO_COMMAND(?T("Get User Last Login Time"), Lang);
?NS_ADMINL(<<"user-stats">>) -> ?NS_ADMINL(<<"user-stats">>) ->
?INFO_COMMAND(?T("Get User Statistics"), Lang); ?INFO_COMMAND(?T("Get User Statistics"), Lang);
?NS_ADMINL(<<"get-registered-users-list">>) ->
?INFO_COMMAND(?T("Get List of Registered Users"),
Lang);
?NS_ADMINL(<<"get-registered-users-num">>) -> ?NS_ADMINL(<<"get-registered-users-num">>) ->
?INFO_COMMAND(?T("Get Number of Registered Users"), ?INFO_COMMAND(?T("Get Number of Registered Users"),
Lang); Lang);
?NS_ADMINL(<<"get-online-users-list">>) ->
?INFO_COMMAND(?T("Get List of Online Users"), Lang);
?NS_ADMINL(<<"get-online-users-num">>) -> ?NS_ADMINL(<<"get-online-users-num">>) ->
?INFO_COMMAND(?T("Get Number of Online Users"), Lang); ?INFO_COMMAND(?T("Get Number of Online Users"), Lang);
_ -> Acc _ -> Acc
@ -252,8 +257,12 @@ get_local_features(Acc, From,
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang); ?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
?NS_ADMINL(<<"user-stats">>) -> ?NS_ADMINL(<<"user-stats">>) ->
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang); ?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
?NS_ADMINL(<<"get-registered-users-list">>) ->
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
?NS_ADMINL(<<"get-registered-users-num">>) -> ?NS_ADMINL(<<"get-registered-users-num">>) ->
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang); ?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
?NS_ADMINL(<<"get-online-users-list">>) ->
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
?NS_ADMINL(<<"get-online-users-num">>) -> ?NS_ADMINL(<<"get-online-users-num">>) ->
?INFO_RESULT(Allow, [?NS_COMMANDS], Lang); ?INFO_RESULT(Allow, [?NS_COMMANDS], Lang);
_ -> Acc _ -> Acc
@ -476,8 +485,12 @@ get_local_items(Acc, From, #jid{lserver = LServer} = To,
?ITEMS_RESULT(Allow, LNode, {error, Err}); ?ITEMS_RESULT(Allow, LNode, {error, Err});
?NS_ADMINL(<<"user-stats">>) -> ?NS_ADMINL(<<"user-stats">>) ->
?ITEMS_RESULT(Allow, LNode, {error, Err}); ?ITEMS_RESULT(Allow, LNode, {error, Err});
?NS_ADMINL(<<"get-registered-users-list">>) ->
?ITEMS_RESULT(Allow, LNode, {error, Err});
?NS_ADMINL(<<"get-registered-users-num">>) -> ?NS_ADMINL(<<"get-registered-users-num">>) ->
?ITEMS_RESULT(Allow, LNode, {error, Err}); ?ITEMS_RESULT(Allow, LNode, {error, Err});
?NS_ADMINL(<<"get-online-users-list">>) ->
?ITEMS_RESULT(Allow, LNode, {error, Err});
?NS_ADMINL(<<"get-online-users-num">>) -> ?NS_ADMINL(<<"get-online-users-num">>) ->
?ITEMS_RESULT(Allow, LNode, {error, Err}); ?ITEMS_RESULT(Allow, LNode, {error, Err});
_ -> Acc _ -> Acc
@ -515,8 +528,12 @@ get_local_items(_Host, [<<"user">>], Server, Lang) ->
(?NS_ADMINX(<<"get-user-lastlogin">>))), (?NS_ADMINX(<<"get-user-lastlogin">>))),
?NODE(?T("Get User Statistics"), ?NODE(?T("Get User Statistics"),
(?NS_ADMINX(<<"user-stats">>))), (?NS_ADMINX(<<"user-stats">>))),
?NODE(?T("Get List of Registered Users"),
(?NS_ADMINX(<<"get-registered-users-list">>))),
?NODE(?T("Get Number of Registered Users"), ?NODE(?T("Get Number of Registered Users"),
(?NS_ADMINX(<<"get-registered-users-num">>))), (?NS_ADMINX(<<"get-registered-users-num">>))),
?NODE(?T("Get List of Online Users"),
(?NS_ADMINX(<<"get-online-users-list">>))),
?NODE(?T("Get Number of Online Users"), ?NODE(?T("Get Number of Online Users"),
(?NS_ADMINX(<<"get-online-users-num">>)))]}; (?NS_ADMINX(<<"get-online-users-num">>)))]};
get_local_items(_Host, [<<"http:">> | _], _Server, get_local_items(_Host, [<<"http:">> | _], _Server,
@ -1065,6 +1082,16 @@ get_form(_Host, ?NS_ADMINL(<<"user-stats">>), Lang) ->
label = tr(Lang, ?T("Jabber ID")), label = tr(Lang, ?T("Jabber ID")),
var = <<"accountjid">>, var = <<"accountjid">>,
required = true}]}}; required = true}]}};
get_form(Host, ?NS_ADMINL(<<"get-registered-users-list">>), Lang) ->
Values = [jid:encode(jid:make(U, Host))
|| {U, _} <- ejabberd_auth:get_users(Host)],
{result, completed,
#xdata{type = form,
fields = [?HFIELD(),
#xdata_field{type = 'jid-multi',
label = tr(Lang, ?T("The list of all users")),
var = <<"registereduserjids">>,
values = Values}]}};
get_form(Host, get_form(Host,
?NS_ADMINL(<<"get-registered-users-num">>), Lang) -> ?NS_ADMINL(<<"get-registered-users-num">>), Lang) ->
Num = integer_to_binary(ejabberd_auth:count_users(Host)), Num = integer_to_binary(ejabberd_auth:count_users(Host)),
@ -1075,6 +1102,17 @@ get_form(Host,
label = tr(Lang, ?T("Number of registered users")), label = tr(Lang, ?T("Number of registered users")),
var = <<"registeredusersnum">>, var = <<"registeredusersnum">>,
values = [Num]}]}}; values = [Num]}]}};
get_form(Host, ?NS_ADMINL(<<"get-online-users-list">>), Lang) ->
Accounts = [jid:encode(jid:make(U, Host))
|| {U, _, _} <- ejabberd_sm:get_vh_session_list(Host)],
Values = lists:usort(Accounts),
{result, completed,
#xdata{type = form,
fields = [?HFIELD(),
#xdata_field{type = 'jid-multi',
label = tr(Lang, ?T("The list of all online users")),
var = <<"onlineuserjids">>,
values = Values}]}};
get_form(Host, ?NS_ADMINL(<<"get-online-users-num">>), get_form(Host, ?NS_ADMINL(<<"get-online-users-num">>),
Lang) -> Lang) ->
Num = integer_to_binary(ejabberd_sm:get_vh_session_number(Host)), Num = integer_to_binary(ejabberd_sm:get_vh_session_number(Host)),