From 62c6f366dfd93a415393014134fcea818ead5b21 Mon Sep 17 00:00:00 2001 From: SuhorukovAnton Date: Thu, 6 Oct 2022 15:51:15 +0300 Subject: [PATCH 1/2] fix local restore --- common/ASC.Data.Backup.Core/BackupAjaxHandler.cs | 2 +- .../BackupFileUploadHandler.cs | 9 +-------- common/services/ASC.Data.Backup/GlobalUsings.cs | 9 +++------ common/services/ASC.Data.Backup/Startup.cs | 14 ++++++++++++-- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs b/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs index 59de7d95f5..ad0960f45a 100644 --- a/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs +++ b/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs @@ -385,7 +385,7 @@ public class BackupAjaxHandler public string GetTmpFilePath() { - var folder = Path.Combine(_tempPath.GetTempPath(), BackupTempFolder, _tenantManager.GetCurrentTenant().Id.ToString()); + var folder = Path.Combine(_tempPath.GetTempPath().Replace("\\ASC.Data.Backup\\", "\\ASC.Data.Backup.BackgroundTasks\\"), BackupTempFolder, _tenantManager.GetCurrentTenant().Id.ToString()); if (!Directory.Exists(folder)) { diff --git a/common/ASC.Data.Backup.Core/BackupFileUploadHandler.cs b/common/ASC.Data.Backup.Core/BackupFileUploadHandler.cs index 181d1b8bb8..d387b36139 100644 --- a/common/ASC.Data.Backup.Core/BackupFileUploadHandler.cs +++ b/common/ASC.Data.Backup.Core/BackupFileUploadHandler.cs @@ -27,8 +27,7 @@ namespace ASC.Web.Studio.Core.Backup; public class BackupFileUploadHandler -{ - private const long MaxBackupFileSize = 1024L * 1024L * 1024L; +{ public BackupFileUploadHandler(RequestDelegate next) { @@ -53,12 +52,6 @@ public class BackupFileUploadHandler var file = context.Request.Form.Files[0]; - if (file.Length <= 0 || file.Length > MaxBackupFileSize) - { - result = Error($"File size must be greater than 0 and less than {MaxBackupFileSize} bytes"); - } - - var filePath = backupAjaxHandler.GetTmpFilePath(); if (File.Exists(filePath)) diff --git a/common/services/ASC.Data.Backup/GlobalUsings.cs b/common/services/ASC.Data.Backup/GlobalUsings.cs index 9423bc1dfc..e1f011542c 100644 --- a/common/services/ASC.Data.Backup/GlobalUsings.cs +++ b/common/services/ASC.Data.Backup/GlobalUsings.cs @@ -39,6 +39,7 @@ global using ASC.Data.Backup.ApiModels; global using ASC.Data.Backup.Contracts; global using ASC.Data.Backup.Core.IntegrationEvents.Events; global using ASC.Data.Backup.EF.Context; +global using ASC.Data.Backup.Extension; global using ASC.Data.Backup.Services; global using ASC.EventBus.Abstractions; global using ASC.Files.Core.EF; @@ -51,16 +52,12 @@ global using Autofac; global using Microsoft.AspNetCore.Builder; global using Microsoft.AspNetCore.Hosting; +global using Microsoft.AspNetCore.Http.Features; global using Microsoft.AspNetCore.Mvc; +global using Microsoft.AspNetCore.Server.Kestrel.Core; global using Microsoft.Extensions.Configuration; global using Microsoft.Extensions.DependencyInjection; global using Microsoft.Extensions.Hosting; global using Microsoft.Extensions.Hosting.WindowsServices; global using static ASC.Data.Backup.BackupAjaxHandler; - -global using ASC.Data.Backup.Extension; - -global using NLog.Extensions.Logging; -global using NLog.Web; -global using NLog.AWS.Logger; \ No newline at end of file diff --git a/common/services/ASC.Data.Backup/Startup.cs b/common/services/ASC.Data.Backup/Startup.cs index 0fd8242c7d..89e720b64c 100644 --- a/common/services/ASC.Data.Backup/Startup.cs +++ b/common/services/ASC.Data.Backup/Startup.cs @@ -22,8 +22,8 @@ // // All the Product's GUI elements, including illustrations and icon sets, as well as technical writing // content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 -// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode - +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + namespace ASC.Data.Backup; public class Startup : BaseStartup @@ -38,6 +38,16 @@ public class Startup : BaseStartup { base.ConfigureServices(services); + var maxRequestLimit = 1024L * 1024L * 1024L; + services.Configure(options => + { + options.Limits.MaxRequestBodySize = maxRequestLimit; + }); + services.Configure(x => + { + x.MultipartBodyLengthLimit = maxRequestLimit; + }); + services.AddBaseDbContextPool(); services.AddBaseDbContextPool(); From ded6b08e0ea8a57c3e79bc10bbbb37cb5092f7d9 Mon Sep 17 00:00:00 2001 From: SuhorukovAnton Date: Tue, 11 Oct 2022 15:29:23 +0300 Subject: [PATCH 2/2] fix GetTmpFilePath --- common/ASC.Data.Backup.Core/BackupAjaxHandler.cs | 16 ++++++++++------ common/ASC.Data.Backup.Core/GlobalUsings.cs | 2 +- config/storage.json | 8 ++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs b/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs index ad0960f45a..f7ab9eee9d 100644 --- a/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs +++ b/common/ASC.Data.Backup.Core/BackupAjaxHandler.cs @@ -22,8 +22,8 @@ // // All the Product's GUI elements, including illustrations and icon sets, as well as technical writing // content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 -// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode - +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + namespace ASC.Data.Backup; [Scope] @@ -40,8 +40,9 @@ public class BackupAjaxHandler private readonly ConsumerFactory _consumerFactory; private readonly BackupService _backupService; private readonly TempPath _tempPath; + private readonly StorageFactory _storageFactory; - private const string BackupTempFolder = "backup"; + private const string BackupTempModule = "backup_temp"; private const string BackupFileName = "backup.tmp"; #region backup @@ -57,7 +58,8 @@ public class BackupAjaxHandler UserManager userManager, TenantExtra tenantExtra, ConsumerFactory consumerFactory, - TempPath tempPath) + TempPath tempPath, + StorageFactory storageFactory) { _tenantManager = tenantManager; _messageService = messageService; @@ -69,7 +71,8 @@ public class BackupAjaxHandler _tenantExtra = tenantExtra; _consumerFactory = consumerFactory; _backupService = backupService; - _tempPath = tempPath; + _tempPath = tempPath; + _storageFactory = storageFactory; } public void StartBackup(BackupStorageType storageType, Dictionary storageParams) @@ -385,7 +388,8 @@ public class BackupAjaxHandler public string GetTmpFilePath() { - var folder = Path.Combine(_tempPath.GetTempPath().Replace("\\ASC.Data.Backup\\", "\\ASC.Data.Backup.BackgroundTasks\\"), BackupTempFolder, _tenantManager.GetCurrentTenant().Id.ToString()); + var discStore = _storageFactory.GetStorage("", _tenantManager.GetCurrentTenant().Id.ToString(), BackupTempModule, null) as DiscDataStore; + var folder = discStore.GetPhysicalPath("", ""); if (!Directory.Exists(folder)) { diff --git a/common/ASC.Data.Backup.Core/GlobalUsings.cs b/common/ASC.Data.Backup.Core/GlobalUsings.cs index 13b4eeec4d..c488a83300 100644 --- a/common/ASC.Data.Backup.Core/GlobalUsings.cs +++ b/common/ASC.Data.Backup.Core/GlobalUsings.cs @@ -72,6 +72,7 @@ global using ASC.Data.Backup.Tasks.Modules; global using ASC.Data.Backup.Utils; global using ASC.Data.Storage; global using ASC.Data.Storage.Configuration; +global using ASC.Data.Storage.DiscStorage; global using ASC.EventBus.Events; global using ASC.Files.Core; global using ASC.MessagingSystem.Core; @@ -103,6 +104,5 @@ global using Microsoft.Extensions.Logging; global using MySql.Data.MySqlClient; global using Newtonsoft.Json; -global using Newtonsoft.Json.Linq; global using ProtoBuf; diff --git a/config/storage.json b/config/storage.json index 7354eb00a5..33ab61c3ee 100644 --- a/config/storage.json +++ b/config/storage.json @@ -249,6 +249,14 @@ "virtualpath": "~/studio/{0}/backup", "expires": "0:10:0", "disableEncryption": true + }, + { + "name": "backup_temp", + "visible": false, + "type": "disc", + "path": "$STORAGE_ROOT\\Studio\\{0}\\temp\\backup", + "expires": "0:10:0", + "disableEncryption": true }, { "name": "customnavigation",