mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-26 10:11:30 +00:00
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
This commit is contained in:
@ -392,7 +392,7 @@ Response InternalServer::build_500(const std::string& msg)
|
|||||||
{
|
{
|
||||||
kainjow::mustache::data data;
|
kainjow::mustache::data data;
|
||||||
data.set("error", msg);
|
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_template(RESOURCE::templates::_500_html, data);
|
||||||
response.set_mimeType("text/html");
|
response.set_mimeType("text/html");
|
||||||
response.set_code(MHD_HTTP_INTERNAL_SERVER_ERROR);
|
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();
|
auto data = get_default_data();
|
||||||
data.set("source", source);
|
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_template(RESOURCE::templates::captured_external_html, data);
|
||||||
response.set_mimeType("text/html; charset=utf-8");
|
response.set_mimeType("text/html; charset=utf-8");
|
||||||
response.set_compress(true);
|
response.set_compress(true);
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
|
var block_path = "/catch/external";
|
||||||
// called only on external links
|
// 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
|
// called on all link clicks. filters external and call capture_event
|
||||||
function on_click_event(e) {
|
function on_click_event(e) {
|
||||||
if ("target" in e && "href" in e.target) {
|
if ("target" in e && "href" in e.target) {
|
||||||
var href = e.target.href;
|
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)
|
if (href.indexOf(window.location.origin) == 0)
|
||||||
return;
|
return;
|
||||||
if (href.substr(0, 2) == "//")
|
if (href.substr(0, 2) == "//")
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
<h1>External link blocked</h1>
|
<h1>External link blocked</h1>
|
||||||
<p>This instance of Kiwix protects you from accidentaly going to external (out-of ZIM) links.</p>
|
<p>This instance of Kiwix protects you from accidentaly going to external (out-of ZIM) links.</p>
|
||||||
<p>If you intend to go to such locations, please click the link bellow.</p>
|
<p>If you intend to go to such locations, please click the link below.</p>
|
||||||
<p><a href="{{ source }}">Go to {{ source }}</a></p>
|
<p><a href="{{ source }}">Go to {{ source }}</a></p>
|
||||||
<div id="kiwixfooter">
|
<div id="kiwixfooter">
|
||||||
Powered by <a href="https://kiwix.org">Kiwix</a>
|
Powered by <a href="https://kiwix.org">Kiwix</a>
|
||||||
|
Reference in New Issue
Block a user