add searching by partial ip address

This commit is contained in:
RaidMax 2022-04-04 14:27:22 -05:00
parent 89fdc00f9b
commit dc97956bc3
19 changed files with 10085 additions and 5 deletions

View File

@ -120,6 +120,9 @@ namespace Data.Context
ent.Property(_alias => _alias.SearchableName).HasMaxLength(24);
ent.HasIndex(_alias => _alias.SearchableName);
ent.HasIndex(_alias => new {_alias.Name, _alias.IPAddress});
ent.Property(alias => alias.SearchableIPAddress)
.HasComputedColumnSql(@"((IPAddress & 255) || '.' || ((IPAddress >> 8) & 255)) || '.' || ((IPAddress >> 16) & 255) || '.' || ((IPAddress >> 24) & 255)", stored: true);
ent.HasIndex(alias => alias.SearchableIPAddress);
});
modelBuilder.Entity<EFMeta>(ent =>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Data.Migrations.MySql
{
public partial class AddSearchableIPToEFAlias : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "SearchableIPAddress",
table: "EFAlias",
type: "longtext",
nullable: true,
computedColumnSql: "CONCAT((IPAddress & 255), \".\", ((IPAddress >> 8) & 255), \".\", ((IPAddress >> 16) & 255), \".\", ((IPAddress >> 24) & 255))",
stored: true)
.Annotation("MySql:CharSet", "utf8mb4");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "SearchableIPAddress",
table: "EFAlias");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Data.Migrations.MySql
{
public partial class AddIndexToSearchableIPToEFAlias : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_EFAlias_SearchableIPAddress",
table: "EFAlias",
column: "SearchableIPAddress");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_EFAlias_SearchableIPAddress",
table: "EFAlias");
}
}
}

View File

@ -804,6 +804,11 @@ namespace Data.Migrations.MySql
.HasMaxLength(24)
.HasColumnType("varchar(24)");
b.Property<string>("SearchableIPAddress")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("varchar(255)")
.HasComputedColumnSql("((IPAddress & 255) || '.' || ((IPAddress >> 8) & 255)) || '.' || ((IPAddress >> 16) & 255) || '.' || ((IPAddress >> 24) & 255)", true);
b.Property<string>("SearchableName")
.HasMaxLength(24)
.HasColumnType("varchar(24)");
@ -816,6 +821,8 @@ namespace Data.Migrations.MySql
b.HasIndex("Name");
b.HasIndex("SearchableIPAddress");
b.HasIndex("SearchableName");
b.HasIndex("Name", "IPAddress");

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,27 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Data.Migrations.Postgresql
{
public partial class AddSearchableIPToEFAlias : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "SearchableIPAddress",
table: "EFAlias",
type: "text",
nullable: true,
computedColumnSql: "CASE WHEN \"IPAddress\" IS NULL THEN 'NULL'::text ELSE (\"IPAddress\" & 255)::text || '.'::text || ((\"IPAddress\" >> 8) & 255)::text || '.'::text || ((\"IPAddress\" >> 16) & 255)::text || '.'::text || ((\"IPAddress\" >> 24) & 255)::text END",
stored: true);
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "SearchableIPAddress",
table: "EFAlias");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Data.Migrations.Postgresql
{
public partial class AddIndexToSearchableIPToEFAlias : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_EFAlias_SearchableIPAddress",
table: "EFAlias",
column: "SearchableIPAddress");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_EFAlias_SearchableIPAddress",
table: "EFAlias");
}
}
}

View File

@ -843,6 +843,11 @@ namespace Data.Migrations.Postgresql
.HasMaxLength(24)
.HasColumnType("character varying(24)");
b.Property<string>("SearchableIPAddress")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("text")
.HasComputedColumnSql("((IPAddress & 255) || '.' || ((IPAddress >> 8) & 255)) || '.' || ((IPAddress >> 16) & 255) || '.' || ((IPAddress >> 24) & 255)", true);
b.Property<string>("SearchableName")
.HasMaxLength(24)
.HasColumnType("character varying(24)");
@ -855,6 +860,8 @@ namespace Data.Migrations.Postgresql
b.HasIndex("Name");
b.HasIndex("SearchableIPAddress");
b.HasIndex("SearchableName");
b.HasIndex("Name", "IPAddress");

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,26 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Data.Migrations.Sqlite
{
public partial class AddSearchableIPToEFAlias : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<string>(
name: "SearchableIPAddress",
table: "EFAlias",
type: "TEXT",
nullable: true,
computedColumnSql: "((IPAddress & 255) || '.' || ((IPAddress >> 8) & 255)) || '.' || ((IPAddress >> 16) & 255) || '.' || ((IPAddress >> 24) & 255)");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "SearchableIPAddress",
table: "EFAlias");
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,24 @@
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Data.Migrations.Sqlite
{
public partial class AddIndexToSearchableIPToEFAlias : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateIndex(
name: "IX_EFAlias_SearchableIPAddress",
table: "EFAlias",
column: "SearchableIPAddress");
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropIndex(
name: "IX_EFAlias_SearchableIPAddress",
table: "EFAlias");
}
}
}

View File

@ -802,6 +802,11 @@ namespace Data.Migrations.Sqlite
.HasMaxLength(24)
.HasColumnType("TEXT");
b.Property<string>("SearchableIPAddress")
.ValueGeneratedOnAddOrUpdate()
.HasColumnType("TEXT")
.HasComputedColumnSql("((IPAddress & 255) || '.' || ((IPAddress >> 8) & 255)) || '.' || ((IPAddress >> 16) & 255) || '.' || ((IPAddress >> 24) & 255)");
b.Property<string>("SearchableName")
.HasMaxLength(24)
.HasColumnType("TEXT");
@ -814,6 +819,8 @@ namespace Data.Migrations.Sqlite
b.HasIndex("Name");
b.HasIndex("SearchableIPAddress");
b.HasIndex("SearchableName");
b.HasIndex("Name", "IPAddress");

View File

@ -19,6 +19,7 @@ namespace Data.Models
public string SearchableName { get; set; }
[Required]
public int? IPAddress { get; set; }
public string SearchableIPAddress { get; set; }
[Required]
public DateTime DateAdded { get; set; }

View File

@ -59,7 +59,7 @@ isInSubnet = (ip, subnet) => {
};
isSubnetBanned = (ip, list) => {
const matchingSubnets = list.filter(subnet => isInSubnet(ip, subnet, logger));
const matchingSubnets = list.filter(subnet => isInSubnet(ip, subnet));
return matchingSubnets.length !== 0;
}

View File

@ -791,7 +791,7 @@ namespace SharedLibraryCore.Services
public async Task<IList<PlayerInfo>> FindClientsByIdentifier(string identifier)
{
var trimmedIdentifier = identifier?.Trim();
if (trimmedIdentifier?.Length < _appConfig.MinimumNameLength)
if (trimmedIdentifier == null || trimmedIdentifier.Length < _appConfig.MinimumNameLength)
{
return new List<PlayerInfo>();
}
@ -812,7 +812,7 @@ namespace SharedLibraryCore.Services
var iqLinkIds = context.Aliases.Where(_alias => _alias.Active);
// we want to query for the IP Address
if (ipAddress != null)
if (ipAddress != null && trimmedIdentifier.Split('.').Length == 3)
{
iqLinkIds = iqLinkIds.Where(_alias => _alias.IPAddress == ipAddress);
}
@ -821,7 +821,7 @@ namespace SharedLibraryCore.Services
else
{
iqLinkIds = iqLinkIds.Where(_alias => EF.Functions.Like(_alias.SearchableName ?? _alias.Name.ToLower(),
$"%{trimmedIdentifier.ToLower()}%"));
$"%{trimmedIdentifier.ToLower()}%") || EF.Functions.Like(_alias.SearchableIPAddress, $"{trimmedIdentifier}%"));
}
var linkIds = await iqLinkIds
@ -858,7 +858,7 @@ namespace SharedLibraryCore.Services
LastConnection = _client.LastConnection,
ClientId = _client.ClientId,
IPAddress = _client.CurrentAlias.IPAddress.HasValue
? _client.CurrentAlias.IPAddress.Value.ToString()
? _client.CurrentAlias.SearchableIPAddress
: ""
});