diff --git a/web/documentserver-example/csharp-mvc/Content/media.css b/web/documentserver-example/csharp-mvc/Content/media.css index 3f8f7f8a..2e44966b 100644 --- a/web/documentserver-example/csharp-mvc/Content/media.css +++ b/web/documentserver-example/csharp-mvc/Content/media.css @@ -87,10 +87,6 @@ } @media (max-width: 1008px) { - #portal-info { - width: 65vw; - } - .left-panel { margin-left: 0; } @@ -312,6 +308,9 @@ .tableRow td:first-child { max-width: 17%; } + #portal-info { + max-width: 60vw; + } } .downloadContentCellShift:after { diff --git a/web/documentserver-example/csharp-mvc/Content/stylesheet.css b/web/documentserver-example/csharp-mvc/Content/stylesheet.css index 591d0e80..0e057d0f 100644 --- a/web/documentserver-example/csharp-mvc/Content/stylesheet.css +++ b/web/documentserver-example/csharp-mvc/Content/stylesheet.css @@ -22,6 +22,7 @@ } body { + display: inline-table; background: #FFFFFF; color: #333333; font-family: Open Sans; @@ -71,6 +72,7 @@ header img { } .main { + display: table; height: calc(100% - 112px); min-height: 536px; } @@ -97,6 +99,10 @@ header img { width: 896px; } +#portal-info { + max-width: 65vw; +} + .portal-name { color: #FF6F3D; font-size: 24px; diff --git a/web/documentserver-example/csharp-mvc/Helpers/DocManagerHelper.cs b/web/documentserver-example/csharp-mvc/Helpers/DocManagerHelper.cs index dea4eaec..56b903eb 100644 --- a/web/documentserver-example/csharp-mvc/Helpers/DocManagerHelper.cs +++ b/web/documentserver-example/csharp-mvc/Helpers/DocManagerHelper.cs @@ -79,19 +79,37 @@ namespace OnlineEditorsExampleMVC.Helpers // get the storage path of the file public static string StoragePath(string fileName, string userAddress = null) { - var directory = HttpRuntime.AppDomainAppPath + CurUserHostAddress(userAddress) + "\\"; + var directory = ""; + if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["storage-path"]) && Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"])) + { + directory = WebConfigurationManager.AppSettings["storage-path"] + "\\"; + } + else + { + directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\"; + } + if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); } - return directory + Path.GetFileName(fileName); + return directory + (fileName.Contains("\\") ? fileName : Path.GetFileName(fileName)); } // get the path to the forcesaved file version public static string ForcesavePath(string fileName, string userAddress, Boolean create) { // create the directory to this file version - var directory = HttpRuntime.AppDomainAppPath + CurUserHostAddress(userAddress) + "\\"; + var directory = ""; + if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["storage-path"]) && Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"])) + { + directory = WebConfigurationManager.AppSettings["storage-path"] + "\\"; + } + else + { + directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\"; + } + if (!Directory.Exists(directory)) { return ""; @@ -172,7 +190,16 @@ namespace OnlineEditorsExampleMVC.Helpers // get all the stored files from the user host address public static List GetStoredFiles() { - var directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(null) + "\\"; + var directory = ""; + if (!string.IsNullOrEmpty(WebConfigurationManager.AppSettings["storage-path"]) && Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"])) + { + directory = WebConfigurationManager.AppSettings["storage-path"] + "\\"; + } + else + { + directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(null) + "\\"; + } + if (!Directory.Exists(directory)) return new List(); var directoryInfo = new DirectoryInfo(directory); @@ -228,8 +255,7 @@ namespace OnlineEditorsExampleMVC.Helpers { var uri = new UriBuilder(GetServerUrl(true)) { - Path = HttpRuntime.AppDomainAppVirtualPath + "/" - + path, + Path = HttpRuntime.AppDomainAppVirtualPath + "/" + path, Query = "" }; diff --git a/web/documentserver-example/csharp-mvc/Helpers/Users.cs b/web/documentserver-example/csharp-mvc/Helpers/Users.cs index 0b4a88d6..65138f94 100644 --- a/web/documentserver-example/csharp-mvc/Helpers/Users.cs +++ b/web/documentserver-example/csharp-mvc/Helpers/Users.cs @@ -70,7 +70,7 @@ namespace OnlineEditorsExampleMVC.Helpers "uid-1", "John Smith", "smith@example.com", - null, + "", null, new Dictionary(), null, @@ -116,7 +116,7 @@ namespace OnlineEditorsExampleMVC.Helpers "uid-0", null, null, - null, + "", null, new Dictionary(), null, diff --git a/web/documentserver-example/csharp-mvc/Models/FileModel.cs b/web/documentserver-example/csharp-mvc/Models/FileModel.cs index 0b6ea517..dc0baaf0 100644 --- a/web/documentserver-example/csharp-mvc/Models/FileModel.cs +++ b/web/documentserver-example/csharp-mvc/Models/FileModel.cs @@ -21,6 +21,7 @@ using System.Collections; using System.Collections.Generic; using System.IO; using System.Web; +using System.Web.Configuration; using System.Web.Mvc; using System.Web.Script.Serialization; using OnlineEditorsExampleMVC.Helpers; @@ -42,7 +43,7 @@ namespace OnlineEditorsExampleMVC.Models // get file url for user public string FileUriUser { - get { return DocManagerHelper.GetFileUri(FileName, false); } + get { return Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? DownloadUrl + "&dmode=emb" : DocManagerHelper.GetFileUri(FileName, false); } } public string FileName { get; set; } // file name @@ -214,7 +215,8 @@ namespace OnlineEditorsExampleMVC.Models // 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)); @@ -255,7 +257,18 @@ namespace OnlineEditorsExampleMVC.Models dataObj.Add("key", key); // write file url to the data object - dataObj.Add("url", i == currentVersion ? FileUri : DocManagerHelper.GetPathUri(Directory.GetFiles(verDir, "prev.*")[0].Substring(HttpRuntime.AppDomainAppPath.Length))); + string prevFileUrl; + if (Path.IsPathRooted(storagePath) && !string.IsNullOrEmpty(storagePath)) + { + prevFileUrl = i == currentVersion ? DocManagerHelper.GetDownloadUrl(FileName) + : DocManagerHelper.GetDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", "")); + } + else { + prevFileUrl = i == currentVersion ? FileUri + : DocManagerHelper.GetPathUri(Directory.GetFiles(verDir, "prev.*")[0].Substring(HttpRuntime.AppDomainAppPath.Length)); + } + + dataObj.Add("url", prevFileUrl); dataObj.Add("version", i); if (i > 1) // check if the version number is greater than 1 (the file was modified) { @@ -278,7 +291,9 @@ namespace OnlineEditorsExampleMVC.Models { "url", prev["url"] }, }); // write the path to the diff.zip archive with differences in this file version - dataObj.Add("changesUrl", DocManagerHelper.GetZipDownloadUrl((Path.Combine(DocManagerHelper.VersionDir(histDir, i - 1), "diff.zip")))); + var changesUrl = Path.IsPathRooted(storagePath) ? DocManagerHelper.GetDownloadUrl(Path.Combine(DocManagerHelper.VersionDir(histDir, i - 1), "diff.zip").Replace(storagePath + "\\", "")) + : DocManagerHelper.GetZipDownloadUrl((Path.Combine(DocManagerHelper.VersionDir(histDir, i - 1), "diff.zip"))); + dataObj.Add("changesUrl", changesUrl); } if(JwtManager.Enabled) { diff --git a/web/documentserver-example/csharp-mvc/README.md b/web/documentserver-example/csharp-mvc/README.md index 64d112b1..eba2b739 100644 --- a/web/documentserver-example/csharp-mvc/README.md +++ b/web/documentserver-example/csharp-mvc/README.md @@ -13,11 +13,14 @@ See the detailed guide to learn how to install Document Server [for Windows](htt ## Step 2. Download the .Net (C# MVC) code for the editors integration Download the [.Net (C# MVC) example](https://api.onlyoffice.com/editors/demopreview) from our site. -You need to connnect the editors to your website. Specify path to the editors installation in the *settings.config* file: + +To connect the editors to your website, specify the path to the editors installation and the path to the storage folder in the *settings.config* file: ``` + ``` -where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. +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. + If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) in the *DocEditor.aspx* file. ## Step 3. Install the prerequisites @@ -25,6 +28,16 @@ If you want to experiment with the editor configuration, modify the [parameters] * **Microsoft .NET Framework**: version 4.5 (download it from the [official Microsoft website](https://www.microsoft.com/en-US/download/details.aspx?id=30653)); * **Internet Information Services**: version 7 or later. +Configure the IIS components for the server to work correctly: +1. Open Windows features: + + **Start** -> **Control Panel** -> **Programs** -> **Programs and Features** -> **Turn Windows features on or off** + +2. In the opened window, find **Internet Information Services** and choose all the necessary features. To do this, open the **World Wide Web Services** list and check the following components: +* **Application Development Features**: .NET Extensibility 4.8, ASP.NET 4.8, ISAPI Extensions, ISAPI Filters, +* **Common HTTP Features**: Default Document, +* **Security**: Request Filtering. + ## Step 4. Run your website with the editors 1. Run the Internet Information Service (IIS) Manager: diff --git a/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx b/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx index a44d749a..18f8d4d8 100644 --- a/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx +++ b/web/documentserver-example/csharp-mvc/Views/Home/Index.aspx @@ -139,7 +139,7 @@
<% var storedFiles = DocManagerHelper.GetStoredFiles(); %> -
"> +
"> ONLYOFFICE Document Editors – Welcome! Get started with a demo-sample of ONLYOFFICE Document Editors, the first html5-based editors. @@ -222,9 +222,6 @@ <% } %> - <% if (docType != "word" && docType != "cell") { %> - - <% } %> <% if (docType == "word") { %> " target="_blank"> diff --git a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs index 6e2f3aae..1d3a6c32 100644 --- a/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs +++ b/web/documentserver-example/csharp-mvc/WebEditor.ashx.cs @@ -446,10 +446,12 @@ namespace OnlineEditorsExampleMVC { try { - var fileName = Path.GetFileName(context.Request["fileName"]); + var fileName = Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? context.Request["fileName"] + : Path.GetFileName(context.Request["fileName"]); var userAddress = context.Request["userAddress"]; + var isEmbedded = context.Request["dmode"]; - if (JwtManager.Enabled) + if (JwtManager.Enabled && isEmbedded == null) { string JWTheader = WebConfigurationManager.AppSettings["files.docservice.header"].Equals("") ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"]; diff --git a/web/documentserver-example/csharp-mvc/web.appsettings.config b/web/documentserver-example/csharp-mvc/web.appsettings.config index 9b0a0003..d648d827 100644 --- a/web/documentserver-example/csharp-mvc/web.appsettings.config +++ b/web/documentserver-example/csharp-mvc/web.appsettings.config @@ -4,7 +4,8 @@ - + + diff --git a/web/documentserver-example/csharp/App_Themes/media.css b/web/documentserver-example/csharp/App_Themes/media.css index 3f8f7f8a..2e44966b 100644 --- a/web/documentserver-example/csharp/App_Themes/media.css +++ b/web/documentserver-example/csharp/App_Themes/media.css @@ -87,10 +87,6 @@ } @media (max-width: 1008px) { - #portal-info { - width: 65vw; - } - .left-panel { margin-left: 0; } @@ -312,6 +308,9 @@ .tableRow td:first-child { max-width: 17%; } + #portal-info { + max-width: 60vw; + } } .downloadContentCellShift:after { diff --git a/web/documentserver-example/csharp/App_Themes/stylesheet.css b/web/documentserver-example/csharp/App_Themes/stylesheet.css index 35d63865..a8359729 100644 --- a/web/documentserver-example/csharp/App_Themes/stylesheet.css +++ b/web/documentserver-example/csharp/App_Themes/stylesheet.css @@ -22,6 +22,7 @@ html { } body { + display: inline-table; background: #FFFFFF; color: #333333; font-family: Open Sans; @@ -71,6 +72,7 @@ header img { } .main { + display: table; height: calc(100% - 112px); min-height: 536px; } @@ -97,6 +99,10 @@ header img { width: 896px; } +#portal-info { + max-width: 65vw; +} + .portal-name { color: #FF6F3D; font-size: 24px; diff --git a/web/documentserver-example/csharp/Default.aspx b/web/documentserver-example/csharp/Default.aspx index 4cf35f1b..18276ef2 100644 --- a/web/documentserver-example/csharp/Default.aspx +++ b/web/documentserver-example/csharp/Default.aspx @@ -140,7 +140,7 @@ <% var storedFiles = GetStoredFiles(); %>
-
"> +
"> ONLYOFFICE Document Editors – Welcome! Get started with a demo-sample of ONLYOFFICE Document Editors, the first html5-based editors. @@ -223,9 +223,6 @@ <% } %> - <%if (docType != "word" && docType != "cell") { %> - - <% } %> <% if (docType == "word") { %> " target="_blank"> diff --git a/web/documentserver-example/csharp/Default.aspx.cs b/web/documentserver-example/csharp/Default.aspx.cs index 85e5812c..7b3141b8 100644 --- a/web/documentserver-example/csharp/Default.aspx.cs +++ b/web/documentserver-example/csharp/Default.aspx.cs @@ -78,7 +78,9 @@ namespace OnlineEditorsExample { get { - return + return Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? + WebConfigurationManager.AppSettings["storage-path"] + "/" + : HttpRuntime.AppDomainAppVirtualPath + (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/") + WebConfigurationManager.AppSettings["storage-path"] @@ -144,18 +146,36 @@ namespace OnlineEditorsExample // get the storage path of the given file public static string StoragePath(string fileName, string userAddress) { - var directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\"; + var directory = ""; + if (Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"])) + { + directory = WebConfigurationManager.AppSettings["storage-path"] + "\\"; + } + else + { + directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\"; + } + if (!Directory.Exists(directory)) { Directory.CreateDirectory(directory); // if the file directory doesn't exist, make it } - return directory + Path.GetFileName(fileName); + return directory + (fileName.Contains("\\") ? fileName : Path.GetFileName(fileName)); } // get the path to the forcesaved file version public static string ForcesavePath(string fileName, string userAddress, Boolean create) { - var directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\"; + var directory = ""; + if (Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"])) + { + directory = WebConfigurationManager.AppSettings["storage-path"] + "\\"; + } + else + { + directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(userAddress) + "\\"; + } + if (!Directory.Exists(directory)) // the directory with host address doesn't exist { return ""; @@ -528,7 +548,16 @@ namespace OnlineEditorsExample // get all the stored files from the folder protected static List GetStoredFiles() { - var directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(null) + "\\"; + var directory = ""; + if (Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"])) + { + directory = WebConfigurationManager.AppSettings["storage-path"] + "\\"; + } + else + { + directory = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"] + CurUserHostAddress(null) + "\\"; + } + if (!Directory.Exists(directory)) return new List(); var directoryInfo = new DirectoryInfo(directory); // read the user host directory contents diff --git a/web/documentserver-example/csharp/DocEditor.aspx.cs b/web/documentserver-example/csharp/DocEditor.aspx.cs index 71a5719b..a7c7cd99 100644 --- a/web/documentserver-example/csharp/DocEditor.aspx.cs +++ b/web/documentserver-example/csharp/DocEditor.aspx.cs @@ -41,7 +41,7 @@ namespace OnlineEditorsExample // get url to the original file for Document Server public static string FileUriUser { - get { return _Default.FileUri(FileName, false); } + get { return Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? getDownloadUrl(FileName) + "&dmode=emb" : _Default.FileUri(FileName, false); } } protected string Key @@ -100,20 +100,17 @@ namespace OnlineEditorsExample } // get url to download a file - public static string getDownloadUrl + public static string getDownloadUrl(string fileName) { - get - { - var downloadUrl = new UriBuilder(_Default.GetServerUrl(true)); + var downloadUrl = new UriBuilder(_Default.GetServerUrl(true)); downloadUrl.Path = HttpRuntime.AppDomainAppVirtualPath + (HttpRuntime.AppDomainAppVirtualPath.EndsWith("/") ? "" : "/") + "webeditor.ashx"; downloadUrl.Query = "type=download" - + "&fileName=" + HttpUtility.UrlEncode(FileName) + + "&fileName=" + HttpUtility.UrlEncode(fileName) + "&userAddress=" + HttpUtility.UrlEncode(HttpContext.Current.Request.UserHostAddress); return downloadUrl.ToString(); - } } public static string GetZipDownloadUrl(string fileName) { @@ -208,7 +205,7 @@ namespace OnlineEditorsExample "document", new Dictionary { { "title", FileName }, - { "url", getDownloadUrl }, + { "url", getDownloadUrl(FileName) }, { "fileType", ext.Trim('.') }, { "key", Key }, { @@ -331,6 +328,7 @@ namespace OnlineEditorsExample // 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)); @@ -369,7 +367,13 @@ namespace OnlineEditorsExample } dataObj.Add("key", key); - dataObj.Add("url", i == currentVersion ? FileUri : MakePublicUrl(Directory.GetFiles(verDir, "prev.*")[0])); // write file url to the data object + var prevFileUrl = i == currentVersion ? FileUri : MakePublicUrl(Directory.GetFiles(verDir, "prev.*")[0]); + if (Path.IsPathRooted(storagePath)) + { + prevFileUrl = i == currentVersion ? getDownloadUrl(FileName) : getDownloadUrl(Directory.GetFiles(verDir, "prev.*")[0].Replace(storagePath + "\\", "")); + } + + dataObj.Add("url", prevFileUrl); // write file 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) { @@ -392,8 +396,9 @@ namespace OnlineEditorsExample { "url", prev["url"] }, }); // write the path to the diff.zip archive with differences in this file version - //dataObj.Add("changesUrl", MakePublicUrl(Path.Combine(_Default.VersionDir(histDir, i - 1), "diff.zip"))); - dataObj.Add("changesUrl", GetZipDownloadUrl(Path.Combine(_Default.VersionDir(histDir, i - 1), "diff.zip"))); + var changesUrl = Path.IsPathRooted(storagePath) ? getDownloadUrl(Path.Combine(_Default.VersionDir(histDir, i - 1), "diff.zip").Replace(storagePath + "\\", "")) + : GetZipDownloadUrl(Path.Combine(_Default.VersionDir(histDir, i - 1), "diff.zip")); + dataObj.Add("changesUrl", changesUrl); } if (JwtManager.Enabled) { @@ -517,7 +522,8 @@ namespace OnlineEditorsExample // create the public url private string MakePublicUrl(string fullPath) { - var root = HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"]; + var root = Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? WebConfigurationManager.AppSettings["storage-path"] + : HttpRuntime.AppDomainAppPath + WebConfigurationManager.AppSettings["storage-path"]; return _Default.GetServerUrl(true) + fullPath.Substring(root.Length).Replace(Path.DirectorySeparatorChar, '/'); } diff --git a/web/documentserver-example/csharp/README.md b/web/documentserver-example/csharp/README.md index 7f5e41f7..3d5f53bb 100644 --- a/web/documentserver-example/csharp/README.md +++ b/web/documentserver-example/csharp/README.md @@ -14,11 +14,12 @@ See the detailed guide to learn how to install Document Server [for Windows](htt Download the [.Net (C#) example](https://api.onlyoffice.com/editors/demopreview) from our site. -Connect the editors to your website by specifying the path to the editors installation in the *settings.config* file: +To connect the editors to your website, specify the path to the editors installation and the path to the storage folder in the *settings.config* file: ``` + ``` -where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. +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. If you want to experiment with the editor configuration, modify the [parameters](https://api.onlyoffice.com/editors/advanced) in the *DocEditor.aspx* file. @@ -28,6 +29,16 @@ Check that your system meets the requirements: * **Microsoft .NET Framework**: version 4.5 (download it from the [official Microsoft website](https://www.microsoft.com/en-US/download/details.aspx?id=30653)); * **Internet Information Services**: version 7 or later. +Configure the IIS components for the server to work correctly: +1. Open Windows features: + + **Start** -> **Control Panel** -> **Programs** -> **Programs and Features** -> **Turn Windows features on or off** + +2. In the opened window, find **Internet Information Services** and choose all the necessary features. To do this, open the **World Wide Web Services** list and check the following components: +* **Application Development Features**: .NET Extensibility 4.8, ASP.NET 4.8, ISAPI Extensions, ISAPI Filters, +* **Common HTTP Features**: Default Document, +* **Security**: Request Filtering. + ## Step 4. Run your website with the editors 1. Run the Internet Information Service (IIS) Manager: diff --git a/web/documentserver-example/csharp/Users.cs b/web/documentserver-example/csharp/Users.cs index bb45cace..f516e2b7 100644 --- a/web/documentserver-example/csharp/Users.cs +++ b/web/documentserver-example/csharp/Users.cs @@ -69,7 +69,7 @@ namespace OnlineEditorsExample "uid-1", "John Smith", "smith@example.com", - null, + "", null, new Dictionary(), null, @@ -115,7 +115,7 @@ namespace OnlineEditorsExample "uid-0", null, null, - null, + "", null, new Dictionary(), null, diff --git a/web/documentserver-example/csharp/WebEditor.ashx.cs b/web/documentserver-example/csharp/WebEditor.ashx.cs index abd03875..9b6f9704 100644 --- a/web/documentserver-example/csharp/WebEditor.ashx.cs +++ b/web/documentserver-example/csharp/WebEditor.ashx.cs @@ -275,10 +275,11 @@ namespace OnlineEditorsExample { try { - var fileName = Path.GetFileName(context.Request["fileName"]); + var fileName = Path.IsPathRooted(WebConfigurationManager.AppSettings["storage-path"]) ? context.Request["fileName"] : Path.GetFileName(context.Request["fileName"]); var userAddress = Path.GetFileName(context.Request["userAddress"]); + var isEmbedded = context.Request["dmode"]; - if (JwtManager.Enabled) + if (JwtManager.Enabled && isEmbedded == null) { string JWTheader = WebConfigurationManager.AppSettings["files.docservice.header"].Equals("") ? "Authorization" : WebConfigurationManager.AppSettings["files.docservice.header"]; diff --git a/web/documentserver-example/java-spring/README.md b/web/documentserver-example/java-spring/README.md index a5a35c6b..651a771b 100755 --- a/web/documentserver-example/java-spring/README.md +++ b/web/documentserver-example/java-spring/README.md @@ -19,16 +19,15 @@ See the detailed guide to learn how to install Document Server [for Windows](htt Download the [Java-Spring example](https://api.onlyoffice.com/editors/demopreview) from our site. -To connect the editors to your website, specify the path to the editors installation, server address and port in the *\src\main\resources\application.properties* file: +To connect the editors to your website, specify the path to the editors installation, server port and the path to the storage folder in the *\src\main\resources\application.properties* file: ``` - server.address=address + files.storage= server.port=port files.docservice.url.site=https://documentserver/ ``` -where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. -**address** is the address of the server or comment this line to use localhost, **port** is the any available port. +where the **documentserver** is the name of the server with the ONLYOFFICE Docs installed, **port** is any available port and **files.storage** is the path where files will be created and stored (in the project folder by default). 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) it the *\src\main\resources\editor.html* file. @@ -112,8 +111,6 @@ To run the Java example code, install the Java version 11 appropriate for your O ``` http://server.address:server.port/ ``` - - ### Step 6. Check accessibility @@ -173,13 +170,13 @@ See the detailed guide to learn how to install Document Server [for Linux](https Edit the following lines: ``` - server.address=address + files.storage= server.port=port files.docservice.url.site=https://documentserver/ ``` - Where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. - **address** is the address of the server or comment this line to use localhost, **port** is the any available port. + where the **documentserver** is the name of the server with the ONLYOFFICE Docs installed, **port** is any available port and **files.storage** is the path where files will be created and stored (in the project folder by default). You can set an absolute path. + 5. Install **Maven**: @@ -204,7 +201,6 @@ See the detailed guide to learn how to install Document Server [for Linux](https ``` - ### 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. @@ -222,13 +218,12 @@ Make sure that the Document Server has access to the server with the example ins 2. Edit the following lines: ``` - server.address=address + files.storage= server.port=port files.docservice.url.site=https://documentserver/ ``` - Where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. - **address** is the address of the server or comment this line to use localhost, **port** is the any available port. + where the **documentserver** is the name of the server with the ONLYOFFICE Docs installed, **port** is any available port and **files.storage** is the path where files will be created and stored (in the project folder by default). You can set an absolute path. 3. Run the next command in the java example directory: diff --git a/web/documentserver-example/java-spring/docker-compose.yaml b/web/documentserver-example/java-spring/docker-compose.yaml index 31950ed5..562bb046 100644 --- a/web/documentserver-example/java-spring/docker-compose.yaml +++ b/web/documentserver-example/java-spring/docker-compose.yaml @@ -7,7 +7,9 @@ services: image: maven:3.8.1 working_dir: /java-spring volumes: - - .:/java-spring + - .:/java-spring + ports: + - 4000:4000 command: mvn clean spring-boot:run \ No newline at end of file diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/ExampleData.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/ExampleData.java index e68e985e..7b420da4 100644 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/ExampleData.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/ExampleData.java @@ -68,7 +68,7 @@ public class ExampleData { "Can create a file from an editor" ); userService.createUser("John Smith", "smith@example.com", // create user 1 with the specified parameters - description_user_1, null, List.of(FilterState.NULL.toString()), + description_user_1, "", List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()), null); @@ -79,7 +79,7 @@ public class ExampleData { description_user_3, "group-3", List.of("group-2"), List.of("group-2", "group-3"), List.of("group-2"), new ArrayList<>(), false); userService.createUser("Anonymous",null, // create user 0 with the specified parameters - description_user_0,null, List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()), + description_user_0,"", List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()), List.of(FilterState.NULL.toString()), null); } } 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 07d966db..ffabaa55 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 @@ -45,6 +45,8 @@ public class DefaultDocumentManager implements DocumentManager { @Value("${files.storage.folder}") private String storageFolder; + @Value("${files.storage}") + private String filesStorage; @Value("${url.track}") private String trackUrl; @Value("${url.download}") @@ -93,6 +95,9 @@ public class DefaultDocumentManager implements DocumentManager { String hostAddress = storagePathBuilder.getStorageLocation(); // get the storage directory String filePathDownload = !fileName.contains(InetAddress.getLocalHost().getHostAddress()) ? fileName : fileName.substring(fileName.indexOf(InetAddress.getLocalHost().getHostAddress()) + InetAddress.getLocalHost().getHostAddress().length() + 1); + if (!filesStorage.isEmpty() && filePathDownload.contains(filesStorage)) { + filePathDownload = filePathDownload.substring(filesStorage.length() + 1); + } String filePath = serverPath + "/download?fileName=" + URLEncoder.encode(filePathDownload, java.nio.charset.StandardCharsets.UTF_8.toString()) + "&userAddress" + URLEncoder.encode(hostAddress, java.nio.charset.StandardCharsets.UTF_8.toString()); diff --git a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/storage/LocalFileStorage.java b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/storage/LocalFileStorage.java index f26114ca..8cd2dba9 100644 --- a/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/storage/LocalFileStorage.java +++ b/web/documentserver-example/java-spring/src/main/java/com/onlyoffice/integration/documentserver/storage/LocalFileStorage.java @@ -85,10 +85,18 @@ public class LocalFileStorage implements FileStorageMutator, FileStoragePathBuil // get the storage directory public String getStorageLocation(){ String serverPath = System.getProperty("user.dir"); // get the path to the server - String directory = serverPath // create the storage directory - + File.separator + storageFolder - + File.separator + this.storageAddress - + File.separator; + String directory; // create the storage directory + if (Paths.get(this.storageAddress).isAbsolute()) { + directory = this.storageAddress + File.separator; + } else { + directory = serverPath + + File.separator + storageFolder + + File.separator + this.storageAddress + + File.separator; + } + if (!Files.exists(Paths.get(directory))) { + createDirectory(Paths.get(directory)); + } return directory; } 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 3294c3ad..a9d3b2a4 100755 --- a/web/documentserver-example/java-spring/src/main/resources/application.properties +++ b/web/documentserver-example/java-spring/src/main/resources/application.properties @@ -1,6 +1,6 @@ server.version=1.1.0 -server.address=127.0.0.1 +server.address= server.port=4000 filesize-max=5242880 diff --git a/web/documentserver-example/java-spring/src/main/resources/static/css/stylesheet.css b/web/documentserver-example/java-spring/src/main/resources/static/css/stylesheet.css index dde198c4..778a851a 100755 --- a/web/documentserver-example/java-spring/src/main/resources/static/css/stylesheet.css +++ b/web/documentserver-example/java-spring/src/main/resources/static/css/stylesheet.css @@ -98,6 +98,10 @@ header img { width: 896px; } +#portal-info { + max-width: 65vw; +} + .portal-name { color: #FF6F3D; font-size: 24px; diff --git a/web/documentserver-example/java-spring/src/main/resources/templates/index.html b/web/documentserver-example/java-spring/src/main/resources/templates/index.html index a0786f45..384eddd6 100755 --- a/web/documentserver-example/java-spring/src/main/resources/templates/index.html +++ b/web/documentserver-example/java-spring/src/main/resources/templates/index.html @@ -127,7 +127,7 @@
-
+ -
- -
diff --git a/web/documentserver-example/java/Dockerfile b/web/documentserver-example/java/Dockerfile new file mode 100644 index 00000000..14529802 --- /dev/null +++ b/web/documentserver-example/java/Dockerfile @@ -0,0 +1,9 @@ +FROM maven:3.6.1-jdk-8-alpine AS MVN_BLDR +COPY pom.xml /tmp/ +COPY src /tmp/src/ +WORKDIR /tmp/ +RUN mvn package + +FROM tomcat:alpine +RUN rm -fr /usr/local/tomcat/webapps/ROOT +COPY --from=MVN_BLDR /tmp/target/*.war $CATALINA_HOME/webapps/ROOT.war diff --git a/web/documentserver-example/java/README.md b/web/documentserver-example/java/README.md index 03a5f2e6..fc28bbd4 100644 --- a/web/documentserver-example/java/README.md +++ b/web/documentserver-example/java/README.md @@ -16,13 +16,14 @@ See the detailed guide to learn how to [install Document Server for Windows](htt Download the [Java example](https://api.onlyoffice.com/editors/demopreview) from our site. -To connect the editors to your website, specify the path to the editors installation in the *\src\main\resources\settings.properties* file: +To connect the editors to your website, specify the path to the editors installation and the path to the storage folder in the *\src\main\resources\settings.properties* file: ``` +storage-folder = app_data files.docservice.url.site=https://documentserver/ ``` -where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. +where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed and the **storage-folder** 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 *\src\main\webapp\editor.jsp* file. @@ -163,13 +164,17 @@ See the detailed guide to learn how to [install Document Server for Linux](https nano src/main/resources/settings.properties ``` - Edit the following line: + Edit the following lines: ``` + storage-folder = app_data files.docservice.url.site=https://documentserver/ ``` - where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. + where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed and the **storage-folder** is the path where files will be created and stored. Please note that you must have read and write permissions to the folder. If you do not have them, please use the next command: + ``` + sudo chmod -R ugo+rw /{path} + ``` 5. Install **Maven**: @@ -238,13 +243,14 @@ Make sure that the Document Server has access to the server with the example ins nano src/main/resources/settings.properties ``` -2. Edit the following line: +2. Edit the following lines: ``` + storage-folder = app_data files.docservice.url.site=https://documentserver/ ``` - where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. + where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed and the **storage-folder** is the path where files will be created and stored. 3. Run the next command in the Java example directory: diff --git a/web/documentserver-example/java/docker-compose.yml b/web/documentserver-example/java/docker-compose.yml index 923730d9..8ed9f575 100644 --- a/web/documentserver-example/java/docker-compose.yml +++ b/web/documentserver-example/java/docker-compose.yml @@ -1,7 +1,9 @@ version: '3' services: - build: - image: maven:3.6 - volumes: - - .:/java - command: mvn -f /java package + java-intg-ex: + build: + context: ./ + dockerfile: Dockerfile + ports: + - 8080:8080 + diff --git a/web/documentserver-example/java/src/main/java/controllers/EditorServlet.java b/web/documentserver-example/java/src/main/java/controllers/EditorServlet.java index 99153c4f..3a9cbc2f 100644 --- a/web/documentserver-example/java/src/main/java/controllers/EditorServlet.java +++ b/web/documentserver-example/java/src/main/java/controllers/EditorServlet.java @@ -72,7 +72,7 @@ public class EditorServlet extends HttpServlet // create file model (get all the necessary parameters from cookies) FileModel file = new FileModel(fileName, cm.getCookie("ulang"), request.getParameter("actionLink"), user); // change type parameter if needed - file.changeType(request.getParameter("mode"), request.getParameter("type"), user); + file.changeType(request.getParameter("mode"), request.getParameter("type"), user, fileName); // an image that will be inserted into the document Map dataInsertImage = new HashMap<>(); 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 e6b6d7af..2d05d342 100644 --- a/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java +++ b/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java @@ -440,8 +440,9 @@ public class IndexServlet extends HttpServlet try { String fileName = FileUtility.GetFileName(request.getParameter("fileName")); String userAddress = request.getParameter("userAddress"); + String isEmbedded = request.getParameter("dmode"); - if (DocumentManager.TokenEnabled()) { + if (DocumentManager.TokenEnabled() && isEmbedded == null) { String DocumentJwtHeader = ConfigManager.GetProperty("files.docservice.header"); diff --git a/web/documentserver-example/java/src/main/java/entities/FileModel.java b/web/documentserver-example/java/src/main/java/entities/FileModel.java index aedc2edb..7426ea64 100755 --- a/web/documentserver-example/java/src/main/java/entities/FileModel.java +++ b/web/documentserver-example/java/src/main/java/entities/FileModel.java @@ -18,10 +18,7 @@ package entities; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import helpers.ConfigManager; -import helpers.DocumentManager; -import helpers.FileUtility; -import helpers.ServiceConverter; +import helpers.*; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -29,6 +26,7 @@ import org.json.simple.parser.JSONParser; import java.io.File; import java.io.FileInputStream; import java.net.URLEncoder; +import java.text.SimpleDateFormat; import java.util.*; public class FileModel { @@ -51,7 +49,6 @@ public class FileModel { document = new Document(); document.title = fileName; document.url = DocumentManager.GetDownloadUrl(fileName); // get file url - document.urlUser = DocumentManager.GetFileUri(fileName, false); document.fileType = FileUtility.GetFileExtension(fileName).replace(".", ""); // get file extension from the file name // generate document key document.key = ServiceConverter.GenerateRevisionId(DocumentManager.CurUserHostAddress(null) + "/" + fileName + "/" + Long.toString(new File(DocumentManager.StoragePath(fileName, null)).lastModified())); @@ -91,7 +88,7 @@ public class FileModel { // write the absolute URL to the file location editorConfig.customization.goback.url = DocumentManager.GetServerUrl(false) + "/IndexServlet"; - changeType(mode, type, user); + changeType(mode, type, user, fileName); } // turn java objects into json strings @@ -101,7 +98,8 @@ public class FileModel { } // change the document type - public void changeType(String _mode, String _type, User user) { + public void changeType(String _mode, String _type, User user, String fileName) + { if (_mode != null) mode = _mode; if (_type != null) type = _type; @@ -121,11 +119,12 @@ public class FileModel { // set document permissions document.permissions = new Permissions(mode, type, canEdit, user); - if (type.equals("embedded")) InitDesktop(); // set parameters for the embedded document + if (type.equals("embedded")) InitDesktop(fileName); // set parameters for the embedded document } - public void InitDesktop() { - editorConfig.InitDesktop(document.urlUser); + public void InitDesktop(String fileName) + { + editorConfig.InitDesktop(DocumentManager.GetDownloadUrl(fileName) + "&dmode=emb"); } // generate document token @@ -199,8 +198,12 @@ public class FileModel { prevInfo.put("url", prev.get("url")); dataObj.put("previous", prevInfo); // write information about previous file version to the data object // write the path to the diff.zip archive with differences in this file version - dataObj.put("changesUrl", ConfigManager.GetProperty("files.docservice.url.example") + "/IndexServlet?version=" + i + "&histDir=" + URLEncoder.encode(histDir) + "&type=zip"); - // dataObj.put("changesUrl", DocumentManager.GetPathUri(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip")); + String storagePath = ConfigManager.GetProperty("storage-folder"); + String changesUrl = ConfigManager.GetProperty("files.docservice.url.example") + "/IndexServlet?version=" + i + "&histDir=" + URLEncoder.encode(histDir) + "&type=zip"; + if (new File(storagePath).isAbsolute()) { + changesUrl = DocumentManager.GetDownloadUrl((DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip").replace(storagePath, "")); + } + dataObj.put("changesUrl", changesUrl); } if (DocumentManager.TokenEnabled()) { dataObj.put("token", DocumentManager.CreateToken(dataObj)); @@ -245,7 +248,6 @@ public class FileModel { public class Document { public String title; public String url; - public String urlUser; public String fileType; public String key; public Info info; @@ -284,7 +286,14 @@ public class FileModel { // the Favorite icon state public class Info { + public String owner = "Me"; public Boolean favorite; + public String uploaded = getDate(); + + private String getDate() { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE MMM dd yyyy", Locale.US); + return simpleDateFormat.format(new Date()); + } } // the editor config parameters 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 b4665c1a..863c66e0 100644 --- a/web/documentserver-example/java/src/main/java/helpers/DocumentManager.java +++ b/web/documentserver-example/java/src/main/java/helpers/DocumentManager.java @@ -130,7 +130,20 @@ public class DocumentManager String hostAddress = CurUserHostAddress(userAddress); // get current user host address String serverPath = request.getSession().getServletContext().getRealPath(""); // get the server url String storagePath = ConfigManager.GetProperty("storage-folder"); // get the storage directory - String directory = serverPath + storagePath + File.separator + hostAddress + File.separator; + File f = new File(storagePath); + + if (f.isAbsolute()) { + if (!f.exists()) { + if (Files.isWritable(Paths.get(storagePath.substring(0, storagePath.lastIndexOf(File.separator))))) { + f.mkdirs(); + } else { + throw new SecurityException("No write permission to path: " + f.toPath()); + } + } else if (f.exists() && f.isFile()) { + throw new SecurityException("The path to the file is specified instead of the folder"); + } + } + String directory = !f.isAbsolute() ? serverPath + storagePath + File.separator + hostAddress + File.separator : storagePath + File.separator; File file = new File(directory); @@ -320,13 +333,20 @@ public class DocumentManager { String serverPath = GetServerUrl(forDocumentServer); String storagePath = ConfigManager.GetProperty("storage-folder"); + File f = new File(storagePath); String hostAddress = CurUserHostAddress(null); String filePath = serverPath + "/" + storagePath + "/" + hostAddress + "/" + URLEncoder.encode(fileName, java.nio.charset.StandardCharsets.UTF_8.toString()).replace("+", "%20"); + if (f.isAbsolute() && f.isFile()) { + filePath = GetDownloadUrl(fileName); + if (!Files.isWritable(f.toPath())) { + throw new SecurityException("No write permission to path: " + f.toPath()); + } + } return filePath; } - catch (UnsupportedEncodingException e) + catch (Exception e) { return ""; } diff --git a/web/documentserver-example/java/src/main/java/helpers/Users.java b/web/documentserver-example/java/src/main/java/helpers/Users.java index 8fec96ad..d9d3b698 100755 --- a/web/documentserver-example/java/src/main/java/helpers/Users.java +++ b/web/documentserver-example/java/src/main/java/helpers/Users.java @@ -64,7 +64,7 @@ public class Users { private static List users = new ArrayList() {{ add(new User("uid-1", "John Smith", "smith@example.com", - null, null, new CommentGroups(), + "", null, new CommentGroups(), null, new ArrayList(), descr_user_1, true)); add(new User("uid-2", "Mark Pottato", "pottato@example.com", "group-2", Arrays.asList("group-2", ""), new CommentGroups(null, Arrays.asList("group-2", ""), Arrays.asList("group-2")), @@ -73,7 +73,7 @@ public class Users { "group-3", Arrays.asList("group-2"), new CommentGroups(Arrays.asList("group-3", "group-2"), Arrays.asList("group-2"), new ArrayList()), false, Arrays.asList("copy", "download", "print"), descr_user_3, false)); add(new User("uid-0", null, null, - null, null, new CommentGroups(), + "", null, new CommentGroups(), null, new ArrayList(), descr_user_0, false)); }}; diff --git a/web/documentserver-example/java/src/main/webapp/css/media.css b/web/documentserver-example/java/src/main/webapp/css/media.css index 4d95b532..201fb82c 100644 --- a/web/documentserver-example/java/src/main/webapp/css/media.css +++ b/web/documentserver-example/java/src/main/webapp/css/media.css @@ -86,10 +86,6 @@ } @media (max-width: 1008px) { - #portal-info { - width: 65vw; - } - .left-panel { margin-left: 0; } @@ -299,6 +295,9 @@ .tableRow td:first-child { max-width: 17%; } + #portal-info { + max-width: 60vw; + } } .downloadContentCellShift:after { diff --git a/web/documentserver-example/java/src/main/webapp/css/stylesheet.css b/web/documentserver-example/java/src/main/webapp/css/stylesheet.css index cb68a6ee..815209ef 100644 --- a/web/documentserver-example/java/src/main/webapp/css/stylesheet.css +++ b/web/documentserver-example/java/src/main/webapp/css/stylesheet.css @@ -22,6 +22,7 @@ html { } body { + display: inline-table; background: #FFFFFF; color: #333333; font-family: Open Sans; @@ -71,6 +72,7 @@ header img { } .main{ + display: table; height: calc(100% - 112px); min-height: 536px; } @@ -97,6 +99,10 @@ header img { width: 896px; } +#portal-info { + max-width: 65vw; +} + .portal-name { color: #FF6F3D; font-size: 24px; diff --git a/web/documentserver-example/java/src/main/webapp/index.jsp b/web/documentserver-example/java/src/main/webapp/index.jsp index 6d0ca133..03504788 100644 --- a/web/documentserver-example/java/src/main/webapp/index.jsp +++ b/web/documentserver-example/java/src/main/webapp/index.jsp @@ -139,7 +139,7 @@ <% DocumentManager.Init(request, response); %> <% File[] files = DocumentManager.GetStoredFiles(null); %>
-
"> +
"> ONLYOFFICE Document Editors – Welcome! Get started with a demo-sample of ONLYOFFICE Document Editors, the first html5-based editors. @@ -180,7 +180,7 @@ Boolean canEdit = DocumentManager.GetEditedExts().contains(FileUtility.GetFileExtension(files[i].getName())); String version=" ["+DocumentManager.GetFileVersion(DocumentManager.HistoryDir(DocumentManager.StoragePath(files[i].getName(), null)))+"]"; %> - + " target="_blank"> <%= files[i].getName() %> @@ -215,9 +215,6 @@ <% } %> - <% if (!docType.equals("cell") && !docType.equals("word")) { %> - - <% } %> <% if (docType.equals("word")) { %> &type=desktop&mode=blockcontent" target="_blank"> diff --git a/web/documentserver-example/nodejs/README.md b/web/documentserver-example/nodejs/README.md index e2bf5032..5590fbed 100644 --- a/web/documentserver-example/nodejs/README.md +++ b/web/documentserver-example/nodejs/README.md @@ -16,13 +16,15 @@ See the detailed guide to learn how to [install Document Server for Windows](htt Download the [Node.js example](https://api.onlyoffice.com/editors/demopreview) from our site. -You need to connect the editors to your website. Specify the path to the editors installation in the *config/default.json* file: +To connect the editors to your website, specify the path to the editors installation and the path to the storage folder in the *config/default.json* file: ``` +"storageFolder": "./files" +"storagePath": "/files" "siteUrl": "https://documentserver/" ``` -where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. +where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed, the **storageFolder** and **storagePath** are the paths 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 *\views\editor.ejs* file. @@ -114,13 +116,18 @@ See the detailed guide to learn how to [install Document Server for Linux](https nano config/default.json ``` - Edit the following line: + Edit the following lines: ``` + "storageFolder": "./files" + "storagePath": "/files" "siteUrl": "https://documentserver/" ``` - where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. + where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed, the **storageFolder** and **storagePath** are the paths where files will be created and stored. Please note that you must have read and write permissions to the folder. If you do not have them, please use the next command: + ``` + sudo chmod -R ugo+rw /{path} + ``` 6. Run the project with Node.js: diff --git a/web/documentserver-example/nodejs/app.js b/web/documentserver-example/nodejs/app.js index 22cecb96..e8471578 100644 --- a/web/documentserver-example/nodejs/app.js +++ b/web/documentserver-example/nodejs/app.js @@ -123,8 +123,9 @@ app.get("/download", function (req, res) { // define a handler for downloading var fileName = fileUtility.getFileName(req.query.fileName); var userAddress = req.query.useraddress; + var isEmbedded = req.query.dmode; - if (cfgSignatureEnable && cfgSignatureUseForRequest) { + if ((cfgSignatureEnable && cfgSignatureUseForRequest) && isEmbedded == null ) { var authorization = req.get(cfgSignatureAuthorizationHeader); if (authorization && authorization.startsWith(cfgSignatureAuthorizationHeaderPrefix)) { var token = authorization.substring(cfgSignatureAuthorizationHeaderPrefix.length); @@ -185,7 +186,7 @@ app.post("/upload", function (req, res) { // define a handler for uploading fil docManager.storagePath(""); // mkdir if not exist const userIp = docManager.curUserHostAddress(); // get the path to the user host - const uploadDir = path.join(storageFolder, userIp); + const uploadDir = path.isAbsolute(storageFolder) ? storageFolder : path.join(storageFolder, userIp); const uploadDirTmp = path.join(uploadDir, 'tmp'); // and create directory for temporary files if it doesn't exist docManager.createDirectory(uploadDirTmp); @@ -771,7 +772,7 @@ app.get("/editor", function (req, res) { // define a handler for editing docume } var key = docManager.getKey(fileName); var url = docManager.getDownloadUrl(fileName); - var urlUser = docManager.getlocalFileUri(fileName, 0, false) + var urlUser = path.isAbsolute(storageFolder) ? docManager.getDownloadUrl(fileName) + "&dmode=emb" : docManager.getlocalFileUri(fileName, 0, false); var mode = req.query.mode || "edit"; // mode: view/edit/review/comment/fillForms/embedded var type = req.query.type || ""; // type: embedded/mobile/desktop if (type == "") { @@ -815,8 +816,8 @@ app.get("/editor", function (req, res) { // define a handler for editing docume key: historyData[i - 2].key, url: historyData[i - 2].url, }; - //historyD.changesUrl = docManager.getlocalFileUrFi(fileName, i - 1) + "/diff.zip"; // get the path to the diff.zip file and write it to the history object - historyD.changesUrl = `${docManager.getServerUrl(false)}/zip?path=${encodeURIComponent(diffFilePath)}` + let changesUrl = `${docManager.getServerUrl(false)}/zip?path=${encodeURIComponent(diffFilePath)}`; + historyD.changesUrl = changesUrl.includes("diff.zip") ? changesUrl : changesUrl + "/diff.zip"; // get the path to the diff.zip file and write it to the history object } historyData.push(historyD); diff --git a/web/documentserver-example/nodejs/helpers/docManager.js b/web/documentserver-example/nodejs/helpers/docManager.js index 385403cd..3c12609d 100644 --- a/web/documentserver-example/nodejs/helpers/docManager.js +++ b/web/documentserver-example/nodejs/helpers/docManager.js @@ -151,7 +151,12 @@ docManager.getFileUri = function (fileName) { docManager.getlocalFileUri = function (fileName, version, forDocumentServer) { const serverPath = docManager.getServerUrl(forDocumentServer); const hostAddress = docManager.curUserHostAddress(); - const url = serverPath + configServer.get("storagePath") + "/" + hostAddress + "/" + encodeURIComponent(fileName); // get full url address to the file + let url = serverPath + configServer.get("storagePath") + "/" + hostAddress + "/" + encodeURIComponent(fileName); // get full url address to the file + if (path.isAbsolute(configServer.get("storageFolder"))) { + let separator = configServer.get("storagePath").includes("/") ? "/" : "\\"; + url = docManager.getDownloadUrl(fileName + "-history" + separator + version + separator + "diff.zip"); + return url; + } if (!version) { return url; } @@ -208,14 +213,14 @@ docManager.getDownloadUrl = function (fileName) { // get the storage path of the given file docManager.storagePath = function (fileName, userAddress) { fileName = fileUtility.getFileName(fileName); // get the file name with extension - const directory = path.join(docManager.dir, docManager.curUserHostAddress(userAddress)); // get the path to the directory for the host address + const directory = path.isAbsolute(docManager.dir) ? docManager.dir : path.join(docManager.dir, docManager.curUserHostAddress(userAddress)); // get the path to the directory for the host address this.createDirectory(directory); // create a new directory if it doesn't exist return path.join(directory, fileName); // put the given file to this directory }; // get the path to the forcesaved file version docManager.forcesavePath = function (fileName, userAddress, create) { - let directory = path.join(docManager.dir, docManager.curUserHostAddress(userAddress)); + let directory = path.isAbsolute(docManager.dir) ? docManager.dir : path.join(docManager.dir, docManager.curUserHostAddress(userAddress)); if (!this.existsSync(directory)) { // the directory with host address doesn't exist return ""; } @@ -233,7 +238,7 @@ docManager.forcesavePath = function (fileName, userAddress, create) { // create the path to the file history docManager.historyPath = function (fileName, userAddress, create) { - let directory = path.join(docManager.dir, docManager.curUserHostAddress(userAddress)); + let directory = path.isAbsolute(docManager.dir) ? docManager.dir : path.join(docManager.dir, userAddress); if (!this.existsSync(directory)) { return ""; } @@ -278,7 +283,7 @@ docManager.changesUser = function (fileName, userAddress, version) { // get all the stored files docManager.getStoredFiles = function () { const userAddress = docManager.curUserHostAddress(); - const directory = path.join(docManager.dir, userAddress); + const directory = path.isAbsolute(docManager.dir) ? docManager.dir : path.join(docManager.dir, userAddress); this.createDirectory(directory); const result = []; const storedFiles = fileSystem.readdirSync(directory); // read the user host directory contents @@ -451,7 +456,7 @@ docManager.cleanFolderRecursive = function (folder, me) { // get files information docManager.getFilesInfo = function (fileId) { const userAddress = docManager.curUserHostAddress(); - const directory = path.join(docManager.dir, userAddress); + const directory = path.isAbsolute(docManager.dir) ? docManager.dir : path.join(docManager.dir, userAddress); const filesInDirectory = this.getStoredFiles(); // get all the stored files from the folder let responseArray = []; let responseObject; diff --git a/web/documentserver-example/nodejs/public/stylesheets/media.css b/web/documentserver-example/nodejs/public/stylesheets/media.css index 54840adc..bbcd8c19 100644 --- a/web/documentserver-example/nodejs/public/stylesheets/media.css +++ b/web/documentserver-example/nodejs/public/stylesheets/media.css @@ -87,10 +87,6 @@ } @media (max-width: 1008px) { - #portal-info { - width: 65vw; - } - .left-panel { margin-left: 0; } @@ -312,6 +308,9 @@ .tableRow td:first-child { max-width: 17%; } + #portal-info { + max-width: 60vw; + } } .downloadContentCellShift:after { diff --git a/web/documentserver-example/nodejs/public/stylesheets/stylesheet.css b/web/documentserver-example/nodejs/public/stylesheets/stylesheet.css index ca0c5a7a..7901ebda 100644 --- a/web/documentserver-example/nodejs/public/stylesheets/stylesheet.css +++ b/web/documentserver-example/nodejs/public/stylesheets/stylesheet.css @@ -97,6 +97,10 @@ header img { width: 896px; } +#portal-info { + max-width: 65vw; +} + .portal-name { color: #FF6F3D; font-size: 24px; diff --git a/web/documentserver-example/nodejs/views/index.ejs b/web/documentserver-example/nodejs/views/index.ejs index 067308df..e3aa5f41 100644 --- a/web/documentserver-example/nodejs/views/index.ejs +++ b/web/documentserver-example/nodejs/views/index.ejs @@ -133,7 +133,7 @@
-
"> +
"> ONLYOFFICE Document Editors – Welcome! Get started with a demo-sample of ONLYOFFICE Document Editors, the first html5-based editors. @@ -200,9 +200,6 @@ Open in editor without access to change the filter <% } %> - <% if (storedFiles[i].documentType !== "word" && storedFiles[i].documentType !== "cell") {%> - - <% } %> <% if (storedFiles[i].documentType == "word") { %> diff --git a/web/documentserver-example/php/README.md b/web/documentserver-example/php/README.md index b1964ff6..2c676d3c 100644 --- a/web/documentserver-example/php/README.md +++ b/web/documentserver-example/php/README.md @@ -16,13 +16,14 @@ See the detailed guide to learn how to [install Document Server for Windows](htt Download the [PHP example](https://api.onlyoffice.com/editors/demopreview) from our site. -You need to connect the editors to your website. Specify the path to the editors installation in the *config.php* file: +To connect the editors to your website, specify the path to the editors installation and the path to the storage folder in the *config.php* file: ``` +$GLOBALS['STORAGE_PATH'] = ""; $GLOBALS['DOC_SERV_SITE_URL'] = "https://documentserver/"; ``` -where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. +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. 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. @@ -147,13 +148,14 @@ See the detailed guide to learn how to [install Document Server for Linux](https nano config.php ``` - Edit the following line: + Edit the following lines: ``` + $GLOBALS['STORAGE_PATH'] = ""; $GLOBALS['DOC_SERV_SITE_URL'] = "https://documentserver/"; ``` - where the **documentserver** is the name of the server with the ONLYOFFICE Document Server installed. + 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. 5. Set permission for site: diff --git a/web/documentserver-example/php/common.php b/web/documentserver-example/php/common.php index b9cf8e5f..640a19e2 100644 --- a/web/documentserver-example/php/common.php +++ b/web/documentserver-example/php/common.php @@ -228,8 +228,7 @@ function getStoragePath($fileName, $userAddress = NULL) { mkdir($directory); } sendlog("getStoragePath result: " . $directory . basename($fileName), "common.log"); - return $directory . (strpos($fileName, DIRECTORY_SEPARATOR) || strpos($fileName, '\\') ? $fileName : basename($fileName)); -// return realpath($storagePath) === $storagePath ? $directory . $fileName : $directory . basename($fileName); + return realpath($storagePath) === $storagePath ? $directory . $fileName : $directory . (strpos($fileName, DIRECTORY_SEPARATOR) || strpos($fileName, '\\') ? $fileName : basename($fileName)); } // get the path to the forcesaved file version diff --git a/web/documentserver-example/php/css/media.css b/web/documentserver-example/php/css/media.css index 3f8f7f8a..dd5e2c72 100644 --- a/web/documentserver-example/php/css/media.css +++ b/web/documentserver-example/php/css/media.css @@ -87,10 +87,6 @@ } @media (max-width: 1008px) { - #portal-info { - width: 65vw; - } - .left-panel { margin-left: 0; } @@ -312,6 +308,10 @@ .tableRow td:first-child { max-width: 17%; } + + #portal-info { + max-width: 60vw; + } } .downloadContentCellShift:after { diff --git a/web/documentserver-example/php/css/stylesheet.css b/web/documentserver-example/php/css/stylesheet.css index ca73b5ad..43f84a32 100644 --- a/web/documentserver-example/php/css/stylesheet.css +++ b/web/documentserver-example/php/css/stylesheet.css @@ -22,6 +22,7 @@ html { } body { + display: inline-table; background: #FFFFFF; color: #333333; font-family: Open Sans; @@ -70,6 +71,7 @@ header img { } .main{ + display: table; height: calc(100% - 112px); min-height: 536px; } @@ -96,6 +98,10 @@ header img { width: 896px; } +#portal-info { + max-width: 65vw; +} + .portal-name { color: #FF6F3D; font-size: 24px; diff --git a/web/documentserver-example/php/doceditor.php b/web/documentserver-example/php/doceditor.php index cc1ff291..ef7697ab 100644 --- a/web/documentserver-example/php/doceditor.php +++ b/web/documentserver-example/php/doceditor.php @@ -49,7 +49,7 @@ if (!empty($_GET["fileExt"])) } $fileuri = FileUri($filename, true); -$fileuriUser = FileUri($filename); +$fileuriUser = realpath($GLOBALS['STORAGE_PATH']) === $GLOBALS['STORAGE_PATH'] ? getDownloadUrl($filename) . "&dmode=emb" : FileUri($filename); $docKey = getDocEditorKey($filename); $filetype = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); @@ -220,6 +220,7 @@ function getZipDownloadUri($changesURI) { // get document history function getHistory($filename, $filetype, $docKey, $fileuri) { + $storagePath = $GLOBALS['STORAGE_PATH']; $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) @@ -250,8 +251,12 @@ function getHistory($filename, $filetype, $docKey, $fileuri) { $prevFileName = $verDir . DIRECTORY_SEPARATOR . "prev." . $filetype; $prevFileName = substr($prevFileName, strlen(getStoragePath(""))); + $prevFileUrl = $i == $curVer ? $fileuri : getVirtualPath(true) . str_replace("%5C", "/", rawurlencode($prevFileName)); + if (realpath($storagePath) === $storagePath) { + $prevFileUrl = $i == $curVer ? getDownloadUrl($filename) : getDownloadUrl($prevFileName); + } $dataObj["key"] = $key; - $dataObj["url"] = $i == $curVer ? $fileuri : getVirtualPath(true) . str_replace("%5C", "/", rawurlencode($prevFileName)); // write file url to the data object + $dataObj["url"] = $prevFileUrl; // write file url to the data object $dataObj["version"] = $i; if ($i > 1) { // check if the version number is greater than 1 (the document was modified) @@ -268,12 +273,12 @@ function getHistory($filename, $filetype, $docKey, $fileuri) { "key" => $prev["key"], "url" => $prev["url"] ]; - - $changesUrl = getVersionDir($histDir, $i - 1) . DIRECTORY_SEPARATOR . "diff.zip"; - $changesUrl = substr($changesUrl, strlen(getStoragePath(""))); + $changesPath = getVersionDir($histDir, $i - 1) . DIRECTORY_SEPARATOR . "diff.zip"; + $changesPath = substr($changesPath, strlen(getStoragePath(""))); // write the path to the diff.zip archive with differences in this file version - $dataObj["changesUrl"] = getZipDownloadUri($changesUrl); + $changesUrl = realpath($storagePath) === $storagePath ? getDownloadUrl($changesPath) : getZipDownloadUri($changesUrl); + $dataObj["changesUrl"] = $changesUrl; } if (isJwtEnabled()) { diff --git a/web/documentserver-example/php/index.php b/web/documentserver-example/php/index.php index af19ccff..c3f5c89f 100644 --- a/web/documentserver-example/php/index.php +++ b/web/documentserver-example/php/index.php @@ -144,7 +144,7 @@ if (!empty($storedFiles)): ?>