Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve impress templates #10463

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion common/JailUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
4 changes: 4 additions & 0 deletions coolwsd.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,10 @@
<url desc="URL of optional JSON file that lists fonts to be included in Online" type="string" default=""></url>
</remote_font_config>

<remote_asset_config>
<url desc="URL of optional JSON file that lists fonts and impress template to be included in Online" type="string" default=""></url>
</remote_asset_config>

<home_mode>
<enable desc="Enable more configuration options for home users" type="bool" default="false">false</enable>
</home_mode>
Expand Down
32 changes: 32 additions & 0 deletions kit/Kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3254,6 +3254,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();

Expand Down Expand Up @@ -3313,6 +3317,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.
Copy link
Contributor Author

@Rash419 Rash419 Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, how can we improve here except of copying default templates ?

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
Copy link
Contributor Author

@Rash419 Rash419 Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I disable the mounting default templates templates doesn't show up at all. 1st we need to fix default template loading issue I think

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);
Expand Down
41 changes: 34 additions & 7 deletions wsd/COOLWSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,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";
Expand Down Expand Up @@ -1346,6 +1347,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.
Expand Down Expand Up @@ -3619,7 +3622,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.
Expand Down Expand Up @@ -3679,17 +3683,40 @@ int COOLWSD::innerMain()
LOG_ERR("Log level is set very high to '" << LogLevel << "' this will have a "
"significant performance impact. Do not use this in production.");

// Start the remote font downloading polling thread.
std::unique_ptr<RemoteFontConfigPoll> remoteFontConfigThread;
std::string uriConfigKey;
const std::string& fontConfigKey = "remote_font_config.url";
const std::string& assetConfigKey = "remote_asset_config.url";
bool remoteFontDefined = !ConfigUtil::getConfigValue<std::string>(fontConfigKey, "").empty();
bool remoteAssetDefined = !ConfigUtil::getConfigValue<std::string>(assetConfigKey, "").empty();
// Both defined: warn and use assetConfigKey
if (remoteFontDefined && remoteAssetDefined)
{
LOG_WRN("Both remote_font_config.url and remote_asset_config.url are defined, "
"remote_asset_config.url is overriden on remote_font_config.url");
uriConfigKey = assetConfigKey;
}
// only font defined: use fontConfigKey
else if (remoteFontDefined && !remoteAssetDefined)
{
uriConfigKey = fontConfigKey;
}
// only asset defined: use assetConfigKey
else if (!remoteFontDefined && remoteAssetDefined)
{
uriConfigKey = assetConfigKey;
}

// Start the remote asset downloading polling thread.
std::unique_ptr<RemoteAssetConfigPoll> remoteAssetConfigThread;
try
{
// Fetch font settings from server if configured
remoteFontConfigThread = std::make_unique<RemoteFontConfigPoll>(config());
remoteFontConfigThread->start();
// Fetch font and/or templates settings from server if configured
remoteAssetConfigThread = std::make_unique<RemoteAssetConfigPoll>(config(), uriConfigKey);
remoteAssetConfigThread->start();
}
catch (const Poco::Exception&)
{
LOG_DBG("No remote_font_config");
LOG_DBG("No remote_asset_config");
}
#endif

Expand Down
1 change: 1 addition & 0 deletions wsd/COOLWSD.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,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;
Expand Down
Loading
Loading