Compare commits

..

186 Commits

Author SHA1 Message Date
e1e9ad04a3 python-raw: move to the common module 2023-07-10 18:01:22 +04:00
865d071203 python-raw: rename snake case to camel 2023-07-10 17:49:44 +04:00
db48ff64e5 python-raw: rename user_host to address 2023-07-10 17:44:21 +04:00
89a6b94178 python-raw: add missed django_settings_module, DELETE THIS 2023-07-10 17:38:12 +04:00
5ea6d81155 python-raw: continius the history refactoring 2023-07-10 10:47:48 +04:00
72ea75ec02 python-raw: add Rejuvenation Management 2023-07-07 17:28:00 +04:00
89d6917a58 python-raw: add bootstrap 2023-07-07 15:56:54 +04:00
d0354c88f5 python-raw: add http_method 2023-07-07 14:50:24 +04:00
e0ccbd4f93 python-raw: support direct_url 2023-07-07 13:46:56 +04:00
f8194eb459 python-raw: change the save logic, add new endpoints 2023-07-06 18:09:17 +04:00
01f35c9ee4 python-raw: add local development 2023-07-05 12:03:07 +04:00
360c26f7f5 python-raw: fix typo 2023-07-05 12:02:26 +04:00
c4c621d1f2 python-raw: fix server and proxy 2023-07-04 17:55:36 +04:00
14e4904adb python-raw: fix server 2023-07-04 16:29:53 +04:00
69d74d6e8a python-raw: ignore and pylint 2023-07-04 12:15:17 +04:00
00a172f9f2 python-raw: add django-stubs (duplicate) 2023-06-30 14:20:50 +04:00
7a4610ce83 python-raw: codable todo's 2023-06-30 12:34:45 +04:00
8782430bc6 python-raw: codable typo 2023-06-30 11:46:42 +04:00
be8b83929e python-raw: codable 2023-06-30 11:40:01 +04:00
2658bdc783 python-raw: add receipt 2023-06-28 13:59:24 +04:00
d9c9bd6dc3 python-raw: add docker 2023-06-28 13:59:02 +04:00
561117433c python-raw: add support for proxy for the track endpoint 2023-06-28 13:55:54 +04:00
0c8cb2becf python-raw: add the public and private urls 2023-06-28 13:55:08 +04:00
dce9b7911d python-raw: add proxy manager 2023-06-28 13:54:28 +04:00
ae8b32090f python-raw: delete unnecessary index file 2023-06-28 13:52:32 +04:00
82c378f3c3 python-raw: fix test command 2023-06-28 13:50:57 +04:00
5bcc8c0f16 python-raw: fix server secret 2023-06-28 13:50:35 +04:00
478784fbbd python-raw: add recipes to start the server 2023-06-27 16:22:02 +04:00
fb18fc501d python-raw: simplify server configuration 2023-06-27 16:21:39 +04:00
b5941803ee python-raw: set path for static 2023-06-27 13:40:17 +04:00
50e5b6e0f5 python-raw: replace config 2023-06-27 13:33:45 +04:00
e79dcfbf59 python-raw: continius 2023-06-27 11:58:12 +04:00
58855f0cbe python-raw: add configuration 2023-06-26 18:48:57 +04:00
c159ff68ae python: add help, dev, lint, prod recipes to Makefile 2023-06-26 14:09:48 +04:00
88e0411c56 python: add lint dependencies 2023-06-26 14:08:42 +04:00
13be815042 python: pin python version 2023-06-26 14:07:16 +04:00
ccdf599b45 python: pin dependency versions 2023-06-26 14:06:55 +04:00
75b22614cf refresh licenses 2023-06-21 12:29:59 +05:00
6cb15697ab Merge pull request #388 from ONLYOFFICE/feature/ruby-normalize-dependencies
ruby: pin and add new dependencies
2023-06-21 12:12:22 +05:00
39bab74422 Merge pull request #383 from ONLYOFFICE/feature/formats
Feature/formats
2023-06-19 11:47:19 +05:00
665ab6a77d formats to changelog 2023-06-19 11:47:03 +05:00
5663227c55 update formats repo 2023-06-19 11:45:26 +05:00
42ac89e5e5 Merge pull request #370 from ONLYOFFICE/hotfix/headers-charset-on-upload-convert
java: upload and convert fix
2023-06-19 11:33:09 +05:00
c95499536d ruby: add lint recipe to Makefile 2023-06-14 10:38:35 +04:00
5659756c07 ruby: add install recipe to Makefile 2023-06-14 10:38:35 +04:00
038b3b3049 ruby: add help recipe to Makefile 2023-06-14 10:38:35 +04:00
6b555c4d0d ruby: add sorbet as a type-checker dependency 2023-06-14 10:38:27 +04:00
44d49bed62 ruby: add rubocop as a lint dependency 2023-06-14 10:23:02 +04:00
517b130db6 ruby: pin ruby version 2023-06-09 12:13:40 +04:00
0ff435b9bd ruby: pin dependency versions and add support for the arm64 platform 2023-06-09 12:13:14 +04:00
56bc372140 Merge remote-tracking branch 'remotes/origin/release/v7.4.0' into develop
# Conflicts:
#	web/documentserver-example/nodejs/helpers/docManager.js
2023-06-07 18:57:00 +05:00
4679804774 Merge pull request #386 from ONLYOFFICE/hotfix/fix-php-readme
php: composer installation added to readme
2023-06-07 16:30:48 +05:00
d03f74087c php: composer installation added to readme 2023-06-07 16:29:57 +05:00
68390aa26c php: lossy-edit to getEditExtensions() 2023-06-02 12:31:41 +03:00
744e5203cb nodejs: lossy-edit to getEditExtensions() 2023-06-02 12:29:44 +03:00
7df7af3f47 nodejs, php: update submodule document-formats 2023-06-02 12:21:00 +03:00
bf40cd1249 Merge branch 'develop' into feature/formats 2023-06-02 11:01:19 +03:00
f3cb5adb22 nodejs: fix (668df46ec3) 2023-06-02 11:00:30 +03:00
c8d44199c2 php: fix lint 2023-06-01 16:21:36 +03:00
12bcc0009b nodejs: disable eslint for import onlyoffice-docs-formats.json 2023-06-01 16:14:12 +03:00
be1ea81f82 Merge branch 'develop' into feature/formats 2023-06-01 15:53:41 +03:00
668df46ec3 nodejs: fix(dd3255779f) 2023-06-01 15:53:07 +03:00
43905695e0 nodejs: fix lint 2023-06-01 14:50:06 +03:00
4a49becea1 php: revert composer.lock 2023-05-31 15:34:42 +03:00
c91d3a24b9 update submodule document-formats 2023-05-31 14:39:48 +03:00
d6a4984b84 Merge pull request #382 from ONLYOFFICE/feature/restore-version
Feature/restore version
2023-05-22 15:45:19 +05:00
f1dae06746 changelog: restore file 2023-05-22 15:44:45 +05:00
3cf3bcf2c8 Merge remote-tracking branch 'remotes/origin/develop' into feature/restore-version 2023-05-22 15:44:11 +05:00
aa6e19ebaa Merge pull request #372 from ONLYOFFICE/dependabot/bundler/web/documentserver-example/ruby/nokogiri-1.14.3
build(deps): bump nokogiri from 1.13.9 to 1.14.3 in /web/documentserver-example/ruby
2023-05-22 14:01:04 +05:00
d7034c72c9 Merge pull request #379 from ONLYOFFICE/feature/remove-row-without-reload
nodejs: remove row without reload
2023-05-18 18:12:46 +05:00
c0437b152f remove row to changelog 2023-05-18 18:10:44 +05:00
b72b2c6619 Merge branch 'develop' into feature/remove-row-without-reload
# Conflicts:
#	web/documentserver-example/nodejs/public/javascripts/jscript.js
2023-05-18 13:34:34 +03:00
c516631360 nodejs: fix remove for IE 2023-05-18 13:31:50 +03:00
5cc8d7c094 Merge pull request #380 from ONLYOFFICE/feature/get-history-by-request
nodejs: get history data by request
2023-05-18 11:23:10 +05:00
5f4764060c changelog: history request 2023-05-18 11:22:17 +05:00
44832008a8 nodejs: reload the page if deleted line is the last one 2023-05-17 13:24:28 +03:00
d86e737493 nodejs: fix properties for IE, historyObject used in requestRestore 2023-05-17 12:59:55 +03:00
07a1e3101b Merge branch 'feature/get-history-by-request' into feature/restore-version 2023-05-17 12:55:51 +03:00
1ebfe49916 nodejs: fix properties for IE 2023-05-17 12:54:15 +03:00
b1d6f8d652 Merge branch 'feature/get-history-by-request' into feature/restore-version 2023-05-17 12:46:15 +03:00
8f0edf90e6 nodejs: request in onRequestHistory only 2023-05-17 12:43:33 +03:00
7c77389550 build(deps): bump nokogiri in /web/documentserver-example/ruby
Bumps [nokogiri](https://github.com/sparklemotion/nokogiri) from 1.13.9 to 1.14.3.
- [Release notes](https://github.com/sparklemotion/nokogiri/releases)
- [Changelog](https://github.com/sparklemotion/nokogiri/blob/main/CHANGELOG.md)
- [Commits](https://github.com/sparklemotion/nokogiri/compare/v1.13.9...v1.14.3)

---
updated-dependencies:
- dependency-name: nokogiri
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-05-17 12:42:09 +05:00
637731a4d7 Merge pull request #373 from ONLYOFFICE/refactor/collect-params-for-url
Refactor/collect params for url
2023-05-17 12:34:35 +05:00
6fc98a025b Merge branch 'feature/get-history-by-request' into feature/restore-version
# Conflicts:
#	web/documentserver-example/nodejs/app.js
2023-05-12 13:03:31 +03:00
f123cbcce3 nodejs: handler for restore file version 2023-05-12 13:00:48 +03:00
11f166525e nodejs: onRequestRestore method on front 2023-05-12 12:56:24 +03:00
68db498dfd nodejs: get history data by request 2023-05-12 11:12:32 +03:00
f914afcc53 nodejs: remove row without reload 2023-05-11 15:14:07 +03:00
8dcf75f3fb nodejs: get history data by request 2023-05-11 14:06:48 +03:00
3d9e091882 Merge pull request #378 from ONLYOFFICE/hotfix/disable-rule-for-old-nodejs
nodejs: hasOwnProperty() used instead of hasOwn() for NodeJS v.14
2023-05-10 17:36:27 +05:00
a9ca4b3272 Merge remote-tracking branch 'remotes/origin/release/v7.4.0' into develop 2023-05-10 17:32:40 +05:00
35798a7916 nodejs: hasOwnProperty() used instead of hasOwn() for NodeJS v.14 2023-05-10 11:30:26 +03:00
f7000b51a7 Merge branch 'release/v7.4.0' into develop
# Conflicts:
#	web/documentserver-example/nodejs/app.js
#	web/documentserver-example/nodejs/helpers/users.js
2023-05-10 10:55:24 +05:00
66faaab294 Merge branch 'develop' into refactor/collect-params-for-url
# Conflicts:
#	web/documentserver-example/nodejs/views/index.ejs
#	web/documentserver-example/nodejs/views/wopiIndex.ejs
2023-04-28 11:20:25 +03:00
7be2a5a507 nodejs: remove serverUrl 2023-04-27 16:45:22 +03:00
8cf26de5e2 Merge remote-tracking branch 'remotes/origin/release/v7.4.0' into develop 2023-04-27 15:15:15 +03:00
f2a11a5894 nodejs: WOPI-page fix 2023-04-27 14:54:36 +03:00
c6043d4428 nodejs: fix tabulation 2023-04-27 11:36:04 +03:00
c37ba28ad3 php: added work with onlyoffice-docs-formats.json 2023-04-27 11:33:57 +03:00
53f810fc54 php: added module document-formats 2023-04-27 10:48:48 +03:00
a55875ae1e php: added module document-templates 2023-04-27 10:46:33 +03:00
707a634823 php: removed module document-templates 2023-04-27 10:42:31 +03:00
b511fa872a nodejs: added module document-formats 2023-04-27 10:36:56 +03:00
4a2e7d9a9e nodejs: added module document-templates 2023-04-27 10:32:49 +03:00
e4d5de2c0e removed module document-templates 2023-04-27 10:24:32 +03:00
50dca2e2c0 php: added work with onlyoffice-docs-formats.json 2023-04-26 14:58:00 +03:00
893303c27f nodejs: added work with onlyoffice-docs-formats.json 2023-04-26 11:48:38 +03:00
b543392c62 nodejs: server url to link in logo 2023-04-26 09:22:39 +03:00
adf52c756e nodejs: fix url-params + IE fix 2023-04-21 12:55:02 +03:00
693cc5a951 Merge pull request #369 from ONLYOFFICE/refactor/format-by-linter-nodejs
Refactor/format by linter nodejs
2023-04-21 09:40:20 +05:00
ff9ba7fbf1 Merge pull request #371 from ONLYOFFICE/hotfix/editor-warning-fix
php: editor warnings fix
2023-04-20 17:06:59 +05:00
c2b87959a2 nodejs: collectParams() instead of reload() + input text added 2023-04-19 11:14:45 +03:00
18ee7776ef nodejs: radio elements + "name" attribute instead of "data-param" 2023-04-19 10:06:29 +03:00
c99efda67a nodejs: open window in new tab 2023-04-19 09:25:49 +03:00
d65f970255 nodejs: collectParams() method added 2023-04-18 14:45:31 +03:00
f5442a8a89 nodejs: url params for collectable elements 2023-04-18 14:44:04 +03:00
e347ea36ce nodejs: "params" in links deleted, added class for actions 2023-04-18 11:50:54 +03:00
f0651dabf0 php: editor warnings fix 2023-04-10 12:31:04 +03:00
ccf85c1c0f nodejs: "no-plusplus" - rule excluded for loops 2023-04-05 15:16:33 +03:00
6ea35bf55c Merge branch 'refactor/format-by-linter-nodejs' of https://github.com/ONLYOFFICE/document-server-integration into refactor/format-by-linter-nodejs 2023-04-05 15:05:05 +03:00
f6afde346a nodejs: await in loops excluded from check 2023-04-05 15:04:50 +03:00
ce4074bcce nodejs: change order 2023-04-05 11:46:06 +05:00
5697b58aa2 nodejs: radix parameters for parseInt() 2023-04-04 12:57:32 +03:00
d5e6301211 nodejs: no restricted syntax 2023-04-04 12:50:45 +03:00
9048082cb7 nodejs: no shadow vars 2023-04-04 11:05:29 +03:00
56e46466b2 nodejs: useless rules deleted, autofixed spaces before parenthesis, arrow functions syntax, and comma after arguments added 2023-04-03 17:05:26 +03:00
fa9731ab57 nodejs: no unnamed functions 2023-04-03 16:44:48 +03:00
c2ba46ce85 nodejs: no await in loops 2023-04-03 15:25:43 +03:00
4c5780f1d6 nodejs: default param last 2023-04-03 15:20:26 +03:00
0419611a62 nodejs: no prototype builtins 2023-04-03 15:17:57 +03:00
bcc1011ddd nodejs: no constant condition 2023-04-03 15:04:57 +03:00
91a4fe1e52 nodejs: no throw literal 2023-04-03 12:51:30 +03:00
21fed8a81e nodejs: off unused airbnb-base rules 2023-03-31 14:29:59 +03:00
f2fc63c24f nodejs: default cases required 2023-03-31 14:03:14 +03:00
521608fa15 nodejs: no unused else blocks 2023-03-31 13:55:35 +03:00
e16ad4e53d nodejs: define vars is required 2023-03-31 13:48:11 +03:00
7205e383c8 nodejs: no new RegExp() 2023-03-31 13:40:47 +03:00
9bf317b3e0 nodejs: camelCase used 2023-03-31 13:38:38 +03:00
ac668a41c5 nodejs: declaration of methods before use 2023-03-31 13:32:20 +03:00
606f4255dc nodejs: no useless return statements + ';' in the end 2023-03-31 13:03:15 +03:00
22a64dd932 nodejs: no mixed tabs 2023-03-31 12:34:05 +03:00
dd3255779f nodejs: required the use of === and !== 2023-03-31 12:30:04 +03:00
89c7e63ab8 nodejs: object curly spacing 2023-03-31 11:04:35 +03:00
447c604fe9 nodejs: no multiple empty lines 2023-03-31 10:54:40 +03:00
dff9602852 nodejs: require correct order 2023-03-31 10:00:32 +03:00
f4d7915dd6 nodejs: 'use strict' is unnecessary inside of modules 2023-03-31 09:35:57 +03:00
01204d544e nodejs: const declarations for variables that are never reassigned after declared 2023-03-30 17:03:40 +03:00
a06aa8c8b3 nodejs: max-length of lines - 120 2023-03-30 16:31:39 +03:00
7977427038 nodejs: no unused variables 2023-03-30 13:47:33 +03:00
0b8d0ed10a nodejs: disallowed spacing around embedded expressions of template strings 2023-03-30 12:33:52 +03:00
efec141039 nodejs: disallowed padding within blocks 2023-03-30 12:29:39 +03:00
6736555ff3 nodejs: constructor names to begin with a capital letter 2023-03-30 12:20:50 +03:00
d94fe30a3e nodejs: fix no nested ternary expressions 2023-03-30 12:12:04 +03:00
3079320534 nodejs: no multi spaces 2023-03-30 10:57:00 +03:00
4f3af51e54 nodejs: newline after each call in a method chain 2023-03-30 10:52:48 +03:00
d19c81c944 nodejs: EOL last 2023-03-30 10:48:34 +03:00
bc3cbbbb82 nodejs: spacing around infix operators 2023-03-30 10:47:14 +03:00
8ee3ddc925 nodejs: space before the opening parenthesis in control statements 2023-03-30 10:44:00 +03:00
173c05dbf3 nodejs: consistent indentation (2 spaces) 2023-03-30 10:41:27 +03:00
b13c548c4d nodejs: 1 space before comment text 2023-03-30 10:30:18 +03:00
ef8237adfd nodejs: disallowed else blocks after return statements in if statements 2023-03-30 10:24:06 +03:00
c80379da31 nodejs: braces for multi-line blocks with if and else 2023-03-30 10:22:04 +03:00
a54c43c0c2 nodejs: braces with all multi-line blocks 2023-03-30 10:19:25 +03:00
5e524aa148 nodejs: disallow bitwise operators 2023-03-30 10:12:41 +03:00
e84ee9e01b nodejs: no unneeded ternary operators 2023-03-30 09:32:01 +03:00
27ceb1e6c6 nodejs: no nested ternary expressions 2023-03-29 17:23:50 +03:00
508b0d913c nodejs: disallow the unary operators ++ and -- 2023-03-29 16:35:32 +03:00
5999b070dc nodejs: dot notation whenever possible 2023-03-29 15:43:55 +03:00
3ed13f3975 nodejs: braces around arrow function bodies 2023-03-29 13:33:51 +03:00
1789f7c9fd nodejs: parentheses around arrow function arguments 2023-03-29 13:31:33 +03:00
a05ea11dd7 nodejs: spacing before and after the arrow in arrow functions 2023-03-29 13:29:34 +03:00
c6dd46a004 nodejs: linebreaks inside function parentheses if any of the parameters/arguments have a line break between them 2023-03-29 13:27:07 +03:00
bf04979c31 nodejs: reassigning function parameters disallowed 2023-03-29 13:20:33 +03:00
e9274b7303 nodejs: spacing before blocks 2023-03-29 12:52:36 +03:00
03022c5b45 nodejs: spacing before function definition opening parenthesis 2023-03-29 12:50:35 +03:00
ce4ccdd5b0 nodejs: rest parameters instead of arguments 2023-03-29 12:32:28 +03:00
07eba65458 nodejs: used named function expressions instead of function declarations 2023-03-29 10:56:17 +03:00
072b082240 nodejs: require using arrow functions for callbacks 2023-03-29 09:49:21 +03:00
c664bc4ee9 nodejs: template literals instead of string concatenation 2023-03-28 17:38:41 +03:00
f113d7eeb1 nodejs: require destructuring from arrays and objects 2023-03-28 16:52:27 +03:00
9409bf0785 nodejs: quote only properties that are invalid identifiers 2023-03-28 15:41:02 +03:00
d51e724130 nodejs: method and property shorthand syntax for object literals 2023-03-28 15:35:27 +03:00
9489b4dcde nodejs: variables with block scope used 2023-03-28 14:46:09 +03:00
d9c139a42b nodejs: const declarations for variables that are never reassigned after declared 2023-03-28 14:08:15 +03:00
534f1d8284 nodejs: single quotes used 2023-03-28 14:02:31 +03:00
f177af8791 nodejs: added max-length (120) to ruleset 2023-03-28 13:57:52 +03:00
122 changed files with 6832 additions and 3591 deletions

24
.gitmodules vendored
View File

@ -1,15 +1,7 @@
[submodule "web/documentserver-example/nodejs/public/assets"]
path = web/documentserver-example/nodejs/public/assets
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/java/src/main/resources/assets"]
path = web/documentserver-example/java/src/main/resources/assets
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/php/assets"]
path = web/documentserver-example/php/assets
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/python/assets"]
path = web/documentserver-example/python/assets
url = https://github.com/ONLYOFFICE/document-templates
@ -30,3 +22,19 @@
path = web/documentserver-example/java-spring/src/main/resources/assets
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/nodejs/public/assets/document-templates"]
path = web/documentserver-example/nodejs/public/assets/document-templates
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/nodejs/public/assets/document-formats"]
path = web/documentserver-example/nodejs/public/assets/document-formats
url = https://github.com/ONLYOFFICE/document-formats
branch = master
[submodule "web/documentserver-example/php/assets/document-templates"]
path = web/documentserver-example/php/assets/document-templates
url = https://github.com/ONLYOFFICE/document-templates
branch = main/en
[submodule "web/documentserver-example/php/assets/document-formats"]
path = web/documentserver-example/php/assets/document-formats
url = https://github.com/ONLYOFFICE/document-formats
branch = master

View File

@ -3,10 +3,6 @@ Document Server integration example uses code from the following 3rd party proje
web/documentserver-example/csharp
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -19,14 +15,26 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
License File: jQuery.UI.license
JWT - JWT (JSON Web Token) Implementation for .NET (Public Domain) (https://github.com/jwt-dotnet/jwt/)
License: MIT
License File: JWT.license
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://github.com/JamesNK/Newtonsoft.Json)
License: MIT
License File: Newtonsoft.Json.license
web/documentserver-example/csharp-mvc
@ -34,10 +42,6 @@ Entity Framework - Entity Framework is an object-relational mapper that enables
License: MICROSOFT SOFTWARE SUPPLEMENTAL TERMS, MICROSOFT SOFTWARE LICENSE TERMS
License File: EntityFramework.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -50,19 +54,27 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
License File: jQuery.UI.license
JWT - JWT (JSON Web Token) Implementation for .NET (Public Domain) (https://github.com/jwt-dotnet/jwt/)
License: MIT
License File: JWT.license
Microsoft.Web.Infrastructure - This package contains the Microsoft.Web.Infrastructure assembly that lets you dynamically register HTTP modules at run time. (https://www.microsoft.com/web/webpi/eula/aspnetmvc3update-eula.htm)
License: MS-EULA License
License File: Microsoft.Web.Infrastructure.license
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://licenses.nuget.org/MIT)
Newtonsoft.Json - Json.NET is a popular high-performance JSON framework for .NET (https://github.com/JamesNK/Newtonsoft.Json)
License: MIT
License File: Newtonsoft.Json.license
@ -73,10 +85,6 @@ License File: WebGrease.license
web/documentserver-example/java
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -89,9 +97,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
@ -104,9 +116,17 @@ License File: prime-jwt.license
web/documentserver-example/java-spring
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
License: Apache 2.0
License File: gson.license
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
License: MPL 2.0 or EPL 1.0
License File: h2database.license
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
License: Apache 2.0
License File: jackson-databind.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
@ -120,14 +140,30 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
License File: jQuery.UI.license
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
License: Apache 2.0
License File: JSON.simple.license
Project Lombok - Project Lombok is a java library that automatically plugs into your editor and build tools. (https://mvnrepository.com/artifact/org.projectlombok/lombok).
License: MIT
License File lombok.license
ModelMapper - ModelMapper is an intelligent object mapping library that automatically maps objects to each other. (https://github.com/modelmapper/modelmapper)
License: Apache 2.0
License File modelmapper.license
Prime JWT - is intended to be fast and easy to use. Prime JWT has a single external dependency on Jackson. (https://github.com/ws-apps/prime-jwt/blob/master/LICENSE)
License: Apache 2.0
License File: prime-jwt.license
@ -148,22 +184,6 @@ Spring Data JPA - Persist data in SQL stores with Java Persistence API using Spr
License: Apache 2.0
License File: spring-data-jpa.license
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
License: MPL 2.0 or EPL 1.0
License File: h2database.license
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
License: Apache 2.0
License File: JSON.simple.license
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
License: Apache 2.0
License File: gson.license
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
License: Apache 2.0
License File: jackson-databind.license
web/documentserver-example/nodejs
@ -199,10 +219,6 @@ he - a robust HTML entity encoder/decoder written in JavaScript. (htt
License: MIT
License File: he.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -215,9 +231,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
@ -248,11 +268,8 @@ License: MIT
License File: urllib.license
web/documentserver-example/php
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
web/documentserver-example/php
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
@ -266,9 +283,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
@ -289,10 +310,6 @@ Django - Django is a high-level Python web framework that encourages rapi
License: BSD-3-Clause
License File: Django.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -305,52 +322,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
License File: jQuery.UI.license
PyJWT - A Python implementation of RFC 7519. (https://github.com/jpadilla/pyjwt/blob/master/LICENSE)
License: MIT
License File: PyJWT.license
python-magic - python-magic is a Python interface to the libmagic file type identification library. (https://github.com/ahupp/python-magic/blob/master/LICENSE)
License: MIT
License File: python-magic.license
requests - Requests allows you to send HTTP/1.1 requests extremely easily. Theres no need to manually add query strings to your URLs, or to form-encode your PUT & POST data — but nowadays, just use the json method! (https://github.com/psf/requests/blob/main/LICENSE)
License: Apache 2.0
License File: requests.license
web/documentserver-example/python
Django - Django is a high-level Python web framework that encourages rapid development and clean, pragmatic design. Thanks for checking it out. (https://github.com/django/django/blob/main/LICENSE)
License: BSD-3-Clause
License File: Django.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
jQuery.FileUpload - File Upload widget with multiple file selection, drag&drop support, progress bar, validation and preview images, audio and video for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (Google App Engine, PHP, Python, Ruby on Rails, Java, etc.) that supports standard HTML form file uploads. (https://github.com/blueimp/jQuery-File-Upload/blob/master/LICENSE.txt)
License: MIT
License File: jQuery.FileUpload.license
jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https://github.com/blueimp/jQuery-File-Upload/blob/master/LICENSE.txt)
License: MIT
License File: jQuery.iframe-transport.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
@ -379,14 +357,14 @@ coffee-rails - CoffeeScript adapter for the Rails asset pipeline. (https://gith
License: MIT
License File: coffee-rails.license
dalli - High performance memcached client for Ruby. (https://github.com/petergoldstein/dalli/blob/v3.2.0/LICENSE)
License: MIT
License File: dalli.license
jbuilder - Create JSON structures via a Builder-style DSL (https://github.com/rails/jbuilder/blob/master/MIT-LICENSE)
License: MIT
License File: jbuilder.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -399,9 +377,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
@ -411,10 +393,18 @@ jquery-rails - This gem provides jQuery and the jQuery-ujs driver for your Rail
License: MIT
License File: jquery-rails.license
mimemagic - А library to detect the mime type of a file by extension or by content. (https://github.com/mimemagicrb/mimemagic/blob/master/LICENSE)
License: MIT
License File: mimemagic.license
rails - Rails is a web-application framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern. (https://github.com/rails/rails/blob/v6.0.3.2/MIT-LICENSE)
License: MIT
License File: rails.license
rubocop - A Ruby static code analyzer and formatter, based on the community Ruby style guide. (https://github.com/rubocop/rubocop/blob/v1.52.0/LICENSE.txt)
License: MIT
License File: rubocop.license
sass-rails - This gem provides official integration for Ruby on Rails projects with the Sass stylesheet language. (https://github.com/rails/sass-rails/blob/master/MIT-LICENSE)
License: MIT
License File: sass-rails.license
@ -423,10 +413,18 @@ sdoc - rdoc generator html with javascript search index. (https://githu
License: MIT
License File: sdoc.license
sorbet - A fast, powerful type checker designed for Ruby. (https://github.com/sorbet/sorbet/blob/0.5.10871.20230607144259-d9000e2ba/LICENSE)
License: Apache License 2.0
License File: sorbet.license
sqlite3 - This module allows Ruby programs to interface with the SQLite3 database engine (www.sqlite.org). (https://github.com/sparklemotion/sqlite3-ruby/blob/master/LICENSE)
License: BSD-3-Clause
License File: sqlite3.license
tapioca - The swiss army knife of RBI generation. (https://github.com/Shopify/tapioca/blob/v0.11.6/LICENSE.txt)
License: MIT
License File: tapioca.license
turbolinks - Rails engine for Turbolinks 5 support (https://github.com/turbolinks/turbolinks-rails/blob/master/LICENSE)
License: MIT
License File: turbolinks.license

View File

@ -1,6 +1,10 @@
# Change Log
## 1.6.0
- php: using a repo with a list of formats
- nodejs: using a repo with a list of formats
- nodejs: delete file without reloading the page
- nodejs: getting history by a separate request
- nodejs: restore from history
- nodejs: setUsers for region protection
- si skin languages
- fix "no" skin languages

View File

@ -4,10 +4,6 @@ Entity Framework - Entity Framework is an object-relational mapper that enables
License: MICROSOFT SOFTWARE SUPPLEMENTAL TERMS, MICROSOFT SOFTWARE LICENSE TERMS
License File: EntityFramework.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -20,9 +16,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT

View File

@ -220,7 +220,6 @@ namespace OnlineEditorsExampleMVC.Helpers
var fileName = GetCorrectName(demoName); // get a file name with an index if the file with such a name already exists
File.Copy(HttpRuntime.AppDomainAppPath + demoPath + demoName, StoragePath(fileName)); // copy file to the storage directory
File.SetLastWriteTime(StoragePath(fileName), DateTime.Now);
return fileName;
}

View File

@ -236,7 +236,6 @@ if (typeof jQuery != "undefined") {
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
document.location.reload();
});
jq(document).on("click", "#beginView:not(.disable)", function () {
@ -245,7 +244,6 @@ if (typeof jQuery != "undefined") {
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
document.location.reload();
});
jq(document).on("click", "#beginEmbedded:not(.disable)", function () {

View File

@ -249,14 +249,14 @@ namespace OnlineEditorsExampleMVC
// get the url and file type of the converted file
Dictionary<string, string> newFileData;
var result = ServiceConverter.GetConvertedData(downloadUri.ToString(), extension, internalExtension, key, true, out newFileData, filePass, lang);
var newFileUri = newFileData["fileUrl"];
var newFileType = "." + newFileData["fileType"];
if (result != 100)
{
context.Response.Write("{ \"step\" : \"" + result + "\", \"filename\" : \"" + fileName + "\"}");
return;
}
var newFileUri = newFileData["fileUrl"];
var newFileType = "." + newFileData["fileType"];
// get a file name of an internal file extension with an index if the file with such a name already exists
var correctName = DocManagerHelper.GetCorrectName(Path.GetFileNameWithoutExtension(fileName) + newFileType);
@ -659,12 +659,10 @@ namespace OnlineEditorsExampleMVC
return;
}
var directUrl = (bool)body["directUrl"];
var data = new Dictionary<string, object>() {
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower().Trim('.') },
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower() },
{ "url", DocManagerHelper.GetDownloadUrl(fileName)},
{ "directUrl", directUrl ? DocManagerHelper.GetDownloadUrl(fileName, false) : null },
{ "directUrl", DocManagerHelper.GetDownloadUrl(fileName) },
{ "referenceData", new Dictionary<string, string>()
{
{ "fileKey", jss.Serialize(new Dictionary<string, object>{
@ -672,7 +670,7 @@ namespace OnlineEditorsExampleMVC
{"userAddress", HttpUtility.UrlEncode(DocManagerHelper.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress))}
})
},
{ "instanceId", DocManagerHelper.GetServerUrl(false) }
{"instanceId", DocManagerHelper.GetServerUrl(false) }
}
},
{ "path", fileName }

View File

@ -4,10 +4,6 @@ Entity Framework - Entity Framework is an object-relational mapper that enables
License: MICROSOFT SOFTWARE SUPPLEMENTAL TERMS, MICROSOFT SOFTWARE LICENSE TERMS
License File: EntityFramework.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -20,9 +16,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT

View File

@ -1,7 +1,7 @@
<?xml version="1.0"?>
<appSettings>
<clear />
<add key="version" value="1.6.0"/>
<add key="version" value="1.5.1"/>
<add key="filesize-max" value="52428800"/>
<add key="storage-path" value=""/>

View File

@ -1,9 +1,5 @@
ONLYOFFICE Applications example uses code from the following 3rd party projects:
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -16,9 +12,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT

View File

@ -489,13 +489,13 @@ namespace OnlineEditorsExample
// get the url and file type of the converted file
Dictionary<string, string> newFileData;
var result = ServiceConverter.GetConvertedData(fileUrl.ToString() , extension, internalExtension, key, true, out newFileData, filePass, lang);
var newFileUri = newFileData["fileUrl"];
var newFileType = "." + newFileData["fileType"];
if (result != 100)
{
return "{ \"step\" : \"" + result + "\", \"filename\" : \"" + _fileName + "\"}";
}
var newFileUri = newFileData["fileUrl"];
var newFileType = "." + newFileData["fileType"];
// get a file name of an internal file extension with an index if the file with such a name already exists
var fileName = GetCorrectName(Path.GetFileNameWithoutExtension(_fileName) + newFileType);

View File

@ -632,7 +632,6 @@ namespace OnlineEditorsExample
var filePath = _Default.StoragePath(FileName, null);
File.Copy(HttpRuntime.AppDomainAppPath + demoPath + demoName, filePath); // copy this file to the storage directory
File.SetLastWriteTime(filePath, DateTime.Now);
// create a json file with file meta data
var id = request.Cookies.GetOrDefault("uid", null);

View File

@ -477,12 +477,10 @@ namespace OnlineEditorsExample
return;
}
var directUrl = (bool) body["directUrl"];
var data = new Dictionary<string, object>() {
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower().Trim('.') },
{ "fileType", (Path.GetExtension(fileName) ?? "").ToLower() },
{ "url", DocEditor.getDownloadUrl(fileName)},
{ "directUrl", directUrl ? DocEditor.getDownloadUrl(fileName, false) : null},
{ "directUrl", DocEditor.getDownloadUrl(fileName) },
{ "referenceData", new Dictionary<string, string>()
{
{ "fileKey", jss.Serialize(new Dictionary<string, object>{

View File

@ -1,9 +1,5 @@
ONLYOFFICE Applications example uses code from the following 3rd party projects:
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -16,9 +12,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT

View File

@ -236,7 +236,6 @@ if (typeof jQuery != "undefined") {
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
document.location.reload();
});
jq(document).on("click", "#beginView:not(.disable)", function () {
@ -245,7 +244,6 @@ if (typeof jQuery != "undefined") {
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
document.location.reload();
});
jq(document).on("click", "#beginEmbedded:not(.disable)", function () {

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<clear />
<add key="version" value="1.6.0"/>
<add key="version" value="1.5.1"/>
<add key="filesize-max" value="52428800"/>
<add key="storage-path" value=""/>

View File

@ -1,8 +1,17 @@
ONLYOFFICE Applications example uses code from the following 3rd party projects:
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
License: Apache 2.0
License File: gson.license
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
License: MPL 2.0 or EPL 1.0
License File: h2database.license
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
License: Apache 2.0
License File: jackson-databind.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
@ -16,14 +25,30 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
License File: jQuery.UI.license
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
License: Apache 2.0
License File: JSON.simple.license
Project Lombok - Project Lombok is a java library that automatically plugs into your editor and build tools. (https://mvnrepository.com/artifact/org.projectlombok/lombok).
License: MIT
License File lombok.license
ModelMapper - ModelMapper is an intelligent object mapping library that automatically maps objects to each other. (https://github.com/modelmapper/modelmapper)
License: Apache 2.0
License File modelmapper.license
Prime JWT - is intended to be fast and easy to use. Prime JWT has a single external dependency on Jackson. (https://github.com/ws-apps/prime-jwt/blob/master/LICENSE)
License: Apache 2.0
License File: prime-jwt.license
@ -43,27 +68,3 @@ License File: spring-boot.license
Spring Data JPA - Persist data in SQL stores with Java Persistence API using Spring Data and Hibernate. (https://github.com/spring-projects/spring-data-jpa/blob/main/LICENSE.txt)
License: Apache 2.0
License File: spring-data-jpa.license
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
License: MPL 2.0 or EPL 1.0
License File: h2database.license
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
License: Apache 2.0
License File: JSON.simple.license
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
License: Apache 2.0
License File: gson.license
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
License: Apache 2.0
License File: jackson-databind.license
ModelMapper - ModelMapper is an intelligent object mapping library that automatically maps objects to each other. (https://github.com/modelmapper/modelmapper)
License: Apache 2.0
License File modelmapper.license
Project Lombok - Project Lombok is a java library that automatically plugs into your editor and build tools. (https://mvnrepository.com/artifact/org.projectlombok/lombok).
License: MIT
License File lombok.license

View File

@ -1,8 +1,17 @@
ONLYOFFICE Applications example uses code from the following 3rd party projects:
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
License: Apache 2.0
License File: gson.license
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
License: MPL 2.0 or EPL 1.0
License File: h2database.license
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
License: Apache 2.0
License File: jackson-databind.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
@ -16,14 +25,30 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
License File: jQuery.UI.license
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
License: Apache 2.0
License File: JSON.simple.license
Project Lombok - Project Lombok is a java library that automatically plugs into your editor and build tools. (https://mvnrepository.com/artifact/org.projectlombok/lombok).
License: MIT
License File lombok.license
ModelMapper - ModelMapper is an intelligent object mapping library that automatically maps objects to each other. (https://github.com/modelmapper/modelmapper)
License: Apache 2.0
License File modelmapper.license
Prime JWT - is intended to be fast and easy to use. Prime JWT has a single external dependency on Jackson. (https://github.com/ws-apps/prime-jwt/blob/master/LICENSE)
License: Apache 2.0
License File: prime-jwt.license
@ -43,19 +68,3 @@ License File: spring-boot.license
Spring Data JPA - Persist data in SQL stores with Java Persistence API using Spring Data and Hibernate. (https://github.com/spring-projects/spring-data-jpa/blob/main/LICENSE.txt)
License: Apache 2.0
License File: spring-data-jpa.license
H2 Database Engine - This software contains unmodified binary redistributions for H2 database engine. H2 is a relational DBMS that can be embedded in java applications. (https://h2database.com/html/license.html)
License: MPL 2.0 or EPL 1.0
License File: h2database.license
JSON.simple - JSON.simple is a simple Java toolkit for JSON. You can use JSON.simple to encode or decode JSON text. (https://github.com/fangyidong/json-simple/blob/master/LICENSE.txt)
License: Apache 2.0
License File: JSON.simple.license
Gson - Gson is a Java library that can be used to convert Java Objects into their JSON representation. (https://github.com/google/gson/blob/master/LICENSE)
License: Apache 2.0
License File: gson.license
Jackson Databind - General-purpose data-binding functionality and tree-model for Jackson Data Processor. (https://github.com/FasterXML/jackson-databind/blob/master/LICENSE)
License: Apache 2.0
License File: jackson-databind.license

View File

@ -36,7 +36,6 @@ import com.onlyoffice.integration.documentserver.util.service.ServiceConverter;
import com.onlyoffice.integration.documentserver.managers.document.DocumentManager;
import com.onlyoffice.integration.documentserver.managers.callback.CallbackManager;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.Resource;
@ -65,7 +64,6 @@ import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Optional;
@ -236,9 +234,6 @@ public class FileController {
throw new RuntimeException("Input stream is null");
}
// remove source file
storageMutator.deleteFile(fileName);
// create the converted file with input stream
storageMutator.createFile(Path.of(storagePathBuilder.getFileLocation(correctedName)), stream);
fileName = correctedName;
@ -464,18 +459,18 @@ public class FileController {
@ResponseBody
public String reference(@RequestBody final JSONObject body) {
try {
JSONParser parser = new JSONParser();
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
String userAddress = "";
String fileName = "";
if (body.containsKey("referenceData")) {
LinkedHashMap referenceDataObj = (LinkedHashMap) body.get("referenceData");
JSONObject referenceDataObj = (JSONObject) body.get("referenceData");
String instanceId = (String) referenceDataObj.get("instanceId");
if (instanceId.equals(storagePathBuilder.getServerUrl(false))) {
JSONObject fileKey = (JSONObject) parser.parse((String) referenceDataObj.get("fileKey"));
JSONObject fileKey = (JSONObject) referenceDataObj.get("fileKey");
userAddress = (String) fileKey.get("userAddress");
if (userAddress.equals(InetAddress.getLocalHost().getHostAddress())) {
fileName = (String) fileKey.get("fileName");
@ -501,20 +496,18 @@ public class FileController {
return "{ \"error\": \"File not found\"}";
}
boolean directUrl = (boolean) body.get("directUrl");
HashMap<String, Object> fileKey = new HashMap<>();
fileKey.put("fileName", fileName);
fileKey.put("userAddress", InetAddress.getLocalHost().getHostAddress());
HashMap<String, Object> referenceData = new HashMap<>();
referenceData.put("instanceId", storagePathBuilder.getServerUrl(true));
referenceData.put("fileKey", gson.toJson(fileKey));
referenceData.put("fileKey", fileKey);
HashMap<String, Object> data = new HashMap<>();
data.put("fileType", fileUtility.getFileExtension(fileName).replace(".", ""));
data.put("fileType", fileUtility.getFileExtension(fileName));
data.put("url", documentManager.getDownloadUrl(fileName, true));
data.put("directUrl", directUrl ? documentManager.getDownloadUrl(fileName, false) : null);
data.put("directUrl", documentManager.getDownloadUrl(fileName, true));
data.put("referenceData", referenceData);
data.put("path", fileName);

View File

@ -106,17 +106,17 @@ public class DefaultServiceConverter implements ServiceConverter {
connection.connect();
try (OutputStream os = connection.getOutputStream()) {
os.write(bodyByte); // write bytes to the output stream
os.flush(); // force write data to the output stream that can be cached in the current thread
}
int statusCode = connection.getResponseCode();
if (statusCode != HttpStatus.OK.value()) { // checking status code
connection.disconnect();
throw new RuntimeException("Convertation service returned status: " + statusCode);
}
try (OutputStream os = connection.getOutputStream()) {
os.write(bodyByte); // write bytes to the output stream
os.flush(); // force write data to the output stream that can be cached in the current thread
}
response = connection.getInputStream(); // get the input stream
jsonString = convertStreamToString(response); // convert the response stream into a string
} finally {

View File

@ -1,4 +1,4 @@
server.version=1.6.0
server.version=1.5.1
server.address=
server.port=4000
@ -38,8 +38,6 @@ spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
hibernate.ddl-auto
spring.h2.console.enabled=true
spring.h2.console.path=/h2
spring.servlet.multipart.max-file-size=5MB
spring.servlet.multipart.max-request-size=5MB
url.index=/
url.converter=/converter

View File

@ -52,7 +52,7 @@
// the user is trying to switch the document from the viewing into the editing mode
var onRequestEditRights = function () {
location.href = location.href.replace(RegExp("\&?action=view", "i"), "");
location.href = location.href.replace(RegExp("\&?action=view\&?", "i"), "");
};
// an error or some other specific event occurs

View File

@ -1,9 +1,5 @@
ONLYOFFICE Applications example uses code from the following 3rd party projects:
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -16,9 +12,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT

View File

@ -1,9 +1,5 @@
ONLYOFFICE Applications example uses code from the following 3rd party projects:
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -16,9 +12,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT

View File

@ -315,9 +315,9 @@ public class IndexServlet extends HttpServlet {
connection.disconnect();
// remove source file
File sourceFile = new File(DocumentManager.storagePath(fileName, null));
sourceFile.delete();
// remove source file ?
// File sourceFile = new File(DocumentManager.StoragePath(fileName, null));
// sourceFile.delete();
fileName = correctName;
@ -700,8 +700,6 @@ public class IndexServlet extends HttpServlet {
return;
}
boolean directUrl = (boolean) body.get("directUrl");
HashMap<String, Object> fileKey = new HashMap<>();
fileKey.put("fileName", fileName);
fileKey.put("userAddress", DocumentManager.curUserHostAddress(null));
@ -711,9 +709,9 @@ public class IndexServlet extends HttpServlet {
referenceData.put("fileKey", gson.toJson(fileKey));
HashMap<String, Object> data = new HashMap<>();
data.put("fileType", FileUtility.getFileExtension(fileName).replace(".", ""));
data.put("fileType", FileUtility.getFileExtension(fileName));
data.put("url", DocumentManager.getDownloadUrl(fileName, true));
data.put("directUrl", directUrl ? DocumentManager.getDownloadUrl(fileName, false) : null);
data.put("directUrl", DocumentManager.getDownloadUrl(fileName, true));
data.put("referenceData", referenceData);
data.put("path", fileName);

View File

@ -86,11 +86,11 @@ public final class Users {
true, new ArrayList<String>(), descriptionUserSecond, false));
add(new User("uid-3", "Hamish Mitchell", "mitchell@example.com",
"group-3", Arrays.asList("group-2"), new CommentGroups(Arrays.asList("group-3", "group-2"),
Arrays.asList("group-2"), null), Arrays.asList("group-2"),
Arrays.asList("group-2"), new ArrayList<String>()), Arrays.asList("group-2"),
false, Arrays.asList("copy", "download", "print"),
descriptionUserThird, false));
add(new User("uid-0", null, null,
"", null, null, null,
"", null, new CommentGroups(), new ArrayList<String>(),
null, Arrays.asList("protect"), descriptionUserZero, false));
}};

View File

@ -1,4 +1,4 @@
version=1.6.0
version=1.5.1
filesize-max=5242880
storage-folder=app_data

View File

@ -11,5 +11,11 @@ module.exports = {
ecmaVersion: 'latest',
},
rules: {
'max-len': ['error', { code: 120 }],
'no-console': 'off',
'no-continue': 'off',
'no-extend-native': ['error', { exceptions: ['String'] }],
'no-plusplus': ['error', { allowForLoopAfterthoughts: true }],
'no-prototype-builtins': 'off',
},
};

View File

@ -32,10 +32,6 @@ he - a robust HTML entity encoder/decoder written in JavaScript. (htt
License: MIT
License File: he.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -48,9 +44,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,5 @@
{
"version": "1.6.0",
"version": "1.5.1",
"log": {
"appenders": [
{
@ -22,10 +22,6 @@
"apiUrl": "web-apps/apps/api/documents/api.js",
"preloaderUrl": "web-apps/apps/api/documents/cache-scripts.html",
"exampleUrl": null,
"viewedDocs": [".djvu", ".oxps", ".pdf", ".xps"],
"editedDocs": [".csv", ".docm", ".docx", ".docxf", ".dotm", ".dotx", ".epub", ".fb2", ".html", ".odp", ".ods", ".odt", ".otp", ".ots", ".ott", ".potm", ".potx", ".ppsm", ".ppsx", ".pptm", ".pptx", ".rtf", ".txt", ".xlsm", ".xlsx", ".xltm", ".xltx"],
"fillDocs": [".docx", ".oform"],
"convertedDocs": [".doc", ".dot", ".dps", ".dpt", ".epub", ".et", ".ett", ".fb2", ".fodp", ".fods", ".fodt", ".htm", ".html", ".mht", ".mhtml", ".odp", ".ods", ".odt", ".otp", ".ots", ".ott", ".pot", ".pps", ".ppt", ".rtf", ".stw", ".sxc", ".sxi", ".sxw", ".wps", ".wpt", ".xls", ".xlsb", ".xlt", ".xml"],
"storageFolder": "./files",
"storagePath": "/files",
"maxFileSize": 1073741824,

View File

@ -1,4 +1,4 @@
/**
/**
*
* (c) Copyright Ascensio System SIA 2023
*
@ -16,42 +16,43 @@
*
*/
var cache = {};
let cache = {};
// write the key value and its creation time to the cache
exports.put = function (key, value) {
cache[key] = { value:value, time: new Date().getTime()};
}
exports.put = function put(key, value) {
cache[key] = { value, time: new Date().getTime() };
};
// check if the given key is in the cache
exports.containsKey = function (key) {
if (typeof cache[key] == "undefined"){
return false;
}
exports.containsKey = function containsKey(key) {
if (typeof cache[key] === 'undefined') {
return false;
}
var secondsCache = 30;
const secondsCache = 30;
var t1 = new Date(cache[key].time + (1000 * secondsCache)); // get the creation time of the given key and add 30 seconds to it
var t2 = new Date(); // get the current time
if (t1 < t2 ){ // if the current time is greater
delete cache[key]; // delete the given key from the cache
return false;
}
// get the creation time of the given key and add 30 seconds to it
const t1 = new Date(cache[key].time + (1000 * secondsCache));
const t2 = new Date(); // get the current time
if (t1 < t2) { // if the current time is greater
delete cache[key]; // delete the given key from the cache
return false;
}
return true;
}
return true;
};
// get the given key from the cache
exports.get = function (key) {
return cache[key];
}
exports.get = function get(key) {
return cache[key];
};
// delete the given key from the cache
exports.delete = function (key) {
delete cache[key];
}
exports.delete = function deleteKey(key) {
delete cache[key];
};
// clear the cache
exports.clear = function () {
cache = {};
}
exports.clear = function clear() {
cache = {};
};

View File

@ -1,4 +1,3 @@
"use strict";
/**
*
* (c) Copyright Ascensio System SIA 2023
@ -17,488 +16,596 @@
*
*/
const path = require("path");
const fileSystem = require("fs");
const fileUtility = require("./fileUtility");
const documentService = require("./documentService");
const path = require('path');
const fileSystem = require('fs');
const configServer = require('config').get('server');
const storageConfigFolder = configServer.get("storageFolder");
const fileUtility = require('./fileUtility');
const documentService = require('./documentService');
function docManager(req, res) {
this.req = req;
this.res = res;
}
const storageConfigFolder = configServer.get('storageFolder');
const DocManager = function DocManager(req, res) {
this.req = req;
this.res = res;
};
// check if the path exists or not
docManager.prototype.existsSync = function(path) {
let res = true;
try {
fileSystem.accessSync(path, fileSystem.F_OK); // synchronously test the user's permissions for the directory specified by path; the directory is visible to the calling process
} catch (e) { // the response is set to false, if an error occurs
res = false;
}
return res;
DocManager.prototype.existsSync = function existsSync(directory) {
let res = true;
try {
// synchronously test the user's permissions for the directory specified by path;
// the directory is visible to the calling process
fileSystem.accessSync(directory, fileSystem.F_OK);
} catch (e) { // the response is set to false, if an error occurs
res = false;
}
return res;
};
// create a new directory if it doesn't exist
docManager.prototype.createDirectory = function(path) {
if (!this.existsSync(path)) {
fileSystem.mkdirSync(path);
}
DocManager.prototype.createDirectory = function createDirectory(directory) {
if (!this.existsSync(directory)) {
fileSystem.mkdirSync(directory);
}
};
// get the language from the request
docManager.prototype.getLang = function () {
if (new RegExp("^[a-z]{2}(-[A-Z]{2})?$", "i").test(this.req.query.lang)) {
return this.req.query.lang;
} else { // the default language value is English
return "en"
}
DocManager.prototype.getLang = function getLang() {
if (/^[a-z]{2}(-[A-Z]{2})?$/i.test(this.req.query.lang)) {
return this.req.query.lang;
} // the default language value is English
return 'en';
};
// get customization parameters
docManager.prototype.getCustomParams = function () {
let params = "";
DocManager.prototype.getCustomParams = function getCustomParams() {
let params = '';
const userid = this.req.query.userid; // user id
params += (userid ? "&userid=" + userid : "");
const { userid } = this.req.query; // user id
params += (userid ? `&userid=${userid}` : '');
const lang = this.req.query.lang; // language
params += (lang ? "&lang=" + this.getLang() : "");
const { lang } = this.req.query; // language
params += (lang ? `&lang=${this.getLang()}` : '');
const directUrl = this.req.query.directUrl; // directUrl
params += (directUrl ? "&directUrl=" + (directUrl == "true") : "");
const { directUrl } = this.req.query; // directUrl
params += (directUrl ? `&directUrl=${directUrl === 'true'}` : '');
const fileName = this.req.query.fileName; // file name
params += (fileName ? "&fileName=" + fileName : "");
const { fileName } = this.req.query; // file name
params += (fileName ? `&fileName=${fileName}` : '');
const mode = this.req.query.mode; // mode: view/edit/review/comment/fillForms/embedded
params += (mode ? "&mode=" + mode : "");
const { mode } = this.req.query; // mode: view/edit/review/comment/fillForms/embedded
params += (mode ? `&mode=${mode}` : '');
const type = this.req.query.type; // type: embedded/mobile/desktop
params += (type ? "&type=" + type : "");
const { type } = this.req.query; // type: embedded/mobile/desktop
params += (type ? `&type=${type}` : '');
return params;
return params;
};
// get the correct file name if such a name already exists
docManager.prototype.getCorrectName = function (fileName, userAddress) {
const baseName = fileUtility.getFileName(fileName, true); // get file name from the url without extension
const ext = fileUtility.getFileExtension(fileName); // get file extension from the url
let name = baseName + ext; // get full file name
let index = 1;
DocManager.prototype.getCorrectName = function getCorrectName(fileName, userAddress) {
const baseName = fileUtility.getFileName(fileName, true); // get file name from the url without extension
const ext = fileUtility.getFileExtension(fileName); // get file extension from the url
let name = baseName + ext; // get full file name
let index = 1;
while (this.existsSync(this.storagePath(name, userAddress))) { // if the file with such a name already exists in this directory
name = baseName + " (" + index + ")" + ext; // add an index after its base name
index++;
}
// if the file with such a name already exists in this directory
while (this.existsSync(this.storagePath(name, userAddress))) {
name = `${baseName} (${index})${ext}`; // add an index after its base name
index += 1;
}
return name;
return name;
};
// processes a request editnew
docManager.prototype.RequestEditnew = function (req, fileName, user) {
if (req.params['id'] != fileName){ // processes a repeated request editnew
this.fileRemove(req.params['id']);
fileName = this.getCorrectName(req.params['id']);
}
this.fileSizeZero(fileName);
this.saveFileData(fileName, user.id, user.name);
DocManager.prototype.requestEditnew = function requestEditnew(req, fileName, user) {
let correctName = fileName;
if (req.params.id !== fileName) { // processes a repeated request editnew
this.fileRemove(req.params.id);
correctName = this.getCorrectName(req.params.id);
}
this.fileSizeZero(correctName);
this.saveFileData(correctName, user.id, user.name);
return fileName;
}
return correctName;
};
// delete a file with its history
docManager.prototype.fileRemove = function (fileName) {
const filePath = this.storagePath(fileName); // get the path to this file
fileSystem.unlinkSync(filePath); // and delete it
DocManager.prototype.fileRemove = function fileRemove(fileName) {
const filePath = this.storagePath(fileName); // get the path to this file
fileSystem.unlinkSync(filePath); // and delete it
const userAddress = this.curUserHostAddress();
const historyPath = this.historyPath(fileName, userAddress, true);
this.cleanFolderRecursive(historyPath, true); // clean all the files from the history folder
}
const userAddress = this.curUserHostAddress();
const historyPath = this.historyPath(fileName, userAddress, true);
this.cleanFolderRecursive(historyPath, true); // clean all the files from the history folder
};
// create a zero-size file
docManager.prototype.fileSizeZero = function (fileName) {
var path = this.storagePath(fileName);
var fh = fileSystem.openSync(path, 'w');
fileSystem.closeSync(fh);
}
DocManager.prototype.fileSizeZero = function fileSizeZero(fileName) {
const storagePath = this.storagePath(fileName);
const fh = fileSystem.openSync(storagePath, 'w');
fileSystem.closeSync(fh);
};
// create demo document
docManager.prototype.createDemo = function (isSample, fileExt, userid, username, wopi) {
// eslint-disable-next-line no-unused-vars
DocManager.prototype.createDemo = function createDemo(isSample, fileExt, userid, username, wopi) {
const demoName = `${isSample ? 'sample' : 'new'}.${fileExt}`;
const fileName = this.getCorrectName(demoName); // get the correct file name if such a name already exists
const demoName = (isSample ? "sample" : "new") + "." + fileExt;
const fileName = this.getCorrectName(demoName); // get the correct file name if such a name already exists
// copy sample document of a necessary extension to the storage path
this.copyFile(path.join(__dirname, '..', 'public', 'assets', 'document-templates', isSample
? 'sample' : 'new', demoName), this.storagePath(fileName));
this.copyFile(path.join(__dirname, "..","public", "assets", isSample ? "sample" : "new", demoName), this.storagePath(fileName)); // copy sample document of a necessary extension to the storage path
this.saveFileData(fileName, userid, username); // save file data to the file
this.saveFileData(fileName, userid, username); // save file data to the file
return fileName;
return fileName;
};
// save file data to the file
docManager.prototype.saveFileData = function (fileName, userid, username, userAddress) {
if (!userAddress) {
userAddress = this.curUserHostAddress(); // get current user host address
}
// get full creation date of the document
const date_create = fileSystem.statSync(this.storagePath(fileName, userAddress)).mtime;
const minutes = (date_create.getMinutes() < 10 ? '0' : '') + date_create.getMinutes().toString();
const month = (date_create.getMonth() < 10 ? '0' : '') + (parseInt(date_create.getMonth().toString()) + 1);
const sec = (date_create.getSeconds() < 10 ? '0' : '') + date_create.getSeconds().toString();
const date_format = date_create.getFullYear() + "-" + month + "-" + date_create.getDate() + " " + date_create.getHours() + ":" + minutes + ":" + sec;
DocManager.prototype.saveFileData = function saveFileData(fileName, userid, username, userAddress) {
let address = userAddress;
if (!address) {
address = this.curUserHostAddress(); // get current user host address
}
// get full creation date of the document
const dateCreate = fileSystem.statSync(this.storagePath(fileName, address)).mtime;
const minutes = (dateCreate.getMinutes() < 10 ? '0' : '') + dateCreate.getMinutes().toString();
const month = (dateCreate.getMonth() < 10 ? '0' : '') + (parseInt(dateCreate.getMonth().toString(), 10) + 1);
const sec = (dateCreate.getSeconds() < 10 ? '0' : '') + dateCreate.getSeconds().toString();
const dateFormat = `${dateCreate.getFullYear()}-${month}-${dateCreate.getDate()}`
+ `${dateCreate.getHours()}:${minutes}:${sec}`;
const file_info = this.historyPath(fileName, userAddress, true); // get file history information
this.createDirectory(file_info); // create a new history directory if it doesn't exist
const fileInfo = this.historyPath(fileName, address, true); // get file history information
this.createDirectory(fileInfo); // create a new history directory if it doesn't exist
fileSystem.writeFileSync(path.join(file_info, fileName + ".txt"), date_format + "," + userid + "," + username); // write all the file information to a new txt file
// write all the file information to a new txt file
fileSystem.writeFileSync(path.join(fileInfo, `${fileName}.txt`), `${dateFormat},${userid},${username}`);
};
// get file data
docManager.prototype.getFileData = function (fileName, userAddress) {
const history = path.join(this.historyPath(fileName, userAddress, true), fileName + ".txt"); // get the path to the file with file information
if (!this.existsSync(history)) { // if such a file doesn't exist
return ["2017-01-01", "uid-1", "John Smith"]; // return default information
}
DocManager.prototype.getFileData = function getFileData(fileName, userAddress) {
// get the path to the file with file information
const history = path.join(this.historyPath(fileName, userAddress, true), `${fileName}.txt`);
if (!this.existsSync(history)) { // if such a file doesn't exist
return ['2017-01-01', 'uid-1', 'John Smith']; // return default information
}
return ((fileSystem.readFileSync(history)).toString()).split(",");
return ((fileSystem.readFileSync(history)).toString())
.split(',');
};
// get server url
docManager.prototype.getServerUrl = function (forDocumentServer) {
return (forDocumentServer && !!configServer.get("exampleUrl")) ? configServer.get("exampleUrl") : this.getServerPath();
DocManager.prototype.getServerUrl = function getServerUrl(forDocumentServer) {
return (forDocumentServer && !!configServer.get('exampleUrl'))
? configServer.get('exampleUrl') : this.getServerPath();
};
// get server address from the request
docManager.prototype.getServerPath = function () {
return this.getServerHost() + (this.req.headers["x-forwarded-path"] || this.req.baseUrl);
DocManager.prototype.getServerPath = function getServerPath() {
return this.getServerHost() + (this.req.headers['x-forwarded-path'] || this.req.baseUrl);
};
// get host address from the request
docManager.prototype.getServerHost = function () {
return this.getProtocol() + "://" + (this.req.headers["x-forwarded-host"] || this.req.headers["host"]) + (this.req.headers["x-forwarded-prefix"] || "");
DocManager.prototype.getServerHost = function getServerHost() {
return `${this.getProtocol()}://${this.req.headers['x-forwarded-host'] || this.req.headers.host}`
+ `${this.req.headers['x-forwarded-prefix'] || ''}`;
};
// get protocol from the request
docManager.prototype.getProtocol = function () {
return this.req.headers["x-forwarded-proto"] || this.req.protocol;
DocManager.prototype.getProtocol = function getProtocol() {
return this.req.headers['x-forwarded-proto'] || this.req.protocol;
};
// get callback url
docManager.prototype.getCallback = function (fileName) {
const server = this.getServerUrl(true);
const hostAddress = this.curUserHostAddress();
const handler = "/track?filename=" + encodeURIComponent(fileName) + "&useraddress=" + encodeURIComponent(hostAddress); // get callback handler
DocManager.prototype.getCallback = function getCallback(fileName) {
const server = this.getServerUrl(true);
const hostAddress = this.curUserHostAddress();
// get callback handler
const handler = `/track?filename=${encodeURIComponent(fileName)}&useraddress=${encodeURIComponent(hostAddress)}`;
return server + handler;
return server + handler;
};
// get url to the created file
docManager.prototype.getCreateUrl = function (docType, userid, type, lang) {
const server = this.getServerUrl();
var ext = this.getInternalExtension(docType).replace(".", "");
const handler = "/editor?fileExt=" + ext + "&userid=" + userid + "&type=" + type + "&lang=" + lang;
DocManager.prototype.getCreateUrl = function getCreateUrl(docType, userid, type, lang) {
const server = this.getServerUrl();
const ext = this.getInternalExtension(docType).replace('.', '');
const handler = `/editor?fileExt=${ext}&userid=${userid}&type=${type}&lang=${lang}`;
return server + handler;
}
// get url to download a file
docManager.prototype.getDownloadUrl = function (fileName, forDocumentServer) {
const server = this.getServerUrl(forDocumentServer);
var handler = "/download?fileName=" + encodeURIComponent(fileName);
if (forDocumentServer) {
const hostAddress = this.curUserHostAddress();
handler += "&useraddress=" + encodeURIComponent(hostAddress);
}
return server + handler;
return server + handler;
};
docManager.prototype.storageRootPath = function (userAddress) {
return path.join(storageConfigFolder, this.curUserHostAddress(userAddress)); // get the path to the directory for the host address
}
// get url to download a file
DocManager.prototype.getDownloadUrl = function getDownloadUrl(fileName, forDocumentServer) {
const server = this.getServerUrl(forDocumentServer);
let handler = `/download?fileName=${encodeURIComponent(fileName)}`;
if (forDocumentServer) {
const hostAddress = this.curUserHostAddress();
handler += `&useraddress=${encodeURIComponent(hostAddress)}`;
}
return server + handler;
};
DocManager.prototype.storageRootPath = function storageRootPath(userAddress) {
// get the path to the directory for the host address
return path.join(storageConfigFolder, this.curUserHostAddress(userAddress));
};
// get the storage path of the given file
docManager.prototype.storagePath = function (fileName, userAddress) {
fileName = fileUtility.getFileName(fileName); // get the file name with extension
const directory = this.storageRootPath(userAddress);
this.createDirectory(directory); // create a new directory if it doesn't exist
return path.join(directory, fileName); // put the given file to this directory
DocManager.prototype.storagePath = function storagePath(fileName, userAddress) {
const fileNameExt = fileUtility.getFileName(fileName); // get the file name with extension
const directory = this.storageRootPath(userAddress);
this.createDirectory(directory); // create a new directory if it doesn't exist
return path.join(directory, fileNameExt); // put the given file to this directory
};
// get the path to the forcesaved file version
docManager.prototype.forcesavePath = function (fileName, userAddress, create) {
let directory = this.storageRootPath(userAddress);
if (!this.existsSync(directory)) { // the directory with host address doesn't exist
return "";
}
directory = path.join(directory, fileName + "-history"); // get the path to the history of the given file
if (!create && !this.existsSync(directory)) { // the history directory doesn't exist and we are not supposed to create it
return "";
}
this.createDirectory(directory); // create history directory if it doesn't exist
directory = path.join(directory, fileName); // and get the path to the given file
if (!create && !this.existsSync(directory)) {
return "";
}
return directory;
DocManager.prototype.forcesavePath = function forcesavePath(fileName, userAddress, create) {
let directory = this.storageRootPath(userAddress);
if (!this.existsSync(directory)) { // the directory with host address doesn't exist
return '';
}
directory = path.join(directory, `${fileName}-history`); // get the path to the history of the given file
// the history directory doesn't exist and we are not supposed to create it
if (!create && !this.existsSync(directory)) {
return '';
}
this.createDirectory(directory); // create history directory if it doesn't exist
directory = path.join(directory, fileName); // and get the path to the given file
if (!create && !this.existsSync(directory)) {
return '';
}
return directory;
};
// create the path to the file history
docManager.prototype.historyPath = function (fileName, userAddress, create) {
let directory = this.storageRootPath(userAddress);
if (!this.existsSync(directory)) {
return "";
}
directory = path.join(directory, fileName + "-history");
if (!create && !this.existsSync(path.join(directory, "1"))) {
return "";
}
return directory;
DocManager.prototype.historyPath = function historyPath(fileName, userAddress, create) {
let directory = this.storageRootPath(userAddress);
if (!this.existsSync(directory)) {
return '';
}
directory = path.join(directory, `${fileName}-history`);
if (!create && !this.existsSync(path.join(directory, '1'))) {
return '';
}
return directory;
};
// get the path to the specified file version
docManager.prototype.versionPath = function (fileName, userAddress, version) {
const historyPath = this.historyPath(fileName, userAddress, true); // get the path to the history of a given file or create it if it doesn't exist
return path.join(historyPath, "" + version);
DocManager.prototype.versionPath = function versionPath(fileName, userAddress, version) {
// get the path to the history of a given file or create it if it doesn't exist
const historyPath = this.historyPath(fileName, userAddress, true);
return path.join(historyPath, `${version}`);
};
// get the path to the previous file version
docManager.prototype.prevFilePath = function (fileName, userAddress, version) {
return path.join(this.versionPath(fileName, userAddress, version), "prev" + fileUtility.getFileExtension(fileName));
DocManager.prototype.prevFilePath = function prevFilePath(fileName, userAddress, version) {
return path.join(this.versionPath(fileName, userAddress, version), `prev${fileUtility.getFileExtension(fileName)}`);
};
// get the path to the file with document versions differences
docManager.prototype.diffPath = function (fileName, userAddress, version) {
return path.join(this.versionPath(fileName, userAddress, version), "diff.zip");
DocManager.prototype.diffPath = function diffPath(fileName, userAddress, version) {
return path.join(this.versionPath(fileName, userAddress, version), 'diff.zip');
};
// get the path to the file with document changes
docManager.prototype.changesPath = function (fileName, userAddress, version) {
return path.join(this.versionPath(fileName, userAddress, version), "changes.txt");
DocManager.prototype.changesPath = function changesPath(fileName, userAddress, version) {
return path.join(this.versionPath(fileName, userAddress, version), 'changes.txt');
};
// get the path to the file with key value in it
docManager.prototype.keyPath = function (fileName, userAddress, version) {
return path.join(this.versionPath(fileName, userAddress, version), "key.txt");
DocManager.prototype.keyPath = function keyPath(fileName, userAddress, version) {
return path.join(this.versionPath(fileName, userAddress, version), 'key.txt');
};
// get the path to the file with the user information
docManager.prototype.changesUser = function (fileName, userAddress, version) {
return path.join(this.versionPath(fileName, userAddress, version), "user.txt");
DocManager.prototype.changesUser = function changesUser(fileName, userAddress, version) {
return path.join(this.versionPath(fileName, userAddress, version), 'user.txt');
};
// get all the stored files
docManager.prototype.getStoredFiles = function () {
const userAddress = this.curUserHostAddress();
const directory = this.storageRootPath(userAddress);
this.createDirectory(directory);
const result = [];
const storedFiles = fileSystem.readdirSync(directory); // read the user host directory contents
for (let i = 0; i < storedFiles.length; i++) { // run through all the elements from the folder
const stats = fileSystem.lstatSync(path.join(directory, storedFiles[i])); // save element parameters
DocManager.prototype.getStoredFiles = function getStoredFiles() {
const userAddress = this.curUserHostAddress();
const directory = this.storageRootPath(userAddress);
this.createDirectory(directory);
const result = [];
const storedFiles = fileSystem.readdirSync(directory); // read the user host directory contents
for (let i = 0; i < storedFiles.length; i++) { // run through all the elements from the folder
const stats = fileSystem.lstatSync(path.join(directory, storedFiles[i])); // save element parameters
if (!stats.isDirectory()) { // if the element isn't a directory
let historyPath = this.historyPath(storedFiles[i], userAddress); // get the path to the file history
let version = 0;
if (historyPath != "") { // if the history path exists
version = this.countVersion(historyPath); // get the last file version
}
if (!stats.isDirectory()) { // if the element isn't a directory
const historyPath = this.historyPath(storedFiles[i], userAddress); // get the path to the file history
let version = 0;
if (historyPath !== '') { // if the history path exists
version = this.countVersion(historyPath); // get the last file version
}
const time = stats.mtime.getTime(); // get the time of element modification
const item = { // create an object with element data
time: time,
name: storedFiles[i],
documentType: fileUtility.getFileType(storedFiles[i]),
canEdit: configServer.get("editedDocs").indexOf(fileUtility.getFileExtension(storedFiles[i])) != -1,
version: version+1
};
const time = stats.mtime.getTime(); // get the time of element modification
const item = { // create an object with element data
time,
name: storedFiles[i],
documentType: fileUtility.getFileType(storedFiles[i]),
canEdit: fileUtility.getEditExtensions().indexOf(fileUtility.getFileExtension(storedFiles[i], true)) !== -1,
version: version + 1,
};
if (!result.length) { // if the result array is empty
result.push(item); // push the item object to it
} else {
let j = 0;
for (; j < result.length; j++) {
if (time > result[j].time) { // otherwise, run through all the objects from the result array
break;
}
}
result.splice(j, 0, item); // and add new object in ascending order of time
}
if (!result.length) { // if the result array is empty
result.push(item); // push the item object to it
} else {
let j = 0;
for (; j < result.length; j++) {
if (time > result[j].time) { // otherwise, run through all the objects from the result array
break;
}
}
result.splice(j, 0, item); // and add new object in ascending order of time
}
}
return result;
}
return result;
};
// get current user host address
docManager.prototype.curUserHostAddress = function (userAddress) {
if (!userAddress) // if user address isn't passed to the function
userAddress = this.req.headers["x-forwarded-for"] || this.req.connection.remoteAddress; // take it from the header or use the remote address
DocManager.prototype.curUserHostAddress = function curUserHostAddress(userAddress) {
let address = userAddress;
if (!address) { // if user address isn't passed to the function
// take it from the header or use the remote address
address = this.req.headers['x-forwarded-for'] || this.req.connection.remoteAddress;
}
return userAddress.replace(new RegExp("[^0-9a-zA-Z.=]", "g"), "_");
return address.replace(/[^0-9a-zA-Z.=]/g, '_');
};
// copy file
docManager.prototype.copyFile = function (exist, target) {
fileSystem.writeFileSync(target, fileSystem.readFileSync(exist));
DocManager.prototype.copyFile = function copyFile(exist, target) {
fileSystem.writeFileSync(target, fileSystem.readFileSync(exist));
};
// get an internal extension
docManager.prototype.getInternalExtension = function (fileType) {
if (fileType == fileUtility.fileType.word) // .docx for word type
return ".docx";
DocManager.prototype.getInternalExtension = function getInternalExtension(fileType) {
if (fileType === fileUtility.fileType.word) { // .docx for word type
return '.docx';
}
if (fileType == fileUtility.fileType.cell) // .xlsx for cell type
return ".xlsx";
if (fileType === fileUtility.fileType.cell) { // .xlsx for cell type
return '.xlsx';
}
if (fileType == fileUtility.fileType.slide) // .pptx for slide type
return ".pptx";
if (fileType === fileUtility.fileType.slide) { // .pptx for slide type
return '.pptx';
}
return ".docx"; // the default value is .docx
return '.docx'; // the default value is .docx
};
// get the template image url
docManager.prototype.getTemplateImageUrl = function (fileType) {
let path = this.getServerUrl(true);
if (fileType == fileUtility.fileType.word) // for word type
return path + "/images/file_docx.svg";
DocManager.prototype.getTemplateImageUrl = function getTemplateImageUrl(fileType) {
const serverUrl = this.getServerUrl(true);
if (fileType === fileUtility.fileType.word) { // for word type
return `${serverUrl}/images/file_docx.svg`;
}
if (fileType == fileUtility.fileType.cell) // for cell type
return path + "/images/file_xlsx.svg";
if (fileType === fileUtility.fileType.cell) { // for cell type
return `${path}/images/file_xlsx.svg`;
}
if (fileType == fileUtility.fileType.slide) // for slide type
return path + "/images/file_pptx.svg";
if (fileType === fileUtility.fileType.slide) { // for slide type
return `${path}/images/file_pptx.svg`;
}
return path + "/images/file_docx.svg"; // the default value
}
return `${path}/images/file_docx.svg`; // the default value
};
// get document key
docManager.prototype.getKey = function (fileName, userAddress) {
userAddress = userAddress || this.curUserHostAddress();
let key = userAddress + fileName; // get document key by adding local file url to the current user host address
DocManager.prototype.getKey = function getKey(fileName, userAddress) {
const address = userAddress || this.curUserHostAddress();
let key = address + fileName; // get document key by adding local file url to the current user host address
let historyPath = this.historyPath(fileName, userAddress); // get the path to the file history
if (historyPath != ""){ // if the path to the file history exists
key += this.countVersion(historyPath); // add file version number to the document key
}
const historyPath = this.historyPath(fileName, address); // get the path to the file history
if (historyPath !== '') { // if the path to the file history exists
key += this.countVersion(historyPath); // add file version number to the document key
}
let storagePath = this.storagePath(fileName, userAddress); // get the storage path to the given file
const stat = fileSystem.statSync(storagePath); // get file information
key += stat.mtime.getTime(); // and add creation time to the document key
const storagePath = this.storagePath(fileName, address); // get the storage path to the given file
const stat = fileSystem.statSync(storagePath); // get file information
key += stat.mtime.getTime(); // and add creation time to the document key
return documentService.generateRevisionId(key); // generate the document key value
return documentService.generateRevisionId(key); // generate the document key value
};
// get current date
docManager.prototype.getDate = function (date) {
const minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes().toString();
return date.getMonth() + "/" + date.getDate() + "/" + date.getFullYear() + " " + date.getHours() + ":" + minutes;
DocManager.prototype.getDate = function getDate(date) {
const minutes = (date.getMinutes() < 10 ? '0' : '') + date.getMinutes().toString();
return `${date.getMonth()}/${date.getDate()}/${date.getFullYear()} ${date.getHours()}:${minutes}`;
};
// get changes made in the file
docManager.prototype.getChanges = function (fileName) {
if (this.existsSync(fileName)) { // if the directory with such a file exists
return JSON.parse(fileSystem.readFileSync(fileName)); // read this file and parse it
}
return null;
DocManager.prototype.getChanges = function getChanges(fileName) {
if (this.existsSync(fileName)) { // if the directory with such a file exists
return JSON.parse(fileSystem.readFileSync(fileName)); // read this file and parse it
}
return null;
};
// get the last file version
docManager.prototype.countVersion = function(directory) {
let i = 0;
while (this.existsSync(path.join(directory, '' + (i + 1)))) { // run through all the file versions
i++; // and count them
}
return i;
DocManager.prototype.countVersion = function countVersion(directory) {
let i = 0;
while (this.existsSync(path.join(directory, `${i + 1}`))) { // run through all the file versions
i += 1; // and count them
}
return i;
};
// get file history information
docManager.prototype.getHistory = function (fileName, content, keyVersion, version) {
let oldVersion = false;
let contentJson = null;
if (content) { // if content is defined
if (content.changes && content.changes.length) { // and there are some modifications in the content
contentJson = content.changes[0]; // write these modifications to the json content
} else if (content.length){
contentJson = content[0]; // otherwise, write original content to the json content
oldVersion = true; // and note that this is an old version
} else {
content = false;
}
DocManager.prototype.getHistoryObject = function getHistoryObject(fileName, userAddr = null, userDirectUrl = null) {
const userAddress = userAddr || this.curUserHostAddress();
const historyPath = this.historyPath(fileName, userAddress);
const key = this.getKey(fileName);
const directUrl = this.getDownloadUrl(fileName);
const fileExt = fileUtility.getFileExtension(fileName);
const url = this.getDownloadUrl(fileName, true);
const history = [];
const historyData = [];
let countVersion = 1;
let changes = null;
let keyVersion = key;
if (historyPath !== '') {
countVersion = this.countVersion(historyPath) + 1; // get the number of file versions
for (let i = 1; i <= countVersion; i++) { // get keys to all the file versions
if (i < countVersion) {
const keyPath = this.keyPath(fileName, userAddress, i);
if (!fileSystem.existsSync(keyPath)) continue;
keyVersion = `${fileSystem.readFileSync(keyPath)}`;
} else {
keyVersion = key;
}
// write all the file history information
history.push(this.getHistory(fileName, changes, keyVersion, i));
const userUrl = i === countVersion ? directUrl : (`${this.getServerUrl(false)}/history?fileName=`
+ `${encodeURIComponent(fileName)}&file=prev${fileExt}&ver=${i}`);
const historyD = {
fileType: fileExt.slice(1),
version: i,
key: keyVersion,
url: i === countVersion ? url : (`${this.getServerUrl(true)}/history?fileName=`
+ `${encodeURIComponent(fileName)}&file=prev${fileExt}&ver=${i}&useraddress=${userAddress}`),
directUrl: !userDirectUrl ? null : userUrl,
};
// check if the path to the file with document versions differences exists
if (i > 1 && this.existsSync(this.diffPath(fileName, userAddress, i - 1))) {
historyD.previous = { // write information about previous file version
fileType: historyData[i - 2].fileType,
key: historyData[i - 2].key,
url: historyData[i - 2].url,
directUrl: !userDirectUrl ? null : historyData[i - 2].directUrl,
};
const changesUrl = `${this.getServerUrl(true)}/history?fileName=`
+ `${encodeURIComponent(fileName)}&file=diff.zip&ver=${i - 1}&useraddress=${userAddress}`;
historyD.changesUrl = changesUrl; // get the path to the diff.zip file and write it to the history object
}
historyData.push(historyD);
if (i < countVersion) {
// get the path to the file with document changes
const changesFile = this.changesPath(fileName, userAddress, i);
changes = this.getChanges(changesFile); // get changes made in the file
}
}
} else { // if history path is empty
// write the history information about the last file version
history.push(this.getHistory(fileName, changes, keyVersion, countVersion));
historyData.push({
fileType: fileExt.slice(1),
version: countVersion,
key,
url,
directUrl: !userDirectUrl ? null : directUrl,
});
}
const userAddress = this.curUserHostAddress();
const username = content ? (oldVersion ? contentJson.username : contentJson.user.name) : (this.getFileData(fileName, userAddress))[2];
const userid = content ? (oldVersion ? contentJson.userid : contentJson.user.id) : (this.getFileData(fileName, userAddress))[1];
const created = content ? (oldVersion ? contentJson.date : contentJson.created) : (this.getFileData(fileName, userAddress))[0];
const res = (content && !oldVersion) ? content : {changes: content};
res.key = keyVersion; // write the information about the user, creation time, key and version to the result object
res.version = version;
res.created = created;
res.user = {
id: userid,
name: username != "null" ? username : null
};
return { history, historyData, countVersion };
};
// get file history information
DocManager.prototype.getHistory = function getHistory(fileName, content, keyVersion, version) {
let oldVersion = false;
let contentJson = null;
let fileContent = content;
let userNameFromJson = null;
let userIdFromJson = null;
let createdFromJson = null;
if (fileContent) { // if content is defined
if (fileContent.changes && fileContent.changes.length) { // and there are some modifications in the content
[contentJson] = fileContent.changes; // write these modifications to the json content
} else if (fileContent.length) {
[contentJson] = fileContent; // otherwise, write original content to the json content
oldVersion = true; // and note that this is an old version
} else {
fileContent = false;
}
}
return res;
const userAddress = this.curUserHostAddress();
if (content && contentJson) {
userNameFromJson = oldVersion ? contentJson.username : contentJson.user.name;
userIdFromJson = oldVersion ? contentJson.userid : contentJson.user.userid;
createdFromJson = oldVersion ? contentJson.date : contentJson.created;
}
const username = userNameFromJson || (this.getFileData(fileName, userAddress))[2];
const userid = userIdFromJson || (this.getFileData(fileName, userAddress))[1];
const created = createdFromJson || (this.getFileData(fileName, userAddress))[0];
const res = (fileContent && !oldVersion) ? fileContent : { changes: fileContent };
res.key = keyVersion; // write the information about the user, creation time, key and version to the result object
res.version = version;
res.created = created;
res.user = {
id: userid,
name: username !== 'null' ? username : null,
};
return res;
};
// clean folder
docManager.prototype.cleanFolderRecursive = function (folder, me) {
if (fileSystem.existsSync(folder)) { // if the given folder exists
const files = fileSystem.readdirSync(folder);
files.forEach((file) => { // for each file from the folder
const curPath = path.join(folder, file); // get its current path
if (fileSystem.lstatSync(curPath).isDirectory()) {
this.cleanFolderRecursive(curPath, true); // for each folder included in this one repeat the same procedure
} else {
fileSystem.unlinkSync(curPath); // remove the file
}
});
if (me) {
fileSystem.rmdirSync(folder);
}
DocManager.prototype.cleanFolderRecursive = function cleanFolderRecursive(folder, me) {
if (fileSystem.existsSync(folder)) { // if the given folder exists
const files = fileSystem.readdirSync(folder);
files.forEach((file) => { // for each file from the folder
const curPath = path.join(folder, file); // get its current path
if (fileSystem.lstatSync(curPath).isDirectory()) {
this.cleanFolderRecursive(curPath, true); // for each folder included in this one repeat the same procedure
} else {
fileSystem.unlinkSync(curPath); // remove the file
}
});
if (me) {
fileSystem.rmdirSync(folder);
}
}
};
// get files information
docManager.prototype.getFilesInfo = function (fileId) {
const userAddress = this.curUserHostAddress();
const directory = this.storageRootPath(userAddress);
const filesInDirectory = this.getStoredFiles(); // get all the stored files from the folder
let responseArray = [];
let responseObject;
for (let currentFile = 0; currentFile < filesInDirectory.length; currentFile++) { // run through all the files from the directory
const file = filesInDirectory[currentFile];
const stats = fileSystem.lstatSync(path.join(directory, file.name)); // get file information
const fileObject = { // write file parameters to the file object
version: file.version,
id: this.getKey(file.name),
contentLength: `${(stats.size/1024).toFixed(2)} KB`,
pureContentLength: stats.size,
title: file.name,
updated: stats.mtime
};
if (fileId !== undefined) { // if file id is defined
if (this.getKey(file.name) == fileId) { // and it is equal to the document key value
responseObject = fileObject; // response object will be equal to the file object
break;
}
}
else responseArray.push(fileObject); // otherwise, push file object to the response array
DocManager.prototype.getFilesInfo = function getFilesInfo(fileId) {
const userAddress = this.curUserHostAddress();
const directory = this.storageRootPath(userAddress);
const filesInDirectory = this.getStoredFiles(); // get all the stored files from the folder
const responseArray = [];
let responseObject;
// run through all the files from the directory
for (let currentFile = 0; currentFile < filesInDirectory.length; currentFile++) {
const file = filesInDirectory[currentFile];
const stats = fileSystem.lstatSync(path.join(directory, file.name)); // get file information
const fileObject = { // write file parameters to the file object
version: file.version,
id: this.getKey(file.name),
contentLength: `${(stats.size / 1024).toFixed(2)} KB`,
pureContentLength: stats.size,
title: file.name,
updated: stats.mtime,
};
if (fileId !== undefined) {
if (responseObject !== undefined) return responseObject;
else return "File not found";
}
else return responseArray;
if (fileId !== undefined) { // if file id is defined
if (this.getKey(file.name) === fileId) { // and it is equal to the document key value
responseObject = fileObject; // response object will be equal to the file object
break;
}
} else responseArray.push(fileObject); // otherwise, push file object to the response array
}
if (fileId !== undefined) {
if (responseObject !== undefined) return responseObject;
return 'File not found';
} return responseArray;
};
docManager.prototype.getInstanceId = function () {
return this.getServerUrl();
DocManager.prototype.getInstanceId = function getInstanceId() {
return this.getServerUrl();
};
// save all the functions to the docManager module to export it later in other files
module.exports = docManager;
// save all the functions to the DocManager module to export it later in other files
module.exports = DocManager;

View File

@ -1,4 +1,4 @@
/**
/**
*
* (c) Copyright Ascensio System SIA 2023
*
@ -17,229 +17,261 @@
*/
// get all the necessary values and modules
var urlModule = require("url");
var urllib = require("urllib");
var jwt = require("jsonwebtoken");
var fileUtility = require("./fileUtility");
var guidManager = require("./guidManager");
var configServer = require('config').get('server');
var siteUrl = configServer.get('siteUrl'); // the path to the editors installation
var cfgSignatureEnable = configServer.get('token.enable');
var cfgSignatureUseForRequest = configServer.get('token.useforrequest');
var cfgSignatureAuthorizationHeader = configServer.get('token.authorizationHeader');
var cfgSignatureAuthorizationHeaderPrefix = configServer.get('token.authorizationHeaderPrefix');
var cfgSignatureSecretExpiresIn = configServer.get('token.expiresIn');
var cfgSignatureSecret = configServer.get('token.secret');
var cfgSignatureSecretAlgorithmRequest = configServer.get('token.algorithmRequest');
const urlModule = require('url');
const urllib = require('urllib');
const jwt = require('jsonwebtoken');
const configServer = require('config').get('server');
const fileUtility = require('./fileUtility');
const guidManager = require('./guidManager');
var documentService = {};
const siteUrl = configServer.get('siteUrl'); // the path to the editors installation
const cfgSignatureEnable = configServer.get('token.enable');
const cfgSignatureUseForRequest = configServer.get('token.useforrequest');
const cfgSignatureAuthorizationHeader = configServer.get('token.authorizationHeader');
const cfgSignatureAuthorizationHeaderPrefix = configServer.get('token.authorizationHeaderPrefix');
const cfgSignatureSecretExpiresIn = configServer.get('token.expiresIn');
const cfgSignatureSecret = configServer.get('token.secret');
const cfgSignatureSecretAlgorithmRequest = configServer.get('token.algorithmRequest');
const documentService = {};
documentService.userIp = null;
// get the url of the converted file (synchronous)
documentService.getConvertedUriSync = function (documentUri, fromExtension, toExtension, documentRevisionId, callback) {
documentService.getConvertedUri(documentUri, fromExtension, toExtension, documentRevisionId, false, function (err, data) {
callback(err, data);
});
documentService.getConvertedUriSync = function getConvertedUriSync(
documentUri,
fromExtension,
toExtension,
documentRevisionId,
callback,
) {
documentService.getConvertedUri(documentUri, fromExtension, toExtension, documentRevisionId, false, (err, data) => {
callback(err, data);
});
};
// get the url of the converted file
documentService.getConvertedUri = function (documentUri, fromExtension, toExtension, documentRevisionId, async, callback, filePass = null, lang = null) {
fromExtension = fromExtension || fileUtility.getFileExtension(documentUri); // get the current document extension
documentService.getConvertedUri = function getConvertedUri(
documentUri,
fromExtension,
toExtension,
documentRevisionId,
async,
callback,
filePass = null,
lang = null,
) {
const fromExt = fromExtension || fileUtility.getFileExtension(documentUri); // get the current document extension
var title = fileUtility.getFileName(documentUri) || guidManager.newGuid(); // get the current document name or uuid
const title = fileUtility.getFileName(documentUri) || guidManager.newGuid(); // get the current document name or uuid
documentRevisionId = documentService.generateRevisionId(documentRevisionId || documentUri); // generate the document key value
// generate the document key value
const revisionId = documentService.generateRevisionId(documentRevisionId || documentUri);
var params = { // write all the conversion parameters to the params dictionary
async: async,
url: documentUri,
outputtype: toExtension.replace(".", ""),
filetype: fromExtension.replace(".", ""),
title: title,
key: documentRevisionId,
password: filePass,
region: lang,
};
const params = { // write all the conversion parameters to the params dictionary
async,
url: documentUri,
outputtype: toExtension.replace('.', ''),
filetype: fromExt.replace('.', ''),
title,
key: revisionId,
password: filePass,
region: lang,
};
var uri = siteUrl + configServer.get('converterUrl'); // get the absolute converter url
var headers = {
'Content-Type': 'application/json',
"Accept": "application/json"
};
const uri = siteUrl + configServer.get('converterUrl'); // get the absolute converter url
const headers = {
'Content-Type': 'application/json',
Accept: 'application/json',
};
if (cfgSignatureEnable && cfgSignatureUseForRequest) { // if the signature is enabled and it can be used for request
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params); // write signature authorization header
params.token = documentService.getToken(params); // get token and save it to the parameters
}
if (cfgSignatureEnable && cfgSignatureUseForRequest) { // if the signature is enabled and it can be used for request
// write signature authorization header
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params);
params.token = documentService.getToken(params); // get token and save it to the parameters
}
//parse url to allow request by relative url after https://github.com/node-modules/urllib/pull/321/commits/514de1924bf17a38a6c2db2a22a6bc3494c0a959
urllib.request(urlModule.parse(uri),
{
method: "POST",
headers: headers,
data: params
},
callback);
// parse url to allow request by relative url after
// https://github.com/node-modules/urllib/pull/321/commits/514de1924bf17a38a6c2db2a22a6bc3494c0a959
urllib.request(
urlModule.parse(uri),
{
method: 'POST',
headers,
data: params,
},
callback,
);
};
// generate the document key value
documentService.generateRevisionId = function (expectedKey) {
let maxKeyLength = 128; // the max key length is 128
if (expectedKey.length > maxKeyLength) { // if the expected key length is greater than the max key length
expectedKey = expectedKey.hashCode().toString(); // the expected key is hashed and a fixed length value is stored in the string format
}
documentService.generateRevisionId = function generateRevisionId(expectedKey) {
const maxKeyLength = 128; // the max key length is 128
let expKey = expectedKey;
if (expKey.length > maxKeyLength) { // if the expected key length is greater than the max key length
// the expected key is hashed and a fixed length value is stored in the string format
expKey = expKey.hashCode().toString();
}
var key = expectedKey.replace(new RegExp("[^0-9-.a-zA-Z_=]", "g"), "_");
const key = expKey.replace(/[^0-9-.a-zA-Z_=]/g, '_');
return key.substring(0, Math.min(key.length, maxKeyLength)); // the resulting key is of the max key length or less
return key.substring(0, Math.min(key.length, maxKeyLength)); // the resulting key is of the max key length or less
};
// create an error message for the error code
documentService.processConvertServiceResponceError = function (errorCode) {
var errorMessage = "";
var errorMessageTemplate = "Error occurred in the ConvertService: ";
documentService.processConvertServiceResponceError = function processConvertServiceResponceError(errorCode) {
let errorMessage = '';
const errorMessageTemplate = 'Error occurred in the ConvertService: ';
// add the error message to the error message template depending on the error code
switch (errorCode) {
case -20:
errorMessage = errorMessageTemplate + "Error encrypt signature";
break;
case -8:
errorMessage = errorMessageTemplate + "Error document signature";
break;
case -7:
errorMessage = errorMessageTemplate + "Error document request";
break;
case -6:
errorMessage = errorMessageTemplate + "Error database";
break;
case -5:
errorMessage = errorMessageTemplate + "Incorrect password";
break;
case -4:
errorMessage = errorMessageTemplate + "Error download error";
break;
case -3:
errorMessage = errorMessageTemplate + "Error convertation error";
break;
case -2:
errorMessage = errorMessageTemplate + "Error convertation timeout";
break;
case -1:
errorMessage = errorMessageTemplate + "Error convertation unknown";
break;
case 0: // if the error code is equal to 0, the error message is empty
break;
default:
errorMessage = "ErrorCode = " + errorCode; // default value for the error message
break;
}
// add the error message to the error message template depending on the error code
switch (errorCode) {
case -20:
errorMessage = `${errorMessageTemplate}Error encrypt signature`;
break;
case -8:
errorMessage = `${errorMessageTemplate}Error document signature`;
break;
case -7:
errorMessage = `${errorMessageTemplate}Error document request`;
break;
case -6:
errorMessage = `${errorMessageTemplate}Error database`;
break;
case -5:
errorMessage = `${errorMessageTemplate}Incorrect password`;
break;
case -4:
errorMessage = `${errorMessageTemplate}Error download error`;
break;
case -3:
errorMessage = `${errorMessageTemplate}Error convertation error`;
break;
case -2:
errorMessage = `${errorMessageTemplate}Error convertation timeout`;
break;
case -1:
errorMessage = `${errorMessageTemplate}Error convertation unknown`;
break;
case 0: // if the error code is equal to 0, the error message is empty
break;
default:
errorMessage = `ErrorCode = ${errorCode}`; // default value for the error message
break;
}
throw { message: errorMessage };
throw new Error(errorMessage);
};
// get the response url
documentService.getResponseUri = function (json) {
var fileResult = JSON.parse(json);
documentService.getResponseUri = function getResponseUri(json) {
const fileResult = JSON.parse(json);
if (fileResult.error) // if an error occurs
documentService.processConvertServiceResponceError(parseInt(fileResult.error)); // get an error message
if (fileResult.error) { // if an error occurs
documentService.processConvertServiceResponceError(parseInt(fileResult.error, 10)); // get an error message
}
var isEndConvert = fileResult.endConvert // check if the conversion is completed
const isEndConvert = fileResult.endConvert; // check if the conversion is completed
var percent = parseInt(fileResult.percent); // get the conversion percentage
var uri = null;
var fileType = null;
let percent = parseInt(fileResult.percent, 10); // get the conversion percentage
let uri = null;
let fileType = null;
if (isEndConvert) { // if the conversion is completed
if (!fileResult.fileUrl) // and the file url doesn't exist
throw { message: "FileUrl is null" }; // the file url is null
uri = fileResult.fileUrl; // otherwise, get the file url
fileType = fileResult.fileType; // get the file type
percent = 100;
} else { // if the conversion isn't completed
percent = percent >= 100 ? 99 : percent; // get the percentage value
if (isEndConvert) { // if the conversion is completed
if (!fileResult.fileUrl) { // and the file url doesn't exist
throw new Error('FileUrl is null'); // the file url is null
}
return {
percent : percent,
uri : uri,
fileType : fileType
};
uri = fileResult.fileUrl; // otherwise, get the file url
({ fileType } = fileResult); // get the file type
percent = 100;
} else { // if the conversion isn't completed
percent = percent >= 100 ? 99 : percent; // get the percentage value
}
return {
percent,
uri,
fileType,
};
};
// create a command request
documentService.commandRequest = function (method, documentRevisionId, meta = null, callback) {
documentService.commandRequest = function commandRequest(method, documentRevisionId, callback, meta = null) {
const revisionId = documentService.generateRevisionId(documentRevisionId); // generate the document key value
const params = { // create a parameter object with command method and the document key value in it
c: method,
key: revisionId,
};
documentRevisionId = documentService.generateRevisionId(documentRevisionId); // generate the document key value
params = { // create a parameter object with command method and the document key value in it
c: method,
key: documentRevisionId
};
if (meta) {
params.meta = meta;
}
if (meta) {
params.meta = meta;
}
const uri = siteUrl + configServer.get('commandUrl'); // get the absolute command url
const headers = { // create a headers object
'Content-Type': 'application/json',
};
if (cfgSignatureEnable && cfgSignatureUseForRequest) {
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params);
params.token = documentService.getToken(params);
}
var uri = siteUrl + configServer.get('commandUrl'); // get the absolute command url
var headers = { // create a headers object
'Content-Type': 'application/json'
};
if (cfgSignatureEnable && cfgSignatureUseForRequest) {
headers[cfgSignatureAuthorizationHeader] = cfgSignatureAuthorizationHeaderPrefix + this.fillJwtByUrl(uri, params);
params.token = documentService.getToken(params);
}
//parse url to allow request by relative url after https://github.com/node-modules/urllib/pull/321/commits/514de1924bf17a38a6c2db2a22a6bc3494c0a959
urllib.request(urlModule.parse(uri),
{
method: "POST",
headers: headers,
data: params
},
callback);
// parse url to allow request by relative url after
// https://github.com/node-modules/urllib/pull/321/commits/514de1924bf17a38a6c2db2a22a6bc3494c0a959
urllib.request(
urlModule.parse(uri),
{
method: 'POST',
headers,
data: params,
},
callback,
);
};
// check jwt token headers
documentService.checkJwtHeader = function (req) {
var decoded = null;
var authorization = req.get(cfgSignatureAuthorizationHeader); // get signature authorization header from the request
if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) { // if authorization header exists and it starts with the authorization header prefix
var token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length); // the resulting token starts after the authorization header prefix
documentService.checkJwtHeader = function checkJwtHeader(req) {
let decoded = null;
const authorization = req.get(cfgSignatureAuthorizationHeader); // get signature authorization header from the request
// if authorization header exists and it starts with the authorization header prefix
if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) {
// the resulting token starts after the authorization header prefix
const token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length);
try {
decoded = jwt.verify(token, cfgSignatureSecret); // verify signature on jwt token using signature secret
decoded = jwt.verify(token, cfgSignatureSecret); // verify signature on jwt token using signature secret
} catch (err) {
console.log('checkJwtHeader error: name = ' + err.name + ' message = ' + err.message + ' token = ' + token) // print debug information to the console
// print debug information to the console
console.log(`checkJwtHeader error: name = ${err.name} message = ${err.message} token = ${token}`);
}
}
return decoded;
}
};
// get jwt token using url information
documentService.fillJwtByUrl = function (uri, opt_dataObject) {
var parseObject = urlModule.parse(uri, true); // get parse object from the url
var payload = {query: parseObject.query, payload: opt_dataObject}; // create payload object
documentService.fillJwtByUrl = function fillJwtByUrl(uri, optDataObject) {
const parseObject = urlModule.parse(uri, true); // get parse object from the url
const payload = { query: parseObject.query, payload: optDataObject }; // create payload object
var options = {algorithm: cfgSignatureSecretAlgorithmRequest, expiresIn: cfgSignatureSecretExpiresIn};
return jwt.sign(payload, cfgSignatureSecret, options); // sign token with given data using signature secret and options parameters
}
const options = { algorithm: cfgSignatureSecretAlgorithmRequest, expiresIn: cfgSignatureSecretExpiresIn };
// sign token with given data using signature secret and options parameters
return jwt.sign(payload, cfgSignatureSecret, options);
};
// get token
documentService.getToken = function (data) {
var options = {algorithm: cfgSignatureSecretAlgorithmRequest, expiresIn: cfgSignatureSecretExpiresIn};
return jwt.sign(data, cfgSignatureSecret, options); // sign token with given data using signature secret and options parameters
documentService.getToken = function getToken(data) {
const options = { algorithm: cfgSignatureSecretAlgorithmRequest, expiresIn: cfgSignatureSecretExpiresIn };
// sign token with given data using signature secret and options parameters
return jwt.sign(data, cfgSignatureSecret, options);
};
// read and verify token
documentService.readToken = function (token) {
try {
return jwt.verify(token, cfgSignatureSecret); // verify signature on jwt token using signature secret
} catch (err) {
console.log('checkJwtHeader error: name = ' + err.name + ' message = ' + err.message + ' token = ' + token)
}
return null;
documentService.readToken = function readToken(token) {
try {
return jwt.verify(token, cfgSignatureSecret); // verify signature on jwt token using signature secret
} catch (err) {
console.log(`checkJwtHeader error: name = ${err.name} message = ${err.message} token = ${token}`);
}
return null;
};
// save all the functions to the documentService module to export it later in other files

View File

@ -1,4 +1,4 @@
/**
/**
*
* (c) Copyright Ascensio System SIA 2023
*
@ -16,79 +16,103 @@
*
*/
var fileUtility = {};
const supportedFormats = require('../public/assets/document-formats/onlyoffice-docs-formats.json'); // eslint-disable-line
const fileUtility = {};
// get file name from the given url
fileUtility.getFileName = function (url, withoutExtension) {
if (!url) return "";
fileUtility.getFileName = function getFileName(url, withoutExtension) {
if (!url) return '';
var parts = url.split("\\");
parts = parts.pop();
parts = parts.split("/");
var fileName = parts.pop(); // get the file name from the last part of the url
fileName = fileName.split("?")[0];
let parts = url.split('\\');
parts = parts.pop();
parts = parts.split('/');
let fileName = parts.pop(); // get the file name from the last part of the url
[fileName] = fileName.split('?');
// get file name without extension
if (withoutExtension) {
return fileName.substring(0, fileName.lastIndexOf("."));
}
// get file name without extension
if (withoutExtension) {
return fileName.substring(0, fileName.lastIndexOf('.'));
}
return fileName;
return fileName;
};
// get file extension from the given url
fileUtility.getFileExtension = function (url, withoutDot) {
if (!url) return null;
fileUtility.getFileExtension = function getFileExtension(url, withoutDot) {
if (!url) return null;
var fileName = fileUtility.getFileName(url); // get file name from the given url
const fileName = fileUtility.getFileName(url); // get file name from the given url
var parts = fileName.toLowerCase().split(".");
const parts = fileName.toLowerCase().split('.');
return withoutDot ? parts.pop() : "." + parts.pop(); // get the extension from the file name with or without dot
return withoutDot ? parts.pop() : `.${parts.pop()}`; // get the extension from the file name with or without dot
};
// get file type from the given url
fileUtility.getFileType = function (url) {
var ext = fileUtility.getFileExtension(url); // get the file extension from the given url
fileUtility.getFileType = function getFileType(url) {
const ext = fileUtility.getFileExtension(url, true); // get the file extension from the given url
if (fileUtility.documentExts.indexOf(ext) != -1) return fileUtility.fileType.word; // word type for document extensions
if (fileUtility.spreadsheetExts.indexOf(ext) != -1) return fileUtility.fileType.cell; // cell type for spreadsheet extensions
if (fileUtility.presentationExts.indexOf(ext) != -1) return fileUtility.fileType.slide; // slide type for presentation extensions
for (let i = 0; i < supportedFormats.length; i++) {
if (supportedFormats[i].name === ext) return supportedFormats[i].type;
}
return fileUtility.fileType.word; // the default file type is word
}
return fileUtility.fileType.word; // the default file type is word
};
fileUtility.fileType = {
word: "word",
cell: "cell",
slide: "slide"
}
word: 'word',
cell: 'cell',
slide: 'slide',
};
// the document extension list
fileUtility.documentExts = [".doc", ".docx", ".oform", ".docm", ".dot", ".dotx", ".dotm", ".odt", ".fodt", ".ott", ".rtf", ".txt", ".html", ".htm", ".mht", ".xml", ".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oxps"];
fileUtility.getSuppotredExtensions = function getSuppotredExtensions() {
return supportedFormats.reduce((extensions, format) => [...extensions, format.name], []);
};
// the spreadsheet extension list
fileUtility.spreadsheetExts = [".xls", ".xlsx", ".xlsm", ".xlsb", ".xlt", ".xltx", ".xltm", ".ods", ".fods", ".ots", ".csv"];
fileUtility.getViewExtensions = function getViewExtensions() {
return supportedFormats.filter(
(format) => format.actions.includes('view'),
).reduce((extensions, format) => [...extensions, format.name], []);
};
// the presentation extension list
fileUtility.presentationExts = [".pps", ".ppsx", ".ppsm", ".ppt", ".pptx", ".pptm", ".pot", ".potx", ".potm", ".odp", ".fodp", ".otp"];
fileUtility.getEditExtensions = function getEditExtensions() {
return supportedFormats.filter(
(format) => format.actions.includes('edit') || format.actions.includes('lossy-edit'),
).reduce((extensions, format) => [...extensions, format.name], []);
};
fileUtility.getFillExtensions = function getFillExtensions() {
return supportedFormats.filter(
(format) => format.actions.includes('fill'),
).reduce((extensions, format) => [...extensions, format.name], []);
};
fileUtility.getConvertExtensions = function getConvertExtensions() {
return supportedFormats.filter(
(format) => (format.type === 'word' && format.convert.includes('docx'))
|| (format.type === 'cell' && format.convert.includes('xlsx'))
|| (format.type === 'slide' && format.convert.includes('pptx')),
).reduce((extensions, format) => [...extensions, format.name], []);
};
// get url parameters
function getUrlParams(url) {
try {
var query = url.split("?").pop(); // take all the parameters which are placed after ? sign in the file url
var params = query.split("&"); // parameters are separated by & sign
var map = {}; // write parameters and their values to the map dictionary
for (var i = 0; i < params.length; i++) {
var parts = param.split("=");
map[parts[0]] = parts[1];
}
return map;
// eslint-disable-next-line no-unused-vars
const getUrlParams = function getUrlParams(url) {
try {
const query = url.split('?').pop(); // take all the parameters which are placed after ? sign in the file url
const params = query.split('&'); // parameters are separated by & sign
const map = {}; // write parameters and their values to the map dictionary
for (let i = 0; i < params.length; i++) {
// eslint-disable-next-line no-undef
const parts = param.split('=');
[, map[parts[0]]] = parts;
}
catch (ex) {
return null;
}
}
return map;
} catch (ex) {
return null;
}
};
// save all the functions to the fileUtility module to export it later in other files
module.exports = fileUtility;

View File

@ -1,4 +1,4 @@
/**
/**
*
* (c) Copyright Ascensio System SIA 2023
*
@ -17,11 +17,12 @@
*/
// generate 16 octet
var s4 = function () {
return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
const s4 = function s4() {
return Math.trunc((1 + Math.random()) * 0x10000).toString(16)
.substring(1);
};
// create uuid v4
exports.newGuid = function () {
return (s4() + s4() + "-" + s4() + "-" + s4() + "-" + s4() + "-" + s4() + s4() + s4());
};
exports.newGuid = function newGuid() {
return (`${s4() + s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`);
};

View File

@ -16,80 +16,20 @@
*
*/
var descr_user_1 = [
"File author by default",
"Doesnt belong to any group",
"Can review all the changes",
"Can perform all actions with comments",
"The file favorite state is undefined",
"Can create files from templates using data from the editor",
"Can see the information about all users",
//"Can submit forms"
];
var descr_user_2 = [
"Belongs to Group2",
"Can review only his own changes or changes made by users with no group",
"Can view comments, edit his own comments and comments left by users with no group. Can remove his own comments only",
"This file is marked as favorite",
"Can create new files from the editor",
"Can see the information about users from Group2 and users who dont belong to any group",
//"Cant submit forms"
];
var descr_user_3 = [
"Belongs to Group3",
"Can review changes made by Group2 users",
"Can view comments left by Group2 and Group3 users. Can edit comments left by the Group2 users",
"This file isnt marked as favorite",
"Cant copy data from the file to clipboard",
"Cant download the file",
"Cant print the file",
"Can create new files from the editor",
"Can see the information about Group2 users",
//"Cant submit forms"
];
var descr_user_0 = [
"The name is requested when the editor is opened",
"Doesnt belong to any group",
"Can review all the changes",
"Can perform all actions with comments",
"The file favorite state is undefined",
"Can't mention others in comments",
"Can't create new files from the editor",
"Cant see anyones information",
"Can't rename files from the editor",
"Can't view chat",
"Can't protect file",
"View file without collaboration",
//"Cant submit forms"
];
var users = [
new User("uid-1", "John Smith", "smith@example.com",
null, null, {}, null,
null, [], descr_user_1, true),
new User("uid-2", "Mark Pottato", "pottato@example.com",
"group-2", ["group-2", ""], {
view: "",
edit: ["group-2", ""],
remove: ["group-2"]
}, ["group-2", ""],
true, [], descr_user_2, false), // own and without group
new User("uid-3", "Hamish Mitchell", null,
"group-3", ["group-2"], {
view: ["group-3", "group-2"],
edit: ["group-2"],
remove: []
}, ["group-2"],
false, ["copy", "download", "print"], descr_user_3, false), // other group only
new User("uid-0", null, null,
null, null, {}, [],
null, ["protect"], descr_user_0, false),
];
function User(id, name, email, group, reviewGroups, commentGroups, userInfoGroups, favorite, deniedPermissions, descriptions, templates) {
class User {
constructor(
id,
name,
email,
group,
reviewGroups,
commentGroups,
userInfoGroups,
favorite,
deniedPermissions,
descriptions,
templates,
) {
this.id = id;
this.name = name;
this.email = email;
@ -101,51 +41,117 @@ function User(id, name, email, group, reviewGroups, commentGroups, userInfoGroup
this.deniedPermissions = deniedPermissions;
this.descriptions = descriptions;
this.templates = templates;
};
}
}
const descrUser1 = [
'File author by default',
'Doesnt belong to any group',
'Can review all the changes',
'Can perform all actions with comments',
'The file favorite state is undefined',
'Can create files from templates using data from the editor',
'Can see the information about all users',
// "Can submit forms"
];
const descrUser2 = [
'Belongs to Group2',
'Can review only his own changes or changes made by users with no group',
'Can view comments, edit his own comments and comments left by users with no group. Can remove his own comments only',
'This file is marked as favorite',
'Can create new files from the editor',
'Can see the information about users from Group2 and users who dont belong to any group',
// "Cant submit forms"
];
const descrUser3 = [
'Belongs to Group3',
'Can review changes made by Group2 users',
'Can view comments left by Group2 and Group3 users. Can edit comments left by the Group2 users',
'This file isnt marked as favorite',
'Cant copy data from the file to clipboard',
'Cant download the file',
'Cant print the file',
'Can create new files from the editor',
'Can see the information about Group2 users',
// "Cant submit forms"
];
const descrUser0 = [
'The name is requested when the editor is opened',
'Doesnt belong to any group',
'Can review all the changes',
'Can perform all actions with comments',
'The file favorite state is undefined',
'Can\'t mention others in comments',
'Can\'t create new files from the editor',
'Cant see anyones information',
'Can\'t rename files from the editor',
'Can\'t view chat',
'Can\'t protect file',
'View file without collaboration',
// "Cant submit forms"
];
const users = [
new User('uid-1', 'John Smith', 'smith@example.com', null, null, {}, null, null, [], descrUser1, true),
new User('uid-2', 'Mark Pottato', 'pottato@example.com', 'group-2', ['group-2', ''], {
view: '',
edit: ['group-2', ''],
remove: ['group-2'],
}, ['group-2', ''], true, [], descrUser2, false), // own and without group
new User('uid-3', 'Hamish Mitchell', 'mitchell@example.com', 'group-3', ['group-2'], {
view: ['group-3', 'group-2'],
edit: ['group-2'],
remove: [],
}, ['group-2'], false, ['copy', 'download', 'print'], descrUser3, false), // other group only
new User('uid-0', null, null, null, null, {}, [], null, ['protect'], descrUser0, false),
];
// get a list of all the users
users.getAllUsers = function () {
return users;
users.getAllUsers = function getAllUsers() {
return users;
};
// get a user by id specified
users.getUser = function (id) {
var result = null;
this.forEach(user => {
if (user.id == id) {
result = user;
}
});
return result ? result : this[0];
users.getUser = function getUser(id) {
let result = null;
this.forEach((user) => {
if (user.id === id) {
result = user;
}
});
return result || this[0];
};
// get a list of users with their name and email for mentions
users.getUsersForMentions = function (id) {
var result = [];
this.forEach(user => {
if (user.id != id && user.name != null && user.email != null) {
result.push({
email: user.email,
name: user.name
});
}
});
return result;
users.getUsersForMentions = function getUsersForMentions(id) {
const result = [];
this.forEach((user) => {
if (user.id !== id && user.name && user.email) {
result.push({
email: user.email,
name: user.name,
});
}
});
return result;
};
// get a list of users with their name, id and email for protect
users.getUsersForProtect = function (id) {
var result = [];
this.forEach(user => {
if (user.id != id && user.name != null) {
result.push({
email: user.email,
id: user.id,
name: user.name
});
}
});
return result;
users.getUsersForProtect = function getUsersForProtect(id) {
const result = [];
this.forEach((user) => {
if (user.id !== id && user.name != null) {
result.push({
email: user.email,
id: user.id,
name: user.name,
});
}
});
return result;
};
module.exports = users;

View File

@ -16,14 +16,343 @@
*
*/
const fileSystem = require('fs');
const mime = require('mime');
const path = require('path');
const reqConsts = require('./request');
const fileUtility = require("../fileUtility");
const lockManager = require("./lockManager");
const fileSystem = require("fs");
const mime = require("mime");
const path = require("path");
const users = require("../users");
const docManager = require("../docManager");
const fileUtility = require('../fileUtility');
const lockManager = require('./lockManager');
const users = require('../users');
const DocManager = require('../docManager');
// return lock mismatch
const returnLockMismatch = function returnLockMismatch(res, lock, reason) {
res.setHeader(reqConsts.requestHeaders.Lock, lock || ''); // set the X-WOPI-Lock header
if (reason) { // if there is a reason for lock mismatch
res.setHeader(reqConsts.requestHeaders.LockFailureReason, reason); // set it as the X-WOPI-LockFailureReason header
}
res.sendStatus(409); // conflict
};
// lock file editing
const lock = function lock(wopi, req, res, userHost) {
const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
const userAddress = req.DocManager.curUserHostAddress(userHost); // get current user host address
const filePath = req.DocManager.storagePath(wopi.id, userAddress); // get the storage path of the given file
if (!lockManager.hasLock(filePath)) {
// file isn't locked => lock
lockManager.lock(filePath, requestLock);
res.sendStatus(200);
} else if (lockManager.getLock(filePath) === requestLock) {
// lock matches current lock => extend duration
lockManager.lock(filePath, requestLock);
res.sendStatus(200);
} else {
// file locked by someone else => return lock mismatch
const locked = lockManager.getLock(filePath);
returnLockMismatch(res, lock, `File already locked by ${locked}`);
}
};
const saveFileFromBody = function saveFileFromBody(req, filename, userAddress, isNewVersion, callback) {
if (req.body) {
const storagePath = req.DocManager.storagePath(filename, userAddress);
let historyPath = req.DocManager.historyPath(filename, userAddress); // get the path to the file history
if (historyPath === '') { // if it is empty
historyPath = req.DocManager.historyPath(filename, userAddress, true); // create it
req.DocManager.createDirectory(historyPath); // and create a new directory for the history
}
let version = 0;
if (isNewVersion) {
const countVersion = req.DocManager.countVersion(historyPath); // get the last file version
version = countVersion + 1; // get a number of a new file version
// get the path to the specified file version
const versionPath = req.DocManager.versionPath(filename, userAddress, version);
req.DocManager.createDirectory(versionPath); // and create a new directory for the specified version
// get the path to the previous file version
const pathPrev = path.join(versionPath, `prev${fileUtility.getFileExtension(filename)}`);
fileSystem.renameSync(storagePath, pathPrev); // synchronously rename the given file as the previous file version
}
const filestream = fileSystem.createWriteStream(storagePath);
req.pipe(filestream);
req.on('end', () => {
filestream.close();
callback(null, version);
});
} else {
callback('empty body');
}
};
// return name that wopi-client can use as the value of X-WOPI-RelativeTarget in a future PutRelativeFile operation
const returnValidRelativeTarget = function returnValidRelativeTarget(res, filename) {
res.setHeader(reqConsts.requestHeaders.ValidRelativeTarget, filename); // set the X-WOPI-ValidRelativeTarget header
res.sendStatus(409); // file with that name already exists
};
// retrieve a lock on a file
const getLock = function getLock(wopi, req, res, userHost) {
const userAddress = req.DocManager.curUserHostAddress(userHost);
const filePath = req.DocManager.storagePath(wopi.id, userAddress);
// get the lock of the specified file and set it as the X-WOPI-Lock header
res.setHeader(reqConsts.requestHeaders.lock, lockManager.getLock(filePath));
res.sendStatus(200);
};
// refresh the lock on a file by resetting its automatic expiration timer to 30 minutes
const refreshLock = function refreshLock(wopi, req, res, userHost) {
const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
const userAddress = req.DocManager.curUserHostAddress(userHost);
const filePath = req.DocManager.storagePath(wopi.id, userAddress);
if (!lockManager.hasLock(filePath)) {
// file isn't locked => mismatch
returnLockMismatch(res, '', 'File isn\'t locked');
} else if (lockManager.getLock(filePath) === requestLock) {
// lock matches current lock => extend duration
lockManager.lock(filePath, requestLock);
res.sendStatus(200);
} else {
// lock mismatch
returnLockMismatch(res, lockManager.getLock(filePath), 'Lock mismatch');
}
};
// allow for file editing
const unlock = function unlock(wopi, req, res, userHost) {
const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
const userAddress = req.DocManager.curUserHostAddress(userHost);
const filePath = req.DocManager.storagePath(wopi.id, userAddress);
if (!lockManager.hasLock(filePath)) {
// file isn't locked => mismatch
returnLockMismatch(res, '', 'File isn\'t locked');
} else if (lockManager.getLock(filePath) === requestLock) {
// lock matches current lock => unlock
lockManager.unlock(filePath);
res.sendStatus(200);
} else {
// lock mismatch
returnLockMismatch(res, lockManager.getLock(filePath), 'Lock mismatch');
}
};
// allow for file editing, and then immediately take a new lock on the file
const unlockAndRelock = function unlockAndRelock(wopi, req, res, userHost) {
const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
const oldLock = req.headers[reqConsts.requestHeaders.oldLock.toLowerCase()]; // get the X-WOPI-OldLock header
const userAddress = req.DocManager.curUserHostAddress(userHost);
const filePath = req.DocManager.storagePath(wopi.id, userAddress);
if (!lockManager.hasLock(filePath)) {
// file isn't locked => mismatch
returnLockMismatch(res, '', 'File isn\'t locked');
} else if (lockManager.getLock(filePath) === oldLock) {
// lock matches current lock => lock with new key
lockManager.lock(filePath, requestLock);
res.sendStatus(200);
} else {
// lock mismatch
returnLockMismatch(res, lockManager.getLock(filePath), 'Lock mismatch');
}
};
// request a message to retrieve a file
const getFile = function getFile(wopi, req, res, userHost) {
const userAddress = req.DocManager.curUserHostAddress(userHost);
const storagePath = req.DocManager.storagePath(wopi.id, userAddress);
res.setHeader('Content-Length', fileSystem.statSync(storagePath).size);
res.setHeader('Content-Type', mime.getType(storagePath));
res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(wopi.id)}`);
const filestream = fileSystem.createReadStream(storagePath); // open a file as a readable stream
filestream.pipe(res); // retrieve data from file stream and output it to the response object
};
// request a message to update a file
const putFile = function putFile(wopi, req, res, userHost) {
const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
const userAddress = req.DocManager.curUserHostAddress(userHost);
const storagePath = req.DocManager.storagePath(wopi.id, userAddress);
if (!lockManager.hasLock(storagePath)) {
// ToDo: if body length is 0 bytes => handle document creation
// file isn't locked => mismatch
returnLockMismatch(res, '', 'File isn\'t locked');
} else if (lockManager.getLock(storagePath) === requestLock) {
// lock matches current lock => put file
saveFileFromBody(req, wopi.id, userAddress, true, (err, version) => {
if (!err) {
res.setHeader(reqConsts.requestHeaders.ItemVersion, version); // set the X-WOPI-ItemVersion header
}
res.sendStatus(err ? 404 : 200);
});
} else {
// lock mismatch
returnLockMismatch(res, lockManager.getLock(storagePath), 'Lock mismatch');
}
};
const putRelativeFile = function putRelativeFile(wopi, req, res, userHost) {
const userAddress = req.DocManager.curUserHostAddress(userHost);
const storagePath = req.DocManager.storagePath(wopi.id, userAddress);
let filename = req.headers[reqConsts.requestHeaders.RelativeTarget.toLowerCase()]; // we cannot modify this filename
if (filename) {
if (req.DocManager.existsSync(storagePath)) { // check if already exists
const overwrite = req.headers[reqConsts.requestHeaders.OverwriteRelativeTarget.toLowerCase()]; // overwrite header
if (overwrite && overwrite === 'true') { // check if we can overwrite
if (lockManager.hasLock(storagePath)) { // check if file locked
// file is locked, cannot overwrite
returnValidRelativeTarget(res, req.DocManager.getCorrectName(wopi.id, userAddress));
return;
}
} else {
// file exists and overwrite header is false
returnValidRelativeTarget(res, req.DocManager.getCorrectName(wopi.id, userAddress));
return;
}
}
} else {
filename = req.headers[reqConsts.requestHeaders.SuggestedTarget.toLowerCase()]; // we can modify this filename
if (filename.startsWith('.')) { // check if extension
filename = fileUtility.getFileName(wopi.id, true) + filename; // get original filename with new extension
}
filename = req.DocManager.getCorrectName(filename, userAddress); // get correct filename if already exists
}
const isConverted = req.headers[reqConsts.requestHeaders.FileConversion.toLowerCase()];
console.log(`putRelativeFile after conversation: ${isConverted}`);
// if we got here, then we can save a file
saveFileFromBody(req, filename, userAddress, false, (err) => {
if (err) {
res.sendStatus(404);
return;
}
const serverUrl = req.DocManager.getServerUrl(true);
const fileActionUrl = `${serverUrl}/wopi-action/${filename}?action=`;
const fileInfo = {
Name: filename,
Url: `${serverUrl}/wopi/files/${filename}`,
HostViewUrl: `${fileActionUrl}view`,
HostEditNewUrl: `${fileActionUrl}editnew`,
HostEditUrl: `${fileActionUrl}edit`,
};
res.status(200).send(fileInfo);
});
};
// return information about the file properties, access rights and editor settings
const checkFileInfo = function checkFileInfo(wopi, req, res, userHost) {
const userAddress = req.DocManager.curUserHostAddress(userHost);
const version = req.DocManager.getKey(wopi.id, userAddress);
const storagePath = req.DocManager.storagePath(wopi.id, userAddress);
// add wopi query
const query = new URLSearchParams(wopi.accessToken);
const user = users.getUser(query.get('userid'));
// create the file information object
const fileInfo = {
BaseFileName: wopi.id,
OwnerId: req.DocManager.getFileData(wopi.id, userAddress)[1],
Size: fileSystem.statSync(storagePath).size,
UserId: user.id,
UserFriendlyName: user.name,
Version: version,
UserCanWrite: true,
SupportsGetLock: true,
SupportsLocks: true,
SupportsUpdate: true,
};
res.status(200).send(fileInfo);
};
// parse wopi request
const parseWopiRequest = function parseWopiRequest(req) {
const wopiData = {
requestType: reqConsts.requestType.None,
accessToken: req.query.access_token,
id: req.params.id,
};
// get the request path
const reqPath = req.path.substring('/wopi/'.length);
if (reqPath.startsWith('files')) { // if it starts with "files"
if (reqPath.endsWith('/contents')) { // ends with "/contents"
if (req.method === 'GET') { // and the request method is GET
wopiData.requestType = reqConsts.requestType.GetFile; // then the request type is GetFile
} else if (req.method === 'POST') { // if the request method is POST
wopiData.requestType = reqConsts.requestType.PutFile; // then the request type is PutFile
}
} else if (req.method === 'GET') { // otherwise, if the request method is GET
wopiData.requestType = reqConsts.requestType.CheckFileInfo; // the request type is CheckFileInfo
} else if (req.method === 'POST') { // if the request method is POST
// get the X-WOPI-Override header which determines the request type
const wopiOverride = req.headers[reqConsts.requestHeaders.RequestType.toLowerCase()];
switch (wopiOverride) {
case 'LOCK': // if it is equal to LOCK
// check if the request sends the X-WOPI-OldLock header
if (req.headers[reqConsts.requestHeaders.OldLock.toLowerCase()]) {
// if yes, then the request type is UnlockAndRelock
wopiData.requestType = reqConsts.requestType.UnlockAndRelock;
} else {
wopiData.requestType = reqConsts.requestType.Lock; // otherwise, it is Lock
}
break;
case 'GET_LOCK': // if it is equal to GET_LOCK
wopiData.requestType = reqConsts.requestType.GetLock; // the request type is GetLock
break;
case 'REFRESH_LOCK': // if it is equal to REFRESH_LOCK
wopiData.requestType = reqConsts.requestType.RefreshLock; // the request type is RefreshLock
break;
case 'UNLOCK': // if it is equal to UNLOCK
wopiData.requestType = reqConsts.requestType.Unlock; // the request type is Unlock
break;
case 'PUT_RELATIVE': // if it is equal to PUT_RELATIVE
// the request type is PutRelativeFile (creates a new file on the host based on the current file)
wopiData.requestType = reqConsts.requestType.PutRelativeFile;
break;
case 'RENAME_FILE': // if it is equal to RENAME_FILE
wopiData.requestType = reqConsts.requestType.RenameFile; // the request type is RenameFile (renames a file)
break;
case 'PUT_USER_INFO': // if it is equal to PUT_USER_INFO
// the request type is PutUserInfo (stores some basic user information on the host)
wopiData.requestType = reqConsts.requestType.PutUserInfo;
break;
default:
}
}
}
return wopiData;
};
const actionMapping = {};
actionMapping[reqConsts.requestType.GetFile] = getFile;
@ -36,352 +365,33 @@ actionMapping[reqConsts.requestType.GetLock] = getLock;
actionMapping[reqConsts.requestType.RefreshLock] = refreshLock;
actionMapping[reqConsts.requestType.Unlock] = unlock;
// parse wopi request
function parseWopiRequest(req) {
let wopiData = {
requestType: reqConsts.requestType.None,
accessToken: req.query["access_token"],
id: req.params['id']
}
// get the request path
let reqPath = req.path.substring("/wopi/".length)
if (reqPath.startsWith("files")) { // if it starts with "files"
if (reqPath.endsWith("/contents")) { // ends with "/contents"
if (req.method == "GET") { // and the request method is GET
wopiData.requestType = reqConsts.requestType.GetFile; // then the request type is GetFile
} else if (req.method == "POST") { // if the request method is POST
wopiData.requestType = reqConsts.requestType.PutFile; // then the request type is PutFile
}
} else {
if (req.method == "GET") { // otherwise, if the request method is GET
wopiData.requestType = reqConsts.requestType.CheckFileInfo; // the request type is CheckFileInfo
} else if (req.method == "POST") { // if the request method is POST
let wopiOverride = req.headers[reqConsts.requestHeaders.RequestType.toLowerCase()]; // get the X-WOPI-Override header which determines the request type
switch (wopiOverride) {
case "LOCK": // if it is equal to LOCK
if (req.headers[reqConsts.requestHeaders.OldLock.toLowerCase()]) { // check if the request sends the X-WOPI-OldLock header
wopiData.requestType = reqConsts.requestType.UnlockAndRelock; // if yes, then the request type is UnlockAndRelock
} else {
wopiData.requestType = reqConsts.requestType.Lock; // otherwise, it is Lock
}
break;
case "GET_LOCK": // if it is equal to GET_LOCK
wopiData.requestType = reqConsts.requestType.GetLock; // the request type is GetLock
break;
case "REFRESH_LOCK": // if it is equal to REFRESH_LOCK
wopiData.requestType = reqConsts.requestType.RefreshLock; // the request type is RefreshLock
break;
case "UNLOCK": // if it is equal to UNLOCK
wopiData.requestType = reqConsts.requestType.Unlock; // the request type is Unlock
break;
case "PUT_RELATIVE": // if it is equal to PUT_RELATIVE
wopiData.requestType = reqConsts.requestType.PutRelativeFile; // the request type is PutRelativeFile (creates a new file on the host based on the current file)
break;
case "RENAME_FILE": // if it is equal to RENAME_FILE
wopiData.requestType = reqConsts.requestType.RenameFile; // the request type is RenameFile (renames a file)
break;
case "PUT_USER_INFO": // if it is equal to PUT_USER_INFO
wopiData.requestType = reqConsts.requestType.PutUserInfo; // the request type is PutUserInfo (stores some basic user information on the host)
break;
}
}
}
} else if (reqPath.startsWith("folders")) {
}
return wopiData;
}
// lock file editing
function lock(wopi, req, res, userHost) {
let requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
let userAddress = req.docManager.curUserHostAddress(userHost); // get current user host address
let filePath = req.docManager.storagePath(wopi.id, userAddress); // get the storage path of the given file
if (!lockManager.hasLock(filePath)) {
// file isn't locked => lock
lockManager.lock(filePath, requestLock);
res.sendStatus(200);
} else if (lockManager.getLock(filePath) == requestLock) {
// lock matches current lock => extend duration
lockManager.lock(filePath, requestLock);
res.sendStatus(200);
} else {
// file locked by someone else => return lock mismatch
let lock = lockManager.getLock(filePath);
returnLockMismatch(res, lock, "File already locked by " + lock)
}
}
// retrieve a lock on a file
function getLock(wopi, req, res, userHost) {
let userAddress = req.docManager.curUserHostAddress(userHost);
let filePath = req.docManager.storagePath(wopi.id, userAddress);
// get the lock of the specified file and set it as the X-WOPI-Lock header
res.setHeader(reqConsts.requestHeaders.lock, lockManager.getLock(filePath));
res.sendStatus(200);
}
// refresh the lock on a file by resetting its automatic expiration timer to 30 minutes
function refreshLock(wopi, req, res, userHost) {
let requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
let userAddress = req.docManager.curUserHostAddress(userHost);
let filePath = req.docManager.storagePath(wopi.id, userAddress);
if (!lockManager.hasLock(filePath)) {
// file isn't locked => mismatch
returnLockMismatch(res, "", "File isn't locked");
} else if (lockManager.getLock(filePath) == requestLock) {
// lock matches current lock => extend duration
lockManager.lock(filePath, requestLock);
res.sendStatus(200);
} else {
// lock mismatch
returnLockMismatch(res, lockManager.getLock(filePath), "Lock mismatch");
}
}
// allow for file editing
function unlock(wopi, req, res, userHost) {
let requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
let userAddress = req.docManager.curUserHostAddress(userHost);
let filePath = req.docManager.storagePath(wopi.id, userAddress);
if (!lockManager.hasLock(filePath)) {
// file isn't locked => mismatch
returnLockMismatch(res, "", "File isn't locked");
} else if (lockManager.getLock(filePath) == requestLock) {
// lock matches current lock => unlock
lockManager.unlock(filePath);
res.sendStatus(200);
} else {
// lock mismatch
returnLockMismatch(res, lockManager.getLock(filePath), "Lock mismatch");
}
}
// allow for file editing, and then immediately take a new lock on the file
function unlockAndRelock(wopi, req, res, userHost) {
let requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
let oldLock = req.headers[reqConsts.requestHeaders.oldLock.toLowerCase()]; // get the X-WOPI-OldLock header
let userAddress = req.docManager.curUserHostAddress(userHost);
let filePath = req.docManager.storagePath(wopi.id, userAddress);
if (!lockManager.hasLock(filePath)) {
// file isn't locked => mismatch
returnLockMismatch(res, "", "File isn't locked");
} else if (lockManager.getLock(filePath) == oldLock) {
// lock matches current lock => lock with new key
lockManager.lock(filePath, requestLock);
res.sendStatus(200);
} else {
// lock mismatch
returnLockMismatch(res, lockManager.getLock(filePath), "Lock mismatch");
}
}
// request a message to retrieve a file
function getFile(wopi, req, res, userHost) {
let userAddress = req.docManager.curUserHostAddress(userHost);
let path = req.docManager.storagePath(wopi.id, userAddress);
res.setHeader("Content-Length", fileSystem.statSync(path).size);
res.setHeader("Content-Type", mime.getType(path));
res.setHeader("Content-Disposition", "attachment; filename*=UTF-8\'\'" + encodeURIComponent(wopi.id));
let filestream = fileSystem.createReadStream(path); // open a file as a readable stream
filestream.pipe(res); // retrieve data from file stream and output it to the response object
}
// request a message to update a file
function putFile(wopi, req, res, userHost) {
let requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()];
let userAddress = req.docManager.curUserHostAddress(userHost);
let storagePath = req.docManager.storagePath(wopi.id, userAddress);
if (!lockManager.hasLock(storagePath)) {
// ToDo: if body length is 0 bytes => handle document creation
// file isn't locked => mismatch
returnLockMismatch(res, "", "File isn't locked");
} else if (lockManager.getLock(storagePath) == requestLock) {
// lock matches current lock => put file
saveFileFromBody(req, wopi.id, userAddress, true, (err, version) => {
if (!err) {
res.setHeader(reqConsts.requestHeaders.ItemVersion, version); // set the X-WOPI-ItemVersion header
}
res.sendStatus(err ? 404 : 200);
});
} else {
// lock mismatch
returnLockMismatch(res, lockManager.getLock(storagePath), "Lock mismatch");
}
}
function putRelativeFile(wopi, req, res, userHost) {
let userAddress = req.docManager.curUserHostAddress(userHost);
let storagePath = req.docManager.storagePath(wopi.id, userAddress);
let filename = req.headers[reqConsts.requestHeaders.RelativeTarget.toLowerCase()]; // we cannot modify this filename
if (filename) {
if (req.docManager.existsSync(storagePath)) { // check if already exists
let overwrite = req.headers[reqConsts.requestHeaders.OverwriteRelativeTarget.toLowerCase()]; // overwrite header
if (overwrite && overwrite === "true") { // check if we can overwrite
if (lockManager.hasLock(storagePath)) { // check if file locked
returnValidRelativeTarget(res, req.docManager.getCorrectName(wopi.id, userAddress)); // file is locked, cannot overwrite
return;
}
} else {
returnValidRelativeTarget(res, req.docManager.getCorrectName(wopi.id, userAddress)); // file exists and overwrite header is false
return;
}
}
} else {
filename = req.headers[reqConsts.requestHeaders.SuggestedTarget.toLowerCase()]; // we can modify this filename
if (filename.startsWith(".")) { // check if extension
filename = fileUtility.getFileName(wopi.id, true) + filename; // get original filename with new extension
}
filename = req.docManager.getCorrectName(filename, userAddress); // get correct filename if already exists
}
let isConverted = req.headers[reqConsts.requestHeaders.FileConversion.toLowerCase()];
console.log("putRelativeFile after conversation: " + isConverted);
// if we got here, then we can save a file
saveFileFromBody(req, filename, userAddress, false, (err) => {
if (err) {
res.sendStatus(404);
return;
}
let serverUrl = req.docManager.getServerUrl(true);
let fileActionUrl = serverUrl + "/wopi-action/" + filename + "?action=";
let fileInfo = {
"Name": filename,
"Url": serverUrl + "/wopi/files/" + filename,
"HostViewUrl": fileActionUrl + "view",
"HostEditNewUrl": fileActionUrl + "editnew",
"HostEditUrl": fileActionUrl + "edit",
};
res.status(200).send(fileInfo);
});
}
// return information about the file properties, access rights and editor settings
function checkFileInfo(wopi, req, res, userHost) {
let userAddress = req.docManager.curUserHostAddress(userHost);
let version = req.docManager.getKey(wopi.id, userAddress);
let path = req.docManager.storagePath(wopi.id, userAddress);
// add wopi query
var query = new URLSearchParams(wopi.accessToken);
let user = users.getUser(query.get("userid"));
// create the file information object
let fileInfo = {
"BaseFileName": wopi.id,
"OwnerId": req.docManager.getFileData(wopi.id, userAddress)[1],
"Size": fileSystem.statSync(path).size,
"UserId": user.id,
"UserFriendlyName": user.name,
"Version": version,
"UserCanWrite": true,
"SupportsGetLock": true,
"SupportsLocks": true,
"SupportsUpdate": true,
};
res.status(200).send(fileInfo);
}
function saveFileFromBody(req, filename, userAddress, isNewVersion, callback) {
if (req.body) {
var storagePath = req.docManager.storagePath(filename, userAddress);
var historyPath = req.docManager.historyPath(filename, userAddress); // get the path to the file history
if (historyPath == "") { // if it is empty
historyPath = req.docManager.historyPath(filename, userAddress, true); // create it
req.docManager.createDirectory(historyPath); // and create a new directory for the history
}
var version = 0;
if (isNewVersion) {
var count_version = req.docManager.countVersion(historyPath); // get the last file version
version = count_version + 1; // get a number of a new file version
var versionPath = req.docManager.versionPath(filename, userAddress, version); // get the path to the specified file version
req.docManager.createDirectory(versionPath); // and create a new directory for the specified version
var path_prev = path.join(versionPath, "prev" + fileUtility.getFileExtension(filename)); // get the path to the previous file version
fileSystem.renameSync(storagePath, path_prev); // synchronously rename the given file as the previous file version
}
let filestream = fileSystem.createWriteStream(storagePath);
req.pipe(filestream);
req.on('end', () => {
filestream.close();
callback(null, version);
})
} else {
callback("empty body");
}
}
// return name that wopi-client can use as the value of X-WOPI-RelativeTarget in a future PutRelativeFile operation
function returnValidRelativeTarget(res, filename) {
res.setHeader(reqConsts.requestHeaders.ValidRelativeTarget, filename); // set the X-WOPI-ValidRelativeTarget header
res.sendStatus(409); // file with that name already exists
}
// return lock mismatch
function returnLockMismatch(res, lock, reason) {
res.setHeader(reqConsts.requestHeaders.Lock, lock || ""); // set the X-WOPI-Lock header
if (reason) { // if there is a reason for lock mismatch
res.setHeader(reqConsts.requestHeaders.LockFailureReason, reason); // set it as the X-WOPI-LockFailureReason header
}
res.sendStatus(409); // conflict
}
exports.fileRequestHandler = (req, res) => {
let userAddress = null;
req.docManager = new docManager(req, res);
if (req.params['id'].includes("@")) { // if there is the "@" sign in the id parameter
let split = req.params['id'].split("@"); // split this parameter by "@"
req.params['id'] = split[0]; // rewrite id with the first part of the split parameter
userAddress = split[1]; // save the second part as the user address
}
let userAddress = null;
req.DocManager = new DocManager(req, res);
if (req.params.id.includes('@')) { // if there is the "@" sign in the id parameter
const split = req.params.id.split('@'); // split this parameter by "@"
[req.params.id] = split; // rewrite id with the first part of the split parameter
[, userAddress] = split; // save the second part as the user address
}
let wopiData = parseWopiRequest(req); // get the wopi data
const wopiData = parseWopiRequest(req); // get the wopi data
// an error of the unknown request type
if (wopiData.requestType == reqConsts.requestType.None) {
res.status(500).send({ 'title': 'fileHandler', 'method': req.method, 'id': req.params['id'], 'error': "unknown" });
return;
}
// an error of the unknown request type
if (wopiData.requestType === reqConsts.requestType.None) {
res.status(500).send({
title: 'fileHandler', method: req.method, id: req.params.id, error: 'unknown',
});
return;
}
// an error of the unsupported request type
let action = actionMapping[wopiData.requestType];
if (!action) {
res.status(501).send({ 'title': 'fileHandler', 'method': req.method, 'id': req.params['id'], 'error': "unsupported" });
return;
}
// an error of the unsupported request type
const action = actionMapping[wopiData.requestType];
if (!action) {
res.status(501).send({
title: 'fileHandler', method: req.method, id: req.params.id, error: 'unsupported',
});
return;
}
action(wopiData, req, res, userAddress);
}
action(wopiData, req, res, userAddress);
};

View File

@ -16,54 +16,54 @@
*
*/
var lockDict = {};
const lockDict = {};
// get the lock object of the specified file
function getLockObject(filePath) {
return lockDict[filePath];
}
const getLockObject = function getLockObject(filePath) {
return lockDict[filePath];
};
// clear the lock timeout
function clearLockTimeout(lockObject) {
if (lockObject && lockObject.timeout) {
clearTimeout(lockObject.timeout);
}
}
const clearLockTimeout = function clearLockTimeout(lockObject) {
if (lockObject && lockObject.timeout) {
clearTimeout(lockObject.timeout);
}
};
// get the lock value of the specified file
function getLockValue(filePath) {
let lock = getLockObject(filePath); // get the lock object of the specified file
if (lock) return lock.value; // if it exists, get the lock value from it
return "";
}
const getLockValue = function getLockValue(filePath) {
const lock = getLockObject(filePath); // get the lock object of the specified file
if (lock) return lock.value; // if it exists, get the lock value from it
return '';
};
// check if the specified file path has lock or not
function hasLock(filePath) {
return !!getLockObject(filePath);
}
// lock file editing
function lock(filePath, lockValue) {
let oldLock = getLockObject(filePath); // get the old lock of the specified file
clearLockTimeout(oldLock); // clear its timeout
// create a new lock object
lockDict[filePath] = {
value: lockValue,
timeout: setTimeout(unlock, 1000 * 60 * 30, filePath) // set lock for 30 minutes
}
}
const hasLock = function hasLock(filePath) {
return !!getLockObject(filePath);
};
// allow for file editing
function unlock(filePath) {
let lock = getLockObject(filePath); // get the lock of the specified file
clearLockTimeout(lock); // clear its timeout
delete lockDict[filePath]; // delete the lock
}
const unlock = function unlock(filePath) {
const lock = getLockObject(filePath); // get the lock of the specified file
clearLockTimeout(lock); // clear its timeout
delete lockDict[filePath]; // delete the lock
};
// lock file editing
const lock = function lock(filePath, lockValue) {
const oldLock = getLockObject(filePath); // get the old lock of the specified file
clearLockTimeout(oldLock); // clear its timeout
// create a new lock object
lockDict[filePath] = {
value: lockValue,
timeout: setTimeout(unlock, 1000 * 60 * 30, filePath), // set lock for 30 minutes
};
};
module.exports = {
hasLock: hasLock,
getLock: getLockValue,
lock: lock,
unlock: unlock
}
hasLock,
getLock: getLockValue,
lock,
unlock,
};

View File

@ -18,55 +18,55 @@
// request types
const requestType = Object.freeze({
"None": 0,
None: 0,
"CheckFileInfo": 1,
"PutRelativeFile": 2,
CheckFileInfo: 1,
PutRelativeFile: 2,
"Lock": 3,
"GetLock": 4,
"Unlock": 5,
"RefreshLock": 6,
"UnlockAndRelock": 7,
Lock: 3,
GetLock: 4,
Unlock: 5,
RefreshLock: 6,
UnlockAndRelock: 7,
"ExecuteCobaltRequest": 8,
ExecuteCobaltRequest: 8,
"DeleteFile": 9,
"ReadSecureStore": 10,
"GetRestrictedLink": 11,
"RevokeRestrictedLink": 12,
DeleteFile: 9,
ReadSecureStore: 10,
GetRestrictedLink: 11,
RevokeRestrictedLink: 12,
"CheckFolderInfo": 13,
CheckFolderInfo: 13,
"GetFile": 14,
"PutFile": 16,
GetFile: 14,
PutFile: 16,
"EnumerateChildren": 16,
EnumerateChildren: 16,
"RenameFile": 17,
"PutUserInfo": 18,
RenameFile: 17,
PutUserInfo: 18,
});
// request headers
const requestHeaders = Object.freeze({
"RequestType": "X-WOPI-Override",
"ItemVersion": "X-WOPI-ItemVersion",
RequestType: 'X-WOPI-Override',
ItemVersion: 'X-WOPI-ItemVersion',
"Lock": "X-WOPI-Lock",
"OldLock": "X-WOPI-OldLock",
"LockFailureReason": "X-WOPI-LockFailureReason",
"LockedByOtherInterface": "X-WOPI-LockedByOtherInterface",
Lock: 'X-WOPI-Lock',
OldLock: 'X-WOPI-OldLock',
LockFailureReason: 'X-WOPI-LockFailureReason',
LockedByOtherInterface: 'X-WOPI-LockedByOtherInterface',
"FileConversion": "X-WOPI-FileConversion",
FileConversion: 'X-WOPI-FileConversion',
"SuggestedTarget": "X-WOPI-SuggestedTarget",
"RelativeTarget": "X-WOPI-RelativeTarget",
"OverwriteRelativeTarget": "X-WOPI-OverwriteRelativeTarget",
SuggestedTarget: 'X-WOPI-SuggestedTarget',
RelativeTarget: 'X-WOPI-RelativeTarget',
OverwriteRelativeTarget: 'X-WOPI-OverwriteRelativeTarget',
"ValidRelativeTarget": "X-WOPI-ValidRelativeTarget",
ValidRelativeTarget: 'X-WOPI-ValidRelativeTarget',
});
module.exports = {
requestType: requestType,
requestHeaders: requestHeaders,
}
requestType,
requestHeaders,
};

View File

@ -16,8 +16,4 @@
*
*/
exports.isValidToken = (req, res, next) => {
if (true) {
return next();
}
}
exports.isValidToken = (req, res, next) => next();

View File

@ -16,129 +16,139 @@
*
*/
const config = require("config");
const configServer = config.get("server");
var urlModule = require("url");
var urllib = require("urllib");
const xmlParser = require("fast-xml-parser");
const he = require("he");
const siteUrl = configServer.get("siteUrl"); // the path to the editors installation
const config = require('config');
const urlModule = require('url');
const urllib = require('urllib');
const xmlParser = require('fast-xml-parser');
const he = require('he');
var cache = null;
const configServer = config.get('server');
const siteUrl = configServer.get('siteUrl'); // the path to the editors installation
async function initWopi(docManager) {
let absSiteUrl = siteUrl;
if (absSiteUrl.indexOf("/") === 0) {
absSiteUrl = docManager.getServerHost() + siteUrl;
}
let cache = null;
// get the wopi discovery information
await getDiscoveryInfo(absSiteUrl);
}
const requestDiscovery = async function requestDiscovery(url) {
// eslint-disable-next-line no-unused-vars
return new Promise((resolve, reject) => {
const actions = [];
urllib.request(urlModule.parse(url + configServer.get('wopi.discovery')), { method: 'GET' }, (err, data) => {
if (data) {
// create the discovery XML file with the parameters from the response
const discovery = xmlParser.parse(data.toString(), {
attributeNamePrefix: '',
ignoreAttributes: false,
parseAttributeValue: true,
// eslint-disable-next-line no-unused-vars
attrValueProcessor: (val, attrName) => he.decode(val, { isAttributeValue: true }),
});
if (discovery['wopi-discovery']) {
discovery['wopi-discovery']['net-zone'].app.forEach((app) => {
let appAction = app.action;
if (!Array.isArray(appAction)) {
appAction = [appAction];
}
appAction.forEach((action) => {
actions.push({ // write all the parameters to the actions element
app: app.name,
favIconUrl: app.favIconUrl,
checkLicense: app.checkLicense === 'true',
name: action.name,
ext: action.ext || '',
progid: action.progid || '',
isDefault: !!action.default,
urlsrc: action.urlsrc,
requires: action.requires || '',
});
});
});
}
}
resolve(actions);
});
});
};
// get the wopi discovery information
async function getDiscoveryInfo(siteUrl) {
let actions = [];
const getDiscoveryInfo = async function getDiscoveryInfo(url) {
let actions = [];
if (cache) return cache;
try {
actions = await requestDiscovery(siteUrl);
} catch (e) {
return actions;
}
cache = actions;
setTimeout(() => cache = null, 1000 * 60 * 60); // 1 hour
if (cache) return cache;
try {
actions = await requestDiscovery(url);
} catch (e) {
return actions;
}
}
async function requestDiscovery(siteUrl) {
return new Promise((resolve, reject) => {
var actions = [];
urllib.request(urlModule.parse(siteUrl + configServer.get("wopi.discovery")), {method: "GET"}, (err, data) => {
if (data) {
let discovery = xmlParser.parse(data.toString(), { // create the discovery XML file with the parameters from the response
attributeNamePrefix: "",
ignoreAttributes: false,
parseAttributeValue: true,
attrValueProcessor: (val, attrName) => he.decode(val, {isAttributeValue: true})
});
if (discovery["wopi-discovery"]) {
for (let app of discovery["wopi-discovery"]["net-zone"].app) {
if (!Array.isArray(app.action)) {
app.action = [app.action];
}
for (let action of app.action) {
actions.push({ // write all the parameters to the actions element
app: app.name,
favIconUrl: app.favIconUrl,
checkLicense: app.checkLicense == 'true',
name: action.name,
ext: action.ext || "",
progid: action.progid || "",
isDefault: action.default ? true : false,
urlsrc: action.urlsrc,
requires: action.requires || ""
});
}
}
}
}
resolve(actions);
});
})
}
cache = actions;
setTimeout(() => {
cache = null;
return cache;
}, 1000 * 60 * 60); // 1 hour
return actions;
};
const initWopi = async function initWopi(DocManager) {
let absSiteUrl = siteUrl;
if (absSiteUrl.indexOf('/') === 0) {
absSiteUrl = DocManager.getServerHost() + siteUrl;
}
// get the wopi discovery information
await getDiscoveryInfo(absSiteUrl);
};
// get actions of the specified extension
async function getActions(ext) {
let actions = await getDiscoveryInfo(); // get the wopi discovery information
let filtered = [];
const getActions = async function getActions(ext) {
const actions = await getDiscoveryInfo(); // get the wopi discovery information
const filtered = [];
for (let action of actions) { // and filter it by the specified extention
if (action.ext == ext) {
filtered.push(action);
}
actions.forEach((action) => { // and filter it by the specified extention
if (action.ext === ext) {
filtered.push(action);
}
});
return filtered;
}
return filtered;
};
// get an action for the specified extension and name
async function getAction(ext, name) {
let actions = await getDiscoveryInfo();
const getAction = async function getAction(ext, name) {
const actions = await getDiscoveryInfo();
let act = null;
for (let action of actions) {
if (action.ext == ext && action.name == name) {
return action;
}
actions.forEach((action) => {
if (action.ext === ext && action.name === name) {
act = action;
}
});
return null;
}
return act;
};
// get the default action for the specified extension
async function getDefaultAction(ext) {
let actions = await getDiscoveryInfo();
const getDefaultAction = async function getDefaultAction(ext) {
const actions = await getDiscoveryInfo();
let act = null;
for (let action of actions) {
if (action.ext == ext && action.isDefault) {
return action;
}
actions.forEach((action) => {
if (action.ext === ext && action.isDefault) {
act = action;
}
});
return null;
}
return act;
};
// get the action url
function getActionUrl(host, userAddress, action, filename) {
return action.urlsrc.replace(/<.*&>/g, "") + "WOPISrc=" + host + "/wopi/files/" + filename + "@" + userAddress;
}
const getActionUrl = function getActionUrl(host, userAddress, action, filename) {
return `${action.urlsrc.replace(/<.*&>/g, '')}WOPISrc=${host}/wopi/files/${filename}@${userAddress}`;
};
exports.initWopi = initWopi;
exports.getDiscoveryInfo = getDiscoveryInfo;
exports.getAction = getAction;
exports.getActions = getActions;
exports.getActionUrl = getActionUrl;
exports.getDefaultAction = getDefaultAction;
exports.getDefaultAction = getDefaultAction;

View File

@ -16,157 +16,160 @@
*
*/
const tokenValidator = require("./tokenValidator");
const filesController = require("./filesController");
const utils = require("./utils");
const docManager = require("../docManager");
const fileUtility = require("../fileUtility");
const config = require('config');
const tokenValidator = require('./tokenValidator');
const filesController = require('./filesController');
const utils = require('./utils');
const DocManager = require('../docManager');
const fileUtility = require('../fileUtility');
const users = require('../users');
const configServer = config.get('server');
const siteUrl = configServer.get("siteUrl"); // the path to the editors installation
const users = require("../users");
const siteUrl = configServer.get('siteUrl'); // the path to the editors installation
getCustomWopiParams = function (query) {
let tokenParams = "";
let actionParams = "";
const getCustomWopiParams = function getCustomWopiParams(query) {
let tokenParams = '';
let actionParams = '';
const userid = query.userid; // user id
tokenParams += (userid ? "&userid=" + userid : "");
const { userid } = query; // user id
tokenParams += (userid ? `&userid=${userid}` : '');
const lang = query.lang; // language
actionParams += (lang ? "&ui=" + lang : "");
const { lang } = query; // language
actionParams += (lang ? `&ui=${lang}` : '');
return { "tokenParams": tokenParams, "actionParams": actionParams };
return { tokenParams, actionParams };
};
exports.registerRoutes = function(app) {
exports.registerRoutes = function registerRoutes(app) {
// define a handler for the default wopi page
app.get('/wopi', async (req, res) => {
req.DocManager = new DocManager(req, res);
// define a handler for the default wopi page
app.get("/wopi", async function(req, res) {
await utils.initWopi(req.DocManager);
req.docManager = new docManager(req, res);
// get the wopi discovery information
const actions = await utils.getDiscoveryInfo();
const wopiEnable = actions.length !== 0;
const docsExtEdit = []; // Supported extensions for WOPI
await utils.initWopi(req.docManager);
// get the wopi discovery information
let actions = await utils.getDiscoveryInfo();
let wopiEnable = actions.length != 0 ? true : false;
let docsExtEdit = []; // Supported extensions for WOPI
actions.forEach(el => {
if (el.name == "edit") docsExtEdit.push("."+el.ext);
});
let editedExts = configServer.get('editedDocs').filter(i => docsExtEdit.includes(i)); // Checking supported extensions
let fillExts = configServer.get("fillDocs").filter(i => docsExtEdit.includes(i));
try {
// get all the stored files
let files = req.docManager.getStoredFiles();
// run through all the files and write the corresponding information to each file
for (var file of files) {
let ext = fileUtility.getFileExtension(file.name, true); // get an extension of each file
file.actions = await utils.getActions(ext); // get actions of the specified extension
file.defaultAction = await utils.getDefaultAction(ext); // get the default action of the specified extension
}
// render wopiIndex template with the parameters specified
res.render("wopiIndex", {
wopiEnable : wopiEnable,
storedFiles: wopiEnable ? files : [],
params: req.docManager.getCustomParams(),
users: users,
serverUrl: req.docManager.getServerUrl(),
preloaderUrl: siteUrl + configServer.get('preloaderUrl'),
convertExts: configServer.get('convertedDocs'),
editedExts: editedExts,
fillExts: fillExts,
languages: configServer.get('languages'),
});
} catch (ex) {
console.log(ex); // display error message in the console
res.status(500); // write status parameter to the response
res.render("error", { message: "Server error" }); // render error template with the message parameter specified
return;
}
});
// define a handler for creating a new wopi editing session
app.get("/wopi-new", function(req, res) {
var fileExt = req.query.fileExt; // get the file extension from the request
req.docManager = new docManager(req, res);
if (fileExt != null) { // if the file extension exists
var fileName = req.docManager.getCorrectName("new." + fileExt)
var redirectPath = req.docManager.getServerUrl(true) + "/wopi-action/" + encodeURIComponent(fileName) + "?action=editnew" + req.docManager.getCustomParams(); // get the redirect path
res.redirect(redirectPath);
return;
}
});
// define a handler for getting wopi action information by its id
app.get("/wopi-action/:id", async function(req, res) {
try {
req.docManager = new docManager(req, res);
await utils.initWopi(req.docManager);
var fileName = req.docManager.getCorrectName(req.params['id'])
var fileExt = fileUtility.getFileExtension(fileName, true); // get the file extension from the request
var user = users.getUser(req.query.userid); // get a user by the id
// get an action for the specified extension and name
let action = await utils.getAction(fileExt, req.query["action"]);
if (action != null && req.query["action"] == "editnew") {
fileName = req.docManager.RequestEditnew(req, fileName, user);
}
// render wopiAction template with the parameters specified
res.render("wopiAction", {
actionUrl: utils.getActionUrl(req.docManager.getServerUrl(true), req.docManager.curUserHostAddress(), action, req.params['id']),
token: "test",
tokenTtl: Date.now() + 1000 * 60 * 60 * 10,
params: getCustomWopiParams(req.query),
});
} catch (ex) {
console.log(ex);
res.status(500);
res.render("error", { message: "Server error" });
return;
}
actions.forEach((el) => {
if (el.name === 'edit') docsExtEdit.push(`.${el.ext}`);
});
// define a handler for getting file information by its id
app.route('/wopi/files/:id')
.all(tokenValidator.isValidToken)
.get(filesController.fileRequestHandler)
.post(filesController.fileRequestHandler);
// Checking supported extensions
const editedExts = fileUtility.getEditExtensions().filter((i) => docsExtEdit.includes(i));
const fillExts = fileUtility.getFillExtensions().filter((i) => docsExtEdit.includes(i));
// define a handler for reading/writing the file contents
app.route('/wopi/files/:id/contents')
.all(tokenValidator.isValidToken)
.get(filesController.fileRequestHandler)
.post(filesController.fileRequestHandler);
try {
// get all the stored files
const files = req.DocManager.getStoredFiles();
// define a handler for getting folder information by its id
app.route('/wopi/folders/:id')
.all(tokenValidator.isValidToken)
.get(filesController.fileRequestHandler)
.post(filesController.fileRequestHandler);
// run through all the files and write the corresponding information to each file
// eslint-disable-next-line no-restricted-syntax
for (const file of files) {
const ext = fileUtility.getFileExtension(file.name, true); // get an extension of each file
// eslint-disable-next-line no-await-in-loop
file.actions = await utils.getActions(ext); // get actions of the specified extension
// eslint-disable-next-line no-await-in-loop
file.defaultAction = await utils.getDefaultAction(ext);// get the default action of the specified extension
}
// define a handler for reading/writing the folder contents
app.route('/wopi/folders/:id/contents')
.all(tokenValidator.isValidToken)
.get(filesController.fileRequestHandler)
.post(filesController.fileRequestHandler);
// render wopiIndex template with the parameters specified
res.render('wopiIndex', {
wopiEnable,
storedFiles: wopiEnable ? files : [],
params: req.DocManager.getCustomParams(),
users,
preloaderUrl: siteUrl + configServer.get('preloaderUrl'),
convertExts: fileUtility.getConvertExtensions(),
editedExts,
fillExts,
languages: configServer.get('languages'),
});
} catch (ex) {
console.log(ex); // display error message in the console
res.status(500); // write status parameter to the response
// render error template with the message parameter specified
res.render('error', { message: 'Server error' });
}
});
// define a handler for creating a new wopi editing session
app.get('/wopi-new', (req, res) => {
const { fileExt } = req.query; // get the file extension from the request
// define a handler for upload files
app.route('/wopi/upload')
.all(tokenValidator.isValidToken)
.get(filesController.fileRequestHandler)
.post(filesController.fileRequestHandler);
req.DocManager = new DocManager(req, res);
if (fileExt) { // if the file extension exists
const fileName = req.DocManager.getCorrectName(`new.${fileExt}`);
const redirectPath = `${req.DocManager.getServerUrl(true)}/wopi-action/`
+ `${encodeURIComponent(fileName)}?action=editnew${req.DocManager.getCustomParams()}`; // get the redirect path
res.redirect(redirectPath);
}
});
// define a handler for getting wopi action information by its id
app.get('/wopi-action/:id', async (req, res) => {
try {
req.DocManager = new DocManager(req, res);
await utils.initWopi(req.DocManager);
let fileName = req.DocManager.getCorrectName(req.params.id);
const fileExt = fileUtility.getFileExtension(fileName, true); // get the file extension from the request
const user = users.getUser(req.query.userid); // get a user by the id
// get an action for the specified extension and name
const action = await utils.getAction(fileExt, req.query.action);
if (action && req.query.action === 'editnew') {
fileName = req.DocManager.requestEditnew(req, fileName, user);
}
// render wopiAction template with the parameters specified
res.render('wopiAction', {
actionUrl: utils.getActionUrl(
req.DocManager.getServerUrl(true),
req.DocManager.curUserHostAddress(),
action,
req.params.id,
),
token: 'test',
tokenTtl: Date.now() + 1000 * 60 * 60 * 10,
params: getCustomWopiParams(req.query),
});
} catch (ex) {
console.log(ex);
res.status(500);
res.render('error', { message: 'Server error' });
}
});
// define a handler for getting file information by its id
app.route('/wopi/files/:id')
.all(tokenValidator.isValidToken)
.get(filesController.fileRequestHandler)
.post(filesController.fileRequestHandler);
// define a handler for reading/writing the file contents
app.route('/wopi/files/:id/contents')
.all(tokenValidator.isValidToken)
.get(filesController.fileRequestHandler)
.post(filesController.fileRequestHandler);
// define a handler for getting folder information by its id
app.route('/wopi/folders/:id')
.all(tokenValidator.isValidToken)
.get(filesController.fileRequestHandler)
.post(filesController.fileRequestHandler);
// define a handler for reading/writing the folder contents
app.route('/wopi/folders/:id/contents')
.all(tokenValidator.isValidToken)
.get(filesController.fileRequestHandler)
.post(filesController.fileRequestHandler);
// define a handler for upload files
app.route('/wopi/upload')
.all(tokenValidator.isValidToken)
.get(filesController.fileRequestHandler)
.post(filesController.fileRequestHandler);
};

View File

@ -20,13 +20,17 @@ express - Fast, unopinionated, minimalist web framework for node. (https:/
License: MIT
License File: express.license
fast-xml-parser - Validate XML, Parse XML to JS/JSON and vice versa, or parse XML to Nimn rapidly without C/C++ based libraries and no callback. (https://github.com/NaturalIntelligence/fast-xml-parser/blob/master/LICENSE)
License: MIT
License File: fast-xml-parser.license
formidable - A Node.js module for parsing form data, especially file uploads. (https://github.com/node-formidable/formidable/blob/master/LICENSE)
License: MIT
License File: formidable.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
he - a robust HTML entity encoder/decoder written in JavaScript. (https://github.com/mathiasbynens/he/blob/master/LICENSE-MIT.txt)
License: MIT
License File: jQuery.license
License File: he.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
@ -40,9 +44,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT

View File

@ -34,30 +34,17 @@ if (typeof jQuery != "undefined") {
else
language = jq("#language").val();
jq("#language").change(function() {
window.location = "?lang=" + jq(this).val() + "&userid=" + userid + "&directUrl=" + directUrl;
});
if ("" != userid && undefined != userid)
jq("#user").val(userid);
else
userid = jq("#user").val();
jq("#user").change(function() {
window.location = "?lang=" + language + "&userid=" + jq(this).val() + "&directUrl=" + directUrl;
});
if (directUrl)
jq("#directUrl").prop("checked", directUrl);
else
directUrl = jq("#directUrl").prop("checked");
jq("#directUrl").change(function() {
window.location = "?lang=" + language + "&userid=" + userid + "&directUrl=" + jq(this).prop("checked");
});
jq(function () {
jq('#fileupload').fileupload({
@ -111,7 +98,7 @@ if (typeof jQuery != "undefined") {
}
});
});
var timer = null;
var checkConvert = function (filePass) {
filePass = filePass ? filePass : null;
@ -126,7 +113,7 @@ if (typeof jQuery != "undefined") {
jq("#filePass").val("");
var fileName = jq("#hiddenFileName").val();
var posExt = fileName.lastIndexOf('.');
var posExt = fileName.lastIndexOf('.') + 1;
posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : '';
if (ConverExtList.indexOf(posExt) == -1) {
@ -207,7 +194,7 @@ if (typeof jQuery != "undefined") {
jq("#beginView, #beginEmbedded").removeClass("disable");
var fileName = jq("#hiddenFileName").val();
var posExt = fileName.lastIndexOf('.');
var posExt = fileName.lastIndexOf('.') + 1;
posExt = 0 <= posExt ? fileName.substring(posExt).trim().toLowerCase() : '';
var checkEdited = EditedExtList.split(",").filter(function(ext) { return ext == posExt;});
@ -230,6 +217,20 @@ if (typeof jQuery != "undefined") {
}
});
jq(document).on("click", ".action-link", function (e) {
e.preventDefault();
let url = this.href + collectParams(true);
let target = null;
if (e.target.hasAttribute("target")) {
target = e.target.getAttribute("target");
} else if (e.target.parentNode.hasAttribute("target")) {
target = e.target.parentNode.getAttribute("target");
}
target !== null ? window.open(url, target) : window.location = url;
});
jq(document).on("click", "#skipPass", function () {
jq("#blockPassword").hide();
loadScripts();
@ -238,32 +239,32 @@ if (typeof jQuery != "undefined") {
jq(document).on("click", "#beginEdit:not(.disable)", function () {
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
if (UrlEditor == "wopi-action"){
var url = UrlEditor + "/" + fileId + "?action=edit";
var url = UrlEditor + "/" + fileId + "?action=edit" + collectParams(true);
}else{
var url = UrlEditor + "?fileName=" + fileId + "&lang=" + language + "&userid=" + userid + "&directUrl=" + directUrl;
var url = UrlEditor + "?fileName=" + fileId + collectParams(true);
}
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
document.location.reload(true);
window.location = collectParams();
});
jq(document).on("click", "#beginView:not(.disable)", function () {
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
if (UrlEditor == "wopi-action"){
var url = UrlEditor + "/" + fileId + "?action=view";
var url = UrlEditor + "/" + fileId + "?action=view" + collectParams(true);
}else{
var url = UrlEditor + "?mode=view&fileName=" + fileId + "&lang=" + language + "&userid=" + userid + "&directUrl=" + directUrl;
var url = UrlEditor + "?mode=view&fileName=" + fileId + collectParams(true);
}
window.open(url, "_blank");
jq('#hiddenFileName').val("");
jq.unblockUI();
document.location.reload(true);
window.location = collectParams();
});
jq(document).on("click", "#beginEmbedded:not(.disable)", function () {
var fileId = encodeURIComponent(jq('#hiddenFileName').val());
var url = UrlEditor + "?type=embedded&fileName=" + fileId + "&lang=" + language + "&userid=" + userid + "&directUrl=" + directUrl;
var url = UrlEditor + "?type=embedded&fileName=" + fileId + collectParams(true);
jq("#mainProgress").addClass("embedded");
jq("#beginEmbedded").addClass("disable");
@ -272,13 +273,13 @@ if (typeof jQuery != "undefined") {
});
jq(document).on("click", ".reload-page", function () {
setTimeout(function () { document.location.reload(true); }, 1000);
setTimeout(function () { window.location = collectParams(); }, 1000);
return true;
});
jq(document).on("mouseup", ".reload-page", function (event) {
if (event.which == 2) {
setTimeout(function () { document.location.reload(true); }, 1000);
setTimeout(function () { window.location = collectParams(); }, 1000);
}
return true;
});
@ -288,12 +289,13 @@ if (typeof jQuery != "undefined") {
jq("#embeddedView").remove();
jq.unblockUI();
if (mustReload) {
document.location.reload(true);
window.location = collectParams();
}
});
jq(document).on("click", ".delete-file", function () {
var fileName = jq(this).attr("data");
const currentElement = jq(this);
var fileName = currentElement.attr("data");
var requestAddress = "file?filename=" + fileName;
@ -303,7 +305,16 @@ if (typeof jQuery != "undefined") {
type: "delete",
url: requestAddress,
complete: function (data) {
document.location.reload(true);
if (JSON.parse(data.responseText).success) {
const parentRow = currentElement.parents('tr')[0];
if (parentRow) {
jq(parentRow).remove();
}
const remainingRows = jq('tr.tableRow');
if (remainingRows.length === 0) {
window.location = collectParams();
}
}
}
});
});
@ -394,4 +405,32 @@ function getUrlVars() {
vars[hash[0]] = hash[1];
}
return vars;
};
};
function collectParams(startParams) {
let paramsObjects = Array.prototype.slice.call(document.getElementsByClassName('collectable'));
let params = [];
let startChar = startParams ? "&" : "?";
paramsObjects.forEach( function (element) {
if (element.name) {
switch (element.type) {
case "select-one":
case "text":
if (element.value) {
params.push(element.name + "=" + element.value);
}
break;
case "checkbox":
params.push(element.name + "=" + element.checked);
break;
case "radio":
if (element.checked) {
params.push(element.name + "=" + element.value);
}
break;
default:
}
}
});
return startChar + params.join("&");
}

View File

@ -39,6 +39,7 @@
var docEditor;
var config;
let historyObject;
var innerAlert = function (message, inEditor) {
if (console && console.log)
@ -72,26 +73,72 @@
};
var onRequestHistory = function (event) { // the user is trying to show the document version history
var historyObj = <%- JSON.stringify(history) %> || null;
docEditor.refreshHistory( // show the document version history
const fileName = "<%- file.name %>" || null;
const directUrl = "<%- file.directUrl %>" || null;
const data = {
fileName: fileName,
directUrl: directUrl
};
let xhr = new XMLHttpRequest();
xhr.open("POST", "historyObj");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(data));
xhr.onload = function () {
historyObject = JSON.parse(xhr.responseText);
docEditor.refreshHistory( // show the document version history
{
currentVersion: "<%- file.version %>",
history: historyObj
currentVersion: historyObject.countVersion,
history: historyObject.history
});
}
};
var onRequestHistoryData = function (data) { // the user is trying to click the specific document version in the document version history
var version = data.data;
var historyData = <%- JSON.stringify(historyData) %> || null;
docEditor.setHistoryData(historyData[version-1]); // send the link to the document for viewing the version history
var onRequestHistoryData = function (event) { // the user is trying to click the specific document version in the document version history
const version = event.data;
docEditor.setHistoryData(historyObject.historyData[version-1]); // send the link to the document for viewing the version history
};
var onRequestHistoryClose = function (event){ // the user is trying to go back to the document from viewing the document version history
document.location.reload();
};
var onRequestRestore = function (event) { // the user is trying to restore file version
const version = event.data.version;
const fileName = "<%- file.name %>" || null;
const directUrl = "<%- file.directUrl %>" || null;
const restoreData = {
version: version,
fileName: fileName,
};
let xhr = new XMLHttpRequest();
xhr.open("PUT", "restore");
xhr.setRequestHeader('Content-Type', 'application/json');
xhr.send(JSON.stringify(restoreData));
xhr.onload = function () {
const response = JSON.parse(xhr.responseText);
if (response.success && !response.error) {
const dataForHistory = {
fileName: fileName,
directUrl: directUrl
};
let xhr = new XMLHttpRequest();
xhr.open("POST", "historyObj");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(JSON.stringify(dataForHistory));
xhr.onload = function () {
historyObject = JSON.parse(xhr.responseText);
docEditor.refreshHistory( // show the document version history
{
currentVersion: historyObject.countVersion,
history: historyObject.history
});
}
} else {
innerAlert(response.error);
}
}
}
var onError = function (event) { // an error or some other specific event occurs
if (event)
innerAlert(event.data);
@ -235,6 +282,7 @@
config.events.onRequestHistory = onRequestHistory;
config.events.onRequestHistoryData = onRequestHistoryData;
config.events.onRequestHistoryClose = onRequestHistoryClose;
config.events.onRequestRestore = onRequestRestore;
config.events.onRequestRename = onRequestRename;
config.events.onRequestUsers = onRequestUsers;
config.events.onRequestSendNotify = onRequestSendNotify;

View File

@ -32,7 +32,7 @@
<body>
<header>
<div class="center">
<a href="">
<a href="./">
<img src ="images/logo.svg" alt="ONLYOFFICE" />
</a>
</div>
@ -48,16 +48,16 @@
<div class="create-panel clearFix">
<ul class="try-editor-list clearFix">
<li>
<a class="try-editor word reload-page" target="_blank" href="editor?fileExt=docx<%= params %>" title="Create new document">Document</a>
<a class="try-editor word reload-page action-link" target="_blank" href="editor?fileExt=docx" title="Create new document">Document</a>
</li>
<li>
<a class="try-editor cell reload-page" target="_blank" href="editor?fileExt=xlsx<%= params %>" title="Create new spreadsheet">Spreadsheet</a>
<a class="try-editor cell reload-page action-link" target="_blank" href="editor?fileExt=xlsx" title="Create new spreadsheet">Spreadsheet</a>
</li>
<li>
<a class="try-editor slide reload-page" target="_blank" href="editor?fileExt=pptx<%= params %>" title="Create new presentation">Presentation</a>
<a class="try-editor slide reload-page action-link" target="_blank" href="editor?fileExt=pptx" title="Create new presentation">Presentation</a>
</li>
<li>
<a class="try-editor form reload-page" target="_blank" href="editor?fileExt=docxf<%= params %>" title="Create new form template">Form template</a>
<a class="try-editor form reload-page action-link" target="_blank" href="editor?fileExt=docxf" title="Create new form template">Form template</a>
</li>
</ul>
<label class="side-option">
@ -67,7 +67,7 @@
<div class="upload-panel clearFix">
<a class="file-upload">Upload file
<input type="file" id="fileupload" name="uploadedFile" data-url="upload?<%= params %>" />
<input type="file" id="fileupload" name="uploadedFile" data-url="upload" />
</a>
</div>
@ -77,7 +77,7 @@
<td valign="middle">
<span class="select-user">Username</span>
<img id="info" class="info" src="images/info.svg" />
<select class="select-user" id="user">
<select class="select-user collectable" name="userid" id="user">
<% users.forEach(user => { %>
<option value="<%= user.id %>"><%= user.name == null ? "Anonymous" : user.name %></option>
<% }) %>
@ -88,7 +88,7 @@
<td valign="middle">
<span class="select-user">Language</span>
<img class="info info-tooltip" data-id="language" data-tooltip="Choose the language for ONLYOFFICE editors interface" src="images/info.svg" />
<select class="select-user" id="language">
<select class="select-user collectable" name="lang" id="language">
<% Object.keys(languages).forEach(key => { %>
<option value="<%= key %>"><%= languages[key] %></option>
<% }) %>
@ -98,7 +98,7 @@
<tr>
<td valign="middle">
<label class="side-option">
<input id="directUrl" type="checkbox" class="checkbox" />Try opening on client
<input id="directUrl" type="checkbox" class="checkbox collectable" name="directUrl" />Try opening on client
<img id="directUrlInfo" class="info info-tooltip" data-id="directUrlInfo" data-tooltip="Some files can be opened in the user's browser without connecting to the document server." src="images/info.svg" />
</label>
</td>
@ -107,7 +107,7 @@
</table>
<div class="links-panel links-panel-border clearFix">
<a href="<%= serverUrl %>/wopi" class="">Go to WOPI page</a>
<a href="wopi" class="">Go to WOPI page</a>
</div>
</div>
</div>
@ -154,33 +154,33 @@
<% for (var i = 0; i < storedFiles.length; i++) { %>
<tr class="tableRow" title="<%= storedFiles[i].name %> [<%= storedFiles[i].version %>]">
<td class="contentCells">
<a class="stored-edit <%= storedFiles[i].documentType %>" href="editor?fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="stored-edit <%= storedFiles[i].documentType %> action-link" href="editor?fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<span><%= storedFiles[i].name %></span>
</a>
</td>
<% if (storedFiles[i].canEdit) { %>
<td class="contentCells contentCells-icon">
<a href="editor?type=desktop&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=desktop&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/desktop.svg" alt="Open in editor for full size screens" title="Open in editor for full size screens" /></a>
</td>
<td class="contentCells contentCells-icon">
<a href="editor?type=desktop&mode=comment&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=desktop&mode=comment&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/comment.svg" alt="Open in editor for comment" title="Open in editor for comment" /></a>
</td>
<% if (storedFiles[i].documentType == "word") { %>
<td class="contentCells contentCells-icon">
<a href="editor?type=desktop&mode=review&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=desktop&mode=review&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/review.svg" alt="Open in editor for review" title="Open in editor for review" /></a>
</td>
<% } else if (storedFiles[i].documentType == "cell") { %>
<td class="contentCells contentCells-icon">
<a href="editor?type=desktop&mode=filter&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=desktop&mode=filter&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/filter.svg" alt="Open in editor without access to change the filter" title="Open in editor without access to change the filter" /></a>
</td>
<% } %>
<% if (storedFiles[i].documentType == "word") { %>
<td class="contentCells contentCells-icon">
<a href="editor?type=desktop&mode=blockcontent&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=desktop&mode=blockcontent&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/block-content.svg" alt="Open in editor without content control modification" title="Open in editor without content control modification" /></a>
</td>
<% } else { %>
@ -189,44 +189,44 @@
<% if (storedFiles[i].documentType !== "word" && storedFiles[i].documentType !== "cell") {%>
<td class="contentCells contentCells-icon "></td>
<% } %>
<% if (fillExts.indexOf(storedFiles[i].name.substring(storedFiles[i].name.lastIndexOf('.')).trim().toLowerCase()) !== -1) { %>
<% if (fillExts.indexOf(storedFiles[i].name.substring(storedFiles[i].name.lastIndexOf('.') + 1).trim().toLowerCase()) !== -1) { %>
<td class="contentCells contentCells-icon">
<a href="editor?type=desktop&mode=fillForms&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=desktop&mode=fillForms&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms" /></a>
</td>
<% } else {%>
<td class="contentCells contentCells-icon"></td>
<%}%>
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift">
<a href="editor?type=mobile&mode=edit&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=mobile&mode=edit&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/mobile.svg" alt="Open in editor for mobile devices" title="Open in editor for mobile devices" /></a>
</td>
<% } else if (fillExts.indexOf(storedFiles[i].name.substring(storedFiles[i].name.lastIndexOf('.')).trim().toLowerCase()) !== -1) { %>
<% } else if (fillExts.indexOf(storedFiles[i].name.substring(storedFiles[i].name.lastIndexOf('.') + 1).trim().toLowerCase()) !== -1) { %>
<td class="contentCells contentCells-icon "></td>
<td class="contentCells contentCells-icon "></td>
<td class="contentCells contentCells-icon "></td>
<td class="contentCells contentCells-icon "></td>
<td class="contentCells contentCells-icon">
<a href="editor?type=desktop&mode=fillForms&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=desktop&mode=fillForms&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/fill-forms.svg" alt="Open in editor for filling in forms" title="Open in editor for filling in forms" /></a>
</td>
<td class="contentCells contentCells-shift contentCells-icon firstContentCellShift">
<a href="editor?type=mobile&mode=fillForms&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=mobile&mode=fillForms&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/mobile-fill-forms.svg" alt="Open in editor for filling in forms for mobile devices" title="Open in editor for filling in forms for mobile devices" /></a>
</td>
<% } else { %>
<td class="contentCells contentCells-shift contentCells-icon contentCellsEmpty" colspan="6"></td>
<% } %>
<td class="contentCells contentCells-icon firstContentCellViewers">
<a href="editor?type=desktop&mode=view&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=desktop&mode=view&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/desktop.svg" alt="Open in viewer for full size screens" title="Open in viewer for full size screens" /></a>
</td>
<td class="contentCells contentCells-icon">
<a href="editor?type=mobile&mode=view&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=mobile&mode=view&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/mobile.svg" alt="Open in viewer for mobile devices" title="Open in viewer for mobile devices" /></a>
</td>
<td class="contentCells contentCells-icon contentCells-shift">
<a href="editor?type=embedded&mode=embedded&fileName=<%= encodeURIComponent(storedFiles[i].name) + params %>" target="_blank">
<a class="action-link" href="editor?type=embedded&mode=embedded&fileName=<%= encodeURIComponent(storedFiles[i].name) %>" target="_blank">
<img src="images/embeded.svg" alt="Open in embedded mode" title="Open in embedded mode" /></a>
</td>
<td class="contentCells contentCells-icon contentCells-shift downloadContentCellShift">

View File

@ -35,7 +35,7 @@
<body>
<header>
<div class="center">
<a href="">
<a href="wopi">
<img src="images/logo.svg" alt="ONLYOFFICE" />
</a>
</div>
@ -51,16 +51,16 @@
<div class="create-panel clearFix">
<ul class="try-editor-list clearFix">
<li>
<a class="try-editor word reload-page" target="_blank" href="<%= serverUrl %>/wopi-new?fileExt=docx<%= params %>" title="Create new document">Document</a>
<a class="try-editor word reload-page action-link" target="_blank" href="wopi-new?fileExt=docx" title="Create new document">Document</a>
</li>
<li>
<a class="try-editor cell reload-page" target="_blank" href="<%= serverUrl %>/wopi-new?fileExt=xlsx<%= params %>" title="Create new spreadsheet">Spreadsheet</a>
<a class="try-editor cell reload-page action-link" target="_blank" href="wopi-new?fileExt=xlsx" title="Create new spreadsheet">Spreadsheet</a>
</li>
<li>
<a class="try-editor slide reload-page" target="_blank" href="<%= serverUrl %>/wopi-new?fileExt=pptx<%= params %>" title="Create new presentation">Presentation</a>
<a class="try-editor slide reload-page action-link" target="_blank" href="wopi-new?fileExt=pptx" title="Create new presentation">Presentation</a>
</li>
<li>
<a class="try-editor form reload-page" target="_blank" href="<%= serverUrl %>/wopi-new?fileExt=docxf<%= params %>" title="Create new form template">Form template</a>
<a class="try-editor form reload-page action-link" target="_blank" href="wopi-new?fileExt=docxf" title="Create new form template">Form template</a>
</li>
</ul>
</div>
@ -68,7 +68,7 @@
<div class="upload-panel clearFix">
<a class="file-upload">Upload file
<input type="file" id="fileupload" name="uploadedFile" data-url="upload?<%= params %>" />
<input type="file" id="fileupload" name="uploadedFile" data-url="upload" />
</a>
</div>
@ -78,7 +78,7 @@
<td valign="middle">
<span class="select-user">Username</span>
<img id="info" class="info" data-id="user" src="images/info.svg" />
<select class="select-user" id="user">
<select class="select-user collectable" name="userid" id="user">
<% users.forEach(user => { %>
<option value="<%= user.id %>"><%= user.name == null ? "Anonymous" : user.name %></option>
<% }) %>
@ -89,7 +89,7 @@
<td valign="middle">
<span class="select-user">Language</span>
<img class="info info-tooltip" data-id="language" data-tooltip="Choose the language for ONLYOFFICE editors interface" src="images/info.svg" />
<select class="select-user" id="language">
<select class="select-user collectable" name="lang" id="language">
<% Object.keys(languages).forEach(key => { %>
<option value="<%= key %>"><%= languages[key] %></option>
<% }) %>
@ -100,7 +100,7 @@
</table>
<div class="links-panel links-panel-border clearFix">
<a href="<%= serverUrl %>/" class="">Go to Index page</a>
<a href="./" class="">Go to Index page</a>
</div>
</div>
</td>
@ -148,7 +148,7 @@
<tr class="tableRow" title="<%= storedFiles[i].name %> [<%= storedFiles[i].version %>]">
<td class="contentCells">
<% if (storedFiles[i].defaultAction) { %>
<a class="stored-edit <%= storedFiles[i].documentType %>" href="<%= serverUrl %>/wopi-action/<%= encodeURIComponent(storedFiles[i].name) %>?action=<%= storedFiles[i].defaultAction.name %><%= params %>" target="_blank">
<a class="stored-edit <%= storedFiles[i].documentType %> action-link" href="wopi-action/<%= encodeURIComponent(storedFiles[i].name) %>?action=<%= storedFiles[i].defaultAction.name %>" target="_blank">
<%} else { %>
<a class="stored-edit <%= storedFiles[i].documentType %>" href="#">
<% } %>
@ -158,7 +158,7 @@
<% if (storedFiles[i].actions && storedFiles[i].actions.length > 0) { %>
<td class="contentCells contentCells-wopi contentCells-shift">
<% for (var j = 0; j < storedFiles[i].actions.length; j++) { %>
<a href="<%= serverUrl %>/wopi-action/<%= encodeURIComponent(storedFiles[i].name) %>?action=<%= storedFiles[i].actions[j].name %><%= params %>" target="_blank">
<a class="action-link" href="wopi-action/<%= encodeURIComponent(storedFiles[i].name) %>?action=<%= storedFiles[i].actions[j].name %>" target="_blank">
<img
src="images/wopi-<%= storedFiles[i].actions[j].name %>.svg"
alt="<%= storedFiles[i].actions[j].name %>" title="<%= storedFiles[i].actions[j].name %>" />
@ -167,7 +167,7 @@
</td>
<% } %>
<td class="contentCells contentCells-icon contentCells-shift downloadContentCells">
<a href="<%= serverUrl %>/wopi/files/<%= encodeURIComponent(storedFiles[i].name) %>/contents">
<a href="wopi/files/<%= encodeURIComponent(storedFiles[i].name) %>/contents">
<img class="icon-download" src="images/download.svg" alt="Download" title="Download" /></a>
</td>
<td class="contentCells contentCells-icon contentCells-shift">

View File

@ -1,9 +1,5 @@
ONLYOFFICE Applications example uses code from the following 3rd party projects:
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -16,9 +12,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT

View File

@ -34,6 +34,7 @@ You can use any web server capable of running PHP code to run the example. We wi
* **IIS**: version 7 or later (refer to [Microsoft official website](https://www.iis.net/learn/application-frameworks/scenario-build-a-php-website-on-iis/configuring-step-1-install-iis-and-php) to learn how to install IIS);
* **PHP** (download it from the [http://php.net](https://php.net/downloads.php) site);
* **PHP Manager for IIS** (download it from the [Microsoft open source site](https://phpmanager.codeplex.com/releases/view/69115)).
* **Composer** (download it from the [Composer official website](https://getcomposer.org/download/)).
### Step 4. IIS configuration
@ -78,7 +79,13 @@ You can use any web server capable of running PHP code to run the example. We wi
After IIS manager configuration is complete, everything is ready for running the PHP example.
### Step 5. Run your website with the editors
### Step 5. Run *composer install*:
```
php composer.phar install
```
### Step 6. Run your website with the editors
1. Add your website in the IIS Manager.
@ -100,7 +107,7 @@ You can use any web server capable of running PHP code to run the example. We wi
![browse](screenshots/browse.png)
### Step 6. Check accessibility
### Step 7. Check accessibility
In case the example and Document Server are installed on different computers, make sure that your server with the example installed has access to the Document Server with the address which you specify instead of **documentserver** in the configuration files.
@ -124,8 +131,11 @@ See the detailed guide to learn how to [install Document Server for Linux](https
2. Install **Composer**:
To install composer globally, use the following command which will download and install Composer as a system-wide command named composer, under /usr/local/bin:
```
instructions should be here
curl -sS https://getcomposer.org/installer -o /tmp/composer-setup.php
sudo php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer
```
3. Download the archive with the PHP example and unpack the archive:

View File

@ -95,15 +95,10 @@ function saveas()
$title = $post["title"];
$extension = mb_strtolower(pathinfo($title, PATHINFO_EXTENSION));
$configManager = new ConfigManager();
$allexts = array_merge(
$configManager->getConfig("docServConvert"),
$configManager->getConfig("docServEdited"),
$configManager->getConfig("docServViewd"),
$configManager->getConfig("docServFillforms")
);
$allexts = $configManager->getSuppotredExtensions();
$filename = GetCorrectName($title);
if (!in_array("." . $extension, $allexts)) {
if (!in_array($extension, $allexts)) {
$result["error"] = "File type is not supported";
return $result;
}
@ -156,7 +151,7 @@ function upload()
// check if the file was uploaded using HTTP POST
if (is_uploaded_file($tmp)) {
$filesize = $_FILES['files']['size']; // get the file size
$ext = mb_strtolower('.' . pathinfo($_FILES['files']['name'], PATHINFO_EXTENSION)); // get file extension
$ext = mb_strtolower(pathinfo($_FILES['files']['name'], PATHINFO_EXTENSION)); // get file extension
// check if the file size is correct (it should be less than the max file size, but greater than 0)
if ($filesize <= 0 || $filesize > $configManager->getConfig("fileSizeMax")) {
@ -165,7 +160,7 @@ function upload()
}
// check if the file extension is supported by the editor
if (!in_array($ext, getFileExts())) {
if (!in_array($ext, $configManager->getSuppotredExtensions())) {
$result["error"] = 'File type is not supported'; // if not, then an error occurs
return $result;
}
@ -250,13 +245,13 @@ function convert()
$post = json_decode(file_get_contents('php://input'), true);
$fileName = basename($post["filename"]);
$filePass = $post["filePass"];
$lang = $_COOKIE["ulang"] ?? "";
$lang = $_COOKIE["ulang"];
$extension = mb_strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
$internalExtension = "ooxml";
$configManager = new ConfigManager();
// check if the file with such an extension can be converted
if (in_array("." . $extension, $configManager->getConfig("docServConvert")) &&
if (in_array($extension, $configManager->getConvertExtensions()) &&
$internalExtension != "") {
$fileUri = $post["fileUri"];
if ($fileUri == null || $fileUri == "") {
@ -369,7 +364,8 @@ function assets()
{
$fileName = basename($_GET["name"]);
$filePath = dirname(__FILE__) .
DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "sample" . DIRECTORY_SEPARATOR . $fileName;
DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "document-templates"
. DIRECTORY_SEPARATOR . "sample" . DIRECTORY_SEPARATOR . $fileName;
downloadFile($filePath);
}
@ -382,7 +378,8 @@ function csv()
{
$fileName = "csv.csv";
$filePath = dirname(__FILE__) .
DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "sample" . DIRECTORY_SEPARATOR . $fileName;
DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "document-templates"
. DIRECTORY_SEPARATOR . "sample" . DIRECTORY_SEPARATOR . $fileName;
downloadFile($filePath);
}
@ -445,8 +442,8 @@ function download()
$fileName = realpath($configManager->getConfig("storagePath"))
=== $configManager->getConfig("storagePath") ?
$_GET["fileName"] : basename($_GET["fileName"]); // get the file name
$userAddress = $_GET["userAddress"] ?? null;
$isEmbedded = $_GET["&dmode"] ?? null;
$userAddress = $_GET["userAddress"];
$isEmbedded = $_GET["&dmode"];
$jwtManager = new JwtManager();
if ($jwtManager->isJwtEnabled() && $isEmbedded == null && $userAddress) {
@ -491,9 +488,8 @@ function downloadFile($filePath)
// write headers to the response object
@header('Content-Length: ' . filesize($filePath));
@header('Content-Disposition: attachment; filename*=UTF-8\'\'' . str_replace("+", "%20", urlencode(basename($filePath))));
@header('Content-Disposition: attachment; filename*=UTF-8\'\'' . urldecode(basename($filePath)));
@header('Content-Type: ' . mime_content_type($filePath));
@header('Access-Control-Allow-Origin: *');
if ($fd = fopen($filePath, 'rb')) {
while (!feof($fd)) {
@ -589,9 +585,9 @@ function reference()
}
$data = [
"fileType" => trim(getInternalExtension($fileName), '.'),
"fileType" => getInternalExtension($fileName),
"url" => getDownloadUrl($fileName),
"directUrl" => $post["directUrl"] ? getDownloadUrl($fileName, false) : null,
"directUrl" => $post["directUrl"] ? getDownloadUrl($fileName) : getDownloadUrl($fileName, false),
"referenceData" => [
"fileKey" => json_encode([
"fileName" => $fileName,

View File

@ -1,20 +1,10 @@
{
"version": "1.6.0",
"version": "1.5.1",
"fileSizeMax": 5242880,
"storagePath": "",
"alone": false,
"docServFillforms": [".docx", ".oform"],
"docServViewd": [".djvu", ".oxps", ".pdf", ".xps"],
"docServEdited": [".csv", ".docm", ".docx", ".docxf", ".dotm", ".dotx", ".epub",
".fb2", ".html", ".odp", ".ods", ".odt", ".otp", ".ots", ".ott", ".potm", ".potx",
".ppsm", ".ppsx", ".pptm", ".pptx", ".rtf", ".txt", ".xlsm", ".xlsx", ".xltm", ".xltx"],
"docServConvert": [".doc", ".dot", ".dps", ".dpt", ".epub",
".et", ".ett", ".fb2", ".fodp", ".fods", ".fodt", ".htm", ".html",
".mht", ".mhtml", ".odp", ".ods", ".odt", ".otp", ".ots", ".ott", ".pot",
".pps", ".ppt", ".rtf", ".stw", ".sxc", ".sxi", ".sxw", ".wps", ".wpt", ".xls", ".xlsb", ".xlt", ".xml"],
"docServTimeout": "120000",
"docServSiteUrl": "https://documentserver/",
@ -31,18 +21,6 @@
"exampleUrl": "",
"mobileRegex": "android|avantgo|playbook|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od|ad)|iris|kindle|lge |maemo|midp|mmp|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\\/|plucker|pocket|psp|symbian|treo|up\\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino",
"extsSpreadsheet": [".xls", ".xlsx", ".xlsm", ".xlsb",
".xlt", ".xltx", ".xltm",
".ods", ".fods", ".ots", ".csv"],
"extsPresentation": [".pps", ".ppsx", ".ppsm",
".ppt", ".pptx", ".pptm",
".pot", ".potx", ".potm",
".odp", ".fodp", ".otp"],
"extsDocument": [".doc", ".docx", ".docm",
".dot", ".dotx", ".dotm",
".odt", ".fodt", ".ott", ".rtf", ".txt",
".html", ".htm", ".mht", ".xml",
".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oxps", ".oform"],
"languages": {
"en": "English",
"hy": "Armenian",

View File

@ -130,18 +130,24 @@ function getCurUserHostAddress($userAddress = null)
*/
function getInternalExtension($filename)
{
$ext = mb_strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION));
$ext = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$configManager = new ConfigManager();
if (in_array($ext, $configManager->getConfig("extsDocument"))) {
return ".docx";
} // .docx for text document extensions
if (in_array($ext, $configManager->getConfig("extsSpreadsheet"))) {
return ".xlsx";
} // .xlsx for spreadsheet extensions
if (in_array($ext, $configManager->getConfig("extsPresentation"))) {
return ".pptx";
} // .pptx for presentation extensions
foreach ($configManager->getSuppotredFormats() as $format) {
if ($format->name === $ext) {
if ($format->type === "word") {
return ".docx";
}
if ($format->type === "cell") {
return ".xlsx";
}
if ($format->type === "slide") {
return ".pptx";
}
}
}
return "";
}
@ -154,19 +160,24 @@ function getInternalExtension($filename)
*/
function getTemplateImageUrl($filename)
{
$ext = mb_strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION));
$ext = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$path = serverPath(true) . "/css/images/";
$configManager = new ConfigManager();
if (in_array($ext, $configManager->getConfig("extsDocument"))) {
return $path . "file_docx.svg";
} // for text document extensions
if (in_array($ext, $configManager->getConfig("extsSpreadsheet"))) {
return $path . "file_xlsx.svg";
} // for spreadsheet extensions
if (in_array($ext, $configManager->getConfig("extsPresentation"))) {
return $path . "file_pptx.svg";
} // for presentation extensions
foreach ($configManager->getSuppotredFormats() as $format) {
if ($format->name === $ext) {
if ($format->type === "word") {
return $path . "file_docx.svg";
}
if ($format->type === "cell") {
return $path . "file_xlsx.svg";
}
if ($format->type === "slide") {
return $path . "file_pptx.svg";
}
}
}
return $path . "file_docx.svg";
}
@ -179,18 +190,15 @@ function getTemplateImageUrl($filename)
*/
function getDocumentType($filename)
{
$ext = mb_strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION));
$ext = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$configManager = new ConfigManager();
if (in_array($ext, $configManager->getConfig("extsDocument"))) {
return "word";
} // word for text document extensions
if (in_array($ext, $configManager->getConfig("extsSpreadsheet"))) {
return "cell";
} // cell for spreadsheet extensions
if (in_array($ext, $configManager->getConfig("extsPresentation"))) {
return "slide";
} // slide for presentation extensions
foreach ($configManager->getSuppotredFormats() as $format) {
if ($format->name === $ext) {
return $format->type;
}
}
return "word";
}
@ -400,13 +408,13 @@ function getStoredFiles()
foreach ($cdir as $key => $fileName) { // run through all the file and folder names
if (!in_array($fileName, [".", ".."])) {
if (!is_dir($directory . DIRECTORY_SEPARATOR . $fileName)) { // if an element isn't a directory
$ext = mb_strtolower('.' . pathinfo($fileName, PATHINFO_EXTENSION));
$ext = mb_strtolower(pathinfo($fileName, PATHINFO_EXTENSION));
$dat = filemtime($directory . DIRECTORY_SEPARATOR . $fileName); // get the time of element modification
$result[$dat] = (object) [ // and write the file to the result
"name" => $fileName,
"documentType" => getDocumentType($fileName),
"canEdit" => in_array($ext, $configManager->getConfig("docServEdited")),
"isFillFormDoc" => in_array($ext, $configManager->getConfig("docServFillforms")),
"canEdit" => in_array($ext, $configManager->getEditExtensions()),
"isFillFormDoc" => in_array($ext, $configManager->getFillExtensions()),
];
}
}
@ -521,22 +529,6 @@ function getFileInfo($fileId)
return $result;
}
/**
* Get all the supported file extensions
*
* @return array
*/
function getFileExts()
{
$configManager = new ConfigManager();
return array_merge(
$configManager->getConfig("docServViewd"),
$configManager->getConfig("docServEdited"),
$configManager->getConfig("docServConvert"),
$configManager->getConfig("docServFillforms")
);
}
/**
* Get the correct file name if such a name already exists
*
@ -590,10 +582,11 @@ function getDocEditorKey($fileName)
function doUpload($fileUri)
{
$_fileName = GetCorrectName($fileUri);
$configManager = new ConfigManager();
// check if file extension is supported by the editor
$ext = mb_strtolower('.' . pathinfo($_fileName, PATHINFO_EXTENSION));
if (!in_array($ext, getFileExts())) {
$ext = mb_strtolower(pathinfo($_fileName, PATHINFO_EXTENSION));
if (!in_array($ext, $configManager->getSuppotredExtensions())) {
throw new Exception("File type is not supported");
}
@ -895,9 +888,9 @@ function getResponseUri($document_response, &$response_uri)
*/
function tryGetDefaultByType($createExt, $user)
{
$sample = isset($_GET["sample"]) && $_GET["sample"];
$demoName = ($sample ? "sample." : "new.") . $createExt;
$demoPath = "assets" . DIRECTORY_SEPARATOR . ($sample ? "sample" : "new") . DIRECTORY_SEPARATOR;
$demoName = (isset($_GET["sample"]) ? "sample." : "new.") . $createExt;
$demoPath = "assets" . DIRECTORY_SEPARATOR . "document-templates" . DIRECTORY_SEPARATOR
. (isset($_GET["sample"]) ? "sample" : "new") . DIRECTORY_SEPARATOR;
$demoFilename = GetCorrectName($demoName);
if (!@copy(dirname(__FILE__) . DIRECTORY_SEPARATOR . $demoPath . $demoName, getStoragePath($demoFilename))) {

View File

@ -21,10 +21,12 @@ namespace OnlineEditorsExamplePhp\Helpers;
final class ConfigManager
{
private mixed $config;
private mixed $configFormats;
public function __construct()
{
$this->config = json_decode($this->getConfigurationJson());
$this->configFormats = json_decode($this->getConfigurationFromatsJson());
}
private function getConfigurationJson(): bool|string
@ -32,6 +34,13 @@ final class ConfigManager
return file_exists("./config.json") ? file_get_contents("./config.json") : false;
}
private function getConfigurationFromatsJson(): bool|string
{
return file_exists("./assets/document-formats/onlyoffice-docs-formats.json")
? file_get_contents("./assets/document-formats/onlyoffice-docs-formats.json")
: false;
}
/**
* @param string|null $configName
* @return mixed
@ -43,4 +52,74 @@ final class ConfigManager
}
return $this->config;
}
public function getSuppotredFormats(): mixed
{
return $this->configFormats;
}
public function getSuppotredExtensions(): mixed
{
return array_reduce(
$this->configFormats,
function ($extensions, $format) {
$extensions[] = $format->name;
return $extensions;
}
);
}
public function getViewExtensions(): mixed
{
return array_reduce(
$this->configFormats,
function ($extensions, $format) {
if (in_array("view", $format->actions)) {
$extensions[] = $format->name;
}
return $extensions;
}
);
}
public function getEditExtensions(): mixed
{
return array_reduce(
$this->configFormats,
function ($extensions, $format) {
if (in_array("edit", $format->actions) || in_array("lossy-edit", $format->actions)) {
$extensions[] = $format->name;
}
return $extensions;
}
);
}
public function getFillExtensions(): mixed
{
return array_reduce(
$this->configFormats,
function ($extensions, $format) {
if (in_array("fill", $format->actions)) {
$extensions[] = $format->name;
}
return $extensions;
}
);
}
public function getConvertExtensions(): mixed
{
return array_reduce(
$this->configFormats,
function ($extensions, $format) {
if ($format->type === "word" && in_array("docx", $format->convert)
|| $format->type === "cell" && in_array("xlsx", $format->convert)
|| $format->type === "slide" && in_array("pptx", $format->convert)) {
$extensions[] = $format->name;
}
return $extensions;
}
);
}
}

View File

@ -1,9 +1,5 @@
ONLYOFFICE Applications example uses code from the following 3rd party projects:
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -16,9 +12,13 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT

View File

@ -212,7 +212,7 @@
<script type="text/javascript" src="js/jquery.dropdownToggle.js"></script>
<script type="text/javascript" src="js/jscript.js"></script>
<script type="text/javascript">
var FillFormsExtList = '{docServFillforms}';
var FillFormsExtList = '{fillFormsExtList}';
var ConverExtList = '{converExtList}';
var EditedExtList = '{editedExtList}';
</script>

View File

@ -43,14 +43,13 @@ final class DocEditorView extends View
$confgManager = new ConfigManager();
$jwtManager = new JwtManager();
$userList = new ExampleUsers();
$fileId = $request["fileID"] ?? "";
$user = $userList->getUser($request["user"]);
$isEnableDirectUrl = isset($request["directUrl"]) ? filter_var($request["directUrl"], FILTER_VALIDATE_BOOLEAN)
: false;
if (!empty($externalUrl)) {
$filename = doUpload($externalUrl);
} else { // if the file url doesn't exist, get file name and file extension
$filename = basename($fileId);
$filename = basename($request["fileID"] ?? "");
}
$createExt = $request["fileExt"] ?? "";
@ -72,12 +71,12 @@ final class DocEditorView extends View
$docKey = getDocEditorKey($filename);
$filetype = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$ext = mb_strtolower('.' . pathinfo($filename, PATHINFO_EXTENSION));
$ext = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION));
$editorsMode = empty($request["action"]) ? "edit" : $request["action"]; // get the editors mode
$canEdit = in_array($ext, $confgManager->getConfig("docServEdited")); // check if the file can be edited
$canEdit = in_array($ext, $confgManager->getEditExtensions()); // check if the file can be edited
if ((!$canEdit && $editorsMode == "edit"
|| $editorsMode == "fillForms")
&& in_array($ext, $confgManager->getConfig("docServFillforms"))
&& in_array($ext, $confgManager->getFillExtensions())
) {
$editorsMode = "fillForms";
$canEdit = true;

View File

@ -41,9 +41,9 @@ final class IndexView extends View
"editButton" => $this->getEditButton(),
"dataDocs" => $this->getPreloaderUrl(),
"date" => date("Y"),
"fillFormsExtList" => implode(",", $configManager->getConfig("docServFillforms")),
"converExtList" => implode(",", $configManager->getConfig("docServConvert")),
"editedExtList" => implode(",", $configManager->getConfig("docServEdited")),
"fillFormsExtList" => implode(",", $configManager->getFillExtensions()),
"converExtList" => implode(",", $configManager->getConvertExtensions()),
"editedExtList" => implode(",", $configManager->getEditExtensions()),
];
}

View File

@ -0,0 +1,3 @@
*.egg-info
build
storage/*

View File

@ -0,0 +1 @@
3.11

View File

@ -4,10 +4,6 @@ Django - Django is a high-level Python web framework that encourages rapi
License: BSD-3-Clause
License File: Django.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -20,18 +16,30 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
License File: jQuery.UI.license
mypy - Optional static typing for Python. (https://github.com/python/mypy/raw/v1.4.1/LICENSE)
License: MIT
License File: mypy.license
PyJWT - A Python implementation of RFC 7519. (https://github.com/jpadilla/pyjwt/blob/master/LICENSE)
License: MIT
License File: PyJWT.license
pylint - It's not just a linter that annoys you! (https://github.com/pylint-dev/pylint/raw/v2.17.4/LICENSE)
License: GPL v2
License File: pylint.license
python-magic - python-magic is a Python interface to the libmagic file type identification library. (https://github.com/ahupp/python-magic/blob/master/LICENSE)
License: MIT
License File: python-magic.license

View File

@ -0,0 +1,13 @@
FROM python:3.11.4-alpine3.18 as example
WORKDIR /srv
COPY . .
RUN \
apk update && \
apk add --no-cache \
libmagic \
make && \
make prod
CMD ["make", "prod-server"]
FROM nginx:1.23.4-alpine3.17 as proxy
COPY proxy/nginx.conf /etc/nginx/nginx.conf

View File

@ -0,0 +1,39 @@
.DEFAULT_GOAL := help
.PHONY: help
help: # Show help message for each of the Makefile recipes.
@grep -E "^[a-z-]+: #" $(MAKEFILE_LIST) | \
sort | \
awk 'BEGIN {FS = ": # "}; {printf "%s: %s\n", $$1, $$2}'
.PHONY: dev
dev: # Install development dependencies.
@pip install --editable .[development]
.PHONY: dev-server
dev-server: \
export DEBUG := true
dev-server: # Start the development server on localhost at $PORT (default: 8000).
@python manage.py runserver
.PHONY: lint
lint: # Lint the source code for style and check for types.
@pylint --recursive=y .
@mypy .
.PHONY: prod
prod: # Install production dependencies.
@pip install .
.PHONY: prod-server
prod-server: # Start the production server on 0.0.0.0 at $PORT (default: 8000).
@python manage.py runserver
.PHONY: test
test: # Recursively run the tests.
@python -m unittest ./src/**/*_tests.py
.PHONY: up
up: # Build and up docker containers.
@docker-compose build
@docker-compose up -d

View File

@ -1,108 +0,0 @@
import os
VERSION = '1.6.0'
FILE_SIZE_MAX = 5242880
STORAGE_PATH = 'app_data'
DOC_SERV_FILLFORMS = [".docx", ".oform"]
DOC_SERV_VIEWED = [".djvu", ".oxps", ".pdf", ".xps"] # file extensions that can be viewed
DOC_SERV_EDITED = [ # file extensions that can be edited
".csv", ".docm", ".docx", ".docxf", ".dotm", ".dotx",
".epub", ".fb2", ".html", ".odp", ".ods", ".odt", ".otp",
".ots", ".ott", ".potm", ".potx", ".ppsm", ".ppsx", ".pptm",
".pptx", ".rtf", ".txt", ".xlsm", ".xlsx", ".xltm", ".xltx"
]
DOC_SERV_CONVERT = [ # file extensions that can be converted
".doc", ".dot", ".dps", ".dpt", ".epub", ".et", ".ett", ".fb2",
".fodp", ".fods", ".fodt", ".htm", ".html", ".mht", ".mhtml",
".odp", ".ods", ".odt", ".otp", ".ots", ".ott", ".pot", ".pps",
".ppt", ".rtf", ".stw", ".sxc", ".sxi", ".sxw", ".wps", ".wpt",
".xls", ".xlsb", ".xlt", ".xml"
]
DOC_SERV_TIMEOUT = 120000
DOC_SERV_SITE_URL = 'http://documentserver/'
DOC_SERV_CONVERTER_URL = 'ConvertService.ashx'
DOC_SERV_API_URL = 'web-apps/apps/api/documents/api.js'
DOC_SERV_PRELOADER_URL = 'web-apps/apps/api/documents/cache-scripts.html'
DOC_SERV_COMMAND_URL='coauthoring/CommandService.ashx'
EXAMPLE_DOMAIN = None
DOC_SERV_JWT_SECRET = '' # the secret key for generating token
DOC_SERV_JWT_HEADER = 'Authorization'
DOC_SERV_JWT_USE_FOR_REQUEST = True
DOC_SERV_VERIFY_PEER = False
EXT_SPREADSHEET = [
".xls", ".xlsx", ".xlsm", ".xlsb",
".xlt", ".xltx", ".xltm",
".ods", ".fods", ".ots", ".csv"
]
EXT_PRESENTATION = [
".pps", ".ppsx", ".ppsm",
".ppt", ".pptx", ".pptm",
".pot", ".potx", ".potm",
".odp", ".fodp", ".otp"
]
EXT_DOCUMENT = [
".doc", ".docx", ".docm",
".dot", ".dotx", ".dotm",
".odt", ".fodt", ".ott", ".rtf", ".txt",
".html", ".htm", ".mht", ".xml",
".pdf", ".djvu", ".fb2", ".epub", ".xps", ".oxps", ".oform"
]
LANGUAGES = {
'en': 'English',
'hy': 'Armenian',
'az': 'Azerbaijani',
'eu': 'Basque',
'be': 'Belarusian',
'bg': 'Bulgarian',
'ca': 'Catalan',
'zh': 'Chinese (Simplified)',
'zh-TW': 'Chinese (Traditional)',
'cs': 'Czech',
'da': 'Danish',
'nl': 'Dutch',
'fi': 'Finnish',
'fr': 'French',
'gl': 'Galego',
'de': 'German',
'el': 'Greek',
'hu': 'Hungarian',
'id': 'Indonesian',
'it': 'Italian',
'ja': 'Japanese',
'ko': 'Korean',
'lo': 'Lao',
'lv': 'Latvian',
'ms': 'Malay (Malaysia)',
'no': 'Norwegian',
'pl': 'Polish',
'pt': 'Portuguese (Brazil)',
'pt-PT': 'Portuguese (Portugal)',
'ro': 'Romanian',
'ru': 'Russian',
'si': 'Sinhala (Sri Lanka)',
'sk': 'Slovak',
'sl': 'Slovenian',
'es': 'Spanish',
'sv': 'Swedish',
'tr': 'Turkish',
'uk': 'Ukrainian',
'vi': 'Vietnamese',
'aa-AA': 'Test Language'
}
if os.environ.get("EXAMPLE_DOMAIN"): # generates a link for example domain
EXAMPLE_DOMAIN = os.environ.get("EXAMPLE_DOMAIN")
if os.environ.get("DOC_SERV"): # generates links for document server
DOC_SERV_SITE_URL = os.environ.get("DOC_SERV")

View File

@ -0,0 +1,40 @@
version: "3.8"
services:
document-server:
container_name: document-server
image: onlyoffice/documentserver:7.3.3.50
expose:
- "80"
environment:
- JWT_SECRET=your-256-bit-secret
example:
container_name: example
build:
context: .
target: example
volumes:
- static:/srv/static
expose:
- "80"
environment:
- DOCUMENT_SERVER_PRIVATE_URL=http://proxy:3000/
- DOCUMENT_SERVER_PUBLIC_URL=http://localhost:3000/
- EXAMPLE_URL=http://proxy:8080/
- JWT_SECRET=your-256-bit-secret
- PORT=80
proxy:
container_name: proxy
build:
context: .
target: proxy
volumes:
- static:/srv/static
ports:
- "8080:8080"
- "3000:3000"
volumes:
static:

View File

@ -4,10 +4,6 @@ Django - Django is a high-level Python web framework that encourages rapi
License: BSD-3-Clause
License File: Django.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.BlockUI - The jQuery BlockUI Plugin lets you simulate synchronous behavior when using AJAX, without locking the browser. (https://github.com/malsup/blockui/)
License: MIT, GPL
License File: jQuery.BlockUI.license
@ -20,18 +16,30 @@ jQuery.iframe-transport - jQuery Iframe Transport Plugin for File Upload (https:
License: MIT
License File: jQuery.iframe-transport.license
jQuery - jQuery is a new kind of JavaScript Library. jQuery is a fast and concise JavaScript Library that simplifies HTML document traversing, event handling, animating, and Ajax interactions for rapid web development. jQuery is designed to change the way that you write JavaScript. NOTE: This package is maintained on behalf of the library owners by the NuGet Community Packages project at https://nugetpackages.codeplex.com/ (https://jquery.org/license/)
License: MIT
License File: jQuery.license
jQuery.Migrate - Upgrading libraries such as jQuery can be a lot of work, when breaking changes have been introduced. jQuery Migrate makes this easier, by restoring the APIs that were removed, and additionally shows warnings in the browser console (development version of jQuery Migrate only) when removed and/or deprecated APIs are used. (https://github.com/jquery/jquery-migrate/blob/main/LICENSE.txt)
License: OpenJS
License File: jQuery.Migrate.license
License: OpenJS
License File: jQuery.Migrate.license
jQuery.UI - jQuery UI is an open source library of interface components — interactions, full-featured widgets, and animation effects — based on the stellar jQuery javascript library . Each component is built according to jQuery's event-driven architecture (find something, manipulate it) and is themeable, making it easy for developers of any skill level to integrate and extend into their own code. (https://jquery.org/license/)
License: MIT
License File: jQuery.UI.license
mypy - Optional static typing for Python. (https://github.com/python/mypy/raw/v1.4.1/LICENSE)
License: MIT
License File: mypy.license
PyJWT - A Python implementation of RFC 7519. (https://github.com/jpadilla/pyjwt/blob/master/LICENSE)
License: MIT
License File: PyJWT.license
pylint - It's not just a linter that annoys you! (https://github.com/pylint-dev/pylint/raw/v2.17.4/LICENSE)
License: GPL v2
License File: pylint.license
python-magic - python-magic is a Python interface to the libmagic file type identification library. (https://github.com/ahupp/python-magic/blob/master/LICENSE)
License: MIT
License File: python-magic.license

View File

@ -0,0 +1,229 @@
Mypy (and mypyc) are licensed under the terms of the MIT license, reproduced below.
= = = = =
The MIT License
Copyright (c) 2012-2022 Jukka Lehtosalo and contributors
Copyright (c) 2015-2022 Dropbox, Inc.
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
= = = = =
Portions of mypy and mypyc are licensed under different licenses.
The files
mypyc/lib-rt/pythonsupport.h, mypyc/lib-rt/getargs.c and
mypyc/lib-rt/getargsfast.c are licensed under the PSF 2 License, reproduced
below.
= = = = =
PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
--------------------------------------------
1. This LICENSE AGREEMENT is between the Python Software Foundation
("PSF"), and the Individual or Organization ("Licensee") accessing and
otherwise using this software ("Python") in source or binary form and
its associated documentation.
2. Subject to the terms and conditions of this License Agreement, PSF hereby
grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce,
analyze, test, perform and/or display publicly, prepare derivative works,
distribute, and otherwise use Python alone or in any derivative version,
provided, however, that PSF's License Agreement and PSF's notice of copyright,
i.e., "Copyright (c) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010,
2011, 2012 Python Software Foundation; All Rights Reserved" are retained in Python
alone or in any derivative version prepared by Licensee.
3. In the event Licensee prepares a derivative work that is based on
or incorporates Python or any part thereof, and wants to make
the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to Python.
4. PSF is making Python available to Licensee on an "AS IS"
basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON WILL NOT
INFRINGE ANY THIRD PARTY RIGHTS.
5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON,
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.
7. Nothing in this License Agreement shall be deemed to create any
relationship of agency, partnership, or joint venture between PSF and
Licensee. This License Agreement does not grant permission to use PSF
trademarks or trade name in a trademark sense to endorse or promote
products or services of Licensee, or any third party.
8. By copying, installing or otherwise using Python, Licensee
agrees to be bound by the terms and conditions of this License
Agreement.
BEOPEN.COM LICENSE AGREEMENT FOR PYTHON 2.0
-------------------------------------------
BEOPEN PYTHON OPEN SOURCE LICENSE AGREEMENT VERSION 1
1. This LICENSE AGREEMENT is between BeOpen.com ("BeOpen"), having an
office at 160 Saratoga Avenue, Santa Clara, CA 95051, and the
Individual or Organization ("Licensee") accessing and otherwise using
this software in source or binary form and its associated
documentation ("the Software").
2. Subject to the terms and conditions of this BeOpen Python License
Agreement, BeOpen hereby grants Licensee a non-exclusive,
royalty-free, world-wide license to reproduce, analyze, test, perform
and/or display publicly, prepare derivative works, distribute, and
otherwise use the Software alone or in any derivative version,
provided, however, that the BeOpen Python License is retained in the
Software, alone or in any derivative version prepared by Licensee.
3. BeOpen is making the Software available to Licensee on an "AS IS"
basis. BEOPEN MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, BEOPEN MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE WILL NOT
INFRINGE ANY THIRD PARTY RIGHTS.
4. BEOPEN SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF THE
SOFTWARE FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS
AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THE SOFTWARE, OR ANY
DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
5. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.
6. This License Agreement shall be governed by and interpreted in all
respects by the law of the State of California, excluding conflict of
law provisions. Nothing in this License Agreement shall be deemed to
create any relationship of agency, partnership, or joint venture
between BeOpen and Licensee. This License Agreement does not grant
permission to use BeOpen trademarks or trade names in a trademark
sense to endorse or promote products or services of Licensee, or any
third party. As an exception, the "BeOpen Python" logos available at
http://www.pythonlabs.com/logos.html may be used according to the
permissions granted on that web page.
7. By copying, installing or otherwise using the software, Licensee
agrees to be bound by the terms and conditions of this License
Agreement.
CNRI LICENSE AGREEMENT FOR PYTHON 1.6.1
---------------------------------------
1. This LICENSE AGREEMENT is between the Corporation for National
Research Initiatives, having an office at 1895 Preston White Drive,
Reston, VA 20191 ("CNRI"), and the Individual or Organization
("Licensee") accessing and otherwise using Python 1.6.1 software in
source or binary form and its associated documentation.
2. Subject to the terms and conditions of this License Agreement, CNRI
hereby grants Licensee a nonexclusive, royalty-free, world-wide
license to reproduce, analyze, test, perform and/or display publicly,
prepare derivative works, distribute, and otherwise use Python 1.6.1
alone or in any derivative version, provided, however, that CNRI's
License Agreement and CNRI's notice of copyright, i.e., "Copyright (c)
1995-2001 Corporation for National Research Initiatives; All Rights
Reserved" are retained in Python 1.6.1 alone or in any derivative
version prepared by Licensee. Alternately, in lieu of CNRI's License
Agreement, Licensee may substitute the following text (omitting the
quotes): "Python 1.6.1 is made available subject to the terms and
conditions in CNRI's License Agreement. This Agreement together with
Python 1.6.1 may be located on the Internet using the following
unique, persistent identifier (known as a handle): 1895.22/1013. This
Agreement may also be obtained from a proxy server on the Internet
using the following URL: http://hdl.handle.net/1895.22/1013".
3. In the event Licensee prepares a derivative work that is based on
or incorporates Python 1.6.1 or any part thereof, and wants to make
the derivative work available to others as provided herein, then
Licensee hereby agrees to include in any such work a brief summary of
the changes made to Python 1.6.1.
4. CNRI is making Python 1.6.1 available to Licensee on an "AS IS"
basis. CNRI MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR
IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, CNRI MAKES NO AND
DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 1.6.1 WILL NOT
INFRINGE ANY THIRD PARTY RIGHTS.
5. CNRI SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON
1.6.1 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS
A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 1.6.1,
OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF.
6. This License Agreement will automatically terminate upon a material
breach of its terms and conditions.
7. This License Agreement shall be governed by the federal
intellectual property law of the United States, including without
limitation the federal copyright law, and, to the extent such
U.S. federal law does not apply, by the law of the Commonwealth of
Virginia, excluding Virginia's conflict of law provisions.
Notwithstanding the foregoing, with regard to derivative works based
on Python 1.6.1 that incorporate non-separable material that was
previously distributed under the GNU General Public License (GPL), the
law of the Commonwealth of Virginia shall govern this License
Agreement only as to issues arising under or with respect to
Paragraphs 4, 5, and 7 of this License Agreement. Nothing in this
License Agreement shall be deemed to create any relationship of
agency, partnership, or joint venture between CNRI and Licensee. This
License Agreement does not grant permission to use CNRI trademarks or
trade name in a trademark sense to endorse or promote products or
services of Licensee, or any third party.
8. By clicking on the "ACCEPT" button where indicated, or by copying,
installing or otherwise using Python 1.6.1, Licensee agrees to be
bound by the terms and conditions of this License Agreement.
ACCEPT
CWI LICENSE AGREEMENT FOR PYTHON 0.9.0 THROUGH 1.2
--------------------------------------------------
Copyright (c) 1991 - 1995, Stichting Mathematisch Centrum Amsterdam,
The Netherlands. All rights reserved.
Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of Stichting Mathematisch
Centrum or CWI not be used in advertising or publicity pertaining to
distribution of the software without specific, written prior
permission.
STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View File

@ -0,0 +1,340 @@
GNU GENERAL PUBLIC LICENSE
Version 2, June 1991
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
The licenses for most software are designed to take away your
freedom to share and change it. By contrast, the GNU General Public
License is intended to guarantee your freedom to share and change free
software--to make sure the software is free for all its users. This
General Public License applies to most of the Free Software
Foundation's software and to any other program whose authors commit to
using it. (Some other Free Software Foundation software is covered by
the GNU Library General Public License instead.) You can apply it to
your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
have the freedom to distribute copies of free software (and charge for
this service if you wish), that you receive source code or can get it
if you want it, that you can change the software or use pieces of it
in new free programs; and that you know you can do these things.
To protect your rights, we need to make restrictions that forbid
anyone to deny you these rights or to ask you to surrender the rights.
These restrictions translate to certain responsibilities for you if you
distribute copies of the software, or if you modify it.
For example, if you distribute copies of such a program, whether
gratis or for a fee, you must give the recipients all the rights that
you have. You must make sure that they, too, receive or can get the
source code. And you must show them these terms so they know their
rights.
We protect your rights with two steps: (1) copyright the software, and
(2) offer you this license which gives you legal permission to copy,
distribute and/or modify the software.
Also, for each author's protection and ours, we want to make certain
that everyone understands that there is no warranty for this free
software. If the software is modified by someone else and passed on, we
want its recipients to know that what they have is not the original, so
that any problems introduced by others will not reflect on the original
authors' reputations.
Finally, any free program is threatened constantly by software
patents. We wish to avoid the danger that redistributors of a free
program will individually obtain patent licenses, in effect making the
program proprietary. To prevent this, we have made it clear that any
patent must be licensed for everyone's free use or not licensed at all.
The precise terms and conditions for copying, distribution and
modification follow.
GNU GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. This License applies to any program or other work which contains
a notice placed by the copyright holder saying it may be distributed
under the terms of this General Public License. The "Program", below,
refers to any such program or work, and a "work based on the Program"
means either the Program or any derivative work under copyright law:
that is to say, a work containing the Program or a portion of it,
either verbatim or with modifications and/or translated into another
language. (Hereinafter, translation is included without limitation in
the term "modification".) Each licensee is addressed as "you".
Activities other than copying, distribution and modification are not
covered by this License; they are outside its scope. The act of
running the Program is not restricted, and the output from the Program
is covered only if its contents constitute a work based on the
Program (independent of having been made by running the Program).
Whether that is true depends on what the Program does.
1. You may copy and distribute verbatim copies of the Program's
source code as you receive it, in any medium, provided that you
conspicuously and appropriately publish on each copy an appropriate
copyright notice and disclaimer of warranty; keep intact all the
notices that refer to this License and to the absence of any warranty;
and give any other recipients of the Program a copy of this License
along with the Program.
You may charge a fee for the physical act of transferring a copy, and
you may at your option offer warranty protection in exchange for a fee.
2. You may modify your copy or copies of the Program or any portion
of it, thus forming a work based on the Program, and copy and
distribute such modifications or work under the terms of Section 1
above, provided that you also meet all of these conditions:
a) You must cause the modified files to carry prominent notices
stating that you changed the files and the date of any change.
b) You must cause any work that you distribute or publish, that in
whole or in part contains or is derived from the Program or any
part thereof, to be licensed as a whole at no charge to all third
parties under the terms of this License.
c) If the modified program normally reads commands interactively
when run, you must cause it, when started running for such
interactive use in the most ordinary way, to print or display an
announcement including an appropriate copyright notice and a
notice that there is no warranty (or else, saying that you provide
a warranty) and that users may redistribute the program under
these conditions, and telling the user how to view a copy of this
License. (Exception: if the Program itself is interactive but
does not normally print such an announcement, your work based on
the Program is not required to print an announcement.)
These requirements apply to the modified work as a whole. If
identifiable sections of that work are not derived from the Program,
and can be reasonably considered independent and separate works in
themselves, then this License, and its terms, do not apply to those
sections when you distribute them as separate works. But when you
distribute the same sections as part of a whole which is a work based
on the Program, the distribution of the whole must be on the terms of
this License, whose permissions for other licensees extend to the
entire whole, and thus to each and every part regardless of who wrote it.
Thus, it is not the intent of this section to claim rights or contest
your rights to work written entirely by you; rather, the intent is to
exercise the right to control the distribution of derivative or
collective works based on the Program.
In addition, mere aggregation of another work not based on the Program
with the Program (or with a work based on the Program) on a volume of
a storage or distribution medium does not bring the other work under
the scope of this License.
3. You may copy and distribute the Program (or a work based on it,
under Section 2) in object code or executable form under the terms of
Sections 1 and 2 above provided that you also do one of the following:
a) Accompany it with the complete corresponding machine-readable
source code, which must be distributed under the terms of Sections
1 and 2 above on a medium customarily used for software interchange; or,
b) Accompany it with a written offer, valid for at least three
years, to give any third party, for a charge no more than your
cost of physically performing source distribution, a complete
machine-readable copy of the corresponding source code, to be
distributed under the terms of Sections 1 and 2 above on a medium
customarily used for software interchange; or,
c) Accompany it with the information you received as to the offer
to distribute corresponding source code. (This alternative is
allowed only for noncommercial distribution and only if you
received the program in object code or executable form with such
an offer, in accord with Subsection b above.)
The source code for a work means the preferred form of the work for
making modifications to it. For an executable work, complete source
code means all the source code for all modules it contains, plus any
associated interface definition files, plus the scripts used to
control compilation and installation of the executable. However, as a
special exception, the source code distributed need not include
anything that is normally distributed (in either source or binary
form) with the major components (compiler, kernel, and so on) of the
operating system on which the executable runs, unless that component
itself accompanies the executable.
If distribution of executable or object code is made by offering
access to copy from a designated place, then offering equivalent
access to copy the source code from the same place counts as
distribution of the source code, even though third parties are not
compelled to copy the source along with the object code.
4. You may not copy, modify, sublicense, or distribute the Program
except as expressly provided under this License. Any attempt
otherwise to copy, modify, sublicense or distribute the Program is
void, and will automatically terminate your rights under this License.
However, parties who have received copies, or rights, from you under
this License will not have their licenses terminated so long as such
parties remain in full compliance.
5. You are not required to accept this License, since you have not
signed it. However, nothing else grants you permission to modify or
distribute the Program or its derivative works. These actions are
prohibited by law if you do not accept this License. Therefore, by
modifying or distributing the Program (or any work based on the
Program), you indicate your acceptance of this License to do so, and
all its terms and conditions for copying, distributing or modifying
the Program or works based on it.
6. Each time you redistribute the Program (or any work based on the
Program), the recipient automatically receives a license from the
original licensor to copy, distribute or modify the Program subject to
these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties to
this License.
7. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
otherwise) that contradict the conditions of this License, they do not
excuse you from the conditions of this License. If you cannot
distribute so as to satisfy simultaneously your obligations under this
License and any other pertinent obligations, then as a consequence you
may not distribute the Program at all. For example, if a patent
license would not permit royalty-free redistribution of the Program by
all those who receive copies directly or indirectly through you, then
the only way you could satisfy both it and this License would be to
refrain entirely from distribution of the Program.
If any portion of this section is held invalid or unenforceable under
any particular circumstance, the balance of the section is intended to
apply and the section as a whole is intended to apply in other
circumstances.
It is not the purpose of this section to induce you to infringe any
patents or other property right claims or to contest validity of any
such claims; this section has the sole purpose of protecting the
integrity of the free software distribution system, which is
implemented by public license practices. Many people have made
generous contributions to the wide range of software distributed
through that system in reliance on consistent application of that
system; it is up to the author/donor to decide if he or she is willing
to distribute software through any other system and a licensee cannot
impose that choice.
This section is intended to make thoroughly clear what is believed to
be a consequence of the rest of this License.
8. If the distribution and/or use of the Program is restricted in
certain countries either by patents or by copyrighted interfaces, the
original copyright holder who places the Program under this License
may add an explicit geographical distribution limitation excluding
those countries, so that distribution is permitted only in or among
countries not thus excluded. In such case, this License incorporates
the limitation as if written in the body of this License.
9. The Free Software Foundation may publish revised and/or new versions
of the General Public License from time to time. Such new versions will
be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the Program
specifies a version number of this License which applies to it and "any
later version", you have the option of following the terms and conditions
either of that version or of any later version published by the Free
Software Foundation. If the Program does not specify a version number of
this License, you may choose any version ever published by the Free Software
Foundation.
10. If you wish to incorporate parts of the Program into other free
programs whose distribution conditions are different, write to the author
to ask for permission. For software which is copyrighted by the Free
Software Foundation, write to the Free Software Foundation; we sometimes
make exceptions for this. Our decision will be guided by the two goals
of preserving the free status of all derivatives of our free software and
of promoting the sharing and reuse of software generally.
NO WARRANTY
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
REPAIR OR CORRECTION.
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Programs
If you develop a new program, and you want it to be of the greatest
possible use to the public, the best way to achieve this is to make it
free software which everyone can redistribute and change under these terms.
To do so, attach the following notices to the program. It is safest
to attach them to the start of each source file to most effectively
convey the exclusion of warranty; and each file should have at least
the "copyright" line and a pointer to where the full notice is found.
<one line to give the program's name and a brief idea of what it does.>
Copyright (C) <year> <name of author>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Also add information on how to contact you by electronic and paper mail.
If the program is interactive, make it output a short notice like this
when it starts in an interactive mode:
Gnomovision version 69, Copyright (C) year name of author
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.
The hypothetical commands `show w' and `show c' should show the appropriate
parts of the General Public License. Of course, the commands you use may
be called something other than `show w' and `show c'; they could even be
mouse-clicks or menu items--whatever suits your program.
You should also get your employer (if you work as a programmer) or your
school, if any, to sign a "copyright disclaimer" for the program, if
necessary. Here is a sample; alter the names:
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
`Gnomovision' (which makes passes at compilers) written by James Hacker.
<signature of Ty Coon>, 1 April 1989
Ty Coon, President of Vice
This General Public License does not permit incorporating your program into
proprietary programs. If your program is a subroutine library, you may
consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Library General
Public License instead of this License.

View File

@ -1,21 +1,94 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
from os import environ
from sys import argv
from uuid import uuid1
from mimetypes import add_type
from django import setup
from django.conf import settings
from django.core.management import execute_from_command_line
from django.core.management.commands.runserver import Command as RunServer
from django.urls import path
from src.history import HistoryController
from src.views import actions, index
def debug():
env = environ.get('DEBUG')
if env is None:
return False
if env == 'true':
return True
return False
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'src.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
def address():
if settings.DEBUG:
return '127.0.0.1'
return '0.0.0.0'
def port():
env = environ.get('PORT')
return env or '8000'
def configuration():
return {
'ALLOWED_HOSTS': [
'*'
],
'DEBUG': debug(),
'ROOT_URLCONF': __name__,
'SECRET_KEY': uuid1(),
'STATIC_URL': 'static/',
'TEMPLATES': [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
'templates'
]
}
]
}
def routers():
history = HistoryController()
return [
path('', index.default),
path('convert', actions.convert),
path('create', actions.createNew),
path('csv', actions.csv),
path('download', actions.download),
path('downloadhistory', actions.downloadhistory),
path('edit', actions.edit),
path('files', actions.files),
path('reference', actions.reference),
path('remove', actions.remove),
path('rename', actions.rename),
path('saveas', actions.saveAs),
path('track', actions.track),
path('upload', actions.upload),
path(
'history/<str:source_basename>',
history.history
),
path(
'history/<str:source_basename>/<int:version>/data',
history.data
),
path(
'history/<str:source_basename>/<int:version>/download/<str:basename>',
history.download
),
path(
'history/<str:source_basename>/<int:version>/restore',
history.restore
)
]
add_type('text/javascript', '.js', True)
settings.configure(**configuration())
urlpatterns = routers()
RunServer.default_addr = address()
# False positive: the default_port isn't an int, it's a str.
RunServer.default_port = port() # type: ignore # noqa: E261
setup()
if __name__ == '__main__':
main()
execute_from_command_line(argv)

View File

@ -0,0 +1,43 @@
worker_processes auto;
events {
worker_connections 512;
}
http {
include /etc/nginx/mime.types;
server {
listen 8080;
server_name localhost;
location / {
proxy_http_version 1.1;
proxy_pass http://example;
}
location /static {
alias /srv/static;
autoindex on;
}
}
server {
listen 3000;
server_name localhost;
location / {
client_max_body_size 100m;
proxy_http_version 1.1;
proxy_pass http://document-server;
proxy_redirect off;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Host $http_x_forwarded_host;
proxy_set_header X-Forwarded-Proto $http_x_forwarded_proto;
proxy_set_header X-Real-IP $remote_addr;
}
}
}

View File

@ -0,0 +1,46 @@
[build-system]
requires = [
"setuptools>=67.6.0"
]
[project]
name = "online-editor-example"
version = "4.1.0"
requires-python = ">=3.11"
dependencies = [
"django>=3.1.3",
"django-stubs>=4.2.3",
"pyjwt>=2.6.0",
"python-magic>=0.4.27",
"requests>=2.25.0"
]
[project.license]
text = "Apache-2.0"
[[project.authors]]
name = "ONLYOFFICE"
email = "support@onlyoffice.com"
[project.optional-dependencies]
development = [
"mypy>=1.4.1",
"pylint>=2.17.4",
"types-requests>=2.31.0"
]
[tool.mypy]
plugins = [
"mypy_django_plugin.main"
]
[tool.pylint]
disable = [
"missing-module-docstring",
"missing-class-docstring",
"missing-function-docstring"
]
class-const-naming-style = "snake_case"
[tool.django-stubs]
django_settings_module = "manage"

View File

@ -0,0 +1,60 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
'''
The Codable module provides the ability to decode a string JSON into a class
instance and encode it back. It also provides the ability to remap JSON keys and
work with nested Codable instances.
```python
from dataclasses import dataclass
from src.codable import Codable, CodingKey
@dataclass
class Parent(Codable):
class CodingKeys(CodingKey):
native_for_python: 'foreignForPython'
native_for_python: str
```
The algorithm for converting JSON objects to Codable instances is far from
efficient, but it's simple and compatible with new Python features.
Perhaps in the future, it would be worth replacing the local implementation with
an external dependency that offers the same functionality, such as the
relatively popular [dataclasses-json](https://github.com/lidatong/dataclasses-json).
Unfortunately, this library is currently not friendly with type annotations (see [issues](https://github.com/lidatong/dataclasses-json/issues?q=is%3Aissue+annotations))
and struggles with type inference (see [#227](https://github.com/lidatong/dataclasses-json/issues/227)).
On the other hand, developing the current implementation into a full-fledged
library may be more attractive to us.
'''
from .codable import Codable, CodingKey
# TODO: isolate Decoder and Encoder initialization.
# Give the user the ability to override the decode and encode methods in order
# to change the object_hook for a specific property. For instance, this can be
# used to override the default behavior for ParseResult (urlparse).
# TODO: make the CodingKey definition optional.
# If the class doesn't provide the CodingKey, we must also use the native
# property names as foreign.
# TODO: add common presets.
# When overriding a specific CodingKeys method, define a common preset for all
# foreign keys. For example, convert all of them from camel case to snake case.

View File

@ -0,0 +1,189 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import annotations
from copy import deepcopy
from enum import StrEnum
from json import JSONDecoder, JSONEncoder
from typing import Any, Optional, Self, Type, get_args, get_origin, get_type_hints
class Monkey():
key: str
def __init__(self, key: str = '_slugs'):
self.key = key
def patch(self, obj: dict[str, Any]) -> dict[str, Any]:
def inner(slug: list[str], value: Any):
if isinstance(value, dict):
value[self.key] = slug
for child_slug, child_value in value.items():
inner(slug + [child_slug], child_value)
return
if isinstance(value, list):
for child_value in value:
inner(slug, child_value)
copied = deepcopy(obj)
inner([], copied)
return copied
def slugs(self, obj: dict[str, Any]) -> list[str]:
return obj[self.key]
def clean(self, obj: dict[str, Any]) -> dict[str, Any]:
copied = deepcopy(obj)
del copied[self.key]
return copied
class CodingKey(StrEnum):
@classmethod
def keywords(cls, obj: dict[str, Any]) -> dict[str, Any]:
words = {}
for pair in list(cls):
# Errors are false positives.
native = pair.name # type: ignore
foreign = pair.value # type: ignore
value = obj.get(foreign)
words[native] = value
return words
class Codable():
__decoder = JSONDecoder()
__encoder = JSONEncoder()
__monkey = Monkey()
class CodingKeys(CodingKey):
pass
@classmethod
def decode(cls, content: str) -> Self:
decoded = cls.__decoder.decode(content)
patched = cls.__monkey.patch(decoded)
encoded = cls.__encoder.encode(patched)
decoder = Decoder(
monkey=cls.__monkey,
cls=cls
)
return decoder.decode(encoded)
def encode(self) -> str:
cls = type(self)
encoder = Encoder(
decoder=self.__decoder,
cls=cls
)
return encoder.encode(self)
class Decoder(JSONDecoder):
monkey: Monkey
cls: Type[Codable]
def __init__(
self,
monkey: Monkey,
cls: Type[Codable],
**kwargs
):
self.monkey = monkey
self.cls = cls
kwargs['object_hook'] = self.__object_hook
super().__init__(**kwargs)
def __object_hook(self, obj):
cls = self.cls
for foreign in self.monkey.slugs(obj):
native = cls.CodingKeys(foreign).name
if native is None:
return self.monkey.clean(obj)
types = get_type_hints(cls)
cls = self.__find_codable(types[native])
if cls is None:
return self.monkey.clean(obj)
cleaned = self.monkey.clean(obj)
return self.__init_codable(cls, cleaned)
def __find_codable(self, cls: Type) -> Optional[Type[Codable]]:
if issubclass(cls, Codable):
return cls
if get_origin(cls) is list:
item = get_args(cls)[0]
return self.__find_codable(item)
return None
def __init_codable(self, cls: Type[Codable], obj: dict[str, Any]) -> Codable:
keywords = cls.CodingKeys.keywords(obj)
return cls(**keywords)
class Encoder(JSONEncoder):
decoder: JSONDecoder
cls: Type[Codable]
def __init__(
self,
decoder: JSONDecoder,
cls: Type[Codable],
indent: int = 2,
**kwargs
):
self.decoder = decoder
self.cls = cls
kwargs['indent'] = indent
super().__init__(**kwargs)
def default(self, o):
obj = {}
for pair in list(self.cls.CodingKeys):
native = pair.name
foreign = pair.value
if not hasattr(o, native):
continue
value = getattr(o, native)
obj[foreign] = self.__prepare_value(value)
return obj
def __prepare_value(self, value: Any) -> Any:
if isinstance(value, Codable):
return self.__prepare_codable(value)
if isinstance(value, list):
return self.__prepare_list(value)
return value
def __prepare_codable(self, value: Codable) -> Any:
content = value.encode()
return self.decoder.decode(content)
def __prepare_list(self, value: list[Any]) -> list[Any]:
mapped = map(self.__prepare_value, value)
return list(mapped)

View File

@ -0,0 +1,154 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from __future__ import annotations
from dataclasses import dataclass
from textwrap import dedent
from typing import Optional
from unittest import TestCase
from . import Codable, CodingKey
@dataclass
class Fruit(Codable):
class CodingKeys(CodingKey):
name = 'fruit_name'
weight = 'fruitWeight'
texture = 'fruit_texture'
vitamins = 'fruitVitamins'
organic = 'fruit_organic'
name: str
weight: int
texture: Optional[str]
vitamins: list[str]
organic: bool
class CodablePlainTests(TestCase):
json = (
dedent(
'''
{
"fruit_name": "kiwi",
"fruitWeight": 100,
"fruit_texture": null,
"fruitVitamins": [
"Vitamin C",
"Vitamin K"
],
"fruit_organic": true
}
'''
)
.strip()
)
def test_decodes(self):
fruit = Fruit.decode(self.json)
self.assertEqual(fruit.name, 'kiwi')
self.assertEqual(fruit.weight, 100)
self.assertIsNone(fruit.texture)
self.assertEqual(fruit.vitamins, ['Vitamin C', 'Vitamin K'])
self.assertTrue(fruit.organic)
def test_encodes(self):
fruit = Fruit(
name='kiwi',
weight=100,
texture=None,
vitamins=['Vitamin C', 'Vitamin K'],
organic=True
)
content = fruit.encode()
self.assertEqual(content, self.json)
@dataclass
class Smoothie(Codable):
class CodingKeys(CodingKey):
recipe = 'recipe'
recipe: Recipe
@dataclass
class Recipe(Codable):
class CodingKeys(CodingKey):
ingredients = 'ingredients'
ingredients: list[Ingredient]
@dataclass
class Ingredient(Codable):
class CodingKeys(CodingKey):
name = 'name'
name: str
class CodableNestedTests(TestCase):
json = (
dedent(
'''
{
"recipe": {
"ingredients": [
{
"name": "kiwi"
}
]
}
}
'''
)
.strip()
)
def test_decodes(self):
smoothie = Smoothie.decode(self.json)
self.assertEqual(smoothie.recipe.ingredients[0].name, 'kiwi')
def test_encodes(self):
ingredient = Ingredient(name='kiwi')
recipe = Recipe(ingredients=[ingredient])
smoothie = Smoothie(recipe=recipe)
content = smoothie.encode()
self.assertEqual(content, self.json)
@dataclass
class Vegetable(Codable):
class CodingKeys(CodingKey):
name = 'name'
name: Optional[str]
class CodableMissedTests(TestCase):
source_json = '{}'
distribute_json = (
dedent(
'''
{
"name": null
}
'''
)
.strip()
)
def test_decodes(self):
vegetable = Vegetable.decode(self.source_json)
self.assertIsNone(vegetable.name)
def test_encodes(self):
vegetable = Vegetable(name=None)
content = vegetable.encode()
self.assertEqual(content, self.distribute_json)

View File

@ -0,0 +1,18 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from . import http
from . import optional

View File

@ -0,0 +1,44 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# TODO:
# https://github.com/python/typing/discussions/946
from http import HTTPStatus, HTTPMethod
from django.http import HttpRequest, HttpResponse
# TODO: Access-Control-Allow-Origin
def access_control_allow_origin():
pass
def method(meth: HTTPMethod):
def wrapper(func):
def inner(self, request: HttpRequest, *args, **kwargs):
if request.method is None:
return HttpResponse(
status=HTTPStatus.METHOD_NOT_ALLOWED
)
if request.method.upper() != meth.name:
return HttpResponse(
status=HTTPStatus.METHOD_NOT_ALLOWED
)
return func(self, request, *args, **kwargs)
return inner
return wrapper

View File

@ -0,0 +1,25 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from typing import Callable, Optional, TypeVar
T = TypeVar('T')
def expression(callback: Callable[[], T]) -> Optional[T]:
try:
return callback()
except Exception:
return None

View File

@ -0,0 +1,19 @@
"""
(c) Copyright Ascensio System SIA 2023
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from .configuration import *

View File

@ -0,0 +1,242 @@
"""
(c) Copyright Ascensio System SIA 2023
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
from os import environ
from os.path import abspath, dirname
from pathlib import Path
from typing import Dict
from urllib.parse import ParseResult, urlparse, urljoin
class ConfigurationManager:
version = '1.5.1'
def example_url(self) -> (ParseResult | None):
url = environ.get('EXAMPLE_URL')
if not url:
return None
return urlparse(url)
def document_server_public_url(self) -> ParseResult:
url = (
environ.get('DOCUMENT_SERVER_PUBLIC_URL') or
'http://document-server/'
)
return urlparse(url)
def document_server_private_url(self) -> ParseResult:
url = environ.get('DOCUMENT_SERVER_PRIVATE_URL')
if not url:
return self.document_server_public_url()
return urlparse(url)
def document_server_api_url(self) -> ParseResult:
base = self.document_server_public_url().geturl()
path = (
environ.get('DOCUMENT_SERVER_API_PATH') or
'web-apps/apps/api/documents/api.js'
)
url = urljoin(base, path)
return urlparse(url)
def document_server_preloader_url(self) -> ParseResult:
base = self.document_server_public_url().geturl()
path = (
environ.get('DOCUMENT_SERVER_PRELOADER_PATH') or
'web-apps/apps/api/documents/cache-scripts.html'
)
url = urljoin(base, path)
return urlparse(url)
def document_server_command_url(self) -> ParseResult:
base = self.document_server_private_url().geturl()
path = (
environ.get('DOCUMENT_SERVER_COMMAND_PATH') or
'coauthoring/CommandService.ashx'
)
url = urljoin(base, path)
return urlparse(url)
def document_server_converter_url(self) -> ParseResult:
base = self.document_server_private_url().geturl()
path = (
environ.get('DOCUMENT_SERVER_CONVERTER_PATH') or
'ConvertService.ashx'
)
url = urljoin(base, path)
return urlparse(url)
def jwt_secret(self) -> str:
return environ.get('JWT_SECRET') or ''
def jwt_header(self) -> str:
return environ.get('JWT_HEADER') or 'Authorization'
def jwt_use_for_request(self) -> bool:
use = environ.get('JWT_USE_FOR_REQUEST')
if use is None:
return True
if use == 'true':
return True
return False
def ssl_verify_peer_mode_enabled(self) -> bool:
enabled = environ.get('SSL_VERIFY_PEER_MODE_ENABLED')
if enabled is None:
return False
if enabled == 'true':
return True
return False
def storage_path(self) -> Path:
storage_path = environ.get('STORAGE_PATH') or 'storage'
storage_directory = Path(storage_path)
if storage_directory.is_absolute():
return storage_directory
current_directory = Path(dirname(abspath(__file__)))
return current_directory.joinpath('../..', storage_directory).resolve()
def maximum_file_size(self) -> int:
size = environ.get('MAXIMUM_FILE_SIZE')
if size:
return int(size)
return 5 * 1024 * 1024
def conversion_timeout(self) -> int:
timeout = environ.get('CONVERSION_TIMEOUT')
if timeout:
return int(timeout)
return 120 * 1000
def fillable_file_extensions(self) -> list[str]:
return [
'.docx',
'.oform'
]
def viewable_file_extensions(self) -> list[str]:
return [
'.djvu',
'.oxps',
'.pdf',
'.xps'
]
def editable_file_extensions(self) -> list[str]:
return [
'.csv', '.docm', '.docx',
'.docxf', '.dotm', '.dotx',
'.epub', '.fb2', '.html',
'.odp', '.ods', '.odt',
'.otp', '.ots', '.ott',
'.potm', '.potx', '.ppsm',
'.ppsx', '.pptm', '.pptx',
'.rtf', '.txt', '.xlsm',
'.xlsx', '.xltm', '.xltx'
]
def convertible_file_extensions(self) -> list[str]:
return [
'.doc', '.dot', '.dps', '.dpt',
'.epub', '.et', '.ett', '.fb2',
'.fodp', '.fods', '.fodt', '.htm',
'.html', '.mht', '.mhtml', '.odp',
'.ods', '.odt', '.otp', '.ots',
'.ott', '.pot', '.pps', '.ppt',
'.rtf', '.stw', '.sxc', '.sxi',
'.sxw', '.wps', '.wpt', '.xls',
'.xlsb', '.xlt', '.xml'
]
def spreadsheet_file_extensions(self) -> list[str]:
return [
'.xls', '.xlsx',
'.xlsm', '.xlsb',
'.xlt', '.xltx',
'.xltm', '.ods',
'.fods', '.ots',
'.csv'
]
def presentation_file_extensions(self) -> list[str]:
return [
'.pps', '.ppsx',
'.ppsm', '.ppt',
'.pptx', '.pptm',
'.pot', '.potx',
'.potm', '.odp',
'.fodp', '.otp'
]
def document_file_extensions(self) -> list[str]:
return [
'.doc', '.docx', '.docm',
'.dot', '.dotx', '.dotm',
'.odt', '.fodt', '.ott',
'.rtf', '.txt', '.html',
'.htm', '.mht', '.xml',
'.pdf', '.djvu', '.fb2',
'.epub', '.xps', '.oxps',
'.oform'
]
def languages(self) -> Dict[str, str]:
return {
'en': 'English',
'hy': 'Armenian',
'az': 'Azerbaijani',
'eu': 'Basque',
'be': 'Belarusian',
'bg': 'Bulgarian',
'ca': 'Catalan',
'zh': 'Chinese (Simplified)',
'zh-TW': 'Chinese (Traditional)',
'cs': 'Czech',
'da': 'Danish',
'nl': 'Dutch',
'fi': 'Finnish',
'fr': 'French',
'gl': 'Galego',
'de': 'German',
'el': 'Greek',
'hu': 'Hungarian',
'id': 'Indonesian',
'it': 'Italian',
'ja': 'Japanese',
'ko': 'Korean',
'lo': 'Lao',
'lv': 'Latvian',
'ms': 'Malay (Malaysia)',
'no': 'Norwegian',
'pl': 'Polish',
'pt': 'Portuguese (Brazil)',
'pt-PT': 'Portuguese (Portugal)',
'ro': 'Romanian',
'ru': 'Russian',
'si': 'Sinhala (Sri Lanka)',
'sk': 'Slovak',
'sl': 'Slovenian',
'es': 'Spanish',
'sv': 'Swedish',
'tr': 'Turkish',
'uk': 'Ukrainian',
'vi': 'Vietnamese',
'aa-AA': 'Test Language'
}

View File

@ -0,0 +1,301 @@
"""
(c) Copyright Ascensio System SIA 2023
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
from os import environ
from unittest import TestCase
from unittest.mock import patch
from urllib.parse import urlparse
from . import ConfigurationManager
class ConfigurationManagerTests(TestCase):
def test_corresponds_the_latest_version(self):
config = ConfigurationManager()
self.assertEqual(config.version, '1.5.1')
class ConfigurationManagerExampleURLTests(TestCase):
def test_assigns_a_default_value(self):
config = ConfigurationManager()
url = config.example_url()
self.assertIsNone(url)
@patch.dict(environ, {
'EXAMPLE_URL': 'http://localhost'
})
def test_assigns_a_value_from_the_environment(self):
config = ConfigurationManager()
url = config.example_url()
self.assertEqual(url.geturl(), 'http://localhost')
class ConfigurationManagerDocumentServerPublicURLTests(TestCase):
def test_assigns_a_default_value(self):
config = ConfigurationManager()
url = config.document_server_public_url()
self.assertEqual(url.geturl(), 'http://document-server/')
@patch.dict(environ, {
'DOCUMENT_SERVER_PUBLIC_URL': 'http://localhost'
})
def test_assigns_a_value_from_the_environment(self):
config = ConfigurationManager()
url = config.document_server_public_url()
self.assertEqual(url.geturl(), 'http://localhost')
class ConfigurationManagerDocumentServerPrivateURLTests(TestCase):
def test_assigns_a_default_value(self):
config = ConfigurationManager()
url = config.document_server_private_url()
self.assertEqual(url.geturl(), 'http://document-server/')
@patch.dict(environ, {
'DOCUMENT_SERVER_PRIVATE_URL': 'http://localhost'
})
def test_assigns_a_value_from_the_environment(self):
config = ConfigurationManager()
url = config.document_server_private_url()
self.assertEqual(url.geturl(), 'http://localhost')
class ConfigurationManagerDocumentServerAPIURLTests(TestCase):
@patch.object(
ConfigurationManager,
'document_server_public_url',
return_value=urlparse('http://localhost')
)
def test_assigns_a_default_value(self, _):
config = ConfigurationManager()
url = config.document_server_api_url()
self.assertEqual(
url.geturl(),
'http://localhost/web-apps/apps/api/documents/api.js'
)
@patch.object(
ConfigurationManager,
'document_server_public_url',
return_value=urlparse('http://localhost')
)
@patch.dict(environ, {
'DOCUMENT_SERVER_API_PATH': '/api'
})
def test_assigns_a_value_from_the_environment(self, _):
config = ConfigurationManager()
url = config.document_server_api_url()
self.assertEqual(
url.geturl(),
'http://localhost/api'
)
class ConfigurationManagerDocumentServerPreloaderURLTests(TestCase):
@patch.object(
ConfigurationManager,
'document_server_public_url',
return_value=urlparse('http://localhost')
)
def test_assigns_a_default_value(self, _):
config = ConfigurationManager()
url = config.document_server_preloader_url()
self.assertEqual(
url.geturl(),
'http://localhost/web-apps/apps/api/documents/cache-scripts.html'
)
@patch.object(
ConfigurationManager,
'document_server_public_url',
return_value=urlparse('http://localhost')
)
@patch.dict(environ, {
'DOCUMENT_SERVER_PRELOADER_PATH': '/preloader'
})
def test_assigns_a_value_from_the_environment(self, _):
config = ConfigurationManager()
url = config.document_server_preloader_url()
self.assertEqual(
url.geturl(),
'http://localhost/preloader'
)
class ConfigurationManagerDocumentServerCommandURLTests(TestCase):
@patch.object(
ConfigurationManager,
'document_server_private_url',
return_value=urlparse('http://localhost')
)
def test_assigns_a_default_value(self, _):
config = ConfigurationManager()
url = config.document_server_command_url()
self.assertEqual(
url.geturl(),
'http://localhost/coauthoring/CommandService.ashx'
)
@patch.object(
ConfigurationManager,
'document_server_private_url',
return_value=urlparse('http://localhost')
)
@patch.dict(environ, {
'DOCUMENT_SERVER_COMMAND_PATH': '/command'
})
def test_assigns_a_value_from_the_environment(self, _):
config = ConfigurationManager()
url = config.document_server_command_url()
self.assertEqual(
url.geturl(),
'http://localhost/command'
)
class ConfigurationManagerDocumentServerConverterURLTests(TestCase):
@patch.object(
ConfigurationManager,
'document_server_private_url',
return_value=urlparse('http://localhost')
)
def test_assigns_a_default_value(self, _):
config = ConfigurationManager()
url = config.document_server_converter_url()
self.assertEqual(
url.geturl(),
'http://localhost/ConvertService.ashx'
)
@patch.object(
ConfigurationManager,
'document_server_private_url',
return_value=urlparse('http://localhost')
)
@patch.dict(environ, {
'DOCUMENT_SERVER_CONVERTER_PATH': '/converter'
})
def test_assigns_a_value_from_the_environment(self, _):
config = ConfigurationManager()
url = config.document_server_converter_url()
self.assertEqual(
url.geturl(),
'http://localhost/converter'
)
class ConfigurationManagerJWTSecretTests(TestCase):
def test_assigns_a_default_value(self):
config = ConfigurationManager()
secret = config.jwt_secret()
self.assertEqual(secret, '')
@patch.dict(environ, {
'JWT_SECRET': 'your-256-bit-secret'
})
def test_assigns_a_value_from_the_environment(self):
config = ConfigurationManager()
secret = config.jwt_secret()
self.assertEqual(secret, 'your-256-bit-secret')
class ConfigurationManagerJWTHeaderTests(TestCase):
def test_assigns_a_default_value(self):
config = ConfigurationManager()
header = config.jwt_header()
self.assertEqual(header, 'Authorization')
@patch.dict(environ, {
'JWT_HEADER': 'Proxy-Authorization'
})
def test_assigns_a_value_from_the_environment(self):
config = ConfigurationManager()
header = config.jwt_header()
self.assertEqual(header, 'Proxy-Authorization')
class ConfigurationManagerJWTUseForRequest(TestCase):
def test_assigns_a_default_value(self):
config = ConfigurationManager()
use = config.jwt_use_for_request()
self.assertTrue(use)
@patch.dict(environ, {
'JWT_USE_FOR_REQUEST': 'false'
})
def test_assigns_a_value_from_the_environment(self):
config = ConfigurationManager()
use = config.jwt_use_for_request()
self.assertFalse(use)
class ConfigurationManagerSSLTests(TestCase):
def test_assigns_a_default_value(self):
config = ConfigurationManager()
enabled = config.ssl_verify_peer_mode_enabled()
self.assertFalse(enabled)
@patch.dict(environ, {
'SSL_VERIFY_PEER_MODE_ENABLED': 'true'
})
def test_assigns_a_value_from_the_environment(self):
config = ConfigurationManager()
enabled = config.ssl_verify_peer_mode_enabled()
self.assertTrue(enabled)
class ConfigurationManagerStoragePathTests(TestCase):
def test_assigns_a_default_value(self):
config = ConfigurationManager()
path = config.storage_path()
self.assertTrue(path.is_absolute())
self.assertEqual(path.name, 'storage')
@patch.dict(environ, {
'STORAGE_PATH': 'directory'
})
def test_assigns_a_relative_path_from_the_environment(self):
config = ConfigurationManager()
path = config.storage_path()
self.assertTrue(path.is_absolute())
self.assertEqual(path.name, 'directory')
@patch.dict(environ, {
'STORAGE_PATH': '/directory'
})
def test_assigns_an_absolute_path_from_the_environment(self):
config = ConfigurationManager()
path = config.storage_path()
self.assertEqual(path.as_uri(), 'file:///directory')
class ConfigurationManagerMaximumFileSizeTests(TestCase):
def test_assigns_a_default_value(self):
config = ConfigurationManager()
size = config.maximum_file_size()
self.assertEqual(size, 5_242_880)
@patch.dict(environ, {
'MAXIMUM_FILE_SIZE': '10'
})
def test_assigns_a_value_from_the_environment(self):
config = ConfigurationManager()
size = config.maximum_file_size()
self.assertEqual(size, 10)
class ConfigurationManagerConversionTimeoutTests(TestCase):
def test_assigns_a_default_value(self):
config = ConfigurationManager()
timeout = config.conversion_timeout()
self.assertEqual(timeout, 120_000)
@patch.dict(environ, {
'CONVERSION_TIMEOUT': '10'
})
def test_assigns_a_value_from_the_environment(self):
config = ConfigurationManager()
timeout = config.conversion_timeout()
self.assertEqual(timeout, 10)

View File

@ -0,0 +1,19 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# https://api.onlyoffice.com/editors/callback#history
from .history import *

View File

@ -0,0 +1,595 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# TODO: add types for kwargs.
# https://github.com/python/mypy/issues/14697
from __future__ import annotations
from dataclasses import dataclass
from datetime import datetime
from functools import reduce
from http import HTTPMethod
# from http import HTTPStatus
from json import loads
from pathlib import Path
from shutil import copy
from typing import Any, Iterator, Optional
from uuid import uuid1
from urllib.parse import \
ParseResult, \
parse_qs, \
quote, \
urlencode, \
urljoin, \
urlparse
from django.http import FileResponse, HttpRequest, HttpResponse
# Pylance doesn't see the HttpResponseBase export from the django.http.
from django.http.response import HttpResponseBase
from src.codable import Codable, CodingKey
from src.configuration import ConfigurationManager
from src.common import http, optional
from src.request import RequestManager
from src.storage import StorageManager
from src.utils import jwtManager
from src.utils.users import find_user
@dataclass
class History(Codable):
class CodingKeys(CodingKey):
current_version = 'currentVersion'
history = 'history'
current_version: int
history: list[HistoryItem]
@dataclass
class HistoryItem(Codable):
class CodingKeys(CodingKey):
changes = 'changes'
created = 'created'
key = 'key'
server_version = 'serverVersion'
user = 'user'
version = 'version'
changes: list[HistoryChangesItem]
created: str
key: str
server_version: Optional[str]
user: Optional[HistoryUser]
version: int
@dataclass
class HistoryChanges(Codable):
class CodingKeys(CodingKey):
server_version = 'serverVersion'
changes = 'changes'
server_version: Optional[str]
changes: list[HistoryChangesItem]
@dataclass
class HistoryChangesItem(Codable):
class CodingKeys(CodingKey):
created = 'created'
user = 'user'
created: str
user: HistoryUser
@dataclass
class HistoryUser(Codable):
class CodingKeys(CodingKey):
id = 'id'
name = 'name'
id: str
name: str
@dataclass
class HistoryData(Codable):
class CodingKeys(CodingKey):
changes_url = 'changesUrl'
file_type = 'fileType'
key = 'key'
previous = 'previous'
token = 'token'
url = 'url'
direct_url = 'directUrl'
version = 'version'
changes_url: Optional[str]
file_type: Optional[str]
key: str
previous: Optional[HistoryData]
token: Optional[str]
url: Optional[str]
direct_url: Optional[str]
version: int
class HistoryController():
@http.method(HTTPMethod.GET)
def history(self, request: HttpRequest, **kwargs: Any) -> HttpResponseBase:
'''
https://api.onlyoffice.com/editors/methods#refreshHistory
```http
GET {{base_url}}/history/{{source_basename}}?userHost={{user_host}} HTTP/1.1
```
'''
config_manager = ConfigurationManager()
request_manager = RequestManager(
request=request
)
source_basename: str = kwargs['source_basename']
optional_user_host = request.GET.get('userHost')
user_host = request_manager.resolve_address(optional_user_host)
storage_manager = StorageManager(
config_manager=config_manager,
user_host=user_host,
source_basename=source_basename
)
history_manager = HistoryManager(
storage_manager=storage_manager
)
history = history_manager.history()
return HttpResponse(
history.encode(),
content_type='application/json'
)
@http.method(HTTPMethod.GET)
def data(self, request: HttpRequest, **kwargs: Any) -> HttpResponseBase:
'''
https://api.onlyoffice.com/editors/methods#setHistoryData
```http
GET {{base_url}}/history/{{source_basename}}/{{version}}/data?userHost={{user_host}}&direct HTTP/1.1
```
'''
config_manager = ConfigurationManager()
request_manager = RequestManager(
request=request
)
direct = 'direct' in kwargs
example_url: Optional[ParseResult] = None
if direct:
example_url = config_manager.example_url()
base_url = request_manager.resolve_base_url(example_url)
source_basename: str = kwargs['source_basename']
version: int = kwargs['version']
optional_user_host = request.GET.get('userHost')
user_host = request_manager.resolve_address(optional_user_host)
storage_manager = StorageManager(
config_manager=config_manager,
user_host=user_host,
source_basename=source_basename
)
history_manager = HistoryManager(
storage_manager=storage_manager
)
history_data = history_manager.data(
base_url,
version,
user_host,
direct
)
if jwtManager.isEnabled():
history_data.token = jwtManager.encode(loads(history_data.encode()))
return HttpResponse(
history_data.encode(),
content_type='application/json'
)
@http.method(HTTPMethod.GET)
def download(self, request: HttpRequest, **kwargs: Any) -> HttpResponseBase:
'''
```http
GET {{base_url}}/history/{{source_basename}}/{{version}}/download/{{basename}}?userHost={{user_host}} HTTP/1.1
```
'''
config_manager = ConfigurationManager()
request_manager = RequestManager(
request=request
)
source_basename: str = kwargs['source_basename']
version: int = kwargs['version']
basename: str = kwargs['basename']
optional_user_host = request.GET.get('userHost')
user_host = request_manager.resolve_address(optional_user_host)
storage_manager = StorageManager(
config_manager=config_manager,
user_host=user_host,
source_basename=source_basename
)
history_manager = HistoryManager(
storage_manager=storage_manager
)
version_directory = history_manager.version_directory(version)
file = version_directory.joinpath(basename)
# if not file.exists():
# return HttpResponse(
# '{ "error": "not exists" }',
# content_type='application/json'
# )
return FileResponse(
open(file, 'rb'),
as_attachment=True
)
@http.method(HTTPMethod.PUT)
def restore(self, request: HttpRequest, **kwargs: Any) -> HttpResponseBase:
'''
```http
PUT {{base_url}}/history/{{source_basename}}/{{version}}/restore?userHost={{user_host}}&userId={{user_id}} HTTP/1.1
```
'''
config_manager = ConfigurationManager()
request_manager = RequestManager(
request=request
)
source_basename: str = kwargs['source_basename']
version: int = kwargs['version']
optional_user_host = request.GET.get('userHost')
user_host = request_manager.resolve_address(optional_user_host)
user_id = request.GET.get('userId')
storage_manager = StorageManager(
config_manager=config_manager,
user_host=user_host,
source_basename=source_basename
)
history_manager = HistoryManager(
storage_manager=storage_manager
)
raw_user = find_user(user_id)
user = HistoryUser(
id=raw_user.id,
name=raw_user.name
)
history_manager.restore(version, user)
return HttpResponse()
@dataclass
class HistoryManager():
storage_manager: StorageManager
# History Management
def history(self) -> History:
history = History(
current_version=self.latest_version(),
history=[]
)
for version in range(
HistoryManager.minimal_version,
history.current_version + 1
):
item = self.item(version)
if item is None:
continue
history.history.append(item)
return history
# Data Management
def data(
self,
base_url: ParseResult,
version: int,
user_host: str,
direct: bool
) -> Optional[HistoryData]:
key = self.key(version)
if key is None:
return None
previous_version = version - 1
previous = self.data(
base_url,
previous_version,
user_host,
direct
)
history_url = self.history_url(base_url)
version_url = self.version_url(history_url, version)
changes_url: Optional[str] = None
if previous is not None:
file = self.diff_file(version)
download_url = self.download_url(version_url, file.name)
personal_url = self.personalize_url(download_url, user_host)
changes_url = personal_url.geturl()
file = self.item_file(version)
file_type = file.suffix.replace('.', '')
download_url = self.download_url(version_url, file.name)
personal_url = self.personalize_url(download_url, user_host)
url = personal_url.geturl()
direct_url: Optional[str] = None
if direct:
direct_url = download_url.geturl()
return HistoryData(
changes_url=changes_url,
file_type=file_type,
key=key,
previous=previous,
token=None,
url=url,
direct_url=direct_url,
version=version
)
def personalize_url(self, url: ParseResult, user_host: str) -> ParseResult:
parsed_query = parse_qs(url.query)
parsed_query.update({
# False positive: the update supports dict.
'userHost': user_host # type: ignore # noqa: E261
})
query = urlencode(parsed_query)
return ParseResult(
scheme=url.scheme,
netloc=url.netloc,
path=url.path,
params=url.params,
query=query,
fragment=url.fragment
)
def download_url(self, base_url: ParseResult, basename: str) -> ParseResult:
base = base_url.geturl()
url = reduce(urljoin, [
f'{base}/',
'download/',
basename
])
return urlparse(f'{url}')
def version_url(self, base_url: ParseResult, version: int) -> ParseResult:
base = base_url.geturl()
url = reduce(urljoin, [
f'{base}/',
f'{version}'
])
return urlparse(f'{url}')
def history_url(self, base_url: ParseResult) -> ParseResult:
base = base_url.geturl()
source_basename = quote(self.storage_manager.source_basename)
url = reduce(urljoin, [
f'{base}/',
'history/',
source_basename
])
return urlparse(f'{url}')
# Rejuvenation Management
# def force_save(self)
def save(
self,
changes: HistoryChanges,
diff: Iterator[Any],
item: Iterator[Any]
):
version = self.next_version()
self.bootstrap_key(version)
self.write_changes(version, changes)
self.write_diff(version, diff)
self.write_item(version, item)
source_file = self.storage_manager.source_file()
file = self.item_file(version)
copy(f'{file}', f'{source_file}')
def restore(self, version: int, user: HistoryUser):
recovery_file = self.item_file(version)
source_file = self.storage_manager.source_file()
copy(f'{recovery_file}', f'{source_file}')
version = self.next_version()
self.bootstrap(version, user)
def bootstrap_initial_item(self, user: HistoryUser):
self.bootstrap(HistoryManager.minimal_version, user)
def bootstrap(self, version: int, user: HistoryUser):
self.bootstrap_key(version)
self.bootstrap_changes(version, user)
self.bootstrap_item(version)
# Item Management
def bootstrap_item(self, version: int):
source_file = self.storage_manager.source_file()
file = self.item_file(version)
copy(f'{source_file}', f'{file}')
def write_item(self, version: int, stream: Iterator[Any]):
file = self.item_file(version)
with open(f'{file}', 'wb') as output:
for chunk in stream:
output.write(chunk)
def item(self, version: int) -> Optional[HistoryItem]:
key = self.key(version)
if key is None:
return None
changes = self.changes(version)
if changes is None:
return None
first_changes = optional.expression(lambda: changes.changes[0])
if first_changes is None:
return None
return HistoryItem(
changes=changes.changes,
created=first_changes.created,
key=key,
server_version=changes.server_version,
user=first_changes.user,
version=version
)
def item_file(self, version: int) -> Path:
directory = self.version_directory(version)
source_file = self.storage_manager.source_file()
return directory.joinpath(f'prev{source_file.suffix}')
# Changes Management
def bootstrap_changes(self, version: int, user: HistoryUser):
changes = HistoryManager.generate_changes(user)
self.write_changes(version, changes)
def write_changes(self, version: int, changes: HistoryChanges):
content = changes.encode()
file = self.changes_file(version)
file.write_text(content, 'utf-8')
def changes(self, version: int) -> Optional[HistoryChanges]:
file = self.changes_file(version)
if not file.exists():
return None
content = file.read_text('utf-8')
return HistoryChanges.decode(content)
def changes_file(self, version: int) -> Path:
directory = self.version_directory(version)
return directory.joinpath('changes.json')
def write_diff(self, version, stream: Iterator[Any]):
file = self.diff_file(version)
with open(f'{file}', 'wb') as output:
for chunk in stream:
output.write(chunk)
def diff_file(self, version: int) -> Path:
directory = self.version_directory(version)
return directory.joinpath('diff.zip')
@classmethod
def generate_changes(cls, user: HistoryUser) -> HistoryChanges:
today = datetime.today()
created = today.strftime('%Y-%m-%d %H:%M:%S')
item = HistoryChangesItem(
created=created,
user=user
)
return HistoryChanges(
server_version=None,
changes=[
item
]
)
# Key Management
def bootstrap_key(self, version: int):
key = HistoryManager.generate_key()
self.write_key(version, key)
def write_key(self, version: int, key: str):
file = self.key_file(version)
file.write_text(key, 'utf-8')
def key(self, version: int) -> Optional[str]:
file = self.key_file(version)
if not file.exists():
return None
content = file.read_text('utf-8')
return content
def key_file(self, version: int) -> Path:
directory = self.version_directory(version)
return directory.joinpath('key.txt')
@classmethod
def generate_key(cls) -> str:
key = uuid1()
return f'{key}'
# Version Management
# def version_file(self, version: int, basename: str) -> Path
def version_directory(self, version: int) -> Path:
parent_directory = self.history_directory()
directory = parent_directory.joinpath(f'{version}')
if not directory.exists():
directory.mkdir()
return directory
# Storage Management
minimal_version = 1
def next_version(self) -> int:
version = self.latest_version()
return version + 1
def latest_version(self) -> int:
directory = self.history_directory()
version = 0
for file in directory.iterdir():
if not file.is_dir():
continue
if not len(list(file.iterdir())) > 0:
continue
version += 1
return version
def history_directory(self) -> Path:
file = self.storage_manager.source_file()
directory = file.parent.joinpath(f'{file.name}-hist')
if not directory.exists():
directory.mkdir()
return directory

View File

@ -0,0 +1,19 @@
"""
(c) Copyright Ascensio System SIA 2023
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from .proxy import *

View File

@ -0,0 +1,53 @@
"""
(c) Copyright Ascensio System SIA 2023
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
from dataclasses import dataclass
from urllib.parse import ParseResult, urlparse
from src.configuration import ConfigurationManager
@dataclass
class ProxyManager():
config_manager: ConfigurationManager
def resolve_document_server_url(self, url: str) -> ParseResult:
parsed_url = urlparse(url)
if not self.__refer_document_server_public_url(parsed_url):
return parsed_url
return self.__redirect_document_server_public_url(parsed_url)
def __refer_document_server_public_url(self, url: ParseResult) -> bool:
public_url = self.config_manager.document_server_public_url()
return (
url.scheme == public_url.scheme and
url.hostname == public_url.hostname and
url.port == public_url.port
)
def __redirect_document_server_public_url(self, url: ParseResult) -> ParseResult:
private_url = self.config_manager.document_server_private_url()
return ParseResult(
scheme=private_url.scheme,
netloc=f'{private_url.hostname}:{private_url.port}',
path=url.path,
params=url.params,
query=url.query,
fragment=url.fragment
)

View File

@ -0,0 +1,66 @@
"""
(c) Copyright Ascensio System SIA 2023
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
from unittest import TestCase
from unittest.mock import patch
from urllib.parse import urlparse
from src.configuration import ConfigurationManager
from . import ProxyManager
class ProxyManagerTests(TestCase):
@patch.object(
ConfigurationManager,
'document_server_public_url',
return_value=urlparse('http://localhost:3000')
)
@patch.object(
ConfigurationManager,
'document_server_private_url',
return_value=urlparse('http://proxy:3001')
)
def test_resolves_a_url_that_refers_to_the_document_server_public_url(self, *_):
config_manager = ConfigurationManager()
proxy_manager = ProxyManager(config_manager)
url = 'http://localhost:3000/endpoint?query=string'
resolved_url = proxy_manager.resolve_document_server_url(url)
self.assertEqual(
resolved_url.geturl(),
'http://proxy:3001/endpoint?query=string'
)
@patch.object(
ConfigurationManager,
'document_server_public_url',
return_value=urlparse('http://localhost:3000')
)
def test_resolves_a_url_that_does_not_refers_to_the_document_server_public_url(self, _):
config_manager = ConfigurationManager()
proxy_manager = ProxyManager(config_manager)
url = 'http://localhost:8080/endpoint?query=string'
resolved_url = proxy_manager.resolve_document_server_url(url)
self.assertEqual(
resolved_url.geturl(),
'http://localhost:8080/endpoint?query=string'
)

View File

@ -0,0 +1,17 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from .request import *

View File

@ -0,0 +1,57 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from dataclasses import dataclass
from re import sub
from typing import Optional
from urllib.parse import ParseResult
from django.http import HttpRequest
@dataclass
class RequestManager():
request: HttpRequest
def resolve_base_url(
self,
base_url: Optional[ParseResult] = None
) -> ParseResult:
return base_url or self.__base_url()
def __base_url(self):
scheme = (
self.request.headers.get('X-Forwarded-Proto') or
self.request.scheme or
'http'
)
netloc = self.request.get_host()
return ParseResult(
scheme=scheme,
netloc=netloc,
path='',
params='',
query='',
fragment=''
)
def resolve_address(self, address: Optional[str] = None) -> str:
raw = address or self.__address()
return sub(r'[^0-9\-.a-zA-Z_=]', '_', raw)
def __address(self) -> str:
forwarded = self.request.headers.get('X-Forwarded-For')
if forwarded:
return forwarded.split(',')[0]
return self.request.META['REMOTE_ADDR']

View File

@ -1,103 +0,0 @@
"""
Django settings for example project.
Generated by 'django-admin startproject' using Django 2.2.6.
For more information on this file, see
https://docs.djangoproject.com/en/3.1/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""
import os
import config
import mimetypes
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '7a5qnm_bv)iskjhx%4cbwwdmjev03%zewm=3@4s*uz)el#ds5o'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = [
'*'
]
X_FRAME_OPTIONS = 'ALLOWALL'
XS_SHARING_ALLOWED_METHODS = ['GET']
# Application definition
INSTALLED_APPS = [
'django.contrib.contenttypes',
'django.contrib.sessions',
]
MIDDLEWARE = [
'src.utils.historyManager.CorsHeaderMiddleware',
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'src.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [ 'templates' ],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
],
},
},
]
WSGI_APPLICATION = 'src.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.1/ref/settings/#databases
DATABASES = {}
# Password validation
# https://docs.djangoproject.com/en/3.1/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = []
# Internationalization
# https://docs.djangoproject.com/en/3.1/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
mimetypes.add_type("text/javascript", ".js", True)
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = ( os.path.join('static'), os.path.join(config.STORAGE_PATH), os.path.join('assets/sample'))

View File

@ -0,0 +1,17 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from .storage import StorageManager

View File

@ -0,0 +1,42 @@
#
# (c) Copyright Ascensio System SIA 2023
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
from dataclasses import dataclass
from pathlib import Path
from src.configuration import ConfigurationManager
@dataclass
class StorageManager():
config_manager: ConfigurationManager
user_host: str
source_basename: str
def source_file(self) -> Path:
directory = self.user_directory()
return directory.joinpath(self.source_basename)
def user_directory(self) -> Path:
parent_directory = self.storage_directory()
directory = parent_directory.joinpath(self.user_host)
if not directory.exists():
directory.mkdir()
return directory
def storage_directory(self) -> Path:
directory = self.config_manager.storage_path()
if not directory.exists():
directory.mkdir()
return directory

View File

@ -1,41 +0,0 @@
"""
(c) Copyright Ascensio System SIA 2023
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
from django.urls import path, re_path
from src.views import index, actions
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
urlpatterns = [
path('', index.default),
path('upload', actions.upload),
path('download', actions.download),
path('downloadhistory', actions.downloadhistory),
path('convert', actions.convert),
path('create', actions.createNew),
path('edit', actions.edit),
path('track', actions.track),
path('remove', actions.remove),
path('csv', actions.csv),
path('files', actions.files),
path('saveas', actions.saveAs),
path('rename', actions.rename),
path('reference', actions.reference)
]
urlpatterns += staticfiles_urlpatterns()

View File

@ -17,7 +17,6 @@
"""
import config
import os
import shutil
import io
@ -27,24 +26,30 @@ import time
import urllib.parse
import magic
from uuid import uuid1
from django.conf import settings
from django.http import HttpResponse, HttpResponseRedirect, FileResponse
from src import settings
from . import fileUtils, historyManager
from src.configuration import ConfigurationManager
def isCanFillForms(ext):
return ext in config.DOC_SERV_FILLFORMS
config = ConfigurationManager()
return ext in config.fillable_file_extensions()
# check if the file extension can be viewed
def isCanView(ext):
return ext in config.DOC_SERV_VIEWED
config = ConfigurationManager()
return ext in config.viewable_file_extensions()
# check if the file extension can be edited
def isCanEdit(ext):
return ext in config.DOC_SERV_EDITED
config = ConfigurationManager()
return ext in config.editable_file_extensions()
# check if the file extension can be converted
def isCanConvert(ext):
return ext in config.DOC_SERV_CONVERT
config = ConfigurationManager()
return ext in config.convertible_file_extensions()
# check if the file extension is supported by the editor (it can be viewed or edited or converted)
def isSupportedExt(ext):
@ -87,8 +92,10 @@ def getCorrectName(filename, req):
# get server url
def getServerUrl (forDocumentServer, req):
if (forDocumentServer and config.EXAMPLE_DOMAIN is not None):
return config.EXAMPLE_DOMAIN
config = ConfigurationManager()
example_url = config.example_url()
if (forDocumentServer and example_url is not None):
return example_url.geturl()
else:
return req.headers.get("x-forwarded-proto") or req.scheme + "://" + req.get_host()
@ -122,7 +129,8 @@ def getRootFolder(req):
else:
curAdr = req.META['REMOTE_ADDR']
directory = config.STORAGE_PATH if os.path.isabs(config.STORAGE_PATH) else os.path.join(config.STORAGE_PATH, curAdr)
config = ConfigurationManager()
directory = config.storage_path().joinpath(curAdr)
if not os.path.exists(directory): # if such a directory does not exist, make it
os.makedirs(directory)
@ -136,7 +144,8 @@ def getHistoryPath(filename, file, version, req):
else:
curAdr = req.META['REMOTE_ADDR']
directory = os.path.join(config.STORAGE_PATH, curAdr)
config = ConfigurationManager()
directory = config.storage_path().joinpath(curAdr)
if not os.path.exists(directory): # the directory with host address doesn't exist
filePath = os.path.join(getRootFolder(req), f'{filename}-hist', version, file)
else:
@ -157,10 +166,11 @@ def getForcesavePath(filename, req, create):
else:
curAdr = req.META['REMOTE_ADDR']
directory = os.path.join(config.STORAGE_PATH, curAdr)
config = ConfigurationManager()
directory = config.storage_path().joinpath(curAdr)
if not os.path.exists(directory): # the directory with host address doesn't exist
return ""
directory = os.path.join(directory, f'{filename}-hist') # get the path to the history of the given file
if (not os.path.exists(directory)):
if create: # if the history directory doesn't exist
@ -208,9 +218,10 @@ def saveFile(response, path):
file.write(chunk)
return
# download file from the given url
# download file from the given url
def downloadFileFromUri(uri, path = None, withSave = False):
resp = requests.get(uri, stream=True, verify = config.DOC_SERV_VERIFY_PEER, timeout=5)
config = ConfigurationManager()
resp = requests.get(uri, stream=True, verify = config.ssl_verify_peer_mode_enabled(), timeout=5)
status_code = resp.status_code
if status_code != 200: # checking status code
raise RuntimeError('Document editing service returned status: %s' % status_code)
@ -227,7 +238,7 @@ def createSample(fileType, sample, req):
if not sample:
sample = 'false'
sampleName = 'sample' if sample == 'true' else 'new' # create sample or new template
sampleName = 'sample' if sample == 'true' else 'new' # create sample or new template
filename = getCorrectName(f'{sampleName}{ext}', req) # get file name with an index if such a file name already exists
path = getStoragePath(filename, req)
@ -247,13 +258,8 @@ def removeFile(filename, req):
# generate file key
def generateFileKey(filename, req):
path = getStoragePath(filename, req)
uri = getFileUri(filename, False, req)
stat = os.stat(path) # get the directory parameters
h = str(hash(f'{uri}_{stat.st_mtime_ns}')) # get the hash value of the file url and the date of its last modification and turn it into a string format
replaced = re.sub(r'[^0-9-.a-zA-Z_=]', '_', h)
return replaced[:20] # take the first 20 characters for the key
key = uuid1()
return f'{key}'
# generate the document key value
def generateRevisionId(expectedKey):
@ -273,7 +279,7 @@ def getFilesInfo(req):
stats = os.stat(os.path.join(getRootFolder(req), f.get("title"))) # get file information
result.append( # write file parameters to the file object
{ "version" : historyManager.getFileVersion(historyManager.getHistoryDir(getStoragePath(f.get("title"), req))),
"id" : generateFileKey(f.get("title"), req),
"id" : generateFileKey(f.get("title"), req),
"contentLength" : "%.2f KB" % (stats.st_size/1024),
"pureContentLength" : stats.st_size,
"title" : f.get("title"),
@ -285,7 +291,7 @@ def getFilesInfo(req):
if fileId :
if len(resultID) > 0 : return resultID
else : return "File not found"
else : return "File not found"
else :
return result
@ -293,7 +299,6 @@ def getFilesInfo(req):
def download(filePath):
response = FileResponse(open(filePath, 'rb'), True) # write headers to the response object
response['Content-Length'] = os.path.getsize(filePath)
response['Content-Disposition'] = "attachment;filename*=UTF-8\'\'" + urllib.parse.quote_plus(os.path.basename(filePath))
response['Content-Disposition'] = "attachment;filename*=UTF-8\'\'" + urllib.parse.unquote(os.path.basename(filePath))
response['Content-Type'] = magic.from_file(filePath, mime=True)
response['Access-Control-Allow-Origin'] = "*"
return response
return response

View File

@ -16,7 +16,7 @@
"""
import config
from src.configuration import ConfigurationManager
# get file name from the document url
def getFileName(str):
@ -37,12 +37,13 @@ def getFileExt(str):
# get file type
def getFileType(str):
config = ConfigurationManager()
ext = getFileExt(str)
if ext in config.EXT_DOCUMENT:
if ext in config.document_file_extensions():
return 'word'
if ext in config.EXT_SPREADSHEET:
if ext in config.spreadsheet_file_extensions():
return 'cell'
if ext in config.EXT_PRESENTATION:
if ext in config.presentation_file_extensions():
return 'slide'
return 'word' # default file type is word

View File

@ -17,23 +17,26 @@
"""
import os
import io
import json
import config
from pathlib import Path
from src.configuration import ConfigurationManager
from src.history import HistoryManager, HistoryUser
from src.common import optional
from src.storage import StorageManager
from src.utils import users
from . import users, fileUtils
from datetime import datetime
from src import settings
from src.utils import docManager
from src.utils import jwtManager
# get the path to the history direction
def getHistoryDir(storagePath):
return f'{storagePath}-hist'
# get the path to the given file version
def getVersionDir(histDir, version):
return os.path.join(histDir, str(version))
source_file = Path(storagePath)
config_manager = ConfigurationManager()
storage_manager = StorageManager(
config_manager=config_manager,
user_host=source_file.parent.name,
source_basename=source_file.name
)
history_manager = HistoryManager(
storage_manager=storage_manager
)
directory = history_manager.history_directory()
return f'{directory}'
# get file version of the given history directory
def getFileVersion(histDir):
@ -43,188 +46,75 @@ def getFileVersion(histDir):
cnt = 1
for f in os.listdir(histDir): # run through all the files in the history directory
if not os.path.isfile(os.path.join(histDir, f)): # and count the number of files
cnt += 1
path = os.path.join(histDir, f)
directory = Path(path)
if not directory.is_dir():
continue
if not len(list(directory.iterdir())) > 0:
continue
cnt += 1
return cnt
# get the path to the next file version
def getNextVersionDir(histDir):
v = getFileVersion(histDir) # get file version of the given history directory
path = getVersionDir(histDir, v) # get the path to the next file version
if not os.path.exists(path): # if this path doesn't exist
os.makedirs(path) # make the directory for this file version
return path
# get the path to a file archive with differences in the given file version
def getChangesZipPath(verDir):
return os.path.join(verDir, 'diff.zip')
# get the path to a json file with changes of the given file version
def getChangesHistoryPath(verDir):
return os.path.join(verDir, 'changes.json')
# get the path to the previous file version
def getPrevFilePath(verDir, ext):
return os.path.join(verDir, f'prev{ext}')
# get the path to a txt file with a key information in it
def getKeyPath(verDir):
return os.path.join(verDir, 'key.txt')
# get the path to a json file with meta data about this file
def getMetaPath(histDir):
return os.path.join(histDir, 'createdInfo.json')
# create a json file with file meta data using the storage path and request
def createMeta(storagePath, req):
histDir = getHistoryDir(storagePath)
path = getMetaPath(histDir) # get the path to a json file with meta data about file
source_file = Path(storagePath)
config_manager = ConfigurationManager()
storage_manager = StorageManager(
config_manager=config_manager,
user_host=source_file.parent.name,
source_basename=source_file.name
)
history_manager = HistoryManager(
storage_manager=storage_manager
)
raw_user = users.getUserFromReq(req)
user = HistoryUser(
id=raw_user.id,
name=raw_user.name
)
history_manager.bootstrap_initial_item(user)
if not os.path.exists(histDir):
os.makedirs(histDir)
user = users.getUserFromReq(req) # get the user information (id and name)
obj = { # create the meta data object
'created': datetime.today().strftime('%Y-%m-%d %H:%M:%S'),
'uid': user.id,
'uname': user.name
}
writeFile(path, json.dumps(obj))
return
# create a json file with file meta data using the file name, user id, user name and user address
def createMetaData(filename, uid, uname, usAddr):
histDir = getHistoryDir(docManager.getStoragePath(filename, usAddr))
path = getMetaPath(histDir) # get the path to a json file with meta data about file
config_manager = ConfigurationManager()
storage_manager = StorageManager(
config_manager=config_manager,
user_host=usAddr,
source_basename=filename
)
history_manager = HistoryManager(
storage_manager=storage_manager
)
user = HistoryUser(
id=uid,
name=uname
)
history_manager.bootstrap_initial_item(user)
if not os.path.exists(histDir):
os.makedirs(histDir)
obj = { # create the meta data object
'created': datetime.today().strftime('%Y-%m-%d %H:%M:%S'),
'uid': uid,
'uname': uname
}
writeFile(path, json.dumps(obj))
return
# create file with a given content in it
def writeFile(path, content):
with io.open(path, 'w') as out:
out.write(content)
return
# read a file
def readFile(path):
with io.open(path, 'r') as stream:
return stream.read()
# get the url to the history file version with a given extension
def getPublicHistUri(filename, ver, file, req, isServerUrl=True):
host = docManager.getServerUrl(isServerUrl, req)
curAdr = f'&userAddress={req.META["REMOTE_ADDR"]}' if isServerUrl else ''
return f'{host}/downloadhistory?fileName={filename}&ver={ver}&file={file}{curAdr}'
# get the meta data of the file
def getMeta(storagePath):
histDir = getHistoryDir(storagePath)
path = getMetaPath(histDir)
source_file = Path(storagePath)
config_manager = ConfigurationManager()
storage_manager = StorageManager(
config_manager=config_manager,
user_host=source_file.parent.name,
source_basename=source_file.name
)
history_manager = HistoryManager(
storage_manager=storage_manager
)
if os.path.exists(path): # check if the json file with file meta data exists
with io.open(path, 'r') as stream:
return json.loads(stream.read()) # turn meta data into python format
return None
changes = history_manager.changes(HistoryManager.minimal_version)
if changes is None:
return None
# get the document history of a given file
def getHistoryObject(storagePath, filename, docKey, docUrl, isEnableDirectUrl, req):
histDir = getHistoryDir(storagePath)
version = getFileVersion(histDir)
if version > 0: # if the file was modified (the file version is greater than 0)
hist = []
histData = {}
for i in range(1, version + 1): # run through all the file versions
obj = {}
dataObj = {}
prevVerDir = getVersionDir(histDir, i - 1) # get the path to the previous file version
verDir = getVersionDir(histDir, i) # get the path to the given file version
first_changes = optional.expression(lambda: changes.changes[0])
if first_changes is None:
return None
try:
key = docKey if i == version else readFile(getKeyPath(verDir)) # get document key
obj['key'] = key
obj['version'] = i
dataObj['fileType'] = fileUtils.getFileExt(filename)[1:]
dataObj['key'] = key
dataObj['version'] = i
if i == 1: # check if the version number is equal to 1
meta = getMeta(storagePath) # get meta data of this file
if meta: # write meta information to the object (user information and creation date)
obj['created'] = meta['created']
obj['user'] = {
'id': meta['uid'],
'name': meta['uname']
}
dataObj['url'] = docUrl if i == version else getPublicHistUri(filename, i, "prev" + fileUtils.getFileExt(filename), req) # write file url to the data object
if isEnableDirectUrl:
dataObj['directUrl'] = docManager.getDownloadUrl(filename, req, False) if i == version else getPublicHistUri(filename, i, "prev" + fileUtils.getFileExt(filename), req, False) # write file direct url to the data object
if i > 1: # check if the version number is greater than 1 (the file was modified)
changes = json.loads(readFile(getChangesHistoryPath(prevVerDir))) # get the path to the changes.json file
change = changes['changes'][0]
obj['changes'] = changes['changes'] if change else None # write information about changes to the object
obj['serverVersion'] = changes['serverVersion']
obj['created'] = change['created'] if change else None
obj['user'] = change['user'] if change else None
prev = histData[str(i - 2)] # get the history data from the previous file version
prevInfo = { # write key and url information about previous file version
'fileType': prev['fileType'],
'key': prev['key'],
'url': prev['url'],
'directUrl': prev['directUrl']
} if isEnableDirectUrl else { # write key and url information about previous file version
'fileType': prev['fileType'],
'key': prev['key'],
'url': prev['url']
}
dataObj['previous'] = prevInfo # write information about previous file version to the data object
dataObj['changesUrl'] = getPublicHistUri(filename, i - 1, "diff.zip", req) # write the path to the diff.zip archive with differences in this file version
if jwtManager.isEnabled():
dataObj['token'] = jwtManager.encode(dataObj)
hist.append(obj) # add object dictionary to the hist list
histData[str(i - 1)] = dataObj # write data object information to the history data
except Exception:
return {}
histObj = { # write history information about the current file version to the history object
'currentVersion': version,
'history': hist
}
return { 'history': histObj, 'historyData': histData }
return {}
class CorsHeaderMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
resp = self.get_response(request)
if request.path == '/downloadhistory':
resp['Access-Control-Allow-Origin'] = config.DOC_SERV_SITE_URL[0:-1]
return resp
return {
'created': first_changes.created,
'uid': first_changes.user.id,
'uname': first_changes.user.name
}

View File

@ -16,21 +16,25 @@
"""
import config
import jwt
from src.configuration import ConfigurationManager
# check if a secret key to generate token exists or not
def isEnabled():
return bool(config.DOC_SERV_JWT_SECRET)
config = ConfigurationManager()
return bool(config.jwt_secret())
# check if a secret key to generate token exists or not
def useForRequest():
return bool(config.DOC_SERV_JWT_USE_FOR_REQUEST)
config = ConfigurationManager()
return config.jwt_use_for_request()
# encode a payload object into a token using a secret key and decodes it into the utf-8 format
def encode(payload):
return jwt.encode(payload, config.DOC_SERV_JWT_SECRET, algorithm='HS256')
config = ConfigurationManager()
return jwt.encode(payload, config.jwt_secret(), algorithm='HS256')
# decode a token into a payload object using a secret key
def decode(string):
return jwt.decode(string, config.DOC_SERV_JWT_SECRET, algorithms=['HS256'])
config = ConfigurationManager()
return jwt.decode(string, config.jwt_secret(), algorithms=['HS256'])

View File

@ -18,8 +18,8 @@
import json
import requests
import config
from src.configuration import ConfigurationManager
from . import fileUtils, jwtManager
# convert file and give url to a new file
@ -44,13 +44,14 @@ def getConvertedData(docUri, fromExt, toExt, docKey, isAsync, filePass = None, l
if (isAsync): # check if the operation is asynchronous
payload.setdefault('async', True) # and write this information to the payload object
config = ConfigurationManager()
if (jwtManager.isEnabled() and jwtManager.useForRequest()): # check if a secret key to generate token exists or not
jwtHeader = 'Authorization' if config.DOC_SERV_JWT_HEADER is None or config.DOC_SERV_JWT_HEADER == '' else config.DOC_SERV_JWT_HEADER # get jwt header
headerToken = jwtManager.encode({'payload': payload}) # encode a payload object into a header token
payload['token'] = jwtManager.encode(payload) # encode a payload object into a body token
headers[jwtHeader] = f'Bearer {headerToken}' # add a header Authorization with a header token with Authorization prefix in it
headers[config.jwt_header()] = f'Bearer {headerToken}' # add a header Authorization with a header token with Authorization prefix in it
response = requests.post(config.DOC_SERV_SITE_URL + config.DOC_SERV_CONVERTER_URL, json=payload, headers=headers, verify = config.DOC_SERV_VERIFY_PEER, timeout=5) # send the headers and body values to the converter and write the result to the response
response = requests.post(config.document_server_converter_url().geturl(), json=payload, headers=headers, verify = config.ssl_verify_peer_mode_enabled(), timeout=5) # send the headers and body values to the converter and write the result to the response
status_code = response.status_code
if status_code != 200: # checking status code
raise RuntimeError('Convertation service returned status: %s' % status_code)

Some files were not shown because too many files have changed in this diff Show More