@ -80,8 +80,9 @@ namespace proxy {
/* error helpers */
/* error helpers */
void GenericProxyError ( const std : : string & title , const std : : string & description ) ;
void GenericProxyError ( const std : : string & title , const std : : string & description ) ;
void GenericProxyInfo ( const std : : string & title , const std : : string & description ) ;
void GenericProxyInfo ( const std : : string & title , const std : : string & description ) ;
void HostNotFound ( std : : string & host ) ;
void HostNotFound ( std : : string & host ) ;
void SendProxyError ( std : : string & content ) ;
void SendProxyError ( std : : string & content ) ;
void SendRedirect ( std : : string & address ) ;
void ForwardToUpstreamProxy ( ) ;
void ForwardToUpstreamProxy ( ) ;
void HandleUpstreamHTTPProxyConnect ( const boost : : system : : error_code & ec ) ;
void HandleUpstreamHTTPProxyConnect ( const boost : : system : : error_code & ec ) ;
@ -174,7 +175,7 @@ namespace proxy {
SendProxyError ( content ) ;
SendProxyError ( content ) ;
}
}
void HTTPReqHandler : : HostNotFound ( std : : string & host ) {
void HTTPReqHandler : : HostNotFound ( std : : string & host ) {
std : : stringstream ss ;
std : : stringstream ss ;
ss < < " <h1> " < < tr ( " Proxy error: Host not found " ) < < " </h1> \r \n "
ss < < " <h1> " < < tr ( " Proxy error: Host not found " ) < < " </h1> \r \n "
< < " <p> " < < tr ( " Remote host not found in router's addressbook " ) < < " </p> \r \n "
< < " <p> " < < tr ( " Remote host not found in router's addressbook " ) < < " </p> \r \n "
@ -191,7 +192,7 @@ namespace proxy {
SendProxyError ( content ) ;
SendProxyError ( content ) ;
}
}
void HTTPReqHandler : : SendProxyError ( std : : string & content )
void HTTPReqHandler : : SendProxyError ( std : : string & content )
{
{
i2p : : http : : HTTPRes res ;
i2p : : http : : HTTPRes res ;
res . code = 500 ;
res . code = 500 ;
@ -207,6 +208,17 @@ namespace proxy {
std : : bind ( & HTTPReqHandler : : SentHTTPFailed , shared_from_this ( ) , std : : placeholders : : _1 ) ) ;
std : : bind ( & HTTPReqHandler : : SentHTTPFailed , shared_from_this ( ) , std : : placeholders : : _1 ) ) ;
}
}
void HTTPReqHandler : : SendRedirect ( std : : string & address )
{
i2p : : http : : HTTPRes res ;
res . code = 302 ;
res . add_header ( " Location " , address ) ;
res . add_header ( " Connection " , " close " ) ;
std : : string response = res . to_string ( ) ;
boost : : asio : : async_write ( * m_sock , boost : : asio : : buffer ( response ) , boost : : asio : : transfer_all ( ) ,
std : : bind ( & HTTPReqHandler : : SentHTTPFailed , shared_from_this ( ) , std : : placeholders : : _1 ) ) ;
}
bool HTTPReqHandler : : ExtractAddressHelper ( i2p : : http : : URL & url , std : : string & b64 , bool & confirm )
bool HTTPReqHandler : : ExtractAddressHelper ( i2p : : http : : URL & url , std : : string & b64 , bool & confirm )
{
{
confirm = false ;
confirm = false ;
@ -297,7 +309,14 @@ namespace proxy {
GenericProxyError ( tr ( " Invalid request " ) , tr ( " addresshelper is not supported " ) ) ;
GenericProxyError ( tr ( " Invalid request " ) , tr ( " addresshelper is not supported " ) ) ;
return true ;
return true ;
}
}
if ( ! i2p : : client : : context . GetAddressBook ( ) . FindAddress ( m_RequestURL . host ) | | m_Confirm )
if ( i2p : : client : : context . GetAddressBook ( ) . RecordExists ( m_RequestURL . host , jump ) )
{
std : : string full_url = m_RequestURL . to_string ( ) ;
SendRedirect ( full_url ) ;
return true ;
}
else if ( ! i2p : : client : : context . GetAddressBook ( ) . FindAddress ( m_RequestURL . host ) | | m_Confirm )
{
{
i2p : : client : : context . GetAddressBook ( ) . InsertAddress ( m_RequestURL . host , jump ) ;
i2p : : client : : context . GetAddressBook ( ) . InsertAddress ( m_RequestURL . host , jump ) ;
LogPrint ( eLogInfo , " HTTPProxy: Added address from addresshelper for " , m_RequestURL . host ) ;
LogPrint ( eLogInfo , " HTTPProxy: Added address from addresshelper for " , m_RequestURL . host ) ;
@ -313,7 +332,8 @@ namespace proxy {
std : : string full_url = m_RequestURL . to_string ( ) ;
std : : string full_url = m_RequestURL . to_string ( ) ;
std : : stringstream ss ;
std : : stringstream ss ;
ss < < tr ( " Host " ) < < " " < < m_RequestURL . host < < " <font color=red> " < < tr ( " already in router's addressbook " ) < < " </font>. " ;
ss < < tr ( " Host " ) < < " " < < m_RequestURL . host < < " <font color=red> " < < tr ( " already in router's addressbook " ) < < " </font>. " ;
ss < < tr ( /* tr: The "record" means addressbook's record. That message appears when domain was already added to addressbook, but helper link is opened for it. */ " Click here to update record: " ) < < " <a href= \" " < < full_url < < ( full_url . find ( ' ? ' ) ! = std : : string : : npos ? " &i2paddresshelper= " : " ?i2paddresshelper= " ) ;
ss < < tr ( /* tr: The "record" means addressbook's record. That message appears when domain was already added to addressbook, but helper link is opened for it. */ " Click here to update record: " ) ;
ss < < " <a href= \" " < < full_url < < ( full_url . find ( ' ? ' ) ! = std : : string : : npos ? " &i2paddresshelper= " : " ?i2paddresshelper= " ) ;
ss < < jump < < " &update=true \" > " < < tr ( " Continue " ) < < " </a>. " ;
ss < < jump < < " &update=true \" > " < < tr ( " Continue " ) < < " </a>. " ;
GenericProxyInfo ( tr ( " Addresshelper found " ) , ss . str ( ) ) ;
GenericProxyInfo ( tr ( " Addresshelper found " ) , ss . str ( ) ) ;
return true ; /* request processed */
return true ; /* request processed */