@ -22,6 +22,9 @@
# include "HTTPServer.h"
# include "HTTPServer.h"
# include "Daemon.h"
# include "Daemon.h"
# include "util.h"
# include "util.h"
# ifdef WIN32_APP
# include "Win32/Win32App.h"
# endif
// For image and info
// For image and info
# include "version.h"
# include "version.h"
@ -145,8 +148,10 @@ namespace http {
" <a href= \" /?page= " < < HTTP_PAGE_TUNNELS < < " \" >Tunnels</a><br> \r \n "
" <a href= \" /?page= " < < HTTP_PAGE_TUNNELS < < " \" >Tunnels</a><br> \r \n "
" <a href= \" /?page= " < < HTTP_PAGE_TRANSIT_TUNNELS < < " \" >Transit tunnels</a><br> \r \n "
" <a href= \" /?page= " < < HTTP_PAGE_TRANSIT_TUNNELS < < " \" >Transit tunnels</a><br> \r \n "
" <a href= \" /?page= " < < HTTP_PAGE_TRANSPORTS < < " \" >Transports</a><br> \r \n "
" <a href= \" /?page= " < < HTTP_PAGE_TRANSPORTS < < " \" >Transports</a><br> \r \n "
" <a href= \" /?page= " < < HTTP_PAGE_I2P_TUNNELS < < " \" >I2P tunnels</a><br> \r \n "
" <a href= \" /?page= " < < HTTP_PAGE_I2P_TUNNELS < < " \" >I2P tunnels</a><br> \r \n " ;
" <a href= \" /?page= " < < HTTP_PAGE_SAM_SESSIONS < < " \" >SAM sessions</a><br> \r \n "
if ( i2p : : client : : context . GetSAMBridge ( ) )
s < < " <a href= \" /?page= " < < HTTP_PAGE_SAM_SESSIONS < < " \" >SAM sessions</a><br> \r \n " ;
s < <
" </div> \r \n "
" </div> \r \n "
" <div class=right> " ;
" <div class=right> " ;
}
}
@ -207,7 +212,7 @@ namespace http {
s < < " <b>Router Family:</b> " < < i2p : : context . GetRouterInfo ( ) . GetProperty ( " family " ) < < " <br> \r \n " ;
s < < " <b>Router Family:</b> " < < i2p : : context . GetRouterInfo ( ) . GetProperty ( " family " ) < < " <br> \r \n " ;
s < < " <b>Router Caps:</b> " < < i2p : : context . GetRouterInfo ( ) . GetProperty ( " caps " ) < < " <br> \r \n " ;
s < < " <b>Router Caps:</b> " < < i2p : : context . GetRouterInfo ( ) . GetProperty ( " caps " ) < < " <br> \r \n " ;
s < < " <b>Our external address:</b> " < < " <br> \r \n " ;
s < < " <b>Our external address:</b> " < < " <br> \r \n " ;
for ( auto address : i2p : : context . GetRouterInfo ( ) . GetAddresses ( ) )
for ( const auto & address : i2p : : context . GetRouterInfo ( ) . GetAddresses ( ) )
{
{
switch ( address - > transportStyle )
switch ( address - > transportStyle )
{
{
@ -280,7 +285,7 @@ namespace http {
}
}
s < < " <br> \r \n " ;
s < < " <br> \r \n " ;
s < < " <b>Tags</b><br>Incoming: " < < dest - > GetNumIncomingTags ( ) < < " <br>Outgoing:<br> " < < std : : endl ;
s < < " <b>Tags</b><br>Incoming: " < < dest - > GetNumIncomingTags ( ) < < " <br>Outgoing:<br> " < < std : : endl ;
for ( auto it : dest - > GetSessions ( ) )
for ( const auto & it : dest - > GetSessions ( ) )
{
{
s < < i2p : : client : : context . GetAddressBook ( ) . ToAddress ( it . first ) < < " " ;
s < < i2p : : client : : context . GetAddressBook ( ) . ToAddress ( it . first ) < < " " ;
s < < it . second - > GetNumOutgoingTags ( ) < < " <br> " < < std : : endl ;
s < < it . second - > GetNumOutgoingTags ( ) < < " <br> " < < std : : endl ;
@ -311,7 +316,7 @@ namespace http {
s < < " <th>Status</th> " ;
s < < " <th>Status</th> " ;
s < < " </tr> " ;
s < < " </tr> " ;
for ( auto it : dest - > GetAllStreams ( ) )
for ( const auto & it : dest - > GetAllStreams ( ) )
{
{
s < < " <tr> " ;
s < < " <tr> " ;
s < < " <td> " < < it - > GetSendStreamID ( ) < < " </td> " ;
s < < " <td> " < < it - > GetSendStreamID ( ) < < " </td> " ;
@ -331,7 +336,7 @@ namespace http {
void ShowLeasesSets ( std : : stringstream & s )
void ShowLeasesSets ( std : : stringstream & s )
{
{
s < < " <div id='leasesets'>LeaseSets</div><br> " ;
s < < " <div id='leasesets'><b> LeaseSets:</b> </div><br> " ;
// for each lease set
// for each lease set
i2p : : data : : netdb . VisitLeaseSets (
i2p : : data : : netdb . VisitLeaseSets (
[ & s ] ( const i2p : : data : : IdentHash dest , std : : shared_ptr < i2p : : data : : LeaseSet > leaseSet )
[ & s ] ( const i2p : : data : : IdentHash dest , std : : shared_ptr < i2p : : data : : LeaseSet > leaseSet )
@ -409,28 +414,34 @@ namespace http {
else
else
s < < " <a href= \" /?cmd= " < < HTTP_COMMAND_ENABLE_TRANSIT < < " \" >Accept transit tunnels</a><br> \r \n " ;
s < < " <a href= \" /?cmd= " < < HTTP_COMMAND_ENABLE_TRANSIT < < " \" >Accept transit tunnels</a><br> \r \n " ;
# if (!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID))
# if (!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID))
if ( Daemon . gracefullShutdownInterval ) {
if ( Daemon . gracefullShutdownInterval )
{
s < < " <a href= \" /?cmd= " < < HTTP_COMMAND_SHUTDOWN_CANCEL < < " \" >Cancel gracefull shutdown ( " ;
s < < " <a href= \" /?cmd= " < < HTTP_COMMAND_SHUTDOWN_CANCEL < < " \" >Cancel gracefull shutdown ( " ;
s < < Daemon . gracefullShutdownInterval ;
s < < Daemon . gracefullShutdownInterval ;
s < < " seconds remains)</a><br> \r \n " ;
s < < " seconds remains)</a><br> \r \n " ;
} else {
}
else
{
s < < " <a href= \" /?cmd= " < < HTTP_COMMAND_SHUTDOWN_START < < " \" >Start gracefull shutdown</a><br> \r \n " ;
s < < " <a href= \" /?cmd= " < < HTTP_COMMAND_SHUTDOWN_START < < " \" >Start gracefull shutdown</a><br> \r \n " ;
}
}
s < < " <a href= \" /?cmd= " < < HTTP_COMMAND_SHUTDOWN_NOW < < " \" >Force shutdown</a><br> \r \n " ;
# endif
# endif
# ifdef WIN32_APP
s < < " <a href= \" /?cmd= " < < HTTP_COMMAND_SHUTDOWN_START < < " \" >Gracefull shutdown</a><br> \r \n " ;
# endif
s < < " <a href= \" /?cmd= " < < HTTP_COMMAND_SHUTDOWN_NOW < < " \" >Force shutdown</a><br> \r \n " ;
}
}
void ShowTransitTunnels ( std : : stringstream & s )
void ShowTransitTunnels ( std : : stringstream & s )
{
{
s < < " <b>Transit tunnels:</b><br> \r \n <br> \r \n " ;
s < < " <b>Transit tunnels:</b><br> \r \n <br> \r \n " ;
for ( auto it : i2p : : tunnel : : tunnels . GetTransitTunnels ( ) )
for ( const auto & it : i2p : : tunnel : : tunnels . GetTransitTunnels ( ) )
{
{
if ( std : : dynamic_pointer_cast < i2p : : tunnel : : TransitTunnelGateway > ( it ) )
if ( std : : dynamic_pointer_cast < i2p : : tunnel : : TransitTunnelGateway > ( it ) )
s < < it - > GetTunnelID ( ) < < " ⇒ " ;
s < < it - > GetTunnelID ( ) < < " ⇒ " ;
else if ( std : : dynamic_pointer_cast < i2p : : tunnel : : TransitTunnelEndpoint > ( it ) )
else if ( std : : dynamic_pointer_cast < i2p : : tunnel : : TransitTunnelEndpoint > ( it ) )
s < < " ⇒ " < < it - > GetTunnelID ( ) ;
s < < " ⇒ " < < it - > GetTunnelID ( ) ;
else
else
s < < " ⇒ " < < it - > GetTunnelID ( ) < < " ⇒ " ;
s < < " ⇒ " < < it - > GetTunnelID ( ) < < " ⇒ " ;
s < < " " < < it - > GetNumTransmittedBytes ( ) < < " <br> \r \n " ;
s < < " " < < it - > GetNumTransmittedBytes ( ) < < " <br> \r \n " ;
}
}
}
}
@ -442,15 +453,15 @@ namespace http {
if ( ntcpServer )
if ( ntcpServer )
{
{
s < < " <b>NTCP</b><br> \r \n " ;
s < < " <b>NTCP</b><br> \r \n " ;
for ( auto it : ntcpServer - > GetNTCPSessions ( ) )
for ( const auto & it : ntcpServer - > GetNTCPSessions ( ) )
{
{
if ( it . second & & it . second - > IsEstablished ( ) )
if ( it . second & & it . second - > IsEstablished ( ) )
{
{
// incoming connection doesn't have remote RI
// incoming connection doesn't have remote RI
if ( it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
if ( it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
s < < i2p : : data : : GetIdentHashAbbreviation ( it . second - > GetRemoteIdentity ( ) - > GetIdentHash ( ) ) < < " : "
s < < i2p : : data : : GetIdentHashAbbreviation ( it . second - > GetRemoteIdentity ( ) - > GetIdentHash ( ) ) < < " : "
< < it . second - > GetSocket ( ) . remote_endpoint ( ) . address ( ) . to_string ( ) ;
< < it . second - > GetSocket ( ) . remote_endpoint ( ) . address ( ) . to_string ( ) ;
if ( ! it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
if ( ! it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
s < < " [ " < < it . second - > GetNumSentBytes ( ) < < " : " < < it . second - > GetNumReceivedBytes ( ) < < " ] " ;
s < < " [ " < < it . second - > GetNumSentBytes ( ) < < " : " < < it . second - > GetNumReceivedBytes ( ) < < " ] " ;
s < < " <br> \r \n " < < std : : endl ;
s < < " <br> \r \n " < < std : : endl ;
}
}
@ -460,24 +471,24 @@ namespace http {
if ( ssuServer )
if ( ssuServer )
{
{
s < < " <br> \r \n <b>SSU</b><br> \r \n " ;
s < < " <br> \r \n <b>SSU</b><br> \r \n " ;
for ( auto it : ssuServer - > GetSessions ( ) )
for ( const auto & it : ssuServer - > GetSessions ( ) )
{
{
auto endpoint = it . second - > GetRemoteEndpoint ( ) ;
auto endpoint = it . second - > GetRemoteEndpoint ( ) ;
if ( it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
if ( it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
s < < endpoint . address ( ) . to_string ( ) < < " : " < < endpoint . port ( ) ;
s < < endpoint . address ( ) . to_string ( ) < < " : " < < endpoint . port ( ) ;
if ( ! it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
if ( ! it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
s < < " [ " < < it . second - > GetNumSentBytes ( ) < < " : " < < it . second - > GetNumReceivedBytes ( ) < < " ] " ;
s < < " [ " < < it . second - > GetNumSentBytes ( ) < < " : " < < it . second - > GetNumReceivedBytes ( ) < < " ] " ;
if ( it . second - > GetRelayTag ( ) )
if ( it . second - > GetRelayTag ( ) )
s < < " [itag: " < < it . second - > GetRelayTag ( ) < < " ] " ;
s < < " [itag: " < < it . second - > GetRelayTag ( ) < < " ] " ;
s < < " <br> \r \n " < < std : : endl ;
s < < " <br> \r \n " < < std : : endl ;
}
}
s < < " <br> \r \n <b>SSU6</b><br> \r \n " ;
s < < " <br> \r \n <b>SSU6</b><br> \r \n " ;
for ( auto it : ssuServer - > GetSessionsV6 ( ) )
for ( const auto & it : ssuServer - > GetSessionsV6 ( ) )
{
{
auto endpoint = it . second - > GetRemoteEndpoint ( ) ;
auto endpoint = it . second - > GetRemoteEndpoint ( ) ;
if ( it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
if ( it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
s < < endpoint . address ( ) . to_string ( ) < < " : " < < endpoint . port ( ) ;
s < < endpoint . address ( ) . to_string ( ) < < " : " < < endpoint . port ( ) ;
if ( ! it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
if ( ! it . second - > IsOutgoing ( ) ) s < < " ⇒ " ;
s < < " [ " < < it . second - > GetNumSentBytes ( ) < < " : " < < it . second - > GetNumReceivedBytes ( ) < < " ] " ;
s < < " [ " < < it . second - > GetNumSentBytes ( ) < < " : " < < it . second - > GetNumReceivedBytes ( ) < < " ] " ;
s < < " <br> \r \n " < < std : : endl ;
s < < " <br> \r \n " < < std : : endl ;
}
}
@ -517,7 +528,7 @@ namespace http {
s < < i2p : : client : : context . GetAddressBook ( ) . ToAddress ( ident ) < < " </a><br> \r \n " ;
s < < i2p : : client : : context . GetAddressBook ( ) . ToAddress ( ident ) < < " </a><br> \r \n " ;
s < < " <br> \r \n " ;
s < < " <br> \r \n " ;
s < < " <b>Streams:</b><br> \r \n " ;
s < < " <b>Streams:</b><br> \r \n " ;
for ( auto it : session - > ListSockets ( ) )
for ( const auto & it : session - > ListSockets ( ) )
{
{
switch ( it - > GetSocketType ( ) )
switch ( it - > GetSocketType ( ) )
{
{
@ -538,7 +549,7 @@ namespace http {
{
{
auto & ident = it . second - > GetLocalDestination ( ) - > GetIdentHash ( ) ;
auto & ident = it . second - > GetLocalDestination ( ) - > GetIdentHash ( ) ;
s < < " <a href= \" /?page= " < < HTTP_PAGE_LOCAL_DESTINATION < < " &b32= " < < ident . ToBase32 ( ) < < " \" > " ;
s < < " <a href= \" /?page= " < < HTTP_PAGE_LOCAL_DESTINATION < < " &b32= " < < ident . ToBase32 ( ) < < " \" > " ;
s < < it . second - > GetName ( ) < < " </a> ⇐ " ;
s < < it . second - > GetName ( ) < < " </a> ⇐ " ;
s < < i2p : : client : : context . GetAddressBook ( ) . ToAddress ( ident ) ;
s < < i2p : : client : : context . GetAddressBook ( ) . ToAddress ( ident ) ;
s < < " <br> \r \n " < < std : : endl ;
s < < " <br> \r \n " < < std : : endl ;
}
}
@ -547,7 +558,7 @@ namespace http {
{
{
auto & ident = it . second - > GetLocalDestination ( ) - > GetIdentHash ( ) ;
auto & ident = it . second - > GetLocalDestination ( ) - > GetIdentHash ( ) ;
s < < " <a href= \" /?page= " < < HTTP_PAGE_LOCAL_DESTINATION < < " &b32= " < < ident . ToBase32 ( ) < < " \" > " ;
s < < " <a href= \" /?page= " < < HTTP_PAGE_LOCAL_DESTINATION < < " &b32= " < < ident . ToBase32 ( ) < < " \" > " ;
s < < it . second - > GetName ( ) < < " </a> ⇒ " ;
s < < it . second - > GetName ( ) < < " </a> ⇒ " ;
s < < i2p : : client : : context . GetAddressBook ( ) . ToAddress ( ident ) ;
s < < i2p : : client : : context . GetAddressBook ( ) . ToAddress ( ident ) ;
s < < " : " < < it . second - > GetLocalPort ( ) ;
s < < " : " < < it . second - > GetLocalPort ( ) ;
s < < " </a><br> \r \n " < < std : : endl ;
s < < " </a><br> \r \n " < < std : : endl ;
@ -723,6 +734,9 @@ namespace http {
i2p : : context . SetAcceptsTunnels ( false ) ;
i2p : : context . SetAcceptsTunnels ( false ) ;
# if (!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID))
# if (!defined(WIN32) && !defined(QT_GUI_LIB) && !defined(ANDROID))
Daemon . gracefullShutdownInterval = 10 * 60 ;
Daemon . gracefullShutdownInterval = 10 * 60 ;
# endif
# ifdef WIN32_APP
i2p : : win32 : : GracefulShutdown ( ) ;
# endif
# endif
} else if ( cmd = = HTTP_COMMAND_SHUTDOWN_CANCEL ) {
} else if ( cmd = = HTTP_COMMAND_SHUTDOWN_CANCEL ) {
i2p : : context . SetAcceptsTunnels ( true ) ;
i2p : : context . SetAcceptsTunnels ( true ) ;
@ -770,12 +784,14 @@ namespace http {
std : : string pass ; i2p : : config : : GetOption ( " http.pass " , pass ) ;
std : : string pass ; i2p : : config : : GetOption ( " http.pass " , pass ) ;
/* generate pass if needed */
/* generate pass if needed */
if ( needAuth & & pass = = " " ) {
if ( needAuth & & pass = = " " ) {
uint8_t random [ 16 ] ;
char alnum [ ] = " 0123456789 "
char alnum [ ] = " 0123456789 "
" ABCDEFGHIJKLMNOPQRSTUVWXYZ "
" ABCDEFGHIJKLMNOPQRSTUVWXYZ "
" abcdefghijklmnopqrstuvwxyz " ;
" abcdefghijklmnopqrstuvwxyz " ;
pass . resize ( 16 ) ;
pass . resize ( sizeof ( random ) ) ;
for ( size_t i = 0 ; i < pass . size ( ) ; i + + ) {
RAND_bytes ( random , sizeof ( random ) ) ;
pass [ i ] = alnum [ rand ( ) % ( sizeof ( alnum ) - 1 ) ] ;
for ( size_t i = 0 ; i < sizeof ( random ) ; i + + ) {
pass [ i ] = alnum [ random [ i ] % ( sizeof ( alnum ) - 1 ) ] ;
}
}
i2p : : config : : SetOption ( " http.pass " , pass ) ;
i2p : : config : : SetOption ( " http.pass " , pass ) ;
LogPrint ( eLogInfo , " HTTPServer: password set to " , pass ) ;
LogPrint ( eLogInfo , " HTTPServer: password set to " , pass ) ;