diff --git a/HTTPServer.cpp b/HTTPServer.cpp index 0834b4d2..3ced372b 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -457,6 +457,10 @@ namespace util "//8AAAAH/////wAAAA//////gAAAH//////AAAA//////+AAAH//////+AAA///////+AAP///////+" "AH//////////////8="; + const char HTTP_COMMAND_TUNNELS[] = "tunnels"; + const char HTTP_COMMAND_TRANSIT_TUNNELS[] = "transit_tunnels"; + const char HTTP_COMMAND_TRANSPORTS[] = "transports"; + namespace misc_strings { @@ -539,7 +543,7 @@ namespace util void HTTPConnection::RunRequest () { auto address = ExtractAddress (); - if (address.length () > 1) // not just '/' + if (address.length () > 1 && address[1] != '?') // not just '/' or '/?' { std::string uri ("/"), b32; size_t pos = address.find ('/', 1); @@ -554,7 +558,7 @@ namespace util HandleDestinationRequest (b32, uri); } else - HandleRequest (); + HandleRequest (address); } std::string HTTPConnection::ExtractAddress () @@ -582,7 +586,7 @@ namespace util AsyncStreamReceive (); } - void HTTPConnection::HandleRequest () + void HTTPConnection::HandleRequest (const std::string& address) { std::stringstream s; // Html5 head start @@ -590,9 +594,12 @@ namespace util s << ""; // TODO: Find something to parse html/template system. This is horrible. s << "Purple I2Pd Webconsole"; + s << "' />Purple I2P Webconsole"; // Head end - FillContent (s); + if (address.length () > 1) + HandleCommand (address.substr (2), s); + else + FillContent (s); s << ""; SendReply (s.str ()); } @@ -621,7 +628,61 @@ namespace util s << "Floodfills: " << i2p::data::netdb.GetNumFloodfills () << " "; s << "LeaseSets: " << i2p::data::netdb.GetNumLeaseSets () << "
"; - s << "
Tunnels
"; + s << "
Tunnels
"; + s << "
Transit tunnels
"; + s << "
Transports
"; + + s << "

Flibusta

"; + } + + void HTTPConnection::HandleCommand (const std::string& command, std::stringstream& s) + { + if (command == HTTP_COMMAND_TRANSPORTS) + ShowTransports (s); + else if (command == HTTP_COMMAND_TUNNELS) + ShowTunnels (s); + else if (command == HTTP_COMMAND_TRANSIT_TUNNELS) + ShowTransitTunnels (s); + + } + + void HTTPConnection::ShowTransports (std::stringstream& s) + { + s << "NTCP
"; + for (auto it: i2p::transports.GetNTCPSessions ()) + { + // RouterInfo of incoming connection doesn't have address + bool outgoing = it.second->GetRemoteRouterInfo ().GetNTCPAddress (); + if (it.second->IsEstablished ()) + { + if (outgoing) s << "-->"; + s << it.second->GetRemoteRouterInfo ().GetIdentHashAbbreviation () << ": " + << it.second->GetSocket ().remote_endpoint().address ().to_string (); + if (!outgoing) s << "-->"; + s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; + s << "
"; + } + } + auto ssuServer = i2p::transports.GetSSUServer (); + if (ssuServer) + { + s << "
SSU
"; + for (auto it: ssuServer->GetSessions ()) + { + // incoming connections don't have remote router + bool outgoing = it.second->GetRemoteRouter (); + auto endpoint = it.second->GetRemoteEndpoint (); + if (outgoing) s << "-->"; + s << endpoint.address ().to_string () << ":" << endpoint.port (); + if (!outgoing) s << "-->"; + s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; + s << "
"; + } + } + } + + void HTTPConnection::ShowTunnels (std::stringstream& s) + { for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ()) { it->GetTunnelConfig ()->Print (s); @@ -647,8 +708,10 @@ namespace util s << " " << "Exp"; s << " " << (int)it.second->GetNumReceivedBytes () << "
"; } + } - s << "
Transit tunnels
"; + void HTTPConnection::ShowTransitTunnels (std::stringstream& s) + { for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ()) { if (dynamic_cast(it.second)) @@ -659,42 +722,8 @@ namespace util s << "-->" << it.second->GetTunnelID () << "-->"; s << " " << it.second->GetNumTransmittedBytes () << "
"; } - - s << "
Transports
"; - s << "NTCP
"; - for (auto it: i2p::transports.GetNTCPSessions ()) - { - // RouterInfo of incoming connection doesn't have address - bool outgoing = it.second->GetRemoteRouterInfo ().GetNTCPAddress (); - if (it.second->IsEstablished ()) - { - if (outgoing) s << "-->"; - s << it.second->GetRemoteRouterInfo ().GetIdentHashAbbreviation () << ": " - << it.second->GetSocket ().remote_endpoint().address ().to_string (); - if (!outgoing) s << "-->"; - s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; - s << "
"; - } - } - auto ssuServer = i2p::transports.GetSSUServer (); - if (ssuServer) - { - s << "
SSU
"; - for (auto it: ssuServer->GetSessions ()) - { - // incoming connections don't have remote router - bool outgoing = it.second->GetRemoteRouter (); - auto endpoint = it.second->GetRemoteEndpoint (); - if (outgoing) s << "-->"; - s << endpoint.address ().to_string () << ":" << endpoint.port (); - if (!outgoing) s << "-->"; - s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; - s << "
"; - } - } - s << "

Flibusta

"; } - + void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri) { std::string request = "GET " + uri + " HTTP/1.1\r\nHost:" + address + "\r\n"; @@ -856,54 +885,6 @@ namespace util { new HTTPConnection (m_NewSocket); } - -// eepSite. TODO: move away - - void HTTPConnection::EepAccept (i2p::stream::StreamingDestination * destination) - { - if (destination) - destination->SetAcceptor (std::bind (&HTTPConnection::HandleEepAccept, this, std::placeholders::_1)); - } - - void HTTPConnection::HandleEepAccept (i2p::stream::Stream * stream) - { - if (stream) - { - auto conn = new EepSiteDummyConnection (stream); - conn->AsyncStreamReceive (); - } - } - - void EepSiteDummyConnection::AsyncStreamReceive () - { - if (m_Stream) - m_Stream->AsyncReceive (boost::asio::buffer (m_StreamBuffer, 8192), - boost::bind (&EepSiteDummyConnection::HandleStreamReceive, this, - boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred), - 60); // 60 seconds timeout - } - - void EepSiteDummyConnection::HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred) - { - if (ecode) - { - LogPrint ("eepSite error: ", ecode.message ()); - DeleteStream (m_Stream); - } - else - { - std::string content (""); - content += "" + HTTPConnection::itoopieImage + ""; - std::string response ("HTTP/1.0 200 OK\r\n"); - response += "Content-Length: " + boost::lexical_cast(content.length()) + "\r\n"; - response += "Content-Type: text/html\r\n\r\n"; - response += content; - m_Stream->Send ((uint8_t *)response.c_str (), response.length (), 30); - m_Stream->Close (); - } - delete this; - } - } } diff --git a/HTTPServer.h b/HTTPServer.h index 0c0f44f6..28414062 100644 --- a/HTTPServer.h +++ b/HTTPServer.h @@ -57,13 +57,14 @@ namespace util void HandleWrite (const boost::system::error_code& ecode); void SendReply (const std::string& content, int status = 200); - void HandleRequest (); + void HandleRequest (const std::string& address); + void HandleCommand (const std::string& command, std::stringstream& s); + void ShowTransports (std::stringstream& s); + void ShowTunnels (std::stringstream& s); + void ShowTransitTunnels (std::stringstream& s); void FillContent (std::stringstream& s); std::string ExtractAddress (); - // for eepsite - void EepAccept (i2p::stream::StreamingDestination * destination); - void HandleEepAccept (i2p::stream::Stream * stream); protected: @@ -114,24 +115,6 @@ namespace util protected: virtual void CreateConnection(boost::asio::ip::tcp::socket * m_NewSocket); }; - - // TODO: move away - class EepSiteDummyConnection - { - public: - - EepSiteDummyConnection (i2p::stream::Stream * stream): m_Stream (stream) {}; - void AsyncStreamReceive (); - - private: - - void HandleStreamReceive (const boost::system::error_code& ecode, std::size_t bytes_transferred); - - private: - - i2p::stream::Stream * m_Stream; - char m_StreamBuffer[8192]; - }; } }