2022-03-15 18:00:53 +00:00
|
|
|
// (c) Copyright Ascensio System SIA 2010-2022
|
|
|
|
//
|
|
|
|
// This program is a free software product.
|
|
|
|
// You can redistribute it and/or modify it under the terms
|
|
|
|
// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software
|
|
|
|
// Foundation. In accordance with Section 7(a) of the GNU AGPL 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 details, see
|
|
|
|
// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
|
|
|
|
//
|
|
|
|
// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021.
|
|
|
|
//
|
|
|
|
// The interactive user interfaces in modified source and object code versions of the Program must
|
|
|
|
// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3.
|
|
|
|
//
|
|
|
|
// Pursuant to Section 7(b) of the License you must retain the original Product logo when
|
|
|
|
// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under
|
|
|
|
// trademark law for use of our trademarks.
|
|
|
|
//
|
|
|
|
// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing
|
|
|
|
// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0
|
|
|
|
// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
namespace ASC.Web.Studio.Core;
|
|
|
|
|
|
|
|
[Singletone]
|
|
|
|
public class SetupInfo
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 16:57:02 +00:00
|
|
|
private static string _webAutotestSecretEmail;
|
|
|
|
private static string[] _webDisplayMobappsBanner;
|
|
|
|
private static string[] _hideSettings;
|
2022-03-17 15:13:38 +00:00
|
|
|
|
|
|
|
public string MetaImageURL { get; private set; }
|
|
|
|
public string StatisticTrackURL { get; private set; }
|
|
|
|
public string DemoOrder { get; private set; }
|
|
|
|
public string RequestTraining { get; private set; }
|
|
|
|
public string ZendeskKey { get; private set; }
|
|
|
|
public string UserVoiceURL { get; private set; }
|
|
|
|
public string MainLogoURL { get; private set; }
|
|
|
|
public string MainLogoMailTmplURL { get; private set; }
|
|
|
|
public List<CultureInfo> EnabledCultures { get; private set; }
|
|
|
|
private List<CultureInfo> EnabledCulturesPersonal { get; set; }
|
|
|
|
public List<KeyValuePair<string, CultureInfo>> PersonalCultures { get; private set; }
|
|
|
|
public long MaxImageUploadSize { get; private set; }
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Max possible file size for not chunked upload. Less or equal than 100 mb.
|
|
|
|
/// </summary>
|
|
|
|
public long MaxUploadSize(TenantExtra tenantExtra, TenantStatisticsProvider tenantStatisticsProvider)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
return Math.Min(AvailableFileSize, MaxChunkedUploadSize(tenantExtra, tenantStatisticsProvider));
|
|
|
|
}
|
2020-01-29 12:42:17 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public long AvailableFileSize
|
|
|
|
{
|
|
|
|
get;
|
|
|
|
private set;
|
|
|
|
}
|
|
|
|
|
|
|
|
public string TeamlabSiteRedirect { get; private set; }
|
|
|
|
public long ChunkUploadSize { get; private set; }
|
2022-06-14 08:11:41 +00:00
|
|
|
public long ProviderMaxUploadSize { get; private set; }
|
2022-03-17 15:13:38 +00:00
|
|
|
public bool ThirdPartyAuthEnabled { get; private set; }
|
|
|
|
public string NoTenantRedirectURL { get; private set; }
|
|
|
|
public string NotifyAddress { get; private set; }
|
|
|
|
public string TipsAddress { get; private set; }
|
|
|
|
public string UserForum { get; private set; }
|
|
|
|
public string SupportFeedback { get; private set; }
|
|
|
|
public string WebApiBaseUrl { get { return VirtualPathUtility.ToAbsolute(GetAppSettings("api.url", "~/api/2.0/")); } }
|
|
|
|
public TimeSpan ValidEmailKeyInterval { get; private set; }
|
|
|
|
public TimeSpan ValidAuthKeyInterval { get; private set; }
|
|
|
|
public string SalesEmail { get; private set; }
|
|
|
|
public static bool IsSecretEmail(string email)
|
|
|
|
{
|
|
|
|
email = Regex.Replace(email ?? "", "\\.*(?=\\S*(@gmail.com$))", "").ToLower();
|
2022-03-17 16:57:02 +00:00
|
|
|
if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(_webAutotestSecretEmail))
|
2020-01-29 12:42:17 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
return false;
|
2020-01-29 12:42:17 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:57:02 +00:00
|
|
|
var regex = new Regex(_webAutotestSecretEmail, RegexOptions.IgnoreCase | RegexOptions.Singleline | RegexOptions.Compiled);
|
2022-03-17 15:13:38 +00:00
|
|
|
return regex.IsMatch(email);
|
|
|
|
}
|
2020-09-18 14:45:59 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public static bool DisplayMobappBanner(string product)
|
|
|
|
{
|
2022-03-17 16:57:02 +00:00
|
|
|
return _webDisplayMobappsBanner.Contains(product, StringComparer.InvariantCultureIgnoreCase);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public string ShareTwitterUrl { get; private set; }
|
|
|
|
public string ShareFacebookUrl { get; private set; }
|
|
|
|
public string ControlPanelUrl { get; private set; }
|
|
|
|
public string FontOpenSansUrl { get; private set; }
|
|
|
|
public string StartProductList { get; private set; }
|
|
|
|
public string SsoSamlLoginUrl { get; private set; }
|
|
|
|
public string DownloadForDesktopUrl { get; private set; }
|
|
|
|
public string DownloadForIosDocuments { get; private set; }
|
|
|
|
public string DownloadForIosProjects { get; private set; }
|
|
|
|
public string DownloadForAndroidDocuments { get; private set; }
|
|
|
|
public string SsoSamlLogoutUrl { get; private set; }
|
|
|
|
public bool SmsTrial { get; private set; }
|
|
|
|
public string TfaRegistration { get; private set; }
|
|
|
|
public int TfaAppBackupCodeLength { get; private set; }
|
|
|
|
public int TfaAppBackupCodeCount { get; private set; }
|
|
|
|
public string TfaAppSender { get; private set; }
|
|
|
|
public string RecaptchaPublicKey { get; private set; }
|
|
|
|
public string RecaptchaPrivateKey { get; private set; }
|
|
|
|
public string RecaptchaVerifyUrl { get; private set; }
|
|
|
|
public int LoginThreshold { get; private set; }
|
|
|
|
public string AmiMetaUrl { get; private set; }
|
2022-04-15 09:08:06 +00:00
|
|
|
private readonly IConfiguration _configuration;
|
2022-03-17 15:13:38 +00:00
|
|
|
|
|
|
|
public SetupInfo(IConfiguration configuration)
|
|
|
|
{
|
2022-04-15 09:08:06 +00:00
|
|
|
_configuration = configuration;
|
2022-03-17 15:13:38 +00:00
|
|
|
MetaImageURL = GetAppSettings("web.meta-image-url", "https://download.onlyoffice.com/assets/fb/fb_icon_325x325.jpg");
|
|
|
|
StatisticTrackURL = GetAppSettings("web.track-url", string.Empty);
|
|
|
|
UserVoiceURL = GetAppSettings("web.uservoice", string.Empty);
|
|
|
|
DemoOrder = GetAppSettings("web.demo-order", string.Empty);
|
|
|
|
ZendeskKey = GetAppSettings("web.zendesk-key", string.Empty);
|
|
|
|
RequestTraining = GetAppSettings("web.request-training", string.Empty);
|
|
|
|
MainLogoURL = GetAppSettings("web.logo.main", string.Empty);
|
|
|
|
MainLogoMailTmplURL = GetAppSettings("web.logo.mail.tmpl", string.Empty);
|
|
|
|
DownloadForDesktopUrl = GetAppSettings("web.download.for.desktop.url", "https://www.onlyoffice.com/desktop.aspx");
|
|
|
|
DownloadForIosDocuments = GetAppSettings("web.download.for.ios.doc", "https://itunes.apple.com/app/onlyoffice-documents/id944896972");
|
|
|
|
DownloadForIosProjects = GetAppSettings("web.download.for.ios.proj", "https://itunes.apple.com/app/onlyoffice-projects/id1353395928?mt=8");
|
|
|
|
DownloadForAndroidDocuments = GetAppSettings("web.download.for.android.doc", "https://play.google.com/store/apps/details?id=com.onlyoffice.documents");
|
|
|
|
|
|
|
|
EnabledCultures = GetAppSettings("web:cultures", "en-US")
|
|
|
|
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
|
|
|
.Distinct()
|
|
|
|
.Select(l => CultureInfo.GetCultureInfo(l.Trim()))
|
|
|
|
.OrderBy(l => l.DisplayName)
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
EnabledCulturesPersonal = GetAppSettings("web:cultures:personal", GetAppSettings("web:cultures", "en-US"))
|
|
|
|
.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)
|
|
|
|
.Distinct()
|
|
|
|
.Select(l => CultureInfo.GetCultureInfo(l.Trim()))
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
PersonalCultures = GetPersonalCultures();
|
|
|
|
MaxImageUploadSize = GetAppSettings<long>("web:max-upload-size", 1024 * 1024);
|
|
|
|
AvailableFileSize = GetAppSettings("web:available-file-size", 100L * 1024L * 1024L);
|
|
|
|
AvailableFileSize = GetAppSettings("web.available-file-size", 100L * 1024L * 1024L);
|
|
|
|
|
|
|
|
TeamlabSiteRedirect = GetAppSettings("web.teamlab-site", string.Empty);
|
|
|
|
ChunkUploadSize = GetAppSettings("files:uploader:chunk-size", 10 * 1024 * 1024);
|
2022-06-14 08:11:41 +00:00
|
|
|
ProviderMaxUploadSize = GetAppSettings("files:provider:max-upload-size", 1024L * 1024L * 1024L);
|
|
|
|
ThirdPartyAuthEnabled = string.Equals(GetAppSettings("web:thirdparty-auth", "true"), "true");
|
2022-03-17 15:13:38 +00:00
|
|
|
NoTenantRedirectURL = GetAppSettings("web.notenant-url", "");
|
|
|
|
|
|
|
|
NotifyAddress = GetAppSettings("web.promo-url", string.Empty);
|
|
|
|
TipsAddress = GetAppSettings("web.promo-tips-url", string.Empty);
|
|
|
|
UserForum = GetAppSettings("web.user-forum", string.Empty);
|
|
|
|
SupportFeedback = GetAppSettings("web.support-feedback", string.Empty);
|
|
|
|
|
|
|
|
ValidEmailKeyInterval = GetAppSettings("email.validinterval", TimeSpan.FromDays(7));
|
|
|
|
ValidAuthKeyInterval = GetAppSettings("auth.validinterval", TimeSpan.FromHours(1));
|
|
|
|
|
|
|
|
SalesEmail = GetAppSettings("web.payment.email", "sales@onlyoffice.com");
|
2022-03-17 16:57:02 +00:00
|
|
|
_webAutotestSecretEmail = (configuration["web:autotest:secret-email"] ?? "").Trim();
|
2022-03-17 15:13:38 +00:00
|
|
|
|
|
|
|
RecaptchaPublicKey = GetAppSettings("web.recaptcha.public-key", null);
|
|
|
|
RecaptchaPrivateKey = GetAppSettings("web.recaptcha.private-key", "");
|
|
|
|
RecaptchaVerifyUrl = GetAppSettings("web.recaptcha.verify-url", "https://www.recaptcha.net/recaptcha/api/siteverify");
|
|
|
|
LoginThreshold = Convert.ToInt32(GetAppSettings("web.login.threshold", "0"));
|
|
|
|
if (LoginThreshold < 1)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
LoginThreshold = 5;
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 16:57:02 +00:00
|
|
|
_webDisplayMobappsBanner = (configuration["web.display.mobapps.banner"] ?? "").Trim().Split(new char[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
2022-03-17 15:13:38 +00:00
|
|
|
ShareTwitterUrl = GetAppSettings("web.share.twitter", "https://twitter.com/intent/tweet?text={0}");
|
|
|
|
ShareFacebookUrl = GetAppSettings("web.share.facebook", "");
|
|
|
|
ControlPanelUrl = GetAppSettings("web:controlpanel:url", "");
|
|
|
|
FontOpenSansUrl = GetAppSettings("web.font.opensans.url", "");
|
|
|
|
StartProductList = GetAppSettings("web.start.product.list", "");
|
|
|
|
SsoSamlLoginUrl = GetAppSettings("web.sso.saml.login.url", "");
|
|
|
|
SsoSamlLogoutUrl = GetAppSettings("web.sso.saml.logout.url", "");
|
2019-08-12 10:53:12 +00:00
|
|
|
|
2022-03-17 16:57:02 +00:00
|
|
|
_hideSettings = GetAppSettings("web.hide-settings", string.Empty).Split(new[] { ',', ';', ' ' }, StringSplitOptions.RemoveEmptyEntries);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
SmsTrial = GetAppSettings("core.sms.trial", false);
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
TfaRegistration = (GetAppSettings("core.tfa.registration", "") ?? "").Trim().ToLower();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
TfaAppBackupCodeLength = GetAppSettings("web.tfaapp.backup.length", 6);
|
|
|
|
TfaAppBackupCodeCount = GetAppSettings("web.tfaapp.backup.count", 5);
|
|
|
|
TfaAppSender = GetAppSettings("web.tfaapp.backup.title", "ONLYOFFICE");
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
AmiMetaUrl = GetAppSettings("web:ami:meta", "");
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
//TODO
|
|
|
|
public static bool IsVisibleSettings<TSettings>()
|
|
|
|
{
|
|
|
|
return IsVisibleSettings(typeof(TSettings).Name);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static bool IsVisibleSettings(string settings)
|
|
|
|
{
|
2022-03-17 16:57:02 +00:00
|
|
|
return _hideSettings == null || !_hideSettings.Contains(settings, StringComparer.CurrentCultureIgnoreCase);
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public long MaxChunkedUploadSize(TenantExtra tenantExtra, TenantStatisticsProvider tenantStatisticsProvider)
|
|
|
|
{
|
|
|
|
var diskQuota = tenantExtra.GetTenantQuota();
|
|
|
|
if (diskQuota != null)
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
var usedSize = tenantStatisticsProvider.GetUsedSize();
|
|
|
|
var freeSize = Math.Max(diskQuota.MaxTotalSize - usedSize, 0);
|
|
|
|
return Math.Min(freeSize, diskQuota.MaxFileSize);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
return ChunkUploadSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
private string GetAppSettings(string key, string defaultValue)
|
|
|
|
{
|
2022-04-15 09:08:06 +00:00
|
|
|
var result = _configuration[key] ?? defaultValue;
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (!string.IsNullOrEmpty(result))
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
result = result.Trim();
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
private T GetAppSettings<T>(string key, T defaultValue)
|
|
|
|
{
|
2022-04-15 09:08:06 +00:00
|
|
|
var configSetting = _configuration[key];
|
2022-03-17 15:13:38 +00:00
|
|
|
if (!string.IsNullOrEmpty(configSetting))
|
2020-01-28 14:59:59 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
configSetting = configSetting.Trim();
|
|
|
|
var converter = TypeDescriptor.GetConverter(typeof(T));
|
|
|
|
if (converter != null && converter.CanConvertFrom(typeof(string)))
|
2020-01-28 14:59:59 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
return (T)converter.ConvertFromString(configSetting);
|
2020-01-28 14:59:59 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
return defaultValue;
|
|
|
|
}
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
private List<KeyValuePair<string, CultureInfo>> GetPersonalCultures()
|
|
|
|
{
|
|
|
|
var result = new Dictionary<string, CultureInfo>();
|
2019-06-14 16:14:24 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
foreach (var culture in EnabledCulturesPersonal)
|
|
|
|
{
|
|
|
|
if (result.ContainsKey(culture.TwoLetterISOLanguageName))
|
2022-03-17 15:01:39 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
result.Add(culture.Name, culture);
|
2022-03-17 15:01:39 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
else
|
2019-06-14 16:14:24 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
result.Add(culture.TwoLetterISOLanguageName, culture);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-17 14:32:37 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
return result.OrderBy(item => item.Value.DisplayName).ToList();
|
|
|
|
}
|
2021-09-17 14:32:37 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
public KeyValuePair<string, CultureInfo> GetPersonalCulture(string lang)
|
|
|
|
{
|
|
|
|
foreach (var item in PersonalCultures)
|
|
|
|
{
|
|
|
|
if (string.Equals(item.Key, lang, StringComparison.InvariantCultureIgnoreCase))
|
2021-09-17 14:32:37 +00:00
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
return item;
|
2021-09-17 14:32:37 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var cultureInfo = EnabledCulturesPersonal.Find(c => string.Equals(c.Name, lang, StringComparison.InvariantCultureIgnoreCase));
|
2021-09-17 14:32:37 +00:00
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (cultureInfo == null)
|
|
|
|
{
|
|
|
|
cultureInfo = EnabledCulturesPersonal.Find(c => string.Equals(c.TwoLetterISOLanguageName, lang, StringComparison.InvariantCultureIgnoreCase));
|
2021-09-17 14:32:37 +00:00
|
|
|
}
|
|
|
|
|
2022-03-17 15:13:38 +00:00
|
|
|
if (cultureInfo != null)
|
2021-09-17 14:32:37 +00:00
|
|
|
{
|
|
|
|
foreach (var item in PersonalCultures)
|
|
|
|
{
|
2022-03-17 15:13:38 +00:00
|
|
|
if (item.Value == cultureInfo)
|
2021-09-17 14:32:37 +00:00
|
|
|
{
|
|
|
|
return item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
|
|
|
|
return new KeyValuePair<string, CultureInfo>(lang, cultureInfo);
|
2019-06-14 16:14:24 +00:00
|
|
|
}
|
2022-03-17 15:13:38 +00:00
|
|
|
}
|