1 |
|
%% Domain actions for mongooseimctl |
2 |
|
-module(service_admin_extra_domain). |
3 |
|
-export([commands/0, |
4 |
|
insert_domain/2, |
5 |
|
delete_domain/2, |
6 |
|
enable_domain/1, |
7 |
|
disable_domain/1]). |
8 |
|
|
9 |
|
-ignore_xref([ |
10 |
|
commands/0, insert_domain/2, delete_domain/2, enable_domain/1, disable_domain/1 |
11 |
|
]). |
12 |
|
|
13 |
|
-include("mongoose.hrl"). |
14 |
|
-include("ejabberd_commands.hrl"). |
15 |
|
-include("jlib.hrl"). |
16 |
|
|
17 |
|
-type cmd_result() :: {ok, string()} | {error, string()}. |
18 |
|
|
19 |
|
-spec commands() -> [ejabberd_commands:cmd()]. |
20 |
|
commands() -> |
21 |
160 |
[ |
22 |
|
#ejabberd_commands{name = insert_domain, tags = [domain], |
23 |
|
desc = "Insert a domain", |
24 |
|
module = ?MODULE, function = insert_domain, |
25 |
|
args = [{domain, binary}, {host_type, binary}], |
26 |
|
result = {res, restuple}}, |
27 |
|
#ejabberd_commands{name = delete_domain, tags = [domain], |
28 |
|
desc = "Delete a domain", |
29 |
|
module = ?MODULE, function = delete_domain, |
30 |
|
args = [{domain, binary}, {host_type, binary}], |
31 |
|
result = {res, restuple}}, |
32 |
|
#ejabberd_commands{name = enable_domain, tags = [domain], |
33 |
|
desc = "Enable a domain", |
34 |
|
module = ?MODULE, function = enable_domain, |
35 |
|
args = [{domain, binary}], |
36 |
|
result = {res, restuple}}, |
37 |
|
#ejabberd_commands{name = disable_domain, tags = [domain], |
38 |
|
desc = "Disable a domain", |
39 |
|
module = ?MODULE, function = disable_domain, |
40 |
|
args = [{domain, binary}], |
41 |
|
result = {res, restuple}} |
42 |
|
]. |
43 |
|
|
44 |
|
-spec insert_domain(binary(), binary()) -> cmd_result(). |
45 |
|
insert_domain(Domain, HostType) -> |
46 |
:-( |
SDomain = jid:nameprep(Domain), |
47 |
:-( |
case mongoose_domain_api:insert_domain(SDomain, HostType) of |
48 |
:-( |
ok -> {ok, "Added"}; |
49 |
|
{error, duplicate} -> |
50 |
:-( |
{error, "Domain already exists"}; |
51 |
|
{error, static} -> |
52 |
:-( |
{error, "Domain is static"}; |
53 |
|
{error, {db_error, _}} -> |
54 |
:-( |
{error, "Database error"}; |
55 |
|
{error, service_disabled} -> |
56 |
:-( |
{error, "Service disabled"}; |
57 |
|
{error, unknown_host_type} -> |
58 |
:-( |
{error, "Unknown host type"} |
59 |
|
end. |
60 |
|
|
61 |
|
-spec delete_domain(binary(), binary()) -> cmd_result(). |
62 |
|
delete_domain(Domain, HostType) -> |
63 |
:-( |
SDomain = jid:nameprep(Domain), |
64 |
:-( |
case mongoose_domain_api:delete_domain(SDomain, HostType) of |
65 |
:-( |
ok -> {ok, "Deleted"}; |
66 |
|
{error, {db_error, _}} -> |
67 |
:-( |
{error, "Database error"}; |
68 |
|
{error, static} -> |
69 |
:-( |
{error, "Domain is static"}; |
70 |
|
{error, service_disabled} -> |
71 |
:-( |
{error, "Service disabled"}; |
72 |
|
{error, wrong_host_type} -> |
73 |
:-( |
{error, "Wrong host type"}; |
74 |
|
{error, unknown_host_type} -> |
75 |
:-( |
{error, "Unknown host type"} |
76 |
|
end. |
77 |
|
|
78 |
|
-spec enable_domain(binary()) -> cmd_result(). |
79 |
|
enable_domain(Domain) -> |
80 |
:-( |
SDomain = jid:nameprep(Domain), |
81 |
:-( |
Res = mongoose_domain_api:enable_domain(SDomain), |
82 |
:-( |
handle_enabled_result(Res, "enabled"). |
83 |
|
|
84 |
|
-spec disable_domain(binary()) -> cmd_result(). |
85 |
|
disable_domain(Domain) -> |
86 |
:-( |
SDomain = jid:nameprep(Domain), |
87 |
:-( |
Res = mongoose_domain_api:disable_domain(SDomain), |
88 |
:-( |
handle_enabled_result(Res, "disabled"). |
89 |
|
|
90 |
|
handle_enabled_result(Res, OkText) -> |
91 |
:-( |
case Res of |
92 |
|
ok -> |
93 |
:-( |
{ok, OkText}; |
94 |
|
{error, not_found} -> |
95 |
:-( |
{error, "Domain not found"}; |
96 |
|
{error, static} -> |
97 |
:-( |
{error, "Domain is static"}; |
98 |
|
{error, service_disabled} -> |
99 |
:-( |
{error, "Service disabled"}; |
100 |
|
{error, {db_error, _}} -> |
101 |
:-( |
{error, "Database error"} |
102 |
|
end. |