From 85dd378242e628120a609688cb299c555971555a Mon Sep 17 00:00:00 2001 From: Roman Demidov Date: Thu, 15 Feb 2024 16:07:49 +0300 Subject: [PATCH] Fix bug 66342 : Add ability to enable WOPI via 'snap set' (#145) * Fix bug 66342 : Add ability to enable WOPI via 'snap set' * Small changes * Small changes * Small changes * Update local.json * Update local.json --- README.md | 8 ++++++ bin/documentserver-start.sh | 7 ++++++ config/local.json | 2 +- snap/hooks/configure | 50 ++++++++++++++++++++++++++++++++++++- snap/snapcraft.yaml | 2 ++ 5 files changed, 67 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9a9cc74..8dba40d 100644 --- a/README.md +++ b/README.md @@ -176,6 +176,14 @@ If you'd like to change the JSON Web Token parameters, run: # snap set onlyoffice-ds onlyoffice.key=value ``` +#### Allow document server to use WOPI protocol + +By default, document server is prevented from using a WOPI protocol. To allow it, run: + +``` +# snap set onlyoffice-ds onlyoffice.wopi=true +``` + ### Enabling the Example By default, example is not enabled. You can enable the example, using the command: diff --git a/bin/documentserver-start.sh b/bin/documentserver-start.sh index 6715d6e..d92435b 100755 --- a/bin/documentserver-start.sh +++ b/bin/documentserver-start.sh @@ -34,6 +34,13 @@ else sed -i -e 's/"rejectUnauthorized": false/"rejectUnauthorized": true/' $DS_CONF_DIR/local.json fi +WOPI_ENABLED=$(snapctl get onlyoffice.wopi) +if [ "${WOPI_ENABLED}" == "true" ]; then + sed -i -e 's/"enable": false/"enable": true/' $DS_CONF_DIR/local.json +else + sed -i -e 's/"enable": true/"enable": false/' $DS_CONF_DIR/local.json +fi + export LC_ALL=C.UTF-8 #check fonts diff --git a/config/local.json b/config/local.json index 19f7708..b6a1fab 100644 --- a/config/local.json +++ b/config/local.json @@ -8,6 +8,7 @@ } }, "wopi": { + "enable": false, "htmlTemplate" : "/snap/onlyoffice-ds/current/var/www/onlyoffice/documentserver/web-apps/apps/api/wopi" }, "services": { @@ -107,4 +108,3 @@ } } } - \ No newline at end of file diff --git a/snap/hooks/configure b/snap/hooks/configure index d4487ea..f3272ee 100755 --- a/snap/hooks/configure +++ b/snap/hooks/configure @@ -13,6 +13,8 @@ DEFAULT_JWT_HEADER="Authorization" DEFAULT_EXAMPLE_ENABLED="false" DEFAULT_USE_UNAUTHORIZED_STORAGE="false" DEFAULT_LOOPBACK="false" +DEFAULT_WOPI="false" + # onlyoffice.ds-port # onlyoffice.ds-ssl-port @@ -418,6 +420,50 @@ set_previous_onlyoffice_loopback() } +# onlyoffice.wopi + +token_onlyoffice_wopi() +{ + onlyoffice_wopi="$(onlyoffice_wopi)" + previous_onlyoffice_wopi="$(previous_onlyoffice_wopi)" + + if [ "$onlyoffice_wopi" = "$previous_onlyoffice_wopi" ]; then + return 0 + fi + set_onlyoffice_wopi "$onlyoffice_wopi" + set_previous_onlyoffice_wopi "$onlyoffice_wopi" + + snapctl restart onlyoffice-ds.nginx + snapctl restart onlyoffice-ds.documentserver +} + +set_onlyoffice_wopi() +{ + snapctl set onlyoffice.wopi="$1" +} + +onlyoffice_wopi() +{ + param="$(snapctl get onlyoffice.wopi)" + if [ -z "$param" ]; then + param="$DEFAULT_WOPI" + set_onlyoffice_wopi $param + set_previous_onlyoffice_wopi $param + fi + + echo "$param" +} + +previous_onlyoffice_wopi() +{ + snapctl get private.onlyoffice.wopi +} + +set_previous_onlyoffice_wopi() +{ + snapctl set private.onlyoffice.wopi="$1" +} + nginx_onlyoffice_http_port && \ db_onlyoffice_db_port && \ @@ -426,4 +472,6 @@ token_onlyoffice_jwt_secret && \ token_onlyoffice_jwt_header && \ onlyoffice_example_enabled && \ onlyoffice_use_unautorized_storage && \ -token_onlyoffice_loopback +token_onlyoffice_loopback && \ +token_onlyoffice_wopi + diff --git a/snap/snapcraft.yaml b/snap/snapcraft.yaml index 5ee85f8..5a47413 100644 --- a/snap/snapcraft.yaml +++ b/snap/snapcraft.yaml @@ -184,6 +184,8 @@ parts: BUILD_NUMBER=`cat var/www/onlyoffice/documentserver/server/Common/sources/commondefines.js | grep "const buildNumber" | grep -o "[0-9]*"` echo $BUILD_VERSION-$BUILD_NUMBER > $CRAFT_STAGE/version cp -r $DIR/server/Common/node_modules/ms $DIR/server/FileConverter/node_modules/ + #fix wopi enable page + sed -i -e '/wopi.enable/c
Set the onlyoffice.wopi parameter in the Document Server snap configuration to true.' $DIR-example/nodejs/views/wopiIndex.ejs node: plugin: dump