/************************************************************************* * ModernUO * * Copyright 2019-2026 - ModernUO Development Team * * Email: hi@modernuo.com * * File: CrowdSecConfiguration.cs * * * * This program is free software: you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * You should have received a copy of the GNU General Public License * * along with this program. If not, see . * *************************************************************************/ using System; using System.IO; using System.Text.Json.Serialization; using Server.Json; namespace Server.Network.Bans.CrowdSec; /// /// Loads the from Configuration/crowdsec.json (matching the /// per-feature JSON config pattern used by AssistantConfiguration). Loaded once; a missing file /// writes a disabled-by-default template so operators have something to edit. /// public static class CrowdSecConfiguration { private const string _path = "Configuration/crowdsec.json"; public static CrowdSecSettings Settings { get; private set; } public static void Load() { var path = Path.Join(Core.BaseDirectory, _path); if (File.Exists(path)) { Settings = JsonConfig.Deserialize(path); } else { Settings = new CrowdSecSettings { LapiUrl = "http://127.0.0.1:8080", MachineId = "", Password = "", Origin = "modernuo", ManualBanDuration = TimeSpan.FromHours(168), FlushInterval = TimeSpan.FromSeconds(1), MaxQueue = 10000 }; Save(); } } private static void Save() { JsonConfig.Serialize(Path.Join(Core.BaseDirectory, _path), Settings); } } /// /// Bound configuration for . Read once at Configure(). /// The reporter is inert unless is true. /// public record CrowdSecSettings { /// LAPI endpoint. Default http://127.0.0.1:8080. [JsonPropertyName("lapiUrl")] public string LapiUrl { get; set; } = "http://127.0.0.1:8080"; /// Watcher machine id from cscli machines add. Empty disables reporting. [JsonPropertyName("machineId")] public string MachineId { get; set; } = ""; /// Watcher password paired with . [JsonPropertyName("password")] public string Password { get; set; } = ""; /// Decision origin stamped on our contributions. Default modernuo. [JsonPropertyName("origin")] public string Origin { get; set; } = "modernuo"; /// Duration for manual admin bans pushed to CrowdSec. Default 168h (renewable). Finite so a missed retract self-heals. [JsonPropertyName("manualBanDuration")] public TimeSpan ManualBanDuration { get; set; } = TimeSpan.FromHours(168); /// Max time the drain coalesces before flushing a batch. Default 1s. [JsonPropertyName("flushInterval")] public TimeSpan FlushInterval { get; set; } = TimeSpan.FromSeconds(1); /// Bounded contribution queue capacity; overflow is dropped (counted). Default 10000. [JsonPropertyName("maxQueue")] public int MaxQueue { get; set; } = 10000; [JsonIgnore] public bool ReportingEnabled => !string.IsNullOrWhiteSpace(MachineId) && !string.IsNullOrWhiteSpace(Password); }