Add support for using yaml config file.
When converting to use the yaml config, the option for `allowed_ips` gets stored as a binary. But needs to be compared against the client ip of the request (which is a tuple). This converts the list of binaries into a list of ip tuples.
This commit is contained in:
parent
9a30d2d022
commit
73e6b7ed22
|
@ -119,12 +119,31 @@ check_stanza(Stanza, _From, To, Host) ->
|
||||||
check_member_option(Host, StanzaType, allowed_stanza_types),
|
check_member_option(Host, StanzaType, allowed_stanza_types),
|
||||||
allowed.
|
allowed.
|
||||||
|
|
||||||
|
check_member_option(Host, ClientIp, allowed_ips) ->
|
||||||
|
true = case try_get_option(Host, allowed_ips, all) of
|
||||||
|
all -> true;
|
||||||
|
AllowedValues ->
|
||||||
|
case lists:all(fun(El) -> is_binary(El) end, AllowedValues) of
|
||||||
|
true ->
|
||||||
|
AllowedIps = lists:map(fun(El) ->
|
||||||
|
binary_to_ip_tuple(El)
|
||||||
|
end,
|
||||||
|
AllowedValues),
|
||||||
|
lists:member(ClientIp, AllowedIps);
|
||||||
|
false ->
|
||||||
|
lists:member(ClientIp, AllowedValues)
|
||||||
|
end
|
||||||
|
end;
|
||||||
check_member_option(Host, Element, Option) ->
|
check_member_option(Host, Element, Option) ->
|
||||||
true = case try_get_option(Host, Option, all) of
|
true = case try_get_option(Host, Option, all) of
|
||||||
all -> true;
|
all -> true;
|
||||||
AllowedValues -> lists:member(Element, AllowedValues)
|
AllowedValues -> lists:member(Element, AllowedValues)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
binary_to_ip_tuple(IpAddress) when is_binary(IpAddress) ->
|
||||||
|
{ok, IpTuple} = inet_parse:address(binary_to_list(IpAddress)),
|
||||||
|
IpTuple.
|
||||||
|
|
||||||
post_request(Stanza, From, To) ->
|
post_request(Stanza, From, To) ->
|
||||||
case ejabberd_router:route(From, To, Stanza) of
|
case ejabberd_router:route(From, To, Stanza) of
|
||||||
ok -> {200, [], <<"Ok">>};
|
ok -> {200, [], <<"Ok">>};
|
||||||
|
|
Loading…
Reference in New Issue