mirror of
https://github.com/processone/ejabberd.git
synced 2024-12-22 17:28:25 +01:00
Check virtual host before running the command
This commit is contained in:
parent
0545e0a797
commit
cbe84eb50c
@ -498,27 +498,42 @@ update_module(ModuleNameString) ->
|
||||
%%%
|
||||
|
||||
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().
|
||||
@ -812,3 +827,9 @@ mnesia_change_nodename(FromString, ToString, Source, Target) ->
|
||||
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.
|
||||
|
@ -331,8 +331,10 @@ try_call_command(Args, Auth, AccessCommands, Version) ->
|
||||
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}
|
||||
|
Loading…
Reference in New Issue
Block a user