add LastLoggedIn migration, disallow secondary connections
This commit is contained in:
@@ -43,9 +43,18 @@ namespace MareSynchronosServer.Hubs
|
||||
|
||||
if (userId != null && !isBanned && !string.IsNullOrEmpty(characterIdentification))
|
||||
{
|
||||
MareMetrics.AuthorizedConnections.Inc();
|
||||
_logger.LogInformation("Connection from " + userId);
|
||||
var user = (await _dbContext.Users.SingleAsync(u => u.UID == userId));
|
||||
if (!string.IsNullOrEmpty(user.CharacterIdentification))
|
||||
{
|
||||
return new ConnectionDto()
|
||||
{
|
||||
ServerVersion = Api.Version
|
||||
};
|
||||
}
|
||||
|
||||
MareMetrics.AuthorizedConnections.Inc();
|
||||
user.LastLoggedIn = DateTime.UtcNow;
|
||||
user.CharacterIdentification = characterIdentification;
|
||||
await _dbContext.SaveChangesAsync();
|
||||
return new ConnectionDto
|
||||
|
||||
@@ -26,7 +26,6 @@
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\MareAPI\MareSynchronosAPI\MareSynchronos.API.csproj" />
|
||||
<ProjectReference Include="..\MareSynchronos.API\MareSynchronos.API.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
203
MareSynchronosServer/MareSynchronosServer/Migrations/20220718071653_UserLoginDateTime.Designer.cs
generated
Normal file
203
MareSynchronosServer/MareSynchronosServer/Migrations/20220718071653_UserLoginDateTime.Designer.cs
generated
Normal file
@@ -0,0 +1,203 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using MareSynchronosServer.Data;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
[DbContext(typeof(MareDbContext))]
|
||||
[Migration("20220718071653_UserLoginDateTime")]
|
||||
partial class UserLoginDateTime
|
||||
{
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder
|
||||
.HasAnnotation("ProductVersion", "6.0.6")
|
||||
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||
|
||||
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder, 1L, 1);
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.Property<string>("HashedKey")
|
||||
.HasMaxLength(64)
|
||||
.HasColumnType("nvarchar(64)");
|
||||
|
||||
b.Property<string>("UserUID")
|
||||
.HasColumnType("nvarchar(10)");
|
||||
|
||||
b.HasKey("HashedKey");
|
||||
|
||||
b.HasIndex("UserUID");
|
||||
|
||||
b.ToTable("Auth", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Banned", b =>
|
||||
{
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<string>("Reason")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("rowversion");
|
||||
|
||||
b.HasKey("CharacterIdentification");
|
||||
|
||||
b.ToTable("BannedUsers", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.Property<string>("UserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("nvarchar(10)");
|
||||
|
||||
b.Property<string>("OtherUserUID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("nvarchar(10)");
|
||||
|
||||
b.Property<bool>("AllowReceivingMessages")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsPaused")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("rowversion");
|
||||
|
||||
b.HasKey("UserUID", "OtherUserUID");
|
||||
|
||||
b.HasIndex("OtherUserUID");
|
||||
|
||||
b.HasIndex("UserUID");
|
||||
|
||||
b.ToTable("ClientPairs", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("nvarchar(40)");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("rowversion");
|
||||
|
||||
b.Property<bool>("Uploaded")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<string>("UploaderUID")
|
||||
.HasColumnType("nvarchar(10)");
|
||||
|
||||
b.HasKey("Hash");
|
||||
|
||||
b.HasIndex("UploaderUID");
|
||||
|
||||
b.ToTable("FileCaches", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ForbiddenUploadEntry", b =>
|
||||
{
|
||||
b.Property<string>("Hash")
|
||||
.HasMaxLength(40)
|
||||
.HasColumnType("nvarchar(40)");
|
||||
|
||||
b.Property<string>("ForbiddenBy")
|
||||
.HasColumnType("nvarchar(max)");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("rowversion");
|
||||
|
||||
b.HasKey("Hash");
|
||||
|
||||
b.ToTable("ForbiddenUploadEntries", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.User", b =>
|
||||
{
|
||||
b.Property<string>("UID")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("nvarchar(10)");
|
||||
|
||||
b.Property<string>("CharacterIdentification")
|
||||
.HasColumnType("nvarchar(450)");
|
||||
|
||||
b.Property<bool>("IsAdmin")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<bool>("IsModerator")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTime>("LastLoggedIn")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
.HasColumnType("rowversion");
|
||||
|
||||
b.HasKey("UID");
|
||||
|
||||
b.HasIndex("CharacterIdentification");
|
||||
|
||||
b.ToTable("Users", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.Auth", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.ClientPair", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "OtherUser")
|
||||
.WithMany()
|
||||
.HasForeignKey("OtherUserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("MareSynchronosServer.Models.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserUID")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("OtherUser");
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("MareSynchronosServer.Models.FileCache", b =>
|
||||
{
|
||||
b.HasOne("MareSynchronosServer.Models.User", "Uploader")
|
||||
.WithMany()
|
||||
.HasForeignKey("UploaderUID");
|
||||
|
||||
b.Navigation("Uploader");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace MareSynchronosServer.Migrations
|
||||
{
|
||||
public partial class UserLoginDateTime : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.AddColumn<DateTime>(
|
||||
name: "LastLoggedIn",
|
||||
table: "Users",
|
||||
type: "datetime2",
|
||||
nullable: false,
|
||||
defaultValue: new DateTime(1, 1, 1, 0, 0, 0, 0, DateTimeKind.Unspecified));
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "LastLoggedIn",
|
||||
table: "Users");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,6 +144,9 @@ namespace MareSynchronosServer.Migrations
|
||||
b.Property<bool>("IsModerator")
|
||||
.HasColumnType("bit");
|
||||
|
||||
b.Property<DateTime>("LastLoggedIn")
|
||||
.HasColumnType("datetime2");
|
||||
|
||||
b.Property<byte[]>("Timestamp")
|
||||
.IsConcurrencyToken()
|
||||
.ValueGeneratedOnAddOrUpdate()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace MareSynchronosServer.Models
|
||||
{
|
||||
@@ -14,5 +15,7 @@ namespace MareSynchronosServer.Models
|
||||
public bool IsModerator { get; set; } = false;
|
||||
|
||||
public bool IsAdmin { get; set; } = false;
|
||||
|
||||
public DateTime LastLoggedIn { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ namespace MareSynchronosServer
|
||||
|
||||
services.AddSingleton<SystemInfoService, SystemInfoService>();
|
||||
services.AddSingleton<IUserIdProvider, IdBasedUserIdProvider>();
|
||||
services.AddScoped(_ => Configuration);
|
||||
services.AddTransient(_ => Configuration);
|
||||
|
||||
services.AddDbContextPool<MareDbContext>(options =>
|
||||
{
|
||||
|
||||
@@ -1,17 +1,13 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MareSynchronos.API;
|
||||
using MareSynchronosServer.Data;
|
||||
using MareSynchronosServer.Hubs;
|
||||
using MareSynchronosServer.Metrics;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
@@ -20,18 +16,13 @@ namespace MareSynchronosServer;
|
||||
public class SystemInfoService : IHostedService, IDisposable
|
||||
{
|
||||
private readonly ILogger<SystemInfoService> _logger;
|
||||
private readonly IServiceProvider _services;
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IHubContext<MareHub> _hubContext;
|
||||
private Timer _timer;
|
||||
public SystemInfoDto SystemInfoDto { get; private set; } = new();
|
||||
|
||||
public SystemInfoService(ILogger<SystemInfoService> logger, IServiceProvider services,
|
||||
IConfiguration configuration, IHubContext<MareHub> hubContext)
|
||||
public SystemInfoService(ILogger<SystemInfoService> logger, IHubContext<MareHub> hubContext)
|
||||
{
|
||||
_logger = logger;
|
||||
_services = services;
|
||||
_configuration = configuration;
|
||||
_hubContext = hubContext;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user