|
|
@ -7,6 +7,7 @@ |
|
|
|
#include <boost/lexical_cast.hpp> |
|
|
|
#include <boost/lexical_cast.hpp> |
|
|
|
#include <boost/date_time/local_time/local_time.hpp> |
|
|
|
#include <boost/date_time/local_time/local_time.hpp> |
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp> |
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp> |
|
|
|
|
|
|
|
#include <boost/property_tree/ini_parser.hpp> |
|
|
|
#if !GCC47_BOOST149 |
|
|
|
#if !GCC47_BOOST149 |
|
|
|
#include <boost/property_tree/json_parser.hpp> |
|
|
|
#include <boost/property_tree/json_parser.hpp> |
|
|
|
#endif |
|
|
|
#endif |
|
|
@ -30,6 +31,7 @@ namespace client |
|
|
|
m_SSLContext (m_Service, boost::asio::ssl::context::sslv23), |
|
|
|
m_SSLContext (m_Service, boost::asio::ssl::context::sslv23), |
|
|
|
m_ShutdownTimer (m_Service) |
|
|
|
m_ShutdownTimer (m_Service) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
LoadConfig (); |
|
|
|
// certificate
|
|
|
|
// certificate
|
|
|
|
auto path = GetPath (); |
|
|
|
auto path = GetPath (); |
|
|
|
if (!boost::filesystem::exists (path)) |
|
|
|
if (!boost::filesystem::exists (path)) |
|
|
@ -56,6 +58,9 @@ namespace client |
|
|
|
m_MethodHandlers[I2P_CONTROL_METHOD_ROUTER_MANAGER] = &I2PControlService::RouterManagerHandler; |
|
|
|
m_MethodHandlers[I2P_CONTROL_METHOD_ROUTER_MANAGER] = &I2PControlService::RouterManagerHandler; |
|
|
|
m_MethodHandlers[I2P_CONTROL_METHOD_NETWORK_SETTING] = &I2PControlService::NetworkSettingHandler; |
|
|
|
m_MethodHandlers[I2P_CONTROL_METHOD_NETWORK_SETTING] = &I2PControlService::NetworkSettingHandler; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// I2PControl
|
|
|
|
|
|
|
|
m_I2PControlHandlers[I2P_CONTROL_I2PCONTROL_PASSWORD] = &I2PControlService::PasswordHandler; |
|
|
|
|
|
|
|
|
|
|
|
// RouterInfo
|
|
|
|
// RouterInfo
|
|
|
|
m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_UPTIME] = &I2PControlService::UptimeHandler; |
|
|
|
m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_UPTIME] = &I2PControlService::UptimeHandler; |
|
|
|
m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_VERSION] = &I2PControlService::VersionHandler; |
|
|
|
m_RouterInfoHandlers[I2P_CONTROL_ROUTER_INFO_VERSION] = &I2PControlService::VersionHandler; |
|
|
@ -78,6 +83,49 @@ namespace client |
|
|
|
Stop (); |
|
|
|
Stop (); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void I2PControlService::LoadConfig () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
auto path = GetPath (); |
|
|
|
|
|
|
|
if (!boost::filesystem::exists (path)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
if (!boost::filesystem::create_directory (path)) |
|
|
|
|
|
|
|
LogPrint (eLogError, "Failed to create i2pcontrol directory"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
boost::property_tree::ptree pt; |
|
|
|
|
|
|
|
auto filename = path / I2P_CONTROL_CONFIG_FILE; |
|
|
|
|
|
|
|
bool isNew = true; |
|
|
|
|
|
|
|
if (boost::filesystem::exists (filename)) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
boost::property_tree::read_ini (filename.string (), pt); |
|
|
|
|
|
|
|
isNew = false; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (std::exception& ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogError, "Can't read ", filename, ": ", ex.what ()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
m_Password = pt.get (I2P_CONTROL_I2PCONTROL_PASSWORD, I2P_CONTROL_DEFAULT_PASSWORD); |
|
|
|
|
|
|
|
if (isNew) SaveConfig (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void I2PControlService::SaveConfig () |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
boost::property_tree::ptree pt; |
|
|
|
|
|
|
|
pt.put (I2P_CONTROL_I2PCONTROL_PASSWORD, m_Password); |
|
|
|
|
|
|
|
auto filename = GetPath () / I2P_CONTROL_CONFIG_FILE; |
|
|
|
|
|
|
|
// we take care about directory in LoadConfig
|
|
|
|
|
|
|
|
try |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
boost::property_tree::write_ini (filename.string (), pt); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (std::exception& ex) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogError, "Can't write ", filename, ": ", ex.what ()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void I2PControlService::Start () |
|
|
|
void I2PControlService::Start () |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!m_IsRunning) |
|
|
|
if (!m_IsRunning) |
|
|
@ -326,12 +374,23 @@ namespace client |
|
|
|
LogPrint (eLogDebug, it.first); |
|
|
|
LogPrint (eLogDebug, it.first); |
|
|
|
auto it1 = m_I2PControlHandlers.find (it.first); |
|
|
|
auto it1 = m_I2PControlHandlers.find (it.first); |
|
|
|
if (it1 != m_I2PControlHandlers.end ()) |
|
|
|
if (it1 != m_I2PControlHandlers.end ()) |
|
|
|
|
|
|
|
{ |
|
|
|
(this->*(it1->second))(it.second.data ()); |
|
|
|
(this->*(it1->second))(it.second.data ()); |
|
|
|
|
|
|
|
InsertParam (results, it.first, ""); |
|
|
|
|
|
|
|
} |
|
|
|
else |
|
|
|
else |
|
|
|
LogPrint (eLogError, "I2PControl NetworkSetting unknown request ", it.first); |
|
|
|
LogPrint (eLogError, "I2PControl I2PControl unknown request ", it.first); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void I2PControlService::PasswordHandler (const std::string& value) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
LogPrint (eLogDebug, "I2PControl new password=", value); |
|
|
|
|
|
|
|
m_Password = value; |
|
|
|
|
|
|
|
m_Tokens.clear (); |
|
|
|
|
|
|
|
SaveConfig (); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// RouterInfo
|
|
|
|
// RouterInfo
|
|
|
|
|
|
|
|
|
|
|
|
void I2PControlService::RouterInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results) |
|
|
|
void I2PControlService::RouterInfoHandler (const boost::property_tree::ptree& params, std::ostringstream& results) |
|
|
|