From d04d9bf7f30ee384929fd9e4bd492722ce1d5749 Mon Sep 17 00:00:00 2001 From: renaud gaudin Date: Fri, 27 Mar 2020 12:26:22 +0000 Subject: [PATCH] Unblock external link in catch page in JS code Instead of disabling the blocking for the handler, the JS code detects it is displaying the handler and allows external links to go through --- src/server.cpp | 4 ++-- static/skin/block_external.js | 5 ++++- static/templates/captured_external.html | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/server.cpp b/src/server.cpp index c4cf4a546..b830c7c79 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -392,7 +392,7 @@ Response InternalServer::build_500(const std::string& msg) { kainjow::mustache::data data; data.set("error", msg); - Response response(m_root, true, false, false, false); + Response response(m_root, true, false, false, m_blockExternalLinks); response.set_template(RESOURCE::templates::_500_html, data); response.set_mimeType("text/html"); response.set_code(MHD_HTTP_INTERNAL_SERVER_ERROR); @@ -732,7 +732,7 @@ Response InternalServer::handle_captured_external(const RequestContext& request) auto data = get_default_data(); data.set("source", source); - Response response = Response(m_root, m_verbose.load(), m_withTaskbar, m_withLibraryButton, false); + auto response = get_default_response(); response.set_template(RESOURCE::templates::captured_external_html, data); response.set_mimeType("text/html; charset=utf-8"); response.set_compress(true); diff --git a/static/skin/block_external.js b/static/skin/block_external.js index 9b70f243c..04430670b 100644 --- a/static/skin/block_external.js +++ b/static/skin/block_external.js @@ -1,10 +1,13 @@ +var block_path = "/catch/external"; // called only on external links -function capture_event(e) { e.target.setAttribute("href", encodeURI("/catch/external?source=" + e.target.href)); } +function capture_event(e) { e.target.setAttribute("href", encodeURI(block_path + "?source=" + e.target.href)); } // called on all link clicks. filters external and call capture_event function on_click_event(e) { if ("target" in e && "href" in e.target) { var href = e.target.href; + if (window.location.pathname.indexOf(block_path) == 0) // already in catch page + return; if (href.indexOf(window.location.origin) == 0) return; if (href.substr(0, 2) == "//") diff --git a/static/templates/captured_external.html b/static/templates/captured_external.html index 016172316..a75bd3fe8 100644 --- a/static/templates/captured_external.html +++ b/static/templates/captured_external.html @@ -13,7 +13,7 @@

External link blocked

This instance of Kiwix protects you from accidentaly going to external (out-of ZIM) links.

-

If you intend to go to such locations, please click the link bellow.

+

If you intend to go to such locations, please click the link below.

Go to {{ source }}

Powered by Kiwix