|
|
@ -783,8 +783,9 @@ int ReadHTTPStatus(tcp::iostream& stream) |
|
|
|
getline(stream, str); |
|
|
|
getline(stream, str); |
|
|
|
vector<string> vWords; |
|
|
|
vector<string> vWords; |
|
|
|
boost::split(vWords, str, boost::is_any_of(" ")); |
|
|
|
boost::split(vWords, str, boost::is_any_of(" ")); |
|
|
|
int nStatus = atoi(vWords[1].c_str()); |
|
|
|
if (vWords.size() < 2) |
|
|
|
return nStatus; |
|
|
|
return 500; |
|
|
|
|
|
|
|
return atoi(vWords[1].c_str()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
int ReadHTTPHeader(tcp::iostream& stream, map<string, string>& mapHeadersRet) |
|
|
|
int ReadHTTPHeader(tcp::iostream& stream, map<string, string>& mapHeadersRet) |
|
|
@ -918,6 +919,17 @@ string JSONRPCReply(const Value& result, const Value& error, const Value& id) |
|
|
|
return write_string(Value(reply), false) + "\n"; |
|
|
|
return write_string(Value(reply), false) + "\n"; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool ClientAllowed(const string& strAddress) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (strAddress == asio::ip::address_v4::loopback().to_string()) |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
const vector<string>& vAllow = mapMultiArgs["-rpcallowip"]; |
|
|
|
|
|
|
|
foreach(string strAllow, vAllow) |
|
|
|
|
|
|
|
if (WildcardMatch(strAddress, strAllow)) |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
return false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -962,7 +974,7 @@ void ThreadRPCServer2(void* parg) |
|
|
|
|
|
|
|
|
|
|
|
// Bind to loopback 127.0.0.1 so the socket can only be accessed locally
|
|
|
|
// Bind to loopback 127.0.0.1 so the socket can only be accessed locally
|
|
|
|
boost::asio::io_service io_service; |
|
|
|
boost::asio::io_service io_service; |
|
|
|
tcp::endpoint endpoint(boost::asio::ip::address_v4::loopback(), 8332); |
|
|
|
tcp::endpoint endpoint(mapArgs.count("-rpcallowip") ? asio::ip::address_v4::any() : asio::ip::address_v4::loopback(), 8332); |
|
|
|
tcp::acceptor acceptor(io_service, endpoint); |
|
|
|
tcp::acceptor acceptor(io_service, endpoint); |
|
|
|
|
|
|
|
|
|
|
|
loop |
|
|
|
loop |
|
|
@ -976,8 +988,8 @@ void ThreadRPCServer2(void* parg) |
|
|
|
if (fShutdown) |
|
|
|
if (fShutdown) |
|
|
|
return; |
|
|
|
return; |
|
|
|
|
|
|
|
|
|
|
|
// Shouldn't be possible for anyone else to connect, but just in case
|
|
|
|
// Restrict callers by IP
|
|
|
|
if (peer.address().to_string() != "127.0.0.1") |
|
|
|
if (!ClientAllowed(peer.address().to_string())) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
// Receive request
|
|
|
|
// Receive request
|
|
|
@ -1090,7 +1102,7 @@ Object CallRPC(const string& strMethod, const Array& params) |
|
|
|
GetConfigFile().c_str())); |
|
|
|
GetConfigFile().c_str())); |
|
|
|
|
|
|
|
|
|
|
|
// Connect to localhost
|
|
|
|
// Connect to localhost
|
|
|
|
tcp::iostream stream("127.0.0.1", "8332"); |
|
|
|
tcp::iostream stream(GetArg("-rpcconnect", "127.0.0.1"), "8332"); |
|
|
|
if (stream.fail()) |
|
|
|
if (stream.fail()) |
|
|
|
throw runtime_error("couldn't connect to server"); |
|
|
|
throw runtime_error("couldn't connect to server"); |
|
|
|
|
|
|
|
|
|
|
|