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
private/pedro/fix-codeql-analysis
Henry Castro 2022-03-30 11:43:55 -04:00 committed by Andras Timar
parent 6c69202b18
commit c550a206e8
13 changed files with 137 additions and 156 deletions

View File

@ -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>

View File

@ -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

View File

@ -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%';

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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);
}

View File

@ -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 = {

View File

@ -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=
if test -n "$with_feedback_url"; then
FEEDBACK_URL=$with_feedback_url
fi
AC_DEFINE_UNQUOTED([FEEDBACK_URL],["$FEEDBACK_URL"],[User feedback URL.])
INFOBAR_URL=
if test -n "$with_infobar_url"; then
INFOBAR_URL=$with_infobar_url
fi
AC_DEFINE_UNQUOTED([INFOBAR_URL],["$INFOBAR_URL"],[Infobar URL.])
WELCOME_CONFIG_FRAGMENT=/dev/null
ENABLE_WELCOME_MESSAGE=0
if test "$enable_feedback" = "yes"; then
ENABLE_FEEDBACK="true"
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
if test "$enable_welcome_message" = "yes"; then # allow configuration
ENABLE_WELCOME_MESSAGE=1
else
WELCOME_CONFIG_FRAGMENT=$srcdir/coolwsd-welcome.xml
fi
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_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_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

View File

@ -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>

View File

@ -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()

View File

@ -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;

View File

@ -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)

View File

@ -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);