1#include <xrpld/rpc/Role.h>
3#include <boost/beast/http/field.hpp>
4#include <boost/utility/string_view.hpp>
15 "xrpl::passwordUnrequiredOrSentCorrect : non-empty admin nets");
18 return !passwordRequired ||
19 ((params[
"admin_password"].
isString() &&
21 (params[
"admin_user"].isString() && params[
"admin_user"].
asString() == port.
admin_user));
42 auto ipNet = boost::asio::ip::make_network_v4(addrString);
43 for (
auto const& net : nets4)
45 if (ipNet.is_subnet_of(net) || ipNet == net)
52 auto ipNet = boost::asio::ip::make_network_v6(addrString);
53 for (
auto const& net : nets6)
55 if (ipNet.is_subnet_of(net) || ipNet == net)
105 Role const& required,
139 if (firstNonSpace == std::string_view::npos)
146 ret = ret.
substr(firstNonSpace);
152 if (
unsigned char const c = ret.
back(); c ==
' ' || c ==
'\r' || c ==
'\n')
155 if (lastNonSpace == std::string_view::npos)
162 ret = ret.
substr(0, lastNonSpace + 1);
173 if (ret.
front() ==
'"')
189 if (ret.
front() ==
'[')
197 return std::isxdigit(c) || c ==
':' || c ==
'.' || c ==
' ';
202 if (closeBracket == ret.
end() || (*closeBracket) !=
']')
217 ret.
begin(), ret.
end(), [](
unsigned char c) { return std::isxdigit(c) || c ==
' '; });
221 if (colon == ret.
end() || (*colon) ==
':')
227 if (
std::size_t const colon = ret.
find(
':'); colon != std::string_view::npos)
228 ret = ret.
substr(0, colon);
237 if (
auto it = request.find(boost::beast::http::field::forwarded); it != request.end())
239 auto ascii_tolower = [](
char c) ->
char {
240 return ((
static_cast<unsigned>(c) - 65U) < 26) ? c +
'a' -
'A' : c;
250 [&ascii_tolower](
char c1,
char c2) { return ascii_tolower(c1) == ascii_tolower(c2); });
252 if (found == it->value().end())
255 found += forStr.size();
261 if (pos != std::string_view::npos)
264 return it->value().size() - forStr.size();
271 if (
auto it = request.find(
"X-Forwarded-For"); it != request.end())
275 if (found == boost::string_view::npos)
276 found = it->value().length();
std::string asString() const
Returns the unquoted string value.
A version-independent IP address and port combination.
Address const & address() const
Returns the address portion of this endpoint.
Tracks load and resource consumption.
virtual Consumer newUnlimitedEndpoint(beast::IP::Endpoint const &address)=0
Create a new unlimited endpoint keyed by forwarded IP.
virtual Consumer newInboundEndpoint(beast::IP::Endpoint const &address)=0
Create a new endpoint keyed by inbound IP address or the forwarded IP if proxied.
T find_first_not_of(T... args)
T find_first_of(T... args)
T find_last_not_of(T... args)
boost::asio::ip::address Address
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
bool passwordUnrequiredOrSentCorrect(Port const &port, Json::Value const ¶ms)
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
Role requestRole(Role const &required, Port const &port, Json::Value const ¶ms, beast::IP::Endpoint const &remoteIp, std::string_view user)
Return the allowed privilege role.
Resource::Consumer requestInboundEndpoint(Resource::Manager &manager, beast::IP::Endpoint const &remoteAddress, Role const &role, std::string_view user, std::string_view forwardedFor)
std::string_view forwardedFor(http_request_type const &request)
bool isAdmin(Port const &port, Json::Value const ¶ms, beast::IP::Address const &remoteIp)
Role
Indicates the level of administrative permission to grant.
bool ipAllowed(beast::IP::Address const &remoteIp, std::vector< boost::asio::ip::network_v4 > const &nets4, std::vector< boost::asio::ip::network_v6 > const &nets6)
True if remoteIp is in any of adminIp.
static std::string_view extractIpAddrFromField(std::string_view field)
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
T remove_prefix(T... args)
T remove_suffix(T... args)
Configuration information for a Server listening port.
std::vector< boost::asio::ip::network_v4 > admin_nets_v4
std::string admin_password
std::vector< boost::asio::ip::network_v6 > secure_gateway_nets_v6
std::vector< boost::asio::ip::network_v4 > secure_gateway_nets_v4
std::vector< boost::asio::ip::network_v6 > admin_nets_v6