|
|
@ -56,6 +56,8 @@ namespace v2rayN.Handler
|
|
|
|
|
|
|
|
|
|
|
|
GenStatistic(singboxConfig);
|
|
|
|
GenStatistic(singboxConfig);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ConvertGeo2Ruleset(singboxConfig);
|
|
|
|
|
|
|
|
|
|
|
|
msg = string.Format(ResUI.SuccessfulConfiguration, "");
|
|
|
|
msg = string.Format(ResUI.SuccessfulConfiguration, "");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
@ -653,6 +655,7 @@ namespace v2rayN.Handler
|
|
|
|
{
|
|
|
|
{
|
|
|
|
rule.inbound = item.inboundTag;
|
|
|
|
rule.inbound = item.inboundTag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var rule1 = JsonUtils.DeepCopy(rule);
|
|
|
|
var rule2 = JsonUtils.DeepCopy(rule);
|
|
|
|
var rule2 = JsonUtils.DeepCopy(rule);
|
|
|
|
var rule3 = JsonUtils.DeepCopy(rule);
|
|
|
|
var rule3 = JsonUtils.DeepCopy(rule);
|
|
|
|
|
|
|
|
|
|
|
@ -662,11 +665,11 @@ namespace v2rayN.Handler
|
|
|
|
var countDomain = 0;
|
|
|
|
var countDomain = 0;
|
|
|
|
foreach (var it in item.domain)
|
|
|
|
foreach (var it in item.domain)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (ParseV2Domain(it, rule)) countDomain++;
|
|
|
|
if (ParseV2Domain(it, rule1)) countDomain++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (countDomain > 0)
|
|
|
|
if (countDomain > 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
rules.Add(rule);
|
|
|
|
rules.Add(rule1);
|
|
|
|
hasDomainIp = true;
|
|
|
|
hasDomainIp = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -756,6 +759,10 @@ namespace v2rayN.Handler
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (address.Equals("geoip:private"))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
rule.ip_is_private = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
else if (address.StartsWith("geoip:"))
|
|
|
|
else if (address.StartsWith("geoip:"))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (rule.geoip is null) { rule.geoip = new(); }
|
|
|
|
if (rule.geoip is null) { rule.geoip = new(); }
|
|
|
@ -772,29 +779,19 @@ namespace v2rayN.Handler
|
|
|
|
private int GenDns(ProfileItem node, SingboxConfig singboxConfig)
|
|
|
|
private int GenDns(ProfileItem node, SingboxConfig singboxConfig)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
|
|
|
Dns4Sbox? dns4Sbox;
|
|
|
|
|
|
|
|
if (_config.tunModeItem.enableTun)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var item = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box);
|
|
|
|
var item = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box);
|
|
|
|
var tunDNS = item?.tunDNS;
|
|
|
|
var strDNS = string.Empty;
|
|
|
|
if (Utils.IsNullOrEmpty(tunDNS))
|
|
|
|
if (_config.tunModeItem.enableTun)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
tunDNS = Utils.GetEmbedText(Global.TunSingboxDNSFileName);
|
|
|
|
strDNS = Utils.IsNullOrEmpty(item?.tunDNS) ? Utils.GetEmbedText(Global.TunSingboxDNSFileName) : item?.tunDNS;
|
|
|
|
}
|
|
|
|
|
|
|
|
dns4Sbox = JsonUtils.Deserialize<Dns4Sbox>(tunDNS);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var item = LazyConfig.Instance.GetDNSItem(ECoreType.sing_box);
|
|
|
|
strDNS = Utils.IsNullOrEmpty(item?.normalDNS) ? Utils.GetEmbedText(Global.DNSSingboxNormalFileName) : item?.normalDNS;
|
|
|
|
var normalDNS = item?.normalDNS;
|
|
|
|
|
|
|
|
if (Utils.IsNullOrEmpty(normalDNS))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
normalDNS = "{\"servers\":[{\"address\":\"tcp://8.8.8.8\"}]}";
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
dns4Sbox = JsonUtils.Deserialize<Dns4Sbox>(normalDNS);
|
|
|
|
var dns4Sbox = JsonUtils.Deserialize<Dns4Sbox>(strDNS);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dns4Sbox is null)
|
|
|
|
if (dns4Sbox is null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
@ -831,10 +828,10 @@ namespace v2rayN.Handler
|
|
|
|
{
|
|
|
|
{
|
|
|
|
singboxConfig.experimental = new Experimental4Sbox()
|
|
|
|
singboxConfig.experimental = new Experimental4Sbox()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
//cache_file = new CacheFile4Sbox()
|
|
|
|
cache_file = new CacheFile4Sbox()
|
|
|
|
//{
|
|
|
|
{
|
|
|
|
// enabled = true
|
|
|
|
enabled = true
|
|
|
|
//},
|
|
|
|
},
|
|
|
|
//v2ray_api = new V2ray_Api4Sbox()
|
|
|
|
//v2ray_api = new V2ray_Api4Sbox()
|
|
|
|
//{
|
|
|
|
//{
|
|
|
|
// listen = $"{Global.Loopback}:{Global.StatePort}",
|
|
|
|
// listen = $"{Global.Loopback}:{Global.StatePort}",
|
|
|
@ -852,6 +849,59 @@ namespace v2rayN.Handler
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private int ConvertGeo2Ruleset(SingboxConfig singboxConfig)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var geosite = "geosite";
|
|
|
|
|
|
|
|
var geoip = "geoip";
|
|
|
|
|
|
|
|
var ruleSets = new List<string>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//convert route geosite & geoip to ruleset
|
|
|
|
|
|
|
|
foreach (var rule in singboxConfig.route.rules.Where(t => t.geosite?.Count > 0).ToList() ?? [])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
rule.rule_set = rule?.geosite?.Select(t => $"{geosite}-{t}").ToList();
|
|
|
|
|
|
|
|
rule.geosite = null;
|
|
|
|
|
|
|
|
ruleSets.AddRange(rule.rule_set);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var rule in singboxConfig.route.rules.Where(t => t.geoip?.Count > 0).ToList() ?? [])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
rule.rule_set = rule?.geoip?.Select(t => $"{geoip}-{t}").ToList();
|
|
|
|
|
|
|
|
rule.geoip = null;
|
|
|
|
|
|
|
|
ruleSets.AddRange(rule.rule_set);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//convert dns geosite & geoip to ruleset
|
|
|
|
|
|
|
|
foreach (var rule in singboxConfig.dns?.rules.Where(t => t.geosite?.Count > 0).ToList() ?? [])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
rule.rule_set = rule?.geosite?.Select(t => $"{geosite}-{t}").ToList();
|
|
|
|
|
|
|
|
rule.geosite = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var rule in singboxConfig.dns?.rules.Where(t => t.geoip?.Count > 0).ToList() ?? [])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
rule.rule_set = rule?.geoip?.Select(t => $"{geoip}-{t}").ToList();
|
|
|
|
|
|
|
|
rule.geoip = null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var dnsRule in singboxConfig.dns?.rules.Where(t => t.rule_set?.Count > 0).ToList() ?? [])
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ruleSets.AddRange(dnsRule.rule_set);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Add ruleset srs
|
|
|
|
|
|
|
|
singboxConfig.route.rule_set = [];
|
|
|
|
|
|
|
|
foreach (var item in new HashSet<string>(ruleSets))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
singboxConfig.route.rule_set.Add(new()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
type = "remote",
|
|
|
|
|
|
|
|
format = "binary",
|
|
|
|
|
|
|
|
tag = item,
|
|
|
|
|
|
|
|
url = string.Format(Global.SingboxRulesetUrl, item.StartsWith(geosite) ? geosite : geoip, item),
|
|
|
|
|
|
|
|
download_detour = Global.ProxyTag
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#endregion private gen function
|
|
|
|
#endregion private gen function
|
|
|
|
|
|
|
|
|
|
|
|
#region Gen speedtest config
|
|
|
|
#region Gen speedtest config
|
|
|
|