mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-22 12:05:53 +00:00
Refactor RPC login.
This commit is contained in:
@@ -168,6 +168,17 @@ Json::Value RPCParser::parseLedger(const Json::Value& jvParams)
|
|||||||
return jvRequest;
|
return jvRequest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// login <username> <password>
|
||||||
|
Json::Value RPCParser::parseLogin(const Json::Value& jvParams)
|
||||||
|
{
|
||||||
|
Json::Value jvRequest(Json::objectValue);
|
||||||
|
|
||||||
|
jvRequest["username"] = jvParams[0u].asString();
|
||||||
|
jvRequest["password"] = jvParams[1u].asString();
|
||||||
|
|
||||||
|
return jvRequest;
|
||||||
|
}
|
||||||
|
|
||||||
// ripple_lines_get <account>|<nickname>|<account_public_key> [<index>]
|
// ripple_lines_get <account>|<nickname>|<account_public_key> [<index>]
|
||||||
Json::Value RPCParser::parseRippleLinesGet(const Json::Value& jvParams)
|
Json::Value RPCParser::parseRippleLinesGet(const Json::Value& jvParams)
|
||||||
{
|
{
|
||||||
@@ -333,7 +344,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
|||||||
{ "ledger_current", &RPCParser::parseAsIs, 0, 0 },
|
{ "ledger_current", &RPCParser::parseAsIs, 0, 0 },
|
||||||
// { "ledger_entry", &RPCParser::parseLedgerEntry, -1, -1, false, false, optCurrent },
|
// { "ledger_entry", &RPCParser::parseLedgerEntry, -1, -1, false, false, optCurrent },
|
||||||
// { "ledger_header", &RPCParser::parseLedgerHeader, -1, -1, false, false, optCurrent },
|
// { "ledger_header", &RPCParser::parseLedgerHeader, -1, -1, false, false, optCurrent },
|
||||||
// { "log_level", &RPCParser::parseLogLevel, 0, 2, true, false, optNone },
|
// { "log_level", &RPCParser::parseLogLevel, 0, 2 },
|
||||||
{ "logrotate", &RPCParser::parseAsIs, 0, 0 },
|
{ "logrotate", &RPCParser::parseAsIs, 0, 0 },
|
||||||
// { "nickname_info", &RPCParser::parseNicknameInfo, 1, 1, false, false, optCurrent },
|
// { "nickname_info", &RPCParser::parseNicknameInfo, 1, 1, false, false, optCurrent },
|
||||||
// { "owner_info", &RPCParser::parseOwnerInfo, 1, 2, false, false, optCurrent },
|
// { "owner_info", &RPCParser::parseOwnerInfo, 1, 2, false, false, optCurrent },
|
||||||
@@ -364,7 +375,7 @@ Json::Value RPCParser::parseCommand(std::string strMethod, Json::Value jvParams)
|
|||||||
{ "wallet_seed", &RPCParser::parseWalletSeed, 0, 1 },
|
{ "wallet_seed", &RPCParser::parseWalletSeed, 0, 1 },
|
||||||
|
|
||||||
// XXX Unnecessary commands which should be removed.
|
// XXX Unnecessary commands which should be removed.
|
||||||
// { "login", &RPCParser::parseLogin, 2, 2, true, false, optNone },
|
{ "login", &RPCParser::parseLogin, 2, 2 },
|
||||||
// { "data_delete", &RPCParser::parseDataDelete, 1, 1, true, false, optNone },
|
// { "data_delete", &RPCParser::parseDataDelete, 1, 1, true, false, optNone },
|
||||||
// { "data_fetch", &RPCParser::parseDataFetch, 1, 1, true, false, optNone },
|
// { "data_fetch", &RPCParser::parseDataFetch, 1, 1, true, false, optNone },
|
||||||
// { "data_store", &RPCParser::parseDataStore, 2, 2, true, false, optNone },
|
// { "data_store", &RPCParser::parseDataStore, 2, 2, true, false, optNone },
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ protected:
|
|||||||
Json::Value parseEvented(const Json::Value& jvParams);
|
Json::Value parseEvented(const Json::Value& jvParams);
|
||||||
Json::Value parseGetCounts(const Json::Value& jvParams);
|
Json::Value parseGetCounts(const Json::Value& jvParams);
|
||||||
Json::Value parseLedger(const Json::Value& jvParams);
|
Json::Value parseLedger(const Json::Value& jvParams);
|
||||||
|
Json::Value parseLogin(const Json::Value& jvParams);
|
||||||
Json::Value parseRippleLinesGet(const Json::Value& jvParams);
|
Json::Value parseRippleLinesGet(const Json::Value& jvParams);
|
||||||
Json::Value parseSubmit(const Json::Value& jvParams);
|
Json::Value parseSubmit(const Json::Value& jvParams);
|
||||||
Json::Value parseUnlAdd(const Json::Value& jvParams);
|
Json::Value parseUnlAdd(const Json::Value& jvParams);
|
||||||
|
|||||||
@@ -1438,12 +1438,13 @@ Json::Value RPCHandler::doWalletSeed(Json::Value jvRequest)
|
|||||||
// TODO: for now this simply checks if this is the admin account
|
// TODO: for now this simply checks if this is the admin account
|
||||||
// TODO: need to prevent them hammering this over and over
|
// TODO: need to prevent them hammering this over and over
|
||||||
// TODO: maybe a better way is only allow admin from local host
|
// TODO: maybe a better way is only allow admin from local host
|
||||||
Json::Value RPCHandler::doLogin(Json::Value params)
|
// {
|
||||||
|
// username: <string>,
|
||||||
|
// password: <string>
|
||||||
|
// }
|
||||||
|
Json::Value RPCHandler::doLogin(Json::Value jvRequest)
|
||||||
{
|
{
|
||||||
std::string username = params[0u].asString();
|
if (jvRequest["username"].asString() == theConfig.RPC_USER && jvRequest["password"].asString() == theConfig.RPC_PASSWORD)
|
||||||
std::string password = params[1u].asString();
|
|
||||||
|
|
||||||
if (username == theConfig.RPC_USER && password == theConfig.RPC_PASSWORD)
|
|
||||||
{
|
{
|
||||||
//mRole=ADMIN;
|
//mRole=ADMIN;
|
||||||
return "logged in";
|
return "logged in";
|
||||||
@@ -1476,6 +1477,7 @@ Json::Value RPCHandler::doGetCounts(Json::Value jvRequest)
|
|||||||
|
|
||||||
Json::Value RPCHandler::doLogLevel(Json::Value params)
|
Json::Value RPCHandler::doLogLevel(Json::Value params)
|
||||||
{
|
{
|
||||||
|
// log_level
|
||||||
if (params.size() == 0)
|
if (params.size() == 0)
|
||||||
{ // get log severities
|
{ // get log severities
|
||||||
Json::Value ret = Json::objectValue;
|
Json::Value ret = Json::objectValue;
|
||||||
@@ -1486,27 +1488,35 @@ Json::Value RPCHandler::doLogLevel(Json::Value params)
|
|||||||
typedef std::pair<std::string, std::string> stringPair;
|
typedef std::pair<std::string, std::string> stringPair;
|
||||||
BOOST_FOREACH(const stringPair& it, logTable)
|
BOOST_FOREACH(const stringPair& it, logTable)
|
||||||
ret[it.first] = it.second;
|
ret[it.first] = it.second;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// log_level severity
|
||||||
if (params.size() == 1)
|
if (params.size() == 1)
|
||||||
{ // set base log severity
|
{ // set base log severity
|
||||||
LogSeverity sv = Log::stringToSeverity(params[0u].asString());
|
LogSeverity sv = Log::stringToSeverity(params[0u].asString());
|
||||||
if (sv == lsINVALID)
|
if (sv == lsINVALID)
|
||||||
return rpcError(rpcINVALID_PARAMS);
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
Log::setMinSeverity(sv,true);
|
Log::setMinSeverity(sv,true);
|
||||||
|
|
||||||
return rpcError(rpcSUCCESS);
|
return rpcError(rpcSUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// log_level partition severity base?
|
||||||
if (params.size() == 2)
|
if (params.size() == 2)
|
||||||
{ // set partition severity
|
{ // set partition severity
|
||||||
LogSeverity sv = Log::stringToSeverity(params[1u].asString());
|
LogSeverity sv = Log::stringToSeverity(params[1u].asString());
|
||||||
|
|
||||||
if (sv == lsINVALID)
|
if (sv == lsINVALID)
|
||||||
return rpcError(rpcINVALID_PARAMS);
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
if (params[2u].asString() == "base")
|
if (params[2u].asString() == "base")
|
||||||
Log::setMinSeverity(sv,false);
|
Log::setMinSeverity(sv,false);
|
||||||
else if (!LogPartition::setSeverity(params[0u].asString(), sv))
|
else if (!LogPartition::setSeverity(params[0u].asString(), sv))
|
||||||
return rpcError(rpcINVALID_PARAMS);
|
return rpcError(rpcINVALID_PARAMS);
|
||||||
|
|
||||||
return rpcError(rpcSUCCESS);
|
return rpcError(rpcSUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2228,7 +2238,7 @@ Json::Value RPCHandler::doCommand(Json::Value& jvParams, int iRole)
|
|||||||
{ "wallet_seed", &RPCHandler::doWalletSeed, -1, -1, false, false, optNone },
|
{ "wallet_seed", &RPCHandler::doWalletSeed, -1, -1, false, false, optNone },
|
||||||
|
|
||||||
// XXX Unnecessary commands which should be removed.
|
// XXX Unnecessary commands which should be removed.
|
||||||
{ "login", &RPCHandler::doLogin, 2, 2, true, false, optNone },
|
{ "login", &RPCHandler::doLogin, -1, -1, true, false, optNone },
|
||||||
{ "data_delete", &RPCHandler::doDataDelete, 1, 1, true, false, optNone },
|
{ "data_delete", &RPCHandler::doDataDelete, 1, 1, true, false, optNone },
|
||||||
{ "data_fetch", &RPCHandler::doDataFetch, 1, 1, true, false, optNone },
|
{ "data_fetch", &RPCHandler::doDataFetch, 1, 1, true, false, optNone },
|
||||||
{ "data_store", &RPCHandler::doDataStore, 2, 2, true, false, optNone },
|
{ "data_store", &RPCHandler::doDataStore, 2, 2, true, false, optNone },
|
||||||
|
|||||||
Reference in New Issue
Block a user