diff --git a/common/ASC.MessagingSystem/MessageFactory.cs b/common/ASC.MessagingSystem/MessageFactory.cs index 125865b313..076b43609e 100644 --- a/common/ASC.MessagingSystem/MessageFactory.cs +++ b/common/ASC.MessagingSystem/MessageFactory.cs @@ -35,6 +35,7 @@ using ASC.Core; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; +using Microsoft.Extensions.Primitives; namespace ASC.MessagingSystem { @@ -81,7 +82,7 @@ namespace ASC.MessagingSystem } } - public EventMessage Create(MessageUserData userData, Dictionary headers, MessageAction action, MessageTarget target, params string[] description) + public EventMessage Create(MessageUserData userData, IDictionary headers, MessageAction action, MessageTarget target, params string[] description) { try { @@ -97,10 +98,10 @@ namespace ASC.MessagingSystem if (headers != null) { - var userAgent = headers.ContainsKey(userAgentHeader) ? headers[userAgentHeader] : null; - var forwarded = headers.ContainsKey(forwardedHeader) ? headers[forwardedHeader] : null; - var host = headers.ContainsKey(hostHeader) ? headers[hostHeader] : null; - var referer = headers.ContainsKey(refererHeader) ? headers[refererHeader] : null; + var userAgent = headers.ContainsKey(userAgentHeader) ? headers[userAgentHeader].ToString() : null; + var forwarded = headers.ContainsKey(forwardedHeader) ? headers[forwardedHeader].ToString() : null; + var host = headers.ContainsKey(hostHeader) ? headers[hostHeader].ToString() : null; + var referer = headers.ContainsKey(refererHeader) ? headers[refererHeader].ToString() : null; message.IP = forwarded ?? host; message.UAHeader = userAgent; diff --git a/common/ASC.MessagingSystem/MessageService.cs b/common/ASC.MessagingSystem/MessageService.cs index c756848ec4..176414ed7a 100644 --- a/common/ASC.MessagingSystem/MessageService.cs +++ b/common/ASC.MessagingSystem/MessageService.cs @@ -34,6 +34,7 @@ using ASC.MessagingSystem.DbSender; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Options; +using Microsoft.Extensions.Primitives; namespace ASC.MessagingSystem { @@ -212,27 +213,27 @@ namespace ASC.MessagingSystem #region HttpHeaders - public void Send(MessageUserData userData, Dictionary httpHeaders, MessageAction action) + public void Send(MessageUserData userData, IDictionary httpHeaders, MessageAction action) { SendHeadersMessage(userData, httpHeaders, action, null); } - public void Send(Dictionary httpHeaders, MessageAction action) + public void Send(IDictionary httpHeaders, MessageAction action) { SendHeadersMessage(null, httpHeaders, action, null); } - public void Send(Dictionary httpHeaders, MessageAction action, string d1) + public void Send(IDictionary httpHeaders, MessageAction action, string d1) { SendHeadersMessage(null, httpHeaders, action, null, d1); } - public void Send(Dictionary httpHeaders, MessageAction action, IEnumerable d1) + public void Send(IDictionary httpHeaders, MessageAction action, IEnumerable d1) { SendHeadersMessage(null, httpHeaders, action, null, d1?.ToArray()); } - public void Send(MessageUserData userData, Dictionary httpHeaders, MessageAction action, MessageTarget target) + public void Send(MessageUserData userData, IDictionary httpHeaders, MessageAction action, MessageTarget target) { SendHeadersMessage(userData, httpHeaders, action, target); } @@ -241,24 +242,24 @@ namespace ASC.MessagingSystem #region HttpHeaders & Target - public void Send(Dictionary httpHeaders, MessageAction action, MessageTarget target) + public void Send(IDictionary httpHeaders, MessageAction action, MessageTarget target) { SendHeadersMessage(null, httpHeaders, action, target); } - public void Send(Dictionary httpHeaders, MessageAction action, MessageTarget target, string d1) + public void Send(IDictionary httpHeaders, MessageAction action, MessageTarget target, string d1) { SendHeadersMessage(null, httpHeaders, action, target, d1); } - public void Send(Dictionary httpHeaders, MessageAction action, MessageTarget target, IEnumerable d1) + public void Send(IDictionary httpHeaders, MessageAction action, MessageTarget target, IEnumerable d1) { SendHeadersMessage(null, httpHeaders, action, target, d1?.ToArray()); } #endregion - private void SendHeadersMessage(MessageUserData userData, Dictionary httpHeaders, MessageAction action, MessageTarget target, params string[] description) + private void SendHeadersMessage(MessageUserData userData, IDictionary httpHeaders, MessageAction action, MessageTarget target, params string[] description) { if (sender == null) return; diff --git a/products/ASC.Files/Server/Core/FileStorageService.cs b/products/ASC.Files/Server/Core/FileStorageService.cs index e0ee86148d..4b570a319f 100644 --- a/products/ASC.Files/Server/Core/FileStorageService.cs +++ b/products/ASC.Files/Server/Core/FileStorageService.cs @@ -68,6 +68,7 @@ using ASC.Web.Files.Utils; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using Microsoft.Extensions.Primitives; using FileShare = ASC.Files.Core.Security.FileShare; using UrlShortener = ASC.Web.Core.Utility.UrlShortener; @@ -1009,7 +1010,7 @@ namespace ASC.Web.Files.Services.WCFService file = EntryManager.SaveEditing(fileId, null, url, null, doc, string.Format(FilesCommonResource.CommentRevertChanges, modifiedOnString)); } - FilesMessageService.Send(file, GetHttpHeaders(), MessageAction.FileRestoreVersion, file.Title, version.ToString(CultureInfo.InvariantCulture)); + FilesMessageService.Send(file, HttpContextAccessor?.HttpContext?.Request?.Headers, MessageAction.FileRestoreVersion, file.Title, version.ToString(CultureInfo.InvariantCulture)); fileDao = GetFileDao(); return new ItemList(fileDao.GetEditHistory(DocumentServiceHelper, file.ID)); @@ -2041,18 +2042,9 @@ namespace ASC.Web.Files.Services.WCFService return new InvalidOperationException(error.Message, error); } - private Dictionary GetHttpHeaders() + private IDictionary GetHttpHeaders() { - if (HttpContextAccessor?.HttpContext != null && HttpContextAccessor?.HttpContext.Request != null && HttpContextAccessor?.HttpContext.Request.Headers != null) - { - var headers = new Dictionary(); - foreach (var k in HttpContextAccessor?.HttpContext.Request.Headers) - { - headers[k.Key] = string.Join(", ", k.Value); - } - return headers; - } - return null; + return HttpContextAccessor?.HttpContext?.Request?.Headers; } } diff --git a/products/ASC.Files/Server/Helpers/DocuSignHelper.cs b/products/ASC.Files/Server/Helpers/DocuSignHelper.cs index ade0594fb4..79229b5842 100644 --- a/products/ASC.Files/Server/Helpers/DocuSignHelper.cs +++ b/products/ASC.Files/Server/Helpers/DocuSignHelper.cs @@ -60,7 +60,8 @@ using DocuSign.eSign.Model; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; - +using Microsoft.Extensions.Primitives; + using Newtonsoft.Json; namespace ASC.Web.Files.Helpers @@ -204,7 +205,7 @@ namespace ASC.Web.Files.Helpers return true; } - public string SendDocuSign(T fileId, DocuSignData docuSignData, Dictionary requestHeaders) + public string SendDocuSign(T fileId, DocuSignData docuSignData, IDictionary requestHeaders) { if (docuSignData == null) throw new ArgumentNullException("docuSignData"); var token = DocuSignToken.GetToken(); diff --git a/products/ASC.Files/Server/Helpers/FilesMessageService.cs b/products/ASC.Files/Server/Helpers/FilesMessageService.cs index 0cff17fafa..c59a411edb 100644 --- a/products/ASC.Files/Server/Helpers/FilesMessageService.cs +++ b/products/ASC.Files/Server/Helpers/FilesMessageService.cs @@ -33,6 +33,7 @@ using ASC.MessagingSystem; using Microsoft.AspNetCore.Http; using Microsoft.Extensions.Options; +using Microsoft.Extensions.Primitives; namespace ASC.Web.Files.Helpers { @@ -64,12 +65,12 @@ namespace ASC.Web.Files.Helpers HttpContextAccessor = httpContextAccessor; } - public void Send(Dictionary headers, MessageAction action) + public void Send(IDictionary headers, MessageAction action) { SendHeadersMessage(headers, action, null); } - public void Send(FileEntry entry, Dictionary headers, MessageAction action, params string[] description) + public void Send(FileEntry entry, IDictionary headers, MessageAction action, params string[] description) { // do not log actions in users folder if (entry == null || entry.RootFolderType == FolderType.USER) return; @@ -77,7 +78,7 @@ namespace ASC.Web.Files.Helpers SendHeadersMessage(headers, action, MessageTarget.Create(entry.ID), description); } - public void Send(FileEntry entry1, FileEntry entry2, Dictionary headers, MessageAction action, params string[] description) + public void Send(FileEntry entry1, FileEntry entry2, IDictionary headers, MessageAction action, params string[] description) { // do not log actions in users folder if (entry1 == null || entry2 == null || entry1.RootFolderType == FolderType.USER || entry2.RootFolderType == FolderType.USER) return; @@ -85,7 +86,7 @@ namespace ASC.Web.Files.Helpers SendHeadersMessage(headers, action, MessageTarget.Create(new[] { entry1.ID.ToString(), entry2.ID.ToString() }), description); } - private void SendHeadersMessage(Dictionary headers, MessageAction action, MessageTarget target, params string[] description) + private void SendHeadersMessage(IDictionary headers, MessageAction action, MessageTarget target, params string[] description) { if (headers == null) { diff --git a/products/ASC.Files/Server/Services/WCFService/FileOperations/FileDeleteOperation.cs b/products/ASC.Files/Server/Services/WCFService/FileOperations/FileDeleteOperation.cs index d1fcfa2c7f..0e30494e5a 100644 --- a/products/ASC.Files/Server/Services/WCFService/FileOperations/FileDeleteOperation.cs +++ b/products/ASC.Files/Server/Services/WCFService/FileOperations/FileDeleteOperation.cs @@ -37,6 +37,7 @@ using ASC.Web.Files.Helpers; using ASC.Web.Files.Utils; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Primitives; namespace ASC.Web.Files.Services.WCFService.FileOperations { @@ -44,16 +45,16 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations { public bool IgnoreException { get; } public bool Immediately { get; } - public Dictionary Headers { get; } + public IDictionary Headers { get; } public FileDeleteOperationData(IEnumerable folders, IEnumerable files, Tenant tenant, - bool holdResult = true, bool ignoreException = false, bool immediately = false, Dictionary headers = null) + bool holdResult = true, bool ignoreException = false, bool immediately = false, IDictionary headers = null) : this(folders.OfType(), files.OfType(), tenant, holdResult, ignoreException, immediately, headers) { } public FileDeleteOperationData(IEnumerable folders, IEnumerable files, Tenant tenant, - bool holdResult = true, bool ignoreException = false, bool immediately = false, Dictionary headers = null) + bool holdResult = true, bool ignoreException = false, bool immediately = false, IDictionary headers = null) : base(folders, files, tenant, holdResult) { IgnoreException = ignoreException; @@ -80,7 +81,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations private int _trashId; private readonly bool _ignoreException; private readonly bool _immediately; - private readonly Dictionary _headers; + private readonly IDictionary _headers; public override FileOperationType OperationType { diff --git a/products/ASC.Files/Server/Services/WCFService/FileOperations/FileDownloadOperation.cs b/products/ASC.Files/Server/Services/WCFService/FileOperations/FileDownloadOperation.cs index cf04059864..79572c04c0 100644 --- a/products/ASC.Files/Server/Services/WCFService/FileOperations/FileDownloadOperation.cs +++ b/products/ASC.Files/Server/Services/WCFService/FileOperations/FileDownloadOperation.cs @@ -47,15 +47,16 @@ using ASC.Web.Studio.Core; using Ionic.Zip; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Primitives; namespace ASC.Web.Files.Services.WCFService.FileOperations { internal class FileDownloadOperationData : FileOperationData { public Dictionary FilesDownload { get; } - public Dictionary Headers { get; } + public IDictionary Headers { get; } - public FileDownloadOperationData(Dictionary folders, Dictionary files, Tenant tenant, Dictionary headers, bool holdResult = true) + public FileDownloadOperationData(Dictionary folders, Dictionary files, Tenant tenant, IDictionary headers, bool holdResult = true) : base(folders.Select(f => f.Key).ToList(), files.Select(f => f.Key).ToList(), tenant, holdResult) { FilesDownload = files; @@ -117,7 +118,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations class FileDownloadOperation : FileOperation, T> { private readonly Dictionary files; - private readonly Dictionary headers; + private readonly IDictionary headers; ItemNameValueCollection entriesPathId; public override FileOperationType OperationType { diff --git a/products/ASC.Files/Server/Services/WCFService/FileOperations/FileMoveCopyOperation.cs b/products/ASC.Files/Server/Services/WCFService/FileOperations/FileMoveCopyOperation.cs index 12113fd195..b0b5005455 100644 --- a/products/ASC.Files/Server/Services/WCFService/FileOperations/FileMoveCopyOperation.cs +++ b/products/ASC.Files/Server/Services/WCFService/FileOperations/FileMoveCopyOperation.cs @@ -39,6 +39,7 @@ using ASC.Web.Files.Helpers; using ASC.Web.Files.Utils; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Primitives; namespace ASC.Web.Files.Services.WCFService.FileOperations { @@ -67,14 +68,14 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations public int DaoFolderId { get; } public bool Copy { get; } public FileConflictResolveType ResolveType { get; } - public Dictionary Headers { get; } + public IDictionary Headers { get; } - public FileMoveCopyOperationData(IEnumerable folders, IEnumerable files, Tenant tenant, JsonElement toFolderId, bool copy, FileConflictResolveType resolveType, bool holdResult = true, Dictionary headers = null) + public FileMoveCopyOperationData(IEnumerable folders, IEnumerable files, Tenant tenant, JsonElement toFolderId, bool copy, FileConflictResolveType resolveType, bool holdResult = true, IDictionary headers = null) : this(folders.OfType(), files.OfType(), tenant, toFolderId, copy, resolveType, holdResult, headers) { } - public FileMoveCopyOperationData(IEnumerable folders, IEnumerable files, Tenant tenant, JsonElement toFolderId, bool copy, FileConflictResolveType resolveType, bool holdResult = true, Dictionary headers = null) + public FileMoveCopyOperationData(IEnumerable folders, IEnumerable files, Tenant tenant, JsonElement toFolderId, bool copy, FileConflictResolveType resolveType, bool holdResult = true, IDictionary headers = null) : base(folders, files, tenant, holdResult) { if (toFolderId.ValueKind == JsonValueKind.String) @@ -99,7 +100,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations private readonly bool _copy; private readonly FileConflictResolveType _resolveType; - private readonly Dictionary _headers; + private readonly IDictionary _headers; public override FileOperationType OperationType { diff --git a/products/ASC.Files/Server/Services/WCFService/FileOperations/FileOperationsManager.cs b/products/ASC.Files/Server/Services/WCFService/FileOperations/FileOperationsManager.cs index 5ea75a013b..1c51e66333 100644 --- a/products/ASC.Files/Server/Services/WCFService/FileOperations/FileOperationsManager.cs +++ b/products/ASC.Files/Server/Services/WCFService/FileOperations/FileOperationsManager.cs @@ -34,7 +34,9 @@ using ASC.Common; using ASC.Common.Threading; using ASC.Core; using ASC.Files.Resources; - + +using Microsoft.Extensions.Primitives; + namespace ASC.Web.Files.Services.WCFService.FileOperations { public class FileOperationsManager @@ -109,7 +111,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations return QueueTask(authContext, op); } - public ItemList Download(AuthContext authContext, TenantManager tenantManager, Dictionary folders, Dictionary files, Dictionary headers) + public ItemList Download(AuthContext authContext, TenantManager tenantManager, Dictionary folders, Dictionary files, IDictionary headers) { var operations = tasks.GetTasks() .Where(t => t.GetProperty(FileOperation.OWNER) == authContext.CurrentAccount.ID) @@ -128,7 +130,7 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations return QueueTask(authContext, op); } - public ItemList MoveOrCopy(AuthContext authContext, TenantManager tenantManager, IEnumerable folders, IEnumerable files, JsonElement destFolderId, bool copy, FileConflictResolveType resolveType, bool holdResult, Dictionary headers) + public ItemList MoveOrCopy(AuthContext authContext, TenantManager tenantManager, IEnumerable folders, IEnumerable files, JsonElement destFolderId, bool copy, FileConflictResolveType resolveType, bool holdResult, IDictionary headers) { var tenant = tenantManager.GetCurrentTenant(); var op1 = new FileMoveCopyOperation(ServiceProvider, new FileMoveCopyOperationData(folders.Where(r => r.ValueKind == JsonValueKind.Number).Select(r => r.GetInt32()), files.Where(r => r.ValueKind == JsonValueKind.Number).Select(r => r.GetInt32()), tenant, destFolderId, copy, resolveType, holdResult, headers)); @@ -138,13 +140,13 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations return QueueTask(authContext, op); } - public ItemList Delete(AuthContext authContext, TenantManager tenantManager, IEnumerable folders, IEnumerable files, bool ignoreException, bool holdResult, bool immediately, Dictionary headers) + public ItemList Delete(AuthContext authContext, TenantManager tenantManager, IEnumerable folders, IEnumerable files, bool ignoreException, bool holdResult, bool immediately, IDictionary headers) { var op = new FileDeleteOperation(ServiceProvider, new FileDeleteOperationData(folders, files, tenantManager.GetCurrentTenant(), holdResult, ignoreException, immediately, headers)); return QueueTask(authContext, op); } - public ItemList Delete(AuthContext authContext, TenantManager tenantManager, IEnumerable folders, IEnumerable files, bool ignoreException, bool holdResult, bool immediately, Dictionary headers) + public ItemList Delete(AuthContext authContext, TenantManager tenantManager, IEnumerable folders, IEnumerable files, bool ignoreException, bool holdResult, bool immediately, IDictionary headers) { var op1 = new FileDeleteOperation(ServiceProvider, new FileDeleteOperationData(folders.Where(r => r.ValueKind == JsonValueKind.Number).Select(r => r.GetInt32()), files.Where(r => r.ValueKind == JsonValueKind.Number).Select(r => r.GetInt32()), tenantManager.GetCurrentTenant(), holdResult, ignoreException, immediately, headers)); var op2 = new FileDeleteOperation(ServiceProvider, new FileDeleteOperationData(folders.Where(r => r.ValueKind == JsonValueKind.String).Select(r => r.GetString()), files.Where(r => r.ValueKind == JsonValueKind.String).Select(r => r.GetString()), tenantManager.GetCurrentTenant(), holdResult, ignoreException, immediately, headers)); @@ -198,32 +200,32 @@ namespace ASC.Web.Files.Services.WCFService.FileOperations return FileOperationsManager.MarkAsRead(AuthContext, TenantManager, folderIds, fileIds); } - public ItemList Download(Dictionary folders, Dictionary files, Dictionary headers) + public ItemList Download(Dictionary folders, Dictionary files, IDictionary headers) { return FileOperationsManager.Download(AuthContext, TenantManager, folders, files, headers); } - public ItemList MoveOrCopy(IEnumerable folders, IEnumerable files, JsonElement destFolderId, bool copy, FileConflictResolveType resolveType, bool holdResult, Dictionary headers) + public ItemList MoveOrCopy(IEnumerable folders, IEnumerable files, JsonElement destFolderId, bool copy, FileConflictResolveType resolveType, bool holdResult, IDictionary headers) { return FileOperationsManager.MoveOrCopy(AuthContext, TenantManager, folders, files, destFolderId, copy, resolveType, holdResult, headers); } - public ItemList Delete(List folders, List files, bool ignoreException, bool holdResult, bool immediately, Dictionary headers) + public ItemList Delete(List folders, List files, bool ignoreException, bool holdResult, bool immediately, IDictionary headers) { return FileOperationsManager.Delete(AuthContext, TenantManager, folders, files, ignoreException, holdResult, immediately, headers); } - public ItemList Delete(List folders, List files, bool ignoreException, bool holdResult, bool immediately, Dictionary headers) + public ItemList Delete(List folders, List files, bool ignoreException, bool holdResult, bool immediately, IDictionary headers) { return FileOperationsManager.Delete(AuthContext, TenantManager, folders, files, ignoreException, holdResult, immediately, headers); } - public ItemList DeleteFile(T file, bool ignoreException, bool holdResult, bool immediately, Dictionary headers) + public ItemList DeleteFile(T file, bool ignoreException, bool holdResult, bool immediately, IDictionary headers) { return Delete(new List(), new List() { file }, ignoreException, holdResult, immediately, headers); } - public ItemList DeleteFolder(T folder, bool ignoreException, bool holdResult, bool immediately, Dictionary headers) + public ItemList DeleteFolder(T folder, bool ignoreException, bool holdResult, bool immediately, IDictionary headers) { return Delete(new List() { folder }, new List(), ignoreException, holdResult, immediately, headers); }