config option -rpcallowip= to accept json-rpc connections from another machine
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@155 1a98c847-1fd6-4fd8-948a-caf3550aa51b
This commit is contained in:
24
rpc.cpp
24
rpc.cpp
@@ -783,8 +783,9 @@ int ReadHTTPStatus(tcp::iostream& stream)
|
||||
getline(stream, str);
|
||||
vector<string> vWords;
|
||||
boost::split(vWords, str, boost::is_any_of(" "));
|
||||
int nStatus = atoi(vWords[1].c_str());
|
||||
return nStatus;
|
||||
if (vWords.size() < 2)
|
||||
return 500;
|
||||
return atoi(vWords[1].c_str());
|
||||
}
|
||||
|
||||
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";
|
||||
}
|
||||
|
||||
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
|
||||
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);
|
||||
|
||||
loop
|
||||
@@ -976,8 +988,8 @@ void ThreadRPCServer2(void* parg)
|
||||
if (fShutdown)
|
||||
return;
|
||||
|
||||
// Shouldn't be possible for anyone else to connect, but just in case
|
||||
if (peer.address().to_string() != "127.0.0.1")
|
||||
// Restrict callers by IP
|
||||
if (!ClientAllowed(peer.address().to_string()))
|
||||
continue;
|
||||
|
||||
// Receive request
|
||||
@@ -1090,7 +1102,7 @@ Object CallRPC(const string& strMethod, const Array& params)
|
||||
GetConfigFile().c_str()));
|
||||
|
||||
// Connect to localhost
|
||||
tcp::iostream stream("127.0.0.1", "8332");
|
||||
tcp::iostream stream(GetArg("-rpcconnect", "127.0.0.1"), "8332");
|
||||
if (stream.fail())
|
||||
throw runtime_error("couldn't connect to server");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user