mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-02-08 21:04:14 +00:00
Merge pull request #183 from digital-dreamer/public-server
Public server mode
This commit is contained in:
commit
6d1e5a40b1
@ -195,74 +195,74 @@ Value stop(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
|
|
||||||
static const CRPCCommand vRPCCommands[] =
|
static const CRPCCommand vRPCCommands[] =
|
||||||
{ // name actor (function) okSafeMode threadSafe
|
{ // name actor (function) okSafeMode threadSafe allowOnPublicServer
|
||||||
// ------------------------ ----------------------- ---------- ----------
|
// ------------------------ ----------------------- ---------- ---------- -------------------
|
||||||
{ "help", &help, true, true },
|
{ "help", &help, true, true, true },
|
||||||
{ "stop", &stop, true, true },
|
{ "stop", &stop, true, true, false },
|
||||||
{ "getblockcount", &getblockcount, true, false },
|
{ "getblockcount", &getblockcount, true, false, false },
|
||||||
{ "getbestblockhash", &getbestblockhash, true, false },
|
{ "getbestblockhash", &getbestblockhash, true, false, true },
|
||||||
{ "getconnectioncount", &getconnectioncount, true, false },
|
{ "getconnectioncount", &getconnectioncount, true, false, false },
|
||||||
{ "getpeerinfo", &getpeerinfo, true, false },
|
{ "getpeerinfo", &getpeerinfo, true, false, false },
|
||||||
{ "addnode", &addnode, true, true },
|
{ "addnode", &addnode, true, true, false },
|
||||||
{ "adddnsseed", &adddnsseed, true, true },
|
{ "adddnsseed", &adddnsseed, true, true, false },
|
||||||
{ "getaddednodeinfo", &getaddednodeinfo, true, true },
|
{ "getaddednodeinfo", &getaddednodeinfo, true, true, false },
|
||||||
{ "getdifficulty", &getdifficulty, true, false },
|
{ "getdifficulty", &getdifficulty, true, false, false },
|
||||||
{ "getgenerate", &getgenerate, true, false },
|
{ "getgenerate", &getgenerate, true, false, false },
|
||||||
{ "setgenerate", &setgenerate, true, false },
|
{ "setgenerate", &setgenerate, true, false, false },
|
||||||
{ "gethashespersec", &gethashespersec, true, false },
|
{ "gethashespersec", &gethashespersec, true, false, false },
|
||||||
{ "getinfo", &getinfo, true, true },
|
{ "getinfo", &getinfo, true, true, true },
|
||||||
{ "getmininginfo", &getmininginfo, true, false },
|
{ "getmininginfo", &getmininginfo, true, false, false },
|
||||||
{ "createwalletuser", &createwalletuser, true, false },
|
{ "createwalletuser", &createwalletuser, true, false, false },
|
||||||
{ "listwalletusers", &listwalletusers, true, false },
|
{ "listwalletusers", &listwalletusers, true, false, true },
|
||||||
{ "backupwallet", &backupwallet, true, false },
|
{ "backupwallet", &backupwallet, true, false, false },
|
||||||
{ "walletpassphrase", &walletpassphrase, true, false },
|
{ "walletpassphrase", &walletpassphrase, true, false, false },
|
||||||
{ "walletpassphrasechange", &walletpassphrasechange, false, false },
|
{ "walletpassphrasechange", &walletpassphrasechange, false, false, false },
|
||||||
{ "walletlock", &walletlock, true, false },
|
{ "walletlock", &walletlock, true, false, false },
|
||||||
{ "encryptwallet", &encryptwallet, false, false },
|
{ "encryptwallet", &encryptwallet, false, false, false },
|
||||||
{ "getrawmempool", &getrawmempool, true, false },
|
{ "getrawmempool", &getrawmempool, true, false, false },
|
||||||
{ "getblock", &getblock, false, false },
|
{ "getblock", &getblock, false, false, true },
|
||||||
{ "getblockhash", &getblockhash, false, false },
|
{ "getblockhash", &getblockhash, false, false, false },
|
||||||
{ "gettransaction", &gettransaction, false, false },
|
{ "gettransaction", &gettransaction, false, false, false },
|
||||||
{ "listtransactions", &listtransactions, false, false },
|
{ "listtransactions", &listtransactions, false, false, false },
|
||||||
{ "signmessage", &signmessage, false, false },
|
{ "signmessage", &signmessage, false, false, false },
|
||||||
{ "verifymessage", &verifymessage, false, false },
|
{ "verifymessage", &verifymessage, false, false, false },
|
||||||
{ "getwork", &getwork, true, false },
|
{ "getwork", &getwork, true, false, false },
|
||||||
{ "getblocktemplate", &getblocktemplate, true, false },
|
{ "getblocktemplate", &getblocktemplate, true, false, false },
|
||||||
{ "submitblock", &submitblock, false, false },
|
{ "submitblock", &submitblock, false, false, false },
|
||||||
{ "listsinceblock", &listsinceblock, false, false },
|
{ "listsinceblock", &listsinceblock, false, false, false },
|
||||||
{ "dumpprivkey", &dumpprivkey, true, false },
|
{ "dumpprivkey", &dumpprivkey, true, false, false },
|
||||||
{ "dumppubkey", &dumppubkey, false, false },
|
{ "dumppubkey", &dumppubkey, false, false, false },
|
||||||
{ "dumpwallet", &dumpwallet, true, false },
|
{ "dumpwallet", &dumpwallet, true, false, false },
|
||||||
{ "importprivkey", &importprivkey, false, false },
|
{ "importprivkey", &importprivkey, false, false, false },
|
||||||
{ "importwallet", &importwallet, false, false },
|
{ "importwallet", &importwallet, false, false, false },
|
||||||
{ "getrawtransaction", &getrawtransaction, false, false },
|
{ "getrawtransaction", &getrawtransaction, false, false, false },
|
||||||
{ "createrawtransaction", &createrawtransaction, false, false },
|
{ "createrawtransaction", &createrawtransaction, false, false, false },
|
||||||
{ "decoderawtransaction", &decoderawtransaction, false, false },
|
{ "decoderawtransaction", &decoderawtransaction, false, false, false },
|
||||||
{ "sendrawtransaction", &sendrawtransaction, false, false },
|
{ "sendrawtransaction", &sendrawtransaction, false, false, false },
|
||||||
{ "sendnewusertransaction", &sendnewusertransaction, false, false },
|
{ "sendnewusertransaction", &sendnewusertransaction, false, false, false },
|
||||||
{ "verifychain", &verifychain, true, false },
|
{ "verifychain", &verifychain, true, false, false },
|
||||||
{ "getlastsoftcheckpoint", &getlastsoftcheckpoint, true, false },
|
{ "getlastsoftcheckpoint", &getlastsoftcheckpoint, true, false, false },
|
||||||
// twister dht network
|
// twister dht network
|
||||||
{ "dhtput", &dhtput, false, true },
|
{ "dhtput", &dhtput, false, true, false },
|
||||||
{ "dhtget", &dhtget, false, true },
|
{ "dhtget", &dhtget, false, true, true },
|
||||||
{ "newpostmsg", &newpostmsg, false, true },
|
{ "newpostmsg", &newpostmsg, false, true, false },
|
||||||
{ "newdirectmsg", &newdirectmsg, false, true },
|
{ "newdirectmsg", &newdirectmsg, false, true, false },
|
||||||
{ "newrtmsg", &newrtmsg, false, true },
|
{ "newrtmsg", &newrtmsg, false, true, false },
|
||||||
{ "getposts", &getposts, false, true },
|
{ "getposts", &getposts, false, true, false },
|
||||||
{ "getdirectmsgs", &getdirectmsgs, false, true },
|
{ "getdirectmsgs", &getdirectmsgs, false, true, false },
|
||||||
{ "setspammsg", &setspammsg, false, false },
|
{ "setspammsg", &setspammsg, false, false, false },
|
||||||
{ "getspammsg", &getspammsg, false, false },
|
{ "getspammsg", &getspammsg, false, false, false },
|
||||||
{ "follow", &follow, false, true },
|
{ "follow", &follow, false, true, false },
|
||||||
{ "unfollow", &unfollow, false, true },
|
{ "unfollow", &unfollow, false, true, false },
|
||||||
{ "getfollowing", &getfollowing, false, true },
|
{ "getfollowing", &getfollowing, false, true, false },
|
||||||
{ "getlasthave", &getlasthave, false, true },
|
{ "getlasthave", &getlasthave, false, true, false },
|
||||||
{ "getnumpieces", &getnumpieces, false, true },
|
{ "getnumpieces", &getnumpieces, false, true, false },
|
||||||
{ "listusernamespartial", &listusernamespartial, false, true },
|
{ "listusernamespartial", &listusernamespartial, false, true, true },
|
||||||
{ "rescandirectmsgs", &rescandirectmsgs, false, true },
|
{ "rescandirectmsgs", &rescandirectmsgs, false, true, false },
|
||||||
{ "recheckusertorrent", &recheckusertorrent, false, true },
|
{ "recheckusertorrent", &recheckusertorrent, false, true, false },
|
||||||
{ "gettrendinghashtags", &gettrendinghashtags, false, true },
|
{ "gettrendinghashtags", &gettrendinghashtags, false, true, true },
|
||||||
{ "getspamposts", &getspamposts, false, true },
|
{ "getspamposts", &getspamposts, false, true, false },
|
||||||
{ "torrentstatus", &torrentstatus, false, true },
|
{ "torrentstatus", &torrentstatus, false, true, false },
|
||||||
};
|
};
|
||||||
|
|
||||||
CRPCTable::CRPCTable()
|
CRPCTable::CRPCTable()
|
||||||
@ -989,6 +989,9 @@ void ServiceConnection(AcceptedConnection *conn)
|
|||||||
// Read HTTP message headers and body
|
// Read HTTP message headers and body
|
||||||
ReadHTTPMessage(conn->stream(), mapHeaders, strRequest, nProto);
|
ReadHTTPMessage(conn->stream(), mapHeaders, strRequest, nProto);
|
||||||
|
|
||||||
|
if(strMethod == "GET" && strURI == "/")
|
||||||
|
strURI="/home.html";
|
||||||
|
|
||||||
if (strURI != "/" && strURI.find("..") == std::string::npos ) {
|
if (strURI != "/" && strURI.find("..") == std::string::npos ) {
|
||||||
filesystem::path pathFile = filesystem::path(GetHTMLDir()) / strURI;
|
filesystem::path pathFile = filesystem::path(GetHTMLDir()) / strURI;
|
||||||
std::string fname = pathFile.string();
|
std::string fname = pathFile.string();
|
||||||
@ -1093,6 +1096,9 @@ json_spirit::Value CRPCTable::execute(const std::string &strMethod, const json_s
|
|||||||
const CRPCCommand *pcmd = tableRPC[strMethod];
|
const CRPCCommand *pcmd = tableRPC[strMethod];
|
||||||
if (!pcmd)
|
if (!pcmd)
|
||||||
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
|
throw JSONRPCError(RPC_METHOD_NOT_FOUND, "Method not found");
|
||||||
|
|
||||||
|
if(!pcmd->allowOnPublicServer && GetBoolArg("-public_server_mode",false))
|
||||||
|
throw JSONRPCError(RPC_FORBIDDEN_ON_PUBLIC_SERVER, "Forbidden: accessing this method is not allowed on a public server");
|
||||||
|
|
||||||
// Observe safe mode
|
// Observe safe mode
|
||||||
string strWarning = GetWarnings("rpc");
|
string strWarning = GetWarnings("rpc");
|
||||||
|
@ -48,6 +48,7 @@ enum RPCErrorCode
|
|||||||
RPC_INVALID_PARAMETER = -8, // Invalid, missing or duplicate parameter
|
RPC_INVALID_PARAMETER = -8, // Invalid, missing or duplicate parameter
|
||||||
RPC_DATABASE_ERROR = -20, // Database error
|
RPC_DATABASE_ERROR = -20, // Database error
|
||||||
RPC_DESERIALIZATION_ERROR = -22, // Error parsing or validating structure in raw format
|
RPC_DESERIALIZATION_ERROR = -22, // Error parsing or validating structure in raw format
|
||||||
|
RPC_FORBIDDEN_ON_PUBLIC_SERVER = -23, // public server mode is activated, this method is not allowed
|
||||||
|
|
||||||
// P2P client errors
|
// P2P client errors
|
||||||
RPC_CLIENT_NOT_CONNECTED = -9, // Bitcoin is not connected
|
RPC_CLIENT_NOT_CONNECTED = -9, // Bitcoin is not connected
|
||||||
@ -103,6 +104,7 @@ public:
|
|||||||
rpcfn_type actor;
|
rpcfn_type actor;
|
||||||
bool okSafeMode;
|
bool okSafeMode;
|
||||||
bool threadSafe;
|
bool threadSafe;
|
||||||
|
bool allowOnPublicServer;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -96,6 +96,7 @@ Value getinfo(const Array& params, bool fHelp)
|
|||||||
if (pwalletMain->IsCrypted())
|
if (pwalletMain->IsCrypted())
|
||||||
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
|
obj.push_back(Pair("unlocked_until", (boost::int64_t)nWalletUnlockTime));
|
||||||
}
|
}
|
||||||
|
obj.push_back(Pair("public_server_mode", GetBoolArg("-public_server_mode",false)));
|
||||||
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
obj.push_back(Pair("errors", GetWarnings("statusbar")));
|
||||||
}
|
}
|
||||||
return obj;
|
return obj;
|
||||||
@ -155,6 +156,11 @@ Value listwalletusers(const Array& params, bool fHelp)
|
|||||||
|
|
||||||
// Find all addresses that have the given account
|
// Find all addresses that have the given account
|
||||||
Array ret;
|
Array ret;
|
||||||
|
|
||||||
|
// Always return an empty array on a public server
|
||||||
|
if(GetBoolArg("-public_server_mode",false))
|
||||||
|
return ret;
|
||||||
|
|
||||||
LOCK(pwalletMain->cs_wallet);
|
LOCK(pwalletMain->cs_wallet);
|
||||||
BOOST_FOREACH(const PAIRTYPE(CKeyID, CKeyMetadata)& item, pwalletMain->mapKeyMetadata)
|
BOOST_FOREACH(const PAIRTYPE(CKeyID, CKeyMetadata)& item, pwalletMain->mapKeyMetadata)
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user