mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-02-02 15:14:14 +00:00
[HTTP Proxy] skip addresshelper page if destination is not changed (closes #1789)
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
parent
3544f77e90
commit
798dd8b27b
@ -397,6 +397,19 @@ namespace client
|
|||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool AddressBook::RecordExists (const std::string& address, const std::string& jump)
|
||||||
|
{
|
||||||
|
auto addr = FindAddress(address);
|
||||||
|
if (!addr)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
i2p::data::IdentityEx ident;
|
||||||
|
if (ident.FromBase64 (jump) && ident.GetIdentHash () == addr->identHash)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
void AddressBook::InsertAddress (const std::string& address, const std::string& jump)
|
void AddressBook::InsertAddress (const std::string& address, const std::string& jump)
|
||||||
{
|
{
|
||||||
auto pos = jump.find(".b32.i2p");
|
auto pos = jump.find(".b32.i2p");
|
||||||
|
@ -90,6 +90,8 @@ namespace client
|
|||||||
void InsertAddress (const std::string& address, const std::string& jump); // for jump links
|
void InsertAddress (const std::string& address, const std::string& jump); // for jump links
|
||||||
void InsertFullAddress (std::shared_ptr<const i2p::data::IdentityEx> address);
|
void InsertFullAddress (std::shared_ptr<const i2p::data::IdentityEx> address);
|
||||||
|
|
||||||
|
bool RecordExists (const std::string& address, const std::string& jump);
|
||||||
|
|
||||||
bool LoadHostsFromStream (std::istream& f, bool is_update);
|
bool LoadHostsFromStream (std::istream& f, bool is_update);
|
||||||
void DownloadComplete (bool success, const i2p::data::IdentHash& subscription, const std::string& etag, const std::string& lastModified);
|
void DownloadComplete (bool success, const i2p::data::IdentHash& subscription, const std::string& etag, const std::string& lastModified);
|
||||||
//This method returns the ".b32.i2p" address
|
//This method returns the ".b32.i2p" address
|
||||||
|
@ -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 */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user