mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-05-03 17:38:22 +00:00
Only allow a single approved IP address
This commit is contained in:
parent
f169236613
commit
eb21c7042f
16 changed files with 124 additions and 141 deletions
|
@ -7,6 +7,12 @@
|
|||
"commands": [
|
||||
"dotnet-ef"
|
||||
]
|
||||
},
|
||||
"dotnet-trace": {
|
||||
"version": "6.0.328102",
|
||||
"commands": [
|
||||
"dotnet-trace"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
|
@ -4,6 +4,9 @@
|
|||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse" />
|
||||
<option name="PASS_PARENT_ENVS" value="1" />
|
||||
<envs>
|
||||
<env name="ASPNETCORE_ENVIRONMENT" value="Development" />
|
||||
</envs>
|
||||
<option name="USE_EXTERNAL_CONSOLE" value="0" />
|
||||
<option name="USE_MONO" value="0" />
|
||||
<option name="RUNTIME_ARGUMENTS" value="" />
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse" />
|
||||
<option name="PASS_PARENT_ENVS" value="1" />
|
||||
<envs>
|
||||
<env name="ASPNETCORE_ENVIRONMENT" value="Development" />
|
||||
</envs>
|
||||
<option name="USE_EXTERNAL_CONSOLE" value="0" />
|
||||
<option name="USE_MONO" value="0" />
|
||||
<option name="RUNTIME_ARGUMENTS" value="" />
|
||||
|
|
|
@ -4,6 +4,9 @@
|
|||
<option name="PROGRAM_PARAMETERS" value="" />
|
||||
<option name="WORKING_DIRECTORY" value="$PROJECT_DIR$/ProjectLighthouse" />
|
||||
<option name="PASS_PARENT_ENVS" value="1" />
|
||||
<envs>
|
||||
<env name="ASPNETCORE_ENVIRONMENT" value="Development" />
|
||||
</envs>
|
||||
<option name="USE_EXTERNAL_CONSOLE" value="0" />
|
||||
<option name="USE_MONO" value="0" />
|
||||
<option name="RUNTIME_ARGUMENTS" value="" />
|
||||
|
|
|
@ -82,7 +82,7 @@ public class LoginController : ControllerBase
|
|||
|
||||
if (ServerConfiguration.Instance.Authentication.UseExternalAuth)
|
||||
{
|
||||
if (this.database.UserApprovedIpAddresses.Where(a => a.UserId == user.UserId).Select(a => a.IpAddress).Contains(ipAddress))
|
||||
if (user.ApprovedIPAddress == ipAddress)
|
||||
{
|
||||
token.Approved = true;
|
||||
}
|
||||
|
|
|
@ -32,15 +32,8 @@ public class AutoApprovalController : ControllerBase
|
|||
if (authAttempt.GameToken.UserId != user.UserId) return this.Redirect("/login");
|
||||
|
||||
authAttempt.GameToken.Approved = true;
|
||||
user.ApprovedIPAddress = authAttempt.IPAddress;
|
||||
|
||||
UserApprovedIpAddress approvedIpAddress = new()
|
||||
{
|
||||
UserId = user.UserId,
|
||||
User = user,
|
||||
IpAddress = authAttempt.IPAddress,
|
||||
};
|
||||
|
||||
this.database.UserApprovedIpAddresses.Add(approvedIpAddress);
|
||||
this.database.AuthenticationAttempts.Remove(authAttempt);
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
@ -48,20 +41,16 @@ public class AutoApprovalController : ControllerBase
|
|||
return this.Redirect("/authentication");
|
||||
}
|
||||
|
||||
[HttpGet("revokeAutoApproval/{id:int}")]
|
||||
public async Task<IActionResult> RevokeAutoApproval([FromRoute] int id)
|
||||
[HttpGet("revokeAutoApproval")]
|
||||
public async Task<IActionResult> RevokeAutoApproval()
|
||||
{
|
||||
User? user = this.database.UserFromWebRequest(this.Request);
|
||||
if (user == null) return this.Redirect("/login");
|
||||
|
||||
UserApprovedIpAddress? approvedIpAddress = await this.database.UserApprovedIpAddresses.FirstOrDefaultAsync(a => a.UserApprovedIpAddressId == id);
|
||||
if (approvedIpAddress == null) return this.BadRequest();
|
||||
if (approvedIpAddress.UserId != user.UserId) return this.Redirect("/login");
|
||||
|
||||
this.database.UserApprovedIpAddresses.Remove(approvedIpAddress);
|
||||
user.ApprovedIPAddress = null;
|
||||
|
||||
await this.database.SaveChangesAsync();
|
||||
|
||||
return this.Redirect("/authentication/autoApprovals");
|
||||
return this.Redirect("/authentication");
|
||||
}
|
||||
}
|
|
@ -21,18 +21,24 @@ else
|
|||
}
|
||||
}
|
||||
|
||||
<a href="/authentication/autoApprovals">
|
||||
<button class="ui small blue button">
|
||||
<i class="cog icon"></i>
|
||||
<span>Manage automatically approved IP addresses</span>
|
||||
@if (Model.User!.ApprovedIPAddress != null)
|
||||
{
|
||||
<a href="/authentication/revokeAutoApproval">
|
||||
<button class="ui red button">
|
||||
<i class="trash icon"></i>
|
||||
<span>Revoke automatically approved IP Address (@Model.User!.ApprovedIPAddress)</span>
|
||||
</button>
|
||||
</a>
|
||||
}
|
||||
@if (Model.AuthenticationAttempts.Count > 1)
|
||||
{
|
||||
<a href="/authentication/denyAll">
|
||||
<button class="ui small red button">
|
||||
<button class="ui red button">
|
||||
<i class="x icon"></i>
|
||||
<span>Deny all</span>
|
||||
</button>
|
||||
</a>
|
||||
}
|
||||
|
||||
@foreach (AuthenticationAttempt authAttempt in Model.AuthenticationAttempts)
|
||||
{
|
||||
|
@ -41,19 +47,19 @@ else
|
|||
<p>A <b>@authAttempt.Platform</b> authentication request was logged at <b>@timestamp.ToString("MM/dd/yyyy @ h:mm tt") UTC</b> from the IP address <b>@authAttempt.IPAddress</b>.</p>
|
||||
<div>
|
||||
<a href="/authentication/autoApprove/@authAttempt.AuthenticationAttemptId">
|
||||
<button class="ui tiny green button">
|
||||
<button class="ui small green button">
|
||||
<i class="check icon"></i>
|
||||
<span>Automatically approve every time</span>
|
||||
</button>
|
||||
</a>
|
||||
<a href="/authentication/approve/@authAttempt.AuthenticationAttemptId">
|
||||
<button class="ui tiny yellow button">
|
||||
<button class="ui small yellow button">
|
||||
<i class="check icon"></i>
|
||||
<span>Approve this time</span>
|
||||
</button>
|
||||
</a>
|
||||
<a href="/authentication/deny/@authAttempt.AuthenticationAttemptId">
|
||||
<button class="ui tiny red button">
|
||||
<button class="ui small red button">
|
||||
<i class="x icon"></i>
|
||||
<span>Deny</span>
|
||||
</button>
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
@page "/authentication/autoApprovals"
|
||||
@using LBPUnion.ProjectLighthouse.PlayerData.Profiles
|
||||
@using LBPUnion.ProjectLighthouse.Types
|
||||
@model LBPUnion.ProjectLighthouse.Servers.Website.Pages.ExternalAuth.ManageUserApprovedIpAddressesPage
|
||||
|
||||
@{
|
||||
Layout = "Layouts/BaseLayout";
|
||||
Model.Title = "Automatically approved IP addresses";
|
||||
}
|
||||
|
||||
|
||||
@foreach (UserApprovedIpAddress approvedIpAddress in Model.ApprovedIpAddresses)
|
||||
{
|
||||
<div class="ui blue segment">
|
||||
<p>@approvedIpAddress.IpAddress</p>
|
||||
<a href="/authentication/revokeAutoApproval/@approvedIpAddress.UserApprovedIpAddressId">
|
||||
<button class="ui red button">
|
||||
<i class="trash icon"></i>
|
||||
<span>Revoke</span>
|
||||
</button>
|
||||
</a>
|
||||
</div>
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
#nullable enable
|
||||
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
||||
using LBPUnion.ProjectLighthouse.Servers.Website.Pages.Layouts;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Servers.Website.Pages.ExternalAuth;
|
||||
|
||||
public class ManageUserApprovedIpAddressesPage : BaseLayout
|
||||
{
|
||||
public List<UserApprovedIpAddress> ApprovedIpAddresses = new();
|
||||
|
||||
public ManageUserApprovedIpAddressesPage(Database database) : base(database)
|
||||
{}
|
||||
|
||||
public async Task<IActionResult> OnGet()
|
||||
{
|
||||
User? user = this.Database.UserFromWebRequest(this.Request);
|
||||
if (user == null) return this.Redirect("/login");
|
||||
|
||||
this.ApprovedIpAddresses = await this.Database.UserApprovedIpAddresses.Where(a => a.UserId == user.UserId).ToListAsync();
|
||||
|
||||
return this.Page();
|
||||
}
|
||||
}
|
|
@ -58,7 +58,10 @@ public class WebsiteStartup
|
|||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseStaticFiles();
|
||||
app.UseStaticFiles(new StaticFileOptions
|
||||
{
|
||||
ServeUnknownFileTypes = true,
|
||||
});
|
||||
|
||||
app.UseEndpoints(endpoints => endpoints.MapControllers());
|
||||
app.UseEndpoints(endpoints => endpoints.MapRazorPages());
|
||||
|
|
|
@ -41,7 +41,6 @@ public class Database : DbContext
|
|||
public DbSet<AuthenticationAttempt> AuthenticationAttempts { get; set; }
|
||||
public DbSet<Review> Reviews { get; set; }
|
||||
public DbSet<RatedReview> RatedReviews { get; set; }
|
||||
public DbSet<UserApprovedIpAddress> UserApprovedIpAddresses { get; set; }
|
||||
public DbSet<DatabaseCategory> CustomCategories { get; set; }
|
||||
public DbSet<Reaction> Reactions { get; set; }
|
||||
public DbSet<GriefReport> Reports { get; set; }
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
using LBPUnion.ProjectLighthouse;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Metadata;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace ProjectLighthouse.Migrations
|
||||
{
|
||||
[DbContext(typeof(Database))]
|
||||
[Migration("20220611221819_OnlyAllowSingleApprovedIP")]
|
||||
public class OnlyAllowSingleApprovedIP : Migration
|
||||
{
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "UserApprovedIpAddresses");
|
||||
|
||||
migrationBuilder.AddColumn<string>(
|
||||
name: "ApprovedIPAddress",
|
||||
table: "Users",
|
||||
type: "longtext",
|
||||
nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
}
|
||||
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropColumn(
|
||||
name: "ApprovedIPAddress",
|
||||
table: "Users");
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "UserApprovedIpAddresses",
|
||||
columns: table => new
|
||||
{
|
||||
UserApprovedIpAddressId = table.Column<int>(type: "int", nullable: false)
|
||||
.Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
|
||||
UserId = table.Column<int>(type: "int", nullable: false),
|
||||
IpAddress = table.Column<string>(type: "longtext", nullable: true)
|
||||
.Annotation("MySql:CharSet", "utf8mb4")
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_UserApprovedIpAddresses", x => x.UserApprovedIpAddressId);
|
||||
table.ForeignKey(
|
||||
name: "FK_UserApprovedIpAddresses_Users_UserId",
|
||||
column: x => x.UserId,
|
||||
principalTable: "Users",
|
||||
principalColumn: "UserId",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
})
|
||||
.Annotation("MySql:CharSet", "utf8mb4");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_UserApprovedIpAddresses_UserId",
|
||||
table: "UserApprovedIpAddresses",
|
||||
column: "UserId");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -595,6 +595,9 @@ namespace ProjectLighthouse.Migrations
|
|||
b.Property<int>("AdminGrantedSlots")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("ApprovedIPAddress")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<bool>("Banned")
|
||||
.HasColumnType("tinyint(1)");
|
||||
|
||||
|
@ -659,25 +662,6 @@ namespace ProjectLighthouse.Migrations
|
|||
b.ToTable("Users");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("LBPUnion.ProjectLighthouse.PlayerData.Profiles.UserApprovedIpAddress", b =>
|
||||
{
|
||||
b.Property<int>("UserApprovedIpAddressId")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("int");
|
||||
|
||||
b.Property<string>("IpAddress")
|
||||
.HasColumnType("longtext");
|
||||
|
||||
b.Property<int>("UserId")
|
||||
.HasColumnType("int");
|
||||
|
||||
b.HasKey("UserApprovedIpAddressId");
|
||||
|
||||
b.HasIndex("UserId");
|
||||
|
||||
b.ToTable("UserApprovedIpAddresses");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("LBPUnion.ProjectLighthouse.PlayerData.Reaction", b =>
|
||||
{
|
||||
b.Property<int>("RatingId")
|
||||
|
@ -1035,17 +1019,6 @@ namespace ProjectLighthouse.Migrations
|
|||
b.Navigation("Location");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("LBPUnion.ProjectLighthouse.PlayerData.Profiles.UserApprovedIpAddress", b =>
|
||||
{
|
||||
b.HasOne("LBPUnion.ProjectLighthouse.PlayerData.Profiles.User", "User")
|
||||
.WithMany()
|
||||
.HasForeignKey("UserId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.Navigation("User");
|
||||
});
|
||||
|
||||
modelBuilder.Entity("LBPUnion.ProjectLighthouse.PlayerData.Reviews.RatedReview", b =>
|
||||
{
|
||||
b.HasOne("LBPUnion.ProjectLighthouse.PlayerData.Reviews.Review", "Review")
|
||||
|
|
|
@ -143,6 +143,9 @@ public class User
|
|||
[JsonIgnore]
|
||||
public string BannedReason { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public string? ApprovedIPAddress { get; set; }
|
||||
|
||||
public string Serialize(GameVersion gameVersion = GameVersion.LittleBigPlanet1)
|
||||
{
|
||||
string user = LbpSerializer.TaggedStringElement("npHandle", this.Username, "icon", this.IconHash) +
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
||||
|
||||
public class UserApprovedIpAddress
|
||||
{
|
||||
[Key]
|
||||
public int UserApprovedIpAddressId { get; set; }
|
||||
|
||||
public int UserId { get; set; }
|
||||
|
||||
[ForeignKey(nameof(UserId))]
|
||||
public User User { get; set; }
|
||||
|
||||
public string IpAddress { get; set; }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue