DocSpace-buildtools/web/ASC.Web.Api/Controllers/SettingsController.cs

1306 lines
52 KiB
C#
Raw Normal View History

2019-08-12 10:53:12 +00:00
/*
*
* (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.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.Linq;
using System.Net;
using System.ServiceModel.Security;
using System.Web;
2019-08-12 10:53:12 +00:00
using ASC.Api.Collections;
using ASC.Api.Core;
using ASC.Api.Utils;
using ASC.Common.Logging;
using ASC.Core;
using ASC.Core.Billing;
using ASC.Core.Common.Configuration;
using ASC.Core.Tenants;
using ASC.Core.Users;
2019-09-13 11:18:27 +00:00
using ASC.Data.Storage;
2019-08-12 10:53:12 +00:00
using ASC.Data.Storage.Configuration;
using ASC.Data.Storage.Migration;
using ASC.IPSecurity;
using ASC.MessagingSystem;
2019-09-17 12:42:32 +00:00
using ASC.Security.Cryptography;
2019-08-12 10:53:12 +00:00
using ASC.Web.Api.Models;
using ASC.Web.Api.Routing;
using ASC.Web.Core;
using ASC.Web.Core.PublicResources;
using ASC.Web.Core.Sms;
2019-09-09 12:56:33 +00:00
using ASC.Web.Core.Users;
2019-08-12 10:53:12 +00:00
using ASC.Web.Core.Utility;
using ASC.Web.Core.Utility.Settings;
using ASC.Web.Core.WebZones;
using ASC.Web.Core.WhiteLabel;
using ASC.Web.Studio.Core;
using ASC.Web.Studio.Core.Notify;
using ASC.Web.Studio.Core.Quota;
using ASC.Web.Studio.Core.SMS;
using ASC.Web.Studio.Core.Statistic;
using ASC.Web.Studio.Core.TFA;
using ASC.Web.Studio.UserControls.CustomNavigation;
2019-09-09 12:56:33 +00:00
using ASC.Web.Studio.UserControls.Statistics;
2019-08-12 10:53:12 +00:00
using ASC.Web.Studio.Utility;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
2019-09-23 12:20:08 +00:00
using Microsoft.Extensions.Configuration;
2019-08-12 10:53:12 +00:00
namespace ASC.Api.Settings
{
[DefaultRoute]
[ApiController]
public partial class SettingsController : ControllerBase
{
2019-10-14 08:23:45 +00:00
//private const int ONE_THREAD = 1;
2019-08-12 10:53:12 +00:00
2019-10-14 08:23:45 +00:00
//private static readonly DistributedTaskQueue quotaTasks = new DistributedTaskQueue("quotaOperations", ONE_THREAD);
//private static DistributedTaskQueue LDAPTasks { get; } = new DistributedTaskQueue("ldapOperations");
//private static DistributedTaskQueue SMTPTasks { get; } = new DistributedTaskQueue("smtpOperations");
2019-08-12 10:53:12 +00:00
public Tenant Tenant { get { return ApiContext.Tenant; } }
public ApiContext ApiContext { get; }
2019-09-18 12:14:15 +00:00
public IServiceProvider ServiceProvider { get; }
2019-08-12 10:53:12 +00:00
public LogManager LogManager { get; }
public MessageService MessageService { get; }
public StudioNotifyService StudioNotifyService { get; }
public IWebHostEnvironment WebHostEnvironment { get; }
2019-09-09 12:56:33 +00:00
public UserManager UserManager { get; }
public TenantManager TenantManager { get; }
public TenantExtra TenantExtra { get; }
public TenantStatisticsProvider TenantStatisticsProvider { get; }
public UserPhotoManager UserPhotoManager { get; }
public AuthContext AuthContext { get; }
public CookiesManager CookiesManager { get; }
public WebItemSecurity WebItemSecurity { get; }
public StudioNotifyHelper StudioNotifyHelper { get; }
public LicenseReader LicenseReader { get; }
public PermissionContext PermissionContext { get; }
2019-09-10 14:29:37 +00:00
public TfaAppUserSettings TfaAppUserSettings { get; }
public CollaboratorSettings CollaboratorSettings { get; }
public PersonalQuotaSettings PersonalQuotaSettings { get; }
public TfaManager TfaManager { get; }
public WebItemManager WebItemManager { get; }
public WebItemManagerSecurity WebItemManagerSecurity { get; }
2019-09-13 11:18:27 +00:00
public CdnStorageSettings CdnStorageSettings { get; }
public StorageSettings StorageSettings { get; }
public WizardSettings WizardSettings { get; }
public CustomNavigationSettings CustomNavigationSettings { get; }
public TenantInfoSettings TenantInfoSettings { get; }
public PasswordSettings PasswordSettings { get; }
public StudioDefaultPageSettings StudioDefaultPageSettings { get; }
public TenantWhiteLabelSettings TenantWhiteLabelSettings { get; }
public StudioSmsNotificationSettings StudioSmsNotificationSettings { get; }
public TfaAppAuthSettings TfaAppAuthSettings { get; }
public CompanyWhiteLabelSettings CompanyWhiteLabelSettings { get; }
public StorageHelper StorageHelper { get; }
public StorageFactory StorageFactory { get; }
public StorageFactoryConfig StorageFactoryConfig { get; }
2019-09-16 14:51:39 +00:00
public TenantLogoManager TenantLogoManager { get; }
2019-09-17 12:42:32 +00:00
public EmailValidationKeyProvider EmailValidationKeyProvider { get; }
public TenantUtil TenantUtil { get; }
2019-09-18 15:19:30 +00:00
public CoreBaseSettings CoreBaseSettings { get; }
2019-09-19 15:55:44 +00:00
public CommonLinkUtility CommonLinkUtility { get; }
2019-09-20 13:06:10 +00:00
public ColorThemesSettings ColorThemesSettings { get; }
2019-09-23 12:20:08 +00:00
public IConfiguration Configuration { get; }
public SetupInfo SetupInfo { get; }
2019-09-24 10:32:12 +00:00
public BuildVersion BuildVersion { get; }
public DisplayUserSettings DisplayUserSettings { get; }
2019-10-10 08:52:21 +00:00
public StatisticManager StatisticManager { get; }
public IPRestrictionsService IPRestrictionsService { get; }
2019-10-10 10:59:22 +00:00
public CoreConfiguration CoreConfiguration { get; }
2019-08-12 10:53:12 +00:00
2019-09-18 12:14:15 +00:00
public SettingsController(
IServiceProvider serviceProvider,
LogManager logManager,
2019-08-12 10:53:12 +00:00
MessageService messageService,
StudioNotifyService studioNotifyService,
2019-09-09 12:56:33 +00:00
ApiContext apiContext,
UserManager userManager,
TenantManager tenantManager,
TenantExtra tenantExtra,
TenantStatisticsProvider tenantStatisticsProvider,
UserPhotoManager userPhotoManager,
AuthContext authContext,
CookiesManager cookiesManager,
WebItemSecurity webItemSecurity,
StudioNotifyHelper studioNotifyHelper,
LicenseReader licenseReader,
2019-09-10 14:29:37 +00:00
PermissionContext permissionContext,
TfaAppUserSettings tfaAppUserSettings,
CollaboratorSettings collaboratorSettings,
PersonalQuotaSettings personalQuotaSettings,
TfaManager tfaManager,
WebItemManager webItemManager,
2019-09-13 11:18:27 +00:00
WebItemManagerSecurity webItemManagerSecurity,
CdnStorageSettings cdnStorageSettings,
StorageSettings storageSettings,
WizardSettings wizardSettings,
CustomNavigationSettings customNavigationSettings,
TenantInfoSettings tenantInfoSettings,
PasswordSettings passwordSettings,
StudioDefaultPageSettings studioDefaultPageSettings,
TenantWhiteLabelSettings tenantWhiteLabelSettings,
StudioSmsNotificationSettings studioSmsNotificationSettings,
TfaAppAuthSettings tfaAppAuthSettings,
CompanyWhiteLabelSettings companyWhiteLabelSettings,
StorageHelper storageHelper,
StorageFactory storageFactory,
2019-09-16 14:51:39 +00:00
StorageFactoryConfig storageFactoryConfig,
2019-09-17 12:42:32 +00:00
TenantLogoManager tenantLogoManager,
EmailValidationKeyProvider emailValidationKeyProvider,
2019-09-18 15:19:30 +00:00
TenantUtil tenantUtil,
2019-09-19 15:55:44 +00:00
CoreBaseSettings coreBaseSettings,
2019-09-20 13:06:10 +00:00
CommonLinkUtility commonLinkUtility,
2019-09-23 12:20:08 +00:00
ColorThemesSettings colorThemesSettings,
IConfiguration configuration,
2019-09-24 10:32:12 +00:00
SetupInfo setupInfo,
BuildVersion buildVersion,
2019-10-10 08:52:21 +00:00
DisplayUserSettings displayUserSettings,
StatisticManager statisticManager,
2019-10-10 10:59:22 +00:00
IPRestrictionsService iPRestrictionsService,
CoreConfiguration coreConfiguration)
2019-08-12 10:53:12 +00:00
{
2019-09-18 12:14:15 +00:00
ServiceProvider = serviceProvider;
2019-08-12 10:53:12 +00:00
LogManager = logManager;
MessageService = messageService;
StudioNotifyService = studioNotifyService;
ApiContext = apiContext;
2019-09-09 12:56:33 +00:00
UserManager = userManager;
TenantManager = tenantManager;
TenantExtra = tenantExtra;
TenantStatisticsProvider = tenantStatisticsProvider;
UserPhotoManager = userPhotoManager;
AuthContext = authContext;
CookiesManager = cookiesManager;
WebItemSecurity = webItemSecurity;
StudioNotifyHelper = studioNotifyHelper;
LicenseReader = licenseReader;
PermissionContext = permissionContext;
2019-09-10 14:29:37 +00:00
TfaAppUserSettings = tfaAppUserSettings;
CollaboratorSettings = collaboratorSettings;
PersonalQuotaSettings = personalQuotaSettings;
TfaManager = tfaManager;
WebItemManager = webItemManager;
WebItemManagerSecurity = webItemManagerSecurity;
2019-09-13 11:18:27 +00:00
CdnStorageSettings = cdnStorageSettings;
StorageSettings = storageSettings;
WizardSettings = wizardSettings;
CustomNavigationSettings = customNavigationSettings;
TenantInfoSettings = tenantInfoSettings;
PasswordSettings = passwordSettings;
StudioDefaultPageSettings = studioDefaultPageSettings;
TenantWhiteLabelSettings = tenantWhiteLabelSettings;
StudioSmsNotificationSettings = studioSmsNotificationSettings;
TfaAppAuthSettings = tfaAppAuthSettings;
CompanyWhiteLabelSettings = companyWhiteLabelSettings;
StorageHelper = storageHelper;
StorageFactory = storageFactory;
StorageFactoryConfig = storageFactoryConfig;
2019-09-16 14:51:39 +00:00
TenantLogoManager = tenantLogoManager;
2019-09-17 12:42:32 +00:00
EmailValidationKeyProvider = emailValidationKeyProvider;
TenantUtil = tenantUtil;
2019-09-18 15:19:30 +00:00
CoreBaseSettings = coreBaseSettings;
2019-09-19 15:55:44 +00:00
CommonLinkUtility = commonLinkUtility;
2019-09-20 13:06:10 +00:00
ColorThemesSettings = colorThemesSettings;
2019-09-23 12:20:08 +00:00
Configuration = configuration;
SetupInfo = setupInfo;
2019-09-24 10:32:12 +00:00
BuildVersion = buildVersion;
DisplayUserSettings = displayUserSettings;
2019-10-10 08:52:21 +00:00
StatisticManager = statisticManager;
IPRestrictionsService = iPRestrictionsService;
2019-10-10 10:59:22 +00:00
CoreConfiguration = coreConfiguration;
2019-08-12 10:53:12 +00:00
}
[Read("")]
2019-08-16 12:11:38 +00:00
[AllowAnonymous]
2019-08-12 10:53:12 +00:00
public SettingsWrapper GetSettings()
{
var settings = new SettingsWrapper
{
Culture = Tenant.GetCulture().ToString()
};
2019-08-16 12:11:38 +00:00
2019-09-09 12:56:33 +00:00
if (AuthContext.IsAuthenticated)
2019-08-16 12:11:38 +00:00
{
settings.TrustedDomains = Tenant.TrustedDomains;
settings.TrustedDomainsType = Tenant.TrustedDomainsType;
var timeZone = Tenant.TimeZone;
settings.Timezone = timeZone.ToSerializedString();
settings.UtcOffset = timeZone.GetUtcOffset(DateTime.UtcNow);
settings.UtcHoursOffset = settings.UtcOffset.TotalHours;
}
2019-08-12 10:53:12 +00:00
return settings;
}
[Read("quota")]
public QuotaWrapper GetQuotaUsed()
{
2019-10-10 10:59:22 +00:00
return new QuotaWrapper(Tenant, CoreBaseSettings, CoreConfiguration, TenantExtra, TenantStatisticsProvider, AuthContext, PersonalQuotaSettings, WebItemManager);
2019-08-12 10:53:12 +00:00
}
2019-09-23 13:19:01 +00:00
[AllowAnonymous]
[Read("cultures")]
public List<CultureInfo> GetSupportedCultures()
{
return SetupInfo.EnabledCultures;
}
2019-10-14 08:23:45 +00:00
//[Read("recalculatequota")]
//public void RecalculateQuota()
//{
// PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
2019-10-14 08:23:45 +00:00
// var operations = quotaTasks.GetTasks()
// .Where(t => t.GetProperty<int>(QuotaSync.TenantIdKey) == Tenant.TenantId);
2019-08-12 10:53:12 +00:00
2019-10-14 08:23:45 +00:00
// if (operations.Any(o => o.Status <= DistributedTaskStatus.Running))
// {
// throw new InvalidOperationException(Resource.LdapSettingsTooManyOperations);
// }
2019-08-12 10:53:12 +00:00
2019-10-14 08:23:45 +00:00
// var op = new QuotaSync(Tenant.TenantId, ServiceProvider);
2019-08-12 10:53:12 +00:00
2019-10-14 08:23:45 +00:00
// quotaTasks.QueueTask(op.RunJob, op.GetDistributedTask());
//}
2019-08-12 10:53:12 +00:00
2019-10-14 08:23:45 +00:00
//[Read("checkrecalculatequota")]
//public bool CheckRecalculateQuota()
//{
// PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
2019-10-14 08:23:45 +00:00
// var task = quotaTasks.GetTasks().FirstOrDefault(t => t.GetProperty<int>(QuotaSync.TenantIdKey) == Tenant.TenantId);
2019-08-12 10:53:12 +00:00
2019-10-14 08:23:45 +00:00
// if (task != null && task.Status == DistributedTaskStatus.Completed)
// {
// quotaTasks.RemoveTask(task.Id);
// return false;
// }
2019-08-12 10:53:12 +00:00
2019-10-14 08:23:45 +00:00
// return task != null;
//}
2019-08-12 10:53:12 +00:00
[AllowAnonymous]
[Read("version/build", false)]
public BuildVersion GetBuildVersions()
{
return BuildVersion.GetCurrentBuildVersion();
}
[Read("version")]
public TenantVersionWrapper GetVersions()
{
2019-09-09 12:56:33 +00:00
return new TenantVersionWrapper(Tenant.Version, TenantManager.GetTenantVersions());
2019-08-12 10:53:12 +00:00
}
[Update("version")]
public TenantVersionWrapper SetVersion(SettingsModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
2019-09-09 12:56:33 +00:00
TenantManager.GetTenantVersions().FirstOrDefault(r => r.Id == model.VersionId).NotFoundIfNull();
TenantManager.SetTenantVersion(Tenant, model.VersionId);
2019-08-12 10:53:12 +00:00
return GetVersions();
}
[Read("security")]
public IEnumerable<SecurityWrapper> GetWebItemSecurityInfo(IEnumerable<string> ids)
{
if (ids == null || !ids.Any())
{
ids = WebItemManager.GetItemsAll().Select(i => i.ID.ToString());
2019-08-12 10:53:12 +00:00
}
var subItemList = WebItemManager.GetItemsAll().Where(item => item.IsSubItem()).Select(i => i.ID.ToString());
2019-08-12 10:53:12 +00:00
return ids.Select(r => WebItemSecurity.GetSecurityInfo(r))
2019-08-12 10:53:12 +00:00
.Select(i => new SecurityWrapper
2019-08-15 12:04:42 +00:00
{
WebItemId = i.WebItemId,
Enabled = i.Enabled,
2019-09-24 10:32:12 +00:00
Users = i.Users.Select(r => EmployeeWraper.Get(r, ApiContext, DisplayUserSettings, UserPhotoManager, CommonLinkUtility)),
Groups = i.Groups.Select(g => new GroupWrapperSummary(g, UserManager)),
2019-08-15 12:04:42 +00:00
IsSubItem = subItemList.Contains(i.WebItemId),
}).ToList();
2019-08-12 10:53:12 +00:00
}
[Read("security/{id}")]
public bool GetWebItemSecurityInfo(Guid id)
{
var module = WebItemManager[id];
2019-08-12 10:53:12 +00:00
2019-09-16 14:51:39 +00:00
return module != null && !module.IsDisabled(WebItemSecurity, AuthContext);
2019-08-12 10:53:12 +00:00
}
[Read("security/modules")]
public object GetEnabledModules()
{
2019-09-16 14:51:39 +00:00
var EnabledModules = WebItemManagerSecurity.GetItems(WebZoneType.All, ItemAvailableState.Normal)
2019-08-12 10:53:12 +00:00
.Where(item => !item.IsSubItem() && item.Visible)
.ToList()
.Select(item => new
{
id = item.ProductClassName.HtmlEncode(),
title = item.Name.HtmlEncode()
});
return EnabledModules;
}
[Read("security/password")]
2019-09-10 12:42:15 +00:00
[Authorize(AuthenticationSchemes = "confirm")]
2019-08-12 10:53:12 +00:00
public object GetPasswordSettings()
{
var UserPasswordSettings = PasswordSettings.Load();
return UserPasswordSettings;
}
[Update("security")]
public IEnumerable<SecurityWrapper> SetWebItemSecurity(WebItemSecurityModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
WebItemSecurity.SetSecurity(model.Id, model.Enabled, model.Subjects?.ToArray());
var securityInfo = GetWebItemSecurityInfo(new List<string> { model.Id });
if (model.Subjects == null) return securityInfo;
var productName = GetProductName(new Guid(model.Id));
if (!model.Subjects.Any())
{
MessageService.Send(MessageAction.ProductAccessOpened, productName);
}
else
{
foreach (var info in securityInfo)
{
if (info.Groups.Any())
{
MessageService.Send(MessageAction.GroupsOpenedProductAccess, productName, info.Groups.Select(x => x.Name));
}
if (info.Users.Any())
{
MessageService.Send(MessageAction.UsersOpenedProductAccess, productName, info.Users.Select(x => HttpUtility.HtmlDecode(x.DisplayName)));
}
}
}
return securityInfo;
}
[Update("security/access")]
public IEnumerable<SecurityWrapper> SetAccessToWebItems(WebItemSecurityModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
var itemList = new ItemDictionary<string, bool>();
foreach (var item in model.Items)
{
if (!itemList.ContainsKey(item.Key))
itemList.Add(item.Key, item.Value);
}
var defaultPageSettings = StudioDefaultPageSettings.Load();
foreach (var item in itemList)
{
Guid[] subjects = null;
var productId = new Guid(item.Key);
if (item.Value)
{
if (WebItemManager[productId] is IProduct webItem)
2019-08-12 10:53:12 +00:00
{
var productInfo = WebItemSecurity.GetSecurityInfo(item.Key);
2019-08-12 10:53:12 +00:00
var selectedGroups = productInfo.Groups.Select(group => group.ID).ToList();
var selectedUsers = productInfo.Users.Select(user => user.ID).ToList();
selectedUsers.AddRange(selectedGroups);
if (selectedUsers.Count > 0)
{
subjects = selectedUsers.ToArray();
}
}
}
else if (productId == defaultPageSettings.DefaultProductID)
{
(defaultPageSettings.GetDefault() as StudioDefaultPageSettings).Save();
}
WebItemSecurity.SetSecurity(item.Key, item.Value, subjects);
}
MessageService.Send(MessageAction.ProductsListUpdated);
return GetWebItemSecurityInfo(itemList.Keys.ToList());
}
[Read("security/administrator/{productid}")]
public IEnumerable<EmployeeWraper> GetProductAdministrators(Guid productid)
{
return WebItemSecurity.GetProductAdministrators(productid)
2019-09-24 10:32:12 +00:00
.Select(r => EmployeeWraper.Get(r, ApiContext, DisplayUserSettings, UserPhotoManager, CommonLinkUtility))
2019-08-12 10:53:12 +00:00
.ToList();
}
[Read("security/administrator")]
public object IsProductAdministrator(Guid productid, Guid userid)
{
var result = WebItemSecurity.IsProductAdministrator(productid, userid);
2019-08-12 10:53:12 +00:00
return new { ProductId = productid, UserId = userid, Administrator = result, };
}
[Update("security/administrator")]
public object SetProductAdministrator(SecurityModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
WebItemSecurity.SetProductAdministrator(model.ProductId, model.UserId, model.Administrator);
2019-08-12 10:53:12 +00:00
2019-09-09 12:56:33 +00:00
var admin = UserManager.GetUsers(model.UserId);
2019-08-12 10:53:12 +00:00
if (model.ProductId == Guid.Empty)
{
var messageAction = model.Administrator ? MessageAction.AdministratorOpenedFullAccess : MessageAction.AdministratorDeleted;
2019-09-24 10:32:12 +00:00
MessageService.Send(messageAction, MessageTarget.Create(admin.ID), admin.DisplayUserName(false, DisplayUserSettings));
2019-08-12 10:53:12 +00:00
}
else
{
var messageAction = model.Administrator ? MessageAction.ProductAddedAdministrator : MessageAction.ProductDeletedAdministrator;
2019-09-24 10:32:12 +00:00
MessageService.Send(messageAction, MessageTarget.Create(admin.ID), GetProductName(model.ProductId), admin.DisplayUserName(false, DisplayUserSettings));
2019-08-12 10:53:12 +00:00
}
return new { model.ProductId, model.UserId, model.Administrator };
}
[Read("logo")]
public string GetLogo()
{
return TenantInfoSettings.Load().GetAbsoluteCompanyLogoPath();
}
///<visible>false</visible>
[Create("whitelabel/save")]
public void SaveWhiteLabelSettings(WhiteLabelModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
if (!TenantLogoManager.WhiteLabelEnabled || !TenantLogoManager.WhiteLabelPaid)
{
throw new BillingException(Resource.ErrorNotAllowedOption, "WhiteLabel");
}
var _tenantWhiteLabelSettings = TenantWhiteLabelSettings.Load();
if (model.Logo != null)
{
var logoDict = new Dictionary<int, string>();
model.Logo.ToList().ForEach(n => logoDict.Add(n.Key, n.Value));
_tenantWhiteLabelSettings.SetLogo(logoDict);
2019-08-12 10:53:12 +00:00
}
_tenantWhiteLabelSettings.LogoText = model.LogoText;
2019-09-16 14:51:39 +00:00
_tenantWhiteLabelSettings.Save(Tenant.TenantId, TenantLogoManager);
2019-08-12 10:53:12 +00:00
}
///<visible>false</visible>
[Create("whitelabel/savefromfiles")]
public void SaveWhiteLabelSettingsFromFiles(WhiteLabelModel model)
{
if (model.Attachments != null && model.Attachments.Any())
{
var _tenantWhiteLabelSettings = TenantWhiteLabelSettings.Load();
foreach (var f in model.Attachments)
{
var parts = f.FileName.Split('.');
var logoType = (WhiteLabelLogoTypeEnum)(Convert.ToInt32(parts[0]));
var fileExt = parts[1];
using var inputStream = f.OpenReadStream();
_tenantWhiteLabelSettings.SetLogoFromStream(logoType, fileExt, inputStream);
}
2019-09-16 14:51:39 +00:00
_tenantWhiteLabelSettings.Save(Tenant.TenantId, TenantLogoManager);
2019-08-12 10:53:12 +00:00
}
else
{
throw new InvalidOperationException("No input files");
}
}
///<visible>false</visible>
[Read("whitelabel/sizes")]
public object GetWhiteLabelSizes()
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
if (!TenantLogoManager.WhiteLabelEnabled)
{
throw new BillingException(Resource.ErrorNotAllowedOption, "WhiteLabel");
}
return
new[]
{
new {type = (int)WhiteLabelLogoTypeEnum.LightSmall, name = WhiteLabelLogoTypeEnum.LightSmall.ToString(), height = TenantWhiteLabelSettings.logoLightSmallSize.Height, width = TenantWhiteLabelSettings.logoLightSmallSize.Width},
new {type = (int)WhiteLabelLogoTypeEnum.Dark, name = WhiteLabelLogoTypeEnum.Dark.ToString(), height = TenantWhiteLabelSettings.logoDarkSize.Height, width = TenantWhiteLabelSettings.logoDarkSize.Width},
new {type = (int)WhiteLabelLogoTypeEnum.Favicon, name = WhiteLabelLogoTypeEnum.Favicon.ToString(), height = TenantWhiteLabelSettings.logoFaviconSize.Height, width = TenantWhiteLabelSettings.logoFaviconSize.Width},
new {type = (int)WhiteLabelLogoTypeEnum.DocsEditor, name = WhiteLabelLogoTypeEnum.DocsEditor.ToString(), height = TenantWhiteLabelSettings.logoDocsEditorSize.Height, width = TenantWhiteLabelSettings.logoDocsEditorSize.Width}
};
}
///<visible>false</visible>
[Read("whitelabel/logos")]
public Dictionary<int, string> GetWhiteLabelLogos(bool retina)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
if (!TenantLogoManager.WhiteLabelEnabled)
{
throw new BillingException(Resource.ErrorNotAllowedOption, "WhiteLabel");
}
var _tenantWhiteLabelSettings = TenantWhiteLabelSettings.Load();
var result = new Dictionary<int, string>
{
2019-09-19 15:55:44 +00:00
{ (int)WhiteLabelLogoTypeEnum.LightSmall, CommonLinkUtility.GetFullAbsolutePath(_tenantWhiteLabelSettings.GetAbsoluteLogoPath(WhiteLabelLogoTypeEnum.LightSmall, !retina)) },
{ (int)WhiteLabelLogoTypeEnum.Dark, CommonLinkUtility.GetFullAbsolutePath(_tenantWhiteLabelSettings.GetAbsoluteLogoPath(WhiteLabelLogoTypeEnum.Dark, !retina)) },
{ (int)WhiteLabelLogoTypeEnum.Favicon, CommonLinkUtility.GetFullAbsolutePath(_tenantWhiteLabelSettings.GetAbsoluteLogoPath(WhiteLabelLogoTypeEnum.Favicon, !retina)) },
{ (int)WhiteLabelLogoTypeEnum.DocsEditor, CommonLinkUtility.GetFullAbsolutePath(_tenantWhiteLabelSettings.GetAbsoluteLogoPath(WhiteLabelLogoTypeEnum.DocsEditor, !retina)) }
2019-08-12 10:53:12 +00:00
};
return result;
}
///<visible>false</visible>
[Read("whitelabel/logotext")]
public string GetWhiteLabelLogoText()
{
if (!TenantLogoManager.WhiteLabelEnabled)
{
throw new BillingException(Resource.ErrorNotAllowedOption, "WhiteLabel");
}
var whiteLabelSettings = TenantWhiteLabelSettings.Load();
return whiteLabelSettings.LogoText ?? TenantWhiteLabelSettings.DefaultLogoText;
}
///<visible>false</visible>
[Update("whitelabel/restore")]
public void RestoreWhiteLabelOptions()
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
if (!TenantLogoManager.WhiteLabelEnabled || !TenantLogoManager.WhiteLabelPaid)
{
throw new BillingException(Resource.ErrorNotAllowedOption, "WhiteLabel");
}
var _tenantWhiteLabelSettings = TenantWhiteLabelSettings.Load();
2019-09-16 14:51:39 +00:00
_tenantWhiteLabelSettings.RestoreDefault(TenantLogoManager);
2019-08-12 10:53:12 +00:00
var _tenantInfoSettings = TenantInfoSettings.Load();
2019-09-16 14:51:39 +00:00
_tenantInfoSettings.RestoreDefaultLogo(TenantLogoManager);
2019-08-12 10:53:12 +00:00
_tenantInfoSettings.Save();
}
[Read("iprestrictions")]
public IEnumerable<IPRestriction> GetIpRestrictions()
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
return IPRestrictionsService.Get(Tenant.TenantId);
}
[Update("iprestrictions")]
public IEnumerable<string> SaveIpRestrictions(IpRestrictionsModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
return IPRestrictionsService.Save(model.Ips, Tenant.TenantId);
}
[Update("iprestrictions/settings")]
public IPRestrictionsSettings UpdateIpRestrictionsSettings(IpRestrictionsModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
var settings = new IPRestrictionsSettings { Enable = model.Enable };
settings.Save();
return settings;
}
[Update("tips")]
public TipsSettings UpdateTipsSettings(SettingsModel model)
{
var settings = new TipsSettings { Show = model.Show };
settings.SaveForCurrentUser();
if (!model.Show && !string.IsNullOrEmpty(SetupInfo.TipsAddress))
{
try
{
using var client = new WebClient();
var data = new NameValueCollection
{
2019-09-09 12:56:33 +00:00
["userId"] = AuthContext.CurrentAccount.ID.ToString(),
2019-08-12 10:53:12 +00:00
["tenantId"] = Tenant.TenantId.ToString(CultureInfo.InvariantCulture)
};
client.UploadValues(string.Format("{0}/tips/deletereaded", SetupInfo.TipsAddress), data);
}
catch (Exception e)
{
LogManager.GetLogger("ASC").Error(e.Message, e);
}
}
return settings;
}
[Update("tips/change/subscription")]
public bool UpdateTipsSubscription()
{
return StudioPeriodicNotify.ChangeSubscription(AuthContext.CurrentAccount.ID, StudioNotifyHelper);
2019-08-12 10:53:12 +00:00
}
[Update("wizard/complete")]
public WizardSettings CompleteWizard()
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
var settings = WizardSettings.Load();
if (settings.Completed)
return settings;
settings.Completed = true;
settings.Save();
return settings;
}
[Update("tfaapp")]
public bool TfaSettings(TfaModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
var result = false;
MessageAction action;
switch (model.Type)
{
case "sms":
2019-09-19 11:34:54 +00:00
if (!StudioSmsNotificationSettings.IsVisibleSettings())
2019-08-12 10:53:12 +00:00
throw new Exception(Resource.SmsNotAvailable);
if (!SmsProviderManager.Enabled())
throw new MethodAccessException();
StudioSmsNotificationSettings.Enable = true;
action = MessageAction.TwoFactorAuthenticationEnabledBySms;
if (TfaAppAuthSettings.Enable)
{
TfaAppAuthSettings.Enable = false;
}
result = true;
break;
case "app":
if (!TfaAppAuthSettings.IsVisibleSettings)
{
throw new Exception(Resource.TfaAppNotAvailable);
}
TfaAppAuthSettings.Enable = true;
action = MessageAction.TwoFactorAuthenticationEnabledByTfaApp;
2019-09-19 11:34:54 +00:00
if (StudioSmsNotificationSettings.IsVisibleSettings() && StudioSmsNotificationSettings.Enable)
2019-08-12 10:53:12 +00:00
{
StudioSmsNotificationSettings.Enable = false;
}
result = true;
break;
default:
if (TfaAppAuthSettings.Enable)
{
TfaAppAuthSettings.Enable = false;
}
2019-09-19 11:34:54 +00:00
if (StudioSmsNotificationSettings.IsVisibleSettings() && StudioSmsNotificationSettings.Enable)
2019-08-12 10:53:12 +00:00
{
StudioSmsNotificationSettings.Enable = false;
}
action = MessageAction.TwoFactorAuthenticationDisabled;
break;
}
if (result)
{
2019-09-09 12:56:33 +00:00
CookiesManager.ResetTenantCookie();
2019-08-12 10:53:12 +00:00
}
MessageService.Send(action);
return result;
}
///<visible>false</visible>
[Read("tfaappcodes")]
public IEnumerable<object> TfaAppGetCodes()
{
2019-09-09 12:56:33 +00:00
var currentUser = UserManager.GetUsers(AuthContext.CurrentAccount.ID);
2019-08-12 10:53:12 +00:00
if (!TfaAppAuthSettings.IsVisibleSettings || !TfaAppUserSettings.EnableForUser(currentUser.ID))
throw new Exception(Resource.TfaAppNotAvailable);
if (currentUser.IsVisitor(UserManager) || currentUser.IsOutsider(UserManager))
2019-08-12 10:53:12 +00:00
throw new NotSupportedException("Not available.");
2019-08-15 12:04:42 +00:00
return TfaAppUserSettings.LoadForCurrentUser().CodesSetting.Select(r => new { r.IsUsed, r.Code }).ToList();
2019-08-12 10:53:12 +00:00
}
[Update("tfaappnewcodes")]
public IEnumerable<object> TfaAppRequestNewCodes()
{
var currentUser = UserManager.GetUsers(AuthContext.CurrentAccount.ID);
2019-08-12 10:53:12 +00:00
if (!TfaAppAuthSettings.IsVisibleSettings || !TfaAppUserSettings.EnableForUser(currentUser.ID))
throw new Exception(Resource.TfaAppNotAvailable);
if (currentUser.IsVisitor(UserManager) || currentUser.IsOutsider(UserManager))
2019-08-12 10:53:12 +00:00
throw new NotSupportedException("Not available.");
2019-09-10 14:29:37 +00:00
var codes = TfaManager.GenerateBackupCodes(currentUser).Select(r => new { r.IsUsed, r.Code }).ToList();
2019-09-24 10:32:12 +00:00
MessageService.Send(MessageAction.UserConnectedTfaApp, MessageTarget.Create(currentUser.ID), currentUser.DisplayUserName(false, DisplayUserSettings));
2019-08-12 10:53:12 +00:00
return codes;
}
[Update("tfaappnewapp")]
public string TfaAppNewApp(TfaModel model)
{
var isMe = model.Id.Equals(Guid.Empty);
2019-09-09 12:56:33 +00:00
var user = UserManager.GetUsers(isMe ? AuthContext.CurrentAccount.ID : model.Id);
2019-08-12 10:53:12 +00:00
if (!isMe && !PermissionContext.CheckPermissions(new UserSecurityProvider(user.ID), Constants.Action_EditUser))
2019-08-12 10:53:12 +00:00
throw new SecurityAccessDeniedException(Resource.ErrorAccessDenied);
if (!TfaAppAuthSettings.IsVisibleSettings || !TfaAppUserSettings.EnableForUser(user.ID))
throw new Exception(Resource.TfaAppNotAvailable);
if (user.IsVisitor(UserManager) || user.IsOutsider(UserManager))
2019-08-12 10:53:12 +00:00
throw new NotSupportedException("Not available.");
TfaAppUserSettings.DisableForUser(user.ID);
2019-09-24 10:32:12 +00:00
MessageService.Send(MessageAction.UserDisconnectedTfaApp, MessageTarget.Create(user.ID), user.DisplayUserName(false, DisplayUserSettings));
2019-08-12 10:53:12 +00:00
if (isMe)
{
2019-09-19 15:55:44 +00:00
return CommonLinkUtility.GetConfirmationUrl(user.Email, ConfirmType.TfaActivation);
2019-08-12 10:53:12 +00:00
}
2019-09-17 12:42:32 +00:00
StudioNotifyService.SendMsgTfaReset(user);
2019-08-12 10:53:12 +00:00
return string.Empty;
}
///<visible>false</visible>
[Update("welcome/close")]
public void CloseWelcomePopup()
{
2019-09-09 12:56:33 +00:00
var currentUser = UserManager.GetUsers(AuthContext.CurrentAccount.ID);
2019-08-12 10:53:12 +00:00
var collaboratorPopupSettings = CollaboratorSettings.LoadForCurrentUser();
if (!(currentUser.IsVisitor(UserManager) && collaboratorPopupSettings.FirstVisit && !currentUser.IsOutsider(UserManager)))
2019-08-12 10:53:12 +00:00
throw new NotSupportedException("Not available.");
collaboratorPopupSettings.FirstVisit = false;
collaboratorPopupSettings.SaveForCurrentUser();
}
///<visible>false</visible>
[Update("colortheme")]
public void SaveColorTheme(SettingsModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
ColorThemesSettings.SaveColorTheme(model.Theme);
MessageService.Send(MessageAction.ColorThemeChanged);
}
///<visible>false</visible>
[Update("timeandlanguage")]
public string TimaAndLanguage(SettingsModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
var culture = CultureInfo.GetCultureInfo(model.Lng);
var changelng = false;
if (SetupInfo.EnabledCultures.Find(c => string.Equals(c.Name, culture.Name, StringComparison.InvariantCultureIgnoreCase)) != null)
{
if (!string.Equals(Tenant.Language, culture.Name, StringComparison.InvariantCultureIgnoreCase))
{
Tenant.Language = culture.Name;
changelng = true;
}
}
var oldTimeZone = Tenant.TimeZone;
var timeZones = TimeZoneInfo.GetSystemTimeZones().ToList();
if (timeZones.All(tz => tz.Id != "UTC"))
{
timeZones.Add(TimeZoneInfo.Utc);
}
Tenant.TimeZone = timeZones.FirstOrDefault(tz => tz.Id == model.TimeZoneID) ?? TimeZoneInfo.Utc;
2019-09-09 12:56:33 +00:00
TenantManager.SaveTenant(Tenant);
2019-08-12 10:53:12 +00:00
if (!Tenant.TimeZone.Id.Equals(oldTimeZone.Id) || changelng)
{
if (!Tenant.TimeZone.Id.Equals(oldTimeZone.Id))
{
MessageService.Send(MessageAction.TimeZoneSettingsUpdated);
}
if (changelng)
{
MessageService.Send(MessageAction.LanguageSettingsUpdated);
}
}
return Resource.SuccessfullySaveSettingsMessage;
}
///<visible>false</visible>
[Update("defaultpage")]
public string SaveDefaultPageSettings(SettingsModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
new StudioDefaultPageSettings { DefaultProductID = model.DefaultProductID }.Save();
MessageService.Send(MessageAction.DefaultStartPageSettingsUpdated);
return Resource.SuccessfullySaveSettingsMessage;
}
private string GetProductName(Guid productId)
2019-08-12 10:53:12 +00:00
{
var product = WebItemManager[productId];
2019-08-12 10:53:12 +00:00
return productId == Guid.Empty ? "All" : product != null ? product.Name : productId.ToString();
}
[Read("license/refresh")]
public bool RefreshLicense()
{
2019-09-18 15:19:30 +00:00
if (!CoreBaseSettings.Standalone) return false;
2019-08-12 10:53:12 +00:00
LicenseReader.RefreshLicense();
return true;
}
[Read("customnavigation/getall")]
public List<CustomNavigationItem> GetCustomNavigationItems()
{
return CustomNavigationSettings.Load().Items;
}
[Read("customnavigation/getsample")]
public CustomNavigationItem GetCustomNavigationItemSample()
{
return CustomNavigationItem.GetSample();
}
[Read("customnavigation/get/{id}")]
public CustomNavigationItem GetCustomNavigationItem(Guid id)
{
return CustomNavigationSettings.Load().Items.FirstOrDefault(item => item.Id == id);
}
[Create("customnavigation/create")]
public CustomNavigationItem CreateCustomNavigationItem(CustomNavigationItem item)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
var settings = CustomNavigationSettings.Load();
var exist = false;
foreach (var existItem in settings.Items)
{
if (existItem.Id != item.Id) continue;
existItem.Label = item.Label;
existItem.Url = item.Url;
existItem.ShowInMenu = item.ShowInMenu;
existItem.ShowOnHomePage = item.ShowOnHomePage;
if (existItem.SmallImg != item.SmallImg)
{
StorageHelper.DeleteLogo(existItem.SmallImg);
2019-09-13 11:18:27 +00:00
existItem.SmallImg = StorageHelper.SaveTmpLogo(item.SmallImg);
2019-08-12 10:53:12 +00:00
}
if (existItem.BigImg != item.BigImg)
{
StorageHelper.DeleteLogo(existItem.BigImg);
2019-09-13 11:18:27 +00:00
existItem.BigImg = StorageHelper.SaveTmpLogo(item.BigImg);
2019-08-12 10:53:12 +00:00
}
exist = true;
break;
}
if (!exist)
{
item.Id = Guid.NewGuid();
2019-09-13 11:18:27 +00:00
item.SmallImg = StorageHelper.SaveTmpLogo(item.SmallImg);
item.BigImg = StorageHelper.SaveTmpLogo(item.BigImg);
2019-08-12 10:53:12 +00:00
settings.Items.Add(item);
}
settings.Save();
MessageService.Send(MessageAction.CustomNavigationSettingsUpdated);
return item;
}
[Delete("customnavigation/delete/{id}")]
public void DeleteCustomNavigationItem(Guid id)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
var settings = CustomNavigationSettings.Load();
var terget = settings.Items.FirstOrDefault(item => item.Id == id);
if (terget == null) return;
StorageHelper.DeleteLogo(terget.SmallImg);
StorageHelper.DeleteLogo(terget.BigImg);
settings.Items.Remove(terget);
settings.Save();
MessageService.Send(MessageAction.CustomNavigationSettingsUpdated);
}
[Update("emailactivation")]
public EmailActivationSettings UpdateEmailActivationSettings(bool show)
{
var settings = new EmailActivationSettings { Show = show };
settings.SaveForCurrentUser();
return settings;
}
///<visible>false</visible>
[Read("companywhitelabel")]
public List<CompanyWhiteLabelSettings> GetCompanyWhiteLabelSettings()
{
var result = new List<CompanyWhiteLabelSettings>();
var instance = CompanyWhiteLabelSettings.Instance;
result.Add(instance);
if (!instance.IsDefault && !instance.IsLicensor)
{
result.Add(instance.GetDefault() as CompanyWhiteLabelSettings);
}
return result;
}
[Read("statistics/spaceusage/{id}")]
public List<UsageSpaceStatItemWrapper> GetSpaceUsageStatistics(Guid id)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
2019-09-16 14:51:39 +00:00
var webtem = WebItemManagerSecurity.GetItems(WebZoneType.All, ItemAvailableState.All)
2019-08-12 10:53:12 +00:00
.FirstOrDefault(item =>
item != null &&
item.ID == id &&
item.Context != null &&
item.Context.SpaceUsageStatManager != null);
if (webtem == null) return new List<UsageSpaceStatItemWrapper>();
return webtem.Context.SpaceUsageStatManager.GetStatData()
.ConvertAll(it => new UsageSpaceStatItemWrapper
2019-08-15 12:04:42 +00:00
{
Name = it.Name.HtmlEncode(),
Icon = it.ImgUrl,
Disabled = it.Disabled,
Size = FileSizeComment.FilesSizeToString(it.SpaceUsage),
Url = it.Url
});
2019-08-12 10:53:12 +00:00
}
[Read("statistics/visit")]
public List<ChartPointWrapper> GetVisitStatistics(ApiDateTime fromDate, ApiDateTime toDate)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
var from = TenantUtil.DateTimeFromUtc(fromDate);
var to = TenantUtil.DateTimeFromUtc(toDate);
var points = new List<ChartPointWrapper>();
if (from.CompareTo(to) >= 0) return points;
for (var d = new DateTime(from.Ticks); d.Date.CompareTo(to.Date) <= 0; d = d.AddDays(1))
{
points.Add(new ChartPointWrapper
2019-08-15 12:04:42 +00:00
{
DisplayDate = d.Date.ToShortDateString(),
Date = d.Date,
Hosts = 0,
Hits = 0
});
2019-08-12 10:53:12 +00:00
}
2019-09-02 15:10:27 +00:00
var hits = StatisticManager.GetHitsByPeriod(Tenant.TenantId, from, to);
var hosts = StatisticManager.GetHostsByPeriod(Tenant.TenantId, from, to);
2019-08-12 10:53:12 +00:00
if (hits.Count == 0 || hosts.Count == 0) return points;
hits.Sort((x, y) => x.VisitDate.CompareTo(y.VisitDate));
hosts.Sort((x, y) => x.VisitDate.CompareTo(y.VisitDate));
for (int i = 0, n = points.Count, hitsNum = 0, hostsNum = 0; i < n; i++)
{
while (hitsNum < hits.Count && points[i].Date.CompareTo(hits[hitsNum].VisitDate.Date) == 0)
{
points[i].Hits += hits[hitsNum].VisitCount;
hitsNum++;
}
while (hostsNum < hosts.Count && points[i].Date.CompareTo(hosts[hostsNum].VisitDate.Date) == 0)
{
points[i].Hosts++;
hostsNum++;
}
}
return points;
}
[Read("storage")]
public List<StorageWrapper> GetAllStorages()
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
var current = StorageSettings.Load();
var consumers = ConsumerFactory.GetAll<DataStoreConsumer>().ToList();
return consumers.Select(consumer => new StorageWrapper(consumer, current)).ToList();
}
[Read("storage/progress", false)]
public double GetStorageProgress()
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
2019-09-18 15:19:30 +00:00
if (!CoreBaseSettings.Standalone) return -1;
2019-08-12 10:53:12 +00:00
2019-08-15 15:08:40 +00:00
using var migrateClient = new ServiceClient();
return migrateClient.GetProgress(Tenant.TenantId);
2019-08-12 10:53:12 +00:00
}
[Update("storage")]
public StorageSettings UpdateStorage(StorageModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-09-18 15:19:30 +00:00
if (!CoreBaseSettings.Standalone) return null;
2019-08-12 10:53:12 +00:00
var consumer = ConsumerFactory.GetByName(model.Module);
if (!consumer.IsSet)
throw new ArgumentException("module");
var settings = StorageSettings.Load();
if (settings.Module == model.Module) return settings;
settings.Module = model.Module;
settings.Props = model.Props.ToDictionary(r => r.Key, b => b.Value);
try
{
StartMigrate(settings);
}
catch (Exception e)
{
LogManager.GetLogger("ASC").Error("UpdateStorage", e);
throw;
}
return settings;
}
[Delete("storage")]
public void ResetStorageToDefault()
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-09-18 15:19:30 +00:00
if (!CoreBaseSettings.Standalone) return;
2019-08-12 10:53:12 +00:00
var settings = StorageSettings.Load();
settings.Module = null;
settings.Props = null;
try
{
StartMigrate(settings);
}
catch (Exception e)
{
LogManager.GetLogger("ASC").Error("ResetStorageToDefault", e);
throw;
}
}
[Read("storage/cdn")]
public List<StorageWrapper> GetAllCdnStorages()
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-09-18 15:19:30 +00:00
if (!CoreBaseSettings.Standalone) return null;
2019-08-12 10:53:12 +00:00
var current = CdnStorageSettings.Load();
var consumers = ConsumerFactory.GetAll<DataStoreConsumer>().Where(r => r.Cdn != null).ToList();
return consumers.Select(consumer => new StorageWrapper(consumer, current)).ToList();
}
[Update("storage/cdn")]
public CdnStorageSettings UpdateCdn(StorageModel model)
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-09-18 15:19:30 +00:00
if (!CoreBaseSettings.Standalone) return null;
2019-08-12 10:53:12 +00:00
var consumer = ConsumerFactory.GetByName(model.Module);
if (!consumer.IsSet)
throw new ArgumentException("module");
var settings = CdnStorageSettings.Load();
if (settings.Module == model.Module) return settings;
settings.Module = model.Module;
settings.Props = model.Props.ToDictionary(r => r.Key, b => b.Value);
try
{
2019-08-15 15:08:40 +00:00
using var migrateClient = new ServiceClient();
migrateClient.UploadCdn(Tenant.TenantId, "/", WebHostEnvironment.ContentRootPath, settings);
2019-08-12 10:53:12 +00:00
}
catch (Exception e)
{
LogManager.GetLogger("ASC").Error("UpdateCdn", e);
throw;
}
return settings;
}
[Delete("storage/cdn")]
public void ResetCdnToDefault()
{
PermissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings);
2019-09-18 15:19:30 +00:00
if (!CoreBaseSettings.Standalone) return;
2019-08-12 10:53:12 +00:00
CdnStorageSettings.Load().Clear();
}
//[Read("storage/backup")]
//public List<StorageWrapper> GetAllBackupStorages()
//{
2019-09-09 12:56:33 +00:00
// PermissionContext.DemandPermissions(Tenant, SecutiryConstants.EditPortalSettings);
2019-08-12 10:53:12 +00:00
// var schedule = new BackupAjaxHandler().GetSchedule();
// var current = new StorageSettings();
// if (schedule != null && schedule.StorageType == Contracts.BackupStorageType.ThirdPartyConsumer)
// {
// current = new StorageSettings
// {
// Module = schedule.StorageParams["module"],
// Props = schedule.StorageParams.Where(r => r.Key != "module").ToDictionary(r => r.Key, r => r.Value)
// };
// }
// var consumers = ConsumerFactory.GetAll<DataStoreConsumer>().ToList();
// return consumers.Select(consumer => new StorageWrapper(consumer, current)).ToList();
//}
private void StartMigrate(StorageSettings settings)
{
using (var migrateClient = new ServiceClient())
{
migrateClient.Migrate(Tenant.TenantId, settings);
}
Tenant.SetStatus(TenantStatus.Migrating);
}
[Read("socket")]
public object GetSocketSettings()
{
2019-09-23 12:20:08 +00:00
var hubUrl = Configuration["web:hub"] ?? string.Empty;
2019-08-12 10:53:12 +00:00
if (hubUrl != string.Empty)
{
if (!hubUrl.EndsWith("/"))
{
hubUrl += "/";
}
}
return new { Url = hubUrl };
}
}
}