loleaflet/dist/loleaflet.html | 66 +++++++++++++++++++++--------------------- loolwsd/FileServer.hpp | 37 ++++++++++++++++++----- loolwsd/LOOLWSD.cpp | 2 - loolwsd/Makefile.am | 2 - 4 files changed, 64 insertions(+), 43 deletions(-)
New commits: commit 97342a2817fa1313190ed48a5a5c7db4ae9c559d Author: Jan Holesovsky <ke...@collabora.com> Date: Wed Apr 20 12:50:14 2016 +0200 bccu#1653: Make the .html's, .css's and .js's versioned. It is still possible to access them directly via loleaflet/dist/<something>, but such use can lead to unexpected behaviour due to various caching in the browsers etc. diff --git a/loleaflet/dist/loleaflet.html b/loleaflet/dist/loleaflet.html index a0c48d3..ee3aaf5 100644 --- a/loleaflet/dist/loleaflet.html +++ b/loleaflet/dist/loleaflet.html @@ -6,43 +6,43 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> -<link rel="stylesheet" href="/loleaflet/dist/leaflet.css"> -<link rel="stylesheet" href="/loleaflet/dist/selectionMarkers.css"> -<link rel="stylesheet" href="/loleaflet/dist/loleaflet.css"> -<link rel="stylesheet" href="/loleaflet/dist/toolbar.css"> -<link rel="stylesheet" href="/loleaflet/dist/partsPreviewControl.css"> -<link rel="stylesheet" href="/loleaflet/dist/scrollBar.css"> -<link rel="stylesheet" href="/loleaflet/dist/searchControl.css"> -<link rel="stylesheet" href="/loleaflet/dist/spreadsheet.css"> -<link rel="stylesheet" href="/loleaflet/dist/branding.css"> <!-- add your logo here --> -<link rel="stylesheet" href="/loleaflet/dist/plugins/draw-0.2.4/dist/leaflet.draw.css"> -<link rel="stylesheet" href="/loleaflet/dist/scrollbar/jquery.mCustomScrollbar.css"> -<link rel="stylesheet" href="/loleaflet/dist/contextMenu/jquery.contextMenu.css"> -<link rel="stylesheet" href="/loleaflet/dist/dialog/vex.css" /> -<link rel="stylesheet" href="/loleaflet/dist/dialog/vex-theme-plain.css" /> -<link rel="stylesheet" href="/loleaflet/dist/toolbar/w2ui.min.css" /> -<link rel="stylesheet" href="/loleaflet/dist/toolbar/select2.min.css" /> +<link rel="stylesheet" href="/loleaflet/%VERSION%/leaflet.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/selectionMarkers.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/loleaflet.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/toolbar.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/partsPreviewControl.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/scrollBar.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/searchControl.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/spreadsheet.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/branding.css"> <!-- add your logo here --> +<link rel="stylesheet" href="/loleaflet/%VERSION%/plugins/draw-0.2.4/dist/leaflet.draw.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/scrollbar/jquery.mCustomScrollbar.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/contextMenu/jquery.contextMenu.css"> +<link rel="stylesheet" href="/loleaflet/%VERSION%/dialog/vex.css" /> +<link rel="stylesheet" href="/loleaflet/%VERSION%/dialog/vex-theme-plain.css" /> +<link rel="stylesheet" href="/loleaflet/%VERSION%/toolbar/w2ui.min.css" /> +<link rel="stylesheet" href="/loleaflet/%VERSION%/toolbar/select2.min.css" /> <link rel="stylesheet" href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/themes/ui-lightness/jquery-ui.css"> -<link rel="stylesheet" href="/loleaflet/dist/toolbar/evol.colorpicker.min.css"> -<link rel="localizations" href="/loleaflet/dist/l10n/localizations.json" type="application/vnd.oftn.l10n+json"/> -<link rel="localizations" href="/loleaflet/dist/l10n/styles-localizations.json" type="application/vnd.oftn.l10n+json" /> +<link rel="stylesheet" href="/loleaflet/%VERSION%/toolbar/evol.colorpicker.min.css"> +<link rel="localizations" href="/loleaflet/%VERSION%/l10n/localizations.json" type="application/vnd.oftn.l10n+json"/> +<link rel="localizations" href="/loleaflet/%VERSION%/l10n/styles-localizations.json" type="application/vnd.oftn.l10n+json" /> <style type="text/css"></style></head> <body> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js"></script> - <script src="/loleaflet/dist/l10n/json2.min.js"></script> - <script src="/loleaflet/dist/l10n/l10n.min.js"></script> - <script src="/loleaflet/dist/toolbar/w2ui.min.js"></script> - <script src="/loleaflet/dist/toolbar/select2.min.js"></script> + <script src="/loleaflet/%VERSION%/l10n/json2.min.js"></script> + <script src="/loleaflet/%VERSION%/l10n/l10n.min.js"></script> + <script src="/loleaflet/%VERSION%/toolbar/w2ui.min.js"></script> + <script src="/loleaflet/%VERSION%/toolbar/select2.min.js"></script> <script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.11.1/jquery-ui.min.js"></script> - <script src="/loleaflet/dist/toolbar/evol.colorpicker.min.js"></script> - <script src="/loleaflet/dist/toolbar/jquery.simplemodal.1.4.4.min.js"></script> - <script src="/loleaflet/dist/leaflet-src.js"></script> - <script src="/loleaflet/dist/plugins/draw-0.2.4/dist/leaflet.draw.js"></script> - <script src="/loleaflet/dist/scrollbar/jquery.mCustomScrollbar.js"></script> - <script src="/loleaflet/dist/contextMenu/jquery.contextMenu.js"></script> - <script src="/loleaflet/dist/contextMenu/jquery.ui.position.min.js"></script> - <script src="/loleaflet/dist/dialog/vex.combined.min.js"></script> - <script src="/loleaflet/dist/branding.js"></script> <!-- logo onclick handler --> + <script src="/loleaflet/%VERSION%/toolbar/evol.colorpicker.min.js"></script> + <script src="/loleaflet/%VERSION%/toolbar/jquery.simplemodal.1.4.4.min.js"></script> + <script src="/loleaflet/%VERSION%/leaflet-src.js"></script> + <script src="/loleaflet/%VERSION%/plugins/draw-0.2.4/dist/leaflet.draw.js"></script> + <script src="/loleaflet/%VERSION%/scrollbar/jquery.mCustomScrollbar.js"></script> + <script src="/loleaflet/%VERSION%/contextMenu/jquery.contextMenu.js"></script> + <script src="/loleaflet/%VERSION%/contextMenu/jquery.ui.position.min.js"></script> + <script src="/loleaflet/%VERSION%/dialog/vex.combined.min.js"></script> + <script src="/loleaflet/%VERSION%/branding.js"></script> <!-- logo onclick handler --> <script>vex.defaultOptions.className = 'vex-theme-plain';</script> <script>var _ = function (string) {return string.toLocaleString();};</script> @@ -124,5 +124,5 @@ </script> - <script src="/loleaflet/dist/toolbar/toolbar.js"></script> + <script src="/loleaflet/%VERSION%/toolbar/toolbar.js"></script> </body></html> diff --git a/loolwsd/FileServer.hpp b/loolwsd/FileServer.hpp index d869e11..b7faf4a 100644 --- a/loolwsd/FileServer.hpp +++ b/loolwsd/FileServer.hpp @@ -10,6 +10,8 @@ #ifndef INCLUDED_FILESERVER_HPP #define INCLUDED_FILESERVER_HPP +#include "config.h" + #include <string> #include <vector> @@ -140,12 +142,12 @@ public: throw Poco::Net::NotAuthenticatedException("Invalid admin login"); } - const auto path = Poco::Path(LOOLWSD::FileServerRoot, requestUri.getPath()); + const auto path = Poco::Path(LOOLWSD::FileServerRoot, getRequestPathname(request)); const auto filepath = path.absolute().toString(); if (filepath.find(LOOLWSD::FileServerRoot) != 0) { // Accessing unauthorized path. - throw Poco::FileNotFoundException("Invalid or forbidden file path: [" + filepath + "]."); + throw Poco::FileAccessDeniedException("Invalid or forbidden file path: [" + filepath + "]."); } const std::size_t extPoint = endPoint.find_last_of("."); @@ -175,30 +177,48 @@ public: response.setContentLength(0); response.send(); } + catch (const Poco::FileAccessDeniedException& exc) + { + Log::error("FileServerRequestHandler: " + exc.displayText()); + response.setStatusAndReason(HTTPResponse::HTTP_FORBIDDEN); + response.setContentLength(0); // TODO return some 403 page? + response.send(); + } catch (const Poco::FileNotFoundException& exc) { Log::error("FileServerRequestHandler: " + exc.displayText()); response.setStatusAndReason(HTTPResponse::HTTP_NOT_FOUND); - response.setContentLength(0); + response.setContentLength(0); // TODO return some 404 page? response.send(); } } private: + std::string getRequestPathname(const HTTPServerRequest& request) + { + Poco::URI requestUri(request.getURI()); + // avoid .'s and ..'s + requestUri.normalize(); + + std::string path(requestUri.getPath()); + + // convert version back to a real file name + Poco::replaceInPlace(path, std::string("/loleaflet/" LOOLWSD_VERSION "/"), std::string("/loleaflet/dist/")); + + return path; + } + void preprocessFile(HTTPServerRequest& request, HTTPServerResponse& response) { HTMLForm form(request, request.stream()); - std::string preprocess; const auto host = (LOOLWSD::SSLEnabled? "wss://": "ws://") + request.getHost(); - - Poco::URI requestUri(request.getURI()); - requestUri.normalize(); // avoid .'s and ..'s - const auto path = Poco::Path(LOOLWSD::FileServerRoot, requestUri.getPath()); + const auto path = Poco::Path(LOOLWSD::FileServerRoot, getRequestPathname(request)); Log::debug("Preprocessing file: " + path.toString()); + std::string preprocess; FileInputStream file(path.toString()); StreamCopier::copyToString(file, preprocess); file.close(); @@ -206,6 +226,7 @@ private: Poco::replaceInPlace(preprocess, std::string("%ACCESS_TOKEN%"), form.get("access_token", "")); Poco::replaceInPlace(preprocess, std::string("%ACCESS_TOKEN_TTL%"), form.get("access_token_ttl", "")); Poco::replaceInPlace(preprocess, std::string("%HOST%"), host); + Poco::replaceInPlace(preprocess, std::string("%VERSION%"), std::string(LOOLWSD_VERSION)); response.setContentType("text/html"); response.setContentLength(preprocess.length()); diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 5248b38..e6886a4 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -657,7 +657,7 @@ private: const std::string urlsrc = "urlsrc"; const std::string uriValue = (LOOLWSD::SSLEnabled ? "https://" : "http://") + (LOOLWSD::ServerName.empty() ? request.getHost() : LOOLWSD::ServerName) + - "/loleaflet/dist/loleaflet.html?"; + "/loleaflet/" LOOLWSD_VERSION "/loleaflet.html?"; InputSource inputSrc(discoveryPath); DOMParser parser; diff --git a/loolwsd/Makefile.am b/loolwsd/Makefile.am index 8e3f3eb..c7ac590 100644 --- a/loolwsd/Makefile.am +++ b/loolwsd/Makefile.am @@ -134,7 +134,7 @@ run: all @JAILS_PATH@ @SYSTEMPLATE_PATH@/system_stamp @echo "Launching loolwsd - launch this in your browser:" @cp $(abs_top_srcdir)/test/data/hello.odt $(abs_top_srcdir)/test/data/hello-world.odt @PROTOCOL="http" ; if test "z@ENABLE_SSL@" != "z"; then PROTOCOL="https" ; fi ; \ - echo " $$PROTOCOL://localhost:9980/loleaflet/dist/loleaflet.html?file_path=file://$(abs_top_srcdir)/test/data/hello-world.odt" + echo " $$PROTOCOL://localhost:9980/loleaflet/@LOOLWSD_VERSION@/loleaflet.html?file_path=file://$(abs_top_srcdir)/test/data/hello-world.odt" @echo ./loolwsd --systemplate="@SYSTEMPLATE_PATH@" --lotemplate="@LO_PATH@" \ --childroot="@JAILS_PATH@" --allowlocalstorage _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits