diff options
author | Riccardo Spagni <ric@spagni.net> | 2017-10-31 20:38:38 +0200 |
---|---|---|
committer | Riccardo Spagni <ric@spagni.net> | 2017-10-31 20:38:38 +0200 |
commit | 54463b33b3169f9d1ed6aefcc321e3715c066bd5 (patch) | |
tree | cd111785fb782181d7a9eebda0a80f53f2587ad3 /src | |
parent | Merge pull request #2711 (diff) | |
parent | RPC Add cross origin resource sharing support (diff) | |
download | monero-54463b33b3169f9d1ed6aefcc321e3715c066bd5.tar.xz |
Merge pull request #2723
69c37200 RPC Add cross origin resource sharing support (Tim L)
Diffstat (limited to 'src')
-rwxr-xr-x[-rw-r--r--] | src/rpc/core_rpc_server.cpp | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | src/rpc/rpc_args.cpp | 18 | ||||
-rwxr-xr-x[-rw-r--r--] | src/rpc/rpc_args.h | 2 | ||||
-rwxr-xr-x[-rw-r--r--] | src/wallet/wallet_rpc_server.cpp | 2 |
4 files changed, 22 insertions, 2 deletions
diff --git a/src/rpc/core_rpc_server.cpp b/src/rpc/core_rpc_server.cpp index 9095aacae..b3ce30d0c 100644..100755 --- a/src/rpc/core_rpc_server.cpp +++ b/src/rpc/core_rpc_server.cpp @@ -101,7 +101,7 @@ namespace cryptonote http_login.emplace(std::move(rpc_config->login->username), std::move(rpc_config->login->password).password()); return epee::http_server_impl_base<core_rpc_server, connection_context>::init( - std::move(port), std::move(rpc_config->bind_ip), std::move(http_login) + std::move(port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login) ); } //------------------------------------------------------------------------------------------------------------------------------ diff --git a/src/rpc/rpc_args.cpp b/src/rpc/rpc_args.cpp index 4435f74d1..93309bf3c 100644..100755 --- a/src/rpc/rpc_args.cpp +++ b/src/rpc/rpc_args.cpp @@ -28,6 +28,7 @@ // #include "rpc_args.h" +#include <boost/algorithm/string.hpp> #include <boost/asio/ip/address.hpp> #include "common/command_line.h" #include "common/i18n.h" @@ -38,6 +39,7 @@ namespace cryptonote : rpc_bind_ip({"rpc-bind-ip", rpc_args::tr("Specify ip to bind rpc server"), "127.0.0.1"}) , rpc_login({"rpc-login", rpc_args::tr("Specify username[:password] required for RPC server"), "", true}) , confirm_external_bind({"confirm-external-bind", rpc_args::tr("Confirm rpc-bind-ip value is NOT a loopback (local) IP")}) + , rpc_access_control_origins({"rpc-access-control-origins", rpc_args::tr("Specify a comma separated list of origins to allow cross origin resource sharing"), ""}) {} const char* rpc_args::tr(const char* str) { return i18n_translate(str, "cryptonote::rpc_args"); } @@ -48,6 +50,7 @@ namespace cryptonote command_line::add_arg(desc, arg.rpc_bind_ip); command_line::add_arg(desc, arg.rpc_login); command_line::add_arg(desc, arg.confirm_external_bind); + command_line::add_arg(desc, arg.rpc_access_control_origins); } boost::optional<rpc_args> rpc_args::process(const boost::program_options::variables_map& vm) @@ -91,6 +94,21 @@ namespace cryptonote } } + auto access_control_origins_input = command_line::get_arg(vm, arg.rpc_access_control_origins); + if (!access_control_origins_input.empty()) + { + if (!config.login) + { + LOG_ERROR(arg.rpc_access_control_origins.name << tr(" requires RFC server password --") << arg.rpc_login.name << tr(" cannot be empty")); + return boost::none; + } + + std::vector<std::string> access_control_origins; + boost::split(access_control_origins, access_control_origins_input, boost::is_any_of(",")); + std::for_each(access_control_origins.begin(), access_control_origins.end(), boost::bind(&boost::trim<std::string>, _1, std::locale::classic())); + config.access_control_origins = std::move(access_control_origins); + } + return {std::move(config)}; } } diff --git a/src/rpc/rpc_args.h b/src/rpc/rpc_args.h index d6e7bab07..72b5aa706 100644..100755 --- a/src/rpc/rpc_args.h +++ b/src/rpc/rpc_args.h @@ -53,6 +53,7 @@ namespace cryptonote const command_line::arg_descriptor<std::string> rpc_bind_ip; const command_line::arg_descriptor<std::string> rpc_login; const command_line::arg_descriptor<bool> confirm_external_bind; + const command_line::arg_descriptor<std::string> rpc_access_control_origins; }; static const char* tr(const char* str); @@ -62,6 +63,7 @@ namespace cryptonote static boost::optional<rpc_args> process(const boost::program_options::variables_map& vm); std::string bind_ip; + std::vector<std::string> access_control_origins; boost::optional<tools::login> login; // currently `boost::none` if unspecified by user }; } diff --git a/src/wallet/wallet_rpc_server.cpp b/src/wallet/wallet_rpc_server.cpp index edd75e517..acd5357ed 100644..100755 --- a/src/wallet/wallet_rpc_server.cpp +++ b/src/wallet/wallet_rpc_server.cpp @@ -216,7 +216,7 @@ namespace tools m_net_server.set_threads_prefix("RPC"); return epee::http_server_impl_base<wallet_rpc_server, connection_context>::init( - std::move(bind_port), std::move(rpc_config->bind_ip), std::move(http_login) + std::move(bind_port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login) ); } //------------------------------------------------------------------------------------------------------------------------------ |