./ct_report/coverage/service_admin_extra_accounts.COVER.html

1 %%%-------------------------------------------------------------------
2 %%% File : service_admin_extra_accounts.erl
3 %%% Author : Badlop <badlop@process-one.net>, Piotr Nosek <piotr.nosek@erlang-solutions.com>
4 %%% Purpose : Contributed administrative functions and commands
5 %%% Created : 10 Aug 2008 by Badlop <badlop@process-one.net>
6 %%%
7 %%%
8 %%% ejabberd, Copyright (C) 2002-2008 ProcessOne
9 %%%
10 %%% This program is free software; you can redistribute it and/or
11 %%% modify it under the terms of the GNU General Public License as
12 %%% published by the Free Software Foundation; either version 2 of the
13 %%% License, or (at your option) any later version.
14 %%%
15 %%% This program is distributed in the hope that it will be useful,
16 %%% but WITHOUT ANY WARRANTY; without even the implied warranty of
17 %%% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 %%% General Public License for more details.
19 %%%
20 %%% You should have received a copy of the GNU General Public License
21 %%% along with this program; if not, write to the Free Software
22 %%% Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 %%%
24 %%%-------------------------------------------------------------------
25
26 -module(service_admin_extra_accounts).
27 -author('badlop@process-one.net').
28
29 -export([
30 commands/0,
31
32 %% Accounts
33 set_password/3,
34 check_password_hash/4,
35 delete_old_users/1,
36 delete_old_users_for_domain/2,
37 ban_account/3,
38 num_active_users/2,
39 check_account/2,
40 check_password/3]).
41
42 -ignore_xref([
43 commands/0, set_password/3, check_password_hash/4,
44 delete_old_users/1, delete_old_users_for_domain/2,
45 ban_account/3, num_active_users/2, check_account/2, check_password/3
46 ]).
47
48 -include("ejabberd_commands.hrl").
49
50 %%%
51 %%% Register commands
52 %%%
53
54 -spec commands() -> [ejabberd_commands:cmd(), ...].
55 commands() ->
56 160 [
57 #ejabberd_commands{name = change_password, tags = [accounts],
58 desc = "Change the password of an account",
59 module = ?MODULE, function = set_password,
60 args = [{user, binary}, {host, binary}, {newpass, binary}],
61 result = {res, restuple}},
62 #ejabberd_commands{name = check_password_hash, tags = [accounts],
63 desc = "Check if the password hash is correct",
64 longdesc = "Allowed hash methods: md5, sha.",
65 module = ?MODULE, function = check_password_hash,
66 args = [{user, binary}, {host, binary}, {passwordhash, string},
67 {hashmethod, string}],
68 result = {res, restuple}},
69 #ejabberd_commands{name = delete_old_users, tags = [accounts, purge],
70 desc = "Delete users that didn't log in last days, or that never logged",
71 module = ?MODULE, function = delete_old_users,
72 args = [{days, integer}],
73 result = {res, restuple}},
74 #ejabberd_commands{name = delete_old_users_vhost, tags = [accounts, purge],
75 desc = "Delete users that didn't log in last days in vhost,"
76 " or that never logged",
77 module = ?MODULE, function = delete_old_users_for_domain,
78 args = [{host, binary}, {days, integer}],
79 result = {res, restuple}},
80 #ejabberd_commands{name = ban_account, tags = [accounts],
81 desc = "Ban an account: kick sessions and set random password",
82 module = ?MODULE, function = ban_account,
83 args = [{user, binary}, {host, binary}, {reason, binary}],
84 result = {res, restuple}},
85 #ejabberd_commands{name = num_active_users, tags = [accounts, stats],
86 desc = "Get number of users active in the last days",
87 module = ?MODULE, function = num_active_users,
88 args = [{host, binary}, {days, integer}],
89 result = {res, restuple}},
90 #ejabberd_commands{name = check_account, tags = [accounts],
91 desc = "Check if an account exists or not",
92 module = ?MODULE, function = check_account,
93 args = [{user, binary}, {host, binary}],
94 result = {res, restuple}},
95 #ejabberd_commands{name = check_password, tags = [accounts],
96 desc = "Check if a password is correct",
97 module = ?MODULE, function = check_password,
98 args = [{user, binary}, {host, binary}, {password, binary}],
99 result = {res, restuple}}
100 ].
101
102 %%%
103 %%% Accounts
104 %%%
105
106 -spec set_password(jid:user(), jid:server(), binary()) ->
107 mongoose_account_api:change_password_result().
108 set_password(User, Host, Password) ->
109 3 mongoose_account_api:change_password(User, Host, Password).
110
111 -spec check_password(jid:user(), jid:server(), binary()) ->
112 mongoose_account_api:check_password_result().
113 check_password(User, Host, Password) ->
114 2 mongoose_account_api:check_password(User, Host, Password).
115
116 -spec check_account(jid:user(), jid:server()) -> mongoose_account_api:check_account_result().
117 check_account(User, Host) ->
118 7 mongoose_account_api:check_account(User, Host).
119
120 -spec check_password_hash(jid:user(), jid:server(), string(), string()) ->
121 mongoose_account_api:check_password_hash_result().
122 check_password_hash(User, Host, PasswordHash, HashMethod) ->
123 3 mongoose_account_api:check_password_hash(User, Host, PasswordHash, HashMethod).
124
125 -spec num_active_users(jid:lserver(), integer()) -> {ok | cannot_count, string()}.
126 num_active_users(Domain, Days) ->
127 2 case mongoose_account_api:num_active_users(Domain, Days) of
128 2 {ok, Num} -> {ok, integer_to_list(Num)};
129
:-(
Res -> Res
130 end.
131
132 -spec delete_old_users(integer()) -> mongoose_account_api:delete_old_users_result().
133 delete_old_users(Days) ->
134 1 {Res, _} = mongoose_account_api:delete_old_users(Days),
135 1 Res.
136
137 -spec delete_old_users_for_domain(jid:server(), integer()) ->
138 mongoose_account_api:delete_old_users().
139 delete_old_users_for_domain(Domain, Days) ->
140 1 {Res, _} = mongoose_account_api:delete_old_users_for_domain(Domain, Days),
141 1 Res.
142
143 -spec ban_account(jid:user(), jid:server(), binary() | string()) ->
144 mongoose_account_api:change_password_result().
145 ban_account(User, Host, ReasonText) ->
146 1 mongoose_account_api:ban_account(User, Host, ReasonText).
Line Hits Source