From 9253478679b265a076c5822905bf41f6a96ec9a3 Mon Sep 17 00:00:00 2001 From: Rashesh Date: Thu, 14 Nov 2024 04:48:00 +0530 Subject: [PATCH] lokit: mount childroot/tmp/incoming/templates over instdir/share/common/template/presnt - once we can download the templates from remote server it can be access by lokit and gets added to MasterSlides impress Signed-off-by: Rashesh Change-Id: I55cb4f340f66d353594331e25debd7124f25f042 --- common/JailUtil.cpp | 4 +++- kit/Kit.cpp | 32 ++++++++++++++++++++++++++++++++ wsd/COOLWSD.cpp | 18 +++++++++++++++++- wsd/COOLWSD.hpp | 1 + 4 files changed, 53 insertions(+), 2 deletions(-) diff --git a/common/JailUtil.cpp b/common/JailUtil.cpp index c2e42138dd736..f0ce50bfa8b5e 100644 --- a/common/JailUtil.cpp +++ b/common/JailUtil.cpp @@ -426,7 +426,9 @@ void setupChildRoot(bool bindMount, const std::string& childRoot, const std::str { // Start with a clean slate. cleanupJails(childRoot); - createJailPath(childRoot + CHILDROOT_TMP_INCOMING_PATH); + + createJailPath(childRoot + CHILDROOT_TMP_INCOMING_PATH + "/fonts"); + createJailPath(childRoot + CHILDROOT_TMP_INCOMING_PATH + "/templates"); disableBindMounting(); // Clear to avoid surprises. diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 25cea412a4cce..2e74913e58a57 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -3189,6 +3189,10 @@ void lokit_main( const std::string tmpSubDir = Poco::Path(tempRoot, "cool-" + jailId).toString(); const std::string jailTmpDir = Poco::Path(jailPath, "tmp").toString(); + const std::string tmpIncoming = Poco::Path(childRoot, JailUtil::CHILDROOT_TMP_INCOMING_PATH).toString(); + const std::string sharedTemplate = Poco::Path(tmpIncoming, "templates").toString(); + const std::string loJailDestImpressTemplatePath = Poco::Path(loJailDestPath, "share/template/common/presnt").toString(); + const std::string sysTemplateSubDir = Poco::Path(tempRoot, "systemplate-" + jailId).toString(); const std::string jailEtcDir = Poco::Path(jailPath, "etc").toString(); @@ -3248,6 +3252,34 @@ void lokit_main( return false; } + // copy default tempates from 'common' dir to shared templates dir + // TODO: maybe I shouldn't copy if whole point to mounting is that we don't require copying. Maybe symlink it + auto defaultTemplates = FileUtil::getDirEntries(loJailDestImpressTemplatePath); + for (auto& name : defaultTemplates) + { + std::string sourcePath = loJailDestImpressTemplatePath; + sourcePath.append("/"); + sourcePath.append(name); + std::string destPath = sharedTemplate; + destPath.append("/"); + destPath.append(name); + if (!FileUtil::copy(sourcePath, destPath, false, false)) + { + LOG_WRN("Failed to copy default impress template from [" + << sourcePath << "] to [" << sharedTemplate << ']'); + } + } + + // mount the shared templates over the lo shared templates' 'common' dir + if (!JailUtil::bind(sharedTemplate, loJailDestImpressTemplatePath) || + !JailUtil::remountReadonly(sharedTemplate, loJailDestImpressTemplatePath)) + { + // TODO: actually do this link on failure + LOG_WRN("Failed to mount [" << sharedTemplate << "] -> [" << sharedTemplate + << "], will link contents"); + return false; + } + // tmpdir inside the jail for added sercurity. Poco::File(tmpSubDir).createDirectories(); LOG_INF("Mounting random temp dir " << tmpSubDir << " -> " << jailTmpDir); diff --git a/wsd/COOLWSD.cpp b/wsd/COOLWSD.cpp index 115a947018844..f1a36d250065f 100644 --- a/wsd/COOLWSD.cpp +++ b/wsd/COOLWSD.cpp @@ -674,6 +674,7 @@ std::string COOLWSD::ServerName; std::string COOLWSD::FileServerRoot; std::string COOLWSD::ServiceRoot; std::string COOLWSD::TmpFontDir; +std::string COOLWSD::TmpTemplateDir; std::string COOLWSD::LOKitVersion; std::string COOLWSD::ConfigFile = COOLWSD_CONFIGDIR "/coolwsd.xml"; std::string COOLWSD::ConfigDir = COOLWSD_CONFIGDIR "/conf.d"; @@ -1340,6 +1341,8 @@ void COOLWSD::innerInitialize(Poco::Util::Application& self) { "extra_export_formats.impress_png", "false" }, { "extra_export_formats.impress_svg", "false" }, { "extra_export_formats.impress_tiff", "false" }, + { "remote_template_config.url", ""}, + { "remote_font_config.url", ""}, }; // Set default values, in case they are missing from the config file. @@ -3600,7 +3603,8 @@ int COOLWSD::innerMain() assert(Server && "The COOLWSDServer instance does not exist."); Server->findClientPort(); - TmpFontDir = ChildRoot + JailUtil::CHILDROOT_TMP_INCOMING_PATH; + TmpFontDir = ChildRoot + JailUtil::CHILDROOT_TMP_INCOMING_PATH + "/fonts"; + TmpTemplateDir = ChildRoot + JailUtil::CHILDROOT_TMP_INCOMING_PATH + "/templates"; // Start the internal prisoner server and spawn forkit, // which in turn forks first child. @@ -3672,6 +3676,18 @@ int COOLWSD::innerMain() { LOG_DBG("No remote_font_config"); } + + std::unique_ptr remoteTemplateConfigThread; + try + { + // Fetch font settings from server if configured + remoteTemplateConfigThread = std::make_unique(config()); + remoteTemplateConfigThread->start(); + } + catch (const Poco::Exception&) + { + LOG_DBG("No remote_template_config"); + } #endif // URI with /contents are public and we don't need to anonymize them. diff --git a/wsd/COOLWSD.hpp b/wsd/COOLWSD.hpp index 7217500293a66..b2907e74aba8b 100644 --- a/wsd/COOLWSD.hpp +++ b/wsd/COOLWSD.hpp @@ -273,6 +273,7 @@ class COOLWSD final : public Poco::Util::ServerApplication, static std::string FileServerRoot; static std::string ServiceRoot; ///< There are installations that need prefixing every page with some path. static std::string TmpFontDir; + static std::string TmpTemplateDir; static std::string LOKitVersion; static bool EnableTraceEventLogging; static bool EnableAccessibility;