diff options
author | Henry Castro <hcastro@collabora.com> | 2022-03-30 11:43:55 -0400 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2022-04-04 10:42:05 +0200 |
commit | 4cc19e1db857c0489f0c68c10b0a537f6d5721fa (patch) | |
tree | 58f532b379bab62485feb009f1a3ec228ac649aa | |
parent | change blinking cursor color to black (diff) | |
download | online-4cc19e1db857c0489f0c68c10b0a537f6d5721fa.tar.gz online-4cc19e1db857c0489f0c68c10b0a537f6d5721fa.zip |
Remove the old vex-based welcome dialog code
... and make Welcome dialog optional for COOL
config: add welome url parameter
Signed-off-by: Henry Castro <hcastro@collabora.com>
config: add feedback url parameter
Signed-off-by: Henry Castro <hcastro@collabora.com>
config: add infobar-url parameter
Signed-off-by: Henry Castro <hcastro@collabora.com>
welcome: fix unhandled exceptions
Signed-off-by: Henry Castro <hcastro@collabora.com>
welcome: preprocess welcome file
added welcome-message.html
Signed-off-by: Henry Castro <hcastro@collabora.com>
welcome: clean up code related to vex welcome
Signed-off-by: Henry Castro <hcastro@collabora.com>
--enable-welcome-message is not necessary, when we specify a welcome URL, then it is enabled, otherwise it's user configurable
Signed-off-by: Andras Timar <andras.timar@collabora.com>
remove the unused welcome config settings
Signed-off-by: Andras Timar <andras.timar@collabora.com>
remove unused define ENABLE_FEEDBACK
Signed-off-by: Andras Timar <andras.timar@collabora.com>
do not install/package fallback welcome dialog, when welcome feature is not configured
Signed-off-by: Andras Timar <andras.timar@collabora.com>
remove welcome-message.html
Signed-off-by: Andras Timar <andras.timar@collabora.com>
Change-Id: I20aa6220362018b63aaebd114b2b661561823fbb
-rw-r--r-- | .gitpod-files/coolwsd-gitpod.xml | 2 | ||||
-rw-r--r-- | browser/Makefile.am | 32 | ||||
-rw-r--r-- | browser/html/cool.html.m4 | 8 | ||||
-rw-r--r-- | browser/src/map/handler/Map.Feedback.js | 4 | ||||
-rw-r--r-- | browser/src/map/handler/Map.Infobar.js | 5 | ||||
-rw-r--r-- | browser/src/map/handler/Map.Welcome.js | 5 | ||||
-rw-r--r-- | browser/welcome/welcome.js | 49 | ||||
-rw-r--r-- | configure.ac | 66 | ||||
-rw-r--r-- | coolwsd-welcome.xml | 2 | ||||
-rw-r--r-- | wsd/COOLWSD.cpp | 9 | ||||
-rw-r--r-- | wsd/COOLWSD.hpp | 1 | ||||
-rw-r--r-- | wsd/FileServer.cpp | 104 | ||||
-rw-r--r-- | wsd/FileServer.hpp | 4 |
13 files changed, 136 insertions, 155 deletions
diff --git a/.gitpod-files/coolwsd-gitpod.xml b/.gitpod-files/coolwsd-gitpod.xml index 18f096c542..270a2da6a6 100644 --- a/.gitpod-files/coolwsd-gitpod.xml +++ b/.gitpod-files/coolwsd-gitpod.xml @@ -128,8 +128,6 @@ <welcome> <enable type="bool" desc="Controls whether the welcome screen should be shown to the users on new install and updates." default="false">false</enable> - <enable_button type="bool" desc="Controls whether the welcome screen should have an explanatory button instead of an X button to close the dialog." default="false">false</enable_button> - <path desc="Path to 'welcome-$lang.html' files served on first start or when the version changes. When empty, defaults to the Release notes." type="path" relative="true" default="browser/welcome"></path> </welcome> <user_interface> diff --git a/browser/Makefile.am b/browser/Makefile.am index 49f3a46b94..1e4e7702d9 100644 --- a/browser/Makefile.am +++ b/browser/Makefile.am @@ -54,8 +54,10 @@ endif COOL_HTML_SRC = $(shell find $(srcdir)/html -name '*.html') COOL_HTML_DST = $(patsubst $(srcdir)/html/%.html,$(DIST_FOLDER)/%.html,$(COOL_HTML_SRC)) +if ENABLE_WELCOME_MESSAGE COOL_WELCOME_SRC = $(shell find $(srcdir)/welcome -name '*') COOL_WELCOME_DST = $(patsubst $(srcdir)/welcome/%,$(DIST_FOLDER)/welcome/%,$(COOL_WELCOME_SRC)) +endif COOL_ADMIN_SRC = $(shell find $(srcdir)/admin -name '*.html' -or -name '*.css' -or -name '*.ttf' -or -name 'OFL.txt' -or -name '*.svg') COOL_ADMIN_ALL = $(shell find $(srcdir)/admin -name '*') @@ -130,12 +132,14 @@ COOL_CSS_LST =\ $(srcdir)/css/spreadsheet.css \ $(srcdir)/css/writer-mobile.css \ $(srcdir)/css/editor.css \ + $(srcdir)/css/iframedialog.css \ $(builddir)/node_modules/jquery-contextmenu/dist/jquery.contextMenu.css \ $(builddir)/node_modules/vex-js/dist/css/vex.css \ $(builddir)/node_modules/vex-js/dist/css/vex-theme-plain.css \ $(builddir)/node_modules/vex-js/dist/css/vex-theme-bottom-right-corner.css \ $(builddir)/node_modules/smartmenus/dist/css/sm-core-css.css \ $(builddir)/node_modules/smartmenus/dist/css/sm-simple/sm-simple.css \ + $(srcdir)/css/welcome.css \ $(srcdir)/css/menubar.css \ $(srcdir)/css/mobilewizard.css \ $(srcdir)/css/jsdialogs.css \ @@ -147,11 +151,6 @@ COOL_CSS_LST =\ $(srcdir)/css/jquery-ui-lightness.css \ $(srcdir)/css/infobar.css -if ENABLE_FEEDBACK -COOL_CSS_LST += $(srcdir)/css/iframedialog.css \ - $(srcdir)/css/welcome.css -endif - COOL_CSS = $(filter %,$(COOL_CSS_LST)) COOL_CSS_DST = $(foreach file,$(COOL_CSS),$(DIST_FOLDER)/$(notdir $(file))) @@ -213,6 +212,7 @@ COOL_JS_LST =\ src/geo/projection/Projection.LonLat.js \ src/geo/crs/CRS.js \ src/geo/crs/CRS.Simple.js \ + src/control/IFrameDialog.js \ src/map/Map.js \ src/map/Clipboard.js \ src/layer/Layer.js \ @@ -292,6 +292,9 @@ COOL_JS_LST =\ src/map/handler/Map.TouchGesture.js \ src/map/handler/Map.BoxZoom.js \ src/map/handler/Map.Keyboard.js \ + src/map/handler/Map.Welcome.js \ + src/map/handler/Map.Feedback.js \ + src/map/handler/Map.Infobar.js \ src/dom/DomEvent.MultiClick.js \ src/map/handler/Map.Mouse.js \ src/map/handler/Map.Print.js \ @@ -321,7 +324,8 @@ COOL_JS_LST =\ src/control/Control.Selection.js \ src/control/Control.LokDialog.js \ src/control/Control.AlertDialog.js \ - src/control/Control.Infobar.js src/control/ColorPicker.js \ + src/control/Control.Infobar.js \ + src/control/ColorPicker.js \ src/control/Control.JSDialog.js \ src/control/Control.JSDialogBuilder.js \ src/control/Control.MobileWizardBuilder.js \ @@ -364,17 +368,7 @@ COOL_JS_LST =\ src/map/anim/Map.PanAnimation.js \ src/dom/PosAnimation.Timer.js \ src/control/Control.Scroll.Annotation.js \ - src/layer/marker/DivOverlay.js - -if ENABLE_FEEDBACK -COOL_JS_LST +=\ - src/control/IFrameDialog.js \ - src/map/handler/Map.Infobar.js \ - src/map/handler/Map.Feedback.js \ - src/map/handler/Map.Welcome.js -endif - -COOL_JS_LST +=\ + src/layer/marker/DivOverlay.js \ src/main.js COOL_JS_WEBORDER = $(filter %,$(COOL_JS_LST)) @@ -534,7 +528,6 @@ $(DIST_FOLDER)/cool.html: $(srcdir)/html/cool.html.m4 \ $(DIST_FOLDER)/bundle.js @echo "Generating cool.html..." m4 -PE -DBUNDLE=$(IS_BUNDLE) \ - -DENABLE_FEEDBACK=$(ENABLE_FEEDBACK) \ -DIOSAPP=$(ENABLE_IOSAPP) \ -DGTKAPP=$(ENABLE_GTKAPP) \ -DANDROIDAPP=$(ENABLE_ANDROIDAPP) \ @@ -583,6 +576,7 @@ $(DIST_FOLDER)/%.html: $(srcdir)/html/%.html `ln -sf $(abs_srcdir)/$< $@`; \ fi +if ENABLE_WELCOME_MESSAGE $(DIST_FOLDER)/welcome/%: $(srcdir)/welcome/% @mkdir -p $(dir $@) @if test -z '$(ENABLE_BROWSERSYNC)'; then \ @@ -590,7 +584,7 @@ $(DIST_FOLDER)/welcome/%: $(srcdir)/welcome/% else \ `ln -sf $(abs_srcdir)/$< $@`; \ fi - +endif if ENABLE_DEBUG SourceMap=--allowJs true --sourceMap true --inlineSources true diff --git a/browser/html/cool.html.m4 b/browser/html/cool.html.m4 index ed7187d527..f829773165 100644 --- a/browser/html/cool.html.m4 +++ b/browser/html/cool.html.m4 @@ -14,13 +14,13 @@ m4_define(_YEAR_,m4_esyscmd(date +%Y|tr -d '\n')) <script> m4_dnl# Define MOBILEAPP as true if this is either for the iOS app or for the gtk+ "app" testbed + window.welcomeUrl = '%WELCOME_URL%'; + window.feedbackUrl = '%FEEDBACK_URL%'; + window.infobarUrl = '%INFOBAR_URL%'; m4_define([MOBILEAPP],[]) m4_ifelse(IOSAPP,[true],[m4_define([MOBILEAPP],[true])]) m4_ifelse(GTKAPP,[true],[m4_define([MOBILEAPP],[true])]) m4_ifelse(ANDROIDAPP,[true],[m4_define([MOBILEAPP],[true])]) - -m4_ifelse(ENABLE_FEEDBACK,[true],[ window.feedbackLocation = '%FEEDBACK_LOCATION%';]) - m4_ifelse(MOBILEAPP,[], // Start listening for Host_PostmessageReady message and save the // result for future @@ -304,7 +304,6 @@ m4_ifelse(MOBILEAPP,[true], window.postMessageOriginExt = ''; window.coolLogging = 'true'; window.enableWelcomeMessage = false; - window.enableWelcomeMessageButton = false; window.outOfFocusTimeoutSecs = 1000000; window.idleTimeoutSecs = 1000000; window.protocolDebug = false; @@ -324,7 +323,6 @@ m4_ifelse(MOBILEAPP,[true], window.coolLogging = '%BROWSER_LOGGING%'; window.coolwsdVersion = '%COOLWSD_VERSION%'; window.enableWelcomeMessage = %ENABLE_WELCOME_MSG%; - window.enableWelcomeMessageButton = %ENABLE_WELCOME_MSG_BTN%; window.userInterfaceMode = '%USER_INTERFACE_MODE%'; window.useIntegrationTheme = '%USE_INTEGRATION_THEME%'; window.enableMacrosExecution = '%ENABLE_MACROS_EXECUTION%'; diff --git a/browser/src/map/handler/Map.Feedback.js b/browser/src/map/handler/Map.Feedback.js index f66742fcbd..c62e181e4f 100644 --- a/browser/src/map/handler/Map.Feedback.js +++ b/browser/src/map/handler/Map.Feedback.js @@ -86,7 +86,7 @@ L.Map.Feedback = L.Handler.extend({ id: 'iframe-feedback', }; - this._iframeDialog = L.iframeDialog(window.feedbackLocation, params, null, options); + this._iframeDialog = L.iframeDialog(window.feedbackUrl, params, null, options); }, onError: function () { @@ -124,6 +124,6 @@ L.Map.Feedback = L.Handler.extend({ } } }); -if (window.feedbackLocation && window.isLocalStorageAllowed) { +if (window.feedbackUrl && window.isLocalStorageAllowed) { L.Map.addInitHook('addHandler', 'feedback', L.Map.Feedback); } diff --git a/browser/src/map/handler/Map.Infobar.js b/browser/src/map/handler/Map.Infobar.js index c471fab014..7278551bb2 100644 --- a/browser/src/map/handler/Map.Infobar.js +++ b/browser/src/map/handler/Map.Infobar.js @@ -37,7 +37,6 @@ L.Map.Infobar = L.Handler.extend({ this._map.off('updateviewslist', this.onUpdateList, this); L.DomEvent.on(window, 'message', this.onMessage, this); - var url = window.feedbackLocation.replace(/Rate\/feedback.html/g, 'UpdateCheck/updatecheck.html'); this.remove(); var loolwsdHash = document.querySelector('#loolwsd-version a') || {}; @@ -54,7 +53,7 @@ L.Map.Infobar = L.Handler.extend({ method: 'post' }; - this._iframeInfobar = L.iframeDialog(url, params, + this._iframeInfobar = L.iframeDialog(window.infobarUrl, params, L.DomUtil.get('main-document-content'), options); }, @@ -87,6 +86,6 @@ L.Map.Infobar = L.Handler.extend({ } }); -if (window.feedbackLocation) { +if (window.infobarUrl && window.isLocalStorageAllowed) { L.Map.addInitHook('addHandler', 'infobar', L.Map.Infobar); } diff --git a/browser/src/map/handler/Map.Welcome.js b/browser/src/map/handler/Map.Welcome.js index bdef5a9b03..2ec27686c4 100644 --- a/browser/src/map/handler/Map.Welcome.js +++ b/browser/src/map/handler/Map.Welcome.js @@ -14,7 +14,8 @@ L.Map.Welcome = L.Handler.extend({ L.Handler.prototype.initialize.call(this, map); this._map.on('statusindicator', this.onStatusIndicator, this); - this._url = window.feedbackLocation.replace(/Rate\/feedback.html/g, 'Welcome/welcome.html'); + this._url = window.enableWelcomeMessage ? L.LOUtil.getURL('/welcome/welcome.html') : + window.welcomeUrl; this._retries = 2; this._fallback = false; }, @@ -114,7 +115,7 @@ L.Map.Welcome = L.Handler.extend({ } }); -if (window.enableWelcomeMessage && window.feedbackLocation && window.isLocalStorageAllowed) { +if ((window.enableWelcomeMessage || window.welcomeUrl) && window.isLocalStorageAllowed) { L.Map.addInitHook('addHandler', 'welcome', L.Map.Welcome); } diff --git a/browser/welcome/welcome.js b/browser/welcome/welcome.js index 65eeb95f81..89ab11e3f4 100644 --- a/browser/welcome/welcome.js +++ b/browser/welcome/welcome.js @@ -1,31 +1,44 @@ window.onload = onLoaded; function onLoaded() { + var elem; window.addEventListener('message', onMessage, false); - document.getElementById('slide-1-button').onclick = function() { - onSlideClick('slide-2-indicator', true); - }; + elem = document.getElementById('slide-1-button'); + if (elem) + elem.onclick = function() { + onSlideClick('slide-2-indicator', true); + }; - document.getElementById('slide-2-button').onclick = function() { - onSlideClick('slide-3-indicator', true); - }; + elem = document.getElementById('slide-2-button'); + if (elem) + elem.onclick = function() { + onSlideClick('slide-3-indicator', true); + }; - document.getElementById('slide-3-button').onclick = function() { - onClose(); - }; + elem = document.getElementById('slide-3-button'); + if (elem) + elem.onclick = function() { + onClose(); + }; - document.getElementById('slide-1-indicator').onclick = function() { - onSlideClick('slide-1-indicator'); - }; + elem = document.getElementById('slide-1-indicator'); + if (elem) + elem.onclick = function() { + onSlideClick('slide-1-indicator'); + }; - document.getElementById('slide-2-indicator').onclick = function() { - onSlideClick('slide-2-indicator'); - }; + elem = document.getElementById('slide-2-indicator'); + if (elem) + elem.onclick = function() { + onSlideClick('slide-2-indicator'); + }; - document.getElementById('slide-3-indicator').onclick = function() { - onSlideClick('slide-3-indicator'); - }; + elem = document.getElementById('slide-3-indicator'); + if (elem) + elem.onclick = function() { + onSlideClick('slide-3-indicator'); + }; if (window.parent !== window.self) { var message = { diff --git a/configure.ac b/configure.ac index e05489e62f..eb0084e769 100644 --- a/configure.ac +++ b/configure.ac @@ -208,6 +208,11 @@ AC_ARG_WITH(info-url, [Set the info url of the build.]), ,) +AC_ARG_WITH(welcome-url, + AS_HELP_STRING([--with-welcome-url=<url>], + [Set the welcome url of the build.]), +,) + AC_ARG_ENABLE([seccomp], AS_HELP_STRING([--disable-seccomp], [Disable use of linux/seccomp.h header when kernel on target system does not support it. @@ -286,19 +291,13 @@ AC_ARG_WITH([max-documents], AS_HELP_STRING([--with-max-documents], [Set the limit on the total number of documents. Def: 10, Min: 2.])) -AC_ARG_WITH([feedback-location], - AS_HELP_STRING([--with-feedback-location=<url>], - [User feedback URL location. Default to http://127.0.0.1:8000/Rate/feedback.html])) +AC_ARG_WITH([feedback-url], + AS_HELP_STRING([--with-feedback-url=<url>], + [User feedback URL.])) -AC_ARG_ENABLE(welcome-message, - AS_HELP_STRING([--enable-welcome-message], - [Ensures welcome message is enabled on version update.]) -) - -AC_ARG_ENABLE(feedback, - AS_HELP_STRING([--enable-feedback], - [Enables feedback, user rating.]) -) +AC_ARG_WITH([infobar-url], + AS_HELP_STRING([--with-infobar-url=<url>], + [Infobar URL.])) AC_ARG_WITH([sanitizer], AS_HELP_STRING([--with-sanitizer], @@ -783,36 +782,35 @@ AS_IF([test "$MAX_DOCUMENTS" -lt "2"], AC_DEFINE_UNQUOTED([MAX_DOCUMENTS],[$MAX_DOCUMENTS],[Limit the maximum number of open documents]) AC_SUBST(MAX_DOCUMENTS) -ENABLE_FEEDBACK= -FEEDBACK_LOCATION= +FEEDBACK_URL= -WELCOME_CONFIG_FRAGMENT=/dev/null -ENABLE_WELCOME_MESSAGE=0 - -if test "$enable_feedback" = "yes"; then - ENABLE_FEEDBACK="true" +if test -n "$with_feedback_url"; then + FEEDBACK_URL=$with_feedback_url +fi - if test -n "$with_feedback_location"; then - FEEDBACK_LOCATION=$with_feedback_location - else - FEEDBACK_LOCATION="http://127.0.0.1:8000/Rate/feedback.html" - fi +AC_DEFINE_UNQUOTED([FEEDBACK_URL],["$FEEDBACK_URL"],[User feedback URL.]) - if test "$enable_welcome_message" = "yes"; then # allow configuration - ENABLE_WELCOME_MESSAGE=1 - else - WELCOME_CONFIG_FRAGMENT=$srcdir/coolwsd-welcome.xml - fi +INFOBAR_URL= +if test -n "$with_infobar_url"; then + INFOBAR_URL=$with_infobar_url fi -AC_DEFINE_UNQUOTED([ENABLE_FEEDBACK],["$ENABLE_FEEDBACK"],[User feedback rating]) -AC_DEFINE_UNQUOTED([FEEDBACK_LOCATION],["$FEEDBACK_LOCATION"],[User feedback URL location]) -AC_SUBST(ENABLE_FEEDBACK) -AM_CONDITIONAL([ENABLE_FEEDBACK], [test "$ENABLE_FEEDBACK" = "true"]) +AC_DEFINE_UNQUOTED([INFOBAR_URL],["$INFOBAR_URL"],[Infobar URL.]) + +WELCOME_CONFIG_FRAGMENT=/dev/null +ENABLE_WELCOME_MESSAGE=0 +WELCOME_URL= +if test -n "$with_welcome_url"; then + WELCOME_URL=$with_welcome_url + ENABLE_WELCOME_MESSAGE=1 +else + WELCOME_CONFIG_FRAGMENT=$srcdir/coolwsd-welcome.xml +fi AC_SUBST_FILE([WELCOME_CONFIG_FRAGMENT]) AC_DEFINE_UNQUOTED([ENABLE_WELCOME_MESSAGE],$ENABLE_WELCOME_MESSAGE,[Should the Release notes message be shown on upgrade]) -AC_SUBST(ENABLE_WELCOME) +AM_CONDITIONAL([ENABLE_WELCOME_MESSAGE], [test "$ENABLE_WELCOME_MESSAGE" = "1"]) +AC_DEFINE_UNQUOTED([WELCOME_URL],["$WELCOME_URL"],[The welcome url of the build.]) VEREIGN_URL= if test "$enable_vereign" = "yes"; then diff --git a/coolwsd-welcome.xml b/coolwsd-welcome.xml index 160f5df4a3..8fe19d37b1 100644 --- a/coolwsd-welcome.xml +++ b/coolwsd-welcome.xml @@ -1,5 +1,3 @@ <welcome> <enable type="bool" desc="Controls whether the welcome screen should be shown to the users on new install and updates." default="false">false</enable> - <enable_button type="bool" desc="Controls whether the welcome screen should have an explanatory button instead of an X button to close the dialog." default="true">true</enable_button> - <path desc="Path to 'welcome-$lang.html' files served on first start or when the version changes. When empty, defaults to the Release notes." type="path" relative="true" default="browser/welcome"></path> </welcome> diff --git a/wsd/COOLWSD.cpp b/wsd/COOLWSD.cpp index 968638b6c9..62a7624ace 100644 --- a/wsd/COOLWSD.cpp +++ b/wsd/COOLWSD.cpp @@ -867,7 +867,6 @@ std::string COOLWSD::LoTemplate = LO_PATH; std::string COOLWSD::ChildRoot; std::string COOLWSD::ServerName; std::string COOLWSD::FileServerRoot; -std::string COOLWSD::WelcomeFilesRoot; std::string COOLWSD::ServiceRoot; std::string COOLWSD::LOKitVersion; std::string COOLWSD::ConfigFile = COOLWSD_CONFIGDIR "/coolwsd.xml"; @@ -1487,8 +1486,6 @@ void COOLWSD::innerInitialize(Application& self) { "trace.path[@snapshot]", "false" }, { "trace[@enable]", "false" }, { "welcome.enable", "false" }, - { "welcome.enable_button", "true" }, - { "welcome.path", "browser/welcome" }, #ifdef ENABLE_FEATURE_LOCK { "feature_lock.locked_hosts[@allow]", "false"}, { "feature_lock.locked_hosts.fallback[@read_only]", "false"}, @@ -1864,12 +1861,7 @@ void COOLWSD::innerInitialize(Application& self) #if ENABLE_WELCOME_MESSAGE conf.setString("welcome.enable", "true"); - conf.setString("welcome.enable_button", "false"); - conf.setString("welcome.path", "browser/welcome"); #endif - WelcomeFilesRoot = getPathFromConfig("welcome.path"); - if (!getConfigValue<bool>(conf, "welcome.enable", true)) - WelcomeFilesRoot = ""; NumPreSpawnedChildren = getConfigValue<int>(conf, "num_prespawn_children", 1); if (NumPreSpawnedChildren < 1) @@ -4418,7 +4410,6 @@ public: << "\n LoTemplate: " << COOLWSD::LoTemplate << "\n ChildRoot: " << COOLWSD::ChildRoot << "\n FileServerRoot: " << COOLWSD::FileServerRoot - << "\n WelcomeFilesRoot: " << COOLWSD::WelcomeFilesRoot << "\n ServiceRoot: " << COOLWSD::ServiceRoot << "\n LOKitVersion: " << COOLWSD::LOKitVersion << "\n HostIdentifier: " << Util::getProcessIdentifier() diff --git a/wsd/COOLWSD.hpp b/wsd/COOLWSD.hpp index 718c0eda62..d513201351 100644 --- a/wsd/COOLWSD.hpp +++ b/wsd/COOLWSD.hpp @@ -245,7 +245,6 @@ public: static std::string ChildRoot; static std::string ServerName; static std::string FileServerRoot; - static std::string WelcomeFilesRoot; ///< From where we should serve the release notes (or otherwise useful content) that is shown on first install or version update. static std::string ServiceRoot; ///< There are installations that need prefixing every page with some path. static std::string LOKitVersion; static bool EnableTraceEventLogging; diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index e787c853e4..1c974a8b72 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -60,10 +60,6 @@ using Poco::Util::Application; std::map<std::string, std::pair<std::string, std::string>> FileServerRequestHandler::FileHash; -/// Place from where we serve the welcome-<lang>.html; defaults to -/// welcome.html if no lang matches. -#define WELCOME_ENDPOINT "/browser/dist/welcome" - namespace { int functionConversation(int /*num_msg*/, const struct pam_message** /*msg*/, @@ -546,43 +542,17 @@ void FileServerRequestHandler::handleRequest(const HTTPRequest& request, } } - // handling of the language in welcome-*.html - shorten the langtag as - // necessary, if we don't have the particular language version - if (Util::startsWith(relPath, WELCOME_ENDPOINT "/")) - { - bool found = true; - while (FileHash.find(relPath) == FileHash.end()) - { - size_t dot = relPath.find_last_of('.'); - if (dot == std::string::npos) - { - found = false; - break; - } - - size_t dash = relPath.find_last_of("-_", dot); - if (dash == std::string::npos) - { - found = false; - break; - } - - relPath = relPath.substr(0, dash) + relPath.substr(dot); - LOG_TRC("Shortening welcome file request to: " << relPath); - } - - if (!found) - throw Poco::FileNotFoundException("Invalid URI welcome file request: [" + requestUri.toString() + "]."); - - endPoint = relPath.substr(sizeof(WELCOME_ENDPOINT)); - } - // Is this a file we read at startup - if not; it's not for serving. if (FileHash.find(relPath) == FileHash.end()) throw Poco::FileNotFoundException("Invalid URI request: [" + requestUri.toString() + "]."); + if (endPoint == "welcome.html") + { + preprocessWelcomeFile(request, requestDetails, message, socket); + return; + } + if (endPoint == "cool.html" || - endPoint == "welcome.html" || endPoint == "help-localizations.json" || endPoint == "localizations.json" || endPoint == "locore-localizations.json" || @@ -839,16 +809,6 @@ void FileServerRequestHandler::initialize() } catch (...) { LOG_ERR("Failed to read from directory " << COOLWSD::FileServerRoot); } - - // welcome / release notes files - if (!COOLWSD::WelcomeFilesRoot.empty()) - { - try { - readDirToHash(COOLWSD::WelcomeFilesRoot, "", WELCOME_ENDPOINT); - } catch (...) { - LOG_ERR("Failed to read from directory " << COOLWSD::WelcomeFilesRoot); - } - } } const std::string *FileServerRequestHandler::getCompressedFile(const std::string &path) @@ -1038,14 +998,11 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, #if ENABLE_WELCOME_MESSAGE std::string enableWelcomeMessage = "true"; - std::string enableWelcomeMessageButton = "false"; #else // configurable std::string enableWelcomeMessage = stringifyBoolFromConfig(config, "welcome.enable", false); - std::string enableWelcomeMessageButton = stringifyBoolFromConfig(config, "welcome.enable_button", false); #endif Poco::replaceInPlace(preprocess, std::string("%ENABLE_WELCOME_MSG%"), enableWelcomeMessage); - Poco::replaceInPlace(preprocess, std::string("%ENABLE_WELCOME_MSG_BTN%"), enableWelcomeMessageButton); // the config value of 'notebookbar' or 'classic' overrides the UIMode // from the WOPI @@ -1071,10 +1028,9 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, std::string enableMacrosExecution = stringifyBoolFromConfig(config, "security.enable_macros_execution", false); Poco::replaceInPlace(preprocess, std::string("%ENABLE_MACROS_EXECUTION%"), enableMacrosExecution); -#ifdef ENABLE_FEEDBACK - Poco::URI uriFeedback(FEEDBACK_LOCATION); - Poco::replaceInPlace(preprocess, std::string("%FEEDBACK_LOCATION%"), std::string(FEEDBACK_LOCATION)); -#endif + Poco::replaceInPlace(preprocess, std::string("%FEEDBACK_URL%"), std::string(FEEDBACK_URL)); + Poco::replaceInPlace(preprocess, std::string("%WELCOME_URL%"), std::string(WELCOME_URL)); + Poco::replaceInPlace(preprocess, std::string("%INFOBAR_URL%"), std::string(INFOBAR_URL)); const std::string mimeType = "text/html"; @@ -1082,11 +1038,7 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, // iframe purposes. std::ostringstream cspOss; cspOss << "Content-Security-Policy: default-src 'none'; " -#ifdef ENABLE_FEEDBACK - "frame-src 'self' " << uriFeedback.getAuthority() << " blob: " << documentSigningURL << "; " -#else - "frame-src 'self' blob: " << documentSigningURL << "; " -#endif + "frame-src 'self' " << WELCOME_URL << " " << FEEDBACK_URL << " " << INFOBAR_URL << " blob: " << documentSigningURL << "; " "connect-src 'self' " << cnxDetails.getWebSocketUrl() << "; " "script-src 'unsafe-inline' 'self'; " "style-src 'self' 'unsafe-inline'; " @@ -1219,6 +1171,42 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, LOG_TRC("Sent file: " << relPath << ": " << preprocess); } + +void FileServerRequestHandler::preprocessWelcomeFile(const HTTPRequest& request, + const RequestDetails &/*requestDetails*/, + Poco::MemoryInputStream& /*message*/, + const std::shared_ptr<StreamSocket>& socket) +{ + Poco::Net::HTTPResponse response; + const std::string relPath = getRequestPathname(request); + LOG_DBG("Preprocessing file: " << relPath); + std::string templateWelcome = *getUncompressedFile(relPath); + +#if ENABLE_WELCOME_MESSAGE + std::string enableWelcomeMessage = "true"; +#else // configurable + const auto& config = Application::instance().config(); + std::string enableWelcomeMessage = stringifyBoolFromConfig(config, "welcome.enable", false); +#endif + + // Ask UAs to block if they detect any XSS attempt + response.add("X-XSS-Protection", "1; mode=block"); + // No referrer-policy + response.add("Referrer-Policy", "no-referrer"); + response.add("X-Content-Type-Options", "nosniff"); + response.set("Server", HTTP_SERVER_STRING); + response.set("Date", Util::getHttpTimeNow()); + + response.setContentType("text/html"); + response.setChunkedTransferEncoding(false); + + std::ostringstream oss; + response.write(oss); + oss << templateWelcome; + socket->send(oss.str()); + LOG_TRC("Sent file: " << relPath); +} + void FileServerRequestHandler::preprocessAdminFile(const HTTPRequest& request, const RequestDetails &requestDetails, const std::shared_ptr<StreamSocket>& socket) diff --git a/wsd/FileServer.hpp b/wsd/FileServer.hpp index 1f6cc4f413..4a46cdd4e2 100644 --- a/wsd/FileServer.hpp +++ b/wsd/FileServer.hpp @@ -25,6 +25,10 @@ class FileServerRequestHandler const RequestDetails &requestDetails, Poco::MemoryInputStream& message, const std::shared_ptr<StreamSocket>& socket); + static void preprocessWelcomeFile(const Poco::Net::HTTPRequest& request, + const RequestDetails &requestDetails, + Poco::MemoryInputStream& message, + const std::shared_ptr<StreamSocket>& socket); static void preprocessAdminFile(const Poco::Net::HTTPRequest& request, const RequestDetails &requestDetails, const std::shared_ptr<StreamSocket>& socket); |