🔥 Remove ProxyMode.DNSIntercept with REMOVE_DNS_INTERCEPT

This commit is contained in:
Aigio Liu
2024-09-01 00:07:27 +08:00
parent 7b9ba5e8a0
commit 7f7fde20bd
15 changed files with 27 additions and 17 deletions
@@ -7,7 +7,7 @@
<RootNamespace>BD.WTTS</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<SelfContained>false</SelfContained>
<DefineConstants>APP_REVERSE_PROXY;NONE_UI;$(DefineConstants)</DefineConstants>
<DefineConstants>APP_REVERSE_PROXY;NONE_UI;REMOVE_DNS_INTERCEPT;$(DefineConstants)</DefineConstants>
<ApplicationManifest>Properties\app.manifest</ApplicationManifest>
</PropertyGroup>
@@ -110,7 +110,7 @@
<PackageReference Include="Utf8StringInterpolation" />
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::IsOSPlatform('windows')) AND ($(RuntimeIdentifier.StartsWith('win-')) OR $(RuntimeIdentifier) == '')">
<ItemGroup Condition="!$(DefineConstants.Contains('REMOVE_DNS_INTERCEPT')) AND $([MSBuild]::IsOSPlatform('windows')) AND ($(RuntimeIdentifier.StartsWith('win-')) OR $(RuntimeIdentifier) == '')">
<PackageReference Include="Aigio.WinDivertSharp" />
</ItemGroup>
@@ -148,6 +148,7 @@ public static partial class ServiceCollectionExtensions
#if WINDOWS
#if !REMOVE_DNS_INTERCEPT
/// <summary>
/// 注册数据包拦截器
/// </summary>
@@ -170,6 +171,7 @@ public static partial class ServiceCollectionExtensions
return services;
}
#endif
#endif
}
@@ -1,6 +1,6 @@
// https://github.com/dotnetcore/FastGithub/blob/2.1.4/FastGithub.PacketIntercept/DnsInterceptHostedService.cs
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
// ReSharper disable once CheckNamespace
namespace BD.WTTS.Services.Implementation;
@@ -1,6 +1,6 @@
// https://github.com/dotnetcore/FastGithub/blob/2.1.4/FastGithub.PacketIntercept/Dns/DnsInterceptor.cs
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
using WinDivertSharp;
using DNS.Protocol;
@@ -1,6 +1,6 @@
// https://github.com/dotnetcore/FastGithub/blob/2.1.4/FastGithub.PacketIntercept/Tcp/GitInterceptor.cs
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
using static BD.WTTS.Models.Abstractions.IReverseProxyConfig;
@@ -1,6 +1,6 @@
// https://github.com/dotnetcore/FastGithub/blob/2.1.4/FastGithub.PacketIntercept/Tcp/HttpInterceptor.cs
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
using static BD.WTTS.Models.Abstractions.IReverseProxyConfig;
@@ -1,6 +1,6 @@
// https://github.com/dotnetcore/FastGithub/blob/2.1.4/FastGithub.PacketIntercept/Tcp/HttpsInterceptor.cs
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
using static BD.WTTS.Models.Abstractions.IReverseProxyConfig;
@@ -1,6 +1,6 @@
// https://github.com/dotnetcore/FastGithub/blob/2.1.4/FastGithub.PacketIntercept/Tcp/SshInterceptor.cs
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
using static BD.WTTS.Models.Abstractions.IReverseProxyConfig;
@@ -1,6 +1,6 @@
// https://github.com/dotnetcore/FastGithub/blob/2.1.4/FastGithub.PacketIntercept/TcpInterceptHostedService.cs
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
using static BD.WTTS.Models.Abstractions.IReverseProxyConfig;
@@ -1,6 +1,6 @@
// https://github.com/dotnetcore/FastGithub/blob/2.1.4/FastGithub.PacketIntercept/Tcp/TcpInterceptor.cs
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
using WinDivertSharp;
@@ -23,7 +23,7 @@ partial class YarpReverseProxyServiceImpl
services.AddReverseProxyServer();
services.AddFlowAnalyze();
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
if (ProxyMode == ProxyMode.DNSIntercept)
{
services.AddPacketIntercept();
@@ -3,7 +3,7 @@
<PropertyGroup>
<RootNamespace>BD.WTTS</RootNamespace>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<DefineConstants>WTTS_PLUGIN;WTTS_PLUGIN_ACCELERATOR;$(DefineConstants)</DefineConstants>
<DefineConstants>WTTS_PLUGIN;WTTS_PLUGIN_ACCELERATOR;REMOVE_DNS_INTERCEPT;$(DefineConstants)</DefineConstants>
<!--<EnableDynamicLoading>true</EnableDynamicLoading>-->
<AvaloniaUseCompiledBindingsByDefault>true</AvaloniaUseCompiledBindingsByDefault>
</PropertyGroup>
@@ -124,7 +124,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<ItemGroup Condition="!$(DefineConstants.Contains('REMOVE_DNS_INTERCEPT')) AND $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">
<Compile Update="Properties\WinDivertResource.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
@@ -136,7 +136,7 @@
</EmbeddedResource>
</ItemGroup>
<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'windows'">
<ItemGroup Condition="$(DefineConstants.Contains('REMOVE_DNS_INTERCEPT')) OR $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'windows'">
<Compile Remove="Properties\WinDivertResource.Designer.cs" />
<EmbeddedResource Remove="Properties\WinDivertResource.resx" />
</ItemGroup>
@@ -1,4 +1,4 @@
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
using WinDivertBinRes = BD.WTTS.Properties.WinDivertResource;
namespace Mobius.Helpers;
@@ -120,6 +120,9 @@ partial class ProxyService
switch (proxyMode)
{
#if REMOVE_DNS_INTERCEPT
case ProxyMode.DNSIntercept:
#endif
case ProxyMode.Hosts:
var inUsePort = SocketHelper.IsUsePort(proxyIp_.Value, httpsPort);
if (inUsePort)
@@ -186,7 +189,7 @@ partial class ProxyService
return Strings.CommunityFix_SetAsSystemPACProxyFail;
}
break;
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
case ProxyMode.DNSIntercept:
{
await Mobius.Helpers.WinDivertInitHelper.InitializeAsync();
@@ -315,6 +318,9 @@ partial class ProxyService
#endif
switch (proxyMode) // 先停止接入代理流量
{
#if REMOVE_DNS_INTERCEPT
case ProxyMode.DNSIntercept:
#endif
case ProxyMode.Hosts:
var needClear = hostsFileService.ContainsHostsByTag();
if (needClear)
@@ -351,7 +357,7 @@ partial class ProxyService
await platformService.SetAsSystemPACProxyAsync(false);
}
break;
#if WINDOWS
#if WINDOWS && !REMOVE_DNS_INTERCEPT
case ProxyMode.DNSIntercept:
{
// 停止时也调用初始化
@@ -11,7 +11,9 @@ public static partial class ProxySettings
{
#if WINDOWS
yield return EProxyMode.Hosts;
#if !REMOVE_DNS_INTERCEPT
yield return EProxyMode.DNSIntercept;
#endif
yield return EProxyMode.PAC;
yield return EProxyMode.System;
#elif ANDROID