[Libreoffice-commits] online.git: wsd/FileServer.cpp

Jan Holesovsky kendy at collabora.com
Thu May 24 19:22:55 UTC 2018


 wsd/FileServer.cpp |   33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

New commits:
commit 49b3957086165891d8a1683e75d6d862f9ddca7e
Author: Jan Holesovsky <kendy at collabora.com>
Date:   Thu May 24 11:54:45 2018 +0200

    Throw if admin console is not enabled.
    
    And few other smaller tweaks around different branding with support key
    enabled.
    
    Change-Id: I9a751374c9384d9535a208c9bd912e2041fd5879
    Reviewed-on: https://gerrit.libreoffice.org/54753
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp
index 17531623f..669f57c4b 100644
--- a/wsd/FileServer.cpp
+++ b/wsd/FileServer.cpp
@@ -47,9 +47,6 @@
 #include <Log.hpp>
 #include <Protocol.hpp>
 
-#define BRAND_SUPPORTED "branding"
-#define BRAND_UNSUPPORTED "branding-CODE"
-
 using Poco::Net::HTMLForm;
 using Poco::Net::HTTPBasicCredentials;
 using Poco::Net::HTTPRequest;
@@ -565,10 +562,13 @@ std::string FileServerRequestHandler::getRequestPathname(const HTTPRequest& requ
     return path;
 }
 
+constexpr char BRANDING[] = "branding";
+#if ENABLE_SUPPORT_KEY
+constexpr char BRANDING_SUPPORTED[] = "branding-supported";
+#endif
+
 void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::MemoryInputStream& message, const std::shared_ptr<StreamSocket>& socket)
 {
-    static const std::string linkCSS = "<link rel=\"stylesheet\" href=\"/loleaflet/" LOOLWSD_VERSION_HASH "/%s.css\">";
-    static const std::string scriptJS = "<script src=\"/loleaflet/" LOOLWSD_VERSION_HASH "/%s.js\"></script>";
     const auto host = ((LOOLWSD::isSSLEnabled() || LOOLWSD::isSSLTermination()) ? "wss://" : "ws://") + (LOOLWSD::ServerName.empty() ? request.getHost() : LOOLWSD::ServerName);
     const Poco::URI::QueryParameters params = Poco::URI(request.getURI()).getQueryParameters();
 
@@ -617,8 +617,11 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
     Poco::replaceInPlace(preprocess, std::string("%HOST%"), host);
     Poco::replaceInPlace(preprocess, std::string("%VERSION%"), std::string(LOOLWSD_VERSION_HASH));
 
-    std::string brandCSS(Poco::format(linkCSS, std::string(BRAND_UNSUPPORTED)));
-    std::string brandJS(Poco::format(scriptJS, std::string(BRAND_UNSUPPORTED)));
+    static const std::string linkCSS("<link rel=\"stylesheet\" href=\"/loleaflet/" LOOLWSD_VERSION_HASH "/%s.css\">");
+    static const std::string scriptJS("<script src=\"/loleaflet/" LOOLWSD_VERSION_HASH "/%s.js\"></script>");
+
+    std::string brandCSS(Poco::format(linkCSS, std::string(BRANDING)));
+    std::string brandJS(Poco::format(scriptJS, std::string(BRANDING)));
 
     const auto& config = Application::instance().config();
 #if ENABLE_SUPPORT_KEY
@@ -626,8 +629,8 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
     SupportKey key(keyString);
     if (key.verify() && key.validDaysRemaining() > 0)
     {
-        brandCSS = Poco::format(linkCSS, std::string(BRAND_SUPPORTED));
-        brandJS = Poco::format(scriptJS, std::string(BRAND_SUPPORTED));
+        brandCSS = Poco::format(linkCSS, std::string(BRANDING_SUPPORTED));
+        brandJS = Poco::format(scriptJS, std::string(BRANDING_SUPPORTED));
     }
 #elif ENABLE_DEBUG
     brandCSS = "";
@@ -783,16 +786,20 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::
 void FileServerRequestHandler::preprocessAdminFile(const HTTPRequest& request,const std::shared_ptr<StreamSocket>& socket)
 {
     Poco::Net::HTTPResponse response;
-    static const std::string scriptJS("<script src=\"/loleaflet/dist/%s.js\"></script>");
-    static const std::string footerPage("<div class=\"footer navbar-fixed-bottom text-info text-center\"><strong>Key:</strong> %s   <strong>Expiry Date:</strong> %s</div>");
+
+    if (!LOOLWSD::AdminEnabled)
+        throw Poco::FileAccessDeniedException("Admin console disabled");
 
     if (!FileServerRequestHandler::isAdminLoggedIn(request, response))
         throw Poco::Net::NotAuthenticatedException("Invalid admin login");
 
+    static const std::string scriptJS("<script src=\"/loleaflet/dist/%s.js\"></script>");
+    static const std::string footerPage("<div class=\"footer navbar-fixed-bottom text-info text-center\"><strong>Key:</strong> %s   <strong>Expiry Date:</strong> %s</div>");
+
     const std::string relPath = getRequestPathname(request);
     LOG_DBG("Preprocessing file: " << relPath);
     std::string adminFile = *getUncompressedFile(relPath);
-    std::string brandJS(Poco::format(scriptJS, std::string(BRAND_UNSUPPORTED)));
+    std::string brandJS(Poco::format(scriptJS, std::string(BRANDING)));
     std::string brandFooter;
 
 #if ENABLE_SUPPORT_KEY
@@ -802,7 +809,7 @@ void FileServerRequestHandler::preprocessAdminFile(const HTTPRequest& request,co
 
     if (key.verify() && key.validDaysRemaining() > 0)
     {
-        brandJS = Poco::format(scriptJS, std::string(BRAND_SUPPORTED));
+        brandJS = Poco::format(scriptJS, std::string(BRANDING_SUPPORTED));
         brandFooter = Poco::format(footerPage, key.data(), Poco::DateTimeFormatter::format(key.expiry(), Poco::DateTimeFormat::RFC822_FORMAT));
     }
 #elif ENABLE_DEBUG


More information about the Libreoffice-commits mailing list