mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-30 01:34:08 +00:00
GeoPrefix move to Global
This commit is contained in:
parent
81d59ce773
commit
1760a92507
5 changed files with 21 additions and 19 deletions
|
|
@ -67,6 +67,8 @@ public class Global
|
|||
public const string AsIs = "AsIs";
|
||||
public const string IPIfNonMatch = "IPIfNonMatch";
|
||||
public const string IPOnDemand = "IPOnDemand";
|
||||
public const string GeoSitePrefix = "geosite:";
|
||||
public const string GeoIPPrefix = "geoip:";
|
||||
|
||||
public const string UserEMail = "t@t.tt";
|
||||
public const string AutoRunRegPath = @"Software\Microsoft\Windows\CurrentVersion\Run";
|
||||
|
|
|
|||
|
|
@ -310,9 +310,9 @@ public partial class CoreConfigSingboxService
|
|||
|
||||
foreach (var ip in ipItems)
|
||||
{
|
||||
if (ip.StartsWith("geoip:", StringComparison.OrdinalIgnoreCase))
|
||||
if (ip.StartsWith(Global.GeoIPPrefix, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var region = ip["geoip:".Length..];
|
||||
var region = ip[Global.GeoIPPrefix.Length..];
|
||||
if (string.IsNullOrEmpty(region))
|
||||
{
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -406,10 +406,10 @@ public partial class CoreConfigSingboxService
|
|||
{
|
||||
return false;
|
||||
}
|
||||
else if (domain.StartsWith("geosite:"))
|
||||
else if (domain.StartsWith(Global.GeoSitePrefix))
|
||||
{
|
||||
rule.geosite ??= [];
|
||||
rule.geosite?.Add(domain.Substring(8));
|
||||
rule.geosite?.Add(domain[Global.GeoSitePrefix.Length..]);
|
||||
}
|
||||
else if (domain.StartsWith("regexp:"))
|
||||
{
|
||||
|
|
@ -450,28 +450,28 @@ public partial class CoreConfigSingboxService
|
|||
{
|
||||
return false;
|
||||
}
|
||||
else if (address.Equals("geoip:private"))
|
||||
else if (address.Equals($"{Global.GeoIPPrefix}private"))
|
||||
{
|
||||
rule.ip_is_private = true;
|
||||
}
|
||||
else if (address.StartsWith("geoip:"))
|
||||
else if (address.StartsWith(Global.GeoIPPrefix))
|
||||
{
|
||||
rule.geoip ??= new();
|
||||
rule.geoip?.Add(address.Substring(6));
|
||||
rule.geoip ??= [];
|
||||
rule.geoip?.Add(address[Global.GeoIPPrefix.Length..]);
|
||||
}
|
||||
else if (address.Equals("geoip:!private"))
|
||||
else if (address.Equals($"{Global.GeoIPPrefix}!private"))
|
||||
{
|
||||
rule.ip_is_private = false;
|
||||
}
|
||||
else if (address.StartsWith("geoip:!"))
|
||||
else if (address.StartsWith($"{Global.GeoIPPrefix}!"))
|
||||
{
|
||||
rule.geoip ??= new();
|
||||
rule.geoip?.Add(address.Substring(6));
|
||||
rule.geoip ??= [];
|
||||
rule.geoip?.Add(address.Substring($"{Global.GeoIPPrefix}!".Length));
|
||||
rule.invert = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
rule.ip_cidr ??= new();
|
||||
rule.ip_cidr ??= [];
|
||||
rule.ip_cidr?.Add(address);
|
||||
}
|
||||
return true;
|
||||
|
|
|
|||
|
|
@ -161,8 +161,8 @@ public partial class CoreConfigV2rayService
|
|||
.ToList();
|
||||
|
||||
foreach (var region in from ip in expectedIPs
|
||||
where ip.StartsWith("geoip:", StringComparison.OrdinalIgnoreCase)
|
||||
select ip["geoip:".Length..]
|
||||
where ip.StartsWith(Global.GeoIPPrefix, StringComparison.OrdinalIgnoreCase)
|
||||
select ip[Global.GeoIPPrefix.Length..]
|
||||
into region
|
||||
where !string.IsNullOrEmpty(region)
|
||||
select region)
|
||||
|
|
@ -197,7 +197,7 @@ public partial class CoreConfigV2rayService
|
|||
|
||||
if (item.OutboundTag == Global.DirectTag)
|
||||
{
|
||||
if (normalizedDomain.StartsWith("geosite:") || normalizedDomain.StartsWith("ext:"))
|
||||
if (normalizedDomain.StartsWith(Global.GeoSitePrefix) || normalizedDomain.StartsWith("ext:"))
|
||||
{
|
||||
var isExpectedDomain = !regionName.IsNullOrEmpty()
|
||||
|| normalizedDomain.EndsWith($"-{regionName}")
|
||||
|
|
@ -212,7 +212,7 @@ public partial class CoreConfigV2rayService
|
|||
}
|
||||
else if (item.OutboundTag != Global.BlockTag)
|
||||
{
|
||||
if (normalizedDomain.StartsWith("geosite:") || normalizedDomain.StartsWith("ext:"))
|
||||
if (normalizedDomain.StartsWith(Global.GeoSitePrefix) || normalizedDomain.StartsWith("ext:"))
|
||||
{
|
||||
proxyGeositeList.Add(normalizedDomain);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -375,8 +375,8 @@ public class UpdateService(Config config, Func<bool, string, Task> updateFunc)
|
|||
var rules = JsonUtils.Deserialize<List<RulesItem>>(routing.RuleSet);
|
||||
foreach (var item in rules ?? [])
|
||||
{
|
||||
AddPrefixedItems(item.Ip, "geoip:", geoipFiles);
|
||||
AddPrefixedItems(item.Domain, "geosite:", geoSiteFiles);
|
||||
AddPrefixedItems(item.Ip, Global.GeoIPPrefix, geoipFiles);
|
||||
AddPrefixedItems(item.Domain, Global.GeoSitePrefix, geoSiteFiles);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue