diff --git a/src/server/internalServer.cpp b/src/server/internalServer.cpp index d1d4f2a0..d364e414 100644 --- a/src/server/internalServer.cpp +++ b/src/server/internalServer.cpp @@ -1085,9 +1085,7 @@ std::unique_ptr InternalServer::handle_captured_external(const Request return UrlNotFoundResponse(request); } - auto data = get_default_data(); - data.set("source", source); - return ContentResponse::build(RESOURCE::templates::captured_external_html, data, "text/html; charset=utf-8"); + return BlockExternalLinkResponse(request, m_root, source); } std::unique_ptr InternalServer::handle_catch(const RequestContext& request) diff --git a/src/server/response.cpp b/src/server/response.cpp index fd0b8594..8e6707e2 100644 --- a/src/server/response.cpp +++ b/src/server/response.cpp @@ -405,6 +405,22 @@ NewHTTP404Response::NewHTTP404Response(const RequestContext& request, }); } +BlockExternalLinkResponse::BlockExternalLinkResponse(const RequestContext& request, + const std::string& root, + const std::string& externalUrl) + : ContentResponseBlueprint(&request, + MHD_HTTP_OK, + "text/html; charset=utf-8", + RESOURCE::templates::captured_external_html, + /*includeKiwixResponseData=*/true) +{ + *this->m_data = Data(Data::Object{ + {"root", root }, + {"external_link_detected", Data::fromMsgId("external-link-detected") }, + {"source", externalUrl }, + }); +} + HTTPErrorResponse::HTTPErrorResponse(const RequestContext& request, int httpStatusCode, const std::string& pageTitleMsgId, diff --git a/src/server/response.h b/src/server/response.h index 47fb5851..597caa9d 100644 --- a/src/server/response.h +++ b/src/server/response.h @@ -197,6 +197,13 @@ class ItemResponse : public Response { std::string m_mimeType; }; +struct BlockExternalLinkResponse : ContentResponseBlueprint +{ + BlockExternalLinkResponse(const RequestContext& request, + const std::string& root, + const std::string& externalUrl); +}; + } #endif //KIWIXLIB_SERVER_RESPONSE_H diff --git a/static/skin/i18n/en.json b/static/skin/i18n/en.json index 15ed6377..cfd71b0e 100644 --- a/static/skin/i18n/en.json +++ b/static/skin/i18n/en.json @@ -32,6 +32,7 @@ , "500-page-title" : "Internal Server Error" , "500-page-heading" : "Internal Server Error" , "500-page-text": "An internal server error occured. We are sorry about that :/" + , "external-link-detected" : "External Link Detected" , "fulltext-search-unavailable" : "Fulltext search unavailable" , "no-search-results": "The fulltext search engine is not available for this content." , "search-results-page-title": "Search: {{SEARCH_PATTERN}}" diff --git a/static/skin/i18n/qqq.json b/static/skin/i18n/qqq.json index e23016d0..fdb006cb 100644 --- a/static/skin/i18n/qqq.json +++ b/static/skin/i18n/qqq.json @@ -36,6 +36,7 @@ "500-page-title": "Title of the 500 error page", "500-page-heading": "Heading of the 500 error page", "500-page-text": "Text of the 500 error page", + "external-link-detected" : "Title & heading of the external link blocker page", "fulltext-search-unavailable": "Title of the error page returned when search is attempted in a book without fulltext search database", "no-search-results": "Text of the error page returned when search is attempted in a book without fulltext search database", "search-results-page-title": "Title of the search results page", diff --git a/static/skin/i18n/test.json b/static/skin/i18n/test.json index 90fcc49b..b2d910f4 100644 --- a/static/skin/i18n/test.json +++ b/static/skin/i18n/test.json @@ -22,6 +22,7 @@ , "404-advice.p3": "[I18N TESTING] Check the spelling of the URL path" , "404-advice.p4": "[I18N TESTING] Press the dice button" , "404-advice.p5": "Good luck! [I18N TESTING]" + , "external-link-detected" : "External [I18] Link [TESTING] Detected" , "library-button-text": "[I18N TESTING] Navigate to the welcome page" , "home-button-text": "[I18N TESTING] Jump to the main page of '{{BOOK_TITLE}}'" , "random-page-button-text": "[I18N TESTING] I am tired of determinism" diff --git a/static/templates/captured_external.html b/static/templates/captured_external.html index 54e1f972..2e22b4bd 100644 --- a/static/templates/captured_external.html +++ b/static/templates/captured_external.html @@ -3,8 +3,12 @@ - External Link Detected + {{external_link_detected}} +{{#KIWIX_RESPONSE_DATA}} {{/KIWIX_RESPONSE_DATA}}
@@ -14,7 +18,7 @@ title="Caution!">
-

