using System.Text.Json.Nodes; namespace Proxd_man.Config; public class ProxdConfig { public InboundConfig Inbound { get; init; } = new(new HttpInboundSetting()); public DefaultOutboundPolicy DefaultOutboundPolicy { get; init; } = DefaultOutboundPolicy.Proxy; public SubscribeSetting Subscribe { get; init; } = new(); } public class InboundConfig(HttpInboundSetting? http = null, SocksInboundSetting? socks = null) { public HttpInboundSetting? Http { get; } = http; public SocksInboundSetting? Socks { get; } = socks; } public interface IInboundSetting { JsonObject ToJsonSetting(); } public class HttpInboundSetting( string? bindAddress = null, ushort port = 1080, BasicInboundAuthSetting? authentication = null) : IInboundSetting { public string? BindAddress { get; } = bindAddress; public ushort Port = port; public BasicInboundAuthSetting? Authentication { get; } = authentication; public JsonObject ToJsonSetting() { JsonObject setting = new() { { "protocol", "http" }, { "listen", $"{BindAddress ?? "0.0.0.0"}" }, { "port", Port }, { "tag", "http-in" }, { "sniffing", new JsonObject { { "enabled", true }, { "routeOnly", true }, { "metadataOnly", true }, { "destOverride", new JsonArray("http", "tls", "quic") } } } }; if (Authentication != null) { setting.Add("settings", new JsonObject { { "accounts", new JsonArray(new JsonObject { { "user", Authentication.Username }, { "pass", Authentication.Password } }) } }); } return setting; } } public class SocksInboundSetting( string? bindAddress = null, ushort port = 1080, bool enableUdp = true, string? bindAddressOnUdp = "127.0.0.1", BasicInboundAuthSetting? authentication = null) : IInboundSetting { public string? BindAddress { get; } = bindAddress; public ushort Port = port; public bool EnableUdp { get; } = enableUdp; public string? BindAddressOnUdp { get; } = bindAddressOnUdp; public BasicInboundAuthSetting? Authentication { get; } = authentication; public JsonObject ToJsonSetting() { JsonObject setting = new() { { "protocol", "http" }, { "listen", $"{BindAddress ?? "0.0.0.0"}" }, { "port", Port }, { "tag", "http-in" }, { "sniffing", new JsonObject { { "enabled", true }, { "routeOnly", true }, { "metadataOnly", true }, { "destOverride", new JsonArray("http", "tls", "quic") } } } }; var settingJson = new JsonObject { { "udp", EnableUdp }, { "ip", BindAddressOnUdp} }; if (Authentication != null) { settingJson.Add("auth", "password"); settingJson.Add("accounts", new JsonArray(new JsonObject { { "user", Authentication.Username }, { "pass", Authentication.Password } })); } else { settingJson.Add("auth", "noauth"); } setting.Add("settings", settingJson); return setting; } } public class BasicInboundAuthSetting(string username, string password) { public string Username { get; } = username; public string Password { get; } = password; } public class SubscribeSetting { public List Subscribes { get; } = []; }