custom proxy exceptions

This commit is contained in:
ASSANDHOLE 2021-06-05 22:29:30 +08:00
parent 5b271108c0
commit bb836e7da2
16 changed files with 1709 additions and 1745 deletions

View file

@ -1,25 +0,0 @@
在提出问题前请先自行排除服务器端问题和升级到最新客户端,同时也请通过搜索确认是否有人提出过相同问题。
### 预期行为
描述你认为应该发生什么
### 实际行为
描述实际发生了什么
### 复现方法
1.
2.
3.
### 日志信息,位置在当前目录下的guiLogs
<details>
```
在这里粘贴日志
```
</details>
### 环境信息(客户端请升级至最新正式版)
### 额外信息(可选)

18
.gitignore vendored
View file

@ -1,18 +0,0 @@
################################################################################
# 此 .gitignore 文件已由 Microsoft(R) Visual Studio 自动创建。
################################################################################
/v2rayN/.vs/
/v2rayN/v2rayN/bin/Debug/app.publish
/v2rayN/v2rayN/bin/Debug
/v2rayN/v2rayN/bin/Release
/v2rayN/v2rayN/obj/
/v2rayN/.vs/v2rayN/DesignTimeBuild
/v2rayN/packages
.vs/ProjectSettings.json
.vs/slnx.sqlite
.vs/VSWorkspaceState.json
/v2rayN/v2rayUpgrade/bin/Debug
/v2rayN/v2rayUpgrade/obj/Debug
/v2rayN/v2rayUpgrade/bin/Release
/v2rayN/v2rayUpgrade/obj/Release

View file

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio Version 16
VisualStudioVersion = 15.0.28010.2050 VisualStudioVersion = 16.0.31321.278
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "v2rayN", "v2rayN\v2rayN.csproj", "{0A9785E6-D256-4B73-9757-4EF59955FD1E}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "v2rayN", "v2rayN\v2rayN.csproj", "{0A9785E6-D256-4B73-9757-4EF59955FD1E}"
EndProject EndProject
@ -22,6 +22,7 @@ Global
{0A9785E6-D256-4B73-9757-4EF59955FD1E}.Release|Any CPU.ActiveCfg = Release|Any CPU {0A9785E6-D256-4B73-9757-4EF59955FD1E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0A9785E6-D256-4B73-9757-4EF59955FD1E}.Release|Any CPU.Build.0 = Release|Any CPU {0A9785E6-D256-4B73-9757-4EF59955FD1E}.Release|Any CPU.Build.0 = Release|Any CPU
{0A9785E6-D256-4B73-9757-4EF59955FD1E}.Release|x86.ActiveCfg = Release|Any CPU {0A9785E6-D256-4B73-9757-4EF59955FD1E}.Release|x86.ActiveCfg = Release|Any CPU
{0A9785E6-D256-4B73-9757-4EF59955FD1E}.Release|x86.Build.0 = Release|Any CPU
{F82BE52A-155C-492C-9E0A-1E917EC62C78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F82BE52A-155C-492C-9E0A-1E917EC62C78}.Debug|Any CPU.Build.0 = Debug|Any CPU {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F82BE52A-155C-492C-9E0A-1E917EC62C78}.Debug|x86.ActiveCfg = Debug|Any CPU {F82BE52A-155C-492C-9E0A-1E917EC62C78}.Debug|x86.ActiveCfg = Debug|Any CPU
@ -35,7 +36,7 @@ Global
HideSolutionNode = FALSE HideSolutionNode = FALSE
EndGlobalSection EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution GlobalSection(ExtensibilityGlobals) = postSolution
RESX_SortFileContentOnSave = True
SolutionGuid = {56B88873-C9CC-4069-A1E5-DABD6C6E865E} SolutionGuid = {56B88873-C9CC-4069-A1E5-DABD6C6E865E}
RESX_SortFileContentOnSave = True
EndGlobalSection EndGlobalSection
EndGlobal EndGlobal

File diff suppressed because it is too large Load diff

View file

