diff --git a/.github/workflows/artifact-csharp-mvc.yml b/.github/workflows/artifact-csharp-mvc.yml index c543d0bce..05805cf49 100644 --- a/.github/workflows/artifact-csharp-mvc.yml +++ b/.github/workflows/artifact-csharp-mvc.yml @@ -21,11 +21,9 @@ jobs: cwd=$(pwd) git submodule update --init --recursive cd ./web/documentserver-example/csharp-mvc - mkdir -p ./deploy/'DotNet (Csharp MVN) Example' + mkdir -p ./deploy/'DotNet (Csharp MVC) Example' rsync -av --exclude='deploy' ./ ./deploy/'DotNet (Csharp MVC) Example' - cd ./deploy/'DotNet (Csharp MVC) Example'/assets - rm -rf ./.git/ - rm .git + rm -rf ./deploy/'DotNet (Csharp MVC) Example'/assets/.git - name: Upload Artifact uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/artifact-csharp.yml b/.github/workflows/artifact-csharp.yml index 6c9ec93ee..bd08a90b4 100644 --- a/.github/workflows/artifact-csharp.yml +++ b/.github/workflows/artifact-csharp.yml @@ -18,14 +18,11 @@ jobs: - name: Build Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) git submodule update --init --recursive cd ./web/documentserver-example/csharp mkdir -p ./deploy/'DotNet (Csharp) Example' rsync -av --exclude='deploy' ./ ./deploy/'DotNet (Csharp) Example' - cd ./deploy/'DotNet (Csharp) Example'/assets - rm -rf ./.git/ - rm .git + rm -rf ./deploy/'DotNet (Csharp) Example'/assets/.git - name: Upload Artifact uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/artifact-java.yml b/.github/workflows/artifact-java.yml index 1a4ce3acf..f026b5cf8 100644 --- a/.github/workflows/artifact-java.yml +++ b/.github/workflows/artifact-java.yml @@ -18,14 +18,12 @@ jobs: - name: Build Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) git submodule update --init --recursive cd ./web/documentserver-example/java mkdir -p ./deploy/'Java Example' rsync -av --exclude='deploy' ./ ./deploy/'Java Example' - cd ./deploy/'Java Example'/src/main/resources/assets - rm -rf ./.git/ - rm .git + rm -rf ./deploy/'Java Example'/src/main/resources/assets/document-formats/.git + rm -rf ./deploy/'Java Example'/src/main/resources/assets/document-templates/.git - name: Upload Artifact uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/artifact-node.yml b/.github/workflows/artifact-node.yml index 46461cbbb..1341c6297 100644 --- a/.github/workflows/artifact-node.yml +++ b/.github/workflows/artifact-node.yml @@ -18,14 +18,12 @@ jobs: - name: Build Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) git submodule update --init --recursive cd ./web/documentserver-example/nodejs mkdir -p ./deploy/'Node.js Example' rsync -av --exclude='deploy' ./ ./deploy/'Node.js Example' - cd ./deploy/'Node.js Example'/public/assets - rm -rf ./.git/ - rm .git + rm -rf ./deploy/'Node.js Example'/public/assets/document-formats/.git + rm -rf ./deploy/'Node.js Example'/public/assets/document-templates/.git - name: Upload Artifact uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/artifact-php.yml b/.github/workflows/artifact-php.yml index 65a07544f..e3358fc15 100644 --- a/.github/workflows/artifact-php.yml +++ b/.github/workflows/artifact-php.yml @@ -18,14 +18,12 @@ jobs: - name: Build Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) git submodule update --init --recursive cd ./web/documentserver-example/php mkdir -p ./deploy/'PHP Example' rsync -av --exclude='deploy' ./ ./deploy/'PHP Example' - cd ./deploy/'PHP Example'/assets - rm -rf ./.git/ - rm .git + rm -rf ./deploy/'PHP Example'/assets/document-formats/.git + rm -rf ./deploy/'PHP Example'/assets/document-templates/.git - name: Upload Artifact uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/artifact-python.yml b/.github/workflows/artifact-python.yml index afdc28a3e..4591aeeb1 100644 --- a/.github/workflows/artifact-python.yml +++ b/.github/workflows/artifact-python.yml @@ -18,14 +18,12 @@ jobs: - name: Build Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) git submodule update --init --recursive cd ./web/documentserver-example/python mkdir -p ./deploy/'Python Example' rsync -av --exclude='deploy' ./ ./deploy/'Python Example' - cd ./deploy/'Python Example'/assets - rm -rf ./.git/ - rm .git + rm -rf ./deploy/'Python Example'/assets/document-formats/.git + rm -rf ./deploy/'Python Example'/assets/document-templates/.git - name: Upload Artifact uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/artifact-ruby.yml b/.github/workflows/artifact-ruby.yml index 7aff4de5f..15fdc0fa6 100644 --- a/.github/workflows/artifact-ruby.yml +++ b/.github/workflows/artifact-ruby.yml @@ -18,14 +18,12 @@ jobs: - name: Build Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) git submodule update --init --recursive cd ./web/documentserver-example/ruby mkdir -p ./deploy/'Ruby Example' rsync -av --exclude='deploy' ./ ./deploy/'Ruby Example' - cd ./deploy/'Ruby Example'/public/assets - rm -rf ./.git/ - rm .git + rm -rf ./deploy/'Ruby Example'/public/assets/document-formats/.git + rm -rf ./deploy/'Ruby Example'/public/assets/document-templates/.git - name: Upload Artifact uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/artifact-spring.yml b/.github/workflows/artifact-spring.yml index e49b336c8..0af691629 100644 --- a/.github/workflows/artifact-spring.yml +++ b/.github/workflows/artifact-spring.yml @@ -23,9 +23,8 @@ jobs: cd ./web/documentserver-example/java-spring mkdir -p ./deploy/'Java Spring Example' rsync -av --exclude='deploy' ./ ./deploy/'Java Spring Example' - cd ./deploy/'Java Spring Example'/src/main/resources/assets - rm -rf ./.git/ - rm .git + rm -rf ./deploy/'Java Spring Example'/src/main/resources/assets/document-formats/.git + rm -rf ./deploy/'Java Spring Example'/src/main/resources/assets/document-templates/.git - name: Upload Artifact uses: actions/upload-artifact@v3 with: diff --git a/.github/workflows/lint-php.yml b/.github/workflows/lint-php.yml index bc8b5a401..d14311fbd 100644 --- a/.github/workflows/lint-php.yml +++ b/.github/workflows/lint-php.yml @@ -25,7 +25,5 @@ jobs: php-version: '8.2' tools: cs2pr, phpcs - - name: Run phpcs - run: | - phpcs --version - phpcs -q --extensions=php,module,inc,install,test,profile,theme,info --ignore=node_modules,bower_components,vendor,css,js,lib --standard=./ruleset.xml ./ \ No newline at end of file + - name: Lint + run: phpcs src index.php diff --git a/.github/workflows/lint-python.yml b/.github/workflows/lint-python.yml index 3e290ec6c..e323439bc 100644 --- a/.github/workflows/lint-python.yml +++ b/.github/workflows/lint-python.yml @@ -32,9 +32,9 @@ jobs: - name: Lint Flake8 run: | - flake8 ./**/*.py --count --select=E9,F63,F7,F82 --show-source --statistics - flake8 ./**/*.py --count --max-complexity=10 --max-line-length=79 --statistics + flake8 --count --select=E9,F63,F7,F82 --show-source --statistics + flake8 --count --max-complexity=10 --max-line-length=79 --statistics - name: Lint Pylint run: | - pylint ./**/*.py + find . -type f -name "*.py" | xargs pylint diff --git a/.github/workflows/lint-ruby.yml b/.github/workflows/lint-ruby.yml index cdb74d238..4b476edf5 100644 --- a/.github/workflows/lint-ruby.yml +++ b/.github/workflows/lint-ruby.yml @@ -16,16 +16,22 @@ jobs: run: working-directory: ./web/documentserver-example/ruby steps: - - name: Checkout Repository - uses: actions/checkout@v3 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.0' - bundler-cache: true - - name: Install dependencies - run: | - bundle install - - name: Rubocop - run: | - gem install rubocop - rubocop + - name: Checkout Repository + uses: actions/checkout@v3 + + - name: Setup Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: '3.2.2' + + - name: Update Submodules + run: | + git submodule update --init --recursive + + - name: Install Dependencies + run: | + bundle update + + - name: Rubocop + run: | + bundle exec rubocop diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 746569160..b8518bbd5 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -13,8 +13,10 @@ jobs: steps: - name: Checkout Repository uses: actions/checkout@v3 - - name: Install Zip - run: sudo apt-get install zip + - name: Clone Submodules + run: | + cd ${{ github.workspace }} + git submodule update --init --recursive - name: Get Info run: | echo "version=$(grep -Eo '[0-9]+(\.[0-9]+)+' CHANGELOG.md | head -n 1)" >> $GITHUB_OUTPUT @@ -25,91 +27,66 @@ jobs: - name: Build Csharp MVC Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) - git submodule update --init --recursive cd ./web/documentserver-example/csharp-mvc mkdir -p ./'DotNet (Csharp MVC) Example' rsync -av --exclude='DotNet (Csharp MVC) Example' ./ ./'DotNet (Csharp MVC) Example' cd ./'DotNet (Csharp MVC) Example'/assets - rm -rf ./.git/ - rm .git + rm -rf .git - name: Build Csharp Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) - git submodule update --init --recursive cd ./web/documentserver-example/csharp mkdir -p ./'DotNet (Csharp) Example' rsync -av --exclude='DotNet (Csharp) Example' ./ ./'DotNet (Csharp) Example' - cd ./'DotNet (Csharp) Example'/assets - rm -rf ./.git/ - rm .git + rm -rf ./'DotNet (Csharp) Example'/assets/.git - name: Build Java Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) - git submodule update --init --recursive cd ./web/documentserver-example/java mkdir -p ./'Java Example' rsync -av --exclude='Java Example' ./ ./'Java Example' - cd ./'Java Example'/src/main/resources/assets - rm -rf ./.git/ - rm .git + rm -rf ./'Java Example'/src/main/resources/assets/document-formats/.git + rm -rf ./'Java Example'/src/main/resources/assets/document-templates/.git - name: Build Nodejs Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) - git submodule update --init --recursive cd ./web/documentserver-example/nodejs mkdir -p ./'Node.js Example' rsync -av --exclude='Node.js Example' ./ ./'Node.js Example' - cd ./'Node.js Example'/public/assets - rm -rf ./.git/ - rm .git + rm -rf ./'Node.js Example'/public/assets/document-formats/.git + rm -rf ./'Node.js Example'/public/assets/document-templates/.git - name: Build PHP Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) - git submodule update --init --recursive cd ./web/documentserver-example/php mkdir -p ./'PHP Example' rsync -av --exclude='PHP Example' ./ ./'PHP Example' - cd ./'PHP Example'/assets - rm -rf ./.git/ - rm .git + rm -rf ./'PHP Example'/assets/document-formats/.git + rm -rf ./'PHP Example'/assets/document-templates/.git - name: Build Python Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) - git submodule update --init --recursive cd ./web/documentserver-example/python mkdir -p ./'Python Example' rsync -av --exclude='Python Example' ./ ./'Python Example' - cd ./'Python Example'/assets - rm -rf ./.git/ - rm .git + rm -rf ./'Python Example'/assets/document-formats/.git + rm -rf ./'Python Example'/assets/document-templates/.git - name: Build Ruby Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) - git submodule update --init --recursive cd ./web/documentserver-example/ruby mkdir -p ./'Ruby Example' rsync -av --exclude='Ruby Example' ./ ./'Ruby Example' - cd ./'Ruby Example'/public/assets - rm -rf ./.git/ - rm .git + rm -rf ./'Ruby Example'/public/assets/document-formats/.git + rm -rf ./'Ruby Example'/public/assets/document-templates/.git - name: Build Spring Artifact run: | cd ${{ github.workspace }} - cwd=$(pwd) - git submodule update --init --recursive cd ./web/documentserver-example/java-spring mkdir -p ./'Java Spring Example' rsync -av --exclude='Java Spring Example' ./ ./'Java Spring Example' - cd ./'Java Spring Example'/src/main/resources/assets - rm -rf ./.git/ - rm .git + rm -rf ./'Java Spring Example'/src/main/resources/assets/document-formats/.git + rm -rf ./'Java Spring Example'/src/main/resources/assets/document-templates/.git - name: Pack Artifacts run: | cd ${{ github.workspace }}/web/documentserver-example/csharp-mvc diff --git a/.gitignore b/.gitignore index ba6bd9b0b..917479534 100644 --- a/.gitignore +++ b/.gitignore @@ -22,8 +22,3 @@ /web/documentserver-example/csharp/packages /web/documentserver-example/csharp-mvc/packages /web/documentserver-example/java-spring/documents/ -/web/documentserver-example/ruby/.bundle -/web/documentserver-example/ruby/db/*.sqlite3 -/web/documentserver-example/ruby/db/*.sqlite3-journal -/web/documentserver-example/ruby/log/* -/web/documentserver-example/ruby/tmp diff --git a/.gitmodules b/.gitmodules index 6a281ad79..52687a2de 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,32 +1,48 @@ -[submodule "web/documentserver-example/nodejs/public/assets"] - path = web/documentserver-example/nodejs/public/assets +[submodule "web/documentserver-example/csharp-mvc/assets"] + path = web/documentserver-example/csharp-mvc/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 +[submodule "web/documentserver-example/csharp/assets"] + path = web/documentserver-example/csharp/assets url = https://github.com/ONLYOFFICE/document-templates branch = main/en -[submodule "web/documentserver-example/php/assets"] - path = web/documentserver-example/php/assets +[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/python/assets"] - path = web/documentserver-example/python/assets +[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/csharp-mvc/assets"] - path = web/documentserver-example/csharp-mvc/assets +[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 +[submodule "web/documentserver-example/python/assets/document-templates"] + path = web/documentserver-example/python/assets/document-templates url = https://github.com/ONLYOFFICE/document-templates branch = main/en -[submodule "web/documentserver-example/csharp/assets"] - path = web/documentserver-example/csharp/assets +[submodule "web/documentserver-example/java/src/main/resources/assets/document-templates"] + path = web/documentserver-example/java/src/main/resources/assets/document-templates url = https://github.com/ONLYOFFICE/document-templates branch = main/en -[submodule "web/documentserver-example/ruby/public/assets"] - path = web/documentserver-example/ruby/public/assets +[submodule "web/documentserver-example/ruby/assets/document-templates"] + path = web/documentserver-example/ruby/assets/document-templates url = https://github.com/ONLYOFFICE/document-templates branch = main/en -[submodule "web/documentserver-example/java-spring/src/main/resources/assets"] - path = web/documentserver-example/java-spring/src/main/resources/assets +[submodule "web/documentserver-example/java-spring/src/main/resources/assets/document-templates"] + path = web/documentserver-example/java-spring/src/main/resources/assets/document-templates url = https://github.com/ONLYOFFICE/document-templates branch = main/en +[submodule "web/documentserver-example/python/assets/document-formats"] + path = web/documentserver-example/python/assets/document-formats + url = https://github.com/ONLYOFFICE/document-formats + branch = master +[submodule "web/documentserver-example/ruby/assets/document-formats"] + path = web/documentserver-example/ruby/assets/document-formats + url = https://github.com/ONLYOFFICE/document-formats + branch = master diff --git a/3rd-Party.license b/3rd-Party.license index 4e0229b2c..aca8b0499 100644 --- a/3rd-Party.license +++ b/3rd-Party.license @@ -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 @@ -282,59 +303,32 @@ PHP_CodeSniffer - PHP_CodeSniffer is a set of two PHP scripts; the main phpcs sc License: BSD-3-Clause License File: PHP_CodeSniffer.license +PHPUnit - The PHP Unit Testing framework. (https://github.com/sebastianbergmann/phpunit/blob/main/LICENSE) +License: BSD 3-Clause +License File: phpunit.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/) +property-access - Provides functions to read and write from/to an object or array using a simple string notation. (https://github.com/symfony/property-access/blob/6.3/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 +License File: property-access.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) +serializer - Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON. (https://github.com/symfony/serializer/blob/6.3/LICENSE) License: MIT -License File: jQuery.FileUpload.license +License File: serializer.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 - -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 +web/documentserver-example/python -python-magic - python-magic is a Python interface to the libmagic file type identification library. (https://github.com/ahupp/python-magic/blob/master/LICENSE) +django-stubs - PEP-484 stubs for Django. (https://github.com/typeddjango/django-stubs/blob/master/LICENSE.md) License: MIT -License File: python-magic.license - -requests - Requests allows you to send HTTP/1.1 requests extremely easily. There’s 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 +License File: django-stubs.license 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/) +flake8 - flake8 is a python tool that glues together pycodestyle, pyflakes, mccabe, and third-party plugins to check the style and quality of some python code. (https://github.com/PyCQA/flake8/blob/main/LICENSE) License: MIT -License File: jQuery.license +License File: flake8.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 @@ -348,14 +342,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 +msgspec - A fast serialization and validation library, with builtin support for JSON, MessagePack, YAML, and TOML. (https://github.com/jcrist/msgspec/blob/0.18.1/LICENSE) +License: BSD 3-Clause +License File: msgspec.license + +mypy - Optional static typing for Python. (https://github.com/python/mypy/blob/master/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 @@ -368,6 +374,10 @@ requests - Requests allows you to send HTTP/1.1 requests extremely easily. License: Apache 2.0 License File: requests.license +typeshed - Collection of library stubs for Python, with static types. (https://github.com/python/typeshed/blob/main/LICENSE) +License: Apache 2.0 +License File: typeshed.license + web/documentserver-example/ruby @@ -379,13 +389,13 @@ coffee-rails - CoffeeScript adapter for the Rails asset pipeline. (https://gith License: MIT License File: coffee-rails.license -jbuilder - Create JSON structures via a Builder-style DSL (https://github.com/rails/jbuilder/blob/master/MIT-LICENSE) +dalli - High performance memcached client for Ruby. (https://github.com/petergoldstein/dalli/blob/v3.2.0/LICENSE) License: MIT -License File: jbuilder.license +License File: dalli.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/) +jbuilder - Create JSON structures via a Builder-style DSL (https://github.com/rails/jbuilder/blob/master/MIT-LICENSE) License: MIT -License File: jQuery.license +License File: jbuilder.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 @@ -399,9 +409,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 +425,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,9 +445,13 @@ sdoc - rdoc generator html with javascript search index. (https://githu License: MIT License File: sdoc.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 +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 + +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 diff --git a/CHANGELOG.md b/CHANGELOG.md index c629d03b1..e93b1af1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,25 @@ # Change Log +## 1.7.0 +- nodejs: onRequestSelectDocument method +- nodejs: onRequestSelectSpreadsheet method +- nodejs: onRequestOpen +- nodejs: submitForm +- nodejs: key in referenceData +- nodejs: change reference source +- 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 +- php: using a repo with a list of formats +- php: restore from history +- python: restore from history +- ruby: restore from history +- csharp-mvc: getting history by a separate request +- csharp-mvc: restore from history +- csharp: getting history by a separate request +- csharp: restore from history + ## 1.6.0 - nodejs: setUsers for region protection - si skin languages diff --git a/web/documentserver-example/csharp-mvc/3rd-Party.license b/web/documentserver-example/csharp-mvc/3rd-Party.license index da13a379b..e14b47cb1 100644 --- a/web/documentserver-example/csharp-mvc/3rd-Party.license +++ b/web/documentserver-example/csharp-mvc/3rd-Party.license @@ -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 diff --git a/web/documentserver-example/csharp-mvc/Models/FileModel.cs b/web/documentserver-example/csharp-mvc/Models/FileModel.cs index a30fd648b..28f537a05 100755 --- a/web/documentserver-example/csharp-mvc/Models/FileModel.cs +++ b/web/documentserver-example/csharp-mvc/Models/FileModel.cs @@ -17,7 +17,6 @@ */ using System; -using System.Collections; using System.Collections.Generic; using System.IO; using System.Web; @@ -236,123 +235,6 @@ public string GetDocConfig(HttpRequest request, UrlHelper url) return jss.Serialize(config); } - // get the document history - public void GetHistory(out string history, out string historyData) - { - var storagePath = WebConfigurationManager.AppSettings["storage-path"]; - var jss = new JavaScriptSerializer(); - var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(FileName, null)); - - history = null; - historyData = null; - - if (DocManagerHelper.GetFileVersion(histDir) > 0) // if the file was modified (the file version is greater than 0) - { - var currentVersion = DocManagerHelper.GetFileVersion(histDir); - var hist = new List>(); - var histData = new Dictionary(); - - for (var i = 1; i <= currentVersion; i++) // run through all the file versions - { - var obj = new Dictionary(); - var dataObj = new Dictionary(); - var verDir = DocManagerHelper.VersionDir(histDir, i); // get the path to the given file version - - var key = i == currentVersion ? Key : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key - - obj.Add("key", key); - obj.Add("version", i); - - if (i == 1) // check if the version number is equal to 1 - { - var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file - - if (File.Exists(infoPath)) - { - var info = jss.Deserialize>(File.ReadAllText(infoPath)); - obj.Add("created", info["created"]); // write meta information to the object (user information and creation date) - obj.Add("user", new Dictionary() { - { "id", info["id"] }, - { "name", info["name"] }, - }); - } - } - - var ext = Path.GetExtension(FileName).ToLower(); - dataObj.Add("fileType", ext.Replace(".", "")); - dataObj.Add("key", key); - // write file url to the data object - string prevFileUrl; - string directPrevFileUrl; - if (Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath)) - { - prevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext) - : DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", "")); - directPrevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext, false) - : DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false); - } - else { - prevFileUrl = i == currentVersion ? FileUri - : DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext); - directPrevFileUrl = i == currentVersion ? DocManagerHelper.GetHistoryDownloadUrl(FileName, i.ToString(), "prev" + ext, false) - : DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false); - } - - dataObj.Add("url", prevFileUrl); - if (IsEnabledDirectUrl) - { - dataObj.Add("directUrl", directPrevFileUrl); - } - dataObj.Add("version", i); - if (i > 1) // check if the version number is greater than 1 (the file was modified) - { - // get the path to the changes.json file - var changes = jss.Deserialize>(File.ReadAllText(Path.Combine(DocManagerHelper.VersionDir(histDir, i - 1), "changes.json"))); - var changesArray = (ArrayList)changes["changes"]; - var change = changesArray.Count > 0 - ? (Dictionary)changesArray[0] - : new Dictionary(); - - // write information about changes to the object - obj.Add("changes", change.Count > 0 ? changes["changes"] : null); - obj.Add("serverVersion", changes["serverVersion"]); - obj.Add("created", change.Count > 0 ? change["created"] : null); - obj.Add("user", change.Count > 0 ? change["user"] : null); - - var prev = (Dictionary)histData[(i - 2).ToString()]; // get the history data from the previous file version - dataObj.Add("previous", IsEnabledDirectUrl ? new Dictionary() { // write information about previous file version to the data object with direct url - { "fileType", prev["fileType"] }, - { "key", prev["key"] }, // write key and url information about previous file version - { "url", prev["url"] }, - { "directUrl", prev["directUrl"] }, - } : new Dictionary() { // write information about previous file version to the data object without direct url - { "fileType", prev["fileType"] }, - { "key", prev["key"] }, // write key and url information about previous file version - { "url", prev["url"] }, - }); - // write the path to the diff.zip archive with differences in this file version - var changesUrl = DocManagerHelper.GetHistoryDownloadUrl(FileName, (i - 1).ToString(), "diff.zip"); - dataObj.Add("changesUrl", changesUrl); - } - if(JwtManager.Enabled) - { - var token = JwtManager.Encode(dataObj); - dataObj.Add("token", token); - } - hist.Add(obj); // add object dictionary to the hist list - histData.Add((i - 1).ToString(), dataObj); // write data object information to the history data - } - - // write history information about the current file version to the history object - history = jss.Serialize(new Dictionary() - { - { "currentVersion", currentVersion }, - { "history", hist } - }); - historyData = jss.Serialize(histData); - } - } - // get a document which will be compared with the current document public void GetCompareFileData(out string compareConfig) { diff --git a/web/documentserver-example/csharp-mvc/Views/Home/Editor.aspx b/web/documentserver-example/csharp-mvc/Views/Home/Editor.aspx index b69f7e61c..c9850fd3b 100644 --- a/web/documentserver-example/csharp-mvc/Views/Home/Editor.aspx +++ b/web/documentserver-example/csharp-mvc/Views/Home/Editor.aspx @@ -190,6 +190,47 @@ } }; + var onRequestHistory = function () { + let xhr = new XMLHttpRequest(); + xhr.open("GET", "webeditor.ashx?type=gethistory&filename=<%= Model.FileName %>"); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.send(); + xhr.onload = function () { + console.log(xhr.responseText); + docEditor.refreshHistory(JSON.parse(xhr.responseText)); + } + }; + + var onRequestHistoryData = function (event) { + var ver = event.data; + + let xhr = new XMLHttpRequest(); + xhr.open("GET", "webeditor.ashx?type=getversiondata&filename=<%= Model.FileName %>&version=" + ver + "&directUrl=" + !!config.document.directUrl); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.send(); + xhr.onload = function () { + console.log(xhr.responseText); + docEditor.setHistoryData(JSON.parse(xhr.responseText)); // send the link to the document for viewing the version history + } + }; + + var onRequestRestore = function (event) { + var fileName = "<%= Model.FileName %>"; + var version = event.data.version; + var data = { + fileName: fileName, + version: version + }; + + let xhr = new XMLHttpRequest(); + xhr.open("POST", "webeditor.ashx?type=restore&directUrl=" + !!config.document.directUrl); + xhr.setRequestHeader('Content-Type', 'application/json'); + xhr.send(JSON.stringify(data)); + xhr.onload = function () { + docEditor.refreshHistory(JSON.parse(xhr.responseText)); + } + } + config = <%= Model.GetDocConfig(Request, Url) %>; config.width = "100%"; @@ -207,30 +248,19 @@ "onRequestMailMergeRecipients": onRequestMailMergeRecipients, }; - <% string hist, histData; %> - <% Model.GetHistory(out hist, out histData); %> - <% string usersForMentions; %> <% Model.GetUsersMentions(Request, out usersForMentions); %> if (config.editorConfig.user.id) { - <% if (!string.IsNullOrEmpty(hist) && !string.IsNullOrEmpty(histData)) - { %> - // the user is trying to show the document version history - config.events['onRequestHistory'] = function () { - docEditor.refreshHistory(<%= hist %>); // show the document version history - }; - // the user is trying to click the specific document version in the document version history - config.events['onRequestHistoryData'] = function (event) { - var ver = event.data; - var histData = <%= histData %>; - docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history - }; - // the user is trying to go back to the document from viewing the document version history - config.events['onRequestHistoryClose'] = function () { - document.location.reload(); - }; - <% } %> + // the user is trying to show the document version history + config.events['onRequestHistory'] = onRequestHistory; + // the user is trying to click the specific document version in the document version history + config.events['onRequestHistoryData'] = onRequestHistoryData; + // the user is trying to go back to the document from viewing the document version history + config.events['onRequestHistoryClose'] = function () { + document.location.reload(); + }; + config.events['onRequestRestore'] = onRequestRestore; // add mentions for not anonymous users <% if (!string.IsNullOrEmpty(usersForMentions)) diff --git a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs index 24a0500e3..25a8ba8b2 100644 --- a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs +++ b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs @@ -17,6 +17,7 @@ */ using System; +using System.Collections; using System.Collections.Generic; using System.IO; using System.Text; @@ -50,6 +51,15 @@ public void ProcessRequest(HttpContext context) case "downloadhistory": DownloadHistory(context); break; + case "gethistory": + GetHistory(context); + break; + case "getversiondata": + GetVersionData(context); + break; + case "restore": + Restore(context); + break; case "convert": Convert(context); break; @@ -513,6 +523,173 @@ public bool IsReusable get { return false; } } + private static void GetHistory(HttpContext context) + { + var jss = new JavaScriptSerializer(); + var fileName = context.Request["filename"]; + + var history = GetHistory(fileName); + + context.Response.Write(jss.Serialize(history)); + } + + private static void GetVersionData(HttpContext context) + { + var storagePath = WebConfigurationManager.AppSettings["storage-path"]; + var jss = new JavaScriptSerializer(); + + var fileName = context.Request["filename"]; + int version; + + if (!int.TryParse(context.Request["version"], out version)) + { + context.Response.Write("{ \"error\": \"Version number invalid!\"}"); + return; + } + + var versionData = new Dictionary(); + + var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(fileName, null)); + var lastVersion = DocManagerHelper.GetFileVersion(histDir); + + var verDir = DocManagerHelper.VersionDir(histDir, version); + + var key = version == lastVersion + ? ServiceConverter.GenerateRevisionId(DocManagerHelper.CurUserHostAddress() + + "/" + fileName + "/" + + File.GetLastWriteTime(DocManagerHelper.StoragePath(fileName, null)).GetHashCode()) + : File.ReadAllText(Path.Combine(verDir, "key.txt")); + + + var ext = Path.GetExtension(fileName).ToLower(); + versionData.Add("fileType", ext.Replace(".", "")); + versionData.Add("key", key); + + // write file url to the data object + string prevFileUrl; + string directPrevFileUrl; + if (Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath)) + { + prevFileUrl = version == lastVersion ? DocManagerHelper.GetDownloadUrl(fileName) + : DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", "")); + directPrevFileUrl = version == lastVersion ? DocManagerHelper.GetDownloadUrl(fileName, false) + : DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false); + } + else + { + prevFileUrl = version == lastVersion ? DocManagerHelper.GetFileUri(fileName, true) + : DocManagerHelper.GetHistoryDownloadUrl(fileName, version.ToString(), "prev" + ext); + directPrevFileUrl = version == lastVersion ? DocManagerHelper.GetFileUri(fileName, false) + : DocManagerHelper.GetHistoryDownloadUrl(fileName, version.ToString(), "prev" + ext, false); + } + + versionData.Add("url", prevFileUrl); + + var isEnableDirectUrl = string.Equals(DocManagerHelper.GetDirectUrl(), "true"); + if (isEnableDirectUrl) + { + versionData.Add("directUrl", directPrevFileUrl); // write direct url to the data object + } + + versionData.Add("version", version); + if (version > 1) + { + var prevVerDir = DocManagerHelper.VersionDir(histDir, version - 1); + + var prevUrl = Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath) + ? DocManagerHelper.GetDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", "")) + : DocManagerHelper.GetHistoryDownloadUrl(fileName, (version - 1).ToString(), "prev" + ext); + + var prevKey = File.ReadAllText(Path.Combine(prevVerDir, "key.txt")); + + Dictionary dataPrev = new Dictionary() { // write information about previous file version to the data object + { "fileType", ext.Replace(".", "") }, + { "key", prevKey }, // write key and url information about previous file version + { "url", prevUrl } + }; + + string directPrevUrl; + if (isEnableDirectUrl) + { + directPrevUrl = Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath) + ? DocManagerHelper.GetDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", ""), false) + : DocManagerHelper.GetHistoryDownloadUrl(fileName, version.ToString(), "prev" + ext, false); + + dataPrev.Add("directUrl", directPrevUrl); + } + + versionData.Add("previous", dataPrev); + + if (File.Exists(Path.Combine(prevVerDir, "diff.zip"))) + { + var changesUrl = DocManagerHelper.GetHistoryDownloadUrl(fileName, (version - 1).ToString(), "diff.zip"); + versionData.Add("changesUrl", changesUrl); + } + } + + if (JwtManager.Enabled) + { + var token = JwtManager.Encode(versionData); + versionData.Add("token", token); + } + + context.Response.Write(jss.Serialize(versionData)); + } + + private static void Restore(HttpContext context) + { + string fileData; + try + { + using (var receiveStream = context.Request.InputStream) + using (var readStream = new StreamReader(receiveStream)) + { + fileData = readStream.ReadToEnd(); + if (string.IsNullOrEmpty(fileData)) return; + } + } + catch (Exception e) + { + throw new HttpException((int)HttpStatusCode.BadRequest, e.Message); + } + + var jss = new JavaScriptSerializer(); + var body = jss.Deserialize>(fileData); + + var fileName = (string)body["fileName"]; + var version = (int)body["version"]; + + var key = ServiceConverter.GenerateRevisionId(DocManagerHelper.CurUserHostAddress() + + "/" + fileName + "/" + + File.GetLastWriteTime(DocManagerHelper.StoragePath(fileName, null)).GetHashCode()); + + var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(fileName, null)); + var currentVersionDir = DocManagerHelper.VersionDir(histDir, DocManagerHelper.GetFileVersion(histDir)); + var verDir = DocManagerHelper.VersionDir(histDir, version); + + if (!Directory.Exists(currentVersionDir)) Directory.CreateDirectory(currentVersionDir); + + var ext = Path.GetExtension(fileName).ToLower(); + File.Copy(DocManagerHelper.StoragePath(fileName, null), Path.Combine(currentVersionDir, "prev" + ext)); + + File.WriteAllText(Path.Combine(currentVersionDir, "key.txt"), key); + + var changesPath = Path.Combine(DocManagerHelper.VersionDir(histDir, version - 1), "changes.json"); + if (File.Exists(changesPath)) + { + File.Copy(changesPath, Path.Combine(currentVersionDir, "changes.json")); + } + + File.Copy(Path.Combine(verDir, "prev" + ext), DocManagerHelper.StoragePath(fileName, null), true); + + var fileInfo = new FileInfo(DocManagerHelper.StoragePath(fileName, null)); + fileInfo.LastWriteTimeUtc = DateTime.UtcNow; + + var history = GetHistory(fileName); + + context.Response.Write(jss.Serialize(history)); + } + // download a history file private static void DownloadHistory(HttpContext context) { @@ -687,6 +864,70 @@ private static void Reference(HttpContext context) context.Response.Write(jss.Serialize(data)); } + // get the document history + private static Dictionary GetHistory(string fileName) + { + var jss = new JavaScriptSerializer(); + var histDir = DocManagerHelper.HistoryDir(DocManagerHelper.StoragePath(fileName, null)); + + var history = new Dictionary(); + + var currentVersion = DocManagerHelper.GetFileVersion(histDir); + var currentKey = ServiceConverter.GenerateRevisionId(DocManagerHelper.CurUserHostAddress() + + "/" + fileName + "/" + + File.GetLastWriteTime(DocManagerHelper.StoragePath(fileName, null)).GetHashCode()); + + var versionList = new List>(); + for (var versionNum = 1; versionNum <= currentVersion; versionNum++) + { + var versionObj = new Dictionary(); + var verDir = DocManagerHelper.VersionDir(histDir, versionNum); // get the path to the given file version + + var key = versionNum == currentVersion ? currentKey : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key + + versionObj.Add("key", key); + versionObj.Add("version", versionNum); + + var changesPath = Path.Combine(DocManagerHelper.VersionDir(histDir, versionNum - 1), "changes.json"); + if (versionNum == 1 || !File.Exists(changesPath)) // check if the version number is equal to 1 + { + var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file + if (File.Exists(infoPath)) + { + var info = jss.Deserialize>(File.ReadAllText(infoPath)); + versionObj.Add("created", info["created"]); // write meta information to the object (user information and creation date) + versionObj.Add("user", new Dictionary() + { + { "id", info["id"] }, + { "name", info["name"] }, + }); + } + } + else if (versionNum > 1) // check if the version number is greater than 1 (the file was modified) + { + // get the path to the changes.json file + var changes = jss.Deserialize>(File.ReadAllText(changesPath)); + var changesArray = (ArrayList)changes["changes"]; + var change = changesArray.Count > 0 + ? (Dictionary)changesArray[0] + : new Dictionary(); + + // write information about changes to the object + versionObj.Add("changes", change.Count > 0 ? changes["changes"] : null); + versionObj.Add("serverVersion", changes["serverVersion"]); + versionObj.Add("created", change.Count > 0 ? change["created"] : null); + versionObj.Add("user", change.Count > 0 ? change["user"] : null); + } + + versionList.Add(versionObj); + } + + history.Add("currentVersion", currentVersion); + history.Add("history", versionList); + + return history; + } + } } \ No newline at end of file diff --git a/web/documentserver-example/csharp-mvc/licenses/3rd-Party.license b/web/documentserver-example/csharp-mvc/licenses/3rd-Party.license index da13a379b..e14b47cb1 100644 --- a/web/documentserver-example/csharp-mvc/licenses/3rd-Party.license +++ b/web/documentserver-example/csharp-mvc/licenses/3rd-Party.license @@ -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 diff --git a/web/documentserver-example/csharp-mvc/web.appsettings.config b/web/documentserver-example/csharp-mvc/web.appsettings.config index 245df5ea6..5d7ebdfee 100644 --- a/web/documentserver-example/csharp-mvc/web.appsettings.config +++ b/web/documentserver-example/csharp-mvc/web.appsettings.config @@ -1,7 +1,7 @@ - + diff --git a/web/documentserver-example/csharp/3rd-Party.license b/web/documentserver-example/csharp/3rd-Party.license index 56e6a6b30..78b44588a 100644 --- a/web/documentserver-example/csharp/3rd-Party.license +++ b/web/documentserver-example/csharp/3rd-Party.license @@ -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 diff --git a/web/documentserver-example/csharp/Default.aspx.cs b/web/documentserver-example/csharp/Default.aspx.cs index cf74da10b..403afb44c 100644 --- a/web/documentserver-example/csharp/Default.aspx.cs +++ b/web/documentserver-example/csharp/Default.aspx.cs @@ -633,5 +633,12 @@ public static string GetDirectUrlParam() string isEnabledDirectUrl = HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query).Get("directUrl"); return "&directUrl=" + (isEnabledDirectUrl != null ? isEnabledDirectUrl : "false"); } + + // get direct url flag + public static bool IsEnabledDirectUrl() + { + string isEnabledDirectUrl = HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query).Get("directUrl"); + return isEnabledDirectUrl != null ? Convert.ToBoolean(isEnabledDirectUrl) : false; + } } } \ No newline at end of file diff --git a/web/documentserver-example/csharp/DocEditor.aspx b/web/documentserver-example/csharp/DocEditor.aspx index d0e0cf6ef..b2600d788 100644 --- a/web/documentserver-example/csharp/DocEditor.aspx +++ b/web/documentserver-example/csharp/DocEditor.aspx @@ -221,20 +221,49 @@ }; if (config.editorConfig.user.id) { - <% if (!string.IsNullOrEmpty(History) && !string.IsNullOrEmpty(HistoryData)) - { %> - config.events['onRequestHistory'] = function () { // the user is trying to show the document version history - docEditor.refreshHistory(<%= History %>); // show the document version history - }; - config.events['onRequestHistoryData'] = function (event) { // the user is trying to click the specific document version in the document version history - var ver = event.data; - var histData = <%= HistoryData %>; - docEditor.setHistoryData(histData[ver - 1]); // send the link to the document for viewing the version history - }; - config.events['onRequestHistoryClose'] = function () { // the user is trying to go back to the document from viewing the document version history - document.location.reload(); + + config.events['onRequestHistory'] = function (event) { // the user is trying to show the document version history + + let xhr = new XMLHttpRequest(); + xhr.open("GET", "webeditor.ashx?type=gethistory&filename=<%= FileName %>"); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.send(); + xhr.onload = function () { + console.log(xhr.responseText); + docEditor.refreshHistory(JSON.parse(xhr.responseText)); + } + }; + config.events['onRequestHistoryData'] = function (event) { // the user is trying to click the specific document version in the document version history + var ver = event.data; + + let xhr = new XMLHttpRequest(); + xhr.open("GET", "webeditor.ashx?type=getversiondata&filename=<%= FileName %>&version=" + ver + "&directUrl=" + !!config.document.directUrl); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.send(); + xhr.onload = function () { + console.log(xhr.responseText); + docEditor.setHistoryData(JSON.parse(xhr.responseText)); // send the link to the document for viewing the version history + } + }; + config.events['onRequestHistoryClose'] = function () { // the user is trying to go back to the document from viewing the document version history + document.location.reload(); + }; + config.events['onRequestRestore'] = function (event) { + var fileName = "<%= FileName %>"; + var version = event.data.version; + var data = { + fileName: fileName, + version: version }; - <% } %> + + let xhr = new XMLHttpRequest(); + xhr.open("POST", "webeditor.ashx?type=restore&directUrl=" + !!config.document.directUrl); + xhr.setRequestHeader('Content-Type', 'application/json'); + xhr.send(JSON.stringify(data)); + xhr.onload = function () { + docEditor.refreshHistory(JSON.parse(xhr.responseText)); + } + }; // add mentions for not anonymous users <% if (!string.IsNullOrEmpty(UsersForMentions)) diff --git a/web/documentserver-example/csharp/DocEditor.aspx.cs b/web/documentserver-example/csharp/DocEditor.aspx.cs index b842e94c9..108ab58d5 100755 --- a/web/documentserver-example/csharp/DocEditor.aspx.cs +++ b/web/documentserver-example/csharp/DocEditor.aspx.cs @@ -17,7 +17,6 @@ */ using System; -using System.Collections; using System.Collections.Generic; using System.IO; using System.Web; @@ -61,8 +60,6 @@ protected string DocServiceApiUri } protected string DocConfig { get; private set; } - protected string History { get; private set; } - protected string HistoryData { get; private set; } protected string InsertImageConfig { get; private set; } protected string CompareFileData { get; private set; } protected string DataMailMergeRecipients { get; private set; } @@ -195,7 +192,7 @@ protected void Page_Load(object sender, EventArgs e) { { "title", FileName }, { "url", getDownloadUrl(FileName) }, - { "directUrl", IsEnabledDirectUrl() ? directUrl : "" }, + { "directUrl", _Default.IsEnabledDirectUrl() ? directUrl : "" }, { "fileType", ext.Trim('.') }, { "key", Key }, { @@ -320,134 +317,10 @@ protected void Page_Load(object sender, EventArgs e) // get users for mentions List> usersData = Users.getUsersForMentions(user.id); UsersForMentions = !user.id.Equals("uid-0") ? jss.Serialize(usersData) : null; - - Dictionary hist; - Dictionary histData; - - // get the document history - GetHistory(out hist, out histData); - if (hist != null && histData != null) - { - History = jss.Serialize(hist); - HistoryData = jss.Serialize(histData); - } } catch { } } - // get the document history - private void GetHistory(out Dictionary history, out Dictionary historyData) - { - var storagePath = WebConfigurationManager.AppSettings["storage-path"]; - var jss = new JavaScriptSerializer(); - var histDir = _Default.HistoryDir(_Default.StoragePath(FileName, null)); - - history = null; - historyData = null; - - if (_Default.GetFileVersion(histDir) > 0) // if the file was modified (the file version is greater than 0) - { - var currentVersion = _Default.GetFileVersion(histDir); - var hist = new List>(); - var histData = new Dictionary(); - - for (var i = 1; i <= currentVersion; i++) // run through all the file versions - { - var obj = new Dictionary(); - var dataObj = new Dictionary(); - var verDir = _Default.VersionDir(histDir, i); // get the path to the given file version - - var key = i == currentVersion ? Key : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key - - obj.Add("key", key); - obj.Add("version", i); - - if (i == 1) // check if the version number is equal to 1 - { - var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file - - if (File.Exists(infoPath)) { - var info = jss.Deserialize>(File.ReadAllText(infoPath)); - obj.Add("created", info["created"]); // write meta information to the object (user information and creation date) - obj.Add("user", new Dictionary() { - { "id", info["id"] }, - { "name", info["name"] }, - }); - } - } - - var ext = Path.GetExtension(FileName).ToLower(); - dataObj.Add("fileType", ext.Replace(".", "")); - dataObj.Add("key", key); - // write file url to the data object - var directPrevFileUrl = i == currentVersion ? _Default.FileUri(FileName, false) : MakePublicHistoryUrl(FileName, i.ToString(), "prev" + ext, false); - var prevFileUrl = i == currentVersion ? FileUri : MakePublicHistoryUrl(FileName, i.ToString(), "prev" + ext); - if (Path.IsPathRooted(storagePath)) - { - prevFileUrl = i == currentVersion ? getDownloadUrl(FileName) : getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", "")); - directPrevFileUrl = i == currentVersion ? getDownloadUrl(FileName, false) : getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false); - } - - dataObj.Add("url", prevFileUrl); // write file url to the data object - - if (IsEnabledDirectUrl()) - { - dataObj.Add("directUrl", directPrevFileUrl); // write direct url to the data object - } - - dataObj.Add("version", i); - if (i > 1) // check if the version number is greater than 1 (the file was modified) - { - // get the path to the changes.json file - var changes = jss.Deserialize>(File.ReadAllText(Path.Combine(_Default.VersionDir(histDir, i - 1), "changes.json"))); - var changesArray = (ArrayList)changes["changes"]; - var change = changesArray.Count > 0 - ? (Dictionary)changesArray[0] - : new Dictionary(); - - // write information about changes to the object - obj.Add("changes", change.Count > 0 ? changes["changes"] : null); - obj.Add("serverVersion", changes["serverVersion"]); - obj.Add("created", change.Count > 0 ? change["created"] : null); - obj.Add("user", change.Count > 0 ? change["user"] : null); - - var prev = (Dictionary)histData[(i - 2).ToString()]; // get the history data from the previous file version - - Dictionary dataPrev = new Dictionary() { // write information about previous file version to the data object - { "fileType", prev["fileType"] }, - { "key", prev["key"] }, // write key and url information about previous file version - { "url", prev["url"] } - }; - - if (IsEnabledDirectUrl()) - { - dataPrev.Add("directUrl", prev["directUrl"]); - } - - dataObj.Add("previous", dataPrev); - // write the path to the diff.zip archive with differences in this file version - var changesUrl = MakePublicHistoryUrl(FileName, (i - 1).ToString(), "diff.zip"); - dataObj.Add("changesUrl", changesUrl); - } - if (JwtManager.Enabled) - { - var token = JwtManager.Encode(dataObj); - dataObj.Add("token", token); - } - hist.Add(obj); // add object dictionary to the hist list - histData.Add((i - 1).ToString(), dataObj); // write data object information to the history data - } - - // write history information about the current file version to the history object - history = new Dictionary() - { - { "currentVersion", currentVersion }, - { "history", hist } - }; - historyData = histData; - } - } - // get a logo config private Dictionary GetLogoConfig() { @@ -469,7 +342,7 @@ private Dictionary GetLogoConfig() { "url", InsertImageUrl.ToString()} }; - if (IsEnabledDirectUrl()) + if (_Default.IsEnabledDirectUrl()) { logoConfig.Add("directUrl", DirectImageUrl.ToString()); } @@ -506,7 +379,7 @@ private Dictionary GetCompareFile() { "url", compareFileUrl.ToString() } }; - if (IsEnabledDirectUrl()) + if (_Default.IsEnabledDirectUrl()) { dataCompareFile.Add("directUrl", DirectFileUrl.ToString()); } @@ -545,7 +418,7 @@ private Dictionary GetMailMergeConfig() { "url", mailmergeUrl.ToString() } }; - if (IsEnabledDirectUrl()) + if (_Default.IsEnabledDirectUrl()) { mailMergeConfig.Add("directUrl", DirectMailMergeUrl.ToString()); } @@ -589,21 +462,6 @@ private string MakePublicUrl(string fullPath) return _Default.GetServerUrl(true) + fullPath.Substring(root.Length).Replace(Path.DirectorySeparatorChar, '/'); } - - // create the public history url - private string MakePublicHistoryUrl(string filename, string version, string file, Boolean isServer = true) - { - var userAddress = isServer ? "&userAddress=" + HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)) : ""; - var fileUrl = new UriBuilder(_Default.GetServerUrl(isServer)); - fileUrl.Path = HttpRuntime.AppDomainAppVirtualPath - + (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/") - + "webeditor.ashx"; - fileUrl.Query = "type=downloadhistory&fileName=" + HttpUtility.UrlEncode(filename) - + "&ver=" + version + "&file=" + file - + userAddress; - return fileUrl.ToString(); - } - // create demo document private static void Try(string type, string sample, HttpRequest request) { @@ -652,12 +510,5 @@ public static void CreateMeta(string fileName, string uid, string uname, string { "name", uname } })); } - - // get direct url flag - private static bool IsEnabledDirectUrl() - { - string isEnabledDirectUrl = HttpUtility.ParseQueryString(HttpContext.Current.Request.Url.Query).Get("directUrl"); - return isEnabledDirectUrl != null ? Convert.ToBoolean(isEnabledDirectUrl) : false; - } } } \ No newline at end of file diff --git a/web/documentserver-example/csharp/WebEditor.ashx.cs b/web/documentserver-example/csharp/WebEditor.ashx.cs index 74caded78..f79e9f4bb 100644 --- a/web/documentserver-example/csharp/WebEditor.ashx.cs +++ b/web/documentserver-example/csharp/WebEditor.ashx.cs @@ -26,7 +26,9 @@ using System.Web.Configuration; using System.Linq; using System.Net; +using System.Collections; using System.Net.Sockets; +using ASC.Api.DocumentConverter; namespace OnlineEditorsExample { @@ -48,6 +50,15 @@ public void ProcessRequest(HttpContext context) case "downloadhistory": DownloadHistory(context); break; + case "gethistory": + GetHistory(context); + break; + case "getversiondata": + GetVersionData(context); + break; + case "restore": + Restore(context); + break; case "convert": Convert(context); break; @@ -333,6 +344,164 @@ public bool IsReusable get { return false; } } + private static void GetHistory(HttpContext context) + { + var jss = new JavaScriptSerializer(); + var fileName = context.Request["filename"]; + + var history = GetHistory(fileName); + + context.Response.Write(jss.Serialize(history)); + } + + private static void GetVersionData(HttpContext context) + { + var storagePath = WebConfigurationManager.AppSettings["storage-path"]; + var jss = new JavaScriptSerializer(); + + var fileName = context.Request["filename"]; + int version; + + if (!int.TryParse(context.Request["version"], out version)) + { + context.Response.Write("{ \"error\": \"Version number invalid!\"}"); + return; + } + + var versionData = new Dictionary(); + + var histDir = _Default.HistoryDir(_Default.StoragePath(fileName, null)); + var lastVersion = _Default.GetFileVersion(histDir); + + var verDir = _Default.VersionDir(histDir, version); + + var lastVersionUri = _Default.FileUri(fileName, true); + var key = version == lastVersion + ? ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null) + + "/" + Path.GetFileName(lastVersionUri) + + "/" + File.GetLastWriteTime(_Default.StoragePath(fileName, null)).GetHashCode()) + : File.ReadAllText(Path.Combine(verDir, "key.txt")); + + + var ext = Path.GetExtension(fileName).ToLower(); + versionData.Add("fileType", ext.Replace(".", "")); + versionData.Add("key", key); + + var directPrevFileUrl = version == lastVersion ? _Default.FileUri(fileName, false) : MakePublicHistoryUrl(fileName, version.ToString(), "prev" + ext, false); + var prevFileUrl = version == lastVersion ? lastVersionUri : MakePublicHistoryUrl(fileName, version.ToString(), "prev" + ext); + if (Path.IsPathRooted(storagePath)) + { + prevFileUrl = version == lastVersion ? DocEditor.getDownloadUrl(fileName) : DocEditor.getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", "")); + directPrevFileUrl = version == lastVersion ? DocEditor.getDownloadUrl(fileName, false) : DocEditor.getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", ""), false); + } + + versionData.Add("url", prevFileUrl); + + if (_Default.IsEnabledDirectUrl()) + { + versionData.Add("directUrl", directPrevFileUrl); // write direct url to the data object + } + + versionData.Add("version", version); + if (version > 1) + { + var prevVerDir = _Default.VersionDir(histDir, version - 1); + + var prevUrl = MakePublicHistoryUrl(fileName, (version - 1).ToString(), "prev" + ext); + if (Path.IsPathRooted(storagePath)) + prevUrl = DocEditor.getDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", "")); + + var prevKey = File.ReadAllText(Path.Combine(prevVerDir, "key.txt")); + + Dictionary dataPrev = new Dictionary() { // write information about previous file version to the data object + { "fileType", ext.Replace(".", "") }, + { "key", prevKey }, // write key and url information about previous file version + { "url", prevUrl } + }; + + string directPrevUrl; + if (_Default.IsEnabledDirectUrl()) + { + directPrevUrl = Path.IsPathRooted(storagePath) + ? DocEditor.getDownloadUrl(Directory.GetFiles(prevVerDir, "prev.*")[0].Replace(storagePath + "\\", ""), false) + : MakePublicHistoryUrl(fileName, (version - 1).ToString(), "prev" + ext, false); + + dataPrev.Add("directUrl", directPrevUrl); // write direct url to the data object + } + + versionData.Add("previous", dataPrev); + + if (File.Exists(Path.Combine(prevVerDir, "diff.zip"))) + { + var changesUrl = MakePublicHistoryUrl(fileName, (version - 1).ToString(), "diff.zip"); + versionData.Add("changesUrl", changesUrl); + } + } + + if (JwtManager.Enabled) + { + var token = JwtManager.Encode(versionData); + versionData.Add("token", token); + } + + context.Response.Write(jss.Serialize(versionData)); + } + + private void Restore(HttpContext context) + { + string fileData; + try + { + using (var receiveStream = context.Request.InputStream) + using (var readStream = new StreamReader(receiveStream)) + { + fileData = readStream.ReadToEnd(); + if (string.IsNullOrEmpty(fileData)) return; + } + } + catch (Exception e) + { + throw new HttpException((int)HttpStatusCode.BadRequest, e.Message); + } + + var jss = new JavaScriptSerializer(); + var body = jss.Deserialize>(fileData); + + var fileName = (string)body["fileName"]; + var version = (int)body["version"]; + + var lastVersionUri = _Default.FileUri(fileName, true); + var key = ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null) + + "/" + Path.GetFileName(lastVersionUri) + + "/" + File.GetLastWriteTime(_Default.StoragePath(fileName, null)).GetHashCode()); + + var histDir = _Default.HistoryDir(_Default.StoragePath(fileName, null)); + var currentVersionDir = _Default.VersionDir(histDir, _Default.GetFileVersion(histDir)); + var verDir = _Default.VersionDir(histDir, version); + + if (!Directory.Exists(currentVersionDir)) Directory.CreateDirectory(currentVersionDir); + + var ext = Path.GetExtension(fileName).ToLower(); + File.Copy(_Default.StoragePath(fileName, null), Path.Combine(currentVersionDir, "prev" + ext)); + + File.WriteAllText(Path.Combine(currentVersionDir, "key.txt"), key); + + var changesPath = Path.Combine(_Default.VersionDir(histDir, version - 1), "changes.json"); + if (File.Exists(changesPath)) + { + File.Copy(changesPath, Path.Combine(currentVersionDir, "changes.json")); + } + + File.Copy(Path.Combine(verDir, "prev" + ext), _Default.StoragePath(fileName, null), true); + + var fileInfo = new FileInfo(_Default.StoragePath(fileName, null)); + fileInfo.LastWriteTimeUtc = DateTime.UtcNow; + + var history = GetHistory(fileName); + + context.Response.Write(jss.Serialize(history)); + } + private static void DownloadHistory(HttpContext context) { try @@ -504,5 +673,84 @@ private static void Reference(HttpContext context) context.Response.Write(jss.Serialize(data)); } + + // get the document history + private static Dictionary GetHistory(string fileName) + { + var jss = new JavaScriptSerializer(); + var histDir = _Default.HistoryDir(_Default.StoragePath(fileName, null)); + + var history = new Dictionary(); + + var currentVersion = _Default.GetFileVersion(histDir); + var currentFileUri = _Default.FileUri(fileName, true); + var currentKey = ServiceConverter.GenerateRevisionId(_Default.CurUserHostAddress(null) + + "/" + Path.GetFileName(currentFileUri) + + "/" + File.GetLastWriteTime(_Default.StoragePath(fileName, null)).GetHashCode()); + + var versionList = new List>(); + for (var versionNum = 1; versionNum <= currentVersion; versionNum++) + { + var versionObj = new Dictionary(); + var verDir = _Default.VersionDir(histDir, versionNum); // get the path to the given file version + + var key = versionNum == currentVersion ? currentKey : File.ReadAllText(Path.Combine(verDir, "key.txt")); // get document key + + versionObj.Add("key", key); + versionObj.Add("version", versionNum); + + var changesPath = Path.Combine(_Default.VersionDir(histDir, versionNum - 1), "changes.json"); + if (versionNum == 1 || !File.Exists(changesPath)) // check if the version number is equal to 1 + { + var infoPath = Path.Combine(histDir, "createdInfo.json"); // get meta data of this file + if (File.Exists(infoPath)) + { + var info = jss.Deserialize>(File.ReadAllText(infoPath)); + versionObj.Add("created", info["created"]); // write meta information to the object (user information and creation date) + versionObj.Add("user", new Dictionary() + { + { "id", info["id"] }, + { "name", info["name"] }, + }); + } + } + else if (versionNum > 1) // check if the version number is greater than 1 (the file was modified) + { + // get the path to the changes.json file + var changes = jss.Deserialize>(File.ReadAllText(changesPath)); + var changesArray = (ArrayList)changes["changes"]; + var change = changesArray.Count > 0 + ? (Dictionary)changesArray[0] + : new Dictionary(); + + // write information about changes to the object + versionObj.Add("changes", change.Count > 0 ? changes["changes"] : null); + versionObj.Add("serverVersion", changes["serverVersion"]); + versionObj.Add("created", change.Count > 0 ? change["created"] : null); + versionObj.Add("user", change.Count > 0 ? change["user"] : null); + } + + versionList.Add(versionObj); + } + + history.Add("currentVersion", currentVersion); + history.Add("history", versionList); + + return history; + } + + // create the public history url + private static string MakePublicHistoryUrl(string filename, string version, string file, Boolean isServer = true) + { + var userAddress = isServer ? "&userAddress=" + HttpUtility.UrlEncode(_Default.CurUserHostAddress(HttpContext.Current.Request.UserHostAddress)) : ""; + var fileUrl = new UriBuilder(_Default.GetServerUrl(isServer)); + fileUrl.Path = HttpRuntime.AppDomainAppVirtualPath + + (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/") + + "webeditor.ashx"; + fileUrl.Query = "type=downloadhistory&fileName=" + HttpUtility.UrlEncode(filename) + + "&ver=" + version + "&file=" + file + + userAddress; + return fileUrl.ToString(); + } } } \ No newline at end of file diff --git a/web/documentserver-example/csharp/licenses/3rd-Party.license b/web/documentserver-example/csharp/licenses/3rd-Party.license index 56e6a6b30..78b44588a 100644 --- a/web/documentserver-example/csharp/licenses/3rd-Party.license +++ b/web/documentserver-example/csharp/licenses/3rd-Party.license @@ -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 diff --git a/web/documentserver-example/csharp/settings.config b/web/documentserver-example/csharp/settings.config index e2486942b..b9b1b0bcc 100644 --- a/web/documentserver-example/csharp/settings.config +++ b/web/documentserver-example/csharp/settings.config @@ -1,7 +1,7 @@ - + diff --git a/web/documentserver-example/java-spring/3rd-Party.license b/web/documentserver-example/java-spring/3rd-Party.license index 73cd80c62..bd056534b 100755 --- a/web/documentserver-example/java-spring/3rd-Party.license +++ b/web/documentserver-example/java-spring/3rd-Party.license @@ -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 diff --git a/web/documentserver-example/java-spring/licenses/3rd-Party.license b/web/documentserver-example/java-spring/licenses/3rd-Party.license index ab7d608c0..bd056534b 100644 --- a/web/documentserver-example/java-spring/licenses/3rd-Party.license +++ b/web/documentserver-example/java-spring/licenses/3rd-Party.license @@ -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 \ No newline at end of file diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java index 520d60a16..c5259eaed 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/controllers/FileController.java @@ -35,6 +35,8 @@ 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.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.springframework.beans.factory.annotation.Autowired; @@ -49,6 +51,7 @@ import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; @@ -56,14 +59,20 @@ import javax.servlet.http.HttpServletRequest; import java.io.File; +import java.io.FileInputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.net.InetAddress; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.LinkedHashMap; import java.util.Map; @@ -355,13 +364,13 @@ public String create(@RequestParam("fileExt") @GetMapping("/assets") public ResponseEntity assets(@RequestParam("name") final String name) { // get sample files from the assests - String fileName = Path.of("assets", "sample", fileUtility.getFileName(name)).toString(); + String fileName = Path.of("assets", "document-templates", "sample", fileUtility.getFileName(name)).toString(); return downloadFile(fileName); } @GetMapping("/csv") public ResponseEntity csv() { // download a csv file - String fileName = Path.of("assets", "sample", "csv.csv").toString(); + String fileName = Path.of("assets", "document-templates", "sample", "csv.csv").toString(); return downloadFile(fileName); } @@ -528,4 +537,88 @@ public String reference(@RequestBody final JSONObject body) { return "{ \"error\" : 1, \"message\" : \"" + e.getMessage() + "\"}"; } } + + @PutMapping("/restore") + @ResponseBody + public String restore(@RequestBody final JSONObject body) { + try { + String sourceBasename = (String) body.get("fileName"); + Integer version = (Integer) body.get("version"); + String userID = (String) body.get("userId"); + + String sourceStringFile = storagePathBuilder.getFileLocation(sourceBasename); + File sourceFile = new File(sourceStringFile); + Path sourcePathFile = sourceFile.toPath(); + String historyDirectory = storagePathBuilder.getHistoryDir(sourcePathFile.toString()); + + Integer bumpedVersion = storagePathBuilder.getFileVersion(historyDirectory, false); + String bumpedVersionStringDirectory = documentManager.versionDir(historyDirectory, bumpedVersion, true); + File bumpedVersionDirectory = new File(bumpedVersionStringDirectory); + if (!bumpedVersionDirectory.exists()) { + bumpedVersionDirectory.mkdir(); + } + + Path bumpedKeyPathFile = Paths.get(bumpedVersionStringDirectory, "key.txt"); + String bumpedKeyStringFile = bumpedKeyPathFile.toString(); + File bumpedKeyFile = new File(bumpedKeyStringFile); + String bumpedKey = serviceConverter.generateRevisionId( + storagePathBuilder.getStorageLocation() + + "/" + + sourceBasename + + "/" + + Long.toString(sourceFile.lastModified()) + ); + FileWriter bumpedKeyFileWriter = new FileWriter(bumpedKeyFile); + bumpedKeyFileWriter.write(bumpedKey); + bumpedKeyFileWriter.close(); + + Integer userInnerID = Integer.parseInt(userID.replace("uid-", "")); + User user = userService.findUserById(userInnerID).get(); + + Path bumpedChangesPathFile = Paths.get(bumpedVersionStringDirectory, "changes.json"); + String bumpedChangesStringFile = bumpedChangesPathFile.toString(); + File bumpedChangesFile = new File(bumpedChangesStringFile); + JSONObject bumpedChangesUser = new JSONObject(); + // Don't add the `uid-` prefix. + // https://github.com/ONLYOFFICE/document-server-integration/issues/437#issuecomment-1663526562 + bumpedChangesUser.put("id", user.getId()); + bumpedChangesUser.put("name", user.getName()); + JSONObject bumpedChangesChangesItem = new JSONObject(); + bumpedChangesChangesItem.put("created", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + bumpedChangesChangesItem.put("user", bumpedChangesUser); + JSONArray bumpedChangesChanges = new JSONArray(); + bumpedChangesChanges.add(bumpedChangesChangesItem); + JSONObject bumpedChanges = new JSONObject(); + bumpedChanges.put("serverVersion", null); + bumpedChanges.put("changes", bumpedChangesChanges); + String bumpedChangesContent = bumpedChanges.toJSONString(); + FileWriter bumpedChangesFileWriter = new FileWriter(bumpedChangesFile); + bumpedChangesFileWriter.write(bumpedChangesContent); + bumpedChangesFileWriter.close(); + + String sourceExtension = fileUtility.getFileExtension(sourceBasename); + String previousBasename = "prev" + sourceExtension; + + Path bumpedFile = Paths.get(bumpedVersionStringDirectory, previousBasename); + Files.move(sourcePathFile, bumpedFile); + + String recoveryVersionStringDirectory = documentManager.versionDir(historyDirectory, version, true); + Path recoveryPathFile = Paths.get(recoveryVersionStringDirectory, previousBasename); + String recoveryStringFile = recoveryPathFile.toString(); + FileInputStream recoveryStream = new FileInputStream(recoveryStringFile); + storageMutator.createFile(sourcePathFile, recoveryStream); + recoveryStream.close(); + + JSONObject responseBody = new JSONObject(); + responseBody.put("error", null); + responseBody.put("success", true); + return responseBody.toJSONString(); + } catch (Exception error) { + error.printStackTrace(); + JSONObject responseBody = new JSONObject(); + responseBody.put("error", error.getMessage()); + responseBody.put("success", false); + return responseBody.toJSONString(); + } + } } diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/callback/DefaultCallbackManager.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/callback/DefaultCallbackManager.java index b2dbdabf8..40434befc 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/callback/DefaultCallbackManager.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/callback/DefaultCallbackManager.java @@ -163,6 +163,8 @@ public void processSave(final Track body, final String fileName) { // file savi storageMutator.createDirectory(ver); // create the file version directory + lastVersion.toFile().renameTo(new File(versionDir + File.separator + "prev" + curExt)); + saveFile(byteArrayFile, toSave); // save document file byte[] byteArrayChanges = getDownloadFile(changesUri); // download file changes diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/document/DefaultDocumentManager.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/document/DefaultDocumentManager.java index 022f3d3d4..1baecb46b 100755 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/document/DefaultDocumentManager.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/managers/document/DefaultDocumentManager.java @@ -217,8 +217,14 @@ public String versionDir(final String path, final Integer version, final boolean public String createDemo(final String fileExt, final Boolean sample, final String uid, final String uname) { String demoName = (sample ? "sample." : "new.") + fileExt; // create sample or new template file with the necessary extension - String demoPath = "assets" + File.separator + (sample ? "sample" : "new") - + File.separator + demoName; // get the path to the sample document + String demoPath = + "assets" + + File.separator + + "document-templates" + + File.separator + + (sample ? "sample" : "new") + + File.separator + + demoName; // get a file name with an index if the file with such a name already exists String fileName = getCorrectName(demoName); diff --git a/web/documentserver-example/java-spring/src/main/resources/application.properties b/web/documentserver-example/java-spring/src/main/resources/application.properties index 1cf199a8d..9598b9355 100755 --- a/web/documentserver-example/java-spring/src/main/resources/application.properties +++ b/web/documentserver-example/java-spring/src/main/resources/application.properties @@ -1,4 +1,4 @@ -server.version=1.6.0 +server.version=1.7.0 server.address= server.port=4000 diff --git a/web/documentserver-example/java-spring/src/main/resources/assets b/web/documentserver-example/java-spring/src/main/resources/assets/document-templates similarity index 100% rename from web/documentserver-example/java-spring/src/main/resources/assets rename to web/documentserver-example/java-spring/src/main/resources/assets/document-templates diff --git a/web/documentserver-example/java-spring/src/main/resources/templates/editor.html b/web/documentserver-example/java-spring/src/main/resources/templates/editor.html index fd2bd2557..e74424817 100755 --- a/web/documentserver-example/java-spring/src/main/resources/templates/editor.html +++ b/web/documentserver-example/java-spring/src/main/resources/templates/editor.html @@ -172,6 +172,28 @@ } }; + function onRequestRestore(event) { + const query = new URLSearchParams(window.location.search) + const config = [[${model}]] + const payload = { + fileName: query.get('fileName'), + version: event.data.version, + userId: config.editorConfig.user.id + } + const request = new XMLHttpRequest() + request.open('PUT', 'restore') + request.setRequestHeader('Content-Type', 'application/json') + request.send(JSON.stringify(payload)) + request.onload = function () { + if (request.status != 200) { + response = JSON.parse(request.response) + innerAlert(response.error) + return + } + document.location.reload() + } + } + config.width = "100%"; config.height = "100%"; config.events = { @@ -184,6 +206,7 @@ "onRequestInsertImage": onRequestInsertImage, "onRequestCompareFile": onRequestCompareFile, "onRequestMailMergeRecipients": onRequestMailMergeRecipients, + "onRequestRestore": onRequestRestore }; var histArray = [[${fileHistory}]]; diff --git a/web/documentserver-example/java/3rd-Party.license b/web/documentserver-example/java/3rd-Party.license index ec8359e52..4d1f25a44 100644 --- a/web/documentserver-example/java/3rd-Party.license +++ b/web/documentserver-example/java/3rd-Party.license @@ -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 diff --git a/web/documentserver-example/java/licenses/3rd-Party.license b/web/documentserver-example/java/licenses/3rd-Party.license index ec8359e52..4d1f25a44 100644 --- a/web/documentserver-example/java/licenses/3rd-Party.license +++ b/web/documentserver-example/java/licenses/3rd-Party.license @@ -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 diff --git a/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java b/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java index a51559acd..663ffd72c 100755 --- a/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java +++ b/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java @@ -48,6 +48,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; @@ -57,7 +58,9 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.text.SimpleDateFormat; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.Map; import java.util.Scanner; @@ -126,6 +129,9 @@ protected void processRequest(final HttpServletRequest request, case "reference": reference(request, response, writer); break; + case "restore": + restore(request, response, writer); + break; default: break; } @@ -451,7 +457,7 @@ private static void files(final HttpServletRequest request, private static void csv(final HttpServletRequest request, final HttpServletResponse response, final PrintWriter writer) { - String fileName = "assets/sample/csv.csv"; + String fileName = "assets/document-templates/sample/csv.csv"; URL fileUrl = Thread.currentThread().getContextClassLoader().getResource(fileName); Path filePath = null; try { @@ -466,7 +472,7 @@ private static void csv(final HttpServletRequest request, private static void assets(final HttpServletRequest request, final HttpServletResponse response, final PrintWriter writer) { - String fileName = "assets/sample/" + FileUtility.getFileName(request.getParameter("name")); + String fileName = "assets/document-templates/sample/" + FileUtility.getFileName(request.getParameter("name")); URL fileUrl = Thread.currentThread().getContextClassLoader().getResource(fileName); Path filePath = null; try { @@ -728,6 +734,97 @@ private static void reference(final HttpServletRequest request, } } + private static void restore(final HttpServletRequest request, + final HttpServletResponse response, + final PrintWriter writer) { + try { + Scanner scanner = new Scanner(request.getInputStream()); + scanner.useDelimiter("\\A"); + String bodyString = scanner.hasNext() ? scanner.next() : ""; + scanner.close(); + + JSONParser parser = new JSONParser(); + JSONObject body = (JSONObject) parser.parse(bodyString); + + String sourceBasename = (String) body.get("fileName"); + Integer version = ((Long) body.get("version")).intValue(); + String userID = (String) body.get("userId"); + + String sourceStringFile = DocumentManager.storagePath(sourceBasename, null); + File sourceFile = new File(sourceStringFile); + Path sourcePathFile = sourceFile.toPath(); + String historyDirectory = DocumentManager.historyDir(sourceStringFile); + + Integer bumpedVersion = DocumentManager.getFileVersion(historyDirectory); + String bumpedVersionStringDirectory = DocumentManager.versionDir(historyDirectory, bumpedVersion); + File bumpedVersionDirectory = new File(bumpedVersionStringDirectory); + if (!bumpedVersionDirectory.exists()) { + bumpedVersionDirectory.mkdir(); + } + + Path bumpedKeyPathFile = Paths.get(bumpedVersionStringDirectory, "key.txt"); + String bumpedKeyStringFile = bumpedKeyPathFile.toString(); + File bumpedKeyFile = new File(bumpedKeyStringFile); + String bumpedKey = ServiceConverter.generateRevisionId( + DocumentManager.curUserHostAddress(null) + + "/" + + sourceBasename + + "/" + + Long.toString(sourceFile.lastModified()) + ); + FileWriter bumpedKeyFileWriter = new FileWriter(bumpedKeyFile); + bumpedKeyFileWriter.write(bumpedKey); + bumpedKeyFileWriter.close(); + + User user = Users.getUser(userID); + + Path bumpedChangesPathFile = Paths.get(bumpedVersionStringDirectory, "changes.json"); + String bumpedChangesStringFile = bumpedChangesPathFile.toString(); + File bumpedChangesFile = new File(bumpedChangesStringFile); + JSONObject bumpedChangesUser = new JSONObject(); + bumpedChangesUser.put("id", user.getId()); + bumpedChangesUser.put("name", user.getName()); + JSONObject bumpedChangesChangesItem = new JSONObject(); + bumpedChangesChangesItem.put("created", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())); + bumpedChangesChangesItem.put("user", bumpedChangesUser); + JSONArray bumpedChangesChanges = new JSONArray(); + bumpedChangesChanges.add(bumpedChangesChangesItem); + JSONObject bumpedChanges = new JSONObject(); + bumpedChanges.put("serverVersion", null); + bumpedChanges.put("changes", bumpedChangesChanges); + String bumpedChangesContent = bumpedChanges.toJSONString(); + FileWriter bumpedChangesFileWriter = new FileWriter(bumpedChangesFile); + bumpedChangesFileWriter.write(bumpedChangesContent); + bumpedChangesFileWriter.close(); + + String sourceExtension = FileUtility.getFileExtension(sourceBasename); + String previousBasename = "prev" + sourceExtension; + + Path bumpedFile = Paths.get(bumpedVersionStringDirectory, previousBasename); + Files.move(sourcePathFile, bumpedFile); + + String recoveryVersionStringDirectory = DocumentManager.versionDir(historyDirectory, version); + Path recoveryPathFile = Paths.get(recoveryVersionStringDirectory, previousBasename); + String recoveryStringFile = recoveryPathFile.toString(); + FileInputStream recoveryStream = new FileInputStream(recoveryStringFile); + DocumentManager.createFile(sourcePathFile, recoveryStream); + recoveryStream.close(); + + JSONObject responseBody = new JSONObject(); + responseBody.put("error", null); + responseBody.put("success", true); + String responseContent = responseBody.toJSONString(); + writer.write(responseContent); + } catch (Exception error) { + error.printStackTrace(); + JSONObject responseBody = new JSONObject(); + responseBody.put("error", error.getMessage()); + responseBody.put("success", false); + String responseContent = responseBody.toJSONString(); + writer.write(responseContent); + } + } + // process get request @Override protected void doGet(final HttpServletRequest request, @@ -742,6 +839,12 @@ protected void doPost(final HttpServletRequest request, processRequest(request, response); } + @Override + protected void doPut(final HttpServletRequest request, + final HttpServletResponse response) throws ServletException, IOException { + processRequest(request, response); + } + // get servlet information @Override public String getServletInfo() { diff --git a/web/documentserver-example/java/src/main/java/helpers/DocumentManager.java b/web/documentserver-example/java/src/main/java/helpers/DocumentManager.java index c3389a8fe..d4bfa66bf 100755 --- a/web/documentserver-example/java/src/main/java/helpers/DocumentManager.java +++ b/web/documentserver-example/java/src/main/java/helpers/DocumentManager.java @@ -306,7 +306,12 @@ public static String createDemo(final String fileExt, final Boolean sample, fina String demoName = (sample ? "sample." : "new.") + fileExt; // get the path to the sample document - String demoPath = "assets" + File.separator + (sample ? "sample" : "new") + File.separator; + String demoPath = "assets" + + File.separator + + "document-templates" + + File.separator + + (sample ? "sample" : "new") + + File.separator; // get a file name with an index if the file with such a name already exists String fileName = getCorrectName(demoName, null); diff --git a/web/documentserver-example/java/src/main/resources/assets b/web/documentserver-example/java/src/main/resources/assets/document-templates similarity index 100% rename from web/documentserver-example/java/src/main/resources/assets rename to web/documentserver-example/java/src/main/resources/assets/document-templates diff --git a/web/documentserver-example/java/src/main/resources/settings.properties b/web/documentserver-example/java/src/main/resources/settings.properties index a020e99dc..587b3d8e2 100644 --- a/web/documentserver-example/java/src/main/resources/settings.properties +++ b/web/documentserver-example/java/src/main/resources/settings.properties @@ -1,4 +1,4 @@ -version=1.6.0 +version=1.7.0 filesize-max=5242880 storage-folder=app_data diff --git a/web/documentserver-example/java/src/main/webapp/editor.jsp b/web/documentserver-example/java/src/main/webapp/editor.jsp index 39fa62204..9d78046e8 100644 --- a/web/documentserver-example/java/src/main/webapp/editor.jsp +++ b/web/documentserver-example/java/src/main/webapp/editor.jsp @@ -173,6 +173,26 @@ } }; + function onRequestRestore(event) { + const query = new URLSearchParams(window.location.search) + const payload = { + fileName: query.get('fileName'), + version: event.data.version, + userId: config.editorConfig.user.id + } + const request = new XMLHttpRequest() + request.open('PUT', 'IndexServlet?type=restore') + request.send(JSON.stringify(payload)) + request.onload = function () { + if (request.status != 200) { + response = JSON.parse(request.response) + innerAlert(response.error) + return + } + document.location.reload() + } + } + config = JSON.parse('<%= FileModel.serialize(Model) %>'); config.width = "100%"; config.height = "100%"; @@ -186,6 +206,7 @@ "onRequestInsertImage": onRequestInsertImage, "onRequestCompareFile": onRequestCompareFile, "onRequestMailMergeRecipients": onRequestMailMergeRecipients, + "onRequestRestore": onRequestRestore }; <% diff --git a/web/documentserver-example/nodejs/.eslintrc.js b/web/documentserver-example/nodejs/.eslintrc.js index f948b5f7e..8ca482700 100644 --- a/web/documentserver-example/nodejs/.eslintrc.js +++ b/web/documentserver-example/nodejs/.eslintrc.js @@ -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', }, }; diff --git a/web/documentserver-example/nodejs/3rd-Party.license b/web/documentserver-example/nodejs/3rd-Party.license index 0800cdc2a..4ce2bb5ad 100644 --- a/web/documentserver-example/nodejs/3rd-Party.license +++ b/web/documentserver-example/nodejs/3rd-Party.license @@ -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 diff --git a/web/documentserver-example/nodejs/app.js b/web/documentserver-example/nodejs/app.js index 9d674217e..ab586a007 100755 --- a/web/documentserver-example/nodejs/app.js +++ b/web/documentserver-example/nodejs/app.js @@ -1,4 +1,3 @@ -"use strict"; /** * * (c) Copyright Ascensio System SIA 2023 @@ -18,1071 +17,1114 @@ */ // connect the necessary packages and modules -const express = require("express"); -const path = require("path"); -const favicon = require("serve-favicon"); -const bodyParser = require("body-parser"); -const fileSystem = require("fs"); -const formidable = require("formidable"); +const express = require('express'); +const path = require('path'); +const favicon = require('serve-favicon'); +const bodyParser = require('body-parser'); +const fileSystem = require('fs'); +const formidable = require('formidable'); const jwt = require('jsonwebtoken'); const config = require('config'); +const mime = require('mime'); +const urllib = require('urllib'); +const { emitWarning } = require('process'); +const DocManager = require('./helpers/docManager'); +const documentService = require('./helpers/documentService'); +const fileUtility = require('./helpers/fileUtility'); +const wopiApp = require('./helpers/wopi/wopiRouting'); +const users = require('./helpers/users'); + const configServer = config.get('server'); -const storageFolder = configServer.get("storageFolder"); -const mime = require("mime"); -const docManager = require("./helpers/docManager"); -const documentService = require("./helpers/documentService"); -const fileUtility = require("./helpers/fileUtility"); -const wopiApp = require("./helpers/wopi/wopiRouting"); -const users = require("./helpers/users"); const siteUrl = configServer.get('siteUrl'); -const fileChoiceUrl = configServer.has('fileChoiceUrl') ? configServer.get('fileChoiceUrl') : ""; -const plugins = config.get('plugins'); +const fileChoiceUrl = configServer.has('fileChoiceUrl') ? configServer.get('fileChoiceUrl') : ''; 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 urllib = require("urllib"); -const { emitWarning } = require("process"); const verifyPeerOff = configServer.get('verify_peer_off'); +const plugins = config.get('plugins'); -if(verifyPeerOff) { - process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; +if (verifyPeerOff) { + process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'; } -String.prototype.hashCode = function () { - const len = this.length; - let ret = 0; - for (let i = 0; i < len; i++) { - ret = (31 * ret + this.charCodeAt(i)) << 0; - } - return ret; +String.prototype.hashCode = function hashCode() { + const len = this.length; + let ret = 0; + for (let i = 0; i < len; i++) { + ret = Math.trunc(31 * ret + this.charCodeAt(i)); + } + return ret; }; -String.prototype.format = function () { - let text = this.toString(); +String.prototype.format = function format(...args) { + let text = this.toString(); - if (!arguments.length) return text; + if (!args.length) return text; - for (let i = 0; i < arguments.length; i++) { - text = text.replace(new RegExp("\\{" + i + "\\}", "gi"), arguments[i]); - } + for (let i = 0; i < args.length; i++) { + text = text.replace(new RegExp(`\\{${i}\\}`, 'gi'), args[i]); + } - return text; + return text; }; +const app = express(); // create an application object +app.disable('x-powered-by'); +app.set('views', path.join(__dirname, 'views')); // specify the path to the main template +app.set('view engine', 'ejs'); // specify which template engine is used -const app = express(); // create an application object -app.disable("x-powered-by"); -app.set("views", path.join(__dirname, "views")); // specify the path to the main template -app.set("view engine", "ejs"); // specify which template engine is used - - -app.use(function (req, res, next) { - res.setHeader('Access-Control-Allow-Origin', '*'); // allow any Internet domain to access the resources of this site - next(); +app.use((req, res, next) => { + res.setHeader('Access-Control-Allow-Origin', '*'); // allow any Internet domain to access the resources of this site + next(); }); -app.use(express.static(path.join(__dirname, "public"))); // public directory -if (config.has('server.static')) { // check if there are static files such as .js, .css files, images, samples and process them +app.use(express.static(path.join(__dirname, 'public'))); // public directory +// check if there are static files such as .js, .css files, images, samples and process them +if (config.has('server.static')) { const staticContent = config.get('server.static'); - for (let i = 0; i < staticContent.length; ++i) { + for (let i = 0; i < staticContent.length; i++) { const staticContentElem = staticContent[i]; - app.use(staticContentElem['name'], express.static(staticContentElem['path'], staticContentElem['options'])); + app.use(staticContentElem.name, express.static(staticContentElem.path, staticContentElem.options)); } } -app.use(favicon(__dirname + "/public/images/favicon.ico")); // use favicon - - -app.use(bodyParser.json()); // connect middleware that parses json -app.use(bodyParser.urlencoded({ extended: false })); // connect middleware that parses urlencoded bodies - - -app.get("/", function (req, res) { // define a handler for default page - try { - - req.docManager = new docManager(req, res); - - res.render("index", { // render index template with the parameters specified - preloaderUrl: siteUrl + configServer.get('preloaderUrl'), - convertExts: configServer.get('convertedDocs'), - editedExts: configServer.get('editedDocs'), - fillExts: configServer.get("fillDocs"), - storedFiles: req.docManager.getStoredFiles(), - params: req.docManager.getCustomParams(), - users: users, - serverUrl: req.docManager.getServerUrl(), - 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; - } +app.use(favicon(`${__dirname}/public/images/favicon.ico`)); // use favicon + +app.use(bodyParser.json()); // connect middleware that parses json +app.use(bodyParser.urlencoded({ extended: false })); // connect middleware that parses urlencoded bodies + +app.get('/', (req, res) => { // define a handler for default page + try { + req.DocManager = new DocManager(req, res); + + res.render('index', { // render index template with the parameters specified + preloaderUrl: siteUrl + configServer.get('preloaderUrl'), + convertExts: fileUtility.getConvertExtensions(), + editedExts: fileUtility.getEditExtensions(), + fillExts: fileUtility.getFillExtensions(), + storedFiles: req.DocManager.getStoredFiles(), + params: req.DocManager.getCustomParams(), + users, + 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 + } }); -app.get("/download", function(req, res) { // define a handler for downloading files - req.docManager = new docManager(req, res); +app.get('/download', (req, res) => { // define a handler for downloading files + req.DocManager = new DocManager(req, res); - var fileName = fileUtility.getFileName(req.query.fileName); - var userAddress = req.query.useraddress; + const fileName = fileUtility.getFileName(req.query.fileName); + const userAddress = req.query.useraddress; + let token = ''; - if (!!userAddress + if (!!userAddress && cfgSignatureEnable && cfgSignatureUseForRequest) { - var authorization = req.get(cfgSignatureAuthorizationHeader); - if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) { - var token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length); - } - - try { - var decoded = jwt.verify(token, cfgSignatureSecret); - } catch (err) { - console.log('checkJwtHeader error: name = ' + err.name + ' message = ' + err.message + ' token = ' + token) - res.sendStatus(403); - return; - } + const authorization = req.get(cfgSignatureAuthorizationHeader); + if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) { + token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length); } - var path = req.docManager.forcesavePath(fileName, userAddress, false); // get the path to the force saved document version - if (path == "") { - path = req.docManager.storagePath(fileName, userAddress); // or to the original document + try { + jwt.verify(token, cfgSignatureSecret); + } catch (err) { + console.log(`checkJwtHeader error: name = ${err.name} message = ${err.message} token = ${token}`); + res.sendStatus(403); + return; } + } - res.setHeader("Content-Length", fileSystem.statSync(path).size); // add headers to the response to specify the page parameters - res.setHeader("Content-Type", mime.getType(path)); - - res.setHeader("Content-Disposition", "attachment; filename*=UTF-8\'\'" + encodeURIComponent(fileName)); + // get the path to the force saved document version + let filePath = req.DocManager.forcesavePath(fileName, userAddress, false); + if (filePath === '') { + filePath = req.DocManager.storagePath(fileName, userAddress); // or to the original document + } - var filestream = fileSystem.createReadStream(path); - filestream.pipe(res); // send file information to the response by streams -}); + // add headers to the response to specify the page parameters + res.setHeader('Content-Length', fileSystem.statSync(filePath).size); + res.setHeader('Content-Type', mime.getType(filePath)); -app.get("/history", function (req, res) { - req.docManager = new docManager(req, res); - if (cfgSignatureEnable && cfgSignatureUseForRequest) { - var authorization = req.get(cfgSignatureAuthorizationHeader); - if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) { - var token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length); - try { - var decoded = jwt.verify(token, cfgSignatureSecret); - } catch (err) { - console.log('checkJwtHeader error: name = ' + err.name + ' message = ' + err.message + ' token = ' + token); - res.sendStatus(403); - return; - } - } else { - res.sendStatus(403); - return; - } - } + res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(fileName)}`); - var fileName = req.query.fileName; - var userAddress = req.query.useraddress; - var ver = req.query.ver; - var file = req.query.file; + const filestream = fileSystem.createReadStream(filePath); + filestream.pipe(res); // send file information to the response by streams +}); - if (file.includes("diff")) { - var Path = req.docManager.diffPath(fileName, userAddress, ver); - } else if (file.includes("prev")) { - var Path = req.docManager.prevFilePath(fileName, userAddress, ver); - } else { +app.get('/history', (req, res) => { + req.DocManager = new DocManager(req, res); + if (cfgSignatureEnable && cfgSignatureUseForRequest) { + const authorization = req.get(cfgSignatureAuthorizationHeader); + if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) { + const token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length); + try { + jwt.verify(token, cfgSignatureSecret); + } catch (err) { + console.log(`checkJwtHeader error: name = ${err.name} message = ${err.message} token = ${token}`); res.sendStatus(403); return; + } + } else { + res.sendStatus(403); + return; } + } - res.setHeader("Content-Length", fileSystem.statSync(Path).size); // add headers to the response to specify the page parameters - res.setHeader("Content-Type", mime.getType(Path)); - res.setHeader("Content-Disposition", "attachment; filename*=UTF-8\'\'" + encodeURIComponent(file)); - - var filestream = fileSystem.createReadStream(Path); - filestream.pipe(res); // send file information to the response by streams -}) - -app.post("/upload", function (req, res) { // define a handler for uploading files - - req.docManager = new docManager(req, res); - req.docManager.storagePath(""); // mkdir if not exist - - const userIp = req.docManager.curUserHostAddress(); // get the path to the user host - const uploadDir = req.docManager.storageRootPath(userIp); - const uploadDirTmp = path.join(uploadDir, 'tmp'); // and create directory for temporary files if it doesn't exist - req.docManager.createDirectory(uploadDirTmp); - - const form = new formidable.IncomingForm(); // create a new incoming form - form.uploadDir = uploadDirTmp; // and write there all the necessary parameters - form.keepExtensions = true; + const { fileName } = req.query; + const userAddress = req.query.useraddress; + const { ver } = req.query; + const { file } = req.query; + let Path = ''; + + if (file.includes('diff')) { + Path = req.DocManager.diffPath(fileName, userAddress, ver); + } else if (file.includes('prev')) { + Path = req.DocManager.prevFilePath(fileName, userAddress, ver); + } else { + res.sendStatus(403); + return; + } - form.parse(req, function (err, fields, files) { // parse this form - if (err) { // if an error occurs - //docManager.cleanFolderRecursive(uploadDirTmp, true); // clean the folder with temporary files - res.writeHead(200, { "Content-Type": "text/plain" }); // and write the error status and message to the response - res.write("{ \"error\": \"" + err.message + "\"}"); - res.end(); - return; - } + // add headers to the response to specify the page parameters + res.setHeader('Content-Length', fileSystem.statSync(Path).size); + res.setHeader('Content-Type', mime.getType(Path)); + res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(file)}`); - const file = files.uploadedFile; + const filestream = fileSystem.createReadStream(Path); + filestream.pipe(res); // send file information to the response by streams +}); - if (file == undefined) { // if file parameter is undefined - res.writeHead(200, { "Content-Type": "text/plain" }); // write the error status and message to the response - res.write("{ \"error\": \"Uploaded file not found\"}"); - res.end(); - return; - } +app.post('/upload', (req, res) => { // define a handler for uploading files + req.DocManager = new DocManager(req, res); + req.DocManager.storagePath(''); // mkdir if not exist + + const userIp = req.DocManager.curUserHostAddress(); // get the path to the user host + const uploadDir = req.DocManager.storageRootPath(userIp); + const uploadDirTmp = path.join(uploadDir, 'tmp'); // and create directory for temporary files if it doesn't exist + req.DocManager.createDirectory(uploadDirTmp); + + const form = new formidable.IncomingForm(); // create a new incoming form + form.uploadDir = uploadDirTmp; // and write there all the necessary parameters + form.keepExtensions = true; + + form.parse(req, (err, fields, files) => { // parse this form + if (err) { // if an error occurs + // DocManager.cleanFolderRecursive(uploadDirTmp, true); // clean the folder with temporary files + res.writeHead(200, { 'Content-Type': 'text/plain' }); // and write the error status and message to the response + res.write(`{ "error": "${err.message}"}`); + res.end(); + return; + } - file.name = req.docManager.getCorrectName(file.name); + const file = files.uploadedFile; - if (configServer.get('maxFileSize') < file.size || file.size <= 0) { // check if the file size exceeds the maximum file size - //docManager.cleanFolderRecursive(uploadDirTmp, true); // clean the folder with temporary files - res.writeHead(200, { "Content-Type": "text/plain" }); - res.write("{ \"error\": \"File size is incorrect\"}"); - res.end(); - return; - } + if (file === undefined) { // if file parameter is undefined + res.writeHead(200, { 'Content-Type': 'text/plain' }); // write the error status and message to the response + res.write('{ "error": "Uploaded file not found"}'); + res.end(); + return; + } - const exts = [].concat(configServer.get('viewedDocs'), configServer.get('editedDocs'), configServer.get('convertedDocs'), configServer.get("fillDocs")); // all the supported file extensions - const curExt = fileUtility.getFileExtension(file.name); - const documentType = fileUtility.getFileType(file.name); + file.name = req.DocManager.getCorrectName(file.name); - if (exts.indexOf(curExt) == -1) { // check if the file extension is supported - //docManager.cleanFolderRecursive(uploadDirTmp, true); // if not, clean the folder with temporary files - res.writeHead(200, { "Content-Type": "text/plain" }); // and write the error status and message to the response - res.write("{ \"error\": \"File type is not supported\"}"); - res.end(); - return; - } + // check if the file size exceeds the maximum file size + if (configServer.get('maxFileSize') < file.size || file.size <= 0) { + // DocManager.cleanFolderRecursive(uploadDirTmp, true); // clean the folder with temporary files + res.writeHead(200, { 'Content-Type': 'text/plain' }); + res.write('{ "error": "File size is incorrect"}'); + res.end(); + return; + } - fileSystem.rename(file.path, uploadDir + "/" + file.name, function (err) { // rename a file - //docManager.cleanFolderRecursive(uploadDirTmp, true); // clean the folder with temporary files - res.writeHead(200, { "Content-Type": "text/plain" }); - if (err) { // if an error occurs - res.write("{ \"error\": \"" + err + "\"}"); // write an error message to the response - } else { - res.write("{ \"filename\": \"" + file.name + "\", \"documentType\": \"" + documentType + "\" }"); // otherwise, write a new file name to the response + const exts = fileUtility.getSuppotredExtensions(); // all the supported file extensions + const curExt = fileUtility.getFileExtension(file.name, true); + const documentType = fileUtility.getFileType(file.name); - var user = users.getUser(req.query.userid); // get user id and name parameters or set them to the default values + if (exts.indexOf(curExt) === -1) { // check if the file extension is supported + // DocManager.cleanFolderRecursive(uploadDirTmp, true); // if not, clean the folder with temporary files + res.writeHead(200, { 'Content-Type': 'text/plain' }); // and write the error status and message to the response + res.write('{ "error": "File type is not supported"}'); + res.end(); + return; + } - req.docManager.saveFileData(file.name, user.id, user.name); - } - res.end(); - }); + fileSystem.rename(file.path, `${uploadDir}/${file.name}`, (error) => { // rename a file + // DocManager.cleanFolderRecursive(uploadDirTmp, true); // clean the folder with temporary files + res.writeHead(200, { 'Content-Type': 'text/plain' }); + if (error) { // if an error occurs + res.write(`{ "error": "${error}"}`); // write an error message to the response + } else { + // otherwise, write a new file name to the response + res.write(`{ "filename": "${file.name}", "documentType": "${documentType}" }`); + + // get user id and name parameters or set them to the default values + const user = users.getUser(req.query.userid); + + req.DocManager.saveFileData(file.name, user.id, user.name); + } + res.end(); }); + }); }); -app.post("/create", function (req, res) { - var title = req.body.title; - var fileUrl = req.body.url; +app.post('/create', (req, res) => { + const { title } = req.body; + const fileUrl = req.body.url; - try { - req.docManager = new docManager(req, res); - req.docManager.storagePath(""); // mkdir if not exist - - var fileName = req.docManager.getCorrectName(title); - var userAddress = req.docManager.curUserHostAddress(); - req.docManager.historyPath(fileName, userAddress, true); - - urllib.request(fileUrl, {method: "GET"},function(err, data) { - if (configServer.get("maxFileSize") < data.length || data.length <= 0) { // check if the file size exceeds the maximum file size - res.writeHead(200, { "Content-Type": "application/json" }); - res.write(JSON.stringify({ "error": "File size is incorrect" })); - res.end(); - return; - } + try { + req.DocManager = new DocManager(req, res); + req.DocManager.storagePath(''); // mkdir if not exist - const exts = [].concat(configServer.get("viewedDocs"), configServer.get("editedDocs"), configServer.get("convertedDocs"), configServer.get("fillDocs")); // all the supported file extensions - const curExt = fileUtility.getFileExtension(fileName); + const fileName = req.DocManager.getCorrectName(title); + const userAddress = req.DocManager.curUserHostAddress(); + req.DocManager.historyPath(fileName, userAddress, true); - if (exts.indexOf(curExt) == -1) { // check if the file extension is supported - res.writeHead(200, { "Content-Type": "application/json" }); // and write the error status and message to the response - res.write(JSON.stringify({ "error": "File type is not supported" })); - res.end(); - return; - } - - fileSystem.writeFileSync(req.docManager.storagePath(fileName), data); - - res.writeHead(200, { "Content-Type": "application/json" }); - res.write(JSON.stringify({ "file" : fileName })); - res.end(); - - }); - - } catch (e) { - res.status(500); - res.write(JSON.stringify({ - error: 1, - message: e.message - })); + urllib.request(fileUrl, { method: 'GET' }, (err, data) => { + // check if the file size exceeds the maximum file size + if (configServer.get('maxFileSize') < data.length || data.length <= 0) { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.write(JSON.stringify({ error: 'File size is incorrect' })); res.end(); - } -}); - -app.post("/convert", function (req, res) { // define a handler for converting files - req.docManager = new docManager(req, res); - - var fileName = fileUtility.getFileName(req.body.filename); - var filePass = req.body.filePass ? req.body.filePass : null; - var lang = req.body.lang ? req.body.lang : null; - var fileUri = req.docManager.getDownloadUrl(fileName, true); - var fileExt = fileUtility.getFileExtension(fileName); - var fileType = fileUtility.getFileType(fileName); - var internalFileExt = 'ooxml'; - var response = res; - - var writeResult = function (filename, step, error) { - var result = {}; + return; + } - // write file name, step and error values to the result object if they are defined - if (filename != null) - result["filename"] = filename; + const exts = fileUtility.getSuppotredExtensions(); // all the supported file extensions + const curExt = fileUtility.getFileExtension(fileName, true); - if (step != null) - result["step"] = step; + if (exts.indexOf(curExt) === -1) { // check if the file extension is supported + // and write the error status and message to the response + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.write(JSON.stringify({ error: 'File type is not supported' })); + res.end(); + return; + } - if (error != null) - result["error"] = error; + fileSystem.writeFileSync(req.DocManager.storagePath(fileName), data); - response.setHeader("Content-Type", "application/json"); - response.write(JSON.stringify(result)); - response.end(); - }; + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.write(JSON.stringify({ file: fileName })); + res.end(); + }); + } catch (e) { + res.status(500); + res.write(JSON.stringify({ + error: 1, + message: e.message, + })); + res.end(); + } +}); - var callback = async function (err, res) { - if (err) { // if an error occurs - if (err.name === "ConnectionTimeoutError" || err.name === "ResponseTimeoutError") { // check what type of error it is - writeResult(fileName, 0, null); // despite the timeout errors, write the file to the result object - } else { - writeResult(null, null, JSON.stringify(err)); // other errors trigger an error message - } - return; - } +app.post('/convert', (req, res) => { // define a handler for converting files + req.DocManager = new DocManager(req, res); + + const fileName = fileUtility.getFileName(req.body.filename); + const filePass = req.body.filePass ? req.body.filePass : null; + const lang = req.body.lang ? req.body.lang : null; + const fileUri = req.DocManager.getDownloadUrl(fileName, true); + const fileExt = fileUtility.getFileExtension(fileName, true); + const internalFileExt = 'ooxml'; + const response = res; + + const writeResult = function writeResult(filename, step, error) { + const result = {}; + + // write file name, step and error values to the result object if they are defined + if (filename !== null) result.filename = filename; + + if (step !== null) result.step = step; + + if (error !== null) result.error = error; + + response.setHeader('Content-Type', 'application/json'); + response.write(JSON.stringify(result)); + response.end(); + }; + + const callback = async function callback(err, resp) { + if (err) { // if an error occurs + // check what type of error it is + if (err.name === 'ConnectionTimeoutError' || err.name === 'ResponseTimeoutError') { + writeResult(fileName, 0, null); // despite the timeout errors, write the file to the result object + } else { + writeResult(null, null, JSON.stringify(err)); // other errors trigger an error message + } + return; + } - try { - var responseData = documentService.getResponseUri(res.toString()); - var result = responseData.percent; - var newFileUri = responseData.uri; // get the callback url - var newFileType = "." + responseData.fileType; // get the file type - - if (result != 100) { // if the status isn't 100 - writeResult(fileName, result, null); // write the origin file to the result object - return; - } + try { + const responseData = documentService.getResponseUri(resp.toString()); + const result = responseData.percent; + const newFileUri = responseData.uri; // get the callback url + const newFileType = `.${responseData.fileType}`; // get the file type - var correctName = req.docManager.getCorrectName(fileUtility.getFileName(fileName, true) + newFileType); // get the file name with a new extension + if (result !== 100) { // if the status isn't 100 + writeResult(fileName, result, null); // write the origin file to the result object + return; + } - const {status, data} = await urllib.request(newFileUri, {method: "GET"}); + // get the file name with a new extension + const correctName = req.DocManager.getCorrectName(fileUtility.getFileName(fileName, true) + newFileType); - if (status != 200) throw new Error("Conversion service returned status: " + status); + const { status, data } = await urllib.request(newFileUri, { method: 'GET' }); - fileSystem.writeFileSync(req.docManager.storagePath(correctName), data); // write a file with a new extension, but with the content from the origin file - fileSystem.unlinkSync(req.docManager.storagePath(fileName)); // remove file with the origin extension + if (status !== 200) throw new Error(`Conversion service returned status: ${status}`); - var userAddress = req.docManager.curUserHostAddress(); - var historyPath = req.docManager.historyPath(fileName, userAddress, true); - var correctHistoryPath = req.docManager.historyPath(correctName, userAddress, true); // get the history path to the file with a new extension + // write a file with a new extension, but with the content from the origin file + fileSystem.writeFileSync(req.DocManager.storagePath(correctName), data); + fileSystem.unlinkSync(req.DocManager.storagePath(fileName)); // remove file with the origin extension - fileSystem.renameSync(historyPath, correctHistoryPath); // change the previous history path + const userAddress = req.DocManager.curUserHostAddress(); + const historyPath = req.DocManager.historyPath(fileName, userAddress, true); + // get the history path to the file with a new extension + const correctHistoryPath = req.DocManager.historyPath(correctName, userAddress, true); - fileSystem.renameSync(path.join(correctHistoryPath, fileName + ".txt"), path.join(correctHistoryPath, correctName + ".txt")); // change the name of the .txt file with document information + fileSystem.renameSync(historyPath, correctHistoryPath); // change the previous history path - writeResult(correctName, result, null); // write a file with a new name to the result object - } catch (e) { - console.log(e); // display error message in the console - writeResult(null, null, e.message); - } - }; + fileSystem.renameSync( + path.join(correctHistoryPath, `${fileName}.txt`), + path.join(correctHistoryPath, `${correctName}.txt`), + ); // change the name of the .txt file with document information - try { - if (configServer.get('convertedDocs').indexOf(fileExt) != -1) { // check if the file with such an extension can be converted - let storagePath = req.docManager.storagePath(fileName); - const stat = fileSystem.statSync(storagePath); - let key = fileUri + stat.mtime.getTime(); - - key = documentService.generateRevisionId(key); // get document key - documentService.getConvertedUri(fileUri, fileExt, internalFileExt, key, true, callback, filePass, lang); // get the url to the converted file - } else { - writeResult(fileName, null, null); // if the file with such an extension can't be converted, write the origin file to the result object - } - } catch (ex) { - console.log(ex); - writeResult(null, null, "Server error"); + writeResult(correctName, result, null); // write a file with a new name to the result object + } catch (e) { + console.log(e); // display error message in the console + writeResult(null, null, e.message); } -}); - -app.get("/files", function(req, res) { // define a handler for getting files information - try { - req.docManager = new docManager(req, res); - const filesInDirectoryInfo = req.docManager.getFilesInfo(); // get the information about the files from the storage path - res.setHeader("Content-Type", "application/json"); - res.write(JSON.stringify(filesInDirectoryInfo)); // transform files information into the json string - } catch (ex) { - console.log(ex); - res.write("Server error"); + }; + + try { + // check if the file with such an extension can be converted + if (fileUtility.getConvertExtensions().indexOf(fileExt) !== -1) { + const storagePath = req.DocManager.storagePath(fileName); + const stat = fileSystem.statSync(storagePath); + let key = fileUri + stat.mtime.getTime(); + + key = documentService.generateRevisionId(key); // get document key + // get the url to the converted file + documentService.getConvertedUri(fileUri, fileExt, internalFileExt, key, true, callback, filePass, lang); + } else { + // if the file with such an extension can't be converted, write the origin file to the result object + writeResult(fileName, null, null); } - res.end(); + } catch (ex) { + console.log(ex); + writeResult(null, null, 'Server error'); + } }); -app.get("/files/file/:fileId", function(req, res) { // define a handler for getting file information by its id - try { - req.docManager = new docManager(req, res); - const fileId = req.params.fileId; - const fileInfoById = req.docManager.getFilesInfo(fileId); // get the information about the file specified by a file id - res.setHeader("Content-Type", "application/json"); - res.write(JSON.stringify(fileInfoById)); - } catch (ex) { - console.log(ex); - res.write("Server error"); - } - res.end(); +app.get('/files', (req, res) => { // define a handler for getting files information + try { + req.DocManager = new DocManager(req, res); + // get the information about the files from the storage path + const filesInDirectoryInfo = req.DocManager.getFilesInfo(); + res.setHeader('Content-Type', 'application/json'); + res.write(JSON.stringify(filesInDirectoryInfo)); // transform files information into the json string + } catch (ex) { + console.log(ex); + res.write('Server error'); + } + res.end(); }); -app.delete("/file", function (req, res) { // define a handler for removing file - try { - req.docManager = new docManager(req, res); - let fileName = req.query.filename; - if (fileName) { // if the file name is defined - fileName = fileUtility.getFileName(fileName); // get its part without an extension - - req.docManager.fileRemove(fileName); // delete file and his history - } else { - req.docManager.cleanFolderRecursive(req.docManager.storagePath(''), false); // if the file name is undefined, clean the storage folder - } - - res.write("{\"success\":true}"); - } catch (ex) { - console.log(ex); - res.write("Server error"); - } - res.end(); +app.get('/files/file/:fileId', (req, res) => { // define a handler for getting file information by its id + try { + req.DocManager = new DocManager(req, res); + const { fileId } = req.params; + // get the information about the file specified by a file id + const fileInfoById = req.DocManager.getFilesInfo(fileId); + res.setHeader('Content-Type', 'application/json'); + res.write(JSON.stringify(fileInfoById)); + } catch (ex) { + console.log(ex); + res.write('Server error'); + } + res.end(); }); -app.get("/csv", function (req, res) { // define a handler for downloading csv files - var fileName = "csv.csv"; - var csvPath = path.join(__dirname, "public", "assets", "sample", fileName); - - res.setHeader("Content-Length", fileSystem.statSync(csvPath).size); // add headers to the response to specify the page parameters - res.setHeader("Content-Type", mime.getType(csvPath)); +app.delete('/file', (req, res) => { // define a handler for removing file + try { + req.DocManager = new DocManager(req, res); + let fileName = req.query.filename; + if (fileName) { // if the file name is defined + fileName = fileUtility.getFileName(fileName); // get its part without an extension - res.setHeader("Content-Disposition", "attachment; filename*=UTF-8\'\'" + encodeURIComponent(fileName)); + req.DocManager.fileRemove(fileName); // delete file and his history + } else { + // if the file name is undefined, clean the storage folder + req.DocManager.cleanFolderRecursive(req.DocManager.storagePath(''), false); + } - var filestream = fileSystem.createReadStream(csvPath); - filestream.pipe(res); // send file information to the response by streams -}) + res.write('{"success":true}'); + } catch (ex) { + console.log(ex); + res.write('Server error'); + } + res.end(); +}); -app.post("/reference", function (req, res) { //define a handler for renaming file +app.get('/csv', (req, res) => { // define a handler for downloading csv files + const fileName = 'csv.csv'; + const csvPath = path.join(__dirname, 'public', 'assets', 'document-templates', 'sample', fileName); - req.docManager = new docManager(req, res); + // add headers to the response to specify the page parameters + res.setHeader('Content-Length', fileSystem.statSync(csvPath).size); + res.setHeader('Content-Type', mime.getType(csvPath)); - var result = function(data) { - res.writeHead(200, {"Content-Type": "application/json" }); - res.write(JSON.stringify(data)); - res.end(); - }; + res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(fileName)}`); - var referenceData = req.body.referenceData; - if (!!referenceData) { - var instanceId = referenceData.instanceId; + const filestream = fileSystem.createReadStream(csvPath); + filestream.pipe(res); // send file information to the response by streams +}); - if (instanceId === req.docManager.getInstanceId()) { - var fileKey = JSON.parse(referenceData.fileKey); - var userAddress = fileKey.userAddress; +app.post('/reference', (req, res) => { // define a handler for renaming file + req.DocManager = new DocManager(req, res); - if (userAddress === req.docManager.curUserHostAddress() - && req.docManager.existsSync(req.docManager.storagePath(fileKey.fileName, userAddress))) { - var fileName = fileKey.fileName; - } - } + const result = function result(data) { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.write(JSON.stringify(data)); + res.end(); + }; + + const { referenceData } = req.body; + let fileName = ''; + let userAddress = ''; + if (referenceData) { + const { instanceId } = referenceData; + + if (instanceId === req.DocManager.getInstanceId()) { + const fileKey = JSON.parse(referenceData.fileKey); + ({ userAddress } = fileKey); + + if (userAddress === req.DocManager.curUserHostAddress() + && req.DocManager.existsSync(req.DocManager.storagePath(fileKey.fileName, userAddress))) { + ({ fileName } = fileKey); + } } + } - if (!fileName && !!req.body.path) { - var path = fileUtility.getFileName(req.body.path); + if (!fileName && !!req.body.path) { + const filePath = fileUtility.getFileName(req.body.path); - if (req.docManager.existsSync(req.docManager.storagePath(path, userAddress))) { - fileName = path; - } - } - - if (!fileName) { - result({ "error": "File is not found" }); - return; + if (req.DocManager.existsSync(req.DocManager.storagePath(filePath, userAddress))) { + fileName = filePath; } + } - var data = { - fileType: fileUtility.getFileExtension(fileName).slice(1), - url: req.docManager.getDownloadUrl(fileName, true), - directUrl: req.body.directUrl ? req.docManager.getDownloadUrl(fileName) : null, - referenceData: { - fileKey: JSON.stringify({ fileName: fileName, userAddress: req.docManager.curUserHostAddress()}), - instanceId: req.docManager.getServerUrl() - }, - path: fileName, - }; + if (!fileName) { + result({ error: 'File is not found' }); + return; + } - if (cfgSignatureEnable) { - data.token = jwt.sign(data, cfgSignatureSecret, {expiresIn: cfgSignatureSecretExpiresIn}); // sign token with given data using signature secret - } + const data = { + fileType: fileUtility.getFileExtension(fileName).slice(1), + key: req.DocManager.getKey(fileName), + url: req.DocManager.getDownloadUrl(fileName, true), + directUrl: req.body.directUrl ? req.DocManager.getDownloadUrl(fileName) : null, + referenceData: { + fileKey: JSON.stringify({ fileName, userAddress: req.DocManager.curUserHostAddress() }), + instanceId: req.DocManager.getServerUrl(), + }, + link: `${req.DocManager.getServerUrl()}/editor?fileName=${encodeURIComponent(fileName)}`, + path: fileName, + }; + + if (cfgSignatureEnable) { + // sign token with given data using signature secret + data.token = jwt.sign(data, cfgSignatureSecret, { expiresIn: cfgSignatureSecretExpiresIn }); + } - result(data); + result(data); }); -app.post("/track", async function (req, res) { // define a handler for tracking file changes - - req.docManager = new docManager(req, res); - - var userAddress = req.query.useraddress; - var fileName = fileUtility.getFileName(req.query.filename); - var version = 0; +app.put('/restore', (req, res) => { // define a handler for restore file version + const { fileName } = req.body; + const result = {}; + if (fileName) { + req.DocManager = new DocManager(req, res); + const userAddress = req.DocManager.curUserHostAddress(); + const key = req.DocManager.getKey(fileName); + const { version } = req.body; + const filePath = req.DocManager.storagePath(fileName, userAddress); + const historyPath = req.DocManager.historyPath(fileName, userAddress); + const newVersion = req.DocManager.countVersion(historyPath) + 1; + const versionPath = path.join(`${historyPath}`, `${version}`, `prev${fileUtility.getFileExtension(fileName)}`); + const newVersionPath = path.join(`${historyPath}`, `${newVersion}`); + + if (fileSystem.existsSync(versionPath)) { + req.DocManager.createDirectory(newVersionPath); + req.DocManager.copyFile( + filePath, + path.join(`${newVersionPath}`, `prev${fileUtility.getFileExtension(fileName)}`), + ); + fileSystem.writeFileSync(path.join(`${newVersionPath}`, 'key.txt'), key); + req.DocManager.copyFile(versionPath, filePath); + result.success = true; + } else { + result.success = false; + result.error = 'Version path does not exists'; + } + } else { + result.success = false; + result.error = 'Filename is empty'; + } - // track file changes - var processTrack = async function (response, body, fileName, userAddress) { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.write(JSON.stringify(result)); + res.end(); +}); - // callback file saving process - var callbackProcessSave = async function (downloadUri, body, fileName, userAddress, newFileName) { - try { - const {status, data} = await urllib.request(downloadUri, {method: "GET"}); +app.post('/track', async (req, res) => { // define a handler for tracking file changes + req.DocManager = new DocManager(req, res); + + let uAddress = req.query.useraddress; + let fName = fileUtility.getFileName(req.query.filename); + let version = 0; + + // track file changes + const processTrack = async function processTrack(response, bodyTrack, fileNameTrack, userAddressTrack) { + // callback file saving process + const callbackProcessSave = async function callbackProcessSave( + downloadUri, + body, + fileName, + userAddress, + newFileName, + ) { + try { + const { status, data } = await urllib.request(downloadUri, { method: 'GET' }); + + if (status !== 200) throw new Error(`Document editing service returned status: ${status}`); + + const storagePath = req.DocManager.storagePath(newFileName, userAddress); + + let historyPath = req.DocManager.historyPath(newFileName, userAddress); // get the path to the history data + if (historyPath === '') { // if the history path doesn't exist + historyPath = req.DocManager.historyPath(newFileName, userAddress, true); // create it + req.DocManager.createDirectory(historyPath); // and create a directory for the history data + } - if (status != 200) throw new Error("Document editing service returned status: " + status); + const countVersion = req.DocManager.countVersion(historyPath); // get the next file version number + version = countVersion + 1; + // get the path to the specified file version + const versionPath = req.DocManager.versionPath(newFileName, userAddress, version); + req.DocManager.createDirectory(versionPath); // create a directory to the specified file version + + const downloadZip = body.changesurl; + if (downloadZip) { + // get the path to the file with document versions differences + const pathChanges = req.DocManager.diffPath(newFileName, userAddress, version); + const zip = await urllib.request(downloadZip, { method: 'GET' }); + const statusZip = zip.status; + const dataZip = zip.data; + if (status === 200) { + fileSystem.writeFileSync(pathChanges, dataZip); // write the document version differences to the archive + } else { + emitWarning(`Document editing service returned status: ${statusZip}`); + } + } - var storagePath = req.docManager.storagePath(newFileName, userAddress); + const changeshistory = body.changeshistory || JSON.stringify(body.history); + if (changeshistory) { + // get the path to the file with document changes + const pathChangesJson = req.DocManager.changesPath(newFileName, userAddress, version); + fileSystem.writeFileSync(pathChangesJson, changeshistory); // and write this data to the path in json format + } - var historyPath = req.docManager.historyPath(newFileName, userAddress); // get the path to the history data - if (historyPath == "") { // if the history path doesn't exist - historyPath = req.docManager.historyPath(newFileName, userAddress, true); // create it - req.docManager.createDirectory(historyPath); // and create a directory for the history data - } + const pathKey = req.DocManager.keyPath(newFileName, userAddress, version); // get the path to the key.txt file + fileSystem.writeFileSync(pathKey, body.key); // write the key value to the key.txt file - var count_version = req.docManager.countVersion(historyPath); // get the next file version number - version = count_version + 1; - var versionPath = req.docManager.versionPath(newFileName, userAddress, version); // get the path to the specified file version - req.docManager.createDirectory(versionPath); // create a directory to the specified file version + // get the path to the previous file version + const pathPrev = path.join(versionPath, `prev${fileUtility.getFileExtension(fileName)}`); + // and write it to the current path + fileSystem.renameSync(req.DocManager.storagePath(fileName, userAddress), pathPrev); - var downloadZip = body.changesurl; - if (downloadZip) { - var path_changes = req.docManager.diffPath(newFileName, userAddress, version); // get the path to the file with document versions differences - const {status, data} = await urllib.request(downloadZip, {method: "GET"}); - if (status == 200) { - fileSystem.writeFileSync(path_changes, data); // write the document version differences to the archive - } else { - emitWarning("Document editing service returned status: " + status); - } - } + fileSystem.writeFileSync(storagePath, data); - var changeshistory = body.changeshistory || JSON.stringify(body.history); - if (changeshistory) { - var path_changes_json = req.docManager.changesPath(newFileName, userAddress, version); // get the path to the file with document changes - fileSystem.writeFileSync(path_changes_json, changeshistory); // and write this data to the path in json format - } + // get the path to the forcesaved file + const forcesavePath = req.DocManager.forcesavePath(newFileName, userAddress, false); + if (forcesavePath !== '') { // if this path is empty + fileSystem.unlinkSync(forcesavePath); // remove it + } + } catch (ex) { + console.log(ex); + response.write('{"error":1}'); + response.end(); + return; + } - var path_key = req.docManager.keyPath(newFileName, userAddress, version); // get the path to the key.txt file - fileSystem.writeFileSync(path_key, body.key); // write the key value to the key.txt file + response.write('{"error":0}'); + response.end(); + }; - var path_prev = path.join(versionPath, "prev" + fileUtility.getFileExtension(fileName)); // get the path to the previous file version - fileSystem.renameSync(req.docManager.storagePath(fileName, userAddress), path_prev); // and write it to the current path + // file saving process + const processSave = async function processSave(downloadUri, body, fileName, userAddress) { + if (!downloadUri) { + response.write('{"error":1}'); + response.end(); + return; + } - fileSystem.writeFileSync(storagePath, data); + const curExt = fileUtility.getFileExtension(fileName); // get current file extension + const downloadExt = `.${body.filetype}`; // get the extension of the downloaded file - var forcesavePath = req.docManager.forcesavePath(newFileName, userAddress, false); // get the path to the forcesaved file - if (forcesavePath != "") { // if this path is empty - fileSystem.unlinkSync(forcesavePath); // remove it - } + let newFileName = fileName; + // convert downloaded file to the file with the current extension if these extensions aren't equal + if (downloadExt !== curExt) { + const key = documentService.generateRevisionId(downloadUri); + // get the correct file name if it already exists + newFileName = req.DocManager.getCorrectName(fileUtility.getFileName(fileName, true) + downloadExt, userAddress); + try { + documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, async (err, data) => { + if (err) { + await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName); + return; + } + try { + const resp = documentService.getResponseUri(data); + await callbackProcessSave(resp.uri, body, fileName, userAddress, fileName); } catch (ex) { - console.log(ex); - response.write("{\"error\":1}"); - response.end(); - return; + console.log(ex); + await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName); } + }); + return; + } catch (ex) { + console.log(ex); + } + } + await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName); + }; - response.write("{\"error\":0}"); - response.end(); + // callback file force saving process + const callbackProcessForceSave = async function callbackProcessForceSave( + downloadUri, + body, + fileName, + userAddress, + newFileName = false, + ) { + try { + const { status, data } = await urllib.request(downloadUri, { method: 'GET' }); + + if (status !== 200) throw new Error(`Document editing service returned status: ${status}`); + + const downloadExt = `.${body.fileType}`; + const isSubmitForm = body.forcesavetype === 3; // SubmitForm + let correctName = fileName; + let forcesavePath = ''; + + if (isSubmitForm) { + // new file + if (newFileName) { + correctName = req.DocManager.getCorrectName( + `${fileUtility.getFileName(fileName, true)}-form${downloadExt}`, + userAddress, + ); + } else { + const ext = fileUtility.getFileExtension(fileName); + correctName = req.DocManager.getCorrectName( + `${fileUtility.getFileName(fileName, true)}-form${ext}`, + userAddress, + ); + } + forcesavePath = req.DocManager.storagePath(correctName, userAddress); + } else { + if (newFileName) { + correctName = req.DocManager.getCorrectName(fileUtility.getFileName( + fileName, + true, + ) + downloadExt, userAddress); + } + // create forcesave path if it doesn't exist + forcesavePath = req.DocManager.forcesavePath(correctName, userAddress, false); + if (forcesavePath === '') { + forcesavePath = req.DocManager.forcesavePath(correctName, userAddress, true); + } } - // file saving process - var processSave = async function (downloadUri, body, fileName, userAddress) { + fileSystem.writeFileSync(forcesavePath, data); - if (!downloadUri) { - response.write("{\"error\":1}"); - response.end(); - return; - } + if (isSubmitForm) { + const uid = body.actions[0].userid; + req.DocManager.saveFileData(correctName, uid, 'Filling Form', userAddress); + } + } catch (ex) { + response.write('{"error":1}'); + response.end(); + return; + } - var curExt = fileUtility.getFileExtension(fileName); // get current file extension - var downloadExt = "." + body.filetype; // get the extension of the downloaded file - - var newFileName = fileName; - - // convert downloaded file to the file with the current extension if these extensions aren't equal - if (downloadExt != curExt) { - var key = documentService.generateRevisionId(downloadUri); - newFileName = req.docManager.getCorrectName(fileUtility.getFileName(fileName, true) + downloadExt, userAddress); // get the correct file name if it already exists - try { - documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, async function (err, data) { - if (err) { - await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName); - return; - } - try { - var res = documentService.getResponseUri(data); - await callbackProcessSave(res.uri, body, fileName, userAddress, fileName); - return; - } catch (ex) { - console.log(ex); - await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName); - return; - } - }); - return; - } catch (ex) { - console.log(ex); - } - } - await callbackProcessSave(downloadUri, body, fileName, userAddress, newFileName); - }; + response.write('{"error":0}'); + response.end(); + }; + + // file force saving process + const processForceSave = async function processForceSave(downloadUri, body, fileName, userAddress) { + if (!downloadUri) { + response.write('{"error":1}'); + response.end(); + return; + } - // callback file force saving process - var callbackProcessForceSave = async function (downloadUri, body, fileName, userAddress, newFileName = false){ + const curExt = fileUtility.getFileExtension(fileName); + const downloadExt = `.${body.filetype}`; + + // convert downloaded file to the file with the current extension if these extensions aren't equal + if (downloadExt !== curExt) { + const key = documentService.generateRevisionId(downloadUri); + try { + documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, async (err, data) => { + if (err) { + await callbackProcessForceSave(downloadUri, body, fileName, userAddress, true); + return; + } try { - const {status, data} = await urllib.request(downloadUri, {method: "GET"}); - - if (status != 200) throw new Error("Document editing service returned status: " + status); - - var downloadExt = "." + body.fileType; - - var isSubmitForm = body.forcesavetype === 3; // SubmitForm - - if (isSubmitForm) { - // new file - if (newFileName){ - fileName = req.docManager.getCorrectName(fileUtility.getFileName(fileName, true) + "-form" + downloadExt, userAddress); - } else { - var ext = fileUtility.getFileExtension(fileName); - fileName = req.docManager.getCorrectName(fileUtility.getFileName(fileName, true) + "-form" + ext, userAddress); - } - var forcesavePath = req.docManager.storagePath(fileName, userAddress); - } else { - if (newFileName){ - fileName = req.docManager.getCorrectName(fileUtility.getFileName(fileName, true) + downloadExt, userAddress); - } - // create forcesave path if it doesn't exist - forcesavePath = req.docManager.forcesavePath(fileName, userAddress, false); - if (forcesavePath == "") { - forcesavePath = req.docManager.forcesavePath(fileName, userAddress, true); - } - } - - fileSystem.writeFileSync(forcesavePath, data); - - if (isSubmitForm) { - var uid =body.actions[0].userid - req.docManager.saveFileData(fileName, uid, "Filling Form", userAddress); - } + const resp = documentService.getResponseUri(data); + await callbackProcessForceSave(resp.uri, body, fileName, userAddress, false); } catch (ex) { - response.write("{\"error\":1}"); - response.end(); - return; + console.log(ex); + await callbackProcessForceSave(downloadUri, body, fileName, userAddress, true); } - - response.write("{\"error\":0}"); - response.end(); + }); + return; + } catch (ex) { + console.log(ex); } + } + await callbackProcessForceSave(downloadUri, body, fileName, userAddress, false); + }; - // file force saving process - var processForceSave = async function (downloadUri, body, fileName, userAddress) { - - if (!downloadUri) { - response.write("{\"error\":1}"); - response.end(); - return; - } - - var curExt = fileUtility.getFileExtension(fileName); - var downloadExt = "." + body.filetype; - - // convert downloaded file to the file with the current extension if these extensions aren't equal - if (downloadExt != curExt) { - var key = documentService.generateRevisionId(downloadUri); - try { - documentService.getConvertedUriSync(downloadUri, downloadExt, curExt, key, async function (err, data) { - if (err) { - await callbackProcessForceSave(downloadUri, body, fileName, userAddress, true); - return; - } - try { - var res = documentService.getResponseUri(data); - await callbackProcessForceSave(res.uri, body, fileName, userAddress, false); - return; - } catch (ex) { - console.log(ex); - await callbackProcessForceSave(downloadUri, body, fileName, userAddress, true); - return; - } - }); - return; - } catch (ex) { - console.log(ex); - } - } - await callbackProcessForceSave (downloadUri, body, fileName, userAddress, false); - }; - - if (body.status == 1) { // editing - if (body.actions && body.actions[0].type == 0) { // finished edit - var user = body.actions[0].userid; - if (body.users.indexOf(user) == -1) { - var key = body.key; - try { - documentService.commandRequest("forcesave", key); // call the forcesave command - } catch (ex) { - console.log(ex); - } - } - } - } else if (body.status == 2 || body.status == 3) { // MustSave, Corrupted - await processSave(body.url, body, fileName, userAddress); // save file - return; - } else if (body.status == 6 || body.status == 7) { // MustForceSave, CorruptedForceSave - await processForceSave(body.url, body, fileName, userAddress); // force save file - return; + if (bodyTrack.status === 1) { // editing + if (bodyTrack.actions && bodyTrack.actions[0].type === 0) { // finished edit + const user = bodyTrack.actions[0].userid; + if (bodyTrack.users.indexOf(user) === -1) { + const { key } = bodyTrack; + try { + documentService.commandRequest('forcesave', key); // call the forcesave command + } catch (ex) { + console.log(ex); + } } + } + } else if (bodyTrack.status === 2 || bodyTrack.status === 3) { // MustSave, Corrupted + await processSave(bodyTrack.url, bodyTrack, fileNameTrack, userAddressTrack); // save file + return; + } else if (bodyTrack.status === 6 || bodyTrack.status === 7) { // MustForceSave, CorruptedForceSave + await processForceSave(bodyTrack.url, bodyTrack, fileNameTrack, userAddressTrack); // force save file + return; + } - response.write("{\"error\":0}"); - response.end(); - }; + response.write('{"error":0}'); + response.end(); + }; - // read request body - var readbody = async function (request, response, fileName, userAddress) { - var content = ""; - request.on('data', async function (data) { // get data from the request - content += data; - }); - request.on('end', async function () { - var body = JSON.parse(content); - await processTrack(response, body, fileName, userAddress); // and track file changes - }); - }; + // read request body + const readbody = async function readbody(request, response, fileName, userAddress) { + let content = ''; + request.on('data', async (data) => { // get data from the request + content += data; + }); + request.on('end', async () => { + const body = JSON.parse(content); + await processTrack(response, body, fileName, userAddress); // and track file changes + }); + }; - // check jwt token - if (cfgSignatureEnable && cfgSignatureUseForRequest) { - var body = null; - if (req.body.hasOwnProperty("token")) { // if request body has its own token - body = documentService.readToken(req.body.token); // read and verify it - } else { - var checkJwtHeaderRes = documentService.checkJwtHeader(req); // otherwise, check jwt token headers - if (checkJwtHeaderRes) { // if they exist - var body; - if (checkJwtHeaderRes.payload) { - body = checkJwtHeaderRes.payload; // get the payload object - } - // get user address and file name from the query - if (checkJwtHeaderRes.query) { - if (checkJwtHeaderRes.query.useraddress) { - userAddress = checkJwtHeaderRes.query.useraddress; - } - if (checkJwtHeaderRes.query.filename) { - fileName = fileUtility.getFileName(checkJwtHeaderRes.query.filename); - } - } - } + // check jwt token + if (cfgSignatureEnable && cfgSignatureUseForRequest) { + let body = null; + if (req.body.hasOwnProperty('token')) { // if request body has its own token + body = documentService.readToken(req.body.token); // read and verify it + } else { + const checkJwtHeaderRes = documentService.checkJwtHeader(req); // otherwise, check jwt token headers + if (checkJwtHeaderRes) { // if they exist + if (checkJwtHeaderRes.payload) { + body = checkJwtHeaderRes.payload; // get the payload object } - if (body == null) { - res.write("{\"error\":1}"); - res.end(); - return; + // get user address and file name from the query + if (checkJwtHeaderRes.query) { + if (checkJwtHeaderRes.query.useraddress) { + uAddress = checkJwtHeaderRes.query.useraddress; + } + if (checkJwtHeaderRes.query.filename) { + fName = fileUtility.getFileName(checkJwtHeaderRes.query.filename); + } } - await processTrack(res, body, fileName, userAddress); - return; + } } - - if (req.body.hasOwnProperty("status")) { // if the request body has status parameter - await processTrack(res, req.body, fileName, userAddress); // track file changes - } else { - await readbody(req, res, fileName, userAddress); // otherwise, read request body first + if (!body) { + res.write('{"error":1}'); + res.end(); + return; } -}); - -app.get("/editor", function (req, res) { // define a handler for editing document - try { - - req.docManager = new docManager(req, res); - - var fileName = fileUtility.getFileName(req.query.fileName); - var fileExt = req.query.fileExt; - var history = []; - var historyData = []; - var lang = req.docManager.getLang(); - var user = users.getUser(req.query.userid); - var userDirectUrl = req.query.directUrl == "true"; - - var userid = user.id; - var name = user.name; + await processTrack(res, body, fName, uAddress); + return; + } - var actionData = "null"; - if (req.query.action){ - try { - actionData = JSON.stringify(JSON.parse(req.query.action)); - } - catch (ex) { - console.log(ex); - } - } + if (req.body.hasOwnProperty('status')) { // if the request body has status parameter + await processTrack(res, req.body, fName, uAddress); // track file changes + } else { + await readbody(req, res, fName, uAddress); // otherwise, read request body first + } +}); - var type = req.query.type || ""; // type: embedded/mobile/desktop - if (type == "") { - type = new RegExp(configServer.get("mobileRegEx"), "i").test(req.get('User-Agent')) ? "mobile" : "desktop"; - } else if (type != "mobile" - && type != "embedded") { - type = "desktop"; - } +app.get('/editor', (req, res) => { // define a handler for editing document + try { + req.DocManager = new DocManager(req, res); - var templatesImageUrl = req.docManager.getTemplateImageUrl(fileUtility.getFileType(fileName)); - var createUrl = req.docManager.getCreateUrl(fileUtility.getFileType(fileName), userid, type, lang); - var templates = [ - { - "image": "", - "title": "Blank", - "url": createUrl - }, - { - "image": templatesImageUrl, - "title": "With sample content", - "url": createUrl + "&sample=true" - } - ]; + const fileName = fileUtility.getFileName(req.query.fileName); + let { fileExt } = req.query; + const lang = req.DocManager.getLang(); + const user = users.getUser(req.query.userid); + const userDirectUrl = req.query.directUrl === 'true'; - var userGroup = user.group; - var reviewGroups = user.reviewGroups; - var commentGroups = user.commentGroups; - var userInfoGroups = user.userInfoGroups; + const userid = user.id; + const { name } = user; - if (fileExt != null) { - var fileName = req.docManager.createDemo(!!req.query.sample, fileExt, userid, name, false); // create demo document of a given extension + let actionData = 'null'; + if (req.query.action) { + try { + actionData = JSON.stringify(JSON.parse(req.query.action)); + } catch (ex) { + console.log(ex); + } + } - // get the redirect path - var redirectPath = req.docManager.getServerUrl() + "/editor?fileName=" + encodeURIComponent(fileName) + req.docManager.getCustomParams(); - res.redirect(redirectPath); - return; - } - fileExt = fileUtility.getFileExtension(fileName); + let type = req.query.type || ''; // type: embedded/mobile/desktop + if (type === '') { + type = new RegExp(configServer.get('mobileRegEx'), 'i').test(req.get('User-Agent')) ? 'mobile' : 'desktop'; + } else if (type !== 'mobile' + && type !== 'embedded') { + type = 'desktop'; + } - var userAddress = req.docManager.curUserHostAddress(); - if (!req.docManager.existsSync(req.docManager.storagePath(fileName, userAddress))) { // if the file with a given name doesn't exist - throw { - "message": "File not found: " + fileName // display error message - }; - } - var key = req.docManager.getKey(fileName); - var url = req.docManager.getDownloadUrl(fileName, true); - var directUrl = req.docManager.getDownloadUrl(fileName); - var mode = req.query.mode || "edit"; // mode: view/edit/review/comment/fillForms/embedded - - var canEdit = configServer.get('editedDocs').indexOf(fileExt) != -1; // check if this file can be edited - if ((!canEdit && mode == "edit" || mode == "fillForms") && configServer.get('fillDocs').indexOf(fileExt) != -1) { - mode = "fillForms"; - canEdit = true; - } - if (!canEdit && mode == "edit") { - mode = "view"; - } - var submitForm = mode == "fillForms" && userid == "uid-1" && !1; - - var countVersion = 1; - - var historyPath = req.docManager.historyPath(fileName, userAddress); - var changes = null; - var keyVersion = key; - - if (historyPath != '') { - - countVersion = req.docManager.countVersion(historyPath) + 1; // get the number of file versions - for (var i = 1; i <= countVersion; i++) { // get keys to all the file versions - if (i < countVersion) { - var keyPath = req.docManager.keyPath(fileName, userAddress, i); - if (!fileSystem.existsSync(keyPath)) continue; - keyVersion = "" + fileSystem.readFileSync(keyPath); - } else { - keyVersion = key; - } - history.push(req.docManager.getHistory(fileName, changes, keyVersion, i)); // write all the file history information - - var historyD = { - fileType: fileExt.slice(1), - version: i, - key: keyVersion, - url: i == countVersion ? url : (`${req.docManager.getServerUrl(true)}/history?fileName=${encodeURIComponent(fileName)}&file=prev${fileExt}&ver=${i}&useraddress=${userAddress}`), - directUrl: !userDirectUrl ? null : i == countVersion ? directUrl : (`${req.docManager.getServerUrl(false)}/history?fileName=${encodeURIComponent(fileName)}&file=prev${fileExt}&ver=${i}`), - }; - - if (i > 1 && req.docManager.existsSync(req.docManager.diffPath(fileName, userAddress, i-1))) { // check if the path to the file with document versions differences exists - 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, - }; - let changesUrl = `${req.docManager.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) { - var changesFile = req.docManager.changesPath(fileName, userAddress, i); // get the path to the file with document changes - changes = req.docManager.getChanges(changesFile); // get changes made in the file - } - } - } else { // if history path is empty - history.push(req.docManager.getHistory(fileName, changes, keyVersion, countVersion)); // write the history information about the last file version - historyData.push({ - fileType: fileExt.slice(1), - version: countVersion, - key: key, - url: url, - directUrl: !userDirectUrl ? null : directUrl, - }); - } + const templatesImageUrl = req.DocManager.getTemplateImageUrl(fileUtility.getFileType(fileName)); + const createUrl = req.DocManager.getCreateUrl(fileUtility.getFileType(fileName), userid, type, lang); + const templates = [ + { + image: '', + title: 'Blank', + url: createUrl, + }, + { + image: templatesImageUrl, + title: 'With sample content', + url: `${createUrl}&sample=true`, + }, + ]; + + const userGroup = user.group; + const { reviewGroups } = user; + const { commentGroups } = user; + const { userInfoGroups } = user; + + if (fileExt) { + // create demo document of a given extension + const fName = req.DocManager.createDemo(!!req.query.sample, fileExt, userid, name, false); + + // get the redirect path + const redirectPath = `${req.DocManager.getServerUrl()}/editor?fileName=` + + `${encodeURIComponent(fName)}${req.DocManager.getCustomParams()}`; + res.redirect(redirectPath); + return; + } + fileExt = fileUtility.getFileExtension(fileName); - if (cfgSignatureEnable) { - for (var i = 0; i < historyData.length; i++) { - historyData[i].token = jwt.sign(historyData[i], cfgSignatureSecret, {expiresIn: cfgSignatureSecretExpiresIn}); // sign token with given data using signature secret - } - } + const userAddress = req.DocManager.curUserHostAddress(); + // if the file with a given name doesn't exist + if (!req.DocManager.existsSync(req.DocManager.storagePath(fileName, userAddress))) { + throw new Error(`File not found: ${fileName}`); // display error message + } + const key = req.DocManager.getKey(fileName); + const url = req.DocManager.getDownloadUrl(fileName, true); + const directUrl = req.DocManager.getDownloadUrl(fileName); + let mode = req.query.mode || 'edit'; // mode: view/edit/review/comment/fillForms/embedded + + let canEdit = fileUtility.getEditExtensions().indexOf(fileExt.slice(1)) !== -1; // check if this file can be edited + if (((!canEdit && mode === 'edit') || mode === 'fillForms') + && fileUtility.getFillExtensions().indexOf(fileExt.slice(1)) !== -1) { + mode = 'fillForms'; + canEdit = true; + } + if (!canEdit && mode === 'edit') { + mode = 'view'; + } + const submitForm = mode === 'fillForms' && userid === 'uid-1'; + + // file config data + const argss = { + apiUrl: siteUrl + configServer.get('apiUrl'), + file: { + name: fileName, + ext: fileUtility.getFileExtension(fileName, true), + uri: url, + directUrl: !userDirectUrl ? null : directUrl, + uriUser: directUrl, + created: new Date().toDateString(), + favorite: user.favorite != null ? user.favorite : 'null', + }, + editor: { + type, + documentType: fileUtility.getFileType(fileName), + key, + token: '', + callbackUrl: req.DocManager.getCallback(fileName), + createUrl: userid !== 'uid-0' ? createUrl : null, + templates: user.templates ? templates : null, + isEdit: canEdit && (mode === 'edit' || mode === 'view' || mode === 'filter' || mode === 'blockcontent'), + review: canEdit && (mode === 'edit' || mode === 'review'), + chat: userid !== 'uid-0', + coEditing: mode === 'view' && userid === 'uid-0' ? { mode: 'strict', change: false } : null, + comment: mode !== 'view' && mode !== 'fillForms' && mode !== 'embedded' && mode !== 'blockcontent', + fillForms: mode !== 'view' && mode !== 'comment' && mode !== 'embedded' && mode !== 'blockcontent', + modifyFilter: mode !== 'filter', + modifyContentControl: mode !== 'blockcontent', + copy: !user.deniedPermissions.includes('copy'), + download: !user.deniedPermissions.includes('download'), + print: !user.deniedPermissions.includes('print'), + mode: mode !== 'view' ? 'edit' : 'view', + canBackToFolder: type !== 'embedded', + backUrl: `${req.DocManager.getServerUrl()}/`, + curUserHostAddress: req.DocManager.curUserHostAddress(), + lang, + userid: userid !== 'uid-0' ? userid : null, + name, + userGroup, + reviewGroups: JSON.stringify(reviewGroups), + commentGroups: JSON.stringify(commentGroups), + userInfoGroups: JSON.stringify(userInfoGroups), + fileChoiceUrl, + submitForm, + plugins: JSON.stringify(plugins), + actionData, + fileKey: userid !== 'uid-0' + ? JSON.stringify({ fileName, userAddress: req.DocManager.curUserHostAddress() }) : null, + instanceId: userid !== 'uid-0' ? req.DocManager.getInstanceId() : null, + protect: !user.deniedPermissions.includes('protect'), + }, + dataInsertImage: { + fileType: 'png', + url: `${req.DocManager.getServerUrl(true)}/images/logo.png`, + directUrl: !userDirectUrl ? null : `${req.DocManager.getServerUrl()}/images/logo.png`, + }, + dataDocument: { + fileType: 'docx', + url: `${req.DocManager.getServerUrl(true)}/assets/document-templates/sample/sample.docx`, + directUrl: !userDirectUrl + ? null + : `${req.DocManager.getServerUrl()}/assets/document-templates/sample/sample.docx`, + }, + dataSpreadsheet: { + fileType: 'csv', + url: `${req.DocManager.getServerUrl(true)}/csv`, + directUrl: !userDirectUrl ? null : `${req.DocManager.getServerUrl()}/csv`, + }, + usersForMentions: user.id !== 'uid-0' ? users.getUsersForMentions(user.id) : null, + usersForProtect: user.id !== 'uid-0' ? users.getUsersForProtect(user.id) : null, + }; - // file config data - var argss = { - apiUrl: siteUrl + configServer.get('apiUrl'), - file: { - name: fileName, - ext: fileUtility.getFileExtension(fileName, true), - uri: url, - directUrl: !userDirectUrl ? null : directUrl, - uriUser: directUrl, - version: countVersion, - created: new Date().toDateString(), - favorite: user.favorite != null ? user.favorite : "null" - }, - editor: { - type: type, - documentType: fileUtility.getFileType(fileName), - key: key, - token: "", - callbackUrl: req.docManager.getCallback(fileName), - createUrl: userid != "uid-0" ? createUrl : null, - templates: user.templates ? templates : null, - isEdit: canEdit && (mode == "edit" || mode == "view" || mode == "filter" || mode == "blockcontent"), - review: canEdit && (mode == "edit" || mode == "review"), - chat: userid != "uid-0", - coEditing: mode == "view" && userid == "uid-0" ? {mode: "strict", change: false} : null, - comment: mode != "view" && mode != "fillForms" && mode != "embedded" && mode != "blockcontent", - fillForms: mode != "view" && mode != "comment" && mode != "embedded" && mode != "blockcontent", - modifyFilter: mode != "filter", - modifyContentControl: mode != "blockcontent", - copy: !user.deniedPermissions.includes("copy"), - download: !user.deniedPermissions.includes("download"), - print: !user.deniedPermissions.includes("print"), - mode: mode != "view" ? "edit" : "view", - canBackToFolder: type != "embedded", - backUrl: req.docManager.getServerUrl() + "/", - curUserHostAddress: req.docManager.curUserHostAddress(), - lang: lang, - userid: userid != "uid-0" ? userid : null, - name: name, - userGroup: userGroup, - reviewGroups: JSON.stringify(reviewGroups), - commentGroups: JSON.stringify(commentGroups), - userInfoGroups: JSON.stringify(userInfoGroups), - fileChoiceUrl: fileChoiceUrl, - submitForm: submitForm, - plugins: JSON.stringify(plugins), - actionData: actionData, - fileKey: userid != "uid-0" ? JSON.stringify({ fileName: fileName, userAddress: req.docManager.curUserHostAddress()}) : null, - instanceId: userid != "uid-0" ? req.docManager.getInstanceId() : null, - protect: !user.deniedPermissions.includes("protect") - }, - history: history, - historyData: historyData, - dataInsertImage: { - fileType: "png", - url: req.docManager.getServerUrl(true) + "/images/logo.png", - directUrl: !userDirectUrl ? null : req.docManager.getServerUrl() + "/images/logo.png", - }, - dataCompareFile: { - fileType: "docx", - url: req.docManager.getServerUrl(true) + "/assets/sample/sample.docx", - directUrl: !userDirectUrl ? null : req.docManager.getServerUrl() + "/assets/sample/sample.docx", - }, - dataMailMergeRecipients: { - fileType: "csv", - url: req.docManager.getServerUrl(true) + "/csv", - directUrl: !userDirectUrl ? null : req.docManager.getServerUrl() + "/csv", - }, - usersForMentions: user.id != "uid-0" ? users.getUsersForMentions(user.id) : null, - usersForProtect: user.id != "uid-0" ? users.getUsersForProtect(user.id) : null, - }; - - if (cfgSignatureEnable) { - app.render('config', argss, function(err, html){ // render a config template with the parameters specified - if (err) { - console.log(err); - } else { - // sign token with given data using signature secret - argss.editor.token = jwt.sign(JSON.parse("{"+html+"}"), cfgSignatureSecret, {expiresIn: cfgSignatureSecretExpiresIn}); - argss.dataInsertImage.token = jwt.sign(argss.dataInsertImage, cfgSignatureSecret, {expiresIn: cfgSignatureSecretExpiresIn}); - argss.dataCompareFile.token = jwt.sign(argss.dataCompareFile, cfgSignatureSecret, {expiresIn: cfgSignatureSecretExpiresIn}); - argss.dataMailMergeRecipients.token = jwt.sign(argss.dataMailMergeRecipients, cfgSignatureSecret, {expiresIn: cfgSignatureSecretExpiresIn}); - } - res.render("editor", argss); // render the editor template with the parameters specified - }); + if (cfgSignatureEnable) { + app.render('config', argss, (err, html) => { // render a config template with the parameters specified + if (err) { + console.log(err); } else { - res.render("editor", argss); + // sign token with given data using signature secret + argss.editor.token = jwt.sign( + JSON.parse(`{${html}}`), + cfgSignatureSecret, + { expiresIn: cfgSignatureSecretExpiresIn }, + ); + argss.dataInsertImage.token = jwt.sign( + argss.dataInsertImage, + cfgSignatureSecret, + { expiresIn: cfgSignatureSecretExpiresIn }, + ); + argss.dataDocument.token = jwt.sign( + argss.dataDocument, + cfgSignatureSecret, + { expiresIn: cfgSignatureSecretExpiresIn }, + ); + argss.dataSpreadsheet.token = jwt.sign( + argss.dataSpreadsheet, + cfgSignatureSecret, + { expiresIn: cfgSignatureSecretExpiresIn }, + ); } + res.render('editor', argss); // render the editor template with the parameters specified + }); + } else { + res.render('editor', argss); } - catch (ex) { - console.log(ex); - res.status(500); - res.render("error", { message: "Server error: " + ex.message }); - } + } catch (ex) { + console.log(ex); + res.status(500); + res.render('error', { message: `Server error: ${ex.message}` }); + } }); -app.post("/rename", function (req, res) { //define a handler for renaming file +app.post('/rename', (req, res) => { // define a handler for renaming file + let { newfilename } = req.body; + const origExt = req.body.ext; + const curExt = fileUtility.getFileExtension(newfilename, true); + if (curExt !== origExt) { + newfilename += `.${origExt}`; + } - var newfilename = req.body.newfilename; - var origExt = req.body.ext; - var curExt = fileUtility.getFileExtension(newfilename, true); - if (curExt !== origExt) { - newfilename += '.' + origExt; - } + const { dockey } = req.body; + const meta = { title: newfilename }; - var dockey = req.body.dockey; - var meta = {title: newfilename}; + const result = function result(err, data, ress) { + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.write(JSON.stringify({ result: ress })); + res.end(); + }; - var result = function(err, data, ress) { - res.writeHead(200, {"Content-Type": "application/json" }); - res.write(JSON.stringify({ "result": ress })); - res.end(); - }; + documentService.commandRequest('meta', dockey, result, meta); +}); - documentService.commandRequest("meta", dockey, meta, result); +app.post('/historyObj', (req, res) => { + req.DocManager = new DocManager(req, res); + const { fileName } = req.body; + const { directUrl } = req.body || null; + const historyObj = req.DocManager.getHistoryObject(fileName, null, directUrl); + + if (cfgSignatureEnable) { + for (let i = 0; i < historyObj.historyData.length; i++) { + // sign token with given data using signature secret + historyObj.historyData[i].token = jwt.sign( + historyObj.historyData[i], + cfgSignatureSecret, + { expiresIn: cfgSignatureSecretExpiresIn }, + ); + } + } + res.writeHead(200, { 'Content-Type': 'application/json' }); + res.write(JSON.stringify(historyObj)); + res.end(); }); wopiApp.registerRoutes(app); // "Not found" error with 404 status -app.use(function (req, res, next) { - const err = new Error("Not Found"); - err.status = 404; - next(err); +app.use((req, res, next) => { + const err = new Error('Not Found'); + err.status = 404; + next(err); }); // render the error template with the parameters specified -app.use(function (err, req, res, next) { - res.status(err.status || 500); - res.render("error", { - message: err.message - }); +// eslint-disable-next-line no-unused-vars +app.use((err, req, res, next) => { + res.status(err.status || 500); + res.render('error', { + message: err.message, + }); }); // save all the functions to the app module to export it later in other files -module.exports = app; \ No newline at end of file +module.exports = app; diff --git a/web/documentserver-example/nodejs/config/default.json b/web/documentserver-example/nodejs/config/default.json index 161bdc93d..fc977ea3f 100644 --- a/web/documentserver-example/nodejs/config/default.json +++ b/web/documentserver-example/nodejs/config/default.json @@ -1,5 +1,5 @@ { - "version": "1.6.0", + "version": "1.7.0", "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, diff --git a/web/documentserver-example/nodejs/helpers/cacheManager.js b/web/documentserver-example/nodejs/helpers/cacheManager.js index 660afe228..5e1510261 100644 --- a/web/documentserver-example/nodejs/helpers/cacheManager.js +++ b/web/documentserver-example/nodejs/helpers/cacheManager.js @@ -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 = {}; -} \ No newline at end of file +exports.clear = function clear() { + cache = {}; +}; diff --git a/web/documentserver-example/nodejs/helpers/docManager.js b/web/documentserver-example/nodejs/helpers/docManager.js index 8dbfa9e49..e70eb955c 100644 --- a/web/documentserver-example/nodejs/helpers/docManager.js +++ b/web/documentserver-example/nodejs/helpers/docManager.js @@ -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; - - 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++; - } +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; + + // 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) { - - const demoName = (isSample ? "sample" : "new") + "." + fileExt; - const fileName = this.getCorrectName(demoName); // get the correct file name if such a name already exists +// 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 - 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 + // 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.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; - - 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 - - fileSystem.writeFileSync(path.join(file_info, fileName + ".txt"), date_format + "," + userid + "," + username); // write all the file information to a new txt file +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() < 9 ? '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 fileInfo = this.historyPath(fileName, address, true); // get file history information + this.createDirectory(fileInfo); // create a new history directory if it doesn't exist + + // 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; -} + 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); - } +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; + 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 -} +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 - - 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 - } - - 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 - }; - - 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 - } +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 + 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, + 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 + } } - 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 `${serverUrl}/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 `${serverUrl}/images/file_pptx.svg`; + } - return path + "/images/file_docx.svg"; // the default value -} + return `${serverUrl}/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 +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; +}; + +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 + } } - return i; + } 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, + }); + } + + return { history, historyData, countVersion }; }; - // 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.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; } + } - 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 - }; + const userAddress = this.curUserHostAddress(); + + if (content && contentJson) { + userNameFromJson = oldVersion ? contentJson.username : contentJson.user.name; + userIdFromJson = oldVersion ? contentJson.userid : contentJson.user.id; + 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; + 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; diff --git a/web/documentserver-example/nodejs/helpers/documentService.js b/web/documentserver-example/nodejs/helpers/documentService.js index dc472ef48..3f1eddfe6 100755 --- a/web/documentserver-example/nodejs/helpers/documentService.js +++ b/web/documentserver-example/nodejs/helpers/documentService.js @@ -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'); - -var documentService = {}; +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'); + +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 - - var title = fileUtility.getFileName(documentUri) || guidManager.newGuid(); // get the current document name or uuid - - documentRevisionId = documentService.generateRevisionId(documentRevisionId || documentUri); // generate the document key value - - 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, - }; - - var uri = siteUrl + configServer.get('converterUrl'); // get the absolute converter url - var 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 - } +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 + + const title = fileUtility.getFileName(documentUri) || guidManager.newGuid(); // get the current document name or uuid + + // generate the document key value + const revisionId = documentService.generateRevisionId(documentRevisionId || documentUri); + + 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, + }; + + 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 + // 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: "; - - // 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; - } +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; + } - throw { message: errorMessage }; + throw new Error(errorMessage); }; // get the response url -documentService.getResponseUri = function (json) { - var fileResult = JSON.parse(json); - - if (fileResult.error) // if an error occurs - documentService.processConvertServiceResponceError(parseInt(fileResult.error)); // get an error message +documentService.getResponseUri = function getResponseUri(json) { + const fileResult = JSON.parse(json); - var isEndConvert = fileResult.endConvert // check if the conversion is completed + if (fileResult.error) { // if an error occurs + documentService.processConvertServiceResponceError(parseInt(fileResult.error, 10)); // get an error message + } - var percent = parseInt(fileResult.percent); // get the conversion percentage - var uri = null; - var fileType = null; + const isEndConvert = fileResult.endConvert; // check if the conversion is completed - 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 + let percent = parseInt(fileResult.percent, 10); // get the conversion percentage + let uri = null; + let fileType = 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) { - - 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; - } +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, + }; + + if (meta) { + params.meta = meta; + } - 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); - } + 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); + } - //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 diff --git a/web/documentserver-example/nodejs/helpers/fileUtility.js b/web/documentserver-example/nodejs/helpers/fileUtility.js index 62a1575f7..5203545ba 100644 --- a/web/documentserver-example/nodejs/helpers/fileUtility.js +++ b/web/documentserver-example/nodejs/helpers/fileUtility.js @@ -1,4 +1,4 @@ -/** +/** * * (c) Copyright Ascensio System SIA 2023 * @@ -16,79 +16,101 @@ * */ -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 ""; - - 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]; - - // get file name without extension - if (withoutExtension) { - return fileName.substring(0, fileName.lastIndexOf(".")); - } +fileUtility.getFileName = function getFileName(url, withoutExtension) { + if (!url) return ''; + + 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('.')); + } - 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.actions.includes('auto-convert'), + ).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; - } - catch (ex) { - return null; +// 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; } -} + return map; + } catch (ex) { + return null; + } +}; // save all the functions to the fileUtility module to export it later in other files module.exports = fileUtility; diff --git a/web/documentserver-example/nodejs/helpers/guidManager.js b/web/documentserver-example/nodejs/helpers/guidManager.js index 391facb96..36d187081 100644 --- a/web/documentserver-example/nodejs/helpers/guidManager.js +++ b/web/documentserver-example/nodejs/helpers/guidManager.js @@ -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()); -}; \ No newline at end of file +exports.newGuid = function newGuid() { + return (`${s4() + s4()}-${s4()}-${s4()}-${s4()}-${s4()}${s4()}${s4()}`); +}; diff --git a/web/documentserver-example/nodejs/helpers/users.js b/web/documentserver-example/nodejs/helpers/users.js index 7e8b0aca0..a8be5af42 100644 --- a/web/documentserver-example/nodejs/helpers/users.js +++ b/web/documentserver-example/nodejs/helpers/users.js @@ -16,80 +16,20 @@ * */ -var descr_user_1 = [ - "File author by default", - "Doesn’t 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 don’t belong to any group", - //"Can’t 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 isn’t marked as favorite", - "Can’t copy data from the file to clipboard", - "Can’t download the file", - "Can’t print the file", - "Can create new files from the editor", - "Can see the information about Group2 users", - //"Can’t submit forms" -]; - -var descr_user_0 = [ - "The name is requested when the editor is opened", - "Doesn’t 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", - "Can’t see anyone’s information", - "Can't rename files from the editor", - "Can't view chat", - "Can't protect file", - "View file without collaboration", - //"Can’t 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', + 'Doesn’t 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 don’t belong to any group', + 'Can’t 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 isn’t marked as favorite', + 'Can’t copy data from the file to clipboard', + 'Can’t download the file', + 'Can’t print the file', + 'Can create new files from the editor', + 'Can see the information about Group2 users', + 'Can’t submit forms', +]; + +const descrUser0 = [ + 'The name is requested when the editor is opened', + 'Doesn’t 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', + 'Can’t see anyone’s information', + 'Can\'t rename files from the editor', + 'Can\'t view chat', + 'Can\'t protect file', + 'View file without collaboration', + 'Can’t 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; diff --git a/web/documentserver-example/nodejs/helpers/wopi/filesController.js b/web/documentserver-example/nodejs/helpers/wopi/filesController.js index 9a204a8d6..077d174a3 100644 --- a/web/documentserver-example/nodejs/helpers/wopi/filesController.js +++ b/web/documentserver-example/nodejs/helpers/wopi/filesController.js @@ -16,372 +16,382 @@ * */ +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'); -const actionMapping = {}; -actionMapping[reqConsts.requestType.GetFile] = getFile; -actionMapping[reqConsts.requestType.PutFile] = putFile; -actionMapping[reqConsts.requestType.PutRelativeFile] = putRelativeFile; -actionMapping[reqConsts.requestType.CheckFileInfo] = checkFileInfo; -actionMapping[reqConsts.requestType.UnlockAndRelock] = unlockAndRelock; -actionMapping[reqConsts.requestType.Lock] = lock; -actionMapping[reqConsts.requestType.GetLock] = getLock; -actionMapping[reqConsts.requestType.RefreshLock] = refreshLock; -actionMapping[reqConsts.requestType.Unlock] = unlock; +// 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 +}; -// parse wopi request -function parseWopiRequest(req) { - let wopiData = { - requestType: reqConsts.requestType.None, - accessToken: req.query["access_token"], - id: req.params['id'] - } +// lock file editing +const lock = function lock(wopi, req, res, userHost) { + const requestLock = req.headers[reqConsts.requestHeaders.Lock.toLowerCase()]; - // 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")) { + 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 } - 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) + 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 -function getLock(wopi, req, res, userHost) { - let userAddress = req.docManager.curUserHostAddress(userHost); - let filePath = req.docManager.storagePath(wopi.id, userAddress); +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); -} + // 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"); - } -} +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 -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"); - } -} +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 -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"); - } -} +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 -function getFile(wopi, req, res, userHost) { - let userAddress = req.docManager.curUserHostAddress(userHost); +const getFile = function getFile(wopi, req, res, userHost) { + const userAddress = req.DocManager.curUserHostAddress(userHost); - let path = req.docManager.storagePath(wopi.id, userAddress); + const storagePath = req.DocManager.storagePath(wopi.id, userAddress); - res.setHeader("Content-Length", fileSystem.statSync(path).size); - res.setHeader("Content-Type", mime.getType(path)); + 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)); + 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 -} + 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 -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 +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 - filename = req.docManager.getCorrectName(filename, userAddress); // get correct filename if already exists + if (filename.startsWith('.')) { // check if extension + filename = fileUtility.getFileName(wopi.id, true) + filename; // get original filename with new extension } - let isConverted = req.headers[reqConsts.requestHeaders.FileConversion.toLowerCase()]; - console.log("putRelativeFile after conversation: " + isConverted); + filename = req.DocManager.getCorrectName(filename, userAddress); // get correct filename if already exists + } - // if we got here, then we can save a file - saveFileFromBody(req, filename, userAddress, false, (err) => { - if (err) { - res.sendStatus(404); - return; - } + const isConverted = req.headers[reqConsts.requestHeaders.FileConversion.toLowerCase()]; + console.log(`putRelativeFile after conversation: ${isConverted}`); - 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); - }); -} + // if we got here, then we can save a file + saveFileFromBody(req, filename, userAddress, false, (err) => { + if (err) { + res.sendStatus(404); + return; + } -// 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, + 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); -} - -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 - } +// 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); +}; - let filestream = fileSystem.createWriteStream(storagePath); - req.pipe(filestream); - req.on('end', () => { - filestream.close(); - callback(null, version); - }) - } else { - callback("empty body"); +// 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 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 wopiData; +}; -// 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 -} +const actionMapping = {}; +actionMapping[reqConsts.requestType.GetFile] = getFile; +actionMapping[reqConsts.requestType.PutFile] = putFile; +actionMapping[reqConsts.requestType.PutRelativeFile] = putRelativeFile; +actionMapping[reqConsts.requestType.CheckFileInfo] = checkFileInfo; +actionMapping[reqConsts.requestType.UnlockAndRelock] = unlockAndRelock; +actionMapping[reqConsts.requestType.Lock] = lock; +actionMapping[reqConsts.requestType.GetLock] = getLock; +actionMapping[reqConsts.requestType.RefreshLock] = refreshLock; +actionMapping[reqConsts.requestType.Unlock] = unlock; 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 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 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; - } + 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 + } + + 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 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); -} \ No newline at end of file + action(wopiData, req, res, userAddress); +}; diff --git a/web/documentserver-example/nodejs/helpers/wopi/lockManager.js b/web/documentserver-example/nodejs/helpers/wopi/lockManager.js index e816a4fc5..9e6a68c22 100644 --- a/web/documentserver-example/nodejs/helpers/wopi/lockManager.js +++ b/web/documentserver-example/nodejs/helpers/wopi/lockManager.js @@ -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); -} +const hasLock = 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 +// allow for file editing +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 +}; - // create a new lock object - lockDict[filePath] = { - value: lockValue, - timeout: setTimeout(unlock, 1000 * 60 * 30, filePath) // set lock for 30 minutes - } -} +// 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 -// 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 -} + // 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 -} \ No newline at end of file + hasLock, + getLock: getLockValue, + lock, + unlock, +}; diff --git a/web/documentserver-example/nodejs/helpers/wopi/request.js b/web/documentserver-example/nodejs/helpers/wopi/request.js index 01fc62df9..ac92f8b52 100644 --- a/web/documentserver-example/nodejs/helpers/wopi/request.js +++ b/web/documentserver-example/nodejs/helpers/wopi/request.js @@ -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, -} \ No newline at end of file + requestType, + requestHeaders, +}; diff --git a/web/documentserver-example/nodejs/helpers/wopi/tokenValidator.js b/web/documentserver-example/nodejs/helpers/wopi/tokenValidator.js index 7421765d6..c8bc8ebca 100644 --- a/web/documentserver-example/nodejs/helpers/wopi/tokenValidator.js +++ b/web/documentserver-example/nodejs/helpers/wopi/tokenValidator.js @@ -16,8 +16,4 @@ * */ -exports.isValidToken = (req, res, next) => { - if (true) { - return next(); - } -} \ No newline at end of file +exports.isValidToken = (req, res, next) => next(); diff --git a/web/documentserver-example/nodejs/helpers/wopi/utils.js b/web/documentserver-example/nodejs/helpers/wopi/utils.js index 3afb181c6..fa0e1dcda 100644 --- a/web/documentserver-example/nodejs/helpers/wopi/utils.js +++ b/web/documentserver-example/nodejs/helpers/wopi/utils.js @@ -16,129 +16,141 @@ * */ -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 - -var cache = null; - -async function initWopi(docManager) { - let absSiteUrl = siteUrl; - if (absSiteUrl.indexOf("/") === 0) { - absSiteUrl = docManager.getServerHost() + siteUrl; - } - - // get the wopi discovery information - await getDiscoveryInfo(absSiteUrl); -} +const config = require('config'); +const urlModule = require('url'); +const urllib = require('urllib'); +const xmlParser = require('fast-xml-parser'); +const he = require('he'); + +const configServer = config.get('server'); +const siteUrl = configServer.get('siteUrl'); // the path to the editors installation + +let cache = null; + +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 xmlParseOptions = { + attributeNamePrefix: '', + ignoreAttributes: false, + parseAttributeValue: true, + attrValueProcessor: (val) => he.decode(val, { isAttributeValue: true }), + }; + const parser = new xmlParser.XMLParser(xmlParseOptions); + // create the discovery XML file with the parameters from the response + const discovery = parser.parse(data.toString()); + 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; + if (cache) return cache; - try { - actions = await requestDiscovery(siteUrl); - } catch (e) { - return actions; - } + try { + actions = await requestDiscovery(url); + } catch (e) { + return actions; + } - cache = actions; - setTimeout(() => cache = null, 1000 * 60 * 60); // 1 hour + cache = actions; + setTimeout(() => { + cache = null; + return cache; + }, 1000 * 60 * 60); // 1 hour - 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); - }); - }) -} + 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; \ No newline at end of file +exports.getDefaultAction = getDefaultAction; diff --git a/web/documentserver-example/nodejs/helpers/wopi/wopiRouting.js b/web/documentserver-example/nodejs/helpers/wopi/wopiRouting.js index 894575f95..650a737be 100755 --- a/web/documentserver-example/nodejs/helpers/wopi/wopiRouting.js +++ b/web/documentserver-example/nodejs/helpers/wopi/wopiRouting.js @@ -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) { - - // define a handler for the default wopi page - app.get("/wopi", async function(req, res) { - - req.docManager = new docManager(req, res); - - 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; - } - }); +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 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); + await utils.initWopi(req.DocManager); + + // get the wopi discovery information + const actions = await utils.getDiscoveryInfo(); + const wopiEnable = actions.length !== 0; + const docsExtEdit = []; // Supported extensions for WOPI + + actions.forEach((el) => { + if (el.name === 'edit') docsExtEdit.push(`.${el.ext}`); + }); + // Checking supported extensions + const editedExts = fileUtility.getEditExtensions().filter((i) => docsExtEdit.includes(i)); + const fillExts = fileUtility.getFillExtensions().filter((i) => docsExtEdit.includes(i)); + + try { + // get all the stored files + const files = req.DocManager.getStoredFiles(); + + // 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 + } + + // 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 + + 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); }; diff --git a/web/documentserver-example/nodejs/licenses/3rd-Party.license b/web/documentserver-example/nodejs/licenses/3rd-Party.license index 851579b42..4ce2bb5ad 100644 --- a/web/documentserver-example/nodejs/licenses/3rd-Party.license +++ b/web/documentserver-example/nodejs/licenses/3rd-Party.license @@ -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 diff --git a/web/documentserver-example/nodejs/npm-shrinkwrap.json b/web/documentserver-example/nodejs/npm-shrinkwrap.json index 8ca8832ae..1396f98b7 100644 --- a/web/documentserver-example/nodejs/npm-shrinkwrap.json +++ b/web/documentserver-example/nodejs/npm-shrinkwrap.json @@ -1,12 +1,12 @@ { "name": "OnlineEditorsExampleNodeJS", - "version": "4.1.0", + "version": "1.6.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "OnlineEditorsExampleNodeJS", - "version": "4.1.0", + "version": "1.6.0", "license": "Apache", "dependencies": { "body-parser": "^1.19.0", @@ -14,7 +14,7 @@ "debug": "^4.2.0", "ejs": "^3.1.5", "express": "^4.17.1", - "fast-xml-parser": "^3.19.0", + "fast-xml-parser": "^4.3.1", "formidable": "^1.2.2", "he": "^1.2.0", "jsonwebtoken": "^9.0.0", @@ -1509,15 +1509,24 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" }, "node_modules/fast-xml-parser": { - "version": "3.19.0", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.19.0.tgz", - "integrity": "sha512-4pXwmBplsCPv8FOY1WRakF970TjNGnGnfbOnLqjlYvMiF1SR3yOHyxMR/YCXpPTOspNF5gwudqktIP4VsWkvBg==", - "bin": { - "xml2js": "cli.js" + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.3.1.tgz", + "integrity": "sha512-viVv3xb8D+SiS1W4cv4tva3bni08kAkx0gQnWrykMM8nXPc1FxqZPU00dCEVjkiCg4HoXd2jC4x29Nzg/l2DAA==", + "funding": [ + { + "type": "paypal", + "url": "https://paypal.me/naturalintelligence" + }, + { + "type": "github", + "url": "https://github.com/sponsors/NaturalIntelligence" + } + ], + "dependencies": { + "strnum": "^1.0.5" }, - "funding": { - "type": "paypal", - "url": "https://paypal.me/naturalintelligence" + "bin": { + "fxparser": "src/cli/cli.js" } }, "node_modules/fastq": { @@ -3515,6 +3524,11 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/strnum": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz", + "integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==" + }, "node_modules/supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -4993,9 +5007,12 @@ "integrity": "sha1-PYpcZog6FqMMqGQ+hR8Zuqd5eRc=" }, "fast-xml-parser": { - "version": "3.19.0", - "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.19.0.tgz", - "integrity": "sha512-4pXwmBplsCPv8FOY1WRakF970TjNGnGnfbOnLqjlYvMiF1SR3yOHyxMR/YCXpPTOspNF5gwudqktIP4VsWkvBg==" + "version": "4.3.1", + "resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.3.1.tgz", + "integrity": "sha512-viVv3xb8D+SiS1W4cv4tva3bni08kAkx0gQnWrykMM8nXPc1FxqZPU00dCEVjkiCg4HoXd2jC4x29Nzg/l2DAA==", + "requires": { + "strnum": "^1.0.5" + } }, "fastq": { "version": "1.13.0", @@ -6511,6 +6528,11 @@ "integrity": "sha512-6fPc+R4ihwqP6N/aIv2f1gMH8lOVtWQHoqC4yK6oSDVVocumAsfCqjkXnqiYMhmMwS/mEHLp7Vehlt3ql6lEig==", "dev": true }, + "strnum": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/strnum/-/strnum-1.0.5.tgz", + "integrity": "sha512-J8bbNyKKXl5qYcR36TIO8W3mVGVHrmmxsd5PAItGkmyzwJvybiw2IVq5nqd0i4LSNSkB/sx9VHllbfFdr9k1JA==" + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", diff --git a/web/documentserver-example/nodejs/package.json b/web/documentserver-example/nodejs/package.json index 94c6155c4..bd2643ea4 100644 --- a/web/documentserver-example/nodejs/package.json +++ b/web/documentserver-example/nodejs/package.json @@ -1,6 +1,6 @@ { "name": "OnlineEditorsExampleNodeJS", - "version": "4.1.0", + "version": "1.6.0", "private": false, "scripts": { "start": "node ./bin/www", @@ -22,7 +22,7 @@ "debug": "^4.2.0", "ejs": "^3.1.5", "express": "^4.17.1", - "fast-xml-parser": "^3.19.0", + "fast-xml-parser": "^4.3.1", "formidable": "^1.2.2", "he": "^1.2.0", "jsonwebtoken": "^9.0.0", diff --git a/web/documentserver-example/nodejs/public/assets/document-formats b/web/documentserver-example/nodejs/public/assets/document-formats new file mode 160000 index 000000000..bf21acc76 --- /dev/null +++ b/web/documentserver-example/nodejs/public/assets/document-formats @@ -0,0 +1 @@ +Subproject commit bf21acc7666b9ddb64606247f5afb119952f8475 diff --git a/web/documentserver-example/nodejs/public/assets b/web/documentserver-example/nodejs/public/assets/document-templates similarity index 100% rename from web/documentserver-example/nodejs/public/assets rename to web/documentserver-example/nodejs/public/assets/document-templates diff --git a/web/documentserver-example/nodejs/public/images/file_docx.svg b/web/documentserver-example/nodejs/public/images/file_docx.svg index 751395f69..662d545cc 100644 --- a/web/documentserver-example/nodejs/public/images/file_docx.svg +++ b/web/documentserver-example/nodejs/public/images/file_docx.svg @@ -1,8 +1 @@ - - - - - - - - + \ No newline at end of file diff --git a/web/documentserver-example/nodejs/public/images/file_docxf.svg b/web/documentserver-example/nodejs/public/images/file_docxf.svg index 984761e6f..ab5f02686 100644 --- a/web/documentserver-example/nodejs/public/images/file_docxf.svg +++ b/web/documentserver-example/nodejs/public/images/file_docxf.svg @@ -1,6 +1 @@ - - - - - - + \ No newline at end of file diff --git a/web/documentserver-example/nodejs/public/images/file_pptx.svg b/web/documentserver-example/nodejs/public/images/file_pptx.svg index deba611bb..66dbeaa0c 100644 --- a/web/documentserver-example/nodejs/public/images/file_pptx.svg +++ b/web/documentserver-example/nodejs/public/images/file_pptx.svg @@ -1,8 +1 @@ - - - - - - - - + \ No newline at end of file diff --git a/web/documentserver-example/nodejs/public/images/file_upload.svg b/web/documentserver-example/nodejs/public/images/file_upload.svg index 3617f42ee..3c78ce310 100644 --- a/web/documentserver-example/nodejs/public/images/file_upload.svg +++ b/web/documentserver-example/nodejs/public/images/file_upload.svg @@ -1,6 +1 @@ - - - - - - + \ No newline at end of file diff --git a/web/documentserver-example/nodejs/public/images/file_xlsx.svg b/web/documentserver-example/nodejs/public/images/file_xlsx.svg index 7ee32b7bd..1e738b599 100644 --- a/web/documentserver-example/nodejs/public/images/file_xlsx.svg +++ b/web/documentserver-example/nodejs/public/images/file_xlsx.svg @@ -1,12 +1 @@ - - - - - - - - - - - - + \ No newline at end of file diff --git a/web/documentserver-example/nodejs/public/javascripts/jscript.js b/web/documentserver-example/nodejs/public/javascripts/jscript.js index bc1b65380..10725bca7 100644 --- a/web/documentserver-example/nodejs/public/javascripts/jscript.js +++ b/web/documentserver-example/nodejs/public/javascripts/jscript.js @@ -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; -}; \ No newline at end of file +}; + +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("&"); +} diff --git a/web/documentserver-example/nodejs/views/editor.ejs b/web/documentserver-example/nodejs/views/editor.ejs index d8d4140f0..ba5f607c3 100644 --- a/web/documentserver-example/nodejs/views/editor.ejs +++ b/web/documentserver-example/nodejs/views/editor.ejs @@ -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); @@ -125,18 +172,21 @@ }; var onRequestInsertImage = function(event) { // the user is trying to insert an image by clicking the Image from Storage button - docEditor.insertImage({ // insert an image into the file - "c": event.data.c, - <%- JSON.stringify(dataInsertImage).substring(1, JSON.stringify(dataInsertImage).length - 1)%> - }) + var data = <%- JSON.stringify(dataInsertImage) %>; + data.c = event.data.c; + docEditor.insertImage(data); // insert an image into the file }; - var onRequestCompareFile = function() { // the user is trying to select document for comparing by clicking the Document from Storage button - docEditor.setRevisedFile(<%- JSON.stringify(dataCompareFile) %>); // select a document for comparing + var onRequestSelectDocument = function() { // the user is trying to select document by clicking the Document from Storage button + var data = <%- JSON.stringify(dataDocument) %>; + data.c = event.data.c; + docEditor.setRequestedDocument(data); // select a document }; - var onRequestMailMergeRecipients = function (event) { // the user is trying to select recipients data by clicking the Mail merge button - docEditor.setMailMergeRecipients(<%- JSON.stringify(dataMailMergeRecipients) %>); // insert recipient data for mail merge into the file + var onRequestSelectSpreadsheet = function (event) { // the user is trying to select recipients data by clicking the Mail merge button + var data = <%- JSON.stringify(dataSpreadsheet) %>; + data.c = event.data.c; + docEditor.setRequestedSpreadsheet(data); // insert recipient data for mail merge into the file }; var onRequestUsers = function (event) { @@ -164,20 +214,91 @@ innerAlert("onRequestSendNotify: " + data); }; + var onRequestOpen = function(event) { // user open external data source + innerAlert("onRequestOpen"); + var windowName = event.data.windowName; + + requestReference(event.data, function (data) { + if (data.error) { + var winEditor = window.open("", windowName); + winEditor.close(); + innerAlert(data.error, true); + return; + } + + var link = data.link; + window.open(link, windowName); + }); + }; + var onRequestReferenceData = function(event) { // user refresh external data source innerAlert("onRequestReferenceData"); - innerAlert(event.data); + + requestReference(event.data, function (data) { + docEditor.setReferenceData(data); + }); + }; + + var requestReference = function(data, callback) { + innerAlert(data); event.data.directUrl = !!config.document.directUrl; let xhr = new XMLHttpRequest(); xhr.open("POST", "reference"); xhr.setRequestHeader("Content-Type", "application/json"); - xhr.send(JSON.stringify(event.data)); + xhr.send(JSON.stringify(data)); xhr.onload = function () { innerAlert(xhr.responseText); - docEditor.setReferenceData(JSON.parse(xhr.responseText)); + callback(JSON.parse(xhr.responseText)); + } + }; + + var onRequestReferenceSource = function (event) { + innerAlert("onRequestReferenceSource"); + let xhr = new XMLHttpRequest(); + xhr.open("GET", "files/"); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.send(); + xhr.onload = function () { + if (xhr.status === 200) { + innerAlert(JSON.parse(xhr.responseText)); + let fileList = JSON.parse(xhr.responseText); + let firstXlsxName; + let file; + for (var i = 0; i < fileList.length; i++) { + file = fileList[i]; + if (file["title"]) { + if (getFileExt(file["title"]) === "xlsx") + { + firstXlsxName = file["title"]; + break; + } + } + } + if (firstXlsxName) { + let data = { + directUrl : "<%- file.directUrl %>" || false, + path : firstXlsxName + }; + let xhr = new XMLHttpRequest(); + xhr.open("POST", "reference"); + xhr.setRequestHeader("Content-Type", "application/json"); + xhr.send(JSON.stringify(data)); + xhr.onload = function () { + if (xhr.status === 200) { + docEditor.setReferenceSource(JSON.parse(xhr.responseText)); + } else { + innerAlert("/reference - bad status"); + } + } + } else { + innerAlert("No *.xlsx files"); + } + } else { + innerAlert("/files - bad status"); } + } }; var onRequestSaveAs = function (event) { // the user is trying to save file by clicking Save Copy as... button @@ -226,8 +347,9 @@ "onMakeActionLink": onMakeActionLink, "onMetaChange": onMetaChange, "onRequestInsertImage": onRequestInsertImage, - "onRequestCompareFile": onRequestCompareFile, - "onRequestMailMergeRecipients": onRequestMailMergeRecipients, + "onRequestSelectDocument": onRequestSelectDocument, + "onRequestSelectSpreadsheet": onRequestSelectSpreadsheet, + "onRequestOpen": onRequestOpen, }; if (<%- JSON.stringify(editor.userid) %> != null) { @@ -235,10 +357,12 @@ 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; config.events.onRequestReferenceData = onRequestReferenceData; + config.events.onRequestReferenceSource = onRequestReferenceSource; } if (config.editorConfig.createUrl) { @@ -278,6 +402,13 @@ } }; + const getFileExt = function (fileName) { + if (fileName.indexOf(".")) { + return fileName.split('.').reverse()[0]; + } + return false; + }; + if (window.addEventListener) { window.addEventListener("load", connectEditor); window.addEventListener("resize", fixSize); diff --git a/web/documentserver-example/nodejs/views/index.ejs b/web/documentserver-example/nodejs/views/index.ejs index 5de68c486..6e3326340 100755 --- a/web/documentserver-example/nodejs/views/index.ejs +++ b/web/documentserver-example/nodejs/views/index.ejs @@ -32,7 +32,7 @@
@@ -48,16 +48,16 @@
@@ -154,33 +154,33 @@ <% for (var i = 0; i < storedFiles.length; i++) { %> - + <%= storedFiles[i].name %> <% if (storedFiles[i].canEdit) { %> - + Open in editor for full size screens - + Open in editor for comment <% if (storedFiles[i].documentType == "word") { %> - + Open in editor for review <% } else if (storedFiles[i].documentType == "cell") { %> - + Open in editor without access to change the filter <% } %> <% if (storedFiles[i].documentType == "word") { %> - + Open in editor without content control modification <% } else { %> @@ -189,44 +189,44 @@ <% if (storedFiles[i].documentType !== "word" && storedFiles[i].documentType !== "cell") {%> <% } %> - <% 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) { %> - + Open in editor for filling in forms <% } else {%> <%}%> - + Open in editor for mobile devices - <% } 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) { %> - + Open in editor for filling in forms - + Open in editor for filling in forms for mobile devices <% } else { %> <% } %> - + Open in viewer for full size screens - + Open in viewer for mobile devices - + Open in embedded mode diff --git a/web/documentserver-example/nodejs/views/wopiIndex.ejs b/web/documentserver-example/nodejs/views/wopiIndex.ejs index ef3eaf625..f9da76960 100755 --- a/web/documentserver-example/nodejs/views/wopiIndex.ejs +++ b/web/documentserver-example/nodejs/views/wopiIndex.ejs @@ -35,7 +35,7 @@
@@ -51,16 +51,16 @@ @@ -68,7 +68,7 @@ @@ -78,7 +78,7 @@ Username - <% users.forEach(user => { %> <% }) %> @@ -89,7 +89,7 @@ Language - <% Object.keys(languages).forEach(key => { %> <% }) %> @@ -100,7 +100,7 @@ @@ -148,7 +148,7 @@ <% if (storedFiles[i].defaultAction) { %> - + <%} else { %> <% } %> @@ -158,7 +158,7 @@ <% if (storedFiles[i].actions && storedFiles[i].actions.length > 0) { %> <% for (var j = 0; j < storedFiles[i].actions.length; j++) { %> - + <%= storedFiles[i].actions[j].name %> @@ -167,7 +167,7 @@ <% } %> - + Download diff --git a/web/documentserver-example/php/.gitignore b/web/documentserver-example/php/.gitignore new file mode 100644 index 000000000..a9396d924 --- /dev/null +++ b/web/documentserver-example/php/.gitignore @@ -0,0 +1,2 @@ +logs +vendor diff --git a/web/documentserver-example/php/.php-version b/web/documentserver-example/php/.php-version new file mode 100644 index 000000000..dc16c14d2 --- /dev/null +++ b/web/documentserver-example/php/.php-version @@ -0,0 +1 @@ +8.1.21 diff --git a/web/documentserver-example/php/3rd-Party.license b/web/documentserver-example/php/3rd-Party.license index 547f71b3c..ffcf52eed 100644 --- a/web/documentserver-example/php/3rd-Party.license +++ b/web/documentserver-example/php/3rd-Party.license @@ -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 @@ -31,3 +31,15 @@ License File: jwt.license PHP_CodeSniffer - PHP_CodeSniffer is a set of two PHP scripts; the main phpcs script that tokenizes PHP, JavaScript and CSS files to detect violations of a defined coding standard, and a second phpcbf script to automatically correct coding standard violations. PHP_CodeSniffer is an essential development tool that ensures your code remains clean and consistent. (https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt) License: BSD-3-Clause License File: PHP_CodeSniffer.license + +PHPUnit - The PHP Unit Testing framework. (https://github.com/sebastianbergmann/phpunit/blob/main/LICENSE) +License: BSD 3-Clause +License File: phpunit.license + +property-access - Provides functions to read and write from/to an object or array using a simple string notation. (https://github.com/symfony/property-access/blob/6.3/LICENSE) +License: MIT +License File: property-access.license + +serializer - Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON. (https://github.com/symfony/serializer/blob/6.3/LICENSE) +License: MIT +License File: serializer.license diff --git a/web/documentserver-example/php/Dockerfile b/web/documentserver-example/php/Dockerfile new file mode 100644 index 000000000..6041a2677 --- /dev/null +++ b/web/documentserver-example/php/Dockerfile @@ -0,0 +1,14 @@ +FROM php:8.2.8-fpm-alpine3.18 AS example +WORKDIR /srv +COPY . . +RUN \ + chown -R www-data:www-data /srv && \ + apk update && \ + apk add --no-cache \ + composer \ + make && \ + make prod +CMD ["make", "server-prod"] + +FROM nginx:1.23.4-alpine3.17 AS proxy +COPY proxy/nginx.conf /etc/nginx/nginx.conf diff --git a/web/documentserver-example/php/Makefile b/web/documentserver-example/php/Makefile new file mode 100644 index 000000000..6112172ab --- /dev/null +++ b/web/documentserver-example/php/Makefile @@ -0,0 +1,77 @@ +.DEFAULT_GOAL := help + +ADDRESS := $(ADDRESS) +PORT := $(PORT) + +.PHONY: help +help: # Show help message for each of the Makefile recipes. + @grep -E "^[a-z-]+: #" $(MAKEFILE_LIST) | \ + awk 'BEGIN {FS = ": # "}; {printf "%s: %s\n", $$1, $$2}' + +.PHONY: dev +dev: # Install development dependencies. + @composer install + +.PHONY: prod +prod: # Install production dependencies. + @composer install --no-dev + +ifeq ($(ADDRESS),) +server-dev: \ + export ADDRESS := localhost +else +server-dev: \ + export ADDRESS := $(ADDRESS) +endif + +ifeq ($(PORT),) +server-dev: \ + export PORT := 9000 +else +server-dev: \ + export PORT := $(PORT) +endif + +.PHONY: server-dev +server-dev: # Start the development server on localhost at $PORT (default: 9000). + @php --server $(ADDRESS):$(PORT) + +ifeq ($(ADDRESS),) +server-prod: \ + export ADDRESS := 0.0.0.0 +else +server-prod: \ + export ADDRESS := $(ADDRESS) +endif + +ifeq ($(PORT),) +server-prod: \ + export PORT := 9000 +else +server-prod: \ + export PORT := $(PORT) +endif + +.PHONY: server-prod +server-prod: # Start the production server on 0.0.0.0 at $PORT (default: 9000). + @php-fpm --fpm-config php-fpm.conf + +.PHONY: compose-prod +compose-prod: # Up containers in a production environment. + @docker-compose build + @docker-compose up --detach + +.PHONY: lint +lint: # Lint the source code for the style. + @./vendor/bin/phpcs src index.php + +.PHONY: test +test: # Run tests recursively. + @./vendor/bin/phpunit \ + --test-suffix "Tests.php" \ + --display-incomplete \ + --display-deprecations \ + --display-errors \ + --display-notices \ + --display-warnings \ + src diff --git a/web/documentserver-example/php/README.md b/web/documentserver-example/php/README.md index 50437be10..f2df1ccc2 100644 --- a/web/documentserver-example/php/README.md +++ b/web/documentserver-example/php/README.md @@ -1,202 +1,85 @@ ## Overview -This example will help you integrate ONLYOFFICE Docs into your web application written in PHP. +This example will help you integrate ONLYOFFICE Docs into your web application written on PHP. -**Please note**: It is intended for testing purposes and demonstrating functionality of the editors. Do NOT use this integration example on your own server without proper code modifications! In case you enabled the test example, disable it before going for production. +> [!WARNING] +> It is intended for testing purposes and demonstrating functionality of the editors. **DO NOT** use this integration example on your own server without proper code modifications. In case you enabled the test example, disable it before going for production. -## For Windows +## Installation -### Step 1. Install ONLYOFFICE Docs +The PHP example offers various installation options, but we highly recommend using Docker for this purpose. -Download and install ONLYOFFICE Docs (packaged as Document Server). +### Using Docker -See the detailed guide to learn how to [install Document Server for Windows](https://helpcenter.onlyoffice.com/installation/docs-developer-install-windows.aspx?from=api_php_example). +To run the example using [Docker](https://docker.com), you will need [Docker Desktop 4.17.0](https://docs.docker.com/desktop) or [Docker Engine 20.10.23](https://docs.docker.com/engine) with [Docker Compose 2.15.1](https://docs.docker.com/compose). Additionally, you might want to consider installing [GNU Make 4.4.1](https://gnu.org/software/make), although it is optional. These are the minimum versions required for the tools. -### Step 2. Download the PHP code for the editors integration - -Download the [PHP example](https://api.onlyoffice.com/editors/demopreview) from our site. - -To connect the editors to your website, specify the path to the editors installation and the path to the storage folder in the *config.json* file: +Once you have everything installed, download the release archive and unarchive it. +```sh +$ curl --output PHP.Example.zip --location https://github.com/ONLYOFFICE/document-server-integration/releases/latest/download/PHP.Example.zip +$ unzip PHP.Example.zip ``` -"storagePath" = ""; -"docServSiteUrl" = "https://documentserver/"; -``` - -where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed and the **storagePath** is the path where files will be created and stored. You can set an absolute path. For example, *D:\\\\folder*. Please note that on Windows OS the double backslash must be used as a separator. - -If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) in the *doceditor.php* file. - -### Step 3. Install the prerequisites - -You can use any web server capable of running PHP code to run the example. We will demonstrate how to run the PHP example using the **Internet Information Services (IIS)** web server. To set up and configure PHP on IIS, **PHP Manager for IIS** will be used. - -* **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)). - -### Step 4. IIS configuration - -1. **PHP Manager for IIS** configuration. - - After PHP Manager for IIS installation is complete, launch the **IIS Manager:** - - **Start** -> **Control Panel** -> **System and Security** -> **Administrative Tools** -> **Internet Information Services (IIS) Manager** - - and find the **PHP Manager** feature in the **Features View** in IIS. - - ![manager](screenshots/manager.png) - - You need to register the installed PHP version in IIS using PHP Manager. - Double-click **PHP Manager** to open it, click the **Register new PHP version** task and specify the full path to the main PHP executable file location. For example: *C:\Program Files\PHP\php-cgi.exe*. +Then open the example directory and [up containers](./Makefile#L60). - ![php-version-1](screenshots/php-version-1.jpg) - - After clicking **OK**, the new **PHP version** will be registered with IIS and will become active. - - ![php-version-2](screenshots/php-version-2.jpg) - -2. Configure IIS to handle PHP requests. - - For IIS to host PHP applications, you must add handler mapping that tells IIS to pass all the PHP-specific requests to the PHP application framework by using the **FastCGI** protocol. - - Double-click the **Handler Mappings** feature: - - ![handlerclick](screenshots/handlerclick.png) - - In the **Action** panel, click **Add Module Mapping**. In the **Add Module Mapping** dialog box, specify the configuration settings as follows: - - * **Request path**: *.php, - * **Module**: FastCgiModule, - * **Executable**: "C:\[Path to your PHP installation]\php-cgi.exe", - * **Name**: PHP via FastCGI. - - Click **OK**. - - ![handler-add](screenshots/handler-add.png) - - After IIS manager configuration is complete, everything is ready for running the PHP example. +```sh +$ cd "PHP Example" +$ make compose-prod +``` -### Step 5. Run your website with the editors +By default, the server starts at `localhost:80`. -1. Add your website in the IIS Manager. +To configure the example, you can edit the environment variables in [`docker-compose.yml`](./docker-compose.yml). See [below](#configuration) for more information about environment variables. - On the **Connections** panel right-click the **Sites** node in the tree, then click **Add Website**. +### On Local Machine - ![add](screenshots/add.png) +Before diving into the example, you will need to install ONLYOFFICE Document Server (also known as Docs). Check the detailed guide to learn how to install it on [Windows](https://helpcenter.onlyoffice.com/installation/docs-developer-install-windows.aspx), [Linux](https://helpcenter.onlyoffice.com/installation/docs-developer-install-ubuntu.aspx), or [Docker](https://helpcenter.onlyoffice.com/installation/docs-developer-install-docker.aspx). -2. In the **Add Website** dialog box, specify the name of the folder with the PHP project in the **Site name** box. +To run the example on your local machine, you will need [PHP 8.2.11](https://php.net) with [Composer 2.6.5](https://getcomposer.org). Additionally, you might want to consider installing [GNU Make 4.4.1](https://gnu.org/software/make), although it is optional. These are the minimum versions required for the tools. - Specify the path to the folder with your project in the **Physical path** box. +Once you have everything installed, download the release archive and unarchive it. - Specify the unique value used only for this website in the **Port** box. +```sh +$ curl --output PHP.Example.zip --location https://github.com/ONLYOFFICE/document-server-integration/releases/latest/download/PHP.Example.zip +$ unzip PHP.Example.zip +``` - ![php-add](screenshots/php-add.png) +Then open the example directory, [install dependencies](./Makefile#L16), and [start the server](./Makefile#L40). -3. Browse your website with the IIS manager: +```sh +$ cd "PHP Example" +$ make prod +$ make server-prod +``` - Right-click the site -> **Manage Website** -> **Browse** +By default, the server starts at `0.0.0.0:9000`. - ![browse](screenshots/browse.png) +To configure the example, you can pass the environment variables before the command that starts the server. See [below](#configuration) for more information about environment variables. -### Step 6. Check accessibility +## Post Installation 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. Make sure that the Document Server has access to the server with the example installed with the address which you specify instead of **example.com** in the configuration files. -## For Linux +## Configuration -### Step 1. Install ONLYOFFICE Docs +The example is configured by changing environment variables. -Download and install ONLYOFFICE Docs (packaged as Document Server). - -See the detailed guide to learn how to [install Document Server for Linux](https://helpcenter.onlyoffice.com/installation/docs-developer-install-ubuntu.aspx?from=api_php_example). - -### Step 2. Install the prerequisites and run the website with the editors - -1. Install **Apache** and **PHP**: - - ``` - apt-get install -y apache2 php7.0 libapache2-mod-php7.0 - ``` - -2. Install **Composer**: - - ``` - instructions should be here - ``` - -3. Download the archive with the PHP example and unpack the archive: - - ``` - cd /var/www/html - ``` - - ``` - wget https://api.onlyoffice.com/app_data/editor/PHP%20Example.zip - ``` - - ``` - unzip PHP\ Example.zip - ``` - -4. Change the current directory for the project directory: - - ``` - cd PHP\ Example/ - ``` - -5. Edit the *config.json* configuration file. Specify the name of your local server with the ONLYOFFICE Document Server installed. - - ``` - nano config.json - ``` - - Edit the following lines: - - ``` - "storagePath" = ""; - "docServSiteUrl" = "https://documentserver/"; - ``` - - where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed and the **STORAGE_PATH** is the path where files will be created and stored. You can set an absolute path. - -6. Run *composer install*: - - ``` - php composer.phar install - ``` -7. Set permission for site: - - ``` - chown -R www-data:www-data /var/www/html - ``` - -8. Restart apache: - - ``` - service apache2 restart - ``` - -9. See the result in your browser using the address: - - ``` - http://localhost/PHP%20Example/ - ``` - -### Step 3. 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. - -Make sure that the Document Server has access to the server with the example installed with the address which you specify instead of **example.com** in the configuration files. +| Name | Description | Example | +| ----------------------------- | ----------------------------------------------------------------------- | ----------------------- | +| `ADDRESS` | The address where the server should be started. | `0.0.0.0` | +| `PORT` | The port on which the server should be running. | `80` | +| `DOCUMENT_SERVER_PRIVATE_URL` | The URL through which the server will communicate with Document Server. | `http://proxy:8080` | +| `DOCUMENT_SERVER_PUBLIC_URL` | The URL through which a user will communicate with Document Server. | `http://localhost:8080` | +| `EXAMPLE_URL` | The URL through which Document Server will communicate with the server. | `http://proxy` | +| `JWT_SECRET` | JWT authorization secret. Leave blank to disable authorization. | `your-256-bit-secret` | -## Important security info +## Security Info Please keep in mind the following security aspects when you are using test examples: -* There is no protection of the storage from unauthorized access since there is no need for authorization. -* There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts. -* There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server. -* There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain. \ No newline at end of file +- There is no protection of the storage from unauthorized access since there is no need for authorization. +- There are no checks against parameter substitution in links, since the parameters are generated by the code according to the pre-arranged scripts. +- There are no data checks in requests of saving the file after editing, since each test example is intended for requests only from ONLYOFFICE Document Server. +- There are no prohibitions on using test examples from other sites, since they are intended to interact with ONLYOFFICE Document Server from another domain. diff --git a/web/documentserver-example/php/css/jquery-ui.css b/web/documentserver-example/php/assets/css/jquery-ui.css similarity index 100% rename from web/documentserver-example/php/css/jquery-ui.css rename to web/documentserver-example/php/assets/css/jquery-ui.css diff --git a/web/documentserver-example/php/css/media.css b/web/documentserver-example/php/assets/css/media.css similarity index 100% rename from web/documentserver-example/php/css/media.css rename to web/documentserver-example/php/assets/css/media.css diff --git a/web/documentserver-example/php/css/stylesheet.css b/web/documentserver-example/php/assets/css/stylesheet.css similarity index 93% rename from web/documentserver-example/php/css/stylesheet.css rename to web/documentserver-example/php/assets/css/stylesheet.css index 76f0c1c17..06b167769 100644 --- a/web/documentserver-example/php/css/stylesheet.css +++ b/web/documentserver-example/php/assets/css/stylesheet.css @@ -151,19 +151,19 @@ label .checkbox { } .try-editor.word { - background-image: url("images/file_docx.svg"); + background-image: url("/assets/images/file_docx.svg"); } .try-editor.cell { - background-image: url("images/file_xlsx.svg"); + background-image: url("/assets/images/file_xlsx.svg"); } .try-editor.slide { - background-image: url("images/file_pptx.svg"); + background-image: url("/assets/images/file_pptx.svg"); } .try-editor.form { - background-image: url("images/file_docxf.svg"); + background-image: url("/assets/images/file_docxf.svg"); } .side-option { @@ -235,7 +235,7 @@ label .checkbox { } .file-upload { - background: url("images/file_upload.svg") no-repeat 0 transparent; + background: url("/assets/images/file_upload.svg") no-repeat 0 transparent; cursor: pointer; display: block; font-size: 14px; @@ -308,7 +308,7 @@ label .checkbox { } .error-message { - background: url("images/error.svg") no-repeat scroll 4px 10px; + background: url("/assets/images/error.svg") no-repeat scroll 4px 10px; color: #CB0000; display: none; line-height: 160%; @@ -329,15 +329,15 @@ label .checkbox { } .current { - background-image: url("images/loader16.gif"); + background-image: url("/assets/images/loader16.gif"); } .done { - background-image: url("images/done.svg"); + background-image: url("/assets/images/done.svg"); } .error { - background-image: url("images/notdone.svg"); + background-image: url("/assets/images/notdone.svg"); } .step-descr { @@ -451,17 +451,17 @@ footer table tr td:first-child { .stored-edit.word, .uploadFileName.word { - background-image: url("images/icon_docx.svg"); + background-image: url("/assets/images/icon_docx.svg"); } .stored-edit.cell, .uploadFileName.cell { - background-image: url("images/icon_xlsx.svg"); + background-image: url("/assets/images/icon_xlsx.svg"); } .stored-edit.slide, .uploadFileName.slide { - background-image: url("images/icon_pptx.svg"); + background-image: url("/assets/images/icon_pptx.svg"); } .stored-edit span { @@ -490,7 +490,7 @@ footer table tr td:first-child { } .dialog-close { - background: url("images/close.svg") no-repeat scroll left top; + background: url("/assets/images/close.svg") no-repeat scroll left top; cursor: pointer; float: right; font-size: 1px; @@ -766,4 +766,4 @@ html { position: absolute; top: 50%; transform: translate(-50%, -50%); -} \ No newline at end of file +} diff --git a/web/documentserver-example/php/assets/document-formats b/web/documentserver-example/php/assets/document-formats new file mode 160000 index 000000000..6e38b1767 --- /dev/null +++ b/web/documentserver-example/php/assets/document-formats @@ -0,0 +1 @@ +Subproject commit 6e38b17679e4939684b067a9175e3bc64cf7923c diff --git a/web/documentserver-example/php/assets b/web/documentserver-example/php/assets/document-templates similarity index 100% rename from web/documentserver-example/php/assets rename to web/documentserver-example/php/assets/document-templates diff --git a/web/documentserver-example/php/css/images/block-content.svg b/web/documentserver-example/php/assets/images/block-content.svg similarity index 100% rename from web/documentserver-example/php/css/images/block-content.svg rename to web/documentserver-example/php/assets/images/block-content.svg diff --git a/web/documentserver-example/php/css/images/cell.ico b/web/documentserver-example/php/assets/images/cell.ico similarity index 100% rename from web/documentserver-example/php/css/images/cell.ico rename to web/documentserver-example/php/assets/images/cell.ico diff --git a/web/documentserver-example/php/css/images/close.svg b/web/documentserver-example/php/assets/images/close.svg similarity index 100% rename from web/documentserver-example/php/css/images/close.svg rename to web/documentserver-example/php/assets/images/close.svg diff --git a/web/documentserver-example/php/css/images/comment.svg b/web/documentserver-example/php/assets/images/comment.svg similarity index 100% rename from web/documentserver-example/php/css/images/comment.svg rename to web/documentserver-example/php/assets/images/comment.svg diff --git a/web/documentserver-example/php/css/images/delete.svg b/web/documentserver-example/php/assets/images/delete.svg similarity index 100% rename from web/documentserver-example/php/css/images/delete.svg rename to web/documentserver-example/php/assets/images/delete.svg diff --git a/web/documentserver-example/php/css/images/desktop.svg b/web/documentserver-example/php/assets/images/desktop.svg similarity index 100% rename from web/documentserver-example/php/css/images/desktop.svg rename to web/documentserver-example/php/assets/images/desktop.svg diff --git a/web/documentserver-example/php/css/images/done.svg b/web/documentserver-example/php/assets/images/done.svg similarity index 100% rename from web/documentserver-example/php/css/images/done.svg rename to web/documentserver-example/php/assets/images/done.svg diff --git a/web/documentserver-example/php/css/images/download.svg b/web/documentserver-example/php/assets/images/download.svg similarity index 100% rename from web/documentserver-example/php/css/images/download.svg rename to web/documentserver-example/php/assets/images/download.svg diff --git a/web/documentserver-example/php/css/images/embeded.svg b/web/documentserver-example/php/assets/images/embeded.svg similarity index 100% rename from web/documentserver-example/php/css/images/embeded.svg rename to web/documentserver-example/php/assets/images/embeded.svg diff --git a/web/documentserver-example/php/css/images/error.svg b/web/documentserver-example/php/assets/images/error.svg similarity index 100% rename from web/documentserver-example/php/css/images/error.svg rename to web/documentserver-example/php/assets/images/error.svg diff --git a/web/documentserver-example/php/favicon.ico b/web/documentserver-example/php/assets/images/favicon.ico similarity index 100% rename from web/documentserver-example/php/favicon.ico rename to web/documentserver-example/php/assets/images/favicon.ico diff --git a/web/documentserver-example/php/css/images/file_docx.svg b/web/documentserver-example/php/assets/images/file_docx.svg similarity index 100% rename from web/documentserver-example/php/css/images/file_docx.svg rename to web/documentserver-example/php/assets/images/file_docx.svg diff --git a/web/documentserver-example/php/css/images/file_docxf.svg b/web/documentserver-example/php/assets/images/file_docxf.svg similarity index 100% rename from web/documentserver-example/php/css/images/file_docxf.svg rename to web/documentserver-example/php/assets/images/file_docxf.svg diff --git a/web/documentserver-example/php/css/images/file_pptx.svg b/web/documentserver-example/php/assets/images/file_pptx.svg similarity index 100% rename from web/documentserver-example/php/css/images/file_pptx.svg rename to web/documentserver-example/php/assets/images/file_pptx.svg diff --git a/web/documentserver-example/php/css/images/file_upload.svg b/web/documentserver-example/php/assets/images/file_upload.svg similarity index 100% rename from web/documentserver-example/php/css/images/file_upload.svg rename to web/documentserver-example/php/assets/images/file_upload.svg diff --git a/web/documentserver-example/php/css/images/file_xlsx.svg b/web/documentserver-example/php/assets/images/file_xlsx.svg similarity index 100% rename from web/documentserver-example/php/css/images/file_xlsx.svg rename to web/documentserver-example/php/assets/images/file_xlsx.svg diff --git a/web/documentserver-example/php/css/images/fill-forms.svg b/web/documentserver-example/php/assets/images/fill-forms.svg similarity index 100% rename from web/documentserver-example/php/css/images/fill-forms.svg rename to web/documentserver-example/php/assets/images/fill-forms.svg diff --git a/web/documentserver-example/php/css/images/filter.svg b/web/documentserver-example/php/assets/images/filter.svg similarity index 100% rename from web/documentserver-example/php/css/images/filter.svg rename to web/documentserver-example/php/assets/images/filter.svg diff --git a/web/documentserver-example/php/css/images/icon_docx.svg b/web/documentserver-example/php/assets/images/icon_docx.svg similarity index 100% rename from web/documentserver-example/php/css/images/icon_docx.svg rename to web/documentserver-example/php/assets/images/icon_docx.svg diff --git a/web/documentserver-example/php/css/images/icon_pptx.svg b/web/documentserver-example/php/assets/images/icon_pptx.svg similarity index 100% rename from web/documentserver-example/php/css/images/icon_pptx.svg rename to web/documentserver-example/php/assets/images/icon_pptx.svg diff --git a/web/documentserver-example/php/css/images/icon_xlsx.svg b/web/documentserver-example/php/assets/images/icon_xlsx.svg similarity index 100% rename from web/documentserver-example/php/css/images/icon_xlsx.svg rename to web/documentserver-example/php/assets/images/icon_xlsx.svg diff --git a/web/documentserver-example/php/css/images/info.svg b/web/documentserver-example/php/assets/images/info.svg similarity index 100% rename from web/documentserver-example/php/css/images/info.svg rename to web/documentserver-example/php/assets/images/info.svg diff --git a/web/documentserver-example/php/css/images/loader16.gif b/web/documentserver-example/php/assets/images/loader16.gif similarity index 100% rename from web/documentserver-example/php/css/images/loader16.gif rename to web/documentserver-example/php/assets/images/loader16.gif diff --git a/web/documentserver-example/php/css/images/logo.png b/web/documentserver-example/php/assets/images/logo.png similarity index 100% rename from web/documentserver-example/php/css/images/logo.png rename to web/documentserver-example/php/assets/images/logo.png diff --git a/web/documentserver-example/php/css/images/logo.svg b/web/documentserver-example/php/assets/images/logo.svg similarity index 100% rename from web/documentserver-example/php/css/images/logo.svg rename to web/documentserver-example/php/assets/images/logo.svg diff --git a/web/documentserver-example/php/css/images/mobile-fill-forms.svg b/web/documentserver-example/php/assets/images/mobile-fill-forms.svg similarity index 100% rename from web/documentserver-example/php/css/images/mobile-fill-forms.svg rename to web/documentserver-example/php/assets/images/mobile-fill-forms.svg diff --git a/web/documentserver-example/php/css/images/mobile.svg b/web/documentserver-example/php/assets/images/mobile.svg similarity index 100% rename from web/documentserver-example/php/css/images/mobile.svg rename to web/documentserver-example/php/assets/images/mobile.svg diff --git a/web/documentserver-example/php/css/images/notdone.svg b/web/documentserver-example/php/assets/images/notdone.svg similarity index 100% rename from web/documentserver-example/php/css/images/notdone.svg rename to web/documentserver-example/php/assets/images/notdone.svg diff --git a/web/documentserver-example/php/css/images/review.svg b/web/documentserver-example/php/assets/images/review.svg similarity index 100% rename from web/documentserver-example/php/css/images/review.svg rename to web/documentserver-example/php/assets/images/review.svg diff --git a/web/documentserver-example/php/css/images/slide.ico b/web/documentserver-example/php/assets/images/slide.ico similarity index 100% rename from web/documentserver-example/php/css/images/slide.ico rename to web/documentserver-example/php/assets/images/slide.ico diff --git a/web/documentserver-example/php/css/images/word.ico b/web/documentserver-example/php/assets/images/word.ico similarity index 100% rename from web/documentserver-example/php/css/images/word.ico rename to web/documentserver-example/php/assets/images/word.ico diff --git a/web/documentserver-example/php/js/jquery-3.6.4.min.js b/web/documentserver-example/php/assets/js/jquery-3.6.4.min.js similarity index 100% rename from web/documentserver-example/php/js/jquery-3.6.4.min.js rename to web/documentserver-example/php/assets/js/jquery-3.6.4.min.js diff --git a/web/documentserver-example/php/js/jquery-migrate-3.4.1.min.js b/web/documentserver-example/php/assets/js/jquery-migrate-3.4.1.min.js similarity index 100% rename from web/documentserver-example/php/js/jquery-migrate-3.4.1.min.js rename to web/documentserver-example/php/assets/js/jquery-migrate-3.4.1.min.js diff --git a/web/documentserver-example/php/js/jquery-ui.min.js b/web/documentserver-example/php/assets/js/jquery-ui.min.js similarity index 100% rename from web/documentserver-example/php/js/jquery-ui.min.js rename to web/documentserver-example/php/assets/js/jquery-ui.min.js diff --git a/web/documentserver-example/php/js/jquery.blockUI.js b/web/documentserver-example/php/assets/js/jquery.blockUI.js similarity index 100% rename from web/documentserver-example/php/js/jquery.blockUI.js rename to web/documentserver-example/php/assets/js/jquery.blockUI.js diff --git a/web/documentserver-example/php/js/jquery.dropdownToggle.js b/web/documentserver-example/php/assets/js/jquery.dropdownToggle.js similarity index 100% rename from web/documentserver-example/php/js/jquery.dropdownToggle.js rename to web/documentserver-example/php/assets/js/jquery.dropdownToggle.js diff --git a/web/documentserver-example/php/js/jquery.fileupload.js b/web/documentserver-example/php/assets/js/jquery.fileupload.js similarity index 100% rename from web/documentserver-example/php/js/jquery.fileupload.js rename to web/documentserver-example/php/assets/js/jquery.fileupload.js diff --git a/web/documentserver-example/php/js/jquery.iframe-transport.js b/web/documentserver-example/php/assets/js/jquery.iframe-transport.js similarity index 100% rename from web/documentserver-example/php/js/jquery.iframe-transport.js rename to web/documentserver-example/php/assets/js/jquery.iframe-transport.js diff --git a/web/documentserver-example/php/js/jscript.js b/web/documentserver-example/php/assets/js/jscript.js similarity index 96% rename from web/documentserver-example/php/js/jscript.js rename to web/documentserver-example/php/assets/js/jscript.js index 49e5ad25f..c24117beb 100644 --- a/web/documentserver-example/php/js/jscript.js +++ b/web/documentserver-example/php/assets/js/jscript.js @@ -125,7 +125,7 @@ if (typeof jQuery != "undefined") { jq("#filePass").val(""); timer = setTimeout(function () { - var requestAddress = "webeditor-ajax.php?type=convert&user=" + user; + var requestAddress = "convert?user=" + user; jq.ajax({ async: true, @@ -247,7 +247,7 @@ if (typeof jQuery != "undefined") { jq(document).on("click", "#beginEdit:not(.disable)", function () { var fileId = encodeURIComponent(jq('#hiddenFileName').val()); - var url = "doceditor.php?fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl; + var url = "editor?fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl; window.open(url, "_blank"); jq('#hiddenFileName').val(""); jq.unblockUI(); @@ -256,7 +256,7 @@ if (typeof jQuery != "undefined") { jq(document).on("click", "#beginView:not(.disable)", function () { var fileId = encodeURIComponent(jq('#hiddenFileName').val()); - var url = "doceditor.php?action=view&fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl; + var url = "editor?action=view&fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl; window.open(url, "_blank"); jq('#hiddenFileName').val(""); jq.unblockUI(); @@ -265,7 +265,7 @@ if (typeof jQuery != "undefined") { jq(document).on("click", "#beginEmbedded:not(.disable)", function () { var fileId = encodeURIComponent(jq('#hiddenFileName').val()); - var url = "doceditor.php?type=embedded&fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl; + var url = "editor?type=embedded&fileID=" + fileId + "&user=" + user + "&directUrl=" + directUrl; jq("#mainProgress").addClass("embedded"); jq("#beginEmbedded").addClass("disable"); @@ -297,7 +297,7 @@ if (typeof jQuery != "undefined") { jq(document).on("click", ".delete-file", function () { var fileName = jq(this).attr("data"); - var requestAddress = "webeditor-ajax.php?type=delete&fileName=" + fileName; + var requestAddress = "delete?fileName=" + fileName; jq.ajax({ async: true, diff --git a/web/documentserver-example/php/composer.json b/web/documentserver-example/php/composer.json index 25b28ff5c..b0aebee10 100644 --- a/web/documentserver-example/php/composer.json +++ b/web/documentserver-example/php/composer.json @@ -1,26 +1,22 @@ { - "require-dev": { - "squizlabs/php_codesniffer": "*", - "ext-mbstring": "*" + "require": { + "ext-mbstring": "*", + "firebase/php-jwt": "^6.8.1", + "symfony/serializer": "^6.3", + "symfony/property-access": "^6.3" }, - "scripts": { - "code-sniffer": [ - "./vendor/bin/phpcs --config-set default_standard ruleset.xml", - "./vendor/bin/phpcs --config-set colors 1" - ], - "post-install-cmd": [ - "@code-sniffer" - ], - "post-update-cmd": [ - "@code-sniffer" - ] + "require-dev": { + "squizlabs/php_codesniffer": "^3.7.2", + "phpunit/phpunit": "^10.2.6" }, - "autoload-dev": { + "autoload": { "psr-4": { - "OnlineEditorsExamplePhp\\" : "", - "OnlineEditorsExamplePhp\\Helpers\\" : "helpers/", - "OnlineEditorsExamplePhp\\Views\\" : "views/", - "Firebase\\JWT\\" : "lib/jwt/" + "Example\\Common\\": "src/common/", + "Example\\Configuration\\" : "src/configuration/", + "Example\\Format\\" : "src/format/", + "Example\\Helpers\\" : "src/helpers/", + "Example\\Proxy\\": "src/proxy/", + "Example\\Views\\" : "src/views/" } } } diff --git a/web/documentserver-example/php/composer.lock b/web/documentserver-example/php/composer.lock index 7e021df5d..e4e6f946f 100644 --- a/web/documentserver-example/php/composer.lock +++ b/web/documentserver-example/php/composer.lock @@ -4,21 +4,2379 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0ae1576e556ebadd2933ecd2483a4b26", - "packages": [], + "content-hash": "5d476b9c61f48836ee5e6c9cab7a1980", + "packages": [ + { + "name": "firebase/php-jwt", + "version": "v6.8.1", + "source": { + "type": "git", + "url": "https://github.com/firebase/php-jwt.git", + "reference": "5dbc8959427416b8ee09a100d7a8588c00fb2e26" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/firebase/php-jwt/zipball/5dbc8959427416b8ee09a100d7a8588c00fb2e26", + "reference": "5dbc8959427416b8ee09a100d7a8588c00fb2e26", + "shasum": "" + }, + "require": { + "php": "^7.4||^8.0" + }, + "require-dev": { + "guzzlehttp/guzzle": "^6.5||^7.4", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^9.5", + "psr/cache": "^1.0||^2.0", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0" + }, + "suggest": { + "ext-sodium": "Support EdDSA (Ed25519) signatures", + "paragonie/sodium_compat": "Support EdDSA (Ed25519) signatures when libsodium is not present" + }, + "type": "library", + "autoload": { + "psr-4": { + "Firebase\\JWT\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Neuman Vong", + "email": "neuman+pear@twilio.com", + "role": "Developer" + }, + { + "name": "Anant Narayanan", + "email": "anant@php.net", + "role": "Developer" + } + ], + "description": "A simple library to encode and decode JSON Web Tokens (JWT) in PHP. Should conform to the current spec.", + "homepage": "https://github.com/firebase/php-jwt", + "keywords": [ + "jwt", + "php" + ], + "support": { + "issues": "https://github.com/firebase/php-jwt/issues", + "source": "https://github.com/firebase/php-jwt/tree/v6.8.1" + }, + "time": "2023-07-14T18:33:00+00:00" + }, + { + "name": "symfony/deprecation-contracts", + "version": "v3.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/deprecation-contracts.git", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/7c3aff79d10325257a001fcf92d991f24fc967cf", + "reference": "7c3aff79d10325257a001fcf92d991f24fc967cf", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.4-dev" + }, + "thanks": { + "name": "symfony/contracts", + "url": "https://github.com/symfony/contracts" + } + }, + "autoload": { + "files": [ + "function.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "A generic function and convention to trigger deprecation notices", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/deprecation-contracts/tree/v3.3.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-05-23T14:45:45+00:00" + }, + { + "name": "symfony/polyfill-ctype", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-ctype.git", + "reference": "5bbc823adecdae860bb64756d639ecfec17b050a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-ctype/zipball/5bbc823adecdae860bb64756d639ecfec17b050a", + "reference": "5bbc823adecdae860bb64756d639ecfec17b050a", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-ctype": "*" + }, + "suggest": { + "ext-ctype": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Ctype\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Gert de Pagter", + "email": "BackEndTea@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for ctype functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "ctype", + "polyfill", + "portable" + ], + "support": { + "source": "https://github.com/symfony/polyfill-ctype/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + }, + { + "name": "symfony/polyfill-intl-grapheme", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-grapheme.git", + "reference": "511a08c03c1960e08a883f4cffcacd219b758354" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-grapheme/zipball/511a08c03c1960e08a883f4cffcacd219b758354", + "reference": "511a08c03c1960e08a883f4cffcacd219b758354", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Grapheme\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's grapheme_* functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "grapheme", + "intl", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-grapheme/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + }, + { + "name": "symfony/polyfill-intl-normalizer", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-intl-normalizer.git", + "reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/19bd1e4fcd5b91116f14d8533c57831ed00571b6", + "reference": "19bd1e4fcd5b91116f14d8533c57831ed00571b6", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "suggest": { + "ext-intl": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Intl\\Normalizer\\": "" + }, + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for intl's Normalizer class and related functions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "intl", + "normalizer", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + }, + { + "name": "symfony/polyfill-mbstring", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-mbstring.git", + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "reference": "8ad114f6b39e2c98a8b0e3bd907732c207c2b534", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "provide": { + "ext-mbstring": "*" + }, + "suggest": { + "ext-mbstring": "For best performance" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + }, + "thanks": { + "name": "symfony/polyfill", + "url": "https://github.com/symfony/polyfill" + } + }, + "autoload": { + "files": [ + "bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\Mbstring\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill for the Mbstring extension", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "mbstring", + "polyfill", + "portable", + "shim" + ], + "support": { + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-03T14:55:06+00:00" + }, + { + "name": "symfony/property-access", + "version": "v6.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/property-access.git", + "reference": "db9358571ce63f09c439c2fee6c12e5b090b69ac" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/property-access/zipball/db9358571ce63f09c439c2fee6c12e5b090b69ac", + "reference": "db9358571ce63f09c439c2fee6c12e5b090b69ac", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/deprecation-contracts": "^2.5|^3", + "symfony/property-info": "^5.4|^6.0" + }, + "require-dev": { + "symfony/cache": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\PropertyAccess\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides functions to read and write from/to an object or array using a simple string notation", + "homepage": "https://symfony.com", + "keywords": [ + "access", + "array", + "extraction", + "index", + "injection", + "object", + "property", + "property-path", + "reflection" + ], + "support": { + "source": "https://github.com/symfony/property-access/tree/v6.3.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-05-19T08:06:44+00:00" + }, + { + "name": "symfony/property-info", + "version": "v6.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/property-info.git", + "reference": "7f3a03716112269741fe2a809f8f791a371d1fcd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/property-info/zipball/7f3a03716112269741fe2a809f8f791a371d1fcd", + "reference": "7f3a03716112269741fe2a809f8f791a371d1fcd", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/string": "^5.4|^6.0" + }, + "conflict": { + "phpdocumentor/reflection-docblock": "<5.2", + "phpdocumentor/type-resolver": "<1.5.1", + "symfony/dependency-injection": "<5.4" + }, + "require-dev": { + "doctrine/annotations": "^1.10.4|^2", + "phpdocumentor/reflection-docblock": "^5.2", + "phpstan/phpdoc-parser": "^1.0", + "symfony/cache": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/serializer": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\PropertyInfo\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Kévin Dunglas", + "email": "dunglas@gmail.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Extracts information about PHP class' properties using metadata of popular sources", + "homepage": "https://symfony.com", + "keywords": [ + "doctrine", + "phpdoc", + "property", + "symfony", + "type", + "validator" + ], + "support": { + "source": "https://github.com/symfony/property-info/tree/v6.3.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-05-19T08:06:44+00:00" + }, + { + "name": "symfony/serializer", + "version": "v6.3.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/serializer.git", + "reference": "1d238ee3180bc047f8ab713bfb73848d553f4407" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/serializer/zipball/1d238ee3180bc047f8ab713bfb73848d553f4407", + "reference": "1d238ee3180bc047f8ab713bfb73848d553f4407", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-ctype": "~1.8" + }, + "conflict": { + "doctrine/annotations": "<1.12", + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0", + "symfony/dependency-injection": "<5.4", + "symfony/property-access": "<5.4", + "symfony/property-info": "<5.4", + "symfony/uid": "<5.4", + "symfony/yaml": "<5.4" + }, + "require-dev": { + "doctrine/annotations": "^1.12|^2", + "phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0", + "symfony/cache": "^5.4|^6.0", + "symfony/config": "^5.4|^6.0", + "symfony/console": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/error-handler": "^5.4|^6.0", + "symfony/filesystem": "^5.4|^6.0", + "symfony/form": "^5.4|^6.0", + "symfony/http-foundation": "^5.4|^6.0", + "symfony/http-kernel": "^5.4|^6.0", + "symfony/mime": "^5.4|^6.0", + "symfony/property-access": "^5.4|^6.0", + "symfony/property-info": "^5.4|^6.0", + "symfony/uid": "^5.4|^6.0", + "symfony/validator": "^5.4|^6.0", + "symfony/var-dumper": "^5.4|^6.0", + "symfony/var-exporter": "^5.4|^6.0", + "symfony/yaml": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Serializer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/serializer/tree/v6.3.1" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-06-21T19:54:33+00:00" + }, + { + "name": "symfony/string", + "version": "v6.3.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/string.git", + "reference": "f2e190ee75ff0f5eced645ec0be5c66fac81f51f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/string/zipball/f2e190ee75ff0f5eced645ec0be5c66fac81f51f", + "reference": "f2e190ee75ff0f5eced645ec0be5c66fac81f51f", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "symfony/polyfill-ctype": "~1.8", + "symfony/polyfill-intl-grapheme": "~1.0", + "symfony/polyfill-intl-normalizer": "~1.0", + "symfony/polyfill-mbstring": "~1.0" + }, + "conflict": { + "symfony/translation-contracts": "<2.5" + }, + "require-dev": { + "symfony/error-handler": "^5.4|^6.0", + "symfony/http-client": "^5.4|^6.0", + "symfony/intl": "^6.2", + "symfony/translation-contracts": "^2.5|^3.0", + "symfony/var-exporter": "^5.4|^6.0" + }, + "type": "library", + "autoload": { + "files": [ + "Resources/functions.php" + ], + "psr-4": { + "Symfony\\Component\\String\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an object-oriented API to strings and deals with bytes, UTF-8 code points and grapheme clusters in a unified way", + "homepage": "https://symfony.com", + "keywords": [ + "grapheme", + "i18n", + "string", + "unicode", + "utf-8", + "utf8" + ], + "support": { + "source": "https://github.com/symfony/string/tree/v6.3.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2023-03-21T21:06:29+00:00" + } + ], "packages-dev": [ + { + "name": "myclabs/deep-copy", + "version": "1.11.1", + "source": { + "type": "git", + "url": "https://github.com/myclabs/DeepCopy.git", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "reference": "7284c22080590fb39f2ffa3e9057f10a4ddd0e0c", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "doctrine/collections": "<1.6.8", + "doctrine/common": "<2.13.3 || >=3,<3.2.2" + }, + "require-dev": { + "doctrine/collections": "^1.6.8", + "doctrine/common": "^2.13.3 || ^3.2.2", + "phpunit/phpunit": "^7.5.20 || ^8.5.23 || ^9.5.13" + }, + "type": "library", + "autoload": { + "files": [ + "src/DeepCopy/deep_copy.php" + ], + "psr-4": { + "DeepCopy\\": "src/DeepCopy/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Create deep copies (clones) of your objects", + "keywords": [ + "clone", + "copy", + "duplicate", + "object", + "object graph" + ], + "support": { + "issues": "https://github.com/myclabs/DeepCopy/issues", + "source": "https://github.com/myclabs/DeepCopy/tree/1.11.1" + }, + "funding": [ + { + "url": "https://tidelift.com/funding/github/packagist/myclabs/deep-copy", + "type": "tidelift" + } + ], + "time": "2023-03-08T13:26:56+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v4.16.0", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "19526a33fb561ef417e822e85f08a00db4059c17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/19526a33fb561ef417e822e85f08a00db4059c17", + "reference": "19526a33fb561ef417e822e85f08a00db4059c17", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.16.0" + }, + "time": "2023-06-25T14:52:30+00:00" + }, + { + "name": "phar-io/manifest", + "version": "2.0.3", + "source": { + "type": "git", + "url": "https://github.com/phar-io/manifest.git", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/manifest/zipball/97803eca37d319dfa7826cc2437fc020857acb53", + "reference": "97803eca37d319dfa7826cc2437fc020857acb53", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-phar": "*", + "ext-xmlwriter": "*", + "phar-io/version": "^3.0.1", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.0.x-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Component for reading phar.io manifest information from a PHP Archive (PHAR)", + "support": { + "issues": "https://github.com/phar-io/manifest/issues", + "source": "https://github.com/phar-io/manifest/tree/2.0.3" + }, + "time": "2021-07-20T11:28:43+00:00" + }, + { + "name": "phar-io/version", + "version": "3.2.1", + "source": { + "type": "git", + "url": "https://github.com/phar-io/version.git", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phar-io/version/zipball/4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "reference": "4f7fd7836c6f332bb2933569e566a0d6c4cbed74", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + }, + { + "name": "Sebastian Heuer", + "email": "sebastian@phpeople.de", + "role": "Developer" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "Developer" + } + ], + "description": "Library for handling version information and constraints", + "support": { + "issues": "https://github.com/phar-io/version/issues", + "source": "https://github.com/phar-io/version/tree/3.2.1" + }, + "time": "2022-02-21T01:04:05+00:00" + }, + { + "name": "phpunit/php-code-coverage", + "version": "10.1.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-code-coverage.git", + "reference": "db1497ec8dd382e82c962f7abbe0320e4882ee4e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/db1497ec8dd382e82c962f7abbe0320e4882ee4e", + "reference": "db1497ec8dd382e82c962f7abbe0320e4882ee4e", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-libxml": "*", + "ext-xmlwriter": "*", + "nikic/php-parser": "^4.15", + "php": ">=8.1", + "phpunit/php-file-iterator": "^4.0", + "phpunit/php-text-template": "^3.0", + "sebastian/code-unit-reverse-lookup": "^3.0", + "sebastian/complexity": "^3.0", + "sebastian/environment": "^6.0", + "sebastian/lines-of-code": "^2.0", + "sebastian/version": "^4.0", + "theseer/tokenizer": "^1.2.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.1" + }, + "suggest": { + "ext-pcov": "PHP extension that provides line coverage", + "ext-xdebug": "PHP extension that provides line coverage as well as branch and path coverage" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "10.1-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that provides collection, processing, and rendering functionality for PHP code coverage information.", + "homepage": "https://github.com/sebastianbergmann/php-code-coverage", + "keywords": [ + "coverage", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-code-coverage/issues", + "security": "https://github.com/sebastianbergmann/php-code-coverage/security/policy", + "source": "https://github.com/sebastianbergmann/php-code-coverage/tree/10.1.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-05-22T09:04:27+00:00" + }, + { + "name": "phpunit/php-file-iterator", + "version": "4.0.2", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-file-iterator.git", + "reference": "5647d65443818959172645e7ed999217360654b6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-file-iterator/zipball/5647d65443818959172645e7ed999217360654b6", + "reference": "5647d65443818959172645e7ed999217360654b6", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "FilterIterator implementation that filters files based on a list of suffixes.", + "homepage": "https://github.com/sebastianbergmann/php-file-iterator/", + "keywords": [ + "filesystem", + "iterator" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", + "security": "https://github.com/sebastianbergmann/php-file-iterator/security/policy", + "source": "https://github.com/sebastianbergmann/php-file-iterator/tree/4.0.2" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-05-07T09:13:23+00:00" + }, + { + "name": "phpunit/php-invoker", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-invoker.git", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-invoker/zipball/f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "reference": "f5e568ba02fa5ba0ddd0f618391d5a9ea50b06d7", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "ext-pcntl": "*", + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-pcntl": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Invoke callables with a timeout", + "homepage": "https://github.com/sebastianbergmann/php-invoker/", + "keywords": [ + "process" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-invoker/issues", + "source": "https://github.com/sebastianbergmann/php-invoker/tree/4.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:56:09+00:00" + }, + { + "name": "phpunit/php-text-template", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-text-template.git", + "reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-text-template/zipball/9f3d3709577a527025f55bcf0f7ab8052c8bb37d", + "reference": "9f3d3709577a527025f55bcf0f7ab8052c8bb37d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Simple template engine.", + "homepage": "https://github.com/sebastianbergmann/php-text-template/", + "keywords": [ + "template" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-text-template/issues", + "source": "https://github.com/sebastianbergmann/php-text-template/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:56:46+00:00" + }, + { + "name": "phpunit/php-timer", + "version": "6.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/php-timer.git", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/php-timer/zipball/e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "reference": "e2a2d67966e740530f4a3343fe2e030ffdc1161d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Utility class for timing", + "homepage": "https://github.com/sebastianbergmann/php-timer/", + "keywords": [ + "timer" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/php-timer/issues", + "source": "https://github.com/sebastianbergmann/php-timer/tree/6.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:57:52+00:00" + }, + { + "name": "phpunit/phpunit", + "version": "10.2.6", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/phpunit.git", + "reference": "1c17815c129f133f3019cc18e8d0c8622e6d9bcd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1c17815c129f133f3019cc18e8d0c8622e6d9bcd", + "reference": "1c17815c129f133f3019cc18e8d0c8622e6d9bcd", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-json": "*", + "ext-libxml": "*", + "ext-mbstring": "*", + "ext-xml": "*", + "ext-xmlwriter": "*", + "myclabs/deep-copy": "^1.10.1", + "phar-io/manifest": "^2.0.3", + "phar-io/version": "^3.0.2", + "php": ">=8.1", + "phpunit/php-code-coverage": "^10.1.1", + "phpunit/php-file-iterator": "^4.0", + "phpunit/php-invoker": "^4.0", + "phpunit/php-text-template": "^3.0", + "phpunit/php-timer": "^6.0", + "sebastian/cli-parser": "^2.0", + "sebastian/code-unit": "^2.0", + "sebastian/comparator": "^5.0", + "sebastian/diff": "^5.0", + "sebastian/environment": "^6.0", + "sebastian/exporter": "^5.0", + "sebastian/global-state": "^6.0", + "sebastian/object-enumerator": "^5.0", + "sebastian/recursion-context": "^5.0", + "sebastian/type": "^4.0", + "sebastian/version": "^4.0" + }, + "suggest": { + "ext-soap": "To be able to generate mocks based on WSDL files" + }, + "bin": [ + "phpunit" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "10.2-dev" + } + }, + "autoload": { + "files": [ + "src/Framework/Assert/Functions.php" + ], + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "The PHP Unit Testing framework.", + "homepage": "https://phpunit.de/", + "keywords": [ + "phpunit", + "testing", + "xunit" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/phpunit/issues", + "security": "https://github.com/sebastianbergmann/phpunit/security/policy", + "source": "https://github.com/sebastianbergmann/phpunit/tree/10.2.6" + }, + "funding": [ + { + "url": "https://phpunit.de/sponsors.html", + "type": "custom" + }, + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/phpunit/phpunit", + "type": "tidelift" + } + ], + "time": "2023-07-17T12:08:28+00:00" + }, + { + "name": "sebastian/cli-parser", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/cli-parser.git", + "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/cli-parser/zipball/efdc130dbbbb8ef0b545a994fd811725c5282cae", + "reference": "efdc130dbbbb8ef0b545a994fd811725c5282cae", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for parsing CLI options", + "homepage": "https://github.com/sebastianbergmann/cli-parser", + "support": { + "issues": "https://github.com/sebastianbergmann/cli-parser/issues", + "source": "https://github.com/sebastianbergmann/cli-parser/tree/2.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:58:15+00:00" + }, + { + "name": "sebastian/code-unit", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit.git", + "reference": "a81fee9eef0b7a76af11d121767abc44c104e503" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit/zipball/a81fee9eef0b7a76af11d121767abc44c104e503", + "reference": "a81fee9eef0b7a76af11d121767abc44c104e503", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the PHP code units", + "homepage": "https://github.com/sebastianbergmann/code-unit", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit/issues", + "source": "https://github.com/sebastianbergmann/code-unit/tree/2.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:58:43+00:00" + }, + { + "name": "sebastian/code-unit-reverse-lookup", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/code-unit-reverse-lookup.git", + "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/code-unit-reverse-lookup/zipball/5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", + "reference": "5e3a687f7d8ae33fb362c5c0743794bbb2420a1d", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Looks up which function or method a line of code belongs to", + "homepage": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/", + "support": { + "issues": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/issues", + "source": "https://github.com/sebastianbergmann/code-unit-reverse-lookup/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:59:15+00:00" + }, + { + "name": "sebastian/comparator", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/comparator.git", + "reference": "72f01e6586e0caf6af81297897bd112eb7e9627c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/comparator/zipball/72f01e6586e0caf6af81297897bd112eb7e9627c", + "reference": "72f01e6586e0caf6af81297897bd112eb7e9627c", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-mbstring": "*", + "php": ">=8.1", + "sebastian/diff": "^5.0", + "sebastian/exporter": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@2bepublished.at" + } + ], + "description": "Provides the functionality to compare PHP values for equality", + "homepage": "https://github.com/sebastianbergmann/comparator", + "keywords": [ + "comparator", + "compare", + "equality" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/comparator/issues", + "source": "https://github.com/sebastianbergmann/comparator/tree/5.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:07:16+00:00" + }, + { + "name": "sebastian/complexity", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/complexity.git", + "reference": "e67d240970c9dc7ea7b2123a6d520e334dd61dc6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/complexity/zipball/e67d240970c9dc7ea7b2123a6d520e334dd61dc6", + "reference": "e67d240970c9dc7ea7b2123a6d520e334dd61dc6", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.10", + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for calculating the complexity of PHP code units", + "homepage": "https://github.com/sebastianbergmann/complexity", + "support": { + "issues": "https://github.com/sebastianbergmann/complexity/issues", + "source": "https://github.com/sebastianbergmann/complexity/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T06:59:47+00:00" + }, + { + "name": "sebastian/diff", + "version": "5.0.3", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/diff.git", + "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/diff/zipball/912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "reference": "912dc2fbe3e3c1e7873313cc801b100b6c68c87b", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0", + "symfony/process": "^4.2 || ^5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + } + ], + "description": "Diff implementation", + "homepage": "https://github.com/sebastianbergmann/diff", + "keywords": [ + "diff", + "udiff", + "unidiff", + "unified diff" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/diff/issues", + "security": "https://github.com/sebastianbergmann/diff/security/policy", + "source": "https://github.com/sebastianbergmann/diff/tree/5.0.3" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-05-01T07:48:21+00:00" + }, + { + "name": "sebastian/environment", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/environment.git", + "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/environment/zipball/43c751b41d74f96cbbd4e07b7aec9675651e2951", + "reference": "43c751b41d74f96cbbd4e07b7aec9675651e2951", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "suggest": { + "ext-posix": "*" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Provides functionality to handle HHVM/PHP environments", + "homepage": "https://github.com/sebastianbergmann/environment", + "keywords": [ + "Xdebug", + "environment", + "hhvm" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/environment/issues", + "security": "https://github.com/sebastianbergmann/environment/security/policy", + "source": "https://github.com/sebastianbergmann/environment/tree/6.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-04-11T05:39:26+00:00" + }, + { + "name": "sebastian/exporter", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/exporter.git", + "reference": "f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/exporter/zipball/f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0", + "reference": "f3ec4bf931c0b31e5b413f5b4fc970a7d03338c0", + "shasum": "" + }, + "require": { + "ext-mbstring": "*", + "php": ">=8.1", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Volker Dusch", + "email": "github@wallbash.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + }, + { + "name": "Bernhard Schussek", + "email": "bschussek@gmail.com" + } + ], + "description": "Provides the functionality to export PHP variables for visualization", + "homepage": "https://www.github.com/sebastianbergmann/exporter", + "keywords": [ + "export", + "exporter" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/exporter/issues", + "source": "https://github.com/sebastianbergmann/exporter/tree/5.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:06:49+00:00" + }, + { + "name": "sebastian/global-state", + "version": "6.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/global-state.git", + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/global-state/zipball/7ea9ead78f6d380d2a667864c132c2f7b83055e4", + "reference": "7ea9ead78f6d380d2a667864c132c2f7b83055e4", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "sebastian/object-reflector": "^3.0", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "ext-dom": "*", + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "6.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Snapshotting of global state", + "homepage": "http://www.github.com/sebastianbergmann/global-state", + "keywords": [ + "global state" + ], + "support": { + "issues": "https://github.com/sebastianbergmann/global-state/issues", + "security": "https://github.com/sebastianbergmann/global-state/security/policy", + "source": "https://github.com/sebastianbergmann/global-state/tree/6.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-07-19T07:19:23+00:00" + }, + { + "name": "sebastian/lines-of-code", + "version": "2.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/lines-of-code.git", + "reference": "17c4d940ecafb3d15d2cf916f4108f664e28b130" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/lines-of-code/zipball/17c4d940ecafb3d15d2cf916f4108f664e28b130", + "reference": "17c4d940ecafb3d15d2cf916f4108f664e28b130", + "shasum": "" + }, + "require": { + "nikic/php-parser": "^4.10", + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "2.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library for counting the lines of code in PHP source code", + "homepage": "https://github.com/sebastianbergmann/lines-of-code", + "support": { + "issues": "https://github.com/sebastianbergmann/lines-of-code/issues", + "source": "https://github.com/sebastianbergmann/lines-of-code/tree/2.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:08:02+00:00" + }, + { + "name": "sebastian/object-enumerator", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-enumerator.git", + "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/202d0e344a580d7f7d04b3fafce6933e59dae906", + "reference": "202d0e344a580d7f7d04b3fafce6933e59dae906", + "shasum": "" + }, + "require": { + "php": ">=8.1", + "sebastian/object-reflector": "^3.0", + "sebastian/recursion-context": "^5.0" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Traverses array structures and object graphs to enumerate all referenced objects", + "homepage": "https://github.com/sebastianbergmann/object-enumerator/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-enumerator/issues", + "source": "https://github.com/sebastianbergmann/object-enumerator/tree/5.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:08:32+00:00" + }, + { + "name": "sebastian/object-reflector", + "version": "3.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/object-reflector.git", + "reference": "24ed13d98130f0e7122df55d06c5c4942a577957" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/24ed13d98130f0e7122df55d06c5c4942a577957", + "reference": "24ed13d98130f0e7122df55d06c5c4942a577957", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "3.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + } + ], + "description": "Allows reflection of object attributes, including inherited and non-public ones", + "homepage": "https://github.com/sebastianbergmann/object-reflector/", + "support": { + "issues": "https://github.com/sebastianbergmann/object-reflector/issues", + "source": "https://github.com/sebastianbergmann/object-reflector/tree/3.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:06:18+00:00" + }, + { + "name": "sebastian/recursion-context", + "version": "5.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/recursion-context.git", + "reference": "05909fb5bc7df4c52992396d0116aed689f93712" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/05909fb5bc7df4c52992396d0116aed689f93712", + "reference": "05909fb5bc7df4c52992396d0116aed689f93712", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "5.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "Jeff Welch", + "email": "whatthejeff@gmail.com" + }, + { + "name": "Adam Harvey", + "email": "aharvey@php.net" + } + ], + "description": "Provides functionality to recursively process PHP variables", + "homepage": "https://github.com/sebastianbergmann/recursion-context", + "support": { + "issues": "https://github.com/sebastianbergmann/recursion-context/issues", + "source": "https://github.com/sebastianbergmann/recursion-context/tree/5.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:05:40+00:00" + }, + { + "name": "sebastian/type", + "version": "4.0.0", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/type.git", + "reference": "462699a16464c3944eefc02ebdd77882bd3925bf" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/type/zipball/462699a16464c3944eefc02ebdd77882bd3925bf", + "reference": "462699a16464c3944eefc02ebdd77882bd3925bf", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "require-dev": { + "phpunit/phpunit": "^10.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Collection of value objects that represent the types of the PHP type system", + "homepage": "https://github.com/sebastianbergmann/type", + "support": { + "issues": "https://github.com/sebastianbergmann/type/issues", + "source": "https://github.com/sebastianbergmann/type/tree/4.0.0" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-03T07:10:45+00:00" + }, + { + "name": "sebastian/version", + "version": "4.0.1", + "source": { + "type": "git", + "url": "https://github.com/sebastianbergmann/version.git", + "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/sebastianbergmann/version/zipball/c51fa83a5d8f43f1402e3f32a005e6262244ef17", + "reference": "c51fa83a5d8f43f1402e3f32a005e6262244ef17", + "shasum": "" + }, + "require": { + "php": ">=8.1" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "4.0-dev" + } + }, + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de", + "role": "lead" + } + ], + "description": "Library that helps with managing the version number of Git-hosted PHP projects", + "homepage": "https://github.com/sebastianbergmann/version", + "support": { + "issues": "https://github.com/sebastianbergmann/version/issues", + "source": "https://github.com/sebastianbergmann/version/tree/4.0.1" + }, + "funding": [ + { + "url": "https://github.com/sebastianbergmann", + "type": "github" + } + ], + "time": "2023-02-07T11:34:05+00:00" + }, { "name": "squizlabs/php_codesniffer", - "version": "3.7.1", + "version": "3.7.2", "source": { "type": "git", "url": "https://github.com/squizlabs/PHP_CodeSniffer.git", - "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619" + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/1359e176e9307e906dc3d890bcc9603ff6d90619", - "reference": "1359e176e9307e906dc3d890bcc9603ff6d90619", + "url": "https://api.github.com/repos/squizlabs/PHP_CodeSniffer/zipball/ed8e00df0a83aa96acf703f8c2979ff33341f879", + "reference": "ed8e00df0a83aa96acf703f8c2979ff33341f879", "shasum": "" }, "require": { @@ -54,14 +2412,65 @@ "homepage": "https://github.com/squizlabs/PHP_CodeSniffer", "keywords": [ "phpcs", - "standards" + "standards", + "static analysis" ], "support": { "issues": "https://github.com/squizlabs/PHP_CodeSniffer/issues", "source": "https://github.com/squizlabs/PHP_CodeSniffer", "wiki": "https://github.com/squizlabs/PHP_CodeSniffer/wiki" }, - "time": "2022-06-18T07:21:10+00:00" + "time": "2023-02-22T23:07:41+00:00" + }, + { + "name": "theseer/tokenizer", + "version": "1.2.1", + "source": { + "type": "git", + "url": "https://github.com/theseer/tokenizer.git", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theseer/tokenizer/zipball/34a41e998c2183e22995f158c581e7b5e755ab9e", + "reference": "34a41e998c2183e22995f158c581e7b5e755ab9e", + "shasum": "" + }, + "require": { + "ext-dom": "*", + "ext-tokenizer": "*", + "ext-xmlwriter": "*", + "php": "^7.2 || ^8.0" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Arne Blankerts", + "email": "arne@blankerts.de", + "role": "Developer" + } + ], + "description": "A small library for converting tokenized PHP source code into XML and potentially other formats", + "support": { + "issues": "https://github.com/theseer/tokenizer/issues", + "source": "https://github.com/theseer/tokenizer/tree/1.2.1" + }, + "funding": [ + { + "url": "https://github.com/theseer", + "type": "github" + } + ], + "time": "2021-07-28T10:34:58+00:00" } ], "aliases": [], @@ -69,7 +2478,9 @@ "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, - "platform": [], + "platform": { + "ext-mbstring": "*" + }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/web/documentserver-example/php/config.json b/web/documentserver-example/php/config.json deleted file mode 100644 index 01518ebd2..000000000 --- a/web/documentserver-example/php/config.json +++ /dev/null @@ -1,88 +0,0 @@ -{ - "version": "1.6.0", - - "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/", - - "docServConverterUrl": "ConvertService.ashx", - "docServApiUrl": "web-apps/apps/api/documents/api.js", - "docServPreloaderUrl": "web-apps/apps/api/documents/cache-scripts.html", - "docServCommandUrl": "coauthoring/CommandService.ashx", - - "docServJwtSecret": "", - "docServJwtHeader": "Authorization", - "docServJwtUseForRequest": true, - - "docServVerifyPeerOff": true, - - "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", - "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" - } -} diff --git a/web/documentserver-example/php/doceditor.php b/web/documentserver-example/php/doceditor.php deleted file mode 100755 index 918fa7e28..000000000 --- a/web/documentserver-example/php/doceditor.php +++ /dev/null @@ -1,26 +0,0 @@ -render(); diff --git a/web/documentserver-example/php/docker-compose.yml b/web/documentserver-example/php/docker-compose.yml new file mode 100644 index 000000000..704b253e9 --- /dev/null +++ b/web/documentserver-example/php/docker-compose.yml @@ -0,0 +1,41 @@ +version: "3.8" + +services: + document-server: + container_name: document-server + image: onlyoffice/documentserver:7.5 + expose: + - "80" + environment: + - JWT_SECRET=your-256-bit-secret + + example: + container_name: example + build: + context: . + target: example + expose: + - "80" + volumes: + - "example:/srv" + environment: + - ADDRESS=0.0.0.0 + - DOCUMENT_SERVER_PRIVATE_URL=http://proxy:8080 + - DOCUMENT_SERVER_PUBLIC_URL=http://localhost:8080 + - EXAMPLE_URL=http://proxy + - JWT_SECRET=your-256-bit-secret + - PORT=80 + + proxy: + container_name: proxy + build: + context: . + target: proxy + ports: + - "80:80" + - "8080:8080" + volumes: + - "example:/srv" + +volumes: + example: diff --git a/web/documentserver-example/php/helpers/ConfigManager.php b/web/documentserver-example/php/helpers/ConfigManager.php deleted file mode 100644 index af898522d..000000000 --- a/web/documentserver-example/php/helpers/ConfigManager.php +++ /dev/null @@ -1,46 +0,0 @@ -config = json_decode($this->getConfigurationJson()); - } - - private function getConfigurationJson(): bool|string - { - return file_exists("./config.json") ? file_get_contents("./config.json") : false; - } - - /** - * @param string|null $configName - * @return mixed - */ - public function getConfig(string $configName = null): mixed - { - if ($configName) { - return $this->config->$configName ?? ""; - } - return $this->config; - } -} diff --git a/web/documentserver-example/php/index.php b/web/documentserver-example/php/index.php index b63f81576..88ed6ab69 100755 --- a/web/documentserver-example/php/index.php +++ b/web/documentserver-example/php/index.php @@ -1,4 +1,4 @@ -render(); +function configure() +{ + $configManager = new ConfigurationManager(); + if ($configManager->sslVerifyPeerModeEnabled()) { + // Ignore self-signed certificate. + stream_context_set_default([ + 'ssl' => [ + 'verify_peer' => false, + 'verify_peer_name' => false + ] + ]); + } +} + +function routers() +{ + // TODO: delete fallback. + // In theory, the content type of the response should be declared inside the + // router function. However, this statement isn't true for all routers, and + // it's also not true for all branches in all routers. Therefore, we are + // setting the default content type for all routers here. + header('Content-Type: application/json; charset=utf-8'); + + header('Cache-Control: no-cache, must-revalidate, max-age=0'); + header('Expires: Wed, 11 Jan 1984 05:00:00 GMT'); + header('Pragma: no-cache'); + @header_remove('Last-Modified'); + header('X-Content-Type-Options: nosniff'); + header('X-Robots-Tag: noindex'); + + $url = new URL($_SERVER['REQUEST_URI']); + sendlog($url->string(), 'webedior-ajax.log'); + + $path = $url->path(); + if (!$path || $path === '/') { + header('Content-Type: text/html; charset=utf-8'); + $view = new IndexView($_REQUEST); + $view->render(); + return; + } + if (str_starts_with($path, '/editor')) { + header('Content-Type: text/html; charset=utf-8'); + $view = new DocEditorView($_REQUEST); + $view->render(); + return; + } + if (str_starts_with($path, '/assets')) { + $response = assets(); + $response['status'] = 'success'; + echo json_encode($response); + return; + } + if (str_starts_with($path, '/convert')) { + $response = convert(); + $response['status'] = 'success'; + echo json_encode($response); + return; + } + if (str_starts_with($path, '/csv')) { + $response = csv(); + $response['status'] = 'success'; + echo json_encode($response); + return; + } + if (str_starts_with($path, '/delete')) { + $response = delete(); + $response['status'] = isset($response['error']) ? 'error' : 'success'; + echo json_encode($response); + return; + } + if (str_starts_with($path, '/download')) { + $response = download(); + $response['status'] = 'success'; + echo json_encode($response); + return; + } + if (str_starts_with($path, '/files')) { + $response = files(); + echo json_encode($response); + return; + } + if (str_starts_with($path, '/history')) { + $response = historyDownload(); + $response['status'] = 'success'; + echo json_encode($response); + return; + } + if (str_starts_with($path, '/reference')) { + $response = reference(); + $response['status'] = 'success'; + echo json_encode($response); + return; + } + if (str_starts_with($path, '/rename')) { + $response = renamefile(); + $content = json_encode($response); + echo $content; + return; + } + if (str_starts_with($path, '/restore')) { + $response = restore(); + echo json_encode($response); + return; + } + if (str_starts_with($path, '/saveas')) { + $response = saveas(); + $response['status'] = 'success'; + echo json_encode($response); + return; + } + if (str_starts_with($path, '/track')) { + $response = track(); + $response['status'] = 'success'; + echo json_encode($response); + return; + } + if (str_starts_with($path, '/upload')) { + $response = upload(); + $response['status'] = isset($response['error']) ? 'error' : 'success'; + echo json_encode($response); + return; + } + + http_response_code(HTTPStatus::NotFound->value); +} + +configure(); +routers(); diff --git a/web/documentserver-example/php/lib/jwt/BeforeValidException.php b/web/documentserver-example/php/lib/jwt/BeforeValidException.php deleted file mode 100644 index a6ee2f7c6..000000000 --- a/web/documentserver-example/php/lib/jwt/BeforeValidException.php +++ /dev/null @@ -1,7 +0,0 @@ - - * @author Anant Narayanan - * @license http://opensource.org/licenses/BSD-3-Clause 3-clause BSD - * @link https://github.com/firebase/php-jwt - */ -class JWT -{ - - /** - * When checking nbf, iat or expiration times, - * we want to provide some extra leeway time to - * account for clock skew. - */ - public static $leeway = 0; - - /** - * Allow the current timestamp to be specified. - * Useful for fixing a value within unit testing. - * - * Will default to PHP time() value if null. - */ - public static $timestamp = null; - - public static $supported_algs = array( - 'HS256' => array('hash_hmac', 'SHA256'), - 'HS512' => array('hash_hmac', 'SHA512'), - 'HS384' => array('hash_hmac', 'SHA384'), - 'RS256' => array('openssl', 'SHA256'), - ); - - /** - * Decodes a JWT string into a PHP object. - * - * @param string $jwt The JWT - * @param string|array $key The key, or map of keys. - * If the algorithm used is asymmetric, this is the public key - * @param array $allowed_algs List of supported verification algorithms - * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256' - * - * @return object The JWT's payload as a PHP object - * - * @throws UnexpectedValueException Provided JWT was invalid - * @throws SignatureInvalidException Provided JWT was invalid because the signature verification failed - * @throws BeforeValidException Provided JWT is trying to be used before it's eligible as defined by 'nbf' - * @throws BeforeValidException Provided JWT is trying to be used before it's been created as defined by 'iat' - * @throws ExpiredException Provided JWT has since expired, as defined by the 'exp' claim - * - * @uses jsonDecode - * @uses urlsafeB64Decode - */ - public static function decode($jwt, $key, $allowed_algs = array()) - { - $timestamp = is_null(static::$timestamp) ? time() : static::$timestamp; - - if (empty($key)) { - throw new InvalidArgumentException('Key may not be empty'); - } - if (!is_array($allowed_algs)) { - throw new InvalidArgumentException('Algorithm not allowed'); - } - $tks = explode('.', $jwt); - if (count($tks) != 3) { - throw new UnexpectedValueException('Wrong number of segments'); - } - list($headb64, $bodyb64, $cryptob64) = $tks; - if (null === ($header = static::jsonDecode(static::urlsafeB64Decode($headb64)))) { - throw new UnexpectedValueException('Invalid header encoding'); - } - if (null === $payload = static::jsonDecode(static::urlsafeB64Decode($bodyb64))) { - throw new UnexpectedValueException('Invalid claims encoding'); - } - $sig = static::urlsafeB64Decode($cryptob64); - - if (empty($header->alg)) { - throw new UnexpectedValueException('Empty algorithm'); - } - if (empty(static::$supported_algs[$header->alg])) { - throw new UnexpectedValueException('Algorithm not supported'); - } - if (!in_array($header->alg, $allowed_algs)) { - throw new UnexpectedValueException('Algorithm not allowed'); - } - if (is_array($key) || $key instanceof \ArrayAccess) { - if (isset($header->kid)) { - $key = $key[$header->kid]; - } else { - throw new UnexpectedValueException('"kid" empty, unable to lookup correct key'); - } - } - - // Check the signature - if (!static::verify("$headb64.$bodyb64", $sig, $key, $header->alg)) { - throw new SignatureInvalidException('Signature verification failed'); - } - - // Check if the nbf if it is defined. This is the time that the - // token can actually be used. If it's not yet that time, abort. - if (isset($payload->nbf) && $payload->nbf > ($timestamp + static::$leeway)) { - throw new BeforeValidException( - 'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->nbf) - ); - } - - // Check that this token has been created before 'now'. This prevents - // using tokens that have been created for later use (and haven't - // correctly used the nbf claim). - if (isset($payload->iat) && $payload->iat > ($timestamp + static::$leeway)) { - throw new BeforeValidException( - 'Cannot handle token prior to ' . date(DateTime::ISO8601, $payload->iat) - ); - } - - // Check if this token has expired. - if (isset($payload->exp) && ($timestamp - static::$leeway) >= $payload->exp) { - throw new ExpiredException('Expired token'); - } - - return $payload; - } - - /** - * Converts and signs a PHP object or array into a JWT string. - * - * @param object|array $payload PHP object or array - * @param string $key The secret key. - * If the algorithm used is asymmetric, this is the private key - * @param string $alg The signing algorithm. - * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256' - * @param mixed $keyId - * @param array $head An array with header elements to attach - * - * @return string A signed JWT - * - * @uses jsonEncode - * @uses urlsafeB64Encode - */ - public static function encode($payload, $key, $alg = 'HS256', $keyId = null, $head = null) - { - $header = array('typ' => 'JWT', 'alg' => $alg); - if ($keyId !== null) { - $header['kid'] = $keyId; - } - if ( isset($head) && is_array($head) ) { - $header = array_merge($head, $header); - } - $segments = array(); - $segments[] = static::urlsafeB64Encode(static::jsonEncode($header)); - $segments[] = static::urlsafeB64Encode(static::jsonEncode($payload)); - $signing_input = implode('.', $segments); - - $signature = static::sign($signing_input, $key, $alg); - $segments[] = static::urlsafeB64Encode($signature); - - return implode('.', $segments); - } - - /** - * Sign a string with a given key and algorithm. - * - * @param string $msg The message to sign - * @param string|resource $key The secret key - * @param string $alg The signing algorithm. - * Supported algorithms are 'HS256', 'HS384', 'HS512' and 'RS256' - * - * @return string An encrypted message - * - * @throws DomainException Unsupported algorithm was specified - */ - public static function sign($msg, $key, $alg = 'HS256') - { - if (empty(static::$supported_algs[$alg])) { - throw new DomainException('Algorithm not supported'); - } - list($function, $algorithm) = static::$supported_algs[$alg]; - switch($function) { - case 'hash_hmac': - return hash_hmac($algorithm, $msg, $key, true); - case 'openssl': - $signature = ''; - $success = openssl_sign($msg, $signature, $key, $algorithm); - if (!$success) { - throw new DomainException("OpenSSL unable to sign data"); - } else { - return $signature; - } - } - } - - /** - * Verify a signature with the message, key and method. Not all methods - * are symmetric, so we must have a separate verify and sign method. - * - * @param string $msg The original message (header and body) - * @param string $signature The original signature - * @param string|resource $key For HS*, a string key works. for RS*, must be a resource of an openssl public key - * @param string $alg The algorithm - * - * @return bool - * - * @throws DomainException Invalid Algorithm or OpenSSL failure - */ - private static function verify($msg, $signature, $key, $alg) - { - if (empty(static::$supported_algs[$alg])) { - throw new DomainException('Algorithm not supported'); - } - - list($function, $algorithm) = static::$supported_algs[$alg]; - switch($function) { - case 'openssl': - $success = openssl_verify($msg, $signature, $key, $algorithm); - if (!$success) { - throw new DomainException("OpenSSL unable to verify data: " . openssl_error_string()); - } else { - return $signature; - } - case 'hash_hmac': - default: - $hash = hash_hmac($algorithm, $msg, $key, true); - if (function_exists('hash_equals')) { - return hash_equals($signature, $hash); - } - $len = min(static::safeStrlen($signature), static::safeStrlen($hash)); - - $status = 0; - for ($i = 0; $i < $len; $i++) { - $status |= (ord($signature[$i]) ^ ord($hash[$i])); - } - $status |= (static::safeStrlen($signature) ^ static::safeStrlen($hash)); - - return ($status === 0); - } - } - - /** - * Decode a JSON string into a PHP object. - * - * @param string $input JSON string - * - * @return object Object representation of JSON string - * - * @throws DomainException Provided string was invalid JSON - */ - public static function jsonDecode($input) - { - if (version_compare(PHP_VERSION, '5.4.0', '>=') && !(defined('JSON_C_VERSION') && PHP_INT_SIZE > 4)) { - /** In PHP >=5.4.0, json_decode() accepts an options parameter, that allows you - * to specify that large ints (like Steam Transaction IDs) should be treated as - * strings, rather than the PHP default behaviour of converting them to floats. - */ - $obj = json_decode($input, false, 512, JSON_BIGINT_AS_STRING); - } else { - /** Not all servers will support that, however, so for older versions we must - * manually detect large ints in the JSON string and quote them (thus converting - *them to strings) before decoding, hence the preg_replace() call. - */ - $max_int_length = strlen((string) PHP_INT_MAX) - 1; - $json_without_bigints = preg_replace('/:\s*(-?\d{'.$max_int_length.',})/', ': "$1"', $input); - $obj = json_decode($json_without_bigints); - } - - if (function_exists('json_last_error') && $errno = json_last_error()) { - static::handleJsonError($errno); - } elseif ($obj === null && $input !== 'null') { - throw new DomainException('Null result with non-null input'); - } - return $obj; - } - - /** - * Encode a PHP object into a JSON string. - * - * @param object|array $input A PHP object or array - * - * @return string JSON representation of the PHP object or array - * - * @throws DomainException Provided object could not be encoded to valid JSON - */ - public static function jsonEncode($input) - { - $json = json_encode($input); - if (function_exists('json_last_error') && $errno = json_last_error()) { - static::handleJsonError($errno); - } elseif ($json === 'null' && $input !== null) { - throw new DomainException('Null result with non-null input'); - } - return $json; - } - - /** - * Decode a string with URL-safe Base64. - * - * @param string $input A Base64 encoded string - * - * @return string A decoded string - */ - public static function urlsafeB64Decode($input) - { - $remainder = strlen($input) % 4; - if ($remainder) { - $padlen = 4 - $remainder; - $input .= str_repeat('=', $padlen); - } - return base64_decode(strtr($input, '-_', '+/')); - } - - /** - * Encode a string with URL-safe Base64. - * - * @param string $input The string you want encoded - * - * @return string The base64 encode of what you passed in - */ - public static function urlsafeB64Encode($input) - { - return str_replace('=', '', strtr(base64_encode($input), '+/', '-_')); - } - - /** - * Helper method to create a JSON error. - * - * @param int $errno An error number from json_last_error() - * - * @return void - */ - private static function handleJsonError($errno) - { - $messages = array( - JSON_ERROR_DEPTH => 'Maximum stack depth exceeded', - JSON_ERROR_CTRL_CHAR => 'Unexpected control character found', - JSON_ERROR_SYNTAX => 'Syntax error, malformed JSON' - ); - throw new DomainException( - isset($messages[$errno]) - ? $messages[$errno] - : 'Unknown JSON error: ' . $errno - ); - } - - /** - * Get the number of bytes in cryptographic strings. - * - * @param string - * - * @return int - */ - private static function safeStrlen($str) - { - if (function_exists('mb_strlen')) { - return mb_strlen($str, '8bit'); - } - return strlen($str); - } -} diff --git a/web/documentserver-example/php/lib/jwt/LICENSE b/web/documentserver-example/php/lib/jwt/LICENSE deleted file mode 100644 index cb0c49b33..000000000 --- a/web/documentserver-example/php/lib/jwt/LICENSE +++ /dev/null @@ -1,30 +0,0 @@ -Copyright (c) 2011, Neuman Vong - -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - - * Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - * Redistributions in binary form must reproduce the above - copyright notice, this list of conditions and the following - disclaimer in the documentation and/or other materials provided - with the distribution. - - * Neither the name of Neuman Vong nor the names of other - contributors may be used to endorse or promote products derived - from this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/web/documentserver-example/php/lib/jwt/SignatureInvalidException.php b/web/documentserver-example/php/lib/jwt/SignatureInvalidException.php deleted file mode 100644 index 27332b21b..000000000 --- a/web/documentserver-example/php/lib/jwt/SignatureInvalidException.php +++ /dev/null @@ -1,7 +0,0 @@ - + + A custom coding standard + + + + + + + + + + + + + + 0 + + + 0 + + diff --git a/web/documentserver-example/php/proxy/nginx.conf b/web/documentserver-example/php/proxy/nginx.conf new file mode 100644 index 000000000..ccdc7cb77 --- /dev/null +++ b/web/documentserver-example/php/proxy/nginx.conf @@ -0,0 +1,47 @@ +worker_processes auto; + +events { + worker_connections 512; +} + +http { + include /etc/nginx/mime.types; + + server { + listen 80; + root /srv; + server_name localhost; + + location / { + index index.html index.php; + try_files $uri $uri/ /index.php?$query_string; + } + + location ~ \.php$ { + include fastcgi_params; + + fastcgi_index index.php; + fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; + fastcgi_pass example:80; + } + } + + server { + listen 8080; + 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; + } + } +} diff --git a/web/documentserver-example/php/ruleset.xml b/web/documentserver-example/php/ruleset.xml deleted file mode 100644 index fb66fb007..000000000 --- a/web/documentserver-example/php/ruleset.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - This standard changes the line length - - - - - - - - - - - \ No newline at end of file diff --git a/web/documentserver-example/php/ajax.php b/web/documentserver-example/php/src/ajax.php similarity index 76% rename from web/documentserver-example/php/ajax.php rename to web/documentserver-example/php/src/ajax.php index 012d5e134..e1eb64604 100644 --- a/web/documentserver-example/php/ajax.php +++ b/web/documentserver-example/php/src/ajax.php @@ -15,12 +15,14 @@ * limitations under the License. */ -namespace OnlineEditorsExamplePhp; +namespace Example; use Exception; -use OnlineEditorsExamplePhp\Helpers\ConfigManager; -use OnlineEditorsExamplePhp\Helpers\ExampleUsers; -use OnlineEditorsExamplePhp\Helpers\JwtManager; +use Example\Common\Path; +use Example\Configuration\ConfigurationManager; +use Example\Format\FormatManager; +use Example\Helpers\ExampleUsers; +use Example\Helpers\JwtManager; /** * Check if the request is an AJAX request @@ -47,41 +49,6 @@ function getHttpOrigin() return $origin; } -/** - * Set headers that prevent caching in all the browsers - * - * @return void - */ -function nocacheHeaders() -{ - $headers = [ - 'Expires' => 'Wed, 11 Jan 1984 05:00:00 GMT', - 'Cache-Control' => 'no-cache, must-revalidate, max-age=0', - 'Pragma' => 'no-cache', - ]; - $headers['Last-Modified'] = false; - - unset($headers['Last-Modified']); - - // In PHP 5.3+, make sure we are not sending a Last-Modified header. - if (function_exists('header_remove')) { - @header_remove('Last-Modified'); - } else { - // In PHP 5.2, send an empty Last-Modified header, but only as a - // last resort to override a header already sent. #WP23021 - foreach (headers_list() as $header) { - if (0 === mb_stripos($header, 'Last-Modified')) { - $headers['Last-Modified'] = ''; - break; - } - } - } - - foreach ($headers as $name => $field_value) { - @header("{$name}: {$field_value}"); - } -} - /** * Save copy as... * @@ -90,29 +57,25 @@ function nocacheHeaders() function saveas() { try { + $configManager = new ConfigurationManager(); + $formatManager = new FormatManager(); + $post = json_decode(file_get_contents('php://input'), true); $fileurl = $post["url"]; $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 = $formatManager->allExtensions(); $filename = GetCorrectName($title); - if (!in_array("." . $extension, $allexts)) { + if (!in_array($extension, $allexts)) { $result["error"] = "File type is not supported"; return $result; } $headers = get_headers($fileurl, 1); - $content_length = $headers["Content-Length"]; + $contentLength = $headers["Content-Length"]; $data = file_get_contents(str_replace(" ", "%20", $fileurl)); - if ($data === false || $content_length <= 0 || $content_length > - $configManager->getConfig("fileSizeMax")) { + if ($data === false || $contentLength <= 0 || $contentLength > $configManager->maximumFileSize()) { $result["error"] = "File size is incorrect"; return $result; } @@ -138,7 +101,9 @@ function saveas() */ function upload() { - $configManager = new ConfigManager(); + $configManager = new ConfigurationManager(); + $formatManager = new FormatManager(); + if ($_FILES['files']['error'] > 0) { $result["error"] = 'Error ' . json_encode($_FILES['files']['error']); return $result; @@ -156,16 +121,16 @@ 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")) { + if ($filesize <= 0 || $filesize > $configManager->maximumFileSize()) { $result["error"] = 'File size is incorrect'; // if not, then an error occurs return $result; } // check if the file extension is supported by the editor - if (!in_array($ext, getFileExts())) { + if (!in_array($ext, $formatManager->allExtensions())) { $result["error"] = 'File type is not supported'; // if not, then an error occurs return $result; } @@ -208,8 +173,16 @@ function track() return $data; } - global $_trackerStatus; - $status = $_trackerStatus[$data->status]; // get status from the request body + $trackerStatus = [ + 0 => 'NotFound', + 1 => 'Editing', + 2 => 'MustSave', + 3 => 'Corrupted', + 4 => 'Closed', + 6 => 'MustForceSave', + 7 => 'CorruptedForceSave', + ]; + $status = $trackerStatus[$data->status]; // get status from the request body $userAddress = $_GET["userAddress"]; $fileName = basename($_GET["fileName"]); @@ -247,23 +220,23 @@ function track() */ function convert() { + $formatManager = new FormatManager(); + $post = json_decode(file_get_contents('php://input'), true); $fileName = basename($post["filename"]); $filePass = $post["filePass"]; $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, $formatManager->convertibleExtensions()) && $internalExtension != "") { $fileUri = $post["fileUri"]; if ($fileUri == null || $fileUri == "") { $fileUri = serverPath(true) . '/' - . "webeditor-ajax.php" - . "?type=download" - . "&fileName=" . urlencode($fileName) + . "download" + . "?fileName=" . urlencode($fileName) . "&userAddress=" . getClientIp(); } $key = getDocEditorKey($fileName); @@ -368,8 +341,9 @@ function files() function assets() { $fileName = basename($_GET["name"]); - $filePath = dirname(__FILE__) . - DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "sample" . DIRECTORY_SEPARATOR . $fileName; + $filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . + DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "document-templates" + . DIRECTORY_SEPARATOR . "sample" . DIRECTORY_SEPARATOR . $fileName; downloadFile($filePath); } @@ -381,8 +355,9 @@ function assets() function csv() { $fileName = "csv.csv"; - $filePath = dirname(__FILE__) . - DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "sample" . DIRECTORY_SEPARATOR . $fileName; + $filePath = dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . + DIRECTORY_SEPARATOR . "assets" . DIRECTORY_SEPARATOR . "document-templates" + . DIRECTORY_SEPARATOR . "sample" . DIRECTORY_SEPARATOR . $fileName; downloadFile($filePath); } @@ -394,6 +369,8 @@ function csv() function historyDownload() { try { + $configManager = new ConfigurationManager(); + $fileName = basename($_GET["fileName"]); // get the file name $userAddress = $_GET["userAddress"]; @@ -402,9 +379,7 @@ function historyDownload() $jwtManager = new JwtManager(); if ($jwtManager->isJwtEnabled()) { - $configManager = new ConfigManager(); - $jwtHeader = $configManager->getConfig("docServJwtHeader") == "" ? - "Authorization" : $configManager->getConfig("docServJwtHeader"); + $jwtHeader = $configManager->jwtHeader(); if (!empty(apache_request_headers()[$jwtHeader])) { $token = $jwtManager->jwtDecode(mb_substr( apache_request_headers()[$jwtHeader], @@ -441,17 +416,15 @@ function historyDownload() function download() { try { - $configManager = new ConfigManager(); - $fileName = realpath($configManager->getConfig("storagePath")) - === $configManager->getConfig("storagePath") ? - $_GET["fileName"] : basename($_GET["fileName"]); // get the file name + $configManager = new ConfigurationManager(); + + $fileName = $_GET["fileName"]; $userAddress = $_GET["userAddress"] ?? null; $isEmbedded = $_GET["&dmode"] ?? null; $jwtManager = new JwtManager(); if ($jwtManager->isJwtEnabled() && $isEmbedded == null && $userAddress) { - $jwtHeader = $configManager->getConfig("docServJwtHeader") == "" ? - "Authorization" : $configManager->getConfig("docServJwtHeader"); + $jwtHeader = $configManager->jwtHeader(); if (!empty(apache_request_headers()[$jwtHeader])) { $token = $jwtManager->jwtDecode(mb_substr( apache_request_headers()[$jwtHeader], @@ -491,7 +464,10 @@ 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\'\'' . + str_replace("+", "%20", urlencode(basename($filePath))) + ); @header('Content-Type: ' . mime_content_type($filePath)); @header('Access-Control-Allow-Origin: *'); @@ -608,3 +584,74 @@ function reference() return $data; } + +function restore() +{ + try { + $input = file_get_contents('php://input'); + $body = json_decode($input); + + $sourceBasename = $body->fileName; + $version = $body->version; + $userID = $body->userId; + + $sourceFile = getStoragePath($sourceBasename); + $historyDirectory = getHistoryDir($sourceFile); + + $bumpedVersion = getFileVersion($historyDirectory); + $bumpedVersionStringDirectory = getVersionDir($historyDirectory, $bumpedVersion); + if (!file_exists($bumpedVersionStringDirectory)) { + mkdir($bumpedVersionStringDirectory); + } + $bumpedVersionDirectory = new Path($bumpedVersionStringDirectory); + + $bumpedKeyFile = $bumpedVersionDirectory->joinPath('key.txt'); + $bumpedKeyStringFile = $bumpedKeyFile->string(); + $bumpedKey = getDocEditorKey($sourceBasename); + file_put_contents($bumpedKeyStringFile, $bumpedKey, LOCK_EX); + + $users = new ExampleUsers(); + $user = $users->getUser($userID); + + $bumpedChangesFile = $bumpedVersionDirectory->joinPath('changes.json'); + $bumpedChangesStringFile = $bumpedChangesFile->string(); + $bumpedChanges = [ + 'serverVersion' => null, + 'changes' => array( + [ + 'created' => date('Y-m-d H:i:s'), + 'user' => [ + 'id' => $user->id, + 'name' => $user->name + ] + ] + ) + ]; + $bumpedChangesContent = json_encode($bumpedChanges, JSON_PRETTY_PRINT); + file_put_contents($bumpedChangesStringFile, $bumpedChangesContent, LOCK_EX); + + $sourceExtension = pathinfo($sourceBasename, PATHINFO_EXTENSION); + $previousBasename = "prev.{$sourceExtension}"; + + $bumpedFile = $bumpedVersionDirectory->joinPath($previousBasename); + $bumpedStringFile = $bumpedFile->string(); + copy($sourceFile, $bumpedStringFile); + + $recoveryVersionStringDirectory = getVersionDir($historyDirectory, $version); + $recoveryVersionDirectory = new Path($recoveryVersionStringDirectory); + $recoveryFile = $recoveryVersionDirectory->joinPath($previousBasename); + $recoveryStringFile = $recoveryFile->string(); + copy($recoveryStringFile, $sourceFile); + + return [ + 'error' => null, + 'success' => true + ]; + } catch (Exception $error) { + $message = $error->getMessage(); + return [ + 'error' => $message, + 'success' => false + ]; + } +} diff --git a/web/documentserver-example/php/src/common/HTTPStatus.php b/web/documentserver-example/php/src/common/HTTPStatus.php new file mode 100644 index 000000000..06c1eab35 --- /dev/null +++ b/web/documentserver-example/php/src/common/HTTPStatus.php @@ -0,0 +1,23 @@ +string = $path; + } + + public function string(): string + { + return $this->string; + } + + public function dirname(): ?string + { + $string = $this->string(); + $parsed = pathinfo($string, PATHINFO_DIRNAME); + return $parsed ?: null; + } + + public function basename(): ?string + { + $string = $this->string(); + $parsed = pathinfo($string, PATHINFO_BASENAME); + return $parsed ?: null; + } + + public function extension(): ?string + { + $string = $this->string(); + $parsed = pathinfo($string, PATHINFO_EXTENSION); + return $parsed ?: null; + } + + public function filename(): ?string + { + $string = $this->string(); + $parsed = pathinfo($string, PATHINFO_FILENAME); + return $parsed ?: null; + } + + public function normalize(): self + { + $string = $this->string(); + $filtered = array(); + $slugs = explode($this->separator, $string); + foreach ($slugs as $slug) { + if ($slug === '.') { + continue; + } + if ($slug === '..') { + array_pop($filtered); + continue; + } + $filtered[] = $slug; + } + $joined = implode($this->separator, $filtered); + $escapedSeparator = preg_quote($this->separator, $this->separator); + $separatorRegex = "/{$escapedSeparator}{2,}/"; + $separated = preg_replace($separatorRegex, $this->separator, $joined); + return new Path($separated); + } + + public function joinPath(string $path): self + { + $string = $this->string(); + $separator = + str_ends_with($string, $this->separator) || + str_starts_with($path, $this->separator) + ? '' + : $this->separator; + return new Path("{$string}{$separator}{$path}"); + } + + public function absolute(): bool + { + $string = $this->string(); + + $ntRegex = '/^[A-Za-z]:\\\\/'; + if (preg_match($ntRegex, $string)) { + return true; + } + + $ntSeparator = '\\'; + if (str_starts_with($string, $ntSeparator)) { + return true; + } + + $posixSeparator = '/'; + if (str_starts_with($string, $posixSeparator)) { + return true; + } + + return false; + } + + public function exists(): bool + { + $string = $this->string(); + return file_exists($string); + } + + public function contents(): string + { + $string = $this->string(); + return file_get_contents($string); + } + + public function directory(): bool + { + $string = $this->string(); + return is_dir($string); + } + + public function makeDirectory(): bool + { + $string = $this->string(); + return mkdir($string); + } +} diff --git a/web/documentserver-example/php/src/common/PathAbsolutePOSIXTests.php b/web/documentserver-example/php/src/common/PathAbsolutePOSIXTests.php new file mode 100644 index 000000000..08c71aa73 --- /dev/null +++ b/web/documentserver-example/php/src/common/PathAbsolutePOSIXTests.php @@ -0,0 +1,45 @@ +absolute(); + $this->assertFalse($absolute); + } + + public function testRecognizesARelativeAsANonAbsolute() + { + $path = new Path('.'); + $absolute = $path->absolute(); + $this->assertFalse($absolute); + } + + public function testRecognizesAnAbsoluteAsAnAbsolute() + { + $path = new Path('/'); + $absolute = $path->absolute(); + $this->assertTrue($absolute); + } +} diff --git a/web/documentserver-example/php/src/common/PathJoinPOSIXTests.php b/web/documentserver-example/php/src/common/PathJoinPOSIXTests.php new file mode 100644 index 000000000..c99aeded1 --- /dev/null +++ b/web/documentserver-example/php/src/common/PathJoinPOSIXTests.php @@ -0,0 +1,94 @@ +joinPath('srv'); + $this->assertEquals($joined->dirname(), '/'); + $this->assertEquals($joined->basename(), 'srv'); + $this->assertEquals($joined->extension(), null); + $this->assertEquals($joined->filename(), 'srv'); + } + + public function testJoinsARelativeToARelativeOne() + { + $path = new Path('.'); + $joined = $path->joinPath('srv'); + $this->assertEquals($joined->dirname(), '.'); + $this->assertEquals($joined->basename(), 'srv'); + $this->assertEquals($joined->extension(), null); + $this->assertEquals($joined->filename(), 'srv'); + } + + public function testJoinsARelativeToAnAbsoluteOne() + { + $path = new Path('/'); + $joined = $path->joinPath('srv'); + $this->assertEquals($joined->dirname(), '/'); + $this->assertEquals($joined->basename(), 'srv'); + $this->assertEquals($joined->extension(), null); + $this->assertEquals($joined->filename(), 'srv'); + } + + public function testJoinsAnAbsoluteToAnEmptyOne() + { + $path = new Path(''); + $joined = $path->joinPath('/srv'); + $this->assertEquals($joined->dirname(), '/'); + $this->assertEquals($joined->basename(), 'srv'); + $this->assertEquals($joined->extension(), null); + $this->assertEquals($joined->filename(), 'srv'); + } + + public function testJoinsAnAbsoluteToARelativeOne() + { + $path = new Path('.'); + $joined = $path->joinPath('/srv'); + $this->assertEquals($joined->dirname(), '.'); + $this->assertEquals($joined->basename(), 'srv'); + $this->assertEquals($joined->extension(), null); + $this->assertEquals($joined->filename(), 'srv'); + } + + public function testJoinsAnAbsoluteToAnAbsoluteOne() + { + $path = new Path('/'); + $joined = $path->joinPath('/srv'); + $this->assertEquals($joined->dirname(), '/'); + $this->assertEquals($joined->basename(), 'srv'); + $this->assertEquals($joined->extension(), null); + $this->assertEquals($joined->filename(), 'srv'); + } + + public function testJoinsAnUnnormalized() + { + $path = new Path(''); + $joined = $path->joinPath('../srv'); + $this->assertEquals($joined->dirname(), '/..'); + $this->assertEquals($joined->basename(), 'srv'); + $this->assertEquals($joined->extension(), null); + $this->assertEquals($joined->filename(), 'srv'); + } +} diff --git a/web/documentserver-example/php/src/common/PathNormalizePOSIXTests.php b/web/documentserver-example/php/src/common/PathNormalizePOSIXTests.php new file mode 100644 index 000000000..608d4e971 --- /dev/null +++ b/web/documentserver-example/php/src/common/PathNormalizePOSIXTests.php @@ -0,0 +1,34 @@ +normalize(); + $this->assertEquals($normalized->dirname(), 'srv/sub'); + $this->assertEquals($normalized->basename(), 'file.docx'); + $this->assertEquals($normalized->extension(), 'docx'); + $this->assertEquals($normalized->filename(), 'file'); + } +} diff --git a/web/documentserver-example/php/src/common/PathStringPOSIXTests.php b/web/documentserver-example/php/src/common/PathStringPOSIXTests.php new file mode 100644 index 000000000..d016203ea --- /dev/null +++ b/web/documentserver-example/php/src/common/PathStringPOSIXTests.php @@ -0,0 +1,174 @@ +string(); + $this->assertEquals($string, ''); + } + + public function testGeneratesWithAnEmptyRelative() + { + $path = new Path('.'); + $string = $path->string(); + $this->assertEquals($string, '.'); + } + + public function testGeneratesWithAnEmptyAbsolute() + { + $path = new Path('/'); + $string = $path->string(); + $this->assertEquals($string, '/'); + } + + public function testGeneratesWithARelative() + { + $path = new Path('srv'); + $string = $path->string(); + $this->assertEquals($string, 'srv'); + } + + public function testGeneratesWithARelativeContainingADirectory() + { + $path = new Path('srv/sub'); + $string = $path->string(); + $this->assertEquals($string, 'srv/sub'); + } + + public function testGeneratesWithARelativeContainingAFile() + { + $path = new Path('srv/file.json'); + $string = $path->string(); + $this->assertEquals($string, 'srv/file.json'); + } + + public function testGeneratesWithARelativeContainingADirectoryWithAFile() + { + $path = new Path('srv/sub/file.json'); + $string = $path->string(); + $this->assertEquals($string, 'srv/sub/file.json'); + } + + public function testGeneratesWithAnUnnormalizedRelative() + { + $path = new Path('srv////sub///file.json'); + $string = $path->string(); + $this->assertEquals($string, 'srv////sub///file.json'); + } + + public function testGeneratesWithAnNormalizedRelative() + { + $path = new Path('srv////sub///file.json'); + $normalized = $path->normalize(); + $string = $normalized->string(); + $this->assertEquals($string, 'srv/sub/file.json'); + } + + public function testGeneratesWithAnExplicitRelative() + { + $path = new Path('./srv'); + $string = $path->string(); + $this->assertEquals($string, './srv'); + } + + public function testGeneratesWithAnExplicitRelativeContainingADirectory() + { + $path = new Path('./srv/sub'); + $string = $path->string(); + $this->assertEquals($string, './srv/sub'); + } + + public function testGeneratesWithAnExplicitRelativeContainingAFile() + { + $path = new Path('./srv/file.json'); + $string = $path->string(); + $this->assertEquals($string, './srv/file.json'); + } + + public function testGeneratesWithAnExplicitRelativeContainingADirectoryWithAFile() + { + $path = new Path('./srv/sub/file.json'); + $string = $path->string(); + $this->assertEquals($string, './srv/sub/file.json'); + } + + public function testGeneratesWithAnExplicitUnnormalizedRelative() + { + $path = new Path('./srv////sub///file.json'); + $string = $path->string(); + $this->assertEquals($string, './srv////sub///file.json'); + } + + public function testGeneratesWithAnExplicitNormalizedRelative() + { + $path = new Path('./srv////sub///file.json'); + $normalized = $path->normalize(); + $string = $normalized->string(); + $this->assertEquals($string, 'srv/sub/file.json'); + } + + public function testGeneratesWithAnAbsolute() + { + $path = new Path('/srv'); + $string = $path->string(); + $this->assertEquals($string, '/srv'); + } + + public function testGeneratesWithAnAbsoluteContainingADirectory() + { + $path = new Path('/srv/sub'); + $string = $path->string(); + $this->assertEquals($string, '/srv/sub'); + } + + public function testGeneratesWithAnAbsoluteContainingAFile() + { + $path = new Path('/srv/file.json'); + $string = $path->string(); + $this->assertEquals($string, '/srv/file.json'); + } + + public function testGeneratesWithAnAbsoluteContainingADirectoryWithAFile() + { + $path = new Path('/srv/sub/file.json'); + $string = $path->string(); + $this->assertEquals($string, '/srv/sub/file.json'); + } + + public function testGeneratesWithAnUnnormalizedAbsolute() + { + $path = new Path('/srv////sub///file.json'); + $string = $path->string(); + $this->assertEquals($string, '/srv////sub///file.json'); + } + + public function testGeneratesWithAnNormalizedAbsolute() + { + $path = new Path('/srv////sub///file.json'); + $normalized = $path->normalize(); + $string = $normalized->string(); + $this->assertEquals($string, '/srv/sub/file.json'); + } +} diff --git a/web/documentserver-example/php/src/common/URL.php b/web/documentserver-example/php/src/common/URL.php new file mode 100644 index 000000000..2a65626b4 --- /dev/null +++ b/web/documentserver-example/php/src/common/URL.php @@ -0,0 +1,144 @@ +string = $url; + } + + public function string(): string + { + return $this->string; + } + + public function scheme(): ?string + { + $string = $this->string(); + return parse_url($string, PHP_URL_SCHEME) ?: null; + } + + public function host(): ?string + { + $string = $this->string(); + return parse_url($string, PHP_URL_HOST) ?: null; + } + + public function port(): ?int + { + $string = $this->string(); + return parse_url($string, PHP_URL_PORT) ?: null; + } + + public function user(): ?string + { + $string = $this->string(); + return parse_url($string, PHP_URL_USER) ?: null; + } + + public function pass(): ?string + { + $string = $this->string(); + return parse_url($string, PHP_URL_PASS) ?: null; + } + + public function path(): ?string + { + $string = $this->string(); + return parse_url($string, PHP_URL_PATH) ?: null; + } + + public function query(): ?string + { + $string = $this->string(); + return parse_url($string, PHP_URL_QUERY) ?: null; + } + + public function fragment(): ?string + { + $string = $this->string(); + return parse_url($string, PHP_URL_FRAGMENT) ?: null; + } + + public static function fromComponents( + ?string $scheme, + ?string $host, + ?int $port, + ?string $user, + ?string $pass, + ?string $path, + ?string $query, + ?string $fragment + ): URL { + $string = ''; + if ($scheme) { + $string .= "{$scheme}://"; + } + if ($user) { + $string .= $user; + } + if ($pass) { + $string .= ":{$pass}@"; + } + if ($host) { + $string .= $host; + } + if ($port) { + $string .= ":{$port}"; + } + if ($path) { + $string .= $path; + } + if ($query) { + $string .= "?{$query}"; + } + if ($fragment) { + $string .= "#{$fragment}"; + } + return new URL($string); + } + + public function joinPath(string $path): self + { + $currentPath = $this->path(); + $separator = + $currentPath && + ( + str_ends_with($currentPath, '/') || + str_starts_with($path, '/') + ) || + !$currentPath && str_starts_with($path, '/') + ? '' + : '/'; + $separated = "{$currentPath}{$separator}{$path}"; + return URL::fromComponents( + $this->scheme(), + $this->host(), + $this->port(), + $this->user(), + $this->pass(), + $separated, + $this->query(), + $this->fragment() + ); + } +} diff --git a/web/documentserver-example/php/src/common/URLFromComponentsTests.php b/web/documentserver-example/php/src/common/URLFromComponentsTests.php new file mode 100644 index 000000000..7f850c6f1 --- /dev/null +++ b/web/documentserver-example/php/src/common/URLFromComponentsTests.php @@ -0,0 +1,46 @@ +assertEquals('http', $url->scheme()); + $this->assertEquals('localhost', $url->host()); + $this->assertEquals(8080, $url->port()); + $this->assertEquals('user', $url->user()); + $this->assertEquals('password', $url->pass()); + $this->assertEquals('/path', $url->path()); + $this->assertEquals('q=value', $url->query()); + $this->assertEquals('fragment', $url->fragment()); + } +} diff --git a/web/documentserver-example/php/src/common/URLJoinPathTests.php b/web/documentserver-example/php/src/common/URLJoinPathTests.php new file mode 100644 index 000000000..b87c8746e --- /dev/null +++ b/web/documentserver-example/php/src/common/URLJoinPathTests.php @@ -0,0 +1,80 @@ +joinPath('first'); + $this->assertEquals('http', $joined->scheme()); + $this->assertEquals('localhost', $joined->host()); + $this->assertEquals(null, $joined->port()); + $this->assertEquals(null, $joined->user()); + $this->assertEquals(null, $joined->pass()); + $this->assertEquals('/first', $joined->path()); + $this->assertEquals(null, $joined->query()); + $this->assertEquals(null, $joined->fragment()); + } + + public function testJoinsARelative() + { + $url = new URL('http://localhost/first'); + $joined = $url->joinPath('second'); + $this->assertEquals('http', $joined->scheme()); + $this->assertEquals('localhost', $joined->host()); + $this->assertEquals(null, $joined->port()); + $this->assertEquals(null, $joined->user()); + $this->assertEquals(null, $joined->pass()); + $this->assertEquals('/first/second', $joined->path()); + $this->assertEquals(null, $joined->query()); + $this->assertEquals(null, $joined->fragment()); + } + + public function testJoinsAnAbsoluteToAnEmptyOne() + { + $url = new URL('http://localhost'); + $joined = $url->joinPath('/first'); + $this->assertEquals('http', $joined->scheme()); + $this->assertEquals('localhost', $joined->host()); + $this->assertEquals(null, $joined->port()); + $this->assertEquals(null, $joined->user()); + $this->assertEquals(null, $joined->pass()); + $this->assertEquals('/first', $joined->path()); + $this->assertEquals(null, $joined->query()); + $this->assertEquals(null, $joined->fragment()); + } + + public function testJoinsAnAbsolute() + { + $url = new URL('http://localhost/first'); + $joined = $url->joinPath('/second'); + $this->assertEquals('http', $joined->scheme()); + $this->assertEquals('localhost', $joined->host()); + $this->assertEquals(null, $joined->port()); + $this->assertEquals(null, $joined->user()); + $this->assertEquals(null, $joined->pass()); + $this->assertEquals('/first/second', $joined->path()); + $this->assertEquals(null, $joined->query()); + $this->assertEquals(null, $joined->fragment()); + } +} diff --git a/web/documentserver-example/php/src/common/URLStringTests.php b/web/documentserver-example/php/src/common/URLStringTests.php new file mode 100644 index 000000000..2b51107e3 --- /dev/null +++ b/web/documentserver-example/php/src/common/URLStringTests.php @@ -0,0 +1,34 @@ +string(); + $this->assertEquals( + 'http://user:password@localhost:8080/path?q=value#fragment', + $string + ); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManager.php b/web/documentserver-example/php/src/configuration/ConfigurationManager.php new file mode 100644 index 000000000..400060f2e --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManager.php @@ -0,0 +1,203 @@ +documentServerPublicURL(); + } + return new URL($url); + } + + public function documentServerAPIURL(): URL + { + $serverURL = $this->documentServerPublicURL(); + $path = getenv('DOCUMENT_SERVER_API_PATH') + ?: 'web-apps/apps/api/documents/api.js'; + return $serverURL->joinPath($path); + } + + public function documentServerPreloaderURL(): URL + { + $serverURL = $this->documentServerPublicURL(); + $path = getenv('DOCUMENT_SERVER_PRELOADER_PATH') + ?: 'web-apps/apps/api/documents/cache-scripts.html'; + return $serverURL->joinPath($path); + } + + public function documentServerCommandURL(): URL + { + $serverURL = $this->documentServerPrivateURL(); + $path = getenv('DOCUMENT_SERVER_COMMAND_PATH') + ?: 'coauthoring/CommandService.ashx'; + return $serverURL->joinPath($path); + } + + public function documentServerConverterURL(): URL + { + $serverURL = $this->documentServerPrivateURL(); + $path = getenv('DOCUMENT_SERVER_CONVERTER_PATH') + ?: 'ConvertService.ashx'; + return $serverURL->joinPath($path); + } + + public function jwtSecret(): string + { + return getenv('JWT_SECRET') ?: ''; + } + + public function jwtHeader(): string + { + return getenv('JWT_HEADER') ?: 'Authorization'; + } + + public function jwtUseForRequest(): bool + { + $use = getenv('JWT_USE_FOR_REQUEST'); + if (!$use) { + return true; + } + return filter_var($use, FILTER_VALIDATE_BOOLEAN); + } + + public function sslVerifyPeerModeEnabled(): bool + { + $enabled = getenv('SSL_VERIFY_PEER_MODE_ENABLED'); + if (!$enabled) { + return false; + } + return filter_var($enabled, FILTER_VALIDATE_BOOLEAN); + } + + public function storagePath(): Path + { + $storagePath = getenv('STORAGE_PATH') ?: 'storage'; + $storageDirectory = new Path($storagePath); + if ($storageDirectory->absolute()) { + return $storageDirectory; + } + + $storageStringDirectory = $storageDirectory->string(); + $currentDirectory = new Path(__DIR__); + $directory = $currentDirectory + ->joinPath('..') + ->joinPath('..') + ->joinPath($storageStringDirectory); + return $directory->normalize(); + } + + public function singleUser(): bool + { + $single = getenv('SINGLE_USER'); + if (!$single) { + return false; + } + return filter_var($single, FILTER_VALIDATE_BOOLEAN); + } + + public function maximumFileSize(): int + { + $size = getenv('MAXIMUM_FILE_SIZE'); + if (!$size) { + return 5 * 1024 * 1024; + } + return intval($size); + } + + public function conversionTimeout(): int + { + $timeout = getenv('CONVERSION_TIMEOUT'); + if (!$timeout) { + return 120 * 1000; + } + return intval($timeout); + } + + /** + * @return string[] + */ + public function languages(): array + { + 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' + ]; + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerConversionTimeoutTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerConversionTimeoutTests.php new file mode 100644 index 000000000..d6edf03cb --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerConversionTimeoutTests.php @@ -0,0 +1,54 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $timeout = $configManager->conversionTimeout(); + $this->assertEquals(120_000, $timeout); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('CONVERSION_TIMEOUT=10'); + $configManager = new ConfigurationManager(); + $timeout = $configManager->conversionTimeout(); + $this->assertEquals(10, $timeout); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerAPIURLTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerAPIURLTests.php new file mode 100644 index 000000000..20fbd5751 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerAPIURLTests.php @@ -0,0 +1,60 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerAPIURL(); + $this->assertEquals( + 'http://document-server/web-apps/apps/api/documents/api.js', + $url->string() + ); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('DOCUMENT_SERVER_API_PATH=/api'); + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerAPIURL(); + $this->assertEquals( + 'http://document-server/api', + $url->string() + ); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerCommandURLTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerCommandURLTests.php new file mode 100644 index 000000000..3a4922b7c --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerCommandURLTests.php @@ -0,0 +1,60 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerCommandURL(); + $this->assertEquals( + 'http://document-server/coauthoring/CommandService.ashx', + $url->string() + ); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('DOCUMENT_SERVER_COMMAND_PATH=/command'); + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerCommandURL(); + $this->assertEquals( + 'http://document-server/command', + $url->string() + ); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerConverterURLTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerConverterURLTests.php new file mode 100644 index 000000000..6cfe7ac40 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerConverterURLTests.php @@ -0,0 +1,60 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerConverterURL(); + $this->assertEquals( + 'http://document-server/ConvertService.ashx', + $url->string() + ); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('DOCUMENT_SERVER_CONVERTER_PATH=/converter'); + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerConverterURL(); + $this->assertEquals( + 'http://document-server/converter', + $url->string() + ); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerPreloaderURLTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerPreloaderURLTests.php new file mode 100644 index 000000000..258214132 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerPreloaderURLTests.php @@ -0,0 +1,60 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerPreloaderURL(); + $this->assertEquals( + 'http://document-server/web-apps/apps/api/documents/cache-scripts.html', + $url->string() + ); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('DOCUMENT_SERVER_PRELOADER_PATH=/preloader'); + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerPreloaderURL(); + $this->assertEquals( + 'http://document-server/preloader', + $url->string() + ); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerPrivateURLTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerPrivateURLTests.php new file mode 100644 index 000000000..318cb8a0b --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerPrivateURLTests.php @@ -0,0 +1,54 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerPrivateURL(); + $this->assertEquals('http://document-server', $url->string()); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('DOCUMENT_SERVER_PRIVATE_URL=http://localhost'); + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerPrivateURL(); + $this->assertEquals('http://localhost', $url->string()); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerPublicURLTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerPublicURLTests.php new file mode 100644 index 000000000..d94095f25 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerDocumentServerPublicURLTests.php @@ -0,0 +1,54 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerPublicURL(); + $this->assertEquals('http://document-server', $url->string()); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('DOCUMENT_SERVER_PUBLIC_URL=http://localhost'); + $configManager = new ConfigurationManager(); + $url = $configManager->documentServerPublicURL(); + $this->assertEquals('http://localhost', $url->string()); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerExampleURLTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerExampleURLTests.php new file mode 100644 index 000000000..bd3c762e1 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerExampleURLTests.php @@ -0,0 +1,54 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $url = $configManager->exampleURL(); + $this->assertNull($url); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('EXAMPLE_URL=http://localhost'); + $configManager = new ConfigurationManager(); + $url = $configManager->exampleURL(); + $this->assertEquals('http://localhost', $url->string()); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerJWTHeaderTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerJWTHeaderTests.php new file mode 100644 index 000000000..fe9cb82d8 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerJWTHeaderTests.php @@ -0,0 +1,54 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $header = $configManager->jwtHeader(); + $this->assertEquals('Authorization', $header); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('JWT_HEADER=Proxy-Authorization'); + $configManager = new ConfigurationManager(); + $header = $configManager->jwtHeader(); + $this->assertEquals('Proxy-Authorization', $header); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerJWTSecretTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerJWTSecretTests.php new file mode 100644 index 000000000..1a972783c --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerJWTSecretTests.php @@ -0,0 +1,54 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $secret = $configManager->jwtSecret(); + $this->assertEquals('', $secret); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('JWT_SECRET=your-256-bit-secret'); + $configManager = new ConfigurationManager(); + $secret = $configManager->jwtSecret(); + $this->assertEquals('your-256-bit-secret', $secret); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerJWTUseForRequest.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerJWTUseForRequest.php new file mode 100644 index 000000000..745c31e1c --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerJWTUseForRequest.php @@ -0,0 +1,54 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $use = $configManager->jwtUseForRequest(); + $this->assertTrue($use); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('JWT_USE_FOR_REQUEST=false'); + $configManager = new ConfigurationManager(); + $use = $configManager->jwtUseForRequest(); + $this->assertFalse($use); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerMaximumFileSizeTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerMaximumFileSizeTests.php new file mode 100644 index 000000000..bf0049f02 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerMaximumFileSizeTests.php @@ -0,0 +1,54 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $size = $configManager->maximumFileSize(); + $this->assertEquals(5_242_880, $size); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('MAXIMUM_FILE_SIZE=10'); + $configManager = new ConfigurationManager(); + $size = $configManager->maximumFileSize(); + $this->assertEquals(10, $size); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerSSLTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerSSLTests.php new file mode 100644 index 000000000..ef725c8b3 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerSSLTests.php @@ -0,0 +1,54 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $enabled = $configManager->sslVerifyPeerModeEnabled(); + $this->assertFalse($enabled); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('SSL_VERIFY_PEER_MODE_ENABLED=true'); + $configManager = new ConfigurationManager(); + $enabled = $configManager->sslVerifyPeerModeEnabled(); + $this->assertTrue($enabled); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerSingleUserTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerSingleUserTests.php new file mode 100644 index 000000000..998242b63 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerSingleUserTests.php @@ -0,0 +1,54 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $single = $configManager->singleUser(); + $this->assertFalse($single); + } + + public function testAssignsAValueFromTheEnvironment() + { + putenv('SINGLE_USER=true'); + $configManager = new ConfigurationManager(); + $single = $configManager->singleUser(); + $this->assertTrue($single); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerStoragePathTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerStoragePathTests.php new file mode 100644 index 000000000..657958e65 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerStoragePathTests.php @@ -0,0 +1,64 @@ +env = getenv(); + parent::__construct($name); + } + + protected function setUp(): void + { + foreach ($this->env as $key => $value) { + putenv("{$key}={$value}"); + } + } + + public function testAssignsADefaultValue() + { + $configManager = new ConfigurationManager(); + $path = $configManager->storagePath(); + $this->assertTrue($path->absolute()); + $this->assertEquals($path->basename(), 'storage'); + } + + public function testAssignsARelativePathFromTheEnvironment() + { + putenv('STORAGE_PATH=directory'); + $configManager = new ConfigurationManager(); + $path = $configManager->storagePath(); + $this->assertTrue($path->absolute()); + $this->assertEquals($path->basename(), 'directory'); + } + + public function testAssignsAnAbsolutePathFromTheEnvironment() + { + putenv('STORAGE_PATH=/directory'); + $configManager = new ConfigurationManager(); + $path = $configManager->storagePath(); + $this->assertEquals($path->string(), '/directory'); + } +} diff --git a/web/documentserver-example/php/src/configuration/ConfigurationManagerTests.php b/web/documentserver-example/php/src/configuration/ConfigurationManagerTests.php new file mode 100644 index 000000000..730acfb27 --- /dev/null +++ b/web/documentserver-example/php/src/configuration/ConfigurationManagerTests.php @@ -0,0 +1,30 @@ +assertEquals('1.6.0', $configManager->version); + } +} diff --git a/web/documentserver-example/php/src/format/Format.php b/web/documentserver-example/php/src/format/Format.php new file mode 100644 index 000000000..d993588a7 --- /dev/null +++ b/web/documentserver-example/php/src/format/Format.php @@ -0,0 +1,51 @@ +name; + } +} diff --git a/web/documentserver-example/php/src/format/FormatManager.php b/web/documentserver-example/php/src/format/FormatManager.php new file mode 100644 index 000000000..fcbf8dc51 --- /dev/null +++ b/web/documentserver-example/php/src/format/FormatManager.php @@ -0,0 +1,202 @@ +serializer = new Serializer( + [ + new ArrayDenormalizer(), + new ObjectNormalizer() + ], + [ + new JsonEncoder() + ] + ); + } + + /** + * @return string[] + */ + public function fillableExtensions(): array + { + $formats = $this->fillable(); + $extensions = []; + foreach ($formats as $format) { + $extensions[] = $format->extension(); + } + return $extensions; + } + + /** + * @return Format[] + */ + public function fillable(): array + { + $formats = $this->all(); + $filtered = []; + foreach ($formats as $format) { + if (in_array('fill', $format->actions)) { + $filtered[] = $format; + } + } + return $filtered; + } + + /** + * @return string[] + */ + public function viewableExtensions(): array + { + $formats = $this->viewable(); + $extensions = []; + foreach ($formats as $format) { + $extensions[] = $format->extension(); + } + return $extensions; + } + + /** + * @return Format[] + */ + public function viewable(): array + { + $formats = $this->all(); + $filtered = []; + foreach ($formats as $format) { + if (in_array('view', $format->actions)) { + $filtered[] = $format; + } + } + return $filtered; + } + + /** + * @return string[] + */ + public function editableExtensions(): array + { + $formats = $this->editable(); + $extensions = []; + foreach ($formats as $format) { + $extensions[] = $format->extension(); + } + return $extensions; + } + + /** + * @return Format[] + */ + public function editable(): array + { + $formats = $this->all(); + $filtered = []; + foreach ($formats as $format) { + if (in_array('edit', $format->actions) or + in_array('lossy-edit', $format->actions) + ) { + $filtered[] = $format; + } + } + return $filtered; + } + + /** + * @return string[] + */ + public function convertibleExtensions(): array + { + $formats = $this->convertible(); + $extensions = []; + foreach ($formats as $format) { + $extensions[] = $format->extension(); + } + return $extensions; + } + + /** + * @return Format[] + */ + public function convertible(): array + { + $formats = $this->all(); + $filtered = []; + foreach ($formats as $format) { + if ($format->type === 'cell' and in_array('xlsx', $format->convert) or + $format->type === 'slide' and in_array('pptx', $format->convert) or + $format->type === 'word' and in_array('docx', $format->convert) + ) { + $filtered[] = $format; + } + } + return $filtered; + } + + /** + * @return string[] + */ + public function allExtensions(): array + { + $formats = $this->all(); + $extensions = []; + foreach ($formats as $format) { + $extensions[] = $format->extension(); + } + return $extensions; + } + + /** + * @return Format[] + */ + public function all(): array + { + $file = $this->file(); + $contents = $file->contents(); + return $this->serializer->deserialize( + $contents, + Format::class . '[]', + 'json' + ); + } + + private function file(): Path + { + $directory = $this->directory(); + return $directory->joinPath('onlyoffice-docs-formats.json'); + } + + private function directory(): Path + { + $currentDirectory = new Path(__DIR__); + return $currentDirectory + ->joinPath('..') + ->joinPath('..') + ->joinPath('assets') + ->joinPath('document-formats'); + } +} diff --git a/web/documentserver-example/php/src/format/FormatManagerAllTests.php b/web/documentserver-example/php/src/format/FormatManagerAllTests.php new file mode 100644 index 000000000..4fecaff72 --- /dev/null +++ b/web/documentserver-example/php/src/format/FormatManagerAllTests.php @@ -0,0 +1,31 @@ +all(); + $this->assertNotEmpty($formats); + } +} diff --git a/web/documentserver-example/php/src/format/FormatManagerConvertibleTests.php b/web/documentserver-example/php/src/format/FormatManagerConvertibleTests.php new file mode 100644 index 000000000..a1719986a --- /dev/null +++ b/web/documentserver-example/php/src/format/FormatManagerConvertibleTests.php @@ -0,0 +1,31 @@ +convertible(); + $this->assertNotEmpty($formats); + } +} diff --git a/web/documentserver-example/php/src/format/FormatManagerEditableTests.php b/web/documentserver-example/php/src/format/FormatManagerEditableTests.php new file mode 100644 index 000000000..41af83314 --- /dev/null +++ b/web/documentserver-example/php/src/format/FormatManagerEditableTests.php @@ -0,0 +1,31 @@ +editable(); + $this->assertNotEmpty($formats); + } +} diff --git a/web/documentserver-example/php/src/format/FormatManagerFillableTests.php b/web/documentserver-example/php/src/format/FormatManagerFillableTests.php new file mode 100644 index 000000000..6c27bfd38 --- /dev/null +++ b/web/documentserver-example/php/src/format/FormatManagerFillableTests.php @@ -0,0 +1,31 @@ +editable(); + $this->assertNotEmpty($formats); + } +} diff --git a/web/documentserver-example/php/src/format/FormatManagerViewableTests.php b/web/documentserver-example/php/src/format/FormatManagerViewableTests.php new file mode 100644 index 000000000..b064abb73 --- /dev/null +++ b/web/documentserver-example/php/src/format/FormatManagerViewableTests.php @@ -0,0 +1,31 @@ +viewable(); + $this->assertNotEmpty($formats); + } +} diff --git a/web/documentserver-example/php/src/format/FormatTests.php b/web/documentserver-example/php/src/format/FormatTests.php new file mode 100644 index 000000000..9a91dc98a --- /dev/null +++ b/web/documentserver-example/php/src/format/FormatTests.php @@ -0,0 +1,52 @@ +deserialize($this->json, Format::class, 'json'); + $this->assertEquals('djvu', $format->extension()); + } +} diff --git a/web/documentserver-example/php/functions.php b/web/documentserver-example/php/src/functions.php similarity index 62% rename from web/documentserver-example/php/functions.php rename to web/documentserver-example/php/src/functions.php index 13b6d2b69..0ca7e08f4 100644 --- a/web/documentserver-example/php/functions.php +++ b/web/documentserver-example/php/src/functions.php @@ -15,13 +15,13 @@ * limitations under the License. */ -namespace OnlineEditorsExamplePhp; +namespace Example; use Exception; -use OnlineEditorsExamplePhp\Helpers\ConfigManager; -use OnlineEditorsExamplePhp\Helpers\ExampleUsers; -use OnlineEditorsExamplePhp\Helpers\JwtManager; -use OnlineEditorsExamplePhp\Helpers\Users; +use Example\Configuration\ConfigurationManager; +use Example\Format\FormatManager; +use Example\Helpers\JwtManager; +use Example\Helpers\Users; /** * Put log files into the log folder @@ -92,10 +92,10 @@ function getClientIp() */ function serverPath($forDocumentServer = null) { - $configManager = new ConfigManager(); - return $forDocumentServer && $configManager->getConfig("storagePath") != null - && $configManager->getConfig("exampleUrl") != "" - ? $configManager->getConfig("exampleUrl") + $configManager = new ConfigurationManager(); + $exampleURL = $configManager->exampleURL(); + return $forDocumentServer && $exampleURL + ? $exampleURL->string() : (getScheme() . '://' . $_SERVER['HTTP_HOST']); } @@ -108,11 +108,8 @@ function serverPath($forDocumentServer = null) */ function getCurUserHostAddress($userAddress = null) { - $configManager = new ConfigManager(); - if ($configManager->getConfig("alone")) { - if (empty($configManager->getConfig("storagePath"))) { - return "Storage"; - } + $configManager = new ConfigurationManager(); + if ($configManager->singleUser()) { return ""; } if (is_null($userAddress)) { @@ -130,18 +127,23 @@ function getCurUserHostAddress($userAddress = null) */ function getInternalExtension($filename) { - $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 + $formatManager = new FormatManager(); + $ext = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + + foreach ($formatManager->all() 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 +156,24 @@ function getInternalExtension($filename) */ function getTemplateImageUrl($filename) { - $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 + $formatManager = new FormatManager(); + $ext = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + $path = serverPath(true) . "/assets/images/"; + + foreach ($formatManager->all() 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 +186,15 @@ function getTemplateImageUrl($filename) */ function getDocumentType($filename) { - $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 + $formatManager = new FormatManager(); + $ext = mb_strtolower(pathinfo($filename, PATHINFO_EXTENSION)); + + foreach ($formatManager->all() as $format) { + if ($format->name === $ext) { + return $format->type; + } + } + return "word"; } @@ -214,39 +218,21 @@ function getScheme() */ function getStoragePath($fileName, $userAddress = null) { - $configManager = new ConfigManager(); - $storagePath = trim( - str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $configManager->getConfig("storagePath")), - DIRECTORY_SEPARATOR - ); - if (!empty($storagePath) && !file_exists($storagePath) && !is_dir($storagePath)) { - mkdir($storagePath); - } + $configManager = new ConfigurationManager(); + $storagePath = $configManager->storagePath(); - if (realpath($storagePath) === $storagePath) { - $directory = $storagePath; - } else { - $directory = __DIR__ . DIRECTORY_SEPARATOR . $storagePath; + if (!$storagePath->exists()) { + $storagePath->makeDirectory(); } - if ($storagePath != "") { - $directory = $directory . DIRECTORY_SEPARATOR; - - // if the file directory doesn't exist, make it - if (!file_exists($directory) && !is_dir($directory)) { - mkdir($directory); - } - } - - if (realpath($storagePath) !== $storagePath) { - $directory = $directory . getCurUserHostAddress($userAddress) . DIRECTORY_SEPARATOR; + $userIP = getCurUserHostAddress($userAddress); + $userDirectory = $storagePath->joinPath($userIP); + if (!$userDirectory->exists()) { + $userDirectory->makeDirectory(); } - if (!file_exists($directory) && !is_dir($directory)) { - mkdir($directory); - } - sendlog("getStoragePath result: " . $directory . basename($fileName), "common.log"); - return realpath($storagePath) === $storagePath ? $directory . $fileName : $directory . basename($fileName); + $file = $userDirectory->joinPath($fileName); + return $file->string(); } /** @@ -260,43 +246,30 @@ function getStoragePath($fileName, $userAddress = null) */ function getForcesavePath($fileName, $userAddress, $create) { - $configManager = new ConfigManager(); - $storagePath = trim( - str_replace( - ['/', '\\'], - DIRECTORY_SEPARATOR, - $configManager->getConfig("storagePath") - ), - DIRECTORY_SEPARATOR - ); + $configManager = new ConfigurationManager(); + $storagePath = $configManager->storagePath(); - // create the directory to this file version - if (realpath($storagePath) === $storagePath) { - $directory = $storagePath . DIRECTORY_SEPARATOR; - } else { - $directory = __DIR__ . DIRECTORY_SEPARATOR . $storagePath . getCurUserHostAddress($userAddress) . - DIRECTORY_SEPARATOR; - } - - if (!is_dir($directory)) { - return ""; + $userIP = getCurUserHostAddress($userAddress); + $userDirectory = $storagePath->joinPath($userIP); + if (!$userDirectory->exists()) { + return ''; } - // create the directory to the history of this file version - $directory = $directory . $fileName . "-hist" . DIRECTORY_SEPARATOR; - if (!$create && !is_dir($directory)) { - return ""; + $historyDirectory = $userDirectory->joinPath("{$fileName}-hist"); + if (!$historyDirectory->exists()) { + if ($create) { + $historyDirectory->makeDirectory(); + } else { + return ''; + } } - if (!file_exists($directory) && !is_dir($directory)) { - mkdir($directory); - } - $directory = $directory . $fileName; - if (!$create && !file_exists($directory)) { - return ""; + $file = $historyDirectory->joinPath($fileName); + if (!$file->exists() && !$create) { + return ''; } - return $directory; + return $file->string(); } /** @@ -361,52 +334,35 @@ function getFileVersion($histDir) */ function getStoredFiles() { - $configManager = new ConfigManager(); - $storagePath = trim(str_replace( - ['/', '\\'], - DIRECTORY_SEPARATOR, - $configManager->getConfig("storagePath") - ), DIRECTORY_SEPARATOR); - if (!empty($storagePath) && !file_exists($storagePath) && !is_dir($storagePath)) { - mkdir($storagePath); - } - - if (realpath($storagePath) === $storagePath) { - $directory = $storagePath; - } else { - $directory = __DIR__ . DIRECTORY_SEPARATOR . $storagePath; - } + $formatManager = new FormatManager(); - // get the storage path and check if it exists - $result = []; - if ($storagePath != "") { - $directory = $directory . DIRECTORY_SEPARATOR; + $configManager = new ConfigurationManager(); + $storagePath = $configManager->storagePath(); - if (!file_exists($directory) && !is_dir($directory)) { - return $result; - } + if (!$storagePath->exists()) { + $storagePath->makeDirectory(); } - if (realpath($storagePath) !== $storagePath) { - $directory = $directory . getCurUserHostAddress() . DIRECTORY_SEPARATOR; + $userIP = getCurUserHostAddress(); + $userDirectory = $storagePath->joinPath($userIP); + if (!$userDirectory->exists()) { + $userDirectory->makeDirectory(); } - if (!file_exists($directory) && !is_dir($directory)) { - return $result; - } + $directory = $userDirectory->string(); $cdir = scandir($directory); // get all the files and folders from the directory $result = []; 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, $formatManager->editableExtensions()), + "isFillFormDoc" => in_array($ext, $formatManager->fillableExtensions()), ]; } } @@ -424,21 +380,8 @@ function getStoredFiles() */ function getVirtualPath($forDocumentServer) { - $configManager = new ConfigManager(); - $storagePath = trim(str_replace( - ['/', '\\'], - '/', - $configManager->getConfig("storagePath") - ), '/'); - $storagePath = $storagePath != "" ? $storagePath . '/' : ""; - - if (realpath($storagePath) === $storagePath) { - $virtPath = serverPath($forDocumentServer) . '/' . $storagePath . '/'; - } else { - $virtPath = serverPath($forDocumentServer) . '/' . $storagePath . getCurUserHostAddress() . '/'; - } - sendlog("getVirtualPath virtPath: " . $virtPath, "common.log"); - return $virtPath; + $serverURL = serverPath($forDocumentServer); + return $serverURL . '/' . getCurUserHostAddress() . '/'; } /** @@ -469,14 +412,14 @@ function createMeta($fileName, $uid, $uname, $userAddress = null) /** * Get the file url * - * @param string $file_name + * @param string $fileName * @param string $forDocumentServer * * @return string */ -function fileUri($file_name, $forDocumentServer = null) +function fileUri($fileName, $forDocumentServer = null) { - $uri = getVirtualPath($forDocumentServer) . rawurlencode($file_name); // add encoded file name to the virtual path + $uri = getVirtualPath($forDocumentServer) . rawurlencode($fileName); // add encoded file name to the virtual path return $uri; } @@ -521,22 +464,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 * @@ -547,10 +474,10 @@ function getFileExts() */ function GetCorrectName($fileName, $userAddress = null) { - $path_parts = pathinfo($fileName); + $pathParts = pathinfo($fileName); - $ext = mb_strtolower($path_parts['extension']); - $name = $path_parts['basename']; + $ext = mb_strtolower($pathParts['extension']); + $name = $pathParts['basename']; // get file name from the basename without extension $baseNameWithoutExt = mb_substr($name, 0, mb_strlen($name) - mb_strlen($ext) - 1); $name = $baseNameWithoutExt . "." . $ext; @@ -589,22 +516,23 @@ function getDocEditorKey($fileName) */ function doUpload($fileUri) { - $_fileName = GetCorrectName($fileUri); + $formatManager = new FormatManager(); + $fileName = GetCorrectName($fileUri); // 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, $formatManager->allExtensions())) { throw new Exception("File type is not supported"); } // check if the file copy operation is successful - if (!@copy($fileUri, getStoragePath($_fileName))) { + if (!@copy($fileUri, getStoragePath($fileName))) { $errors = error_get_last(); $err = "Copy file error: " . $errors['type'] . "
\n" . $errors['message']; throw new Exception($err); } - return $_fileName; + return $fileName; } /** @@ -660,16 +588,16 @@ function processConvServResponceError($errorCode) /** * Translation key to a supported form. * - * @param string $expected_key Expected key + * @param string $expectedKey Expected key * * @return string key */ -function generateRevisionId($expected_key) +function generateRevisionId($expectedKey) { - if (mb_strlen($expected_key) > 20) { - $expected_key = crc32($expected_key); + if (mb_strlen($expectedKey) > 20) { + $expectedKey = crc32($expectedKey); } // if the expected key length is greater than 20, calculate the crc32 for it - $key = preg_replace("[^0-9-.a-zA-Z_=]", "_", $expected_key); + $key = preg_replace("[^0-9-.a-zA-Z_=]", "_", $expectedKey); $key = mb_substr($key, 0, min([mb_strlen($key), 20])); // the resulting key length is 20 or less return $key; } @@ -677,62 +605,61 @@ function generateRevisionId($expected_key) /** * Request for conversion to a service. * - * @param string $document_uri Uri for the document to convert - * @param string $from_extension Document extension - * @param string $to_extension Extension to which to convert - * @param string $document_revision_id Key for caching on service - * @param bool $is_async Perform conversions asynchronously - * @param string $filePass - * @param string $lang + * @param string $documentURL Uri for the document to convert + * @param string $fromExtension Document extension + * @param string $toExtension Extension to which to convert + * @param string $documentRevisionID Key for caching on service + * @param bool $async Perform conversions asynchronously + * @param string $filePass + * @param string $lang * * @return string request result of conversion */ function sendRequestToConvertService( - $document_uri, - $from_extension, - $to_extension, - $document_revision_id, - $is_async, + $documentURL, + $fromExtension, + $toExtension, + $documentRevisionID, + $async, $filePass, $lang ) { - if (empty($from_extension)) { - $path_parts = pathinfo($document_uri); - $from_extension = mb_strtolower($path_parts['extension']); + $configManager = new ConfigurationManager(); + + if (empty($fromExtension)) { + $pathParts = pathinfo($documentURL); + $fromExtension = mb_strtolower($pathParts['extension']); } // if title is undefined, then replace it with a random guid - $title = basename($document_uri); + $title = basename($documentURL); if (empty($title)) { $title = guid(); } - if (empty($document_revision_id)) { - $document_revision_id = $document_uri; + if (empty($documentRevisionID)) { + $documentRevisionID = $documentURL; } // generate document token - $document_revision_id = generateRevisionId($document_revision_id); + $documentRevisionID = generateRevisionId($documentRevisionID); - $configManager = new ConfigManager(); - $urlToConverter = $configManager->getConfig("docServSiteUrl"). - $configManager->getConfig("docServConverterUrl"); + $urlToConverter = $configManager->documentServerConverterURL()->string(); $arr = [ - "async" => $is_async, - "url" => $document_uri, - "outputtype" => trim($to_extension, '.'), - "filetype" => trim($from_extension, '.'), + "async" => $async, + "url" => $documentURL, + "outputtype" => trim($toExtension, '.'), + "filetype" => trim($fromExtension, '.'), "title" => $title, - "key" => $document_revision_id, + "key" => $documentRevisionID, "password" => $filePass, "region" => $lang, ]; // add header token $headerToken = ""; - $jwtHeader = $configManager->getConfig("docServJwtHeader") == - "" ? "Authorization" : $configManager->getConfig("docServJwtHeader"); + $jwtHeader = $configManager->jwtHeader(); $jwtManager = new JwtManager(); if ($jwtManager->isJwtEnabled() && $jwtManager->tokenUseForRequest()) { @@ -745,7 +672,7 @@ function sendRequestToConvertService( // request parameters $opts = ['http' => [ 'method' => 'POST', - 'timeout' => $configManager->getConfig("docServTimeout"), + 'timeout' => $configManager->conversionTimeout(), 'header' => "Content-type: application/json\r\n" . "Accept: application/json\r\n" . (empty($headerToken) ? "" : $jwtHeader.": Bearer $headerToken\r\n"), @@ -754,15 +681,15 @@ function sendRequestToConvertService( ]; if (mb_substr($urlToConverter, 0, mb_strlen("https")) === "https") { - if ($configManager->getConfig("docServVerifyPeerOff") === true) { + if ($configManager->sslVerifyPeerModeEnabled()) { $opts['ssl'] = ['verify_peer' => false, 'verify_peer_name' => false]; } } $context = stream_context_create($opts); - $response_data = file_get_contents($urlToConverter, false, $context); + $responseData = file_get_contents($urlToConverter, false, $context); - return $response_data; + return $responseData; } /** @@ -773,12 +700,12 @@ function sendRequestToConvertService( * getConvertedData("http://helpcenter.onlyoffice.com/content/GettingStarted.pdf", * ".pdf", ".docx", "http://helpcenter.onlyoffice.com/content/GettingStarted.pdf", false, out convertedDocumentUri); * - * @param string $document_uri Uri for the document to convert - * @param string $from_extension Document extension - * @param string $to_extension Extension to which to convert - * @param string $document_revision_id Key for caching on service - * @param bool $is_async Perform conversions asynchronously - * @param string $converted_document_uri Uri to the converted document + * @param string $documentURL Uri for the document to convert + * @param string $fromExtension Document extension + * @param string $toExtension Extension to which to convert + * @param string $documentRevisionID Key for caching on service + * @param bool $async Perform conversions asynchronously + * @param string $convertedDocumentURL Uri to the converted document * @param string $filePass File pass * @param string $lang Language * @@ -787,22 +714,22 @@ function sendRequestToConvertService( * @return array percentage of completion of conversion and fileType from Convert service */ function getConvertedData( - $document_uri, - $from_extension, - $to_extension, - $document_revision_id, - $is_async, - &$converted_document_uri, + $documentURL, + $fromExtension, + $toExtension, + $documentRevisionID, + $async, + &$convertedDocumentURL, $filePass, $lang ) { - $converted_document_uri = ""; + $convertedDocumentURL = ""; $responceFromConvertService = sendRequestToConvertService( - $document_uri, - $from_extension, - $to_extension, - $document_revision_id, - $is_async, + $documentURL, + $fromExtension, + $toExtension, + $documentRevisionID, + $async, $filePass, $lang ); @@ -821,7 +748,7 @@ function getConvertedData( // if the conversion is completed successfully if ($isEndConvert != null && $isEndConvert == true) { // then get the file url - $converted_document_uri = $json["fileUrl"]; + $convertedDocumentURL = $json["fileUrl"]; $fileType = $json["fileType"]; $percent = 100; } elseif ($percent >= 100) { // otherwise, get the percentage of conversion completion @@ -831,60 +758,6 @@ function getConvertedData( return ["percent" => $percent, "fileType" => $fileType]; } -/** - * Processing document received from the editing service. - * - * @param Response $document_response The result from editing service - * @param string $response_uri Uri to the converted document - * - * @throws Exception if an error occurs - * - * @return int percentage of completion of conversion - */ -function getResponseUri($document_response, &$response_uri) -{ - $response_uri = ""; - $resultPercent = 0; - - if (!$document_response) { - $errs = "Invalid answer format"; - } - - // if an error occurs, then display an error message - $errorElement = $document_response->Error; - if ($errorElement != null && $errorElement != "") { - processConvServResponceError($document_response->Error); - } - - $endConvert = $document_response->EndConvert; - if ($endConvert != null && $endConvert == "") { - throw new Exception("Invalid answer format"); - } - - // if the conversion is completed successfully - if ($endConvert != null && mb_strtolower($endConvert) == true) { - $fileUrl = $document_response->FileUrl; - if ($fileUrl == null || $fileUrl == "") { - throw new Exception("Invalid answer format"); - } - - // get the response file url - $response_uri = $fileUrl; - $resultPercent = 100; - } else { // otherwise, get the percentage of conversion completion - $percent = $document_response->Percent; - - if ($percent != null && $percent != "") { - $resultPercent = $percent; - } - if ($resultPercent >= 100) { - $resultPercent = 99; - } - } - - return $resultPercent; -} - /** * Get demo file name by the extension * @@ -897,7 +770,11 @@ function tryGetDefaultByType($createExt, $user) { $sample = isset($_GET["sample"]) && $_GET["sample"]; $demoName = ($sample ? "sample." : "new.") . $createExt; - $demoPath = "assets" . DIRECTORY_SEPARATOR . ($sample ? "sample" : "new") . DIRECTORY_SEPARATOR; + $demoPath = + '..' . DIRECTORY_SEPARATOR . + "assets" . DIRECTORY_SEPARATOR . + "document-templates" . DIRECTORY_SEPARATOR . + ($sample ? "sample" : "new") . DIRECTORY_SEPARATOR; $demoFilename = GetCorrectName($demoName); if (!@copy(dirname(__FILE__) . DIRECTORY_SEPARATOR . $demoPath . $demoName, getStoragePath($demoFilename))) { @@ -921,9 +798,8 @@ function tryGetDefaultByType($createExt, $user) function getCallbackUrl($fileName) { return serverPath(true) . '/' - . "webeditor-ajax.php" - . "?type=track" - . "&fileName=" . urlencode($fileName) + . "track" + . "?fileName=" . urlencode($fileName) . "&userAddress=" . getClientIp(); } @@ -940,10 +816,9 @@ function getCreateUrl($fileName, $uid, $type) { $ext = trim(getInternalExtension($fileName), '.'); return serverPath(false) . '/' - . "doceditor.php" + . "editor" . "?fileExt=" . $ext - . "&user=" . $uid - . "&type=" . $type; + . "&user=" . $uid; } /** @@ -960,9 +835,8 @@ function getHistoryDownloadUrl($fileName, $version, $file, $isServer = true) { $userAddress = $isServer ? "&userAddress=" . getClientIp() : ""; return serverPath($isServer) . '/' - . "webeditor-ajax.php" - . "?type=history" - . "&fileName=" . urlencode($fileName) + . "history" + . "?fileName=" . urlencode($fileName) . "&ver=" . $version . "&file=" . urlencode($file) . $userAddress; @@ -980,9 +854,8 @@ function getDownloadUrl($fileName, $isServer = true) { $userAddress = $isServer ? "&userAddress=" . getClientIp() : ""; return serverPath($isServer) . '/' - . "webeditor-ajax.php" - . "?type=download" - . "&fileName=" . urlencode($fileName) + . "download" + . "?fileName=" . urlencode($fileName) . $userAddress; } @@ -999,8 +872,6 @@ function getDownloadUrl($fileName, $isServer = true) */ function getHistory($filename, $filetype, $docKey, $fileuri, $isEnableDirectUrl) { - $configManager = new ConfigManager(); - $storagePath = $configManager->getConfig("storagePath"); $histDir = getHistoryDir(getStoragePath($filename)); // get the path to the file history if (getFileVersion($histDir) > 0) { // check if the file was modified (the file version is greater than 0) @@ -1041,13 +912,11 @@ function getHistory($filename, $filetype, $docKey, $fileuri, $isEnableDirectUrl) $directUrl = $i == $curVer ? fileUri($filename, false) : getHistoryDownloadUrl($filename, $i, "prev.".$fileExe, false); $prevFileUrl = $i == $curVer ? $fileuri : getHistoryDownloadUrl($filename, $i, "prev.".$fileExe); - if (realpath($storagePath) === $storagePath) { - $prevFileUrl = $i == $curVer ? getDownloadUrl($filename) : - getHistoryDownloadUrl($filename, $i, "prev.".$fileExe); - if ($isEnableDirectUrl) { - $directUrl = $i == $curVer ? getDownloadUrl($filename, false) : - getHistoryDownloadUrl($filename, $i, "prev.".$fileExe, false); - } + $prevFileUrl = $i == $curVer ? getDownloadUrl($filename) : + getHistoryDownloadUrl($filename, $i, "prev.".$fileExe); + if ($isEnableDirectUrl) { + $directUrl = $i == $curVer ? getDownloadUrl($filename, false) : + getHistoryDownloadUrl($filename, $i, "prev.".$fileExe, false); } $dataObj["url"] = $prevFileUrl; // write file url to the data object diff --git a/web/documentserver-example/php/helpers/ExampleUsers.php b/web/documentserver-example/php/src/helpers/ExampleUsers.php similarity index 90% rename from web/documentserver-example/php/helpers/ExampleUsers.php rename to web/documentserver-example/php/src/helpers/ExampleUsers.php index b7ac5a42c..cf1e3a0f8 100644 --- a/web/documentserver-example/php/helpers/ExampleUsers.php +++ b/web/documentserver-example/php/src/helpers/ExampleUsers.php @@ -1,8 +1,8 @@ descr_user_1 = [ + $this->user1Description = [ "File author by default", "Doesn’t belong to any group", "Can review all the changes", @@ -39,16 +39,16 @@ public function __construct() "Can create files from templates using data from the editor", "Can see the information about all users", ]; - $this->descr_user_2 = [ + $this->user2Description = [ "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 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 don’t belong to any group", ]; - $this->descr_user_3 = [ + $this->user3Description = [ "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", @@ -59,7 +59,7 @@ public function __construct() "Can create new files from the editor", "Can see the information about Group2 users", ]; - $this->descr_user_0 = [ + $this->user0Description = [ "The name is requested when the editor is opened", "Doesn’t belong to any group", "Can review all the changes", @@ -83,7 +83,7 @@ public function __construct() null, null, [], - $this->descr_user_1, + $this->user1Description, true ), new Users( @@ -100,7 +100,7 @@ public function __construct() ["group-2", ""], true, [], - $this->descr_user_2, + $this->user2Description, false ), new Users( @@ -117,7 +117,7 @@ public function __construct() ["group-2"], false, ["copy", "download", "print"], - $this->descr_user_3, + $this->user3Description, false ), new Users( @@ -130,7 +130,7 @@ public function __construct() [], null, ["protect"], - $this->descr_user_0, + $this->user0Description, false ), ]; diff --git a/web/documentserver-example/php/helpers/JwtManager.php b/web/documentserver-example/php/src/helpers/JwtManager.php similarity index 70% rename from web/documentserver-example/php/helpers/JwtManager.php rename to web/documentserver-example/php/src/helpers/JwtManager.php index 610421cd6..81588981e 100644 --- a/web/documentserver-example/php/helpers/JwtManager.php +++ b/web/documentserver-example/php/src/helpers/JwtManager.php @@ -1,6 +1,6 @@ getConfig("docServJwtSecret")); + $configManager = new ConfigurationManager(); + return !empty($configManager->jwtSecret()); } /** @@ -38,8 +42,8 @@ public function isJwtEnabled(): bool */ public function tokenUseForRequest(): bool { - $configManager = new ConfigManager(); - return $configManager->getConfig("docServJwtUseForRequest") ?: false; + $configManager = new ConfigurationManager(); + return $configManager->jwtUseForRequest() ?: false; } /** @@ -51,8 +55,8 @@ public function tokenUseForRequest(): bool */ public function jwtEncode($payload) { - $configManager = new ConfigManager(); - return \Firebase\JWT\JWT::encode($payload, $configManager->getConfig("docServJwtSecret")); + $configManager = new ConfigurationManager(); + return JWT::encode($payload, $configManager->jwtSecret(), 'HS256'); } /** @@ -64,12 +68,11 @@ public function jwtEncode($payload) */ public function jwtDecode($token) { - $configManager = new ConfigManager(); + $configManager = new ConfigurationManager(); try { - $payload = \Firebase\JWT\JWT::decode( + $payload = JWT::decode( $token, - $configManager->getConfig("docServJwtSecret"), - ["HS256"] + new Key($configManager->jwtSecret(), 'HS256') ); } catch (\UnexpectedValueException $e) { $payload = ""; diff --git a/web/documentserver-example/php/helpers/Users.php b/web/documentserver-example/php/src/helpers/Users.php similarity index 98% rename from web/documentserver-example/php/helpers/Users.php rename to web/documentserver-example/php/src/helpers/Users.php index 9359444c6..837ea4bc1 100644 --- a/web/documentserver-example/php/helpers/Users.php +++ b/web/documentserver-example/php/src/helpers/Users.php @@ -1,6 +1,6 @@ configManager = $configManager; + } + + public function resolveURL(URL $url): URL + { + if (!$this->referPublicURL($url)) { + return $url; + } + return $this->redirectPublicURL($url); + } + + private function referPublicURL(URL $url): bool + { + $publicURL = $this->configManager->documentServerPublicURL(); + return + $url->scheme() == $publicURL->scheme() && + $url->host() == $publicURL->host() && + $url->port() == $publicURL->port(); + } + + private function redirectPublicURL(URL $url): URL + { + $privateURL = $this->configManager->documentServerPrivateURL(); + return URL::fromComponents( + $privateURL->scheme(), + $privateURL->host(), + $privateURL->port(), + $url->user(), + $url->pass(), + $url->path(), + $url->query(), + $url->fragment() + ); + } +} diff --git a/web/documentserver-example/php/src/proxy/ProxyManagerTests.php b/web/documentserver-example/php/src/proxy/ProxyManagerTests.php new file mode 100644 index 000000000..002672245 --- /dev/null +++ b/web/documentserver-example/php/src/proxy/ProxyManagerTests.php @@ -0,0 +1,67 @@ +createStub(ConfigurationManager::class); + $configManager + ->method('documentServerPublicURL') + ->willReturn(new URL('http://localhost')); + $configManager + ->method('documentServerPrivateURL') + ->willReturn(new URL('http://proxy')); + + $proxyManager = new ProxyManager($configManager); + + $rawURL = 'http://localhost/endpoint?query=string'; + $url = new URL($rawURL); + $resolvedURL = $proxyManager->resolveURL($url); + + $this->assertEquals( + 'http://proxy/endpoint?query=string', + $resolvedURL->string() + ); + } + + public function testResolvesAURLThatDoesNotRefersToThePublicURL() + { + $configManager = $this->createStub(ConfigurationManager::class); + $configManager + ->method('documentServerPublicURL') + ->willReturn(new URL('http://localhost')); + + $proxyManager = new ProxyManager($configManager); + + $rawURL = 'http://proxy/endpoint?query=string'; + $url = new URL($rawURL); + $resolvedURL = $proxyManager->resolveURL($url); + + $this->assertEquals( + 'http://proxy/endpoint?query=string', + $resolvedURL->string() + ); + } +} diff --git a/web/documentserver-example/php/trackmanager.php b/web/documentserver-example/php/src/trackmanager.php similarity index 86% rename from web/documentserver-example/php/trackmanager.php rename to web/documentserver-example/php/src/trackmanager.php index 0f54e9512..ec55fb518 100755 --- a/web/documentserver-example/php/trackmanager.php +++ b/web/documentserver-example/php/src/trackmanager.php @@ -15,11 +15,13 @@ * limitations under the License. */ -namespace OnlineEditorsExamplePhp; +namespace Example; use Exception; -use OnlineEditorsExamplePhp\Helpers\ConfigManager; -use OnlineEditorsExamplePhp\Helpers\JwtManager; +use Example\Common\URL; +use Example\Configuration\ConfigurationManager; +use Example\Helpers\JwtManager; +use Example\Proxy\ProxyManager; /** * Read request body @@ -28,16 +30,17 @@ */ function readBody() { + $configManager = new ConfigurationManager(); + $result["error"] = 0; - $configManager = new ConfigManager(); $jwtManager = new JwtManager(); // get the body of the post request and check if it is correct - if (($body_stream = file_get_contents('php://input')) === false) { + if (($bodyStream = file_get_contents('php://input')) === false) { $result["error"] = "Bad Request"; return $result; } - $data = json_decode($body_stream, false); + $data = json_decode($bodyStream, false); // check if the response is correct if ($data === null) { @@ -53,8 +56,7 @@ function readBody() $inHeader = false; $data = ""; - $jwtHeader = $configManager->getConfig("docServJwtHeader") == - "" ? "Authorization" : $configManager->getConfig("docServJwtHeader"); + $jwtHeader = $configManager->jwtHeader(); if (!empty($data["token"])) { // if the document token is in the data $data = $jwtManager->jwtDecode($data["token"]); // decode it @@ -97,8 +99,10 @@ function readBody() * * @return array */ -function processSave($data, $fileName, $userAddress) +function processSave($rawData, $fileName, $userAddress) { + $data = resolveProcessSaveData($rawData); + $downloadUri = $data->url; if ($downloadUri === null) { $result["error"] = 1; @@ -136,7 +140,7 @@ function processSave($data, $fileName, $userAddress) $saved = 1; - if (!(($new_data = file_get_contents( + if (!(($newData = file_get_contents( $downloadUri, false, stream_context_create(["http" => ["timeout" => 5]]) @@ -151,7 +155,7 @@ function processSave($data, $fileName, $userAddress) // get the path to the previous file version and rename the storage path with it rename(getStoragePath($fileName, $userAddress), $verDir . DIRECTORY_SEPARATOR . "prev" . $curExt); - file_put_contents($storagePath, $new_data, LOCK_EX); // save file to the storage directory + file_put_contents($storagePath, $newData, LOCK_EX); // save file to the storage directory if ($changesData = file_get_contents( $data->changesurl, @@ -236,7 +240,7 @@ function processForceSave($data, $fileName, $userAddress) $saved = 1; - if (!(($new_data = file_get_contents( + if (!(($newData = file_get_contents( $downloadUri, false, stream_context_create(["http" => ["timeout" => 5]]) @@ -264,7 +268,7 @@ function processForceSave($data, $fileName, $userAddress) } } - file_put_contents($forcesavePath, $new_data, LOCK_EX); + file_put_contents($forcesavePath, $newData, LOCK_EX); if ($isSubmitForm) { $uid = $data->actions[0]->userid; // get the user id @@ -290,10 +294,10 @@ function processForceSave($data, $fileName, $userAddress) */ function commandRequest($method, $key, $meta = null) { - $configManager = new ConfigManager(); + $configManager = new ConfigurationManager(); + $jwtManager = new JwtManager(); - $documentCommandUrl = $configManager->getConfig("docServSiteUrl"). - $configManager->getConfig("docServCommandUrl"); + $documentCommandUrl = $configManager->documentServerCommandURL()->string(); $arr = [ "c" => $method, @@ -305,8 +309,7 @@ function commandRequest($method, $key, $meta = null) } $headerToken = ""; - $jwtHeader = $configManager->getConfig("docServJwtHeader") == "" ? "Authorization" : - $configManager->getConfig("docServJwtHeader"); + $jwtHeader = $configManager->jwtHeader(); // check if a secret key to generate token exists or not if ($jwtManager->isJwtEnabled() && $jwtManager->tokenUseForRequest()) { @@ -326,13 +329,36 @@ function commandRequest($method, $key, $meta = null) ]]; if (mb_substr($documentCommandUrl, 0, mb_strlen("https")) === "https") { - if ($configManager->getConfig("docServVerifyPeerOff") === true) { + if ($configManager->sslVerifyPeerModeEnabled()) { $opts['ssl'] = ['verify_peer' => false, 'verify_peer_name' => false]; } } $context = stream_context_create($opts); - $response_data = file_get_contents($documentCommandUrl, false, $context); + $responseData = file_get_contents($documentCommandUrl, false, $context); + + return $responseData; +} + +function resolveProcessSaveData($data) +{ + $configManager = new ConfigurationManager(); + $proxyManager = new ProxyManager($configManager); + $copied = clone $data; + + $url = $copied->url; + if ($url) { + $parsedURL = new URL($url); + $resolvedURL = $proxyManager->resolveURL($parsedURL); + $copied->url = $resolvedURL->string(); + } + + $changesURL = $copied->changesurl; + if ($changesURL) { + $parsedURL = new URL($changesURL); + $resolvedURL = $proxyManager->resolveURL($parsedURL); + $copied->changesurl = $resolvedURL->string(); + } - return $response_data; + return $copied; } diff --git a/web/documentserver-example/php/views/DocEditorView.php b/web/documentserver-example/php/src/views/DocEditorView.php similarity index 83% rename from web/documentserver-example/php/views/DocEditorView.php rename to web/documentserver-example/php/src/views/DocEditorView.php index 074d1ae5f..bb551a810 100644 --- a/web/documentserver-example/php/views/DocEditorView.php +++ b/web/documentserver-example/php/src/views/DocEditorView.php @@ -15,32 +15,36 @@ * limitations under the License. */ -namespace OnlineEditorsExamplePhp\Views; +namespace Example\Views; -use OnlineEditorsExamplePhp\Helpers\ConfigManager; -use OnlineEditorsExamplePhp\Helpers\ExampleUsers; -use OnlineEditorsExamplePhp\Helpers\JwtManager; -use function OnlineEditorsExamplePhp\doUpload; -use function OnlineEditorsExamplePhp\fileUri; -use function OnlineEditorsExamplePhp\getCallbackUrl; -use function OnlineEditorsExamplePhp\getCreateUrl; -use function OnlineEditorsExamplePhp\getDocEditorKey; -use function OnlineEditorsExamplePhp\getDocumentType; -use function OnlineEditorsExamplePhp\getDownloadUrl; -use function OnlineEditorsExamplePhp\getHistory; -use function OnlineEditorsExamplePhp\getStoragePath; -use function OnlineEditorsExamplePhp\getTemplateImageUrl; -use function OnlineEditorsExamplePhp\serverPath; -use function OnlineEditorsExamplePhp\tryGetDefaultByType; -use function OnlineEditorsExamplePhp\getCurUserHostAddress; +use Example\Configuration\ConfigurationManager; +use Example\Format\FormatManager; +use Example\Helpers\ExampleUsers; +use Example\Helpers\JwtManager; +use function Example\doUpload; +use function Example\fileUri; +use function Example\getCallbackUrl; +use function Example\getCreateUrl; +use function Example\getDocEditorKey; +use function Example\getDocumentType; +use function Example\getDownloadUrl; +use function Example\getHistory; +use function Example\getStoragePath; +use function Example\getTemplateImageUrl; +use function Example\serverPath; +use function Example\tryGetDefaultByType; +use function Example\getCurUserHostAddress; final class DocEditorView extends View { public function __construct($request, $tempName = "docEditor") { parent::__construct($tempName); + + $configManager = new ConfigurationManager(); + $formatManager = new FormatManager(); + $externalUrl = $request["fileUrl"] ?? ""; - $confgManager = new ConfigManager(); $jwtManager = new JwtManager(); $userList = new ExampleUsers(); $fileId = $request["fileID"] ?? ""; @@ -59,25 +63,22 @@ public function __construct($request, $tempName = "docEditor") $filename = tryGetDefaultByType($createExt, $user); // create the demo file url - $new_url = "doceditor.php?fileID=" . $filename . "&user=" . $request["user"]; - header('Location: ' . $new_url, true); + $newURL = "editor?fileID=" . $filename . "&user=" . $request["user"]; + header('Location: ' . $newURL, true); exit; } $fileuri = fileUri($filename, true); - $fileuriUser = realpath($confgManager->getConfig("storagePath")) === - $confgManager->getConfig("storagePath") ? - getDownloadUrl($filename) . "&dmode=emb" : fileUri($filename); $directUrl = getDownloadUrl($filename, false); $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, $formatManager->editableExtensions()); // check if the file can be edited if ((!$canEdit && $editorsMode == "edit" || $editorsMode == "fillForms") - && in_array($ext, $confgManager->getConfig("docServFillforms")) + && in_array($ext, $formatManager->fillableExtensions()) ) { $editorsMode = "fillForms"; $canEdit = true; @@ -190,31 +191,31 @@ public function __construct($request, $tempName = "docEditor") // an image for inserting $dataInsertImage = $isEnableDirectUrl ? [ "fileType" => "png", - "url" => serverPath(true) . "/css/images/logo.png", - "directUrl" => serverPath(false) . "/css/images/logo.png", + "url" => serverPath(true) . "/assets/images/logo.png", + "directUrl" => serverPath(false) . "/assets/images/logo.png", ] : [ "fileType" => "png", - "url" => serverPath(true) . "/css/images/logo.png", + "url" => serverPath(true) . "/assets/images/logo.png", ]; // a document for comparing $dataCompareFile = $isEnableDirectUrl ? [ "fileType" => "docx", - "url" => serverPath(true) . "/webeditor-ajax.php?type=assets&name=sample.docx", - "directUrl" => serverPath(false) . "/webeditor-ajax.php?type=assets&name=sample.docx", + "url" => serverPath(true) . "/assets?name=sample.docx", + "directUrl" => serverPath(false) . "/assets?name=sample.docx", ] : [ "fileType" => "docx", - "url" => serverPath(true) . "/webeditor-ajax.php?type=assets&name=sample.docx", + "url" => serverPath(true) . "/assets?name=sample.docx", ]; // recipients data for mail merging $dataMailMergeRecipients = $isEnableDirectUrl ? [ "fileType" => "csv", - "url" => serverPath(true) . "/webeditor-ajax.php?type=csv", - "directUrl" => serverPath(false) . "/webeditor-ajax.php?type=csv", + "url" => serverPath(true) . "/csv", + "directUrl" => serverPath(false) . "/csv", ] : [ "fileType" => "csv", - "url" => serverPath(true) . "/webeditor-ajax.php?type=csv", + "url" => serverPath(true) . "/csv", ]; // users data for mentions @@ -266,7 +267,7 @@ public function __construct($request, $tempName = "docEditor") } $this->tagsValues = [ "docType" => getDocumentType($filename), - "apiUrl" => $confgManager->getConfig("docServSiteUrl").$confgManager->getConfig("docServApiUrl"), + "apiUrl" => $configManager->documentServerAPIURL()->string(), "dataInsertImage" => mb_strimwidth( json_encode($dataInsertImage), 1, diff --git a/web/documentserver-example/php/views/IndexStoredListView.php b/web/documentserver-example/php/src/views/IndexStoredListView.php similarity index 73% rename from web/documentserver-example/php/views/IndexStoredListView.php rename to web/documentserver-example/php/src/views/IndexStoredListView.php index cba1ff0eb..100d1b962 100644 --- a/web/documentserver-example/php/views/IndexStoredListView.php +++ b/web/documentserver-example/php/src/views/IndexStoredListView.php @@ -15,12 +15,12 @@ * limitations under the License. */ -namespace OnlineEditorsExamplePhp\Views; +namespace Example\Views; -use function OnlineEditorsExamplePhp\getStoredFiles; -use function OnlineEditorsExamplePhp\getFileVersion; -use function OnlineEditorsExamplePhp\getHistoryDir; -use function OnlineEditorsExamplePhp\getStoragePath; +use function Example\getStoredFiles; +use function Example\getFileVersion; +use function Example\getHistoryDir; +use function Example\getStoragePath; class IndexStoredListView extends View { @@ -50,43 +50,44 @@ public function getStoredListLayout() ) ).']">'; $layout .= ' '.''.$storeFile->name.''; if ($storeFile->canEdit) { - $layout .= ' '. - 'Open in editor for full size screens'. - ' '. - 'Open in editor for mobile devices'. - ' '. - ' Open in editor for comment'; if ($storeFile->documentType == "word") { - $layout .= ' '. - ' Open in editor for review'. - ' '. - ' Open in editor without content control modification'; } elseif ($storeFile->documentType == "cell") { - $layout .= ' '. - ' Open in editor without access to change the filter'; } else { $layout .= ''; @@ -95,55 +96,55 @@ public function getStoredListLayout() if ($storeFile->isFillFormDoc) { $layout.= ' '. - ' '. - ' Open in editor for filling in forms'; } else { $layout .= ''; } } elseif ($storeFile->isFillFormDoc) { - $layout .= ' '. - ' Open in editor for filling in forms'.
+                    '   <img src='. ''. ''. ''. ''. - ''. - 'Open in editor for filling in forms'; } else { $layout .= ''; } $layout .= ''. - ' '. - ' Open in viewer for full size screens'. - ' '. - ' Open in viewer for mobile devices'. ' '. - ' '. - ' Open in embedded mode'. ' '. - ''. - ' Download'. + ' Download'. ''. ' '. - ' Delete'. + ' Delete'. ''; } } diff --git a/web/documentserver-example/php/views/IndexView.php b/web/documentserver-example/php/src/views/IndexView.php similarity index 75% rename from web/documentserver-example/php/views/IndexView.php rename to web/documentserver-example/php/src/views/IndexView.php index b1a987b99..cade07162 100644 --- a/web/documentserver-example/php/views/IndexView.php +++ b/web/documentserver-example/php/src/views/IndexView.php @@ -15,11 +15,12 @@ * limitations under the License. */ -namespace OnlineEditorsExamplePhp\Views; +namespace Example\Views; -use OnlineEditorsExamplePhp\Helpers\ConfigManager; -use OnlineEditorsExamplePhp\Helpers\ExampleUsers; -use function OnlineEditorsExamplePhp\getStoredFiles; +use Example\Configuration\ConfigurationManager; +use Example\Format\FormatManager; +use Example\Helpers\ExampleUsers; +use function Example\getStoredFiles; final class IndexView extends View { @@ -27,8 +28,9 @@ final class IndexView extends View public function __construct($request, $tempName = "index") { parent::__construct($tempName); + $formatManager = new FormatManager(); + $storedList = new IndexStoredListView($request); - $configManager = new ConfigManager(); $portalInfo = $this->getPortalInfoStyleDisplay(); $this->tagsValues = [ @@ -41,9 +43,9 @@ public function __construct($request, $tempName = "index") "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(",", $formatManager->fillableExtensions()), + "converExtList" => implode(",", $formatManager->convertibleExtensions()), + "editedExtList" => implode(",", $formatManager->editableExtensions()), ]; } @@ -61,8 +63,8 @@ private function getUserListOptionsLayout() private function getLanguageListOptionsLayout() { $layout = ""; - $configManager = new ConfigManager(); - foreach ($configManager->getConfig("languages") as $key => $language) { + $configManager = new ConfigurationManager(); + foreach ($configManager->languages() as $key => $language) { $layout .= ''.PHP_EOL; } return $layout; @@ -100,16 +102,12 @@ private function getStoredListLayout() private function getPreloaderUrl() { - $configManager = new ConfigManager(); - - return $configManager->getConfig("docServSiteUrl"). - $configManager->getConfig("docServPreloaderUrl"); + $configManager = new ConfigurationManager(); + return $configManager->documentServerPreloaderURL()->string(); } private function getEditButton() { - $configManager = new ConfigManager(); - return $configManager->getConfig("mode") != "view" ? - '
Edit
' : ""; + return '
Edit
'; } } diff --git a/web/documentserver-example/php/views/View.php b/web/documentserver-example/php/src/views/View.php similarity index 97% rename from web/documentserver-example/php/views/View.php rename to web/documentserver-example/php/src/views/View.php index 57034b684..e9c8a894b 100644 --- a/web/documentserver-example/php/views/View.php +++ b/web/documentserver-example/php/src/views/View.php @@ -15,7 +15,7 @@ * limitations under the License. */ -namespace OnlineEditorsExamplePhp\Views; +namespace Example\Views; class View { diff --git a/web/documentserver-example/php/templates/docEditor.tpl b/web/documentserver-example/php/templates/docEditor.tpl index c8876ab27..a21400f5a 100644 --- a/web/documentserver-example/php/templates/docEditor.tpl +++ b/web/documentserver-example/php/templates/docEditor.tpl @@ -6,7 +6,7 @@ maximum-scale=1, minimum-scale=1, user-scalable=no, minimal-ui" /> - + ONLYOFFICE