require login for wildcard ip search

This commit is contained in:
RaidMax 2023-09-13 22:50:37 -05:00
parent 13d4ec3033
commit 005a8b050d
3 changed files with 17 additions and 7 deletions

View File

@ -8,9 +8,11 @@ using Data.Abstractions;
using Data.Models; using Data.Models;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using SharedLibraryCore; using SharedLibraryCore;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Dtos; using SharedLibraryCore.Dtos;
using SharedLibraryCore.Helpers; using SharedLibraryCore.Helpers;
using SharedLibraryCore.Interfaces; using SharedLibraryCore.Interfaces;
using WebfrontCore.Permissions;
using WebfrontCore.QueryHelpers.Models; using WebfrontCore.QueryHelpers.Models;
using EFClient = Data.Models.Client.EFClient; using EFClient = Data.Models.Client.EFClient;
@ -18,6 +20,7 @@ namespace IW4MAdmin.Application.QueryHelpers;
public class ClientResourceQueryHelper : IResourceQueryHelper<ClientResourceRequest, ClientResourceResponse> public class ClientResourceQueryHelper : IResourceQueryHelper<ClientResourceRequest, ClientResourceResponse>
{ {
public ApplicationConfiguration _appConfig { get; }
private readonly IDatabaseContextFactory _contextFactory; private readonly IDatabaseContextFactory _contextFactory;
private readonly IGeoLocationService _geoLocationService; private readonly IGeoLocationService _geoLocationService;
@ -27,8 +30,10 @@ public class ClientResourceQueryHelper : IResourceQueryHelper<ClientResourceRequ
public EFAlias Alias { get; set; } public EFAlias Alias { get; set; }
} }
public ClientResourceQueryHelper(IDatabaseContextFactory contextFactory, IGeoLocationService geoLocationService) public ClientResourceQueryHelper(IDatabaseContextFactory contextFactory, IGeoLocationService geoLocationService,
ApplicationConfiguration appConfig)
{ {
_appConfig = appConfig;
_contextFactory = contextFactory; _contextFactory = contextFactory;
_geoLocationService = geoLocationService; _geoLocationService = geoLocationService;
} }
@ -75,7 +80,9 @@ public class ClientResourceQueryHelper : IResourceQueryHelper<ClientResourceRequ
if (!string.IsNullOrWhiteSpace(query.ClientIp)) if (!string.IsNullOrWhiteSpace(query.ClientIp))
{ {
clientAliases = SearchByIp(query, clientAliases); clientAliases = SearchByIp(query, clientAliases,
_appConfig.HasPermission(query.RequesterPermission, WebfrontEntity.ClientIPAddress,
WebfrontPermission.Read));
} }
var iqGroupedClientAliases = clientAliases.GroupBy(a => new { a.Client.ClientId, a.Client.LastConnection }); var iqGroupedClientAliases = clientAliases.GroupBy(a => new { a.Client.ClientId, a.Client.LastConnection });
@ -203,7 +210,7 @@ public class ClientResourceQueryHelper : IResourceQueryHelper<ClientResourceRequ
} }
private static IQueryable<ClientAlias> SearchByIp(ClientResourceRequest query, private static IQueryable<ClientAlias> SearchByIp(ClientResourceRequest query,
IQueryable<ClientAlias> clientAliases) IQueryable<ClientAlias> clientAliases, bool canSearchIP)
{ {
var ipString = query.ClientIp.Trim(); var ipString = query.ClientIp.Trim();
var ipAddress = ipString.ConvertToIP(); var ipAddress = ipString.ConvertToIP();
@ -213,7 +220,7 @@ public class ClientResourceQueryHelper : IResourceQueryHelper<ClientResourceRequ
clientAliases = clientAliases.Where(clientAlias => clientAliases = clientAliases.Where(clientAlias =>
clientAlias.Alias.IPAddress != null && clientAlias.Alias.IPAddress == ipAddress); clientAlias.Alias.IPAddress != null && clientAlias.Alias.IPAddress == ipAddress);
} }
else else if(canSearchIP)
{ {
clientAliases = clientAliases.Where(clientAlias => clientAliases = clientAliases.Where(clientAlias =>
EF.Functions.Like(clientAlias.Alias.SearchableIPAddress, $"{ipString}%")); EF.Functions.Like(clientAlias.Alias.SearchableIPAddress, $"{ipString}%"));

View File

@ -249,7 +249,8 @@ namespace WebfrontCore.Controllers
{ {
ViewBag.Title = Localization["WEBFRONT_SEARCH_RESULTS_TITLE"]; ViewBag.Title = Localization["WEBFRONT_SEARCH_RESULTS_TITLE"];
ViewBag.ClientResourceRequest = request; ViewBag.ClientResourceRequest = request;
request.RequesterPermission = Client.Level;
var response = await _clientResourceHelper.QueryResource(request); var response = await _clientResourceHelper.QueryResource(request);
return request.Offset > 0 return request.Offset > 0
? PartialView("Find/_AdvancedFindList", response.Results) ? PartialView("Find/_AdvancedFindList", response.Results)

View File

@ -16,7 +16,9 @@ public class ClientResourceRequest : ClientPaginationRequest
public EFClient.Permission? ClientLevel { get; set; } public EFClient.Permission? ClientLevel { get; set; }
public Reference.Game? GameName { get; set; } public Reference.Game? GameName { get; set; }
public bool IncludeGeolocationData { get; set; } = true; public bool IncludeGeolocationData { get; set; } = true;
public EFClient.Permission RequesterPermission { get; set; } = EFClient.Permission.User;
public bool HasData => !string.IsNullOrEmpty(ClientName) || !string.IsNullOrEmpty(ClientIp) || public bool HasData => !string.IsNullOrEmpty(ClientName) || !string.IsNullOrEmpty(ClientIp) ||
!string.IsNullOrEmpty(ClientGuid) || ClientLevel is not null || GameName is not null; !string.IsNullOrEmpty(ClientGuid) || ClientLevel is not null || GameName is not null;
} }