@ -189,6 +189,8 @@ namespace v2rayN
} }
public const string StatisticLogOverall = "StatisticLogOverall.json"; public const string StatisticLogOverall = "StatisticLogOverall.json";
public const string CustomProxyExceptions = "ProxyExceptions.txt";
public const string IEProxyExceptions = "localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;192.168.*"; public const string IEProxyExceptions = "localhost;127.*;10.*;172.16.*;172.17.*;172.18.*;172.19.*;172.20.*;172.21.*;172.22.*;172.23.*;172.24.*;172.25.*;172.26.*;172.27.*;172.28.*;172.29.*;172.30.*;172.31.*;192.168.*";
public const string RoutingRuleComma = "<COMMA>"; public const string RoutingRuleComma = "<COMMA>";

View file

@ -1,198 +1,198 @@
using System; using System;
using v2rayN.Mode; using v2rayN.Mode;
namespace v2rayN.HttpProxyHandler namespace v2rayN.HttpProxyHandler
{ {
/// <summary> /// <summary>
/// 系统代理(http)模式 /// 系统代理(http)模式
/// </summary> /// </summary>
public enum ListenerType public enum ListenerType
{ {
noHttpProxy = 0, noHttpProxy = 0,
GlobalHttp = 1, GlobalHttp = 1,
HttpOpenAndClear = 2, HttpOpenAndClear = 2,
HttpOpenOnly = 3, HttpOpenOnly = 3,
} }
/// <summary> /// <summary>
/// 系统代理(http)总处理 /// 系统代理(http)总处理
/// 启动privoxy提供http协议 /// 启动privoxy提供http协议
/// 设置IE系统代理 /// 设置IE系统代理
/// </summary> /// </summary>
class HttpProxyHandle class HttpProxyHandle
{ {
private static bool Update(Config config, bool forceDisable) private static bool Update(Config config, bool forceDisable)
{ {
// ListenerType type = config.listenerType; // ListenerType type = config.listenerType;
var type = ListenerType.noHttpProxy; var type = ListenerType.noHttpProxy;
if (forceDisable) if (forceDisable)
{ {
type = ListenerType.noHttpProxy; type = ListenerType.noHttpProxy;
} }
try try
{ {
if (type != ListenerType.noHttpProxy) if (type != ListenerType.noHttpProxy)
{ {
int port = Global.httpPort; int port = Global.httpPort;
if (port <= 0) if (port <= 0)
{ {
return false; return false;
} }
if (type == ListenerType.GlobalHttp) if (type == ListenerType.GlobalHttp)
{ {
//ProxySetting.SetProxy($"{Global.Loopback}:{port}", Global.IEProxyExceptions, 2); //ProxySetting.SetProxy($"{Global.Loopback}:{port}", Global.IEProxyExceptions, 2);
SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}"); SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}");
} }
else if (type == ListenerType.HttpOpenAndClear) else if (type == ListenerType.HttpOpenAndClear)
{ {
SysProxyHandle.ResetIEProxy(); SysProxyHandle.ResetIEProxy();
} }
else if (type == ListenerType.HttpOpenOnly) else if (type == ListenerType.HttpOpenOnly)
{ {
//SysProxyHandle.ResetIEProxy(); //SysProxyHandle.ResetIEProxy();
} }
} }
else else
{ {
SysProxyHandle.ResetIEProxy(); SysProxyHandle.ResetIEProxy();
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Utils.SaveLog(ex.Message, ex);
} }
return true; return true;
} }
/// <summary> /// <summary>
/// 启用系统代理(http) /// 启用系统代理(http)
/// </summary> /// </summary>
/// <param name="config"></param> /// <param name="config"></param>
private static void StartHttpAgent(Config config) private static void StartHttpAgent(Config config)
{ {
try try
{ {
int localPort = config.GetLocalPort(Global.InboundSocks); int localPort = config.GetLocalPort(Global.InboundSocks);
if (localPort > 0) if (localPort > 0)
{ {
PrivoxyHandler.Instance.Restart(localPort, config); PrivoxyHandler.Instance.Restart(localPort, config);
if (PrivoxyHandler.Instance.RunningPort > 0) if (PrivoxyHandler.Instance.RunningPort > 0)
{ {
Global.sysAgent = true; Global.sysAgent = true;
Global.socksPort = localPort; Global.socksPort = localPort;
Global.httpPort = PrivoxyHandler.Instance.RunningPort; Global.httpPort = PrivoxyHandler.Instance.RunningPort;
} }
} }
} }
catch catch
{ {
} }
} }
/// <summary> /// <summary>
/// 关闭系统代理 /// 关闭系统代理
/// </summary> /// </summary>
/// <param name="config"></param> /// <param name="config"></param>
public static void CloseHttpAgent(Config config) public static void CloseHttpAgent(Config config)
{ {
try try
{ {
//if (config.listenerType != ListenerType.HttpOpenOnly) //if (config.listenerType != ListenerType.HttpOpenOnly)
//{ //{
// Update(config, true); // Update(config, true);
//} //}
PrivoxyHandler.Instance.Stop(); PrivoxyHandler.Instance.Stop();
Global.sysAgent = false; Global.sysAgent = false;
Global.socksPort = 0; Global.socksPort = 0;
Global.httpPort = 0; Global.httpPort = 0;
} }
catch catch
{ {
} }
} }
/// <summary> /// <summary>
/// 重启系统代理(http) /// 重启系统代理(http)
/// </summary> /// </summary>
/// <param name="config"></param> /// <param name="config"></param>
/// <param name="forced"></param> /// <param name="forced"></param>
public static void RestartHttpAgent(Config config, bool forced) public static void RestartHttpAgent(Config config, bool forced)
{ {
bool isRestart = false; bool isRestart = false;
//if (config.listenerType == ListenerType.noHttpProxy) //if (config.listenerType == ListenerType.noHttpProxy)
//{ //{
// // 关闭http proxy时直接返回 // // 关闭http proxy时直接返回
// return; // return;
//} //}
//强制重启或者socks端口变化 //强制重启或者socks端口变化
if (forced) if (forced)
{ {
isRestart = true; isRestart = true;
} }
else else
{ {
int localPort = config.GetLocalPort(Global.InboundSocks); int localPort = config.GetLocalPort(Global.InboundSocks);
if (localPort != Global.socksPort) if (localPort != Global.socksPort)
{ {
isRestart = true; isRestart = true;
} }
} }
if (isRestart) if (isRestart)
{ {
CloseHttpAgent(config); CloseHttpAgent(config);
StartHttpAgent(config); StartHttpAgent(config);
} }
Update(config, false); Update(config, false);
} }
public static bool UpdateSysProxy(Config config, bool forceDisable) public static bool UpdateSysProxy(Config config, bool forceDisable)
{ {
var type = config.sysProxyType; var type = config.sysProxyType;
if (forceDisable && type == ESysProxyType.ForcedChange) if (forceDisable && type == ESysProxyType.ForcedChange)
{ {
type = ESysProxyType.ForcedClear; type = ESysProxyType.ForcedClear;
} }
try try
{ {
Global.httpPort = config.GetLocalPort(Global.InboundHttp); Global.httpPort = config.GetLocalPort(Global.InboundHttp);
int port = Global.httpPort; int port = Global.httpPort;
if (port <= 0) if (port <= 0)
{ {
return false; return false;
} }
if (type == ESysProxyType.ForcedChange) if (type == ESysProxyType.ForcedChange)
{ {
SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}"); SysProxyHandle.SetIEProxy(true, true, $"{Global.Loopback}:{port}");
} }
else if (type == ESysProxyType.ForcedClear) else if (type == ESysProxyType.ForcedClear)
{ {
SysProxyHandle.ResetIEProxy(); SysProxyHandle.ResetIEProxy();
} }
else if (type == ESysProxyType.Unchanged) else if (type == ESysProxyType.Unchanged)
{ {
} }
} }
catch (Exception ex) catch (Exception ex)
{ {
Utils.SaveLog(ex.Message, ex); Utils.SaveLog(ex.Message, ex);
} }
return true; return true;
} }
public static void ResetIEProxy4WindowsShutDown() public static void ResetIEProxy4WindowsShutDown()
{ {
try try
{ {
//TODO To be verified //TODO To be verified
Utils.RegWriteValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", 0); Utils.RegWriteValue(@"Software\Microsoft\Windows\CurrentVersion\Internet Settings", "ProxyEnable", 0);
} }
catch catch
{ {
} }
} }
} }
} }

