20#include <xrpld/rpc/Role.h>
21#include <boost/beast/http/field.hpp>
22#include <boost/utility/string_view.hpp>
33 "ripple::passwordUnrequiredOrSentCorrect : non-empty admin nets");
34 bool const passwordRequired =
37 return !passwordRequired ||
38 ((params[
"admin_password"].
isString() &&
40 (params[
"admin_user"].isString() &&
62 auto ipNet = boost::asio::ip::make_network_v4(addrString);
63 for (
auto const& net : nets4)
65 if (ipNet.is_subnet_of(net) || ipNet == net)
72 auto ipNet = boost::asio::ip::make_network_v6(addrString);
73 for (
auto const& net : nets6)
75 if (ipNet.is_subnet_of(net) || ipNet == net)
131 Role const& required,
166 if (firstNonSpace == std::string_view::npos)
171 ret = ret.
substr(firstNonSpace);
177 if (
unsigned char const c = ret.
back();
178 c ==
' ' || c ==
'\r' || c ==
'\n')
181 if (lastNonSpace == std::string_view::npos)
186 ret = ret.
substr(0, lastNonSpace + 1);
197 if (ret.
front() ==
'"')
213 if (ret.
front() ==
'[')
220 auto const closeBracket =
222 return std::isxdigit(c) || c ==
':' || c ==
'.' || c ==
' ';
227 if (closeBracket == ret.
end() || (*closeBracket) !=
']')
243 return std::isxdigit(c) || c ==
' ';
248 if (colon == ret.
end() || (*colon) ==
':')
254 if (
std::size_t colon = ret.
find(
':'); colon != std::string_view::npos)
255 ret = ret.
substr(0, colon);
264 if (
auto it = request.find(boost::beast::http::field::forwarded);
267 auto ascii_tolower = [](
char c) ->
char {
268 return ((
static_cast<unsigned>(c) - 65U) < 26) ? c +
'a' -
'A' : c;
278 [&ascii_tolower](
char c1,
char c2) {
279 return ascii_tolower(c1) == ascii_tolower(c2);
282 if (found == it->value().end())
285 found += forStr.size();
291 if (pos != std::string_view::npos)
294 return it->value().size() - forStr.size();
301 if (
auto it = request.find(
"X-Forwarded-For"); it != request.end())
305 if (found == boost::string_view::npos)
306 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 newInboundEndpoint(beast::IP::Endpoint const &address)=0
Create a new endpoint keyed by inbound IP address or the forwarded IP if proxied.
virtual Consumer newUnlimitedEndpoint(beast::IP::Endpoint const &address)=0
Create a new unlimited endpoint keyed by forwarded IP.
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.
Resource::Consumer requestInboundEndpoint(Resource::Manager &manager, beast::IP::Endpoint const &remoteAddress, Role const &role, std::string_view user, std::string_view forwardedFor)
static std::string_view extractIpAddrFromField(std::string_view field)
bool isAdmin(Port const &port, Json::Value const ¶ms, beast::IP::Address const &remoteIp)
bool isUnlimited(Role const &role)
ADMIN and IDENTIFIED roles shall have unlimited resources.
std::string_view forwardedFor(http_request_type const &request)
boost::beast::http::request< boost::beast::http::dynamic_body > http_request_type
bool passwordUnrequiredOrSentCorrect(Port const &port, Json::Value const ¶ms)
Role
Indicates the level of administrative permission to grant.
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.
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.
T remove_prefix(T... args)
T remove_suffix(T... args)
Configuration information for a Server listening port.
std::vector< boost::asio::ip::network_v6 > admin_nets_v6
std::vector< boost::asio::ip::network_v6 > secure_gateway_nets_v6
std::vector< boost::asio::ip::network_v4 > secure_gateway_nets_v4
std::string admin_password
std::vector< boost::asio::ip::network_v4 > admin_nets_v4