[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/Storage.cpp wsd/Storage.hpp
wsd/ClientSession.cpp | 35 +++ wsd/DocumentBroker.cpp | 13 - wsd/DocumentBroker.hpp |9 + wsd/Storage.cpp| 20 +--- wsd/Storage.hpp| 24 5 files changed, 93 insertions(+), 8 deletions(-) New commits: commit b3bdd5786d48da4b4073d05b9eddba9d242ac6bf Author: Ashod Nakashian Date: Tue Apr 24 12:09:37 2018 -0400 wsd: support optional forcing tracking changes at load Since changing the tracking state is done by toggling, we need to wait to get the current state at load time before we can tell whether we need to toggle it or not. Change-Id: Ib5a2639b2acf3874c191971eedf9a3bebcefebad Reviewed-on: https://gerrit.libreoffice.org/53415 Reviewed-by: Jan Holesovsky Tested-by: Jan Holesovsky diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 8203b2a34..70ee741fa 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -19,6 +19,7 @@ #include "DocumentBroker.hpp" #include "LOOLWSD.hpp" +#include "Storage.hpp" #include #include #include @@ -738,6 +739,40 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt { docBroker->setModified(stateTokens[1] == "true"); } +else +{ +// Set the initial settings per the user's request. +const std::pair unoStatePair = LOOLProtocol::split(tokens[1], '='); + +if (!docBroker->isInitialSettingSet(unoStatePair.first)) +{ +docBroker->setInitialSetting(unoStatePair.first); +if (unoStatePair.first == ".uno:TrackChanges") +{ +if ((unoStatePair.second == "true" && + _wopiFileInfo->_disableChangeTrackingRecord == WopiStorage::WOPIFileInfo::TriState::True) || +(unoStatePair.second == "false" && + _wopiFileInfo->_disableChangeTrackingRecord == WopiStorage::WOPIFileInfo::TriState::False)) +{ +// Toggle the TrackChanges state. +LOG_DBG("Forcing " << unoStatePair.first << " toggle per user settings."); +forwardToChild("uno .uno:TrackChanges", docBroker); +} +} +else if (unoStatePair.first == ".uno:ShowTrackedChanges") +{ +if ((unoStatePair.second == "true" && + _wopiFileInfo->_disableChangeTrackingShow == WopiStorage::WOPIFileInfo::TriState::True) || +(unoStatePair.second == "false" && + _wopiFileInfo->_disableChangeTrackingShow == WopiStorage::WOPIFileInfo::TriState::False)) +{ +// Toggle the ShowTrackChanges state. +LOG_DBG("Forcing " << unoStatePair.first << " toggle per user settings."); +forwardToChild("uno .uno:ShowTrackedChanges", docBroker); +} +} +} +} } if (!_isDocPasswordProtected) diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 1006dc2dc..4d465a39d 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -502,12 +502,13 @@ bool DocumentBroker::load(const std::shared_ptr& session, const s wopiInfo->set("HidePrintOption", wopifileinfo->_hidePrintOption); wopiInfo->set("HideSaveOption", wopifileinfo->_hideSaveOption); wopiInfo->set("HideExportOption", wopifileinfo->_hideExportOption); -wopiInfo->set("HideChangeTrackingControls", wopifileinfo->_hideChangeTrackingControls); wopiInfo->set("DisablePrint", wopifileinfo->_disablePrint); wopiInfo->set("DisableExport", wopifileinfo->_disableExport); wopiInfo->set("DisableCopy", wopifileinfo->_disableCopy); wopiInfo->set("DisableInactiveMessages", wopifileinfo->_disableInactiveMessages); wopiInfo->set("UserCanNotWriteRelative", wopifileinfo->_userCanNotWriteRelative); +if (wopifileinfo->_hideChangeTrackingControls != WopiStorage::WOPIFileInfo::TriState::Unset) +wopiInfo->set("HideChangeTrackingControls", wopifileinfo->_hideChangeTrackingControls == WopiStorage::WOPIFileInfo::TriState::True); std::ostringstream ossWopiInfo; wopiInfo->stringify(ossWopiInfo); @@ -1447,6 +1448,16 @@ void DocumentBroker::setModified(const bool value) _tileCache->setUnsavedChanges(value); } +bool DocumentBroker::isInitialSettingSet(const std::string& name) const +{ +return _isInitialStateSet.find(name) != _isInitialStateSet.end(); +} + +void DocumentBroker::setInitialSetting(const std::string& name) +{ +_isInitialStateSet.emplace(name); +} + bool DocumentBroker::forwardToChild(const std::string& viewId, const std::string&
[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/Storage.cpp wsd/Storage.hpp
wsd/ClientSession.cpp |1 wsd/DocumentBroker.cpp | 19 - wsd/DocumentBroker.hpp |1 wsd/Storage.cpp| 46 ++- wsd/Storage.hpp| 52 +++-- 5 files changed, 21 insertions(+), 98 deletions(-) New commits: commit 9db41725f423f00f95db4b68d70827d24f80bb6c Author: Jan HolesovskyDate: Fri May 19 10:32:24 2017 +0200 Revert "wsd: use WOPI host instance ID to support hostname aliases" Turns out this introduces two calls to the CheckFileInfo which is not really what we should be doing; instead, let's do a kind of cannonicalization in the WOPI host directly. This reverts commit ec2fd0844f997f9a7347229e282daeb8dc4471bc. Change-Id: I311bf8a45b706ed9a4d8cd00db0a990ac6d461b4 diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 479bc2b9..105b30d3 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -737,6 +737,7 @@ bool ClientSession::forwardToClient(const std::shared_ptr& payload) std::string ClientSession::getAccessToken() const { +std::string accessToken; Poco::URI::QueryParameters queryParams = _uriPublic.getQueryParameters(); for (auto& param: queryParams) { diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 66a5de80..e5924f87 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -102,7 +102,15 @@ Poco::URI DocumentBroker::sanitizeURI(const std::string& uri) std::string DocumentBroker::getDocKey(const Poco::URI& uri) { -return StorageBase::getUniqueDocId(uri); +// If multiple host-names are used to access us, then +// we force same document (when opened from +// alias hosts) to load as separate documents and sharing doesn't +// work. Worse, saving overwrites one another. +// But we also do not want different WOPI hosts using the same path +// for some file getting shared across WOPI hosts +std::string docKey; +Poco::URI::encode(uri.getHost() + ":" + std::to_string(uri.getPort()) + uri.getPath(), "", docKey); +return docKey; } /// The Document Broker Poll - one of these in a thread per document @@ -401,7 +409,6 @@ bool DocumentBroker::load(const std::shared_ptr& session, const s LOG_ERR("Failed to create Storage instance for [" << _docKey << "] in " << jailPath.toString()); return false; } - firstInstance = true; } @@ -416,14 +423,6 @@ bool DocumentBroker::load(const std::shared_ptr& session, const s std::unique_ptr wopifileinfo = wopiStorage->getWOPIFileInfo(session->getAccessToken()); userid = wopifileinfo->_userid; username = wopifileinfo->_username; -if (firstInstance) -{ -_hostInstanceId = wopifileinfo->_hostInstanceId; -} -else if (!_hostInstanceId.empty() && _hostInstanceId != wopifileinfo->_hostInstanceId) -{ -throw UnauthorizedRequestException("Unauthorized WOPI host."); -} if (!wopifileinfo->_userCanWrite) { diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 8ac67ee2..46481cba 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -369,7 +369,6 @@ private: Poco::URI _uriJailed; std::string _jailId; std::string _filename; -std::string _hostInstanceId; /// The last time we tried saving, regardless of whether the /// document was modified and saved or not. diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index 0c31e53c..12f0a49e 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -125,7 +125,7 @@ void StorageBase::initialize() #endif } -bool StorageBase::isLocalhost(const std::string& targetHost) +bool isLocalhost(const std::string& targetHost) { std::string targetAddress; try @@ -202,7 +202,7 @@ std::unique_ptr StorageBase::create(const Poco::URI& uri, const std { LOG_INF("Public URI [" << uri.toString() << "] considered WOPI."); const auto& targetHost = uri.getHost(); -if (isWopiHostAuthorized(targetHost)) +if (WopiHosts.match(targetHost) || isLocalhost(targetHost)) { return std::unique_ptr(new WopiStorage(uri, jailRoot, jailPath)); } @@ -213,39 +213,6 @@ std::unique_ptr StorageBase::create(const Poco::URI& uri, const std throw BadRequestException("No Storage configured or invalid URI."); } -std::string StorageBase::getUniqueDocId(const Poco::URI& uri) -{ -std::string docId; -if (uri.isRelative() || uri.getScheme() == "file") -{ -Poco::URI::encode(uri.getPath(), "", docId); -} -else if (WopiEnabled) -{ -const auto& targetHost = uri.getHost(); -if (isWopiHostAuthorized(targetHost)) -{ -std::string accessToken; -Poco::URI::QueryParameters queryParams = uri.getQueryParameters(); -
[Libreoffice-commits] online.git: wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/Storage.cpp wsd/Storage.hpp
wsd/ClientSession.cpp |1 wsd/DocumentBroker.cpp | 19 + wsd/DocumentBroker.hpp |1 wsd/Storage.cpp| 46 --- wsd/Storage.hpp| 52 + 5 files changed, 98 insertions(+), 21 deletions(-) New commits: commit ec2fd0844f997f9a7347229e282daeb8dc4471bc Author: Ashod NakashianDate: Tue May 16 16:38:44 2017 -0400 wsd: use WOPI host instance ID to support hostname aliases The docKey creation moved to Storage where we first invoke WOPI (if/when it's a WOPI-hosted doc and WOPI enabled) and see if the user has access to the document at all. If they do, we expect the server to give us a unique ID to use for identifying the host regardless of hostname aliases. If a unique ID is not returned (i.e. empty or missing) we use the hostname and port in its place as fallback. This will break hostname aliases, but it will still work. Change-Id: I407b0087395f9df6ad9cc6e037570487999be4a4 Reviewed-on: https://gerrit.libreoffice.org/37697 Reviewed-by: Ashod Nakashian Tested-by: Ashod Nakashian diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 5a0af025..8ce4c327 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -736,7 +736,6 @@ bool ClientSession::forwardToClient(const std::shared_ptr& payload) std::string ClientSession::getAccessToken() const { -std::string accessToken; Poco::URI::QueryParameters queryParams = _uriPublic.getQueryParameters(); for (auto& param: queryParams) { diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index e5924f87..66a5de80 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -102,15 +102,7 @@ Poco::URI DocumentBroker::sanitizeURI(const std::string& uri) std::string DocumentBroker::getDocKey(const Poco::URI& uri) { -// If multiple host-names are used to access us, then -// we force same document (when opened from -// alias hosts) to load as separate documents and sharing doesn't -// work. Worse, saving overwrites one another. -// But we also do not want different WOPI hosts using the same path -// for some file getting shared across WOPI hosts -std::string docKey; -Poco::URI::encode(uri.getHost() + ":" + std::to_string(uri.getPort()) + uri.getPath(), "", docKey); -return docKey; +return StorageBase::getUniqueDocId(uri); } /// The Document Broker Poll - one of these in a thread per document @@ -409,6 +401,7 @@ bool DocumentBroker::load(const std::shared_ptr& session, const s LOG_ERR("Failed to create Storage instance for [" << _docKey << "] in " << jailPath.toString()); return false; } + firstInstance = true; } @@ -423,6 +416,14 @@ bool DocumentBroker::load(const std::shared_ptr& session, const s std::unique_ptr wopifileinfo = wopiStorage->getWOPIFileInfo(session->getAccessToken()); userid = wopifileinfo->_userid; username = wopifileinfo->_username; +if (firstInstance) +{ +_hostInstanceId = wopifileinfo->_hostInstanceId; +} +else if (!_hostInstanceId.empty() && _hostInstanceId != wopifileinfo->_hostInstanceId) +{ +throw UnauthorizedRequestException("Unauthorized WOPI host."); +} if (!wopifileinfo->_userCanWrite) { diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp index 46481cba..8ac67ee2 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -369,6 +369,7 @@ private: Poco::URI _uriJailed; std::string _jailId; std::string _filename; +std::string _hostInstanceId; /// The last time we tried saving, regardless of whether the /// document was modified and saved or not. diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index e07ffd55..bdaeab56 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -124,7 +124,7 @@ void StorageBase::initialize() #endif } -bool isLocalhost(const std::string& targetHost) +bool StorageBase::isLocalhost(const std::string& targetHost) { std::string targetAddress; try @@ -201,7 +201,7 @@ std::unique_ptr StorageBase::create(const Poco::URI& uri, const std { LOG_INF("Public URI [" << uri.toString() << "] considered WOPI."); const auto& targetHost = uri.getHost(); -if (WopiHosts.match(targetHost) || isLocalhost(targetHost)) +if (isWopiHostAuthorized(targetHost)) { return std::unique_ptr(new WopiStorage(uri, jailRoot, jailPath)); } @@ -212,6 +212,39 @@ std::unique_ptr StorageBase::create(const Poco::URI& uri, const std throw BadRequestException("No Storage configured or invalid URI."); } +std::string StorageBase::getUniqueDocId(const Poco::URI& uri) +{ +