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

View file

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

View file

@ -59,10 +59,14 @@ namespace v2rayN.HttpProxyHandler
//}
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
? $"global {strProxy} {Global.IEProxyExceptions}"
? $"global {strProxy} {finalProxyExceptions}"
: $"pac {strProxy}";
}
else

View file

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

View file

@ -12,7 +12,7 @@ namespace v2rayN.Properties {
[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 {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -12,7 +12,7 @@ namespace v2rayUpgrade.Properties {
[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 {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

View file

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