diff --git a/cmd/config_init.go b/cmd/config_init.go index 1dc0fd52..c9455d00 100644 --- a/cmd/config_init.go +++ b/cmd/config_init.go @@ -39,7 +39,10 @@ override the options.`, DisableExternal: mustGetBool(flags, "branding.disableExternal"), Files: mustGetString(flags, "branding.files"), }, - OnlyOffice: "", + OnlyOffice: settings.OnlyOffice{ + URL: mustGetString(flags, "onlyoffice.url"), + JWTSecret: mustGetString(flags, "onlyoffice.jwtSecret"), + }, } ser := &settings.Server{ diff --git a/cmd/config_set.go b/cmd/config_set.go index 31b83e29..5152d785 100644 --- a/cmd/config_set.go +++ b/cmd/config_set.go @@ -55,8 +55,10 @@ you want to change. Other options will remain unchanged.`, set.Branding.DisableExternal = mustGetBool(flags, flag.Name) case "branding.files": set.Branding.Files = mustGetString(flags, flag.Name) - case "onlyoffice": - set.OnlyOffice = mustGetString(flags, flag.Name) + case "onlyoffice.url": + set.OnlyOffice.URL = mustGetString(flags, flag.Name) + case "onlyoffice.jwtSecret": + set.OnlyOffice.JWTSecret = mustGetString(flags, flag.Name) } }) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index ad4009d1..406d6c64 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -12,6 +12,7 @@ "clipboard": "^2.0.4", "core-js": "^3.9.1", "css-vars-ponyfill": "^2.4.3", + "jose": "^4.13.1", "js-base64": "^2.5.1", "lodash.clonedeep": "^4.5.0", "lodash.throttle": "^4.1.1", @@ -8523,6 +8524,14 @@ "node": ">=8" } }, + "node_modules/jose": { + "version": "4.13.1", + "resolved": "https://registry.npmjs.org/jose/-/jose-4.13.1.tgz", + "integrity": "sha512-MSJQC5vXco5Br38mzaQKiq9mwt7lwj2eXpgpRyQYNHYt2lq1PjkWa7DLXX0WVcQLE9HhMh3jPiufS7fhJf+CLQ==", + "funding": { + "url": "https://github.com/sponsors/panva" + } + }, "node_modules/js-base64": { "version": "2.6.4", "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.6.4.tgz", @@ -16835,6 +16844,7 @@ "integrity": "sha512-8q67ORQ9O0Ms0nlqsXTVhaBefRBaLrzPxOewAZhdcO7onHwcO5/wRdWtHhZgfpCZlhY7NogkU16z3WnorSSkEA==", "dev": true, "requires": { + "@babel/core": "^7.11.0", "@babel/helper-compilation-targets": "^7.9.6", "@babel/helper-module-imports": "^7.8.3", "@babel/plugin-proposal-class-properties": "^7.8.3", @@ -16847,6 +16857,7 @@ "@vue/babel-plugin-jsx": "^1.0.3", "@vue/babel-preset-jsx": "^1.2.4", "babel-plugin-dynamic-import-node": "^2.3.3", + "core-js": "^3.6.5", "core-js-compat": "^3.6.5", "semver": "^6.1.0" } @@ -22220,6 +22231,11 @@ } } }, + "jose": { + "version": "4.13.1", + "resolved": "https://registry.npmjs.org/jose/-/jose-4.13.1.tgz", + "integrity": "sha512-MSJQC5vXco5Br38mzaQKiq9mwt7lwj2eXpgpRyQYNHYt2lq1PjkWa7DLXX0WVcQLE9HhMh3jPiufS7fhJf+CLQ==" + }, "js-base64": { "version": "2.6.4", "resolved": "https://registry.npmjs.org/js-base64/-/js-base64-2.6.4.tgz", diff --git a/frontend/package.json b/frontend/package.json index bdf17bc9..f7aa2752 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,6 +14,7 @@ "clipboard": "^2.0.4", "core-js": "^3.9.1", "css-vars-ponyfill": "^2.4.3", + "jose": "^4.13.1", "js-base64": "^2.5.1", "lodash.clonedeep": "^4.5.0", "lodash.throttle": "^4.1.1", diff --git a/frontend/src/i18n/en.json b/frontend/src/i18n/en.json index 22e05141..7ec663a2 100644 --- a/frontend/src/i18n/en.json +++ b/frontend/src/i18n/en.json @@ -195,6 +195,7 @@ "newUser": "New User", "onlyOffice": "Only Office Integration", "onlyOfficeUrl": "Only Office URL (leave blank to disable)", + "onlyOfficeJwtSecret": "Only Office JWT Secret (works only with https, leave blank to disable)", "password": "Password", "passwordUpdated": "Password updated!", "path": "Path", diff --git a/frontend/src/views/files/OnlyOfficeEditor.vue b/frontend/src/views/files/OnlyOfficeEditor.vue index 01bfd487..a577df0a 100644 --- a/frontend/src/views/files/OnlyOfficeEditor.vue +++ b/frontend/src/views/files/OnlyOfficeEditor.vue @@ -22,6 +22,7 @@ import { mapState } from "vuex"; import url from "@/utils/url"; import { baseURL, onlyOffice } from "@/utils/constants"; +import * as jose from "jose"; import HeaderBar from "@/components/header/HeaderBar"; import Action from "@/components/header/Action"; @@ -80,7 +81,7 @@ export default { let onlyofficeScript = document.createElement("script"); onlyofficeScript.setAttribute( "src", - `${onlyOffice}/web-apps/apps/api/documents/api.js` + `${onlyOffice.url}/web-apps/apps/api/documents/api.js` ); document.head.appendChild(onlyofficeScript); @@ -100,7 +101,7 @@ export default { .replaceAll(/[!~[\]*'()/,;:\-%+. ]/g, "") ).substring(0, 20); - let config = { + const config = { document: { fileType: this.req.extension.substring(1), key: key, @@ -126,7 +127,18 @@ export default { mode: this.user.perm.modify ? "edit" : "view" } }; - this.editor = new DocsAPI.DocEditor("editor", config); + + if(onlyOffice.jwtSecret != "") { + const alg = 'HS256'; + new jose.SignJWT(config) + .setProtectedHeader({ alg }) + .sign(new TextEncoder().encode(onlyOffice.jwtSecret)).then((jwt) => { + config.token = jwt; + this.editor = new DocsAPI.DocEditor("editor", config); + }) + } else { + this.editor = new DocsAPI.DocEditor("editor", config); + } }; /*eslint-enable */ }, diff --git a/frontend/src/views/settings/Global.vue b/frontend/src/views/settings/Global.vue index 060fcea4..47e5bd84 100644 --- a/frontend/src/views/settings/Global.vue +++ b/frontend/src/views/settings/Global.vue @@ -93,10 +93,21 @@
++ + +