View file

@ -59,10 +59,14 @@ namespace v2rayN.HttpProxyHandler
//} //}
string arguments; string arguments;
if (enable) if (enable) {
{ var customProxyException = Utils.LoadResource(Utils.GetPath(Global.CustomProxyExceptions));
var finalProxyExceptions = Global.IEProxyExceptions;
if (customProxyException != null && customProxyException.Trim() != string.Empty) {
finalProxyExceptions = finalProxyExceptions + ';' + customProxyException.Trim();
}
arguments = global arguments = global
? $"global {strProxy} {Global.IEProxyExceptions}" ? $"global {strProxy} {finalProxyExceptions}"
: $"pac {strProxy}"; : $"pac {strProxy}";
} }
else else

View file

@ -47,8 +47,8 @@ namespace v2rayN.Properties {
} }
/// <summary> /// <summary>
/// 重写当前线程的 CurrentUICulture 属性 /// 重写当前线程的 CurrentUICulture 属性,对
/// 重写当前线程的 CurrentUICulture 属性 /// 使用此强类型资源类的所有资源查找执行重写
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture { internal static global::System.Globalization.CultureInfo Culture {

View file

@ -12,7 +12,7 @@ namespace v2rayN.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "14.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View file

@ -47,8 +47,8 @@ namespace v2rayN.Resx {
} }
/// <summary> /// <summary>
/// 重写当前线程的 CurrentUICulture 属性 /// 重写当前线程的 CurrentUICulture 属性,对
/// 重写当前线程的 CurrentUICulture 属性 /// 使用此强类型资源类的所有资源查找执行重写
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture { internal static global::System.Globalization.CultureInfo Culture {

View file

@ -1,7 +1,7 @@
<?xml version="1.0"?> <?xml version="1.0"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/></startup>
</configuration> </configuration>

View file

@ -9,7 +9,7 @@
<AppDesignerFolder>Properties</AppDesignerFolder> <AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>v2rayN</RootNamespace> <RootNamespace>v2rayN</RootNamespace>
<AssemblyName>v2rayN</AssemblyName> <AssemblyName>v2rayN</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<TargetFrameworkProfile /> <TargetFrameworkProfile />
<IsWebBootstrapper>false</IsWebBootstrapper> <IsWebBootstrapper>false</IsWebBootstrapper>

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<configuration> <configuration>
<startup> <startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup> </startup>
</configuration> </configuration>

View file

@ -19,7 +19,7 @@ namespace v2rayUpgrade.Properties {
// 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。
// 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen
// (以 /str 作为命令选项),或重新生成 VS 项目。 // (以 /str 作为命令选项),或重新生成 VS 项目。
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources { internal class Resources {
@ -47,8 +47,8 @@ namespace v2rayUpgrade.Properties {
} }
/// <summary> /// <summary>
/// 重写当前线程的 CurrentUICulture 属性 /// 重写当前线程的 CurrentUICulture 属性,对
/// 重写当前线程的 CurrentUICulture 属性 /// 使用此强类型资源类的所有资源查找执行重写
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture { internal static global::System.Globalization.CultureInfo Culture {

View file

@ -12,7 +12,7 @@ namespace v2rayUpgrade.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.9.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.10.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View file

@ -8,7 +8,7 @@
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>v2rayUpgrade</RootNamespace> <RootNamespace>v2rayUpgrade</RootNamespace>
<AssemblyName>v2rayUpgrade</AssemblyName> <AssemblyName>v2rayUpgrade</AssemblyName>
<TargetFrameworkVersion>v4.6</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic> <Deterministic>true</Deterministic>