using System.Text.Json.Nodes; namespace Proxd_man.Config; public class ProxdConfig { public InboundConfig Inbounds { get; init; } = new(); public DefaultOutboundPolicy DefaultOutboundPolicy { get; init; } = DefaultOutboundPolicy.Proxy; public string RemoteDnsServer { get; init; } = "https://1.1.1.1/dns-query"; public string XrayCoreProgramDirectory { get; init; } = "./xray-core"; public string XrayCoreWorkingDirectory { get; init; } = "./xray-core"; public bool SkipUpdateXrayCore { get; init; } = false; public SubscribeSetting Subscribe { get; init; } = new(); } public class InboundConfig { public HttpInboundSetting? Http { get; init; } public SocksInboundSetting? Socks { get; init; } public List ToInboundSettings() { var inboundSettings = new List(); if (Http != null) { inboundSettings.Add(Http); } if (Socks != null) { inboundSettings.Add(Socks); } return inboundSettings; } } public interface IInboundSetting { JsonObject ToJsonSetting(); string GetTag(); } public class HttpInboundSetting : IInboundSetting { public string? BindAddress { get; init; } public ushort Port { get; init; } public BasicInboundAuthSetting? Authentication { get; init; } public JsonObject ToJsonSetting() { JsonObject setting = new() { { "protocol", "http" }, { "listen", $"{BindAddress ?? "0.0.0.0"}" }, { "port", Port }, { "tag", GetTag() }, { "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 string GetTag() { return "http-in"; } } public class SocksInboundSetting : IInboundSetting { public string? BindAddress { get; init; } public ushort Port { get; init; } public bool EnableUdp { get; init; } public string? BindAddressOnUdp { get; init; } public BasicInboundAuthSetting? Authentication { get; init; } public JsonObject ToJsonSetting() { JsonObject setting = new() { { "protocol", "socks" }, { "listen", $"{BindAddress ?? "0.0.0.0"}" }, { "port", Port }, { "tag", GetTag() }, { "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 string GetTag() { return "socks-in"; } } public class BasicInboundAuthSetting(string username, string password) { public string Username { get; } = username; public string Password { get; } = password; } public class SubscribeSetting { public List Subscribes { get; } = []; public string SubscribeSaveFile { get; } = "./subscribes.json"; }