diff --git a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs index 200d072e..efda6eb9 100644 --- a/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs +++ b/v2rayN/v2rayN/Handler/CoreConfigSingbox.cs @@ -50,7 +50,7 @@ namespace v2rayN.Handler routing(singboxConfig); - dns(singboxConfig); + dns(node, singboxConfig); //statistic(singboxConfig); @@ -133,7 +133,7 @@ namespace v2rayN.Handler inbound.listen_port = LazyConfig.Instance.GetLocalPort(Global.InboundSocks); inbound.sniff = _config.inbound[0].sniffingEnabled; inbound.sniff_override_destination = _config.inbound[0].routeOnly ? false : _config.inbound[0].sniffingEnabled; - inbound.domain_strategy = Utils.IsNullOrEmpty(_config.routingBasicItem.domainStrategy4Singbox) ? null: _config.routingBasicItem.domainStrategy4Singbox; + inbound.domain_strategy = Utils.IsNullOrEmpty(_config.routingBasicItem.domainStrategy4Singbox) ? null : _config.routingBasicItem.domainStrategy4Singbox; //http var inbound2 = GetInbound(inbound, Global.InboundHttp, 1, false); @@ -635,10 +635,13 @@ namespace v2rayN.Handler #endregion routing rule private - private int dns(SingboxConfig singboxConfig) + #region dns private + + private int dns(ProfileItem node, SingboxConfig singboxConfig) { try { + Dns4Sbox? dns4Sbox; if (_config.tunModeItem.enableTun) { string tunDNS = String.Empty; @@ -650,12 +653,11 @@ namespace v2rayN.Handler { tunDNS = _config.tunModeItem.proxyDNS; } - if (tunDNS.IsNullOrEmpty() || Utils.ParseJson(tunDNS)?.ContainsKey("servers") == false) + if (tunDNS.IsNullOrEmpty() || Utils.FromJson(tunDNS) is null) { tunDNS = Utils.GetEmbedText(Global.TunSingboxDNSFileName); } - var obj = Utils.ParseJson(tunDNS); - singboxConfig.dns = obj; + dns4Sbox = Utils.FromJson(tunDNS); } else { @@ -666,12 +668,33 @@ namespace v2rayN.Handler normalDNS = "{\"servers\":[{\"address\":\"tcp://8.8.8.8\"}]}"; } - var obj = Utils.ParseJson(normalDNS); - if (obj?.ContainsKey("servers") == true) - { - singboxConfig.dns = obj; - } + dns4Sbox = Utils.FromJson(normalDNS); } + if (dns4Sbox is null) + { + return 0; + } + //Add the dns of the remote server domain + if (Utils.IsDomain(node.address)) + { + if (dns4Sbox.rules is null) + { + dns4Sbox.rules = new(); + } + dns4Sbox.servers.Add(new() + { + tag = "local_local", + address = "223.5.5.5", + detour = "direct" + }); + dns4Sbox.rules.Add(new() + { + server = "local_local", + domain = new List() { node.address } + }); + } + + singboxConfig.dns = dns4Sbox; } catch (Exception ex) { @@ -680,6 +703,8 @@ namespace v2rayN.Handler return 0; } + #endregion dns private + private int statistic(SingboxConfig singboxConfig) { if (_config.guiItem.enableStatistics) diff --git a/v2rayN/v2rayN/Sample/dns_singbox_normal b/v2rayN/v2rayN/Sample/dns_singbox_normal index dc6e83a7..d75d9e97 100644 --- a/v2rayN/v2rayN/Sample/dns_singbox_normal +++ b/v2rayN/v2rayN/Sample/dns_singbox_normal @@ -17,11 +17,11 @@ ], "rules": [ { - "geosite": "cn", + "geosite": [ "cn" ], "server": "local" }, { - "geosite": "category-ads-all", + "geosite": [ "category-ads-all" ], "server": "block" } ]} diff --git a/v2rayN/v2rayN/Sample/tun_singbox_dns b/v2rayN/v2rayN/Sample/tun_singbox_dns index 603122be..b0e58d69 100644 --- a/v2rayN/v2rayN/Sample/tun_singbox_dns +++ b/v2rayN/v2rayN/Sample/tun_singbox_dns @@ -17,12 +17,12 @@ ], "rules": [ { - "geosite": "cn", + "geosite": [ "cn" ], "server": "local", "disable_cache": true }, { - "geosite": "category-ads-all", + "geosite": [ "category-ads-all" ], "server": "block", "disable_cache": true } diff --git a/v2rayN/v2rayN/Tool/Utils.cs b/v2rayN/v2rayN/Tool/Utils.cs index 10932cf5..fbbd7516 100644 --- a/v2rayN/v2rayN/Tool/Utils.cs +++ b/v2rayN/v2rayN/Tool/Utils.cs @@ -554,14 +554,7 @@ namespace v2rayN return false; } - //清除要验证字符串中的空格 - //domain = domain.TrimEx(); - - //模式字符串 - string pattern = @"^(?=^.{3,255}$)[a-zA-Z0-9][-a-zA-Z0-9]{0,62}(\.[a-zA-Z0-9][-a-zA-Z0-9]{0,62})+$"; - - //验证 - return IsMatch(domain, pattern); + return Uri.CheckHostName(domain) == UriHostNameType.Dns; } /// diff --git a/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs b/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs index ac31cd49..c1e1ee6c 100644 --- a/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/DNSSettingViewModel.cs @@ -73,8 +73,8 @@ namespace v2rayN.ViewModels } if (!Utils.IsNullOrEmpty(normalDNS2)) { - var obj2 = Utils.ParseJson(normalDNS2); - if (obj2 == null || obj2.ContainsKey("servers") == false) + var obj2 = Utils.FromJson(normalDNS2); + if (obj2 == null) { UI.Show(ResUI.FillCorrectDNSText); return; diff --git a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs index df67105c..b809d97d 100644 --- a/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs +++ b/v2rayN/v2rayN/ViewModels/MainWindowViewModel.cs @@ -939,6 +939,7 @@ namespace v2rayN.ViewModels { subid = _subId, configType = eConfigType, + isSub = false, }; } else @@ -1337,7 +1338,6 @@ namespace v2rayN.ViewModels { //RefreshServers(); Reload(); - TunModeSwitch(); } } @@ -1352,6 +1352,7 @@ namespace v2rayN.ViewModels Reload(); } } + private void DNSSetting() { var ret = (new DNSSettingWindow()).ShowDialog(); @@ -1483,10 +1484,6 @@ namespace v2rayN.ViewModels BlReloadEnabled = false; })); - //if (Global.reloadV2ray) - //{ - // _noticeHandler?.SendMessage(Global.CommandClearMsg); - //} await Task.Run(() => { _coreHandler.LoadCore(_config); @@ -1620,8 +1617,8 @@ namespace v2rayN.ViewModels if (_config.tunModeItem.enableTun != EnableTun) { _config.tunModeItem.enableTun = EnableTun; + Reload(); } - TunModeSwitch(); } private void TunModeSwitch()