From a0816b04e59f0b5a4eac786ff5e0aa35062b0789 Mon Sep 17 00:00:00 2001 From: orignal Date: Tue, 12 Jan 2016 20:31:25 -0500 Subject: [PATCH] purple links, coloured tunnels --- HTTPServer.cpp | 269 ++++++++++++++++++++++++++----------------------- 1 file changed, 141 insertions(+), 128 deletions(-) diff --git a/HTTPServer.cpp b/HTTPServer.cpp index f1c91793..40edd5c7 100644 --- a/HTTPServer.cpp +++ b/HTTPServer.cpp @@ -357,34 +357,52 @@ namespace util std::stringstream s; // Html5 head start s << "\n"; // TODO: Add support for locale. - s << ""; // TODO: Find something to parse html/template system. This is horrible. + s << ""; // TODO: Find something to parse html/template system. This is horrible. s << ""; - s << "Purple I2P " << VERSION " Webconsole"; + s << "' />Purple I2P " << VERSION " Webconsole"; s << ""; - s << ""; - // Head end + s << ""; + s << "
"; + s << "

i2pd webconsole

"; + s << "
"; + s << "
"; + s << "
"; + s << "Main page

"; + s << "Local destinations
"; + s << "Tunnels
"; + s << "Transit tunnels
"; + s << "Transports

"; + if (i2p::client::context.GetSAMBridge ()) + s << "SAM sessions

"; + if (i2p::context.AcceptsTunnels ()) + s << "Stop accepting tunnels

"; + else + s << "Start accepting tunnels

"; + s << "Run peer test

"; + s << "
"; if (address.length () > 1) HandleCommand (address.substr (2), s); else FillContent (s); - s << ""; + s << "
"; SendReply (s.str ()); } void HTTPConnection::FillContent (std::stringstream& s) { - s << "
i2pd webconsole
"; - s << "
"; - s << "
"; s << "Uptime: " << boost::posix_time::to_simple_string ( boost::posix_time::time_duration (boost::posix_time::seconds ( i2p::context.GetUptime ()))) << "
"; @@ -428,19 +446,6 @@ namespace util s << "
Routers: " << i2p::data::netdb.GetNumRouters () << " "; s << "Floodfills: " << i2p::data::netdb.GetNumFloodfills () << " "; s << "LeaseSets: " << i2p::data::netdb.GetNumLeaseSets () << "
"; - s << "
"; - s << "[ Local destinations ]
"; - s << "[ Tunnels ]
"; - s << "[ Transit tunnels ]
"; - s << "[ Transports ]
"; - if (i2p::client::context.GetSAMBridge ()) - s << "[ SAM sessions ]

"; - if (i2p::context.AcceptsTunnels ()) - s << "[ Stop accepting tunnels ]

"; - else - s << "[ Start accepting tunnels ]

"; - s << "[ Run peer test ]

"; - s << "
"; } void HTTPConnection::HandleCommand (const std::string& command, std::stringstream& s) @@ -479,100 +484,9 @@ namespace util } } - void HTTPConnection::ShowTransports (std::stringstream& s) - { - auto ntcpServer = i2p::transport::transports.GetNTCPServer (); - if (ntcpServer) - { - s << "NTCP
"; - for (auto it: ntcpServer->GetNTCPSessions ()) - { - if (it.second && it.second->IsEstablished ()) - { - // incoming connection doesn't have remote RI - if (it.second->IsOutgoing ()) s << "-->"; - s << i2p::data::GetIdentHashAbbreviation (it.second->GetRemoteIdentity ()->GetIdentHash ()) << ": " - << it.second->GetSocket ().remote_endpoint().address ().to_string (); - if (!it.second->IsOutgoing ()) s << "-->"; - s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; - s << "
"; - } - s << std::endl; - } - } - auto ssuServer = i2p::transport::transports.GetSSUServer (); - if (ssuServer) - { - s << "
SSU
"; - for (auto it: ssuServer->GetSessions ()) - { - auto endpoint = it.second->GetRemoteEndpoint (); - if (it.second->IsOutgoing ()) s << "-->"; - s << endpoint.address ().to_string () << ":" << endpoint.port (); - if (!it.second->IsOutgoing ()) s << "-->"; - s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; - if (it.second->GetRelayTag ()) - s << " [itag:" << it.second->GetRelayTag () << "]"; - s << "
" << std::endl; - } - s << "
SSU6
"; - for (auto it: ssuServer->GetSessionsV6 ()) - { - auto endpoint = it.second->GetRemoteEndpoint (); - if (it.second->IsOutgoing ()) s << "-->"; - s << endpoint.address ().to_string () << ":" << endpoint.port (); - if (!it.second->IsOutgoing ()) s << "-->"; - s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; - s << "
" << std::endl; - } - } - } - - void HTTPConnection::ShowTunnels (std::stringstream& s) - { - s << "Queue size:" << i2p::tunnel::tunnels.GetQueueSize () << "
"; - - for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ()) - { - it->Print (s); - auto state = it->GetState (); - if (state == i2p::tunnel::eTunnelStateFailed) - s << " " << "Failed"; - else if (state == i2p::tunnel::eTunnelStateExpiring) - s << " " << "Exp"; - s << " " << (int)it->GetNumSentBytes () << "
"; - s << std::endl; - } - - for (auto it: i2p::tunnel::tunnels.GetInboundTunnels ()) - { - it.second->Print (s); - auto state = it.second->GetState (); - if (state == i2p::tunnel::eTunnelStateFailed) - s << " " << "Failed"; - else if (state == i2p::tunnel::eTunnelStateExpiring) - s << " " << "Exp"; - s << " " << (int)it.second->GetNumReceivedBytes () << "
"; - s << std::endl; - } - } - - void HTTPConnection::ShowTransitTunnels (std::stringstream& s) - { - for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ()) - { - if (dynamic_cast(it.second)) - s << it.second->GetTunnelID () << "-->"; - else if (dynamic_cast(it.second)) - s << "-->" << it.second->GetTunnelID (); - else - s << "-->" << it.second->GetTunnelID () << "-->"; - s << " " << it.second->GetNumTransmittedBytes () << "
"; - } - } - void HTTPConnection::ShowLocalDestinations (std::stringstream& s) { + s << "Local Destinations:

"; for (auto& it: i2p::client::context.GetDestinations ()) { auto ident = it.second->GetIdentHash ();; @@ -580,10 +494,11 @@ namespace util s << "&" << HTTP_PARAM_BASE32_ADDRESS << "=" << ident.ToBase32 () << ">"; s << i2p::client::context.GetAddressBook ().ToAddress(ident) << "
" << std::endl; } - } + } void HTTPConnection::ShowLocalDestination (const std::string& b32, std::stringstream& s) { + s << "Local Destination:

"; i2p::data::IdentHash ident; ident.FromBase32 (b32); auto dest = i2p::client::context.FindLocalDestination (ident); @@ -629,10 +544,104 @@ namespace util s << "
"<< std::endl; } } + } + + void HTTPConnection::ShowTunnels (std::stringstream& s) + { + s << "Tunnels:

"; + s << "Queue size:" << i2p::tunnel::tunnels.GetQueueSize () << "
"; + for (auto it: i2p::tunnel::tunnels.GetOutboundTunnels ()) + { + it->Print (s); + auto state = it->GetState (); + if (state == i2p::tunnel::eTunnelStateFailed) + s << " " << "Failed"; + else if (state == i2p::tunnel::eTunnelStateExpiring) + s << " " << "Exp"; + s << " " << (int)it->GetNumSentBytes () << "
"; + s << std::endl; + } + + for (auto it: i2p::tunnel::tunnels.GetInboundTunnels ()) + { + it.second->Print (s); + auto state = it.second->GetState (); + if (state == i2p::tunnel::eTunnelStateFailed) + s << " " << "Failed"; + else if (state == i2p::tunnel::eTunnelStateExpiring) + s << " " << "Exp"; + s << " " << (int)it.second->GetNumReceivedBytes () << "
"; + s << std::endl; + } } + void HTTPConnection::ShowTransitTunnels (std::stringstream& s) + { + s << "Transit tunnels:

"; + for (auto it: i2p::tunnel::tunnels.GetTransitTunnels ()) + { + if (dynamic_cast(it.second)) + s << it.second->GetTunnelID () << "-->"; + else if (dynamic_cast(it.second)) + s << "-->" << it.second->GetTunnelID (); + else + s << "-->" << it.second->GetTunnelID () << "-->"; + s << " " << it.second->GetNumTransmittedBytes () << "
"; + } + } + + void HTTPConnection::ShowTransports (std::stringstream& s) + { + s << "Transports:

"; + auto ntcpServer = i2p::transport::transports.GetNTCPServer (); + if (ntcpServer) + { + s << "NTCP
"; + for (auto it: ntcpServer->GetNTCPSessions ()) + { + if (it.second && it.second->IsEstablished ()) + { + // incoming connection doesn't have remote RI + if (it.second->IsOutgoing ()) s << "-->"; + s << i2p::data::GetIdentHashAbbreviation (it.second->GetRemoteIdentity ()->GetIdentHash ()) << ": " + << it.second->GetSocket ().remote_endpoint().address ().to_string (); + if (!it.second->IsOutgoing ()) s << "-->"; + s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; + } + s << "
" << std::endl; + } + } + auto ssuServer = i2p::transport::transports.GetSSUServer (); + if (ssuServer) + { + s << "
SSU
"; + for (auto it: ssuServer->GetSessions ()) + { + auto endpoint = it.second->GetRemoteEndpoint (); + if (it.second->IsOutgoing ()) s << "-->"; + s << endpoint.address ().to_string () << ":" << endpoint.port (); + if (!it.second->IsOutgoing ()) s << "-->"; + s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; + if (it.second->GetRelayTag ()) + s << " [itag:" << it.second->GetRelayTag () << "]"; + s << "
" << std::endl; + } + s << "
SSU6
"; + for (auto it: ssuServer->GetSessionsV6 ()) + { + auto endpoint = it.second->GetRemoteEndpoint (); + if (it.second->IsOutgoing ()) s << "-->"; + s << endpoint.address ().to_string () << ":" << endpoint.port (); + if (!it.second->IsOutgoing ()) s << "-->"; + s << " [" << it.second->GetNumSentBytes () << ":" << it.second->GetNumReceivedBytes () << "]"; + s << "
" << std::endl; + } + } + } + void HTTPConnection::ShowSAMSessions (std::stringstream& s) { + s << "SAM Sessions:

"; auto sam = i2p::client::context.GetSAMBridge (); if (sam) { @@ -647,6 +656,7 @@ namespace util void HTTPConnection::ShowSAMSession (const std::string& id, std::stringstream& s) { + s << "SAM Session:

"; auto sam = i2p::client::context.GetSAMBridge (); if (sam) { @@ -680,23 +690,26 @@ namespace util } } } - - void HTTPConnection::StartAcceptingTunnels (std::stringstream& s) - { - i2p::context.SetAcceptsTunnels (true); - s << "Accepting tunnels started" << std::endl; - } void HTTPConnection::StopAcceptingTunnels (std::stringstream& s) { + s << "Stop Accepting Tunnels:

"; i2p::context.SetAcceptsTunnels (false); s << "Accepting tunnels stopped" << std::endl; } + void HTTPConnection::StartAcceptingTunnels (std::stringstream& s) + { + s << "Start Accepting Tunnels:

"; + i2p::context.SetAcceptsTunnels (true); + s << "Accepting tunnels started" << std::endl; + } + void HTTPConnection::RunPeerTest (std::stringstream& s) { + s << "Run Peer Test:

"; i2p::transport::transports.PeerTest (); - s << "Peer test" << std::endl; + s << "Peer test is running" << std::endl; } void HTTPConnection::HandleDestinationRequest (const std::string& address, const std::string& uri)