add datetime string to initial auth hash, add logging for discord commands, add file logger

This commit is contained in:
Stanley Dimant
2022-08-29 23:51:37 +02:00
parent 507c7cac11
commit 9c88f3cfcf
4 changed files with 15 additions and 1 deletions

View File

@@ -138,6 +138,7 @@ namespace MareSynchronosServices
var otherPairData = dbContext.ClientPairs.Include(u => u.User)
.Where(u => u.OtherUser.UID == user.UID).ToList();
_logger.LogInformation("User purged: {uid}", user.UID);
metrics.DecGauge(MetricsAPI.GaugePairs, ownPairData.Count + otherPairData.Count);
metrics.DecGauge(MetricsAPI.GaugePairsPaused, ownPairData.Count + ownPairData.Count(c => c.IsPaused));

View File

@@ -71,8 +71,11 @@ public class DiscordBot : IHostedService
{
if (arg.Data.Name == "register")
{
logger.LogInformation("{user} called register", arg.User.Id);
if (arg.Data.Options.FirstOrDefault(f => f.Name == "overwrite_old_account") != null)
{
logger.LogInformation("{user} called register with overwrite_old_account", arg.User.Id);
await DeletePreviousUserAccount(arg.User.Id).ConfigureAwait(false);
}
@@ -84,6 +87,7 @@ public class DiscordBot : IHostedService
}
else if (arg.Data.Name == "verify")
{
logger.LogInformation("{user} called verify", arg.User.Id);
EmbedBuilder eb = new();
if (verificationQueue.Any(u => u.User.Id == arg.User.Id))
{
@@ -105,6 +109,8 @@ public class DiscordBot : IHostedService
}
else if (arg.Data.Name == "setvanityuid")
{
logger.LogInformation("{user} called setvanityuid", arg.User.Id);
EmbedBuilder eb = new();
var newUid = (string)arg.Data.Options.First(f => f.Name == "vanity_uid").Value;
eb = await HandleVanityUid(eb, arg.User.Id, newUid);
@@ -247,7 +253,7 @@ public class DiscordBot : IHostedService
user.LastLoggedIn = DateTime.UtcNow - TimeSpan.FromDays(purgedDays) + TimeSpan.FromDays(1);
}
var computedHash = BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(GenerateRandomString(64)))).Replace("-", "");
var computedHash = BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(GenerateRandomString(64) + DateTime.UtcNow.ToString()))).Replace("-", "");
var auth = new Auth()
{
HashedKey = BitConverter.ToString(sha256.ComputeHash(Encoding.UTF8.GetBytes(computedHash)))

View File

@@ -23,6 +23,7 @@
<PackageReference Include="Discord.Net" Version="3.7.2" />
<PackageReference Include="EFCore.NamingConventions" Version="6.0.0" />
<PackageReference Include="Grpc.AspNetCore" Version="2.47.0" />
<PackageReference Include="Karambolo.Extensions.Logging.File" Version="3.3.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="6.0.8" />
<PackageReference Include="Microsoft.Extensions.Hosting.Systemd" Version="6.0.0" />
<PackageReference Include="prometheus-net.AspNetCore" Version="6.0.0" />

View File

@@ -4,6 +4,7 @@ using MareSynchronosShared.Metrics;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using System;
using System.Linq;
@@ -33,6 +34,11 @@ public class Program
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseContentRoot(AppContext.BaseDirectory);
webBuilder.ConfigureLogging((ctx, builder) =>
{
builder.AddConfiguration(ctx.Configuration.GetSection("Logging"));
builder.AddFile(o => o.RootPath = AppContext.BaseDirectory);
});
webBuilder.UseStartup<Startup>();
});
}