mirror of
https://github.com/2dust/v2rayN.git
synced 2026-01-15 02:23:03 +00:00
Full template merges standard config DNS settings
This commit is contained in:
parent
2b28254fbc
commit
ceccdbf671
2 changed files with 91 additions and 0 deletions
|
|
@ -22,6 +22,53 @@ public partial class CoreConfigSingboxService
|
|||
return JsonUtils.Serialize(singboxConfig);
|
||||
}
|
||||
|
||||
// Ensure dns node exists
|
||||
if (singboxConfig.dns != null)
|
||||
{
|
||||
if (fullConfigTemplateNode["dns"] == null)
|
||||
{
|
||||
fullConfigTemplateNode["dns"] = JsonNode.Parse(JsonUtils.Serialize(singboxConfig.dns));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle dns rules - append instead of override
|
||||
if (fullConfigTemplateNode["dns"]["rules"] is JsonArray customDnsRulesNode)
|
||||
{
|
||||
if (JsonNode.Parse(JsonUtils.Serialize(singboxConfig.dns?.rules)) is JsonArray newDnsRules)
|
||||
{
|
||||
foreach (var ruleNode in newDnsRules)
|
||||
{
|
||||
customDnsRulesNode.Add(ruleNode?.DeepClone());
|
||||
}
|
||||
|
||||
fullConfigTemplateNode["dns"]["rules"] = customDnsRulesNode;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fullConfigTemplateNode["dns"]["rules"] = JsonNode.Parse(JsonUtils.Serialize(singboxConfig.dns?.rules));
|
||||
}
|
||||
|
||||
// Handle dns servers - append instead of override
|
||||
if (fullConfigTemplateNode["dns"]["servers"] is JsonArray customDnsServersNode)
|
||||
{
|
||||
if (JsonNode.Parse(JsonUtils.Serialize(singboxConfig.dns?.servers)) is JsonArray newDnsServers)
|
||||
{
|
||||
foreach (var serverNode in newDnsServers)
|
||||
{
|
||||
customDnsServersNode.Add(serverNode?.DeepClone());
|
||||
}
|
||||
|
||||
fullConfigTemplateNode["dns"]["servers"] = customDnsServersNode;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fullConfigTemplateNode["dns"]["servers"] = JsonNode.Parse(JsonUtils.Serialize(singboxConfig.dns?.servers));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Process outbounds
|
||||
var customOutboundsNode = fullConfigTemplateNode["outbounds"] is JsonArray outbounds ? outbounds : new JsonArray();
|
||||
foreach (var outbound in singboxConfig.outbounds)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,50 @@ public partial class CoreConfigV2rayService
|
|||
return JsonUtils.Serialize(v2rayConfig);
|
||||
}
|
||||
|
||||
// Ensure dns node exists
|
||||
if (fullConfigTemplateNode["dns"] == null)
|
||||
{
|
||||
fullConfigTemplateNode["dns"] = JsonNode.Parse(JsonUtils.Serialize(v2rayConfig.dns));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Handle dns hosts - append instead of override
|
||||
if (fullConfigTemplateNode["dns"]["hosts"] is JsonObject customDnsHostsNode)
|
||||
{
|
||||
if (JsonNode.Parse(JsonUtils.Serialize(v2rayConfig.dns.hosts)) is JsonObject newDnsHosts)
|
||||
{
|
||||
foreach (var hostNode in newDnsHosts)
|
||||
{
|
||||
customDnsHostsNode.Add(hostNode.Key, hostNode.Value?.DeepClone());
|
||||
}
|
||||
|
||||
fullConfigTemplateNode["dns"]["hosts"] = customDnsHostsNode;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fullConfigTemplateNode["dns"]["hosts"] = JsonNode.Parse(JsonUtils.Serialize(v2rayConfig.dns.hosts));
|
||||
}
|
||||
|
||||
// Handle dns servers - append instead of override
|
||||
if (fullConfigTemplateNode["dns"]["servers"] is JsonArray customDnsServersNode)
|
||||
{
|
||||
if (JsonNode.Parse(JsonUtils.Serialize(v2rayConfig.dns.servers)) is JsonArray newDnsServers)
|
||||
{
|
||||
foreach (var serverNode in newDnsServers)
|
||||
{
|
||||
customDnsServersNode.Add(serverNode?.DeepClone());
|
||||
}
|
||||
|
||||
fullConfigTemplateNode["dns"]["servers"] = customDnsServersNode;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
fullConfigTemplateNode["dns"]["servers"] = JsonNode.Parse(JsonUtils.Serialize(v2rayConfig.dns.servers));
|
||||
}
|
||||
}
|
||||
|
||||
// Handle balancer and rules modifications (for multiple load scenarios)
|
||||
if (v2rayConfig.routing?.balancers?.Count > 0)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue