|
|
@ -54,7 +54,7 @@ namespace proxy { |
|
|
|
void HandleSockRecv(const boost::system::error_code & ecode, std::size_t bytes_transfered); |
|
|
|
void HandleSockRecv(const boost::system::error_code & ecode, std::size_t bytes_transfered); |
|
|
|
void Terminate(); |
|
|
|
void Terminate(); |
|
|
|
void AsyncSockRead(); |
|
|
|
void AsyncSockRead(); |
|
|
|
bool ExtractAddressHelper(i2p::http::URL & url, std::string & b64); |
|
|
|
bool ExtractAddressHelper(i2p::http::URL & url, std::string & b64, bool & confirm); |
|
|
|
void SanitizeHTTPRequest(i2p::http::HTTPReq & req); |
|
|
|
void SanitizeHTTPRequest(i2p::http::HTTPReq & req); |
|
|
|
void SentHTTPFailed(const boost::system::error_code & ecode); |
|
|
|
void SentHTTPFailed(const boost::system::error_code & ecode); |
|
|
|
void HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream); |
|
|
|
void HandleStreamRequestComplete (std::shared_ptr<i2p::stream::Stream> stream); |
|
|
@ -182,13 +182,15 @@ namespace proxy { |
|
|
|
std::bind(&HTTPReqHandler::SentHTTPFailed, shared_from_this(), std::placeholders::_1)); |
|
|
|
std::bind(&HTTPReqHandler::SentHTTPFailed, shared_from_this(), std::placeholders::_1)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool HTTPReqHandler::ExtractAddressHelper(i2p::http::URL & url, std::string & b64) |
|
|
|
bool HTTPReqHandler::ExtractAddressHelper(i2p::http::URL & url, std::string & b64, bool & confirm) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
confirm = false; |
|
|
|
const char *param = "i2paddresshelper="; |
|
|
|
const char *param = "i2paddresshelper="; |
|
|
|
std::size_t pos = url.query.find(param); |
|
|
|
std::size_t pos = url.query.find(param); |
|
|
|
std::size_t len = std::strlen(param); |
|
|
|
std::size_t len = std::strlen(param); |
|
|
|
std::map<std::string, std::string> params; |
|
|
|
std::map<std::string, std::string> params; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (pos == std::string::npos) |
|
|
|
if (pos == std::string::npos) |
|
|
|
return false; /* not found */ |
|
|
|
return false; /* not found */ |
|
|
|
if (!url.parse_query(params)) |
|
|
|
if (!url.parse_query(params)) |
|
|
@ -197,6 +199,8 @@ namespace proxy { |
|
|
|
std::string value = params["i2paddresshelper"]; |
|
|
|
std::string value = params["i2paddresshelper"]; |
|
|
|
len += value.length(); |
|
|
|
len += value.length(); |
|
|
|
b64 = i2p::http::UrlDecode(value); |
|
|
|
b64 = i2p::http::UrlDecode(value); |
|
|
|
|
|
|
|
// if we need update exists, request formed with update param
|
|
|
|
|
|
|
|
if (params["update"] == "true") { len += std::strlen("&update=true"); confirm = true; } |
|
|
|
url.query.replace(pos, len, ""); |
|
|
|
url.query.replace(pos, len, ""); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -242,16 +246,19 @@ namespace proxy { |
|
|
|
/* parsing success, now let's look inside request */ |
|
|
|
/* parsing success, now let's look inside request */ |
|
|
|
LogPrint(eLogDebug, "HTTPProxy: requested: ", m_ClientRequest.uri); |
|
|
|
LogPrint(eLogDebug, "HTTPProxy: requested: ", m_ClientRequest.uri); |
|
|
|
m_RequestURL.parse(m_ClientRequest.uri); |
|
|
|
m_RequestURL.parse(m_ClientRequest.uri); |
|
|
|
|
|
|
|
bool m_Confirm; |
|
|
|
|
|
|
|
|
|
|
|
if (ExtractAddressHelper(m_RequestURL, b64)) |
|
|
|
if (ExtractAddressHelper(m_RequestURL, b64, m_Confirm)) |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool addresshelper; i2p::config::GetOption("httpproxy.addresshelper", addresshelper); |
|
|
|
bool addresshelper; i2p::config::GetOption("httpproxy.addresshelper", addresshelper); |
|
|
|
if (!addresshelper) |
|
|
|
if (!addresshelper) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogPrint(eLogWarning, "HTTPProxy: addresshelper disabled"); |
|
|
|
LogPrint(eLogWarning, "HTTPProxy: addresshelper request rejected"); |
|
|
|
GenericProxyError("Invalid request", "adddresshelper is not supported"); |
|
|
|
GenericProxyError("Invalid request", "addresshelper is not supported"); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (!i2p::client::context.GetAddressBook ().FindAddress (m_RequestURL.host) || m_Confirm) |
|
|
|
|
|
|
|
{ |
|
|
|
i2p::client::context.GetAddressBook ().InsertAddress (m_RequestURL.host, b64); |
|
|
|
i2p::client::context.GetAddressBook ().InsertAddress (m_RequestURL.host, b64); |
|
|
|
LogPrint (eLogInfo, "HTTPProxy: added b64 from addresshelper for ", m_RequestURL.host); |
|
|
|
LogPrint (eLogInfo, "HTTPProxy: added b64 from addresshelper for ", m_RequestURL.host); |
|
|
|
std::string full_url = m_RequestURL.to_string(); |
|
|
|
std::string full_url = m_RequestURL.to_string(); |
|
|
@ -261,6 +268,15 @@ namespace proxy { |
|
|
|
GenericProxyInfo("Addresshelper found", ss.str().c_str()); |
|
|
|
GenericProxyInfo("Addresshelper found", ss.str().c_str()); |
|
|
|
return true; /* request processed */ |
|
|
|
return true; /* request processed */ |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
std::stringstream ss; |
|
|
|
|
|
|
|
ss << "Host " << m_RequestURL.host << " <font color=red>already in router's addressbook</font>. " |
|
|
|
|
|
|
|
<< "Click <a href=\"" << m_RequestURL.query << "?i2paddresshelper=" << b64 << "&update=true\">here</a> to update record."; |
|
|
|
|
|
|
|
GenericProxyInfo("Addresshelper found", ss.str().c_str()); |
|
|
|
|
|
|
|
return true; /* request processed */ |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
std::string dest_host; |
|
|
|
std::string dest_host; |
|
|
|
uint16_t dest_port; |
|
|
|
uint16_t dest_port; |
|
|
|
bool useConnect = false; |
|
|
|
bool useConnect = false; |
|
|
@ -570,7 +586,7 @@ namespace proxy { |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!stream) { |
|
|
|
if (!stream) { |
|
|
|
LogPrint (eLogError, "HTTPProxy: error when creating the stream, check the previous warnings for more info"); |
|
|
|
LogPrint (eLogError, "HTTPProxy: error when creating the stream, check the previous warnings for more info"); |
|
|
|
GenericProxyError("Host is down", "Can't create connection to requested host, it may be down"); |
|
|
|
GenericProxyError("Host is down", "Can't create connection to requested host, it may be down. Please try again later."); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
if (Kill()) |
|
|
|
if (Kill()) |
|
|
|