20 #include <ripple/rpc/Role.h>
21 #include <boost/beast/core/string.hpp>
22 #include <boost/beast/http/field.hpp>
23 #include <boost/beast/http/rfc7230.hpp>
24 #include <boost/utility/string_view.hpp>
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)
99 boost::string_view
const& user)
131 Role const& required,
145 boost::string_view
const& user,
155 static boost::string_view
159 auto trim = [](boost::string_view str) -> boost::string_view {
160 boost::string_view ret = str;
163 if (!ret.empty() && ret.front() ==
' ')
165 std::size_t const firstNonSpace = ret.find_first_not_of(
' ');
166 if (firstNonSpace == boost::string_view::npos)
171 ret = ret.substr(firstNonSpace);
177 if (
unsigned char const c = ret.back();
178 c ==
' ' || c ==
'\r' || c ==
'\n')
180 std::size_t const lastNonSpace = ret.find_last_not_of(
" \r\n");
181 if (lastNonSpace == boost::string_view::npos)
186 ret = ret.substr(0, lastNonSpace + 1);
192 boost::string_view ret = trim(field);
197 if (ret.front() ==
'"')
199 ret.remove_prefix(1);
200 if (ret.empty() || ret.back() !=
'"')
203 ret.remove_suffix(1);
213 if (ret.front() ==
'[')
216 ret.remove_prefix(1);
220 auto const closeBracket =
222 return std::isxdigit(c) || c ==
':' || c ==
'.' || c ==
' ';
227 if (closeBracket == ret.end() || (*closeBracket) !=
']')
231 ret = ret.substr(0, closeBracket - ret.begin());
243 return std::isxdigit(c) || c ==
' ';
248 if (colon == ret.end() || (*colon) ==
':')
254 if (
std::size_t colon = ret.find(
':'); colon != boost::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();
290 boost::string_view(found, it->value().end() - found)
291 .find_first_of(
",;");
292 if (pos != boost::string_view::npos)
295 return it->value().size() - forStr.size();
302 if (
auto it = request.find(
"X-Forwarded-For"); it != request.end())
306 if (found == boost::string_view::npos)
307 found = it->value().length();