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 ece7e5c3..54f75f62 100644 --- a/web/documentserver-example/csharp-mvc/Helpers/DocManagerHelper.cs +++ b/web/documentserver-example/csharp-mvc/Helpers/DocManagerHelper.cs @@ -79,12 +79,21 @@ 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 history file version @@ -99,7 +108,16 @@ namespace OnlineEditorsExampleMVC.Helpers 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 ""; @@ -180,7 +198,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); @@ -236,8 +263,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 5c494cd6..1af7a132 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)); @@ -256,7 +258,18 @@ namespace OnlineEditorsExampleMVC.Models dataObj.Add("fileType", ext.Replace(".", "")); dataObj.Add("key", key); // write file url to the data object - dataObj.Add("url", i == currentVersion ? FileUri : DocManagerHelper.GetHistoryDownloadUrl(FileName,i.ToString(),"prev"+ext)); + string prevFileUrl; + 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 + "\\", "")); + } + 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) { @@ -280,7 +293,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.GetPathUri(Path.Combine(DocManagerHelper.VersionDir(histDir, i - 1), "diff.zip").Substring(HttpRuntime.AppDomainAppPath.Length))); + var changesUrl = Path.IsPathRooted(storagePath) ? DocManagerHelper.GetDownloadUrl(Path.Combine(DocManagerHelper.VersionDir(histDir, i - 1), "diff.zip").Replace(storagePath + "\\", "")) + : DocManagerHelper.GetPathUri(Path.Combine(DocManagerHelper.VersionDir(histDir, i - 1), "diff.zip").Substring(HttpRuntime.AppDomainAppPath.Length)); + 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 2a5c4931..d60ab62b 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/assets b/web/documentserver-example/csharp-mvc/assets index 589266f5..d66cdf5b 160000 --- a/web/documentserver-example/csharp-mvc/assets +++ b/web/documentserver-example/csharp-mvc/assets @@ -1 +1 @@ -Subproject commit 589266f57fbd6be588cccb82f9bb8c325a5a2e57 +Subproject commit d66cdf5b05313212e77567e12dfba18814383bd2 diff --git a/web/documentserver-example/csharp-mvc/web.appsettings.config b/web/documentserver-example/csharp-mvc/web.appsettings.config index e9802518..d648d827 100644 --- a/web/documentserver-example/csharp-mvc/web.appsettings.config +++ b/web/documentserver-example/csharp-mvc/web.appsettings.config @@ -1,10 +1,11 @@  - + - + + 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 e852baee..bb9e8da9 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,12 +146,21 @@ 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 history file version @@ -162,7 +173,16 @@ namespace OnlineEditorsExample // 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 ""; @@ -535,7 +555,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 66d9ff8e..f03cd1bb 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(); - } } // loading a page @@ -195,7 +192,7 @@ namespace OnlineEditorsExample "document", new Dictionary { { "title", FileName }, - { "url", getDownloadUrl }, + { "url", getDownloadUrl(FileName) }, { "fileType", ext.Trim('.') }, { "key", Key }, { @@ -318,6 +315,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)); @@ -357,7 +355,15 @@ namespace OnlineEditorsExample var ext = Path.GetExtension(FileName).ToLower(); dataObj.Add("fileType", ext.Replace(".", "")); dataObj.Add("key", key); - dataObj.Add("url", i == currentVersion ? FileUri : MakePublicHistoryUrl(FileName,i.ToString(),"prev"+ext)); // write file url to the data object + + // write file url to the data object + 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 + "\\", "")); + } + + 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) { @@ -381,7 +387,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"))); + var changesUrl = Path.IsPathRooted(storagePath) ? getDownloadUrl(Path.Combine(_Default.VersionDir(histDir, i - 1), "diff.zip").Replace(storagePath + "\\", "")) + : MakePublicUrl(Path.Combine(_Default.VersionDir(histDir, i - 1), "diff.zip")); + dataObj.Add("changesUrl", changesUrl); } if (JwtManager.Enabled) { @@ -505,7 +513,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 bb6a52c6..5a6474a3 100644 --- a/web/documentserver-example/csharp/WebEditor.ashx.cs +++ b/web/documentserver-example/csharp/WebEditor.ashx.cs @@ -274,10 +274,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/csharp/assets b/web/documentserver-example/csharp/assets index 589266f5..d66cdf5b 160000 --- a/web/documentserver-example/csharp/assets +++ b/web/documentserver-example/csharp/assets @@ -1 +1 @@ -Subproject commit 589266f57fbd6be588cccb82f9bb8c325a5a2e57 +Subproject commit d66cdf5b05313212e77567e12dfba18814383bd2 diff --git a/web/documentserver-example/csharp/settings.config b/web/documentserver-example/csharp/settings.config index f98711f6..56f01834 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/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 2c20ac7a..c11d6cce 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 a8869eb4..72a5d3ef 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 6fccee58..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.0.0 +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/assets b/web/documentserver-example/java-spring/src/main/resources/assets index 589266f5..d66cdf5b 160000 --- a/web/documentserver-example/java-spring/src/main/resources/assets +++ b/web/documentserver-example/java-spring/src/main/resources/assets @@ -1 +1 @@ -Subproject commit 589266f57fbd6be588cccb82f9bb8c325a5a2e57 +Subproject commit d66cdf5b05313212e77567e12dfba18814383bd2 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 73f5a54f..63df6e8a 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. @@ -167,13 +168,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**: @@ -242,13 +247,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 f4ab8596..b55b831c 100644 --- a/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java +++ b/web/documentserver-example/java/src/main/java/controllers/IndexServlet.java @@ -481,8 +481,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 d0dc4e93..8cfc90c1 100755 --- a/web/documentserver-example/java/src/main/java/entities/FileModel.java +++ b/web/documentserver-example/java/src/main/java/entities/FileModel.java @@ -20,16 +20,14 @@ package entities; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import helpers.DocumentManager; -import helpers.FileUtility; -import helpers.ServiceConverter; -import helpers.Users; +import helpers.*; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import java.io.File; import java.io.FileInputStream; +import java.text.SimpleDateFormat; import java.util.*; public class FileModel @@ -54,7 +52,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())); @@ -94,11 +91,11 @@ 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); } // 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; @@ -119,12 +116,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() + public void InitDesktop(String fileName) { - editorConfig.InitDesktop(document.urlUser); + editorConfig.InitDesktop(DocumentManager.GetDownloadUrl(fileName) + "&dmode=emb"); } // generate document token @@ -201,7 +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", DocumentManager.GetPathUri(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.zip")); + String storagePath = ConfigManager.GetProperty("storage-folder"); + String changesUrl = DocumentManager.GetPathUri(DocumentManager.VersionDir(histDir, i - 1) + File.separator + "diff.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()) @@ -248,7 +250,6 @@ public class FileModel { public String title; public String url; - public String urlUser; public String fileType; public String key; public Info info; @@ -290,7 +291,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 public class EditorConfig 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 ec956d27..10141325 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); @@ -337,13 +350,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/resources/assets b/web/documentserver-example/java/src/main/resources/assets index 589266f5..d66cdf5b 160000 --- a/web/documentserver-example/java/src/main/resources/assets +++ b/web/documentserver-example/java/src/main/resources/assets @@ -1 +1 @@ -Subproject commit 589266f57fbd6be588cccb82f9bb8c325a5a2e57 +Subproject commit d66cdf5b05313212e77567e12dfba18814383bd2 diff --git a/web/documentserver-example/java/src/main/resources/settings.properties b/web/documentserver-example/java/src/main/resources/settings.properties index 493c5a25..8a8a8b60 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.0.0 +version=1.1.0 filesize-max=5242880 storage-folder=app_data 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 0e357a2a..ed1600b8 100644 --- a/web/documentserver-example/nodejs/app.js +++ b/web/documentserver-example/nodejs/app.js @@ -144,8 +144,9 @@ app.get("/download", function(req, res) { // define a handler for downloading f 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); @@ -179,7 +180,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); @@ -765,7 +766,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 == "") { @@ -811,7 +812,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.getlocalFileUri(fileName, i-1) + "/diff.zip"; // get the path to the diff.zip file and write it to the history object + let changesUrl = docManager.getlocalFileUri(fileName, i-1); + 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/config/default.json b/web/documentserver-example/nodejs/config/default.json index ec446cd4..4f1548fb 100644 --- a/web/documentserver-example/nodejs/config/default.json +++ b/web/documentserver-example/nodejs/config/default.json @@ -1,5 +1,5 @@ { - "version": "1.0.0", + "version": "1.1.0", "log": { "appenders": [ { 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/assets b/web/documentserver-example/nodejs/public/assets index 589266f5..d66cdf5b 160000 --- a/web/documentserver-example/nodejs/public/assets +++ b/web/documentserver-example/nodejs/public/assets @@ -1 +1 @@ -Subproject commit 589266f57fbd6be588cccb82f9bb8c325a5a2e57 +Subproject commit d66cdf5b05313212e77567e12dfba18814383bd2 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/assets b/web/documentserver-example/php/assets index 589266f5..d66cdf5b 160000 --- a/web/documentserver-example/php/assets +++ b/web/documentserver-example/php/assets @@ -1 +1 @@ -Subproject commit 589266f57fbd6be588cccb82f9bb8c325a5a2e57 +Subproject commit d66cdf5b05313212e77567e12dfba18814383bd2 diff --git a/web/documentserver-example/php/common.php b/web/documentserver-example/php/common.php index 766f9c97..16b13248 100644 --- a/web/documentserver-example/php/common.php +++ b/web/documentserver-example/php/common.php @@ -200,7 +200,15 @@ function getScheme() { // get the storage path of the given file function getStoragePath($fileName, $userAddress = NULL) { $storagePath = trim(str_replace(array('/','\\'), DIRECTORY_SEPARATOR, $GLOBALS['STORAGE_PATH']), DIRECTORY_SEPARATOR); - $directory = __DIR__ . DIRECTORY_SEPARATOR . $storagePath; + if (!empty($storagePath) && !file_exists($storagePath) && !is_dir($storagePath)) { + mkdir($storagePath); + } + + if (realpath($storagePath) === $storagePath) { + $directory = $storagePath; + } else { + $directory = __DIR__ . DIRECTORY_SEPARATOR . $storagePath; + } if ($storagePath != "") { @@ -212,20 +220,27 @@ function getStoragePath($fileName, $userAddress = NULL) { } } - $directory = $directory . getCurUserHostAddress($userAddress) . DIRECTORY_SEPARATOR; + if (realpath($storagePath) !== $storagePath) { + $directory = $directory . getCurUserHostAddress($userAddress) . DIRECTORY_SEPARATOR; + } if (!file_exists($directory) && !is_dir($directory)) { mkdir($directory); } sendlog("getStoragePath result: " . $directory . basename($fileName), "common.log"); - return $directory . basename($fileName); + return realpath($storagePath) === $storagePath ? $directory . $fileName : $directory . basename($fileName); } // get the path to the forcesaved file version function getForcesavePath($fileName, $userAddress, $create) { $storagePath = trim(str_replace(array('/','\\'), DIRECTORY_SEPARATOR, $GLOBALS['STORAGE_PATH']), DIRECTORY_SEPARATOR); + // create the directory to this file version - $directory = __DIR__ . DIRECTORY_SEPARATOR . $storagePath . getCurUserHostAddress($userAddress) . DIRECTORY_SEPARATOR; + if (realpath($storagePath) === $storagePath) { + $directory = $storagePath . DIRECTORY_SEPARATOR; + } else { + $directory = __DIR__ . DIRECTORY_SEPARATOR . $storagePath . getCurUserHostAddress($userAddress) . DIRECTORY_SEPARATOR; + } if (!is_dir($directory)) return ""; @@ -233,8 +248,9 @@ function getForcesavePath($fileName, $userAddress, $create) { $directory = $directory . $fileName . "-hist" . DIRECTORY_SEPARATOR; if (!$create && !is_dir($directory)) return ""; - mkdir($directory); - + if (!file_exists($directory) && !is_dir($directory)) { + mkdir($directory); + } $directory = $directory . $fileName; if (!$create && !file_exists($directory)) return ""; @@ -275,7 +291,15 @@ function getFileVersion($histDir) { // get all the stored files from the folder function getStoredFiles() { $storagePath = trim(str_replace(array('/','\\'), DIRECTORY_SEPARATOR, $GLOBALS['STORAGE_PATH']), DIRECTORY_SEPARATOR); - $directory = __DIR__ . DIRECTORY_SEPARATOR . $storagePath; + if (!empty($storagePath) && !file_exists($storagePath) && !is_dir($storagePath)) { + mkdir($storagePath); + } + + if (realpath($storagePath) === $storagePath) { + $directory = $storagePath; + } else { + $directory = __DIR__ . DIRECTORY_SEPARATOR . $storagePath; + } // get the storage path and check if it exists $result = array(); @@ -288,7 +312,9 @@ function getStoredFiles() { } } - $directory = $directory . getCurUserHostAddress() . DIRECTORY_SEPARATOR; + if (realpath($storagePath) !== $storagePath) { + $directory = $directory . getCurUserHostAddress() . DIRECTORY_SEPARATOR; + } if (!file_exists($directory) && !is_dir($directory)) { return $result; @@ -320,7 +346,11 @@ function getVirtualPath($forDocumentServer) { $storagePath = $storagePath != "" ? $storagePath . '/' : ""; - $virtPath = serverPath($forDocumentServer) . '/' . $storagePath . getCurUserHostAddress() . '/'; + if (realpath($storagePath) === $storagePath) { + $virtPath = serverPath($forDocumentServer) . '/' . $storagePath . '/'; + } else { + $virtPath = serverPath($forDocumentServer) . '/' . $storagePath . getCurUserHostAddress() . '/'; + } sendlog("getVirtualPath virtPath: " . $virtPath, "common.log"); return $virtPath; } diff --git a/web/documentserver-example/php/config.php b/web/documentserver-example/php/config.php index 7f83cfb3..0a6c1ef8 100644 --- a/web/documentserver-example/php/config.php +++ b/web/documentserver-example/php/config.php @@ -1,6 +1,6 @@ 0) { // check if the file was modified (the file version is greater than 0) @@ -248,16 +249,21 @@ $fileExe = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); $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["fileType"] = $fileExe; $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) $changes = json_decode(file_get_contents(getVersionDir($histDir, $i - 1) . DIRECTORY_SEPARATOR . "changes.json"), true); // get the path to the changes.json file $change = $changes["changes"][0]; - $obj["changes"] = $change ? $changes["changes"][0] : null; // write information about changes to the object + $obj["changes"] = $changes ? $changes["changes"] : null; // write information about changes to the object $obj["serverVersion"] = $changes["serverVersion"]; $obj["created"] = $change ? $change["created"] : null; $obj["user"] = $change ? $change["user"] : null; @@ -268,11 +274,12 @@ "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"] = getVirtualPath(true) . str_replace("%5C", "/", rawurlencode($changesUrl)); + $changesUrl = realpath($storagePath) === $storagePath ? getDownloadUrl($changesPath) : getVirtualPath(true) . str_replace("%5C", "/", rawurlencode($changesPath)) ; + $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)): ?>