mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 06:00:46 +00:00
Add endpoints to manage IPC bans (#2715)
* Add endpoints to manage IPC bans * Remove debug code * Misc. * Simplify unban logic * Add explanatory comment to new string resource
This commit is contained in:
@@ -24,6 +24,7 @@ using MvcNewtonsoftJsonOptions = Microsoft.AspNetCore.Mvc.MvcJsonOptions;
|
||||
#endif
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
@@ -88,7 +89,19 @@ internal sealed class ApiAuthenticationMiddleware {
|
||||
await context.Response.WriteJsonAsync(new GenericResponse<StatusCodeResponse>(false, statusCodeResponse), jsonOptions.Value.SerializerSettings).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
private static void ClearFailedAuthorizations(object? state = null) => FailedAuthorizations.Clear();
|
||||
internal static void ClearFailedAuthorizations(object? state = null) => FailedAuthorizations.Clear();
|
||||
|
||||
internal static HashSet<IPAddress> GetCurrentlyBannedIPs() => FailedAuthorizations.Where(static kv => kv.Value >= MaxFailedAuthorizationAttempts).Select(static kv => kv.Key).ToHashSet();
|
||||
|
||||
internal static bool UnbanIP(IPAddress ipAddress) {
|
||||
ArgumentNullException.ThrowIfNull(ipAddress);
|
||||
|
||||
if (!FailedAuthorizations.TryGetValue(ipAddress, out byte attempts) || (attempts < MaxFailedAuthorizationAttempts)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return FailedAuthorizations.TryRemove(ipAddress, out _);
|
||||
}
|
||||
|
||||
private async Task<(HttpStatusCode StatusCode, bool Permanent)> GetAuthenticationStatus(HttpContext context) {
|
||||
ArgumentNullException.ThrowIfNull(context);
|
||||
|
||||
Reference in New Issue
Block a user