encryption: add api start
This commit is contained in:
parent
7fae3bf83a
commit
7d3bb9e9a8
54
common/ASC.Core.Common/Tenants/TenantControlPanelSettings.cs
Normal file
54
common/ASC.Core.Common/Tenants/TenantControlPanelSettings.cs
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System Limited 2010-2018
|
||||
*
|
||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||
*
|
||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||
* in every copy of the program you distribute.
|
||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
using ASC.Core.Common.Settings;
|
||||
|
||||
namespace ASC.Core.Tenants
|
||||
{
|
||||
[Serializable]
|
||||
[DataContract]
|
||||
public class TenantControlPanelSettings : ISettings
|
||||
{
|
||||
[DataMember(Name = "LimitedAccess")]
|
||||
public bool LimitedAccess { get; set; }
|
||||
|
||||
public Guid ID
|
||||
{
|
||||
get { return new Guid("{880585C4-52CD-4AE2-8DA4-3B8E2772753B}"); }
|
||||
}
|
||||
|
||||
public ISettings GetDefault(IServiceProvider serviceProvider)
|
||||
{
|
||||
return new TenantControlPanelSettings
|
||||
{
|
||||
LimitedAccess = false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
@ -1,233 +1,267 @@
|
||||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System Limited 2010-2018
|
||||
*
|
||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||
*
|
||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||
* in every copy of the program you distribute.
|
||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace ASC.Core.Tenants
|
||||
{
|
||||
[DebuggerDisplay("{Name}")]
|
||||
public class TenantQuota : ICloneable
|
||||
{
|
||||
/*
|
||||
*
|
||||
* (c) Copyright Ascensio System Limited 2010-2018
|
||||
*
|
||||
* This program is freeware. You can redistribute it and/or modify it under the terms of the GNU
|
||||
* General Public License (GPL) version 3 as published by the Free Software Foundation (https://www.gnu.org/copyleft/gpl.html).
|
||||
* In accordance with Section 7(a) of the GNU GPL its Section 15 shall be amended to the effect that
|
||||
* Ascensio System SIA expressly excludes the warranty of non-infringement of any third-party rights.
|
||||
*
|
||||
* THIS PROGRAM IS DISTRIBUTED WITHOUT ANY WARRANTY; WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. For more details, see GNU GPL at https://www.gnu.org/copyleft/gpl.html
|
||||
*
|
||||
* You can contact Ascensio System SIA by email at sales@onlyoffice.com
|
||||
*
|
||||
* The interactive user interfaces in modified source and object code versions of ONLYOFFICE must display
|
||||
* Appropriate Legal Notices, as required under Section 5 of the GNU GPL version 3.
|
||||
*
|
||||
* Pursuant to Section 7 § 3(b) of the GNU GPL you must retain the original ONLYOFFICE logo which contains
|
||||
* relevant author attributions when distributing the software. If the display of the logo in its graphic
|
||||
* form is not reasonably feasible for technical reasons, you must include the words "Powered by ONLYOFFICE"
|
||||
* in every copy of the program you distribute.
|
||||
* Pursuant to Section 7 § 3(e) we decline to grant you any rights under trademark law for use of our trademarks.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
namespace ASC.Core.Tenants
|
||||
{
|
||||
[DebuggerDisplay("{Name}")]
|
||||
public class TenantQuota : ICloneable
|
||||
{
|
||||
public static readonly TenantQuota Default = new TenantQuota(Tenant.DEFAULT_TENANT)
|
||||
{
|
||||
Name = "Default",
|
||||
MaxFileSize = 25 * 1024 * 1024, // 25Mb
|
||||
MaxTotalSize = long.MaxValue,
|
||||
ActiveUsers = int.MaxValue,
|
||||
};
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public long MaxFileSize { get; set; }
|
||||
|
||||
public long MaxTotalSize { get; set; }
|
||||
|
||||
public int ActiveUsers { get; set; }
|
||||
|
||||
public string Features { get; set; }
|
||||
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public decimal Price2 { get; set; }
|
||||
|
||||
public string AvangateId { get; set; }
|
||||
|
||||
public bool Visible { get; set; }
|
||||
|
||||
public bool Year
|
||||
{
|
||||
get { return GetFeature("year"); }
|
||||
set { SetFeature("year", value); }
|
||||
}
|
||||
|
||||
public bool Year3
|
||||
{
|
||||
get { return GetFeature("year3"); }
|
||||
set { SetFeature("year3", value); }
|
||||
}
|
||||
|
||||
public bool NonProfit
|
||||
{
|
||||
get { return GetFeature("non-profit"); }
|
||||
set { SetFeature("non-profit", value); }
|
||||
}
|
||||
|
||||
public bool Trial
|
||||
{
|
||||
get { return GetFeature("trial"); }
|
||||
set { SetFeature("trial", value); }
|
||||
}
|
||||
|
||||
public bool Free
|
||||
{
|
||||
get { return GetFeature("free"); }
|
||||
set { SetFeature("free", value); }
|
||||
}
|
||||
|
||||
public bool Open
|
||||
{
|
||||
get { return GetFeature("open"); }
|
||||
set { SetFeature("open", value); }
|
||||
}
|
||||
|
||||
public bool ControlPanel
|
||||
{
|
||||
get { return GetFeature("controlpanel"); }
|
||||
set { SetFeature("controlpanel", value); }
|
||||
}
|
||||
|
||||
public bool Update
|
||||
{
|
||||
get { return GetFeature("update"); }
|
||||
set { SetFeature("update", value); }
|
||||
}
|
||||
|
||||
public bool Support
|
||||
{
|
||||
get { return GetFeature("support"); }
|
||||
set { SetFeature("support", value); }
|
||||
}
|
||||
|
||||
public bool Audit
|
||||
{
|
||||
get { return GetFeature("audit"); }
|
||||
set { SetFeature("audit", value); }
|
||||
}
|
||||
|
||||
public bool HasDomain
|
||||
{
|
||||
get { return GetFeature("domain"); }
|
||||
set { SetFeature("domain", value); }
|
||||
}
|
||||
|
||||
public bool HealthCheck
|
||||
{
|
||||
get { return GetFeature("healthcheck"); }
|
||||
set { SetFeature("healthcheck", value); }
|
||||
}
|
||||
|
||||
public bool HasMigration
|
||||
{
|
||||
get { return GetFeature("migration"); }
|
||||
set { SetFeature("migration", value); }
|
||||
}
|
||||
|
||||
public bool Ldap
|
||||
{
|
||||
get { return GetFeature("ldap"); }
|
||||
set { SetFeature("ldap", value); }
|
||||
}
|
||||
|
||||
public bool Sso
|
||||
{
|
||||
get { return GetFeature("sso"); }
|
||||
set { SetFeature("sso", value); }
|
||||
}
|
||||
|
||||
|
||||
public bool WhiteLabel
|
||||
{
|
||||
get { return GetFeature("whitelabel"); }
|
||||
set { SetFeature("whitelabel", value); }
|
||||
}
|
||||
|
||||
public int CountPortals
|
||||
{
|
||||
get
|
||||
{
|
||||
var features = (Features ?? string.Empty).Split(' ', ',', ';').ToList();
|
||||
var portals = features.FirstOrDefault(f => f.StartsWith("portals:"));
|
||||
if (portals == null || !int.TryParse(portals.Replace("portals:", ""), out var countPortals) || countPortals <= 0)
|
||||
{
|
||||
countPortals = 0;
|
||||
}
|
||||
return countPortals;
|
||||
}
|
||||
set
|
||||
{
|
||||
var features = (Features ?? string.Empty).Split(' ', ',', ';').ToList();
|
||||
var portals = features.FirstOrDefault(f => f.StartsWith("portals:"));
|
||||
features.Remove(portals);
|
||||
if (value > 0)
|
||||
{
|
||||
features.Add("portals:" + value);
|
||||
}
|
||||
Features = string.Join(",", features.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TenantQuota()
|
||||
{
|
||||
}
|
||||
public TenantQuota(int tenant)
|
||||
{
|
||||
Id = tenant;
|
||||
}
|
||||
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is TenantQuota q && q.Id == Id;
|
||||
}
|
||||
|
||||
|
||||
public bool GetFeature(string feature)
|
||||
{
|
||||
return !string.IsNullOrEmpty(Features) && Features.Split(' ', ',', ';').Contains(feature);
|
||||
}
|
||||
|
||||
internal void SetFeature(string feature, bool set)
|
||||
{
|
||||
var features = (Features == null
|
||||
? new string[] { }
|
||||
: Features.Split(' ', ',', ';')).ToList();
|
||||
if (set && !features.Contains(feature))
|
||||
{
|
||||
features.Add(feature);
|
||||
}
|
||||
else if (!set && features.Contains(feature))
|
||||
{
|
||||
features.Remove(feature);
|
||||
}
|
||||
Features = string.Join(",", features.ToArray());
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return MemberwiseClone();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public string Name { get; set; }
|
||||
|
||||
public long MaxFileSize { get; set; }
|
||||
|
||||
public long MaxTotalSize { get; set; }
|
||||
|
||||
public int ActiveUsers { get; set; }
|
||||
|
||||
public string Features { get; set; }
|
||||
|
||||
public decimal Price { get; set; }
|
||||
|
||||
public decimal Price2 { get; set; }
|
||||
|
||||
public string AvangateId { get; set; }
|
||||
|
||||
public bool Visible { get; set; }
|
||||
|
||||
public bool Year
|
||||
{
|
||||
get { return GetFeature("year"); }
|
||||
set { SetFeature("year", value); }
|
||||
}
|
||||
|
||||
public bool Year3
|
||||
{
|
||||
get { return GetFeature("year3"); }
|
||||
set { SetFeature("year3", value); }
|
||||
}
|
||||
|
||||
public bool NonProfit
|
||||
{
|
||||
get { return GetFeature("non-profit"); }
|
||||
set { SetFeature("non-profit", value); }
|
||||
}
|
||||
|
||||
public bool Trial
|
||||
{
|
||||
get { return GetFeature("trial"); }
|
||||
set { SetFeature("trial", value); }
|
||||
}
|
||||
|
||||
public bool Free
|
||||
{
|
||||
get { return GetFeature("free"); }
|
||||
set { SetFeature("free", value); }
|
||||
}
|
||||
|
||||
public bool Open
|
||||
{
|
||||
get { return GetFeature("open"); }
|
||||
set { SetFeature("open", value); }
|
||||
}
|
||||
|
||||
public bool ControlPanel
|
||||
{
|
||||
get { return GetFeature("controlpanel"); }
|
||||
set { SetFeature("controlpanel", value); }
|
||||
}
|
||||
|
||||
public bool Update
|
||||
{
|
||||
get { return GetFeature("update"); }
|
||||
set { SetFeature("update", value); }
|
||||
}
|
||||
|
||||
public bool Support
|
||||
{
|
||||
get { return GetFeature("support"); }
|
||||
set { SetFeature("support", value); }
|
||||
}
|
||||
|
||||
public bool Audit
|
||||
{
|
||||
get { return GetFeature("audit"); }
|
||||
set { SetFeature("audit", value); }
|
||||
}
|
||||
|
||||
public bool DocsEdition
|
||||
{
|
||||
get { return GetFeature("docs"); }
|
||||
set { SetFeature("docs", value); }
|
||||
}
|
||||
|
||||
public bool HasDomain
|
||||
{
|
||||
get { return GetFeature("domain"); }
|
||||
set { SetFeature("domain", value); }
|
||||
}
|
||||
|
||||
public bool HealthCheck
|
||||
{
|
||||
get { return GetFeature("healthcheck"); }
|
||||
set { SetFeature("healthcheck", value); }
|
||||
}
|
||||
|
||||
public bool HasMigration
|
||||
{
|
||||
get { return GetFeature("migration"); }
|
||||
set { SetFeature("migration", value); }
|
||||
}
|
||||
|
||||
public bool Ldap
|
||||
{
|
||||
get { return GetFeature("ldap"); }
|
||||
set { SetFeature("ldap", value); }
|
||||
}
|
||||
|
||||
public bool Sso
|
||||
{
|
||||
get { return GetFeature("sso"); }
|
||||
set { SetFeature("sso", value); }
|
||||
}
|
||||
|
||||
public bool Branding
|
||||
{
|
||||
get { return GetFeature("branding"); }
|
||||
set { SetFeature("branding", value); }
|
||||
}
|
||||
|
||||
public bool SSBranding
|
||||
{
|
||||
get { return GetFeature("ssbranding"); }
|
||||
set { SetFeature("ssbranding", value); }
|
||||
}
|
||||
|
||||
public bool WhiteLabel
|
||||
{
|
||||
get { return GetFeature("whitelabel"); }
|
||||
set { SetFeature("whitelabel", value); }
|
||||
}
|
||||
|
||||
public bool Customization
|
||||
{
|
||||
get { return GetFeature("customization"); }
|
||||
set { SetFeature("customization", value); }
|
||||
}
|
||||
|
||||
public bool DiscEncryption
|
||||
{
|
||||
get { return GetFeature("discencryption"); }
|
||||
set { SetFeature("discencryption", value); }
|
||||
}
|
||||
|
||||
public bool PrivacyRoom
|
||||
{
|
||||
get { return GetFeature("privacyroom"); }
|
||||
set { SetFeature("privacyroom", value); }
|
||||
}
|
||||
public int CountPortals
|
||||
{
|
||||
get
|
||||
{
|
||||
var features = (Features ?? string.Empty).Split(' ', ',', ';').ToList();
|
||||
var portals = features.FirstOrDefault(f => f.StartsWith("portals:"));
|
||||
if (portals == null || !int.TryParse(portals.Replace("portals:", ""), out var countPortals) || countPortals <= 0)
|
||||
{
|
||||
countPortals = 0;
|
||||
}
|
||||
return countPortals;
|
||||
}
|
||||
set
|
||||
{
|
||||
var features = (Features ?? string.Empty).Split(' ', ',', ';').ToList();
|
||||
var portals = features.FirstOrDefault(f => f.StartsWith("portals:"));
|
||||
features.Remove(portals);
|
||||
if (value > 0)
|
||||
{
|
||||
features.Add("portals:" + value);
|
||||
}
|
||||
Features = string.Join(",", features.ToArray());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public TenantQuota()
|
||||
{
|
||||
}
|
||||
public TenantQuota(int tenant)
|
||||
{
|
||||
Id = tenant;
|
||||
}
|
||||
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return Id.GetHashCode();
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is TenantQuota q && q.Id == Id;
|
||||
}
|
||||
|
||||
|
||||
public bool GetFeature(string feature)
|
||||
{
|
||||
return !string.IsNullOrEmpty(Features) && Features.Split(' ', ',', ';').Contains(feature);
|
||||
}
|
||||
|
||||
internal void SetFeature(string feature, bool set)
|
||||
{
|
||||
var features = (Features == null
|
||||
? new string[] { }
|
||||
: Features.Split(' ', ',', ';')).ToList();
|
||||
if (set && !features.Contains(feature))
|
||||
{
|
||||
features.Add(feature);
|
||||
}
|
||||
else if (!set && features.Contains(feature))
|
||||
{
|
||||
features.Remove(feature);
|
||||
}
|
||||
Features = string.Join(",", features.ToArray());
|
||||
}
|
||||
|
||||
public object Clone()
|
||||
{
|
||||
return MemberwiseClone();
|
||||
}
|
||||
}
|
||||
}
|
@ -70,7 +70,7 @@ namespace ASC.Data.Storage.Encryption
|
||||
|
||||
private CoreConfiguration CoreConfiguration { get; }
|
||||
private AscCacheNotify AscCacheNotify { get; }
|
||||
public InstanceCrypto InstanceCrypto { get; }
|
||||
private InstanceCrypto InstanceCrypto { get; }
|
||||
|
||||
public EncryptionSettingsHelper(CoreConfiguration coreConfiguration, AscCacheNotify ascCacheNotify, InstanceCrypto instanceCrypto)
|
||||
{
|
||||
@ -196,7 +196,7 @@ namespace ASC.Data.Storage.Encryption
|
||||
{
|
||||
public static DIHelper AddEncryptionSettingsHelperService(this DIHelper services)
|
||||
{
|
||||
services.TryAddSingleton<EncryptionSettingsHelper>();
|
||||
services.TryAddScoped<EncryptionSettingsHelper>();
|
||||
services.TryAddSingleton<AscCacheNotify>();
|
||||
return services
|
||||
.AddCoreConfigurationService();
|
||||
|
@ -506,6 +506,10 @@ namespace ASC.MessagingSystem
|
||||
|
||||
LicenseKeyUploaded = 5042,
|
||||
|
||||
StartStorageEncryption = 5050,
|
||||
|
||||
StartStorageDecryption = 5053,
|
||||
|
||||
#endregion
|
||||
|
||||
#region others
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="protos\BackupProgress.proto" />
|
||||
<None Remove="protos\DeleteSchedule.proto" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@ -32,6 +33,7 @@
|
||||
<ProjectReference Include="..\..\ASC.Data.Storage\ASC.Data.Storage.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Protobuf Include="protos\DeleteSchedule.proto" />
|
||||
<Protobuf Include="protos\BackupProgress.proto" />
|
||||
</ItemGroup>
|
||||
<Target Name="ChangeAliasesOfStrongNameAssemblies" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
|
||||
|
@ -30,6 +30,7 @@ using System.Threading.Tasks;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Utils;
|
||||
using ASC.Data.Backup.Listerners;
|
||||
using ASC.Web.Studio.Core.Notify;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -44,19 +45,22 @@ namespace ASC.Data.Backup.Service
|
||||
private BackupSchedulerService SchedulerService { get; set; }
|
||||
private BackupWorker BackupWorker { get; set; }
|
||||
private IConfiguration Configuration { get; set; }
|
||||
private BackupListener BackupListener { get; set; }
|
||||
|
||||
public BackupServiceLauncher(
|
||||
IServiceProvider serviceProvider,
|
||||
BackupCleanerService cleanerService,
|
||||
BackupSchedulerService schedulerService,
|
||||
BackupWorker backupWorker,
|
||||
IConfiguration configuration)
|
||||
IConfiguration configuration,
|
||||
BackupListener backupListener)
|
||||
{
|
||||
ServiceProvider = serviceProvider;
|
||||
CleanerService = cleanerService;
|
||||
SchedulerService = schedulerService;
|
||||
BackupWorker = backupWorker;
|
||||
Configuration = configuration;
|
||||
BackupListener = backupListener;
|
||||
}
|
||||
|
||||
public Task StartAsync(CancellationToken cancellationToken)
|
||||
@ -66,6 +70,7 @@ namespace ASC.Data.Backup.Service
|
||||
var settings = Configuration.GetSetting<BackupSettings>("backup");
|
||||
|
||||
BackupWorker.Start(settings);
|
||||
BackupListener.Start();
|
||||
|
||||
CleanerService.Period = settings.Cleaner.Period;
|
||||
CleanerService.Start();
|
||||
@ -79,6 +84,7 @@ namespace ASC.Data.Backup.Service
|
||||
public Task StopAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
BackupWorker.Stop();
|
||||
BackupListener.Stop();
|
||||
if (CleanerService != null)
|
||||
{
|
||||
CleanerService.Stop();
|
||||
|
38
common/services/ASC.Data.Backup/Listerners/BackupListener.cs
Normal file
38
common/services/ASC.Data.Backup/Listerners/BackupListener.cs
Normal file
@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
using ASC.Data.Backup.Service;
|
||||
|
||||
namespace ASC.Data.Backup.Listerners
|
||||
{
|
||||
public class BackupListener
|
||||
{
|
||||
private ICacheNotify<DeleteSchedule> CacheDeleteSchedule { get; }
|
||||
private BackupService BackupService { get; }
|
||||
|
||||
public BackupListener(ICacheNotify<DeleteSchedule> cacheDeleteSchedule, BackupService backupService)
|
||||
{
|
||||
CacheDeleteSchedule = cacheDeleteSchedule;
|
||||
BackupService = backupService;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
CacheDeleteSchedule.Subscribe((n) => DeleteScheldure(n), CacheNotifyAction.Insert);
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
CacheDeleteSchedule.Unsubscribe(CacheNotifyAction.Insert);
|
||||
}
|
||||
|
||||
public void DeleteScheldure(DeleteSchedule deleteSchedule)
|
||||
{
|
||||
BackupService.DeleteSchedule(deleteSchedule.TenantId);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
syntax = "proto3";
|
||||
|
||||
package ASC.Data.Backup.Contracts;
|
||||
|
||||
message DeleteSchedule {
|
||||
int32 TenantId = 1;
|
||||
}
|
@ -34,6 +34,7 @@
|
||||
<ProjectReference Include="..\..\common\ASC.Core.Common\ASC.Core.Common.csproj" />
|
||||
<ProjectReference Include="..\..\common\ASC.Data.Reassigns\ASC.Data.Reassigns.csproj" />
|
||||
<ProjectReference Include="..\..\common\ASC.Data.Storage\ASC.Data.Storage.csproj" />
|
||||
<ProjectReference Include="..\..\common\services\ASC.Data.Backup\ASC.Data.Backup.csproj" />
|
||||
<ProjectReference Include="..\ASC.Web.Core\ASC.Web.Core.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
|
@ -40,6 +40,7 @@ using ASC.Api.Collections;
|
||||
using ASC.Api.Core;
|
||||
using ASC.Api.Utils;
|
||||
using ASC.Common;
|
||||
using ASC.Common.Caching;
|
||||
using ASC.Common.Logging;
|
||||
using ASC.Common.Utils;
|
||||
using ASC.Common.Web;
|
||||
@ -49,6 +50,7 @@ using ASC.Core.Common.Configuration;
|
||||
using ASC.Core.Common.Settings;
|
||||
using ASC.Core.Tenants;
|
||||
using ASC.Core.Users;
|
||||
using ASC.Data.Backup.Contracts;
|
||||
using ASC.Data.Storage;
|
||||
using ASC.Data.Storage.Configuration;
|
||||
using ASC.Data.Storage.Encryption;
|
||||
@ -83,6 +85,7 @@ using ASC.Web.Studio.Utility;
|
||||
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
@ -151,7 +154,11 @@ namespace ASC.Api.Settings
|
||||
private StorageSettingsHelper StorageSettingsHelper { get; }
|
||||
private ServiceClient ServiceClient { get; }
|
||||
private EncryptionServiceClient EncryptionServiceClient { get; }
|
||||
private EncryptionSettingsHelper EncryptionSettingsHelper { get; }
|
||||
private ICacheNotify<BackupProgress> CacheBackupProgress { get; }
|
||||
private ICacheNotify<DeleteSchedule> CacheDeleteSchedule { get; }
|
||||
public ILog Log { get; set; }
|
||||
private Dictionary<int, BackupProgress> BackupProgresses = new Dictionary<int, BackupProgress>();
|
||||
|
||||
public SettingsController(
|
||||
IOptionsMonitor<ILog> option,
|
||||
@ -205,7 +212,10 @@ namespace ASC.Api.Settings
|
||||
IOptionsSnapshot<AccountLinker> accountLinker,
|
||||
FirstTimeTenantSettings firstTimeTenantSettings,
|
||||
ServiceClient serviceClient,
|
||||
EncryptionServiceClient encryptionServiceClient)
|
||||
EncryptionServiceClient encryptionServiceClient,
|
||||
EncryptionSettingsHelper encryptionSettingsHelper,
|
||||
ICacheNotify<BackupProgress> cacheBackupProgress,
|
||||
ICacheNotify<DeleteSchedule> cacheDeleteSchedule)
|
||||
{
|
||||
Log = option.Get("ASC.Api");
|
||||
WebHostEnvironment = webHostEnvironment;
|
||||
@ -259,6 +269,9 @@ namespace ASC.Api.Settings
|
||||
StorageSettingsHelper = storageSettingsHelper;
|
||||
ServiceClient = serviceClient;
|
||||
EncryptionServiceClient = encryptionServiceClient;
|
||||
EncryptionSettingsHelper = encryptionSettingsHelper;
|
||||
CacheBackupProgress = cacheBackupProgress;
|
||||
CacheDeleteSchedule = cacheDeleteSchedule;
|
||||
}
|
||||
|
||||
[Read("", Check = false)]
|
||||
@ -1631,6 +1644,137 @@ namespace ASC.Api.Settings
|
||||
EncryptionServiceClient.Start(encryptionSettingsProto);
|
||||
}
|
||||
|
||||
public readonly object Locker = new object();
|
||||
|
||||
[Create("encryption/start")]
|
||||
public void StartStorageEncryption(StorageEncryptionModel storageEncryption)
|
||||
{
|
||||
lock (Locker)
|
||||
{
|
||||
var activeTenants = TenantManager.GetTenants();
|
||||
|
||||
if (activeTenants.Any())
|
||||
{
|
||||
StartEncryption(storageEncryption.NotifyUsers);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void Save(BackupProgress backupProgress)
|
||||
{
|
||||
if (BackupProgresses.ContainsKey(backupProgress.TenantId))
|
||||
{
|
||||
BackupProgresses[backupProgress.TenantId] = backupProgress;
|
||||
}
|
||||
else
|
||||
{
|
||||
BackupProgresses.Add(backupProgress.TenantId, backupProgress);
|
||||
}
|
||||
}
|
||||
private void StartEncryption(bool notifyUsers)
|
||||
{
|
||||
CacheBackupProgress.Subscribe((n) => Save(n), CacheNotifyAction.Insert);
|
||||
if (!SetupInfo.IsVisibleSettings<EncryptionSettings>())
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
if (!CoreBaseSettings.Standalone)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
|
||||
|
||||
TenantExtra.DemandControlPanelPermission();
|
||||
|
||||
if (!TenantManager.GetTenantQuota(TenantManager.GetCurrentTenant().TenantId).DiscEncryption)
|
||||
{
|
||||
// throw new BillingException(Resource.ErrorNotAllowedOption, "DiscEncryption");
|
||||
}
|
||||
|
||||
var storages = GetAllStorages();
|
||||
|
||||
if (storages.Any(s => s.Current))
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
var cdnStorages = GetAllCdnStorages();
|
||||
|
||||
if (cdnStorages.Any(s => s.Current))
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
var tenants = TenantManager.GetTenants();
|
||||
|
||||
foreach (var tenant in tenants)
|
||||
{
|
||||
BackupProgress progress;
|
||||
BackupProgresses.TryGetValue(tenant.TenantId, out progress);
|
||||
if (progress != null && progress.IsCompleted == false)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var tenant in tenants)
|
||||
{
|
||||
CacheDeleteSchedule.Publish(new DeleteSchedule() { TenantId = tenant.TenantId }, CacheNotifyAction.Insert);
|
||||
}
|
||||
|
||||
var settings = EncryptionSettingsHelper.Load();
|
||||
|
||||
settings.NotifyUsers = notifyUsers;
|
||||
|
||||
if (settings.Status == EncryprtionStatus.Decrypted)
|
||||
{
|
||||
settings.Status = EncryprtionStatus.EncryptionStarted;
|
||||
settings.Password = EncryptionSettingsHelper.GeneratePassword(32, 16);
|
||||
}
|
||||
else if (settings.Status == EncryprtionStatus.Encrypted)
|
||||
{
|
||||
settings.Status = EncryprtionStatus.DecryptionStarted;
|
||||
}
|
||||
|
||||
MessageService.Send(settings.Status == EncryprtionStatus.EncryptionStarted ? MessageAction.StartStorageEncryption : MessageAction.StartStorageDecryption);
|
||||
|
||||
var serverRootPath = CommonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/');
|
||||
|
||||
foreach (var tenant in tenants)
|
||||
{
|
||||
TenantManager.SetCurrentTenant(tenant);
|
||||
|
||||
if (notifyUsers)
|
||||
{
|
||||
if (settings.Status == EncryprtionStatus.EncryptionStarted)
|
||||
{
|
||||
StudioNotifyService.SendStorageEncryptionStart(serverRootPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
StudioNotifyService.SendStorageDecryptionStart(serverRootPath);
|
||||
}
|
||||
}
|
||||
|
||||
tenant.SetStatus(TenantStatus.Encryption);
|
||||
TenantManager.SaveTenant(tenant);
|
||||
}
|
||||
|
||||
EncryptionSettingsHelper.Save(settings);
|
||||
|
||||
EncryptionSettingsProto encryptionSettingsProto = new EncryptionSettingsProto
|
||||
{
|
||||
NotifyUsers = settings.NotifyUsers,
|
||||
Password = settings.Password,
|
||||
Status = settings.Status,
|
||||
ServerRootPath = serverRootPath
|
||||
};
|
||||
CacheBackupProgress.Unsubscribe(CacheNotifyAction.Insert);
|
||||
EncryptionServiceClient.Start(encryptionSettingsProto);
|
||||
}
|
||||
|
||||
[Read("encryptionStop")]
|
||||
public void StopEncryption()
|
||||
{
|
||||
@ -1935,7 +2079,8 @@ namespace ASC.Api.Settings
|
||||
.AddFirstTimeTenantSettings()
|
||||
.AddServiceClient()
|
||||
.AddTwilioProviderService()
|
||||
.AddEncryptionServiceClient();
|
||||
.AddEncryptionServiceClient()
|
||||
.AddEncryptionSettingsHelperService();
|
||||
}
|
||||
}
|
||||
}
|
12
web/ASC.Web.Api/Models/StorageEncryptionModel.cs
Normal file
12
web/ASC.Web.Api/Models/StorageEncryptionModel.cs
Normal file
@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ASC.Web.Api.Models
|
||||
{
|
||||
public class StorageEncryptionModel
|
||||
{
|
||||
public bool NotifyUsers { get; set; }
|
||||
}
|
||||
}
|
@ -30,6 +30,7 @@ using System.Linq;
|
||||
|
||||
using ASC.Common;
|
||||
using ASC.Common.Web;
|
||||
using ASC.Common.Utils;
|
||||
using ASC.Core;
|
||||
using ASC.Core.Billing;
|
||||
using ASC.Core.Common.Settings;
|
||||
@ -40,6 +41,8 @@ using ASC.Web.Studio.Core;
|
||||
using ASC.Web.Studio.UserControls.Management;
|
||||
using ASC.Web.Studio.UserControls.Statistics;
|
||||
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
namespace ASC.Web.Studio.Utility
|
||||
{
|
||||
public class TenantExtra
|
||||
@ -53,6 +56,7 @@ namespace ASC.Web.Studio.Utility
|
||||
private LicenseReader LicenseReader { get; }
|
||||
private SetupInfo SetupInfo { get; }
|
||||
private SettingsManager SettingsManager { get; }
|
||||
private TenantControlPanelSettings TenantControlPanelSettings { get; }
|
||||
|
||||
public TenantExtra(
|
||||
UserManager userManager,
|
||||
@ -63,7 +67,8 @@ namespace ASC.Web.Studio.Utility
|
||||
CoreBaseSettings coreBaseSettings,
|
||||
LicenseReader licenseReader,
|
||||
SetupInfo setupInfo,
|
||||
SettingsManager settingsManager)
|
||||
SettingsManager settingsManager,
|
||||
IConfiguration configuration)
|
||||
{
|
||||
UserManager = userManager;
|
||||
TenantStatisticsProvider = tenantStatisticsProvider;
|
||||
@ -74,6 +79,7 @@ namespace ASC.Web.Studio.Utility
|
||||
LicenseReader = licenseReader;
|
||||
SetupInfo = setupInfo;
|
||||
SettingsManager = settingsManager;
|
||||
TenantControlPanelSettings = configuration.GetSetting<TenantControlPanelSettings>("TenantControlPanelSettings");
|
||||
}
|
||||
|
||||
public bool EnableTarrifSettings
|
||||
@ -243,6 +249,14 @@ namespace ASC.Web.Studio.Utility
|
||||
return SetupInfo.ChunkUploadSize;
|
||||
}
|
||||
}
|
||||
|
||||
public void DemandControlPanelPermission()
|
||||
{
|
||||
if (!CoreBaseSettings.Standalone || TenantControlPanelSettings.LimitedAccess)
|
||||
{
|
||||
throw new System.Security.SecurityException();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class TenantExtraExtension
|
||||
|
Loading…
Reference in New Issue
Block a user