Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/64907 #53

Merged
merged 6 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions common/ASC.Api.Core/Core/ApiDateTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,18 +383,14 @@ public override ApiDateTime Read(ref Utf8JsonReader reader, Type typeToConvert,
{
return new ApiDateTime(result, TimeSpan.Zero);
}
else
{
if (DateTime.TryParseExact(reader.GetString(), ApiDateTime.Formats,

if (DateTime.TryParseExact(reader.GetString(), ApiDateTime.Formats,
CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind, out var dateTime))
{
return new ApiDateTime(dateTime, TimeSpan.Zero);
}
else
{
return new ApiDateTime();
}
{
return new ApiDateTime(dateTime, TimeSpan.Zero);
}

return new ApiDateTime();
}

public override void Write(Utf8JsonWriter writer, ApiDateTime value, JsonSerializerOptions options)
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Api.Core/Security/EmailValidationKeyModelHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,11 @@ public async Task<ValidationResult> ValidateAsync(EmailValidationKeyModel inDto)
{
var auditEventDate = _tenantUtil.DateTimeToUtc(auditEvent.Date);

hash = (auditEventDate.CompareTo(passwordStamp) > 0 ? auditEventDate : passwordStamp).ToString("s");
hash = (auditEventDate.CompareTo(passwordStamp) > 0 ? auditEventDate : passwordStamp).ToString("s", CultureInfo.InvariantCulture);
}
else
{
hash = passwordStamp.ToString("s");
hash = passwordStamp.ToString("s", CultureInfo.InvariantCulture);
}

checkKeyResult = await _provider.ValidateEmailKeyAsync(email + type + hash, key, _provider.ValidEmailKeyInterval);
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Core.Common/Billing/BillingClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public IDictionary<string, Dictionary<string, decimal>> GetProductPriceInfo(stri
private string CreateAuthToken(string pkey, string machinekey)
{
using var hasher = new HMACSHA1(Encoding.UTF8.GetBytes(machinekey));
var now = DateTime.UtcNow.ToString("yyyyMMddHHmmss");
var now = DateTime.UtcNow.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture);
var hash = WebEncoders.Base64UrlEncode(hasher.ComputeHash(Encoding.UTF8.GetBytes(string.Join("\n", now, pkey))));

return "ASC " + pkey + ":" + now + ":" + hash;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ private string GetMethod(string method)
private string CreateAuthToken(string pkey = "socketio")
{
using var hasher = new HMACSHA1(_sKey);
var now = DateTime.UtcNow.ToString("yyyyMMddHHmmss");
var now = DateTime.UtcNow.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture);
var hash = Convert.ToBase64String(hasher.ComputeHash(Encoding.UTF8.GetBytes(string.Join("\n", now, pkey))));

return $"ASC {pkey}:{now}:{hash}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public bool DecryptCookie(string cookie, out int tenant, out Guid userid, out in
}
catch (Exception err)
{
_logger.AuthenticateError(cookie, tenant, userid, indexTenant, expire.ToString(DateTimeFormat), loginEventId, err);
_logger.AuthenticateError(cookie, tenant, userid, indexTenant, expire.ToString(DateTimeFormat, CultureInfo.InvariantCulture), loginEventId, err);
}

return false;
Expand Down
4 changes: 2 additions & 2 deletions common/ASC.Data.Backup.Core/Core/NotifyHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public async Task SendAboutRestoreCompletedAsync(Tenant tenant, bool notifyAllUs

foreach (var user in users.Where(r => r.ActivationStatus.HasFlag(EmployeeActivationStatus.Activated)))
{
var hash = (await _authManager.GetUserPasswordStampAsync(user.Id)).ToString("s");
var hash = (await _authManager.GetUserPasswordStampAsync(user.Id)).ToString("s", CultureInfo.InvariantCulture);
var confirmationUrl = await _commonLinkUtility.GetConfirmationEmailUrlAsync(user.Email, ConfirmType.PasswordChange, hash, user.Id);

var orangeButtonText = BackupResource.ResourceManager.GetString("ButtonSetPassword", user.GetCulture());
Expand Down Expand Up @@ -167,7 +167,7 @@ private async Task MigrationNotifyAsync(Tenant tenant, INotifyAction action, str
var currentArgs = new List<ITagValue>(args);

var newTenantId = toTenantId.HasValue ? toTenantId.Value : tenant.Id;
var hash = (await _authManager.GetUserPasswordStampAsync(user.Id)).ToString("s");
var hash = (await _authManager.GetUserPasswordStampAsync(user.Id)).ToString("s", CultureInfo.InvariantCulture);
var confirmationUrl = url + "/" + _commonLinkUtility.GetConfirmationUrlRelative(newTenantId, user.Email, ConfirmType.PasswordChange, hash, user.Id);
var culture = user.GetCulture();

Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Data.Backup.Core/Tasks/RestorePortalTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ private void SetTenantActive(int tenantId)
" statuschanged='{1}' " +
"where id = '{2}'",
(int)TenantStatus.Active,
DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss"),
DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture),
tenantId);

var command = connection.CreateCommand().WithTimeout(120);
Expand Down
2 changes: 1 addition & 1 deletion common/ASC.Data.Backup.Core/Tasks/TransferPortalTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private string GetBackupFilePath(string tenantAlias)
Directory.CreateDirectory(BackupDirectory ?? DefaultDirectoryName);
}

return CrossPlatform.PathCombine(BackupDirectory ?? DefaultDirectoryName, tenantAlias + DateTime.UtcNow.ToString("(yyyy-MM-dd HH-mm-ss)") + ".backup");
return CrossPlatform.PathCombine(BackupDirectory ?? DefaultDirectoryName, tenantAlias + DateTime.UtcNow.ToString("(yyyy-MM-dd HH-mm-ss)", CultureInfo.InvariantCulture) + ".backup");
}

}
4 changes: 2 additions & 2 deletions common/ASC.Data.Storage/GoogleCloud/GoogleCloudStorage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ public async Task<Uri> SaveAsync(string domain, string path, Stream stream, stri
uploaded.Metadata = new Dictionary<string, string>();
}

uploaded.Metadata["Expires"] = DateTime.UtcNow.Add(TimeSpan.FromDays(cacheDays)).ToString("R");
uploaded.Metadata["Expires"] = DateTime.UtcNow.Add(TimeSpan.FromDays(cacheDays)).ToString("R", CultureInfo.InvariantCulture);

if (!string.IsNullOrEmpty(contentDisposition))
{
Expand Down Expand Up @@ -605,7 +605,7 @@ public override async Task<string> SavePrivateAsync(string domain, string path,
uploaded.Metadata = new Dictionary<string, string>();
}

uploaded.Metadata["Expires"] = DateTime.UtcNow.Add(TimeSpan.FromDays(5)).ToString("R");
uploaded.Metadata["Expires"] = DateTime.UtcNow.Add(TimeSpan.FromDays(5)).ToString("R", CultureInfo.InvariantCulture);
uploaded.Metadata.Add("private-expire", expires.ToFileTimeUtc().ToString(CultureInfo.InvariantCulture));

await storage.UpdateObjectAsync(uploaded);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// 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

using System.Globalization;

namespace ASC.FederatedLogin.LoginProviders;

[Scope]
Expand Down Expand Up @@ -179,7 +181,7 @@ protected override OAuth20Token Auth(HttpContext context, string scopes, out boo

private void RequestCode(HttpContext context, string scope = null)
{
var timestamp = DateTime.UtcNow.ToString("yyyy.MM.dd HH:mm:ss +0000");
var timestamp = DateTime.UtcNow.ToString("yyyy.MM.dd HH:mm:ss +0000", CultureInfo.InvariantCulture);
var state = Guid.NewGuid().ToString();//HttpContext.Current.Request.Url().AbsoluteUri;

var msg = scope + timestamp + ClientID + state;
Expand All @@ -206,7 +208,7 @@ private void RequestCode(HttpContext context, string scope = null)

private OAuth20Token GetAccessToken(string state, string code)
{
var timestamp = DateTime.UtcNow.ToString("yyyy.MM.dd HH:mm:ss +0000");
var timestamp = DateTime.UtcNow.ToString("yyyy.MM.dd HH:mm:ss +0000", CultureInfo.InvariantCulture);

var msg = Scopes + timestamp + ClientID + state;
var encodedSignature = SignMsg(msg);
Expand Down
4 changes: 3 additions & 1 deletion common/services/ASC.Feed.Aggregator/Modules/FeedModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// 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

using System.Globalization;

namespace ASC.Feed.Aggregator.Modules;

public abstract class FeedModule : IFeedModule
Expand Down Expand Up @@ -82,7 +84,7 @@ protected static Guid ToGuid(object guid)

protected string GetGroupId(string item, Guid author, DateTime date, string rootId = null, int action = -1)
{
var time = date.ToString("g");
var time = date.ToString("g", CultureInfo.InvariantCulture);

if (rootId == null)
{
Expand Down
2 changes: 1 addition & 1 deletion products/ASC.Files/Core/ApiModels/ResponseDto/FileDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private async Task<FileDto<T>> GetFileWrapperAsync<T>(File<T> file)
{
var result = await GetAsync<FileDto<T>, T>(file);
var isEnabledBadges = await _badgesSettingsHelper.GetEnabledForCurrentUserAsync();

result.FileExst = FileUtility.GetFileExtension(file.Title);
result.FileType = FileUtility.GetFileTypeByExtention(result.FileExst);
result.Version = file.Version;
Expand Down
62 changes: 31 additions & 31 deletions products/ASC.Files/Core/Core/Entries/EntryProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,42 @@
// 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

namespace ASC.Files.Core;
namespace ASC.Files.Core;



/// <summary>
/// </summary>
[DebuggerDisplay("")]
public class EntryProperties
[DebuggerDisplay("")]
public class EntryProperties
{
/// <summary>Form filling properties</summary>
/// <type>ASC.Files.Core.FormFillingProperties, ASC.Files.Core</type>
public FormFillingProperties FormFilling { get; set; }

public static EntryProperties Deserialize(string data, ILogger logger)
{
try
{
return JsonSerializer.Deserialize<EntryProperties>(data);
}
catch (Exception e)
{
logger.ErrorWithException("Error parse EntryProperties: " + data, e);
return null;
}
}

public static string Serialize(EntryProperties entryProperties, ILogger logger)
{
try
{
return JsonSerializer.Serialize(entryProperties);
}
catch (Exception e)
{
logger.ErrorWithException("Error serialize EntryProperties", e);
return null;
}
public static EntryProperties Deserialize(string data, ILogger logger)
{
try
{
return JsonSerializer.Deserialize<EntryProperties>(data);
}
catch (Exception e)
{
logger.ErrorWithException("Error parse EntryProperties: " + data, e);
return null;
}
}
public static string Serialize(EntryProperties entryProperties, ILogger logger)
{
try
{
return JsonSerializer.Serialize(entryProperties);
}
catch (Exception e)
{
logger.ErrorWithException("Error serialize EntryProperties", e);
return null;
}
}
}

Expand Down Expand Up @@ -169,13 +169,13 @@ public async Task<string> GetTitleByMaskAsync(string sourceFileName)
var title = mask
.Replace("{0}", Path.GetFileNameWithoutExtension(sourceFileName))
.Replace("{1}", userName)
.Replace("{2}", _tenantUtil.DateTimeNow().ToString("g"));
.Replace("{2}", _tenantUtil.DateTimeNow().ToString("g", CultureInfo.InvariantCulture));

if (FileUtility.GetFileExtension(title) != "docx")
{
title += ".docx";
}

return title;
}
}
}
29 changes: 27 additions & 2 deletions products/ASC.Files/Core/Core/Entries/FileEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public string ModifiedByString
}

[JsonIgnore]
public string CreateOnString => CreateOn.Equals(default) ? null : CreateOn.ToString("g");
public string CreateOnString => CreateOn.Equals(default) ? null : CreateOn.ConvertNumerals();

[JsonIgnore]
public string ModifiedOnString => ModifiedOn.Equals(default) ? null : ModifiedOn.ToString("g");
public string ModifiedOnString => ModifiedOn.Equals(default) ? null : ModifiedOn.ConvertNumerals();

public string Error { get; set; }
public FileShare Access { get; set; }
Expand Down Expand Up @@ -102,6 +102,31 @@ public object Clone()
}
}

static file class ArabicNumeralHelper
{
public static string ConvertNumerals(this DateTime input)
{
if (!new[] { "ar-lb", "ar-SA" }.Contains(Thread.CurrentThread.CurrentCulture.Name))
{
return input.ToString("g", CultureInfo.InvariantCulture);
}

var result = input.ToString($"g", new CultureInfo("ar"));
return result
.Replace('0', '\u06f0')
.Replace('1', '\u06f1')
.Replace('2', '\u06f2')
.Replace('3', '\u06f3')
.Replace('4', '\u06f4')
.Replace('5', '\u06f5')
.Replace('6', '\u06f6')
.Replace('7', '\u06f7')
.Replace('8', '\u06f8')
.Replace('9', '\u06f9');

}
}

public interface IFileEntry
{
string UniqID { get; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public override async Task RunJob(DistributedTask distributedTask, CancellationT
}
else
{
fileName = string.Format(@"{0}-{1}-{2}{3}", (await tenantManager.GetCurrentTenantAsync()).Alias.ToLower(), FileConstant.DownloadTitle, DateTime.UtcNow.ToString("yyyy-MM-dd"), archiveExtension);
fileName = string.Format(@"{0}-{1}-{2}{3}", (await tenantManager.GetCurrentTenantAsync()).Alias.ToLower(), FileConstant.DownloadTitle, DateTime.UtcNow.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), archiveExtension);
}

var store = await globalStore.GetStoreAsync();
Expand Down
2 changes: 1 addition & 1 deletion web/ASC.Web.Api/Api/ConnectionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public async Task<object> LogOutAllActiveConnectionsChangePassword()
var auditEventDate = DateTime.UtcNow;
auditEventDate = auditEventDate.AddTicks(-(auditEventDate.Ticks % TimeSpan.TicksPerSecond));

var hash = auditEventDate.ToString("s");
var hash = auditEventDate.ToString("s", CultureInfo.InvariantCulture);
var confirmationUrl = await _commonLinkUtility.GetConfirmationEmailUrlAsync(user.Email, ConfirmType.PasswordChange, hash, user.Id);

await _messageService.SendAsync(MessageAction.UserSentPasswordChangeInstructions, _messageTarget.Create(user.Id), auditEventDate, userName);
Expand Down
2 changes: 1 addition & 1 deletion web/ASC.Web.Api/Api/SecurityController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public async Task<object> CreateAuditTrailReport()
var to = DateTime.UtcNow;
var from = to.Subtract(TimeSpan.FromDays(settings.AuditTrailLifeTime));

var reportName = string.Format(AuditReportResource.AuditTrailReportName + ".csv", from.ToString("MM.dd.yyyy"), to.ToString("MM.dd.yyyy"));
var reportName = string.Format(AuditReportResource.AuditTrailReportName + ".csv", from.ToString("MM.dd.yyyy", CultureInfo.InvariantCulture), to.ToString("MM.dd.yyyy"));

var events = await _auditEventsRepository.GetByFilterAsync(from: from, to: to);

Expand Down
2 changes: 1 addition & 1 deletion web/ASC.Web.Core/Helpers/ApiSystemHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public ApiSystemHelper(IConfiguration configuration,
public string CreateAuthToken(string pkey)
{
using var hasher = new HMACSHA1(_skey);
var now = DateTime.UtcNow.ToString("yyyyMMddHHmmss");
var now = DateTime.UtcNow.ToString("yyyyMMddHHmmss", CultureInfo.InvariantCulture);
var hash = WebEncoders.Base64UrlEncode(hasher.ComputeHash(Encoding.UTF8.GetBytes(string.Join("\n", now, pkey))));
return $"ASC {pkey}:{now}:{hash}1"; //hack for .net
}
Expand Down
4 changes: 2 additions & 2 deletions web/ASC.Web.Core/Notify/StudioNotifyService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public async Task UserPasswordChangeAsync(UserInfo userInfo)
0,
DateTimeKind.Utc);

var hash = auditEventDate.ToString("s");
var hash = auditEventDate.ToString("s", CultureInfo.InvariantCulture);

var confirmationUrl = await _commonLinkUtility.GetConfirmationEmailUrlAsync(userInfo.Email, ConfirmType.PasswordChange, hash, userInfo.Id);

Expand Down Expand Up @@ -783,7 +783,7 @@ public async Task SendAlreadyExistAsync(string email)

var portalUrl = _commonLinkUtility.GetFullAbsolutePath("~").TrimEnd('/');

var hash = (await _authentication.GetUserPasswordStampAsync(userInfo.Id)).ToString("s");
var hash = (await _authentication.GetUserPasswordStampAsync(userInfo.Id)).ToString("s", CultureInfo.InvariantCulture);

var linkToRecovery = await _commonLinkUtility.GetConfirmationEmailUrlAsync(userInfo.Email, ConfirmType.PasswordChange, hash, userInfo.Id);

Expand Down