%%%
register(User, Host, Password) ->
- case ejabberd_auth:try_register(User, Host, Password) of
- ok ->
- {ok, io_lib:format("User ~s@~s successfully registered", [User, Host])};
- {error, exists} ->
- Msg = io_lib:format("User ~s@~s already registered", [User, Host]),
- {error, conflict, 10090, Msg};
- {error, Reason} ->
- String = io_lib:format("Can't register user ~s@~s at node ~p: ~s",
- [User, Host, node(),
- mod_register:format_error(Reason)]),
- {error, cannot_register, 10001, String}
+ case is_my_host(Host) of
+ true ->
+ case ejabberd_auth:try_register(User, Host, Password) of
+ ok ->
+ {ok, io_lib:format("User ~s@~s successfully registered", [User, Host])};
+ {error, exists} ->
+ Msg = io_lib:format("User ~s@~s already registered", [User, Host]),
+ {error, conflict, 10090, Msg};
+ {error, Reason} ->
+ String = io_lib:format("Can't register user ~s@~s at node ~p: ~s",
+ [User, Host, node(),
+ mod_register:format_error(Reason)]),
+ {error, cannot_register, 10001, String}
+ end;
+ false ->
+ {error, cannot_register, 10001, "Unknown virtual host"}
end.
unregister(User, Host) ->
- ejabberd_auth:remove_user(User, Host),
- {ok, ""}.
+ case is_my_host(Host) of
+ true ->
+ ejabberd_auth:remove_user(User, Host),
+ {ok, ""};
+ false ->
+ {error, "Unknown virtual host"}
+ end.
registered_users(Host) ->
- Users = ejabberd_auth:get_users(Host),
- SUsers = lists:sort(Users),
- lists:map(fun({U, _S}) -> U end, SUsers).
+ case is_my_host(Host) of
+ true ->
+ Users = ejabberd_auth:get_users(Host),
+ SUsers = lists:sort(Users),
+ lists:map(fun({U, _S}) -> U end, SUsers);
+ false ->
+ {error, "Unknown virtual host"}
+ end.
registered_vhosts() ->
ejabberd_option:hosts().
clear_cache() ->
Nodes = ejabberd_cluster:get_nodes(),
lists:foreach(fun(T) -> ets_cache:clear(T, Nodes) end, ets_cache:all()).
+
+-spec is_my_host(binary()) -> boolean().
+is_my_host(Host) ->
+ try ejabberd_router:is_my_host(Host)
+ catch _:{invalid_domain, _} -> false
+ end.
throw:Error ->
{io_lib:format("~p", [Error]), ?STATUS_ERROR};
?EX_RULE(A, Why, Stack) ->
- {io_lib:format("Problem '~p ~p' occurred executing the command.~nStacktrace: ~p",
- [A, Why, ?EX_STACK(Stack)]), ?STATUS_ERROR}
+ StackTrace = ?EX_STACK(Stack),
+ {io_lib:format("Unhandled exception occurred executing the command:~n** ~s",
+ [misc:format_exception(2, A, Why, StackTrace)]),
+ ?STATUS_ERROR}
end.
%% @spec (Args::[string()], Auth, AccessCommands) -> string() | integer() | {string(), integer()} | {error, ErrorType}