2021-05-29 07:31:33 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
|
|
|
|
/*
|
2023-11-09 12:23:00 -06:00
|
|
|
* Copyright the Collabora Online contributors.
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
*
|
2021-05-29 07:31:33 -05:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
2021-07-05 05:18:21 -05:00
|
|
|
#pragma once
|
2021-05-29 07:31:33 -05:00
|
|
|
|
|
|
|
#include <string>
|
2021-09-17 08:49:06 -05:00
|
|
|
#include <unordered_set>
|
2021-05-29 07:31:33 -05:00
|
|
|
#include "ConfigUtil.hpp"
|
2022-02-07 23:50:09 -06:00
|
|
|
#include <Poco/Util/LayeredConfiguration.h>
|
2022-07-05 07:03:14 -05:00
|
|
|
#include <Poco/URI.h>
|
|
|
|
#include <Poco/Exception.h>
|
|
|
|
#include <Log.hpp>
|
2021-05-29 07:31:33 -05:00
|
|
|
|
2021-09-13 14:24:50 -05:00
|
|
|
namespace CommandControl
|
2021-05-29 07:31:33 -05:00
|
|
|
{
|
2022-02-10 05:22:47 -06:00
|
|
|
class LockManager
|
2021-05-29 07:31:33 -05:00
|
|
|
{
|
2022-02-10 05:22:47 -06:00
|
|
|
static std::unordered_set<std::string> LockedCommandList;
|
|
|
|
static bool _isLockedUser;
|
2022-02-07 23:50:09 -06:00
|
|
|
static bool _isHostReadOnly;
|
2022-02-10 05:22:47 -06:00
|
|
|
static std::string LockedCommandListString;
|
2022-07-05 07:03:14 -05:00
|
|
|
static std::string translationPath;
|
2021-05-29 07:31:33 -05:00
|
|
|
|
2022-02-10 05:22:47 -06:00
|
|
|
static void generateLockedCommandList();
|
2021-05-29 07:31:33 -05:00
|
|
|
|
|
|
|
public:
|
2022-02-10 05:22:47 -06:00
|
|
|
LockManager();
|
|
|
|
static const std::unordered_set<std::string>& getLockedCommandList();
|
|
|
|
static const std::string getLockedCommandListString();
|
|
|
|
|
2022-02-07 23:50:09 -06:00
|
|
|
// Allow/deny Locked hosts
|
|
|
|
static Util::RegexListMatcher readOnlyWopiHosts;
|
|
|
|
static Util::RegexListMatcher disabledCommandWopiHosts;
|
2022-07-14 05:26:58 -05:00
|
|
|
static std::map<std::string, std::string> unlockLinkMap;
|
|
|
|
static std::string unlockLink;
|
2022-02-07 23:50:09 -06:00
|
|
|
static bool lockHostEnabled;
|
|
|
|
|
|
|
|
static void parseLockedHost(Poco::Util::LayeredConfiguration& conf);
|
|
|
|
|
2022-02-10 05:22:47 -06:00
|
|
|
static bool isLockedUser() { return _isLockedUser; }
|
2022-02-07 23:50:09 -06:00
|
|
|
static bool isLockReadOnly()
|
|
|
|
{
|
|
|
|
return config::getBool("feature_lock.is_lock_readonly", false) || isHostReadOnly();
|
|
|
|
}
|
|
|
|
static bool isHostReadOnly() { return _isHostReadOnly; };
|
2022-02-10 05:22:47 -06:00
|
|
|
static bool isLockedReadOnlyUser() { return isLockedUser() && isLockReadOnly(); }
|
|
|
|
|
2022-02-07 23:50:09 -06:00
|
|
|
static bool isHostReadOnly(const std::string& host);
|
|
|
|
static bool isHostCommandDisabled(const std::string& host);
|
|
|
|
static bool hostExist(const std::string& host);
|
|
|
|
|
2022-02-10 05:22:47 -06:00
|
|
|
static void setLockedUser(bool isLocked) { _isLockedUser = isLocked; }
|
2022-02-07 23:50:09 -06:00
|
|
|
static void setHostReadOnly(bool isReadOnly) { _isHostReadOnly = isReadOnly; }
|
2022-07-05 07:03:14 -05:00
|
|
|
static void setTranslationPath(const std::string& lockedDialogLang);
|
2022-02-10 05:22:47 -06:00
|
|
|
static std::string getUnlockTitle()
|
|
|
|
{
|
2022-07-05 07:03:14 -05:00
|
|
|
if (config::has(translationPath + ".unlock_title"))
|
|
|
|
return config::getString(translationPath + ".unlock_title", "");
|
2022-02-10 05:22:47 -06:00
|
|
|
return config::getString("feature_lock.unlock_title", "");
|
|
|
|
}
|
2022-07-05 07:03:14 -05:00
|
|
|
static std::string getUnlockLink()
|
|
|
|
{
|
2022-07-14 05:26:58 -05:00
|
|
|
if (!unlockLink.empty())
|
|
|
|
return unlockLink;
|
2022-07-05 07:03:14 -05:00
|
|
|
return config::getString("feature_lock.unlock_link", "");
|
|
|
|
}
|
2022-02-10 05:22:47 -06:00
|
|
|
static std::string getUnlockDescription()
|
|
|
|
{
|
2022-07-05 07:03:14 -05:00
|
|
|
if (config::has(translationPath + ".unlock_description"))
|
|
|
|
return config::getString(translationPath + ".unlock_description", "");
|
2022-02-10 05:22:47 -06:00
|
|
|
return config::getString("feature_lock.unlock_description", "");
|
|
|
|
}
|
|
|
|
static std::string getWriterHighlights()
|
|
|
|
{
|
2022-07-05 07:03:14 -05:00
|
|
|
if (config::has(translationPath + ".writer_unlock_highlights"))
|
|
|
|
return config::getString(translationPath + ".writer_unlock_highlights", "");
|
2022-02-10 05:22:47 -06:00
|
|
|
return config::getString("feature_lock.writer_unlock_highlights", "");
|
|
|
|
}
|
|
|
|
static std::string getCalcHighlights()
|
|
|
|
{
|
2022-07-05 07:03:14 -05:00
|
|
|
if (config::has(translationPath + ".calc_unlock_highlights"))
|
|
|
|
return config::getString(translationPath + ".calc_unlock_highlights", "");
|
2022-02-10 05:22:47 -06:00
|
|
|
return config::getString("feature_lock.calc_unlock_highlights", "");
|
|
|
|
}
|
|
|
|
static std::string getImpressHighlights()
|
|
|
|
{
|
2022-07-05 07:03:14 -05:00
|
|
|
if (config::has(translationPath + ".impress_unlock_highlights"))
|
|
|
|
return config::getString(translationPath + ".impress_unlock_highlights", "");
|
2022-02-10 05:22:47 -06:00
|
|
|
return config::getString("feature_lock.impress_unlock_highlights", "");
|
|
|
|
}
|
|
|
|
static std::string getDrawHighlights()
|
|
|
|
{
|
2022-07-05 07:03:14 -05:00
|
|
|
if (config::has(translationPath + ".draw_unlock_highlights"))
|
|
|
|
return config::getString(translationPath + ".draw_unlock_highlights", "");
|
2022-02-10 05:22:47 -06:00
|
|
|
return config::getString("feature_lock.draw_unlock_highlights", "");
|
|
|
|
}
|
2022-07-05 07:03:14 -05:00
|
|
|
static const Poco::URI getUnlockImageUri()
|
|
|
|
{
|
|
|
|
const std::string unlockImageUrl = config::getString("feature_lock.unlock_image", "");
|
|
|
|
if (!unlockImageUrl.empty())
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const Poco::URI unlockImageUri(unlockImageUrl);
|
|
|
|
return unlockImageUri;
|
|
|
|
}
|
|
|
|
catch (Poco::SyntaxException& exc)
|
|
|
|
{
|
|
|
|
LOG_ERR("Parsing of unlock_image url failed with " << exc.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return Poco::URI();
|
|
|
|
}
|
2022-07-14 05:26:58 -05:00
|
|
|
static void resetTransalatioPath() { translationPath = std::string(); }
|
|
|
|
static void mapUnlockLink(const std::string& host, const std::string& path);
|
|
|
|
static void setUnlockLink(const std::string& host)
|
2022-07-05 07:03:14 -05:00
|
|
|
{
|
2022-07-14 05:26:58 -05:00
|
|
|
unlockLink = Util::getValue(unlockLinkMap, host);
|
2022-07-05 07:03:14 -05:00
|
|
|
}
|
2021-05-29 07:31:33 -05:00
|
|
|
};
|
2021-09-13 15:02:43 -05:00
|
|
|
|
|
|
|
class RestrictionManager
|
|
|
|
{
|
2021-09-17 08:49:06 -05:00
|
|
|
static std::unordered_set<std::string> RestrictedCommandList;
|
2021-09-13 15:02:43 -05:00
|
|
|
static bool _isRestrictedUser;
|
|
|
|
static std::string RestrictedCommandListString;
|
|
|
|
|
|
|
|
static void generateRestrictedCommandList();
|
|
|
|
|
|
|
|
public:
|
|
|
|
RestrictionManager();
|
2021-09-17 08:49:06 -05:00
|
|
|
static const std::unordered_set<std::string>& getRestrictedCommandList();
|
2021-09-13 15:02:43 -05:00
|
|
|
static const std::string getRestrictedCommandListString();
|
|
|
|
|
|
|
|
static bool isRestrictedUser() { return _isRestrictedUser; }
|
|
|
|
|
|
|
|
static void setRestrictedUser(bool isRestrictedUser) { _isRestrictedUser = isRestrictedUser; }
|
|
|
|
};
|
2021-09-13 14:24:50 -05:00
|
|
|
} // namespace CommandControl
|
2021-05-29 07:31:33 -05:00
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|