Adjust some config for sing-box

pull/3786/head
2dust 2 years ago
parent c8ae834f50
commit 42f7c7cb43

@ -50,7 +50,7 @@ namespace v2rayN.Handler
routing(singboxConfig); routing(singboxConfig);
dns(singboxConfig); dns(node, singboxConfig);
//statistic(singboxConfig); //statistic(singboxConfig);
@ -133,7 +133,7 @@ namespace v2rayN.Handler
inbound.listen_port = LazyConfig.Instance.GetLocalPort(Global.InboundSocks); inbound.listen_port = LazyConfig.Instance.GetLocalPort(Global.InboundSocks);
inbound.sniff = _config.inbound[0].sniffingEnabled; inbound.sniff = _config.inbound[0].sniffingEnabled;
inbound.sniff_override_destination = _config.inbound[0].routeOnly ? false : _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 //http
var inbound2 = GetInbound(inbound, Global.InboundHttp, 1, false); var inbound2 = GetInbound(inbound, Global.InboundHttp, 1, false);
@ -635,10 +635,13 @@ namespace v2rayN.Handler
#endregion routing rule private #endregion routing rule private
private int dns(SingboxConfig singboxConfig) #region dns private
private int dns(ProfileItem node, SingboxConfig singboxConfig)
{ {
try try
{ {
Dns4Sbox? dns4Sbox;
if (_config.tunModeItem.enableTun) if (_config.tunModeItem.enableTun)
{ {
string tunDNS = String.Empty; string tunDNS = String.Empty;
@ -650,12 +653,11 @@ namespace v2rayN.Handler
{ {
tunDNS = _config.tunModeItem.proxyDNS; tunDNS = _config.tunModeItem.proxyDNS;
} }
if (tunDNS.IsNullOrEmpty() || Utils.ParseJson(tunDNS)?.ContainsKey("servers") == false) if (tunDNS.IsNullOrEmpty() || Utils.FromJson<Dns4Sbox>(tunDNS) is null)
{ {
tunDNS = Utils.GetEmbedText(Global.TunSingboxDNSFileName); tunDNS = Utils.GetEmbedText(Global.TunSingboxDNSFileName);
} }
var obj = Utils.ParseJson(tunDNS); dns4Sbox = Utils.FromJson<Dns4Sbox>(tunDNS);
singboxConfig.dns = obj;
} }
else else
{ {
@ -666,12 +668,33 @@ namespace v2rayN.Handler
normalDNS = "{\"servers\":[{\"address\":\"tcp://8.8.8.8\"}]}"; normalDNS = "{\"servers\":[{\"address\":\"tcp://8.8.8.8\"}]}";
} }
var obj = Utils.ParseJson(normalDNS); dns4Sbox = Utils.FromJson<Dns4Sbox>(normalDNS);
if (obj?.ContainsKey("servers") == true) }
if (dns4Sbox is null)
{
return 0;
}
//Add the dns of the remote server domain
if (Utils.IsDomain(node.address))
{
if (dns4Sbox.rules is null)
{ {
singboxConfig.dns = obj; 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<string>() { node.address }
});
} }
singboxConfig.dns = dns4Sbox;
} }
catch (Exception ex) catch (Exception ex)
{ {
@ -680,6 +703,8 @@ namespace v2rayN.Handler
return 0; return 0;
} }
#endregion dns private
private int statistic(SingboxConfig singboxConfig) private int statistic(SingboxConfig singboxConfig)
{ {
if (_config.guiItem.enableStatistics) if (_config.guiItem.enableStatistics)

@ -17,11 +17,11 @@
], ],
"rules": [ "rules": [
{ {
"geosite": "cn", "geosite": [ "cn" ],
"server": "local" "server": "local"
}, },
{ {
"geosite": "category-ads-all", "geosite": [ "category-ads-all" ],
"server": "block" "server": "block"
} }
]} ]}

@ -17,12 +17,12 @@
], ],
"rules": [ "rules": [
{ {
"geosite": "cn", "geosite": [ "cn" ],
"server": "local", "server": "local",
"disable_cache": true "disable_cache": true
}, },
{ {
"geosite": "category-ads-all", "geosite": [ "category-ads-all" ],
"server": "block", "server": "block",
"disable_cache": true "disable_cache": true
} }

@ -554,14 +554,7 @@ namespace v2rayN
return false; return false;
} }
//清除要验证字符串中的空格 return Uri.CheckHostName(domain) == UriHostNameType.Dns;
//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);
} }
/// <summary> /// <summary>

@ -73,8 +73,8 @@ namespace v2rayN.ViewModels
} }
if (!Utils.IsNullOrEmpty(normalDNS2)) if (!Utils.IsNullOrEmpty(normalDNS2))
{ {
var obj2 = Utils.ParseJson(normalDNS2); var obj2 = Utils.FromJson<Dns4Sbox>(normalDNS2);
if (obj2 == null || obj2.ContainsKey("servers") == false) if (obj2 == null)
{ {
UI.Show(ResUI.FillCorrectDNSText); UI.Show(ResUI.FillCorrectDNSText);
return; return;

@ -939,6 +939,7 @@ namespace v2rayN.ViewModels
{ {
subid = _subId, subid = _subId,
configType = eConfigType, configType = eConfigType,
isSub = false,
}; };
} }
else else
@ -1337,7 +1338,6 @@ namespace v2rayN.ViewModels
{ {
//RefreshServers(); //RefreshServers();
Reload(); Reload();
TunModeSwitch();
} }
} }
@ -1352,6 +1352,7 @@ namespace v2rayN.ViewModels
Reload(); Reload();
} }
} }
private void DNSSetting() private void DNSSetting()
{ {
var ret = (new DNSSettingWindow()).ShowDialog(); var ret = (new DNSSettingWindow()).ShowDialog();
@ -1483,10 +1484,6 @@ namespace v2rayN.ViewModels
BlReloadEnabled = false; BlReloadEnabled = false;
})); }));
//if (Global.reloadV2ray)
//{
// _noticeHandler?.SendMessage(Global.CommandClearMsg);
//}
await Task.Run(() => await Task.Run(() =>
{ {
_coreHandler.LoadCore(_config); _coreHandler.LoadCore(_config);
@ -1620,8 +1617,8 @@ namespace v2rayN.ViewModels
if (_config.tunModeItem.enableTun != EnableTun) if (_config.tunModeItem.enableTun != EnableTun)
{ {
_config.tunModeItem.enableTun = EnableTun; _config.tunModeItem.enableTun = EnableTun;
Reload();
} }
TunModeSwitch();
} }
private void TunModeSwitch() private void TunModeSwitch()

Loading…
Cancel
Save