From b1ace5cc691dba47f195a012c3d3eaa823682ba4 Mon Sep 17 00:00:00 2001 From: digital dreamer Date: Mon, 7 Apr 2014 12:45:51 +0200 Subject: [PATCH] add public server mode --- src/bitcoinrpc.cpp | 140 +++++++++++++++++++++++---------------------- src/bitcoinrpc.h | 2 + src/rpcwallet.cpp | 6 ++ 3 files changed, 81 insertions(+), 67 deletions(-) diff --git a/src/bitcoinrpc.cpp b/src/bitcoinrpc.cpp index e709321c..66c103b0 100644 --- a/src/bitcoinrpc.cpp +++ b/src/bitcoinrpc.cpp @@ -195,74 +195,74 @@ Value stop(const Array& params, bool fHelp) static const CRPCCommand vRPCCommands[] = -{ // name actor (function) okSafeMode threadSafe - // ------------------------ ----------------------- ---------- ---------- - { "help", &help, true, true }, - { "stop", &stop, true, true }, - { "getblockcount", &getblockcount, true, false }, - { "getbestblockhash", &getbestblockhash, true, false }, - { "getconnectioncount", &getconnectioncount, true, false }, - { "getpeerinfo", &getpeerinfo, true, false }, - { "addnode", &addnode, true, true }, - { "adddnsseed", &adddnsseed, true, true }, - { "getaddednodeinfo", &getaddednodeinfo, true, true }, - { "getdifficulty", &getdifficulty, true, false }, - { "getgenerate", &getgenerate, true, false }, - { "setgenerate", &setgenerate, true, false }, - { "gethashespersec", &gethashespersec, true, false }, - { "getinfo", &getinfo, true, true }, - { "getmininginfo", &getmininginfo, true, false }, - { "createwalletuser", &createwalletuser, true, false }, - { "listwalletusers", &listwalletusers, true, false }, - { "backupwallet", &backupwallet, true, false }, - { "walletpassphrase", &walletpassphrase, true, false }, - { "walletpassphrasechange", &walletpassphrasechange, false, false }, - { "walletlock", &walletlock, true, false }, - { "encryptwallet", &encryptwallet, false, false }, - { "getrawmempool", &getrawmempool, true, false }, - { "getblock", &getblock, false, false }, - { "getblockhash", &getblockhash, false, false }, - { "gettransaction", &gettransaction, false, false }, - { "listtransactions", &listtransactions, false, false }, - { "signmessage", &signmessage, false, false }, - { "verifymessage", &verifymessage, false, false }, - { "getwork", &getwork, true, false }, - { "getblocktemplate", &getblocktemplate, true, false }, - { "submitblock", &submitblock, false, false }, - { "listsinceblock", &listsinceblock, false, false }, - { "dumpprivkey", &dumpprivkey, true, false }, - { "dumppubkey", &dumppubkey, false, false }, - { "dumpwallet", &dumpwallet, true, false }, - { "importprivkey", &importprivkey, false, false }, - { "importwallet", &importwallet, false, false }, - { "getrawtransaction", &getrawtransaction, false, false }, - { "createrawtransaction", &createrawtransaction, false, false }, - { "decoderawtransaction", &decoderawtransaction, false, false }, - { "sendrawtransaction", &sendrawtransaction, false, false }, - { "sendnewusertransaction", &sendnewusertransaction, false, false }, - { "verifychain", &verifychain, true, false }, - { "getlastsoftcheckpoint", &getlastsoftcheckpoint, true, false }, +{ // name actor (function) okSafeMode threadSafe allowOnPublicServer + // ------------------------ ----------------------- ---------- ---------- ------------------- + { "help", &help, true, true, true }, + { "stop", &stop, true, true, false }, + { "getblockcount", &getblockcount, true, false, false }, + { "getbestblockhash", &getbestblockhash, true, false, true }, + { "getconnectioncount", &getconnectioncount, true, false, false }, + { "getpeerinfo", &getpeerinfo, true, false, false }, + { "addnode", &addnode, true, true, false }, + { "adddnsseed", &adddnsseed, true, true, false }, + { "getaddednodeinfo", &getaddednodeinfo, true, true, false }, + { "getdifficulty", &getdifficulty, true, false, false }, + { "getgenerate", &getgenerate, true, false, false }, + { "setgenerate", &setgenerate, true, false, false }, + { "gethashespersec", &gethashespersec, true, false, false }, + { "getinfo", &getinfo, true, true, true }, + { "getmininginfo", &getmininginfo, true, false, false }, + { "createwalletuser", &createwalletuser, true, false, false }, + { "listwalletusers", &listwalletusers, true, false, true }, + { "backupwallet", &backupwallet, true, false, false }, + { "walletpassphrase", &walletpassphrase, true, false, false }, + { "walletpassphrasechange", &walletpassphrasechange, false, false, false }, + { "walletlock", &walletlock, true, false, false }, + { "encryptwallet", &encryptwallet, false, false, false }, + { "getrawmempool", &getrawmempool, true, false, false }, + { "getblock", &getblock, false, false, true }, + { "getblockhash", &getblockhash, false, false, false }, + { "gettransaction", &gettransaction, false, false, false }, + { "listtransactions", &listtransactions, false, false, false }, + { "signmessage", &signmessage, false, false, false }, + { "verifymessage", &verifymessage, false, false, false }, + { "getwork", &getwork, true, false, false }, + { "getblocktemplate", &getblocktemplate, true, false, false }, + { "submitblock", &submitblock, false, false, false }, + { "listsinceblock", &listsinceblock, false, false, false }, + { "dumpprivkey", &dumpprivkey, true, false, false }, + { "dumppubkey", &dumppubkey, false, false, false }, + { "dumpwallet", &dumpwallet, true, false, false }, + { "importprivkey", &importprivkey, false, false, false }, + { "importwallet", &importwallet, false, false, false }, + { "getrawtransaction", &getrawtransaction, false, false, false }, + { "createrawtransaction", &createrawtransaction, false, false, false }, + { "decoderawtransaction", &decoderawtransaction, false, false, false }, + { "sendrawtransaction", &sendrawtransaction, false, false, false }, + { "sendnewusertransaction", &sendnewusertransaction, false, false, false }, + { "verifychain", &verifychain, true, false, false }, + { "getlastsoftcheckpoint", &getlastsoftcheckpoint, true, false, false }, // twister dht network - { "dhtput", &dhtput, false, true }, - { "dhtget", &dhtget, false, true }, - { "newpostmsg", &newpostmsg, false, true }, - { "newdirectmsg", &newdirectmsg, false, true }, - { "newrtmsg", &newrtmsg, false, true }, - { "getposts", &getposts, false, true }, - { "getdirectmsgs", &getdirectmsgs, false, true }, - { "setspammsg", &setspammsg, false, false }, - { "getspammsg", &getspammsg, false, false }, - { "follow", &follow, false, true }, - { "unfollow", &unfollow, false, true }, - { "getfollowing", &getfollowing, false, true }, - { "getlasthave", &getlasthave, false, true }, - { "getnumpieces", &getnumpieces, false, true }, - { "listusernamespartial", &listusernamespartial, false, true }, - { "rescandirectmsgs", &rescandirectmsgs, false, true }, - { "recheckusertorrent", &recheckusertorrent, false, true }, - { "gettrendinghashtags", &gettrendinghashtags, false, true }, - { "getspamposts", &getspamposts, false, true }, - { "torrentstatus", &torrentstatus, false, true }, + { "dhtput", &dhtput, false, true, false }, + { "dhtget", &dhtget, false, true, true }, + { "newpostmsg", &newpostmsg, false, true, false }, + { "newdirectmsg", &newdirectmsg, false, true, false }, + { "newrtmsg", &newrtmsg, false, true, false }, + { "getposts", &getposts, false, true, false }, + { "getdirectmsgs", &getdirectmsgs, false, true, false }, + { "setspammsg", &setspammsg, false, false, false }, + { "getspammsg", &getspammsg, false, false, false }, + { "follow", &follow, false, true, false }, + { "unfollow", &unfollow, false, true, false }, + { "getfollowing", &getfollowing, false, true, false }, + { "getlasthave", &getlasthave, false, true, false }, + { "getnumpieces", &getnumpieces, false, true, false }, + { "listusernamespartial", &listusernamespartial, false, true, true }, + { "rescandirectmsgs", &rescandirectmsgs, false, true, false }, + { "recheckusertorrent", &recheckusertorrent, false, true, false }, + { "gettrendinghashtags", &gettrendinghashtags, false, true, true }, + { "getspamposts", &getspamposts, false, true, false }, + { "torrentstatus", &torrentstatus, false, true, false }, }; CRPCTable::CRPCTable() @@ -989,6 +989,9 @@ void ServiceConnection(AcceptedConnection *conn) // Read HTTP message headers and body ReadHTTPMessage(conn->stream(), mapHeaders, strRequest, nProto); + if(strMethod == "GET" && strURI == "/") + strURI="/home.html"; + if (strURI != "/" && strURI.find("..") == std::string::npos ) { filesystem::path pathFile = filesystem::path(GetHTMLDir()) / strURI; 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]; if (!pcmd) 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 string strWarning = GetWarnings("rpc"); diff --git a/src/bitcoinrpc.h b/src/bitcoinrpc.h index 7d25e219..b0822e06 100644 --- a/src/bitcoinrpc.h +++ b/src/bitcoinrpc.h @@ -48,6 +48,7 @@ enum RPCErrorCode RPC_INVALID_PARAMETER = -8, // Invalid, missing or duplicate parameter RPC_DATABASE_ERROR = -20, // Database error 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 RPC_CLIENT_NOT_CONNECTED = -9, // Bitcoin is not connected @@ -103,6 +104,7 @@ public: rpcfn_type actor; bool okSafeMode; bool threadSafe; + bool allowOnPublicServer; }; /** diff --git a/src/rpcwallet.cpp b/src/rpcwallet.cpp index 12de4bd9..31311139 100644 --- a/src/rpcwallet.cpp +++ b/src/rpcwallet.cpp @@ -96,6 +96,7 @@ Value getinfo(const Array& params, bool fHelp) if (pwalletMain->IsCrypted()) 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"))); } return obj; @@ -155,6 +156,11 @@ Value listwalletusers(const Array& params, bool fHelp) // Find all addresses that have the given account Array ret; + + // Always return an empty array on a public server + if(GetBoolArg("-public_server_mode",false)) + return ret; + LOCK(pwalletMain->cs_wallet); BOOST_FOREACH(const PAIRTYPE(CKeyID, CKeyMetadata)& item, pwalletMain->mapKeyMetadata) {