namespace EmbedIO.Security { /// /// Provides extension methods for and derived classes. /// public static class IPBanningModuleExtensions { /// /// Adds a collection of valid IPs that never will be banned. /// /// The type of the module. /// The module on which this method is called. /// A collection of valid IPs that never will be banned. /// /// with its whitelist configured. /// public static TModule WithWhitelist(this TModule @this, params string[] value) where TModule : IPBanningModule { @this.AddToWhitelist(value); return @this; } /// /// Add a collection of Regex to match the log messages against as a criterion for banning IP addresses. /// /// The type of the module. /// The module on which this method is called. /// A collection of regex to match log messages against. /// /// with a fail regex criterion configured. /// public static TModule WithRegexRules(this TModule @this, params string[] value) where TModule : IPBanningModule => WithRegexRules(@this, IPBanningRegexCriterion.DefaultMaxMatchCount, IPBanningRegexCriterion.DefaultSecondsMatchingPeriod, value); /// /// Add a collection of Regex to match the log messages against as a criterion for banning IP addresses. /// /// The type of the module. /// The module on which this method is called. /// The maximum match count. /// The seconds matching period. /// A collection of regex to match log messages against. /// /// with a fail regex criterion configured. /// public static TModule WithRegexRules(this TModule @this, int maxMatchCount, int secondsMatchingPeriod, params string[] value) where TModule : IPBanningModule { @this.RegisterCriterion(new IPBanningRegexCriterion(@this, value, maxMatchCount, secondsMatchingPeriod)); return @this; } /// /// Sets a maximum amount of requests per second as a criterion for banning IP addresses. /// /// The type of the module. /// The module on which this method is called. /// The maximum requests per second. /// /// with a maximum requests per second configured. /// public static TModule WithMaxRequestsPerSecond(this TModule @this, int maxRequests = IPBanningRequestsCriterion.DefaultMaxRequestsPerSecond) where TModule : IPBanningModule { @this.RegisterCriterion(new IPBanningRequestsCriterion(maxRequests)); return @this; } } }