164 {
166 if (!rpc_config)
167 return false;
168
169 m_vm = vm;
170
173
174 boost::optional<epee::net_utils::http::login> http_login{};
179 {
181 {
183 return false;
184 }
186#ifdef _WIN32
187#define MKDIR(path, mode) mkdir(path)
188#else
189#define MKDIR(path, mode) mkdir(path, mode)
190#endif
191 if (!m_wallet_dir.empty() &&
MKDIR(m_wallet_dir.c_str(), 0700) < 0 && errno != EEXIST)
192 {
193#ifdef _WIN32
194 LOG_ERROR(
tr(
"Failed to create directory ") + m_wallet_dir);
195#else
196 LOG_ERROR((boost::format(
tr(
"Failed to create directory %s: %s")) % m_wallet_dir % strerror(errno)).str());
197#endif
198 return false;
199 }
200 }
201
202 if (disable_auth)
203 {
204 if (rpc_config->login)
205 {
206 const cryptonote::rpc_args::descriptors arg{};
208 return false;
209 }
210 }
211 else
212 {
213 if (!rpc_config->login)
214 {
215 std::array<std::uint8_t, 16> rand_128bit{{}};
217 http_login.emplace(
218 default_rpc_username,
220 );
221
222 std::string temp = "electroneum-wallet-rpc." + bind_port + ".login";
224 if (!rpc_login_file.handle())
225 {
226 LOG_ERROR(
tr(
"Failed to create file ") << temp <<
tr(
". Check permissions or remove file"));
227 return false;
228 }
229 std::fputs(http_login->username.c_str(), rpc_login_file.handle());
230 std::fputc(':', rpc_login_file.handle());
231 const epee::wipeable_string password = http_login->password;
232 std::fwrite(password.
data(), 1, password.
size(), rpc_login_file.handle());
233 std::fflush(rpc_login_file.handle());
234 if (std::ferror(rpc_login_file.handle()))
235 {
237 return false;
238 }
239 LOG_PRINT_L0(
tr(
"RPC username/password is stored in file ") << temp);
240 }
241 else
242 {
243 http_login.emplace(
244 std::move(rpc_config->login->username), std::move(rpc_config->login->password).password()
245 );
246 }
247 assert(bool(http_login));
248 }
249
251 m_last_auto_refresh_time = boost::posix_time::min_date_time;
252
253 check_background_mining();
254
258 rng, std::move(bind_port), std::move(rpc_config->bind_ip), std::move(rpc_config->access_control_origins), std::move(http_login),
259 std::move(rpc_config->ssl_options)
260 );
261 }
bool init(std::function< void(size_t, uint8_t *)> rng, const std::string &bind_port="0", const std::string &bind_ip="0.0.0.0", std::vector< std::string > access_control_origins=std::vector< std::string >(), boost::optional< net_utils::http::login > user=boost::none, net_utils::ssl_options_t ssl_options=net_utils::ssl_support_t::e_ssl_support_autodetect)
net_utils::boosted_tcp_server< net_utils::http::http_custom_handler< epee::net_utils::connection_context_base > > m_net_server
const char * data() const noexcept
size_t size() const noexcept
bool is_arg_defaulted(const boost::program_options::variables_map &vm, const arg_descriptor< T, required, dependent, NUM_DEPS > &arg)
T get_arg(const boost::program_options::variables_map &vm, const arg_descriptor< T, false, true > &arg)
std::enable_if< std::is_pod< T >::value, T >::type rand()
std::string base64_encode(unsigned char const *bytes_to_encode, size_t in_len)
boost::filesystem::path data_dir
command_line::arg_descriptor< std::string > arg_wallet_file()
const command_line::arg_descriptor< std::string > rpc_login
static boost::optional< rpc_args > process(const boost::program_options::variables_map &vm, const bool any_cert_option=false)
#define MKDIR(path, mode)
#define DEFAULT_AUTO_REFRESH_PERIOD