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>
33 bool const passwordRequired =
36 return !passwordRequired ||
37 ((params[
"admin_password"].
isString() &&
39 (params[
"admin_user"].isString() &&
52 return ip.is_unspecified() || ip == remoteIp;
72 boost::string_view
const& user)
101 Role const& required,
115 boost::string_view
const& user,
125 static boost::string_view
129 auto trim = [](boost::string_view str) -> boost::string_view {
130 boost::string_view ret = str;
133 if (!ret.empty() && ret.front() ==
' ')
135 std::size_t const firstNonSpace = ret.find_first_not_of(
' ');
136 if (firstNonSpace == boost::string_view::npos)
141 ret = ret.substr(firstNonSpace);
147 if (
unsigned char const c = ret.back();
148 c ==
' ' || c ==
'\r' || c ==
'\n')
150 std::size_t const lastNonSpace = ret.find_last_not_of(
" \r\n");
151 if (lastNonSpace == boost::string_view::npos)
156 ret = ret.substr(0, lastNonSpace + 1);
162 boost::string_view ret = trim(field);
167 if (ret.front() ==
'"')
169 ret.remove_prefix(1);
170 if (ret.empty() || ret.back() !=
'"')
173 ret.remove_suffix(1);
183 if (ret.front() ==
'[')
186 ret.remove_prefix(1);
190 auto const closeBracket =
192 return std::isxdigit(c) || c ==
':' || c ==
'.' || c ==
' ';
197 if (closeBracket == ret.end() || (*closeBracket) !=
']')
201 ret = ret.substr(0, closeBracket - ret.begin());
213 return std::isxdigit(c) || c ==
' ';
218 if (colon == ret.end() || (*colon) ==
':')
224 if (
std::size_t colon = ret.find(
':'); colon != boost::string_view::npos)
225 ret = ret.substr(0, colon);
234 if (
auto it = request.find(boost::beast::http::field::forwarded);
237 auto ascii_tolower = [](
char c) ->
char {
238 return ((
static_cast<unsigned>(c) - 65U) < 26) ? c +
'a' -
'A' : c;
248 [&ascii_tolower](
char c1,
char c2) {
249 return ascii_tolower(c1) == ascii_tolower(c2);
252 if (found == it->value().end())
255 found += forStr.size();
260 boost::string_view(found, it->value().end() - found)
261 .find_first_of(
",;");
262 if (pos != boost::string_view::npos)
265 return it->value().size() - forStr.size();
272 if (
auto it = request.find(
"X-Forwarded-For"); it != request.end())
276 if (found == boost::string_view::npos)
277 found = it->value().length();