Add more information to webui.

This commit is contained in:
EinMByte 2015-09-17 16:49:55 +02:00
parent 7e066f7f69
commit 9890bf98e4
13 changed files with 239 additions and 107 deletions

View File

@ -114,10 +114,12 @@ namespace client
// I2P Control
int i2pcontrolPort = i2p::util::config::GetArg("-i2pcontrolport", 0);
if(i2pcontrolPort) {
m_I2PControlService = new I2PControlService(
m_I2PControlService = new i2pcontrol::I2PControlService(
i2p::util::config::GetArg("-i2pcontroladdress", "127.0.0.1"),
i2pcontrolPort,
i2p::util::config::GetArg("-i2pcontrolpassword", I2P_CONTROL_DEFAULT_PASSWORD)
i2p::util::config::GetArg(
"-i2pcontrolpassword", i2pcontrol::constants::DEFAULT_PASSWORD
)
);
m_I2PControlService->Start();
LogPrint("I2PControl started");

View File

@ -72,7 +72,7 @@ namespace client
std::map<i2p::data::IdentHash, std::unique_ptr<I2PServerTunnel> > m_ServerTunnels; // destination->tunnel
SAMBridge * m_SamBridge;
BOBCommandChannel * m_BOBCommandChannel;
I2PControlService * m_I2PControlService;
i2pcontrol::I2PControlService * m_I2PControlService;
public:
// for HTTP

View File

@ -36,7 +36,7 @@ const char HTTP_COMMAND_SAM_SESSION[] = "sam_session";
const char HTTP_PARAM_SAM_SESSION_ID[] = "id";
HTTPConnection::HTTPConnection(boost::asio::ip::tcp::socket* socket,
std::shared_ptr<i2p::client::I2PControlSession> session)
std::shared_ptr<client::i2pcontrol::I2PControlSession> session)
: m_Socket(socket), m_Timer(socket->get_io_service()),
m_BufferLen(0), m_Session(session)
{
@ -159,7 +159,7 @@ void HTTPConnection::HandleRequest()
void HTTPConnection::HandleI2PControlRequest()
{
std::stringstream ss(m_Request.getContent());
const client::I2PControlSession::Response rsp = m_Session->handleRequest(ss);
const client::i2pcontrol::I2PControlSession::Response rsp = m_Session->handleRequest(ss);
m_Reply = i2p::util::http::Response(200, rsp.toJsonString());
m_Reply.setHeader("Content-Type", "application/json");
SendReply();
@ -197,7 +197,7 @@ HTTPServer::HTTPServer(const std::string& address, int port):
boost::asio::ip::address::from_string(address), port)
),
m_NewSocket(nullptr),
m_Session(std::make_shared<i2p::client::I2PControlSession>(m_Service))
m_Session(std::make_shared<client::i2pcontrol::I2PControlSession>(m_Service))
{
}

View File

@ -19,7 +19,7 @@ class HTTPConnection: public std::enable_shared_from_this<HTTPConnection> {
public:
HTTPConnection(boost::asio::ip::tcp::socket* socket,
std::shared_ptr<i2p::client::I2PControlSession> session);
std::shared_ptr<i2p::client::i2pcontrol::I2PControlSession> session);
~HTTPConnection() { delete m_Socket; }
void Receive();
@ -44,7 +44,7 @@ private:
size_t m_BufferLen;
util::http::Request m_Request;
util::http::Response m_Reply;
std::shared_ptr<i2p::client::I2PControlSession> m_Session;
std::shared_ptr<i2p::client::i2pcontrol::I2PControlSession> m_Session;
};
class HTTPServer {
@ -69,7 +69,7 @@ private:
boost::asio::io_service::work m_Work;
boost::asio::ip::tcp::acceptor m_Acceptor;
boost::asio::ip::tcp::socket * m_NewSocket;
std::shared_ptr<i2p::client::I2PControlSession> m_Session;
std::shared_ptr<i2p::client::i2pcontrol::I2PControlSession> m_Session;
protected:
void CreateConnection(boost::asio::ip::tcp::socket* m_NewSocket);

View File

@ -11,6 +11,7 @@
#include <cryptopp/filters.h>
#include <boost/property_tree/json_parser.hpp>
#include "util/util.h"
#include "util/Log.h"
#include "util/Timestamp.h"
#include "transport/Transports.h"
@ -21,6 +22,7 @@
namespace i2p {
namespace client {
namespace i2pcontrol {
I2PControlSession::Response::Response(const std::string& version)
: id(), version(version), error(ErrorCode::None), parameters()
@ -104,28 +106,33 @@ I2PControlSession::I2PControlSession(boost::asio::io_service& ios, const std::st
: password(pass), tokens(), tokensMutex(),
service(ios), shutdownTimer(ios), expireTokensTimer(ios)
{
using namespace i2p::client::i2pcontrol::constants;
// Method handlers
methodHandlers[I2P_CONTROL_METHOD_AUTHENTICATE] = &I2PControlSession::handleAuthenticate;
methodHandlers[I2P_CONTROL_METHOD_ECHO] = &I2PControlSession::handleEcho;
methodHandlers[I2P_CONTROL_METHOD_I2PCONTROL] = &I2PControlSession::handleI2PControl;
methodHandlers[I2P_CONTROL_METHOD_ROUTER_INFO] = &I2PControlSession::handleRouterInfo;
methodHandlers[I2P_CONTROL_METHOD_ROUTER_MANAGER] = &I2PControlSession::handleRouterManager;
methodHandlers[I2P_CONTROL_METHOD_NETWORK_SETTING] = &I2PControlSession::handleNetworkSetting;
methodHandlers[METHOD_AUTHENTICATE] = &I2PControlSession::handleAuthenticate;
methodHandlers[METHOD_ECHO] = &I2PControlSession::handleEcho;
methodHandlers[METHOD_I2PCONTROL] = &I2PControlSession::handleI2PControl;
methodHandlers[METHOD_ROUTER_INFO] = &I2PControlSession::handleRouterInfo;
methodHandlers[METHOD_ROUTER_MANAGER] = &I2PControlSession::handleRouterManager;
methodHandlers[METHOD_NETWORK_SETTING] = &I2PControlSession::handleNetworkSetting;
// RouterInfo handlers
routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_UPTIME] = &I2PControlSession::handleUptime;
routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_VERSION] = &I2PControlSession::handleVersion;
routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_STATUS] = &I2PControlSession::handleStatus;
routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_NETDB_KNOWNPEERS]= &I2PControlSession::handleNetDbKnownPeers;
routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_NETDB_ACTIVEPEERS] = &I2PControlSession::handleNetDbActivePeers;
routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_NET_STATUS] = &I2PControlSession::handleNetStatus;
routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_TUNNELS_PARTICIPATING] = &I2PControlSession::handleTunnelsParticipating;
routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_BW_IB_1S] = &I2PControlSession::handleInBandwidth1S;
routerInfoHandlers[I2P_CONTROL_ROUTER_INFO_BW_OB_1S] = &I2PControlSession::handleOutBandwidth1S;
routerInfoHandlers[ROUTER_INFO_UPTIME] = &I2PControlSession::handleUptime;
routerInfoHandlers[ROUTER_INFO_VERSION] = &I2PControlSession::handleVersion;
routerInfoHandlers[ROUTER_INFO_STATUS] = &I2PControlSession::handleStatus;
routerInfoHandlers[ROUTER_INFO_DATAPATH] = &I2PControlSession::handleDatapath;
routerInfoHandlers[ROUTER_INFO_NETDB_KNOWNPEERS]= &I2PControlSession::handleNetDbKnownPeers;
routerInfoHandlers[ROUTER_INFO_NETDB_ACTIVEPEERS] = &I2PControlSession::handleNetDbActivePeers;
routerInfoHandlers[ROUTER_INFO_NETDB_LEASESETS] = &I2PControlSession::handleNetDbLeaseSets;
routerInfoHandlers[ROUTER_INFO_NETDB_FLOODFILLS] = &I2PControlSession::handleNetDbFloodfills;
routerInfoHandlers[ROUTER_INFO_NET_STATUS] = &I2PControlSession::handleNetStatus;
routerInfoHandlers[ROUTER_INFO_TUNNELS_PARTICIPATING] = &I2PControlSession::handleTunnelsParticipating;
routerInfoHandlers[ROUTER_INFO_TUNNELS_CREATION_SUCCESS] = &I2PControlSession::handleTunnelsCreationSuccess;
routerInfoHandlers[ROUTER_INFO_BW_IB_1S] = &I2PControlSession::handleInBandwidth1S;
routerInfoHandlers[ROUTER_INFO_BW_OB_1S] = &I2PControlSession::handleOutBandwidth1S;
// RouterManager handlers
routerManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN] = &I2PControlSession::handleShutdown;
routerManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN_GRACEFUL] = &I2PControlSession::handleShutdownGraceful;
routerManagerHandlers[I2P_CONTROL_ROUTER_MANAGER_RESEED] = &I2PControlSession::handleReseed;
routerManagerHandlers[ROUTER_MANAGER_SHUTDOWN] = &I2PControlSession::handleShutdown;
routerManagerHandlers[ROUTER_MANAGER_SHUTDOWN_GRACEFUL] = &I2PControlSession::handleShutdownGraceful;
routerManagerHandlers[ROUTER_MANAGER_RESEED] = &I2PControlSession::handleReseed;
}
void I2PControlSession::start()
@ -147,9 +154,9 @@ I2PControlSession::Response I2PControlSession::handleRequest(std::stringstream&
Response response;
try {
response.setId(pt.get<std::string>(I2P_CONTROL_PROPERTY_ID));
response.setId(pt.get<std::string>(constants::PROPERTY_ID));
std::string method = pt.get<std::string>(I2P_CONTROL_PROPERTY_METHOD);
std::string method = pt.get<std::string>(constants::PROPERTY_METHOD);
auto it = methodHandlers.find(method);
if(it == methodHandlers.end()) { // Not found
LogPrint(eLogWarning, "Unknown I2PControl method ", method);
@ -157,8 +164,8 @@ I2PControlSession::Response I2PControlSession::handleRequest(std::stringstream&
return response;
}
PropertyTree params = pt.get_child(I2P_CONTROL_PROPERTY_PARAMS);
if(method != I2P_CONTROL_METHOD_AUTHENTICATE && !authenticate(params, response)) {
PropertyTree params = pt.get_child(constants::PROPERTY_PARAMS);
if(method != constants::METHOD_AUTHENTICATE && !authenticate(params, response)) {
LogPrint(eLogWarning, "I2PControl invalid token presented");
return response;
}
@ -177,14 +184,14 @@ I2PControlSession::Response I2PControlSession::handleRequest(std::stringstream&
bool I2PControlSession::authenticate(const PropertyTree& pt, Response& response)
{
try {
std::string token = pt.get<std::string>(I2P_CONTROL_PARAM_TOKEN);
std::string token = pt.get<std::string>(constants::PARAM_TOKEN);
std::lock_guard<std::mutex> lock(tokensMutex);
auto it = tokens.find(token);
if(it == tokens.end()) {
response.setError(ErrorCode::NonexistentToken);
return false;
} else if(util::GetSecondsSinceEpoch() - it->second > I2P_CONTROL_TOKEN_LIFETIME) {
} else if(util::GetSecondsSinceEpoch() - it->second > constants::TOKEN_LIFETIME) {
response.setError(ErrorCode::ExpiredToken);
return false;
}
@ -199,12 +206,12 @@ bool I2PControlSession::authenticate(const PropertyTree& pt, Response& response)
std::string I2PControlSession::generateToken() const
{
byte random_data[I2P_CONTROL_TOKEN_SIZE] = {};
byte random_data[constants::TOKEN_SIZE] = {};
CryptoPP::AutoSeededRandomPool rng;
rng.GenerateBlock(random_data, I2P_CONTROL_TOKEN_SIZE);
rng.GenerateBlock(random_data, constants::TOKEN_SIZE);
std::string token;
CryptoPP::StringSource ss(
random_data, I2P_CONTROL_TOKEN_SIZE, true,
random_data, constants::TOKEN_SIZE, true,
new CryptoPP::HexEncoder(new CryptoPP::StringSink(token))
);
return token;
@ -212,8 +219,8 @@ std::string I2PControlSession::generateToken() const
void I2PControlSession::handleAuthenticate(const PropertyTree& pt, Response& response)
{
const int api = pt.get<int>(I2P_CONTROL_PARAM_API);
const std::string given_pass = pt.get<std::string>(I2P_CONTROL_PARAM_PASSWORD);
const int api = pt.get<int>(constants::PARAM_API);
const std::string given_pass = pt.get<std::string>(constants::PARAM_PASSWORD);
LogPrint(eLogDebug, "I2PControl Authenticate API = ", api, " Password = ", given_pass);
if(given_pass != password) {
LogPrint(
@ -224,8 +231,8 @@ void I2PControlSession::handleAuthenticate(const PropertyTree& pt, Response& res
return;
}
const std::string token = generateToken();
response.setParam(I2P_CONTROL_PARAM_API, api);
response.setParam(I2P_CONTROL_PARAM_TOKEN, token);
response.setParam(constants::PARAM_API, api);
response.setParam(constants::PARAM_TOKEN, token);
std::lock_guard<std::mutex> lock(tokensMutex);
tokens.insert(std::make_pair(token, util::GetSecondsSinceEpoch()));
@ -233,9 +240,9 @@ void I2PControlSession::handleAuthenticate(const PropertyTree& pt, Response& res
void I2PControlSession::handleEcho(const PropertyTree& pt, Response& response)
{
const std::string echo = pt.get<std::string>(I2P_CONTROL_PARAM_ECHO);
const std::string echo = pt.get<std::string>(constants::PARAM_ECHO);
LogPrint(eLogDebug, "I2PControl Echo Echo = ", echo);
response.setParam(I2P_CONTROL_PARAM_RESULT, echo);
response.setParam(constants::PARAM_RESULT, echo);
}
void I2PControlSession::handleI2PControl(const PropertyTree&, Response&)
@ -249,7 +256,7 @@ void I2PControlSession::handleRouterInfo(const PropertyTree& pt, Response& respo
{
LogPrint(eLogDebug, "I2PControl RouterInfo");
for(const auto& pair : pt) {
if(pair.first == I2P_CONTROL_PARAM_TOKEN)
if(pair.first == constants::PARAM_TOKEN)
continue;
LogPrint(eLogDebug, pair.first);
auto it = routerInfoHandlers.find(pair.first);
@ -266,7 +273,7 @@ void I2PControlSession::handleRouterManager(const PropertyTree& pt, Response& re
{
LogPrint(eLogDebug, "I2PControl RouterManager");
for(const auto& pair : pt) {
if(pair.first == I2P_CONTROL_PARAM_TOKEN)
if(pair.first == constants::PARAM_TOKEN)
continue;
LogPrint(eLogDebug, pair.first);
auto it = routerManagerHandlers.find(pair.first);
@ -286,53 +293,85 @@ void I2PControlSession::handleNetworkSetting(const PropertyTree&, Response&)
void I2PControlSession::handleUptime(Response& response)
{
response.setParam(I2P_CONTROL_ROUTER_INFO_UPTIME, (int)i2p::context.GetUptime()*1000);
response.setParam(constants::ROUTER_INFO_UPTIME, (int)i2p::context.GetUptime()*1000);
}
void I2PControlSession::handleVersion(Response& response)
{
response.setParam(I2P_CONTROL_ROUTER_INFO_VERSION, VERSION);
response.setParam(constants::ROUTER_INFO_VERSION, VERSION);
}
void I2PControlSession::handleStatus(Response& response)
{
response.setParam(I2P_CONTROL_ROUTER_INFO_STATUS, "???"); // TODO:
response.setParam(constants::ROUTER_INFO_STATUS, "???"); // TODO:
}
void I2PControlSession::handleDatapath(Response& response)
{
response.setParam(
constants::ROUTER_INFO_DATAPATH,
i2p::util::filesystem::GetDefaultDataDir().string()
);
}
void I2PControlSession::handleNetDbKnownPeers(Response& response)
{
response.setParam(
I2P_CONTROL_ROUTER_INFO_NETDB_KNOWNPEERS, i2p::data::netdb.GetNumRouters()
constants::ROUTER_INFO_NETDB_KNOWNPEERS, i2p::data::netdb.GetNumRouters()
);
}
void I2PControlSession::handleNetDbActivePeers(Response& response)
{
response.setParam(
I2P_CONTROL_ROUTER_INFO_NETDB_ACTIVEPEERS,
constants::ROUTER_INFO_NETDB_ACTIVEPEERS,
(int)i2p::transport::transports.GetPeers().size()
);
}
void I2PControlSession::handleNetDbFloodfills(Response& response)
{
response.setParam(
constants::ROUTER_INFO_NETDB_FLOODFILLS,
(int)i2p::data::netdb.GetNumFloodfills()
);
}
void I2PControlSession::handleNetDbLeaseSets(Response& response)
{
response.setParam(
constants::ROUTER_INFO_NETDB_LEASESETS,
(int)i2p::data::netdb.GetNumLeaseSets()
);
}
void I2PControlSession::handleNetStatus(Response& response)
{
response.setParam(
I2P_CONTROL_ROUTER_INFO_NET_STATUS, (int)i2p::context.GetStatus()
constants::ROUTER_INFO_NET_STATUS, (int)i2p::context.GetStatus()
);
}
void I2PControlSession::handleTunnelsParticipating(Response& response)
{
response.setParam(
I2P_CONTROL_ROUTER_INFO_TUNNELS_PARTICIPATING,
constants::ROUTER_INFO_TUNNELS_PARTICIPATING,
(int)i2p::tunnel::tunnels.GetTransitTunnels().size()
);
}
void I2PControlSession::handleTunnelsCreationSuccess(Response& response)
{
response.setParam(
constants::ROUTER_INFO_TUNNELS_CREATION_SUCCESS,
i2p::tunnel::tunnels.GetTunnelCreationSuccessRate()
);
}
void I2PControlSession::handleInBandwidth1S(Response& response)
{
response.setParam(
I2P_CONTROL_ROUTER_INFO_BW_IB_1S,
constants::ROUTER_INFO_BW_IB_1S,
(double)i2p::transport::transports.GetInBandwidth()
);
}
@ -340,7 +379,7 @@ void I2PControlSession::handleInBandwidth1S(Response& response)
void I2PControlSession::handleOutBandwidth1S(Response& response)
{
response.setParam(
I2P_CONTROL_ROUTER_INFO_BW_OB_1S,
constants::ROUTER_INFO_BW_OB_1S,
(double)i2p::transport::transports.GetOutBandwidth()
);
}
@ -348,7 +387,7 @@ void I2PControlSession::handleOutBandwidth1S(Response& response)
void I2PControlSession::handleShutdown(Response& response)
{
LogPrint(eLogInfo, "Shutdown requested");
response.setParam(I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN, "");
response.setParam(constants::ROUTER_MANAGER_SHUTDOWN, "");
// 1 second to make sure response has been sent
shutdownTimer.expires_from_now(boost::posix_time::seconds(1));
shutdownTimer.async_wait([](const boost::system::error_code&) {
@ -361,7 +400,7 @@ void I2PControlSession::handleShutdownGraceful(Response& response)
i2p::context.SetAcceptsTunnels(false);
int timeout = i2p::tunnel::tunnels.GetTransitTunnelsExpirationTimeout();
LogPrint(eLogInfo, "Graceful shutdown requested. Will shutdown after ", timeout, " seconds");
response.setParam(I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN_GRACEFUL, "");
response.setParam(constants::ROUTER_MANAGER_SHUTDOWN_GRACEFUL, "");
shutdownTimer.expires_from_now(boost::posix_time::seconds(timeout + 1));
shutdownTimer.async_wait([](const boost::system::error_code&) {
Daemon.running = 0;
@ -371,7 +410,7 @@ void I2PControlSession::handleShutdownGraceful(Response& response)
void I2PControlSession::handleReseed(Response& response)
{
LogPrint(eLogInfo, "Reseed requested");
response.setParam(I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN, "");
response.setParam(constants::ROUTER_MANAGER_SHUTDOWN, "");
i2p::data::netdb.Reseed();
}
@ -385,7 +424,7 @@ void I2PControlSession::expireTokens(const boost::system::error_code& error)
const uint64_t now = util::GetSecondsSinceEpoch();
std::lock_guard<std::mutex> lock(tokensMutex);
for(auto it = tokens.begin(); it != tokens.end(); ) {
if(now - it->second > I2P_CONTROL_TOKEN_LIFETIME)
if(now - it->second > constants::TOKEN_LIFETIME)
it = tokens.erase(it);
else
++it;
@ -394,7 +433,7 @@ void I2PControlSession::expireTokens(const boost::system::error_code& error)
void I2PControlSession::startExpireTokensJob()
{
expireTokensTimer.expires_from_now(boost::posix_time::seconds(I2P_CONTROL_TOKEN_LIFETIME));
expireTokensTimer.expires_from_now(boost::posix_time::seconds(constants::TOKEN_LIFETIME));
expireTokensTimer.async_wait(std::bind(
&I2PControlSession::expireTokens, shared_from_this(), std::placeholders::_1
));
@ -402,3 +441,4 @@ void I2PControlSession::startExpireTokensJob()
}
}
}

View File

@ -10,51 +10,60 @@
namespace i2p {
namespace client {
namespace i2pcontrol {
const char I2P_CONTROL_DEFAULT_PASSWORD[] = "itoopie";
const uint64_t I2P_CONTROL_TOKEN_LIFETIME = 600; // Token lifetime in seconds
const std::size_t I2P_CONTROL_TOKEN_SIZE = 8; // Token size in bytes
namespace constants {
const char I2P_CONTROL_PROPERTY_ID[] = "id";
const char I2P_CONTROL_PROPERTY_METHOD[] = "method";
const char I2P_CONTROL_PROPERTY_PARAMS[] = "params";
const char I2P_CONTROL_PROPERTY_RESULT[] = "result";
const char DEFAULT_PASSWORD[] = "itoopie";
const uint64_t TOKEN_LIFETIME = 600; // Token lifetime in seconds
const std::size_t TOKEN_SIZE = 8; // Token size in bytes
const char PROPERTY_ID[] = "id";
const char PROPERTY_METHOD[] = "method";
const char PROPERTY_PARAMS[] = "params";
const char PROPERTY_RESULT[] = "result";
// methods
const char I2P_CONTROL_METHOD_AUTHENTICATE[] = "Authenticate";
const char I2P_CONTROL_METHOD_ECHO[] = "Echo";
const char I2P_CONTROL_METHOD_I2PCONTROL[] = "I2PControl";
const char I2P_CONTROL_METHOD_ROUTER_INFO[] = "RouterInfo";
const char I2P_CONTROL_METHOD_ROUTER_MANAGER[] = "RouterManager";
const char I2P_CONTROL_METHOD_NETWORK_SETTING[] = "NetworkSetting";
const char METHOD_AUTHENTICATE[] = "Authenticate";
const char METHOD_ECHO[] = "Echo";
const char METHOD_I2PCONTROL[] = "I2PControl";
const char METHOD_ROUTER_INFO[] = "RouterInfo";
const char METHOD_ROUTER_MANAGER[] = "RouterManager";
const char METHOD_NETWORK_SETTING[] = "NetworkSetting";
// params
const char I2P_CONTROL_PARAM_API[] = "API";
const char I2P_CONTROL_PARAM_PASSWORD[] = "Password";
const char I2P_CONTROL_PARAM_TOKEN[] = "Token";
const char I2P_CONTROL_PARAM_ECHO[] = "Echo";
const char I2P_CONTROL_PARAM_RESULT[] = "Result";
const char PARAM_API[] = "API";
const char PARAM_PASSWORD[] = "Password";
const char PARAM_TOKEN[] = "Token";
const char PARAM_ECHO[] = "Echo";
const char PARAM_RESULT[] = "Result";
// I2PControl
const char I2P_CONTROL_I2PCONTROL_ADDRESS[] = "i2pcontrol.address";
const char I2P_CONTROL_I2PCONTROL_PASSWORD[] = "i2pcontrol.password";
const char I2P_CONTROL_I2PCONTROL_PORT[] = "i2pcontrol.port";
const char I2PCONTROL_ADDRESS[] = "i2pcontrol.address";
const char I2PCONTROL_PASSWORD[] = "i2pcontrol.password";
const char I2PCONTROL_PORT[] = "i2pcontrol.port";
// RouterInfo requests
const char I2P_CONTROL_ROUTER_INFO_UPTIME[] = "i2p.router.uptime";
const char I2P_CONTROL_ROUTER_INFO_VERSION[] = "i2p.router.version";
const char I2P_CONTROL_ROUTER_INFO_STATUS[] = "i2p.router.status";
const char I2P_CONTROL_ROUTER_INFO_NETDB_KNOWNPEERS[] = "i2p.router.netdb.knownpeers";
const char I2P_CONTROL_ROUTER_INFO_NETDB_ACTIVEPEERS[] = "i2p.router.netdb.activepeers";
const char I2P_CONTROL_ROUTER_INFO_NET_STATUS[] = "i2p.router.net.status";
const char I2P_CONTROL_ROUTER_INFO_TUNNELS_PARTICIPATING[] = "i2p.router.net.tunnels.participating";
const char I2P_CONTROL_ROUTER_INFO_BW_IB_1S[] = "i2p.router.net.bw.inbound.1s";
const char I2P_CONTROL_ROUTER_INFO_BW_OB_1S[] = "i2p.router.net.bw.outbound.1s";
const char ROUTER_INFO_UPTIME[] = "i2p.router.uptime";
const char ROUTER_INFO_VERSION[] = "i2p.router.version";
const char ROUTER_INFO_STATUS[] = "i2p.router.status";
const char ROUTER_INFO_DATAPATH[] = "i2p.router.datapath";
const char ROUTER_INFO_NETDB_KNOWNPEERS[] = "i2p.router.netdb.knownpeers";
const char ROUTER_INFO_NETDB_ACTIVEPEERS[] = "i2p.router.netdb.activepeers";
const char ROUTER_INFO_NETDB_FLOODFILLS[] = "i2p.router.netdb.floodfills";
const char ROUTER_INFO_NETDB_LEASESETS[] = "i2p.router.netdb.leasesets";
const char ROUTER_INFO_NET_STATUS[] = "i2p.router.net.status";
const char ROUTER_INFO_TUNNELS_PARTICIPATING[] = "i2p.router.net.tunnels.participating";
const char ROUTER_INFO_TUNNELS_CREATION_SUCCESS[] = "i2p.router.net.tunnels.creationsuccessrate";
const char ROUTER_INFO_BW_IB_1S[] = "i2p.router.net.bw.inbound.1s";
const char ROUTER_INFO_BW_OB_1S[] = "i2p.router.net.bw.outbound.1s";
// RouterManager requests
const char I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN[] = "Shutdown";
const char I2P_CONTROL_ROUTER_MANAGER_SHUTDOWN_GRACEFUL[] = "ShutdownGraceful";
const char I2P_CONTROL_ROUTER_MANAGER_RESEED[] = "Reseed";
const char ROUTER_MANAGER_SHUTDOWN[] = "Shutdown";
const char ROUTER_MANAGER_SHUTDOWN_GRACEFUL[] = "ShutdownGraceful";
const char ROUTER_MANAGER_RESEED[] = "Reseed";
} // constants
/**
* "Null" I2P control implementation, does not do actual networking.
@ -113,7 +122,7 @@ public:
* the lifetime of this I2PControlSession.
*/
I2PControlSession(boost::asio::io_service& ios,
const std::string& pass = I2P_CONTROL_DEFAULT_PASSWORD);
const std::string& pass = constants::DEFAULT_PASSWORD);
/**
* Starts the I2PControlSession.
@ -172,10 +181,14 @@ private:
void handleUptime(Response& response);
void handleVersion(Response& response);
void handleStatus(Response& response);
void handleDatapath(Response& response);
void handleNetDbKnownPeers(Response& response);
void handleNetDbActivePeers(Response& response);
void handleNetDbFloodfills(Response& response);
void handleNetDbLeaseSets(Response& response);
void handleNetStatus(Response& response);
void handleTunnelsParticipating(Response& response);
void handleTunnelsCreationSuccess(Response& response);
void handleInBandwidth1S(Response& response);
void handleOutBandwidth1S(Response& response);
@ -198,6 +211,7 @@ private:
boost::asio::deadline_timer expireTokensTimer;
};
}
}
}

View File

@ -8,6 +8,7 @@
namespace i2p {
namespace client {
namespace i2pcontrol {
I2PControlService::I2PControlService(const std::string& address, int port, const std::string& pass)
: m_Session(std::make_shared<I2PControlSession>(m_Service, pass)),
@ -168,3 +169,4 @@ void I2PControlService::HandleResponseSent(const boost::system::error_code& ecod
}
}
}

View File

@ -12,6 +12,7 @@
namespace i2p {
namespace client {
namespace i2pcontrol {
const size_t I2P_CONTROL_MAX_REQUEST_SIZE = 1024;
typedef std::array<char, I2P_CONTROL_MAX_REQUEST_SIZE> I2PControlBuffer;
@ -51,6 +52,7 @@ private:
};
}
}
}
#endif

6
webui/footer.html Normal file
View File

@ -0,0 +1,6 @@
<div id="main">
<noscript>
<div class="header"><h1>Please enable JavaScript!</h1></div>
</noscript>
</div>

View File

@ -22,11 +22,7 @@
</div>
<!--#include virtual="menu.html" -->
<!--#include virtual="footer.html" -->
<div id="main">
<noscript>
<div class="header"><h1>Please enable JavaScript!</h1></div>
</noscript>
</div>
<body>
</body>
</html>

View File

@ -19,6 +19,7 @@ function updateRouterInfo(result, session) {
"knownpeers" : result["i2p.router.netdb.knownpeers"],
"activepeers" : result["i2p.router.netdb.activepeers"],
"tunnels-participating" : result["i2p.router.net.tunnels.participating"],
"tunnels-successrate" : result["i2p.router.net.tunnels.creationsuccessrate"] + "&#37",
"bw-in" : result["i2p.router.net.bw.inbound.1s"],
"bw-out" : result["i2p.router.net.bw.outbound.1s"]
});
@ -34,6 +35,7 @@ function requestRouterInfo(session) {
"i2p.router.netdb.knownpeers" : "",
"i2p.router.netdb.activepeers" : "",
"i2p.router.net.tunnels.participating" : "",
"i2p.router.net.tunnels.creationsuccessrate" : "",
"i2p.router.net.bw.inbound.1s" : "",
"i2p.router.net.bw.outbound.1s" : ""
}, updateRouterInfo);
@ -60,21 +62,27 @@ window.onload = function() {
</div>
<div class="content">
<h2 class="content-subhead">Tunnels participating: <span id="tunnels-participating"></span></h2>
<h2 class="content-subhead">Active peers: <span id="activepeers"></span></h2>
<h2 class="content-subhead">Known peers: <span id="knownpeers"></span></h2>
<h2 class="content-subhead">Bandwidth:
<h2 class="content-subhead">
Tunnels participating: <span id="tunnels-participating"></span>
</h2>
<h2 class="content-subhead">
Tunnel create success rate: <span id="tunnels-successrate"></span>
</h2>
<h2 class="content-subhead">
Active peers: <span id="activepeers"></span>
</h2>
<h2 class="content-subhead">
Known peers: <span id="knownpeers"></span>
</h2>
<h2 class="content-subhead">
Bandwidth:
in <span id="bw-in"></span> Bps /
out <span id="bw-out"></span> Bps
</h2>
</div>
<!--#include virtual="menu.html" -->
<!--#include virtual="footer.html" -->
<div id="main">
<noscript>
<div class="header"><h1>Please enable JavaScript!</h1></div>
</noscript>
</div>
</body>
</html>

View File

@ -4,6 +4,9 @@
<li class="menu-item">
<a href="index.html" class="menu-link">Home</a>
</li>
<li class="menu-item">
<a href="netdb.html" class="menu-link">Network Database</a>
</li>
<li class="menu-item">
<a href="#/config" class="menu-link">Configure</a>
</li>

59
webui/netdb.html Normal file
View File

@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Purple I2P 0.10.0 Webconsole</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="css/main.css">
<script type="text/javascript" src="javascript/I2PControl.js"></script>
<script type="text/javascript">
function updateNetDbInfo(result, session) {
if(session.error) {
alert("Error: " + session.error["message"]);
return;
}
I2PControl.updateDocument({
"knownpeers" : result["i2p.router.netdb.knownpeers"],
"activepeers" : result["i2p.router.netdb.activepeers"],
"floodfills" : result["i2p.router.netdb.floodfills"],
"leasesets" : result["i2p.router.netdb.leasesets"],
});
window.setTimeout(function() { requestNetDbInfo(session); }, 5000);
}
function requestNetDbInfo(session) {
session.request("RouterInfo", {
"i2p.router.netdb.knownpeers" : "",
"i2p.router.netdb.activepeers" : "",
"i2p.router.netdb.floodfills" : "",
"i2p.router.netdb.leasesets" : "",
}, updateNetDbInfo);
}
window.onload = function() {
var session = new I2PControl.Session("itoopie");
session.start(function() { requestNetDbInfo(session); });
};
</script>
</head>
<body>
<div class="header">
<h1>i2pd router console</h1>
<h2>Network Database Information</h2>
</div>
<div class="content">
<h2 class="content-subhead">Active peers: <span id="activepeers"></span></h2>
<h2 class="content-subhead">Known peers: <span id="knownpeers"></span></h2>
<h2 class="content-subhead">Floodfills: <span id="floodfills"></span></h2>
</br>
<h2 class="content-subhead">LeaseSets: <span id="leasesets"></span></h2>
</div>
<!--#include virtual="menu.html" -->
<!--#include virtual="footer.html" -->
</body>
</html>