External Link Detected

+

{{external_link_detected}}

You are about to leave Kiwix's ZIM reader to go online to

{{ source }}

diff --git a/test/server.cpp b/test/server.cpp index fd6486a6..d79c7d02 100644 --- a/test/server.cpp +++ b/test/server.cpp @@ -94,6 +94,8 @@ const ResourceCollection resources200Compressible{ { DYNAMIC_CONTENT, "/ROOT%23%3F/catalog/v2/entries" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/catalog/v2/partial_entries" }, + { DYNAMIC_CONTENT, "/ROOT%23%3F/catch/external?source=www.example.com" }, + { DYNAMIC_CONTENT, "/ROOT%23%3F/search?content=zimfile&pattern=a" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/suggest?content=zimfile&term=ray" }, @@ -178,8 +180,6 @@ const ResourceCollection resources200Uncompressible{ { DYNAMIC_CONTENT, "/ROOT%23%3F/catalog/v2/searchdescription.xml" }, { DYNAMIC_CONTENT, "/ROOT%23%3F/catalog/v2/illustration/6f1d19d0-633f-087b-fb55-7ac324ff9baf?size=48" }, - { DYNAMIC_CONTENT, "/ROOT%23%3F/catch/external?source=www.example.com" }, - { ZIM_CONTENT, "/ROOT%23%3F/content/zimfile/I/m/Ray_Charles_classic_piano_pose.jpg" }, { ZIM_CONTENT, "/ROOT%23%3F/content/corner_cases%23%26/empty.html" }, @@ -355,6 +355,7 @@ R"EXPECTEDRESULT( + window.KIWIX_RESPONSE_TEMPLATE = "<!DOCTYPE html>\n<html>\n <head>\n <meta charset="utf-8">\n <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />\n <title>{{external_link_detected}}</title>\n <link type="text/css" href="{{root}}/skin/error.css?cacheid=b3fa90cf" rel="Stylesheet" />\n{{#KIWIX_RESPONSE_DATA}} <script>\n window.KIWIX_RESPONSE_TEMPLATE = "{{KIWIX_RESPONSE_TEMPLATE}}";\n window.KIWIX_RESPONSE_DATA = {{{KIWIX_RESPONSE_DATA}}};\n </script>{{/KIWIX_RESPONSE_DATA}}\n </head>\n <body>\n <header>\n <img src="{{root}}/skin/blocklink.svg?cacheid=bd56b116"\n alt="Caution!"\n aria-label="Caution!"\n title="Caution!">\n </header>\n <section class="intro">\n <h1>{{external_link_detected}}</h1>\n <p>You are about to leave Kiwix's ZIM reader to go online to</p>\n <p><a href="{{source}}">{{ source }}</a></p>\n </section>\n <section class="advice">\n <p>The link you're trying to access is not part of your offline package and requires an internet connection.</p>\n <p>If you can go online, you can attempt to open the link.</p>\n <p>You can otherwise return to your ZIM's offline content by using your browser's back button.</p>\n </section>\n </body>\n</html>\n";