Compare commits

..

No commits in common. "dbd4f55981628ba0c4fb13d1f82aa14580d5764a" and "5d55a5575435ae48af132af7b334646a65920bd6" have entirely different histories.

17 changed files with 29 additions and 98 deletions

View file

@ -10,7 +10,7 @@ namespace ServiceLib.Common
{ {
private static readonly Lazy<HttpClientHelper> _instance = new(() => private static readonly Lazy<HttpClientHelper> _instance = new(() =>
{ {
SocketsHttpHandler handler = new() { UseCookies = false }; HttpClientHandler handler = new() { UseCookies = false };
HttpClientHelper helper = new(new HttpClient(handler)); HttpClientHelper helper = new(new HttpClient(handler));
return helper; return helper;
}); });

View file

@ -68,8 +68,7 @@
public const string AutoRunRegPath = @"Software\Microsoft\Windows\CurrentVersion\Run"; public const string AutoRunRegPath = @"Software\Microsoft\Windows\CurrentVersion\Run";
public const string AutoRunName = "v2rayNAutoRun"; public const string AutoRunName = "v2rayNAutoRun";
public const string CustomIconName = "v2rayN.ico"; public const string CustomIconName = "v2rayN.ico";
public const string SystemProxyExceptionsWindows = "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 SystemProxyExceptionsLinux = "localhost, 127.0.0.0/8, ::1";
public const string RoutingRuleComma = "<COMMA>"; public const string RoutingRuleComma = "<COMMA>";
public const string GrpcGunMode = "gun"; public const string GrpcGunMode = "gun";
public const string GrpcMultiMode = "multi"; public const string GrpcMultiMode = "multi";

View file

@ -120,14 +120,9 @@ namespace ServiceLib.Handler
} }
config.ConstItem ??= new ConstItem(); config.ConstItem ??= new ConstItem();
if (Utils.IsNotEmpty(config.ConstItem.DefIEProxyExceptions)) if (Utils.IsNullOrEmpty(config.ConstItem.DefIEProxyExceptions))
{ {
config.SystemProxyItem.SystemProxyExceptions = $"{config.ConstItem.DefIEProxyExceptions};{config.SystemProxyItem.SystemProxyExceptions}"; config.ConstItem.DefIEProxyExceptions = Global.IEProxyExceptions;
config.ConstItem.DefIEProxyExceptions = string.Empty;
}
if (config.SystemProxyItem.SystemProxyExceptions.IsNullOrEmpty())
{
config.SystemProxyItem.SystemProxyExceptions = Utils.IsWindows() ? Global.SystemProxyExceptionsWindows : Global.SystemProxyExceptionsLinux;
} }
config.SpeedTestItem ??= new(); config.SpeedTestItem ??= new();

View file

@ -2,9 +2,9 @@
{ {
public class ProxySettingLinux public class ProxySettingLinux
{ {
public static async Task SetProxy(string host, int port, string exceptions) public static async Task SetProxy(string host, int port)
{ {
var lstCmd = GetSetCmds(host, port, exceptions); var lstCmd = GetSetCmds(host, port);
await ExecCmd(lstCmd); await ExecCmd(lstCmd);
} }
@ -29,7 +29,7 @@
} }
} }
private static List<CmdItem> GetSetCmds(string host, int port, string exceptions) private static List<CmdItem> GetSetCmds(string host, int port)
{ {
var isKde = IsKde(out var configDir); var isKde = IsKde(out var configDir);
List<string> lstType = ["", "http", "https", "socks", "ftp"]; List<string> lstType = ["", "http", "https", "socks", "ftp"];
@ -41,10 +41,6 @@
{ {
lstCmd.AddRange(GetSetCmd4Kde(type, host, port, configDir)); lstCmd.AddRange(GetSetCmd4Kde(type, host, port, configDir));
} }
if (exceptions.IsNotEmpty())
{
lstCmd.AddRange(GetSetCmd4Kde("exceptions", exceptions, 0, configDir));
}
} }
else else
{ {
@ -52,10 +48,6 @@
{ {
lstCmd.AddRange(GetSetCmd4Gnome(type, host, port)); lstCmd.AddRange(GetSetCmd4Gnome(type, host, port));
} }
if (exceptions.IsNotEmpty())
{
lstCmd.AddRange(GetSetCmd4Gnome("exceptions", exceptions, 0));
}
} }
return lstCmd; return lstCmd;
} }
@ -97,14 +89,6 @@
Arguments = ["--file", $"{configDir}/kioslaverc", "--group", "Proxy Settings", "--key", "ProxyType", "1"] Arguments = ["--file", $"{configDir}/kioslaverc", "--group", "Proxy Settings", "--key", "ProxyType", "1"]
}); });
} }
else if (type == "exceptions")
{
lstCmd.Add(new()
{
Cmd = "kwriteconfig5",
Arguments = ["--file", $"{configDir}/kioslaverc", "--group", "Proxy Settings", "--key", "NoProxyFor", host]
});
}
else else
{ {
var type2 = type.Equals("https") ? "http" : type; var type2 = type.Equals("https") ? "http" : type;
@ -130,14 +114,6 @@
Arguments = ["set", "org.gnome.system.proxy", "mode", "manual"] Arguments = ["set", "org.gnome.system.proxy", "mode", "manual"]
}); });
} }
else if (type == "exceptions")
{
lstCmd.Add(new()
{
Cmd = "gsettings",
Arguments = ["set", $"org.gnome.system.proxy", "ignore-hosts", JsonUtils.Serialize(host.Split(','), false)]
});
}
else else
{ {
lstCmd.Add(new() lstCmd.Add(new()

View file

@ -14,7 +14,6 @@
try try
{ {
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
var exceptions = config.SystemProxyItem.SystemProxyExceptions;
if (port <= 0) if (port <= 0)
{ {
return false; return false;
@ -28,7 +27,7 @@
break; break;
} }
case ESysProxyType.ForcedChange when Utils.IsLinux(): case ESysProxyType.ForcedChange when Utils.IsLinux():
await ProxySettingLinux.SetProxy(Global.Loopback, port, exceptions); await ProxySettingLinux.SetProxy(Global.Loopback, port);
break; break;
case ESysProxyType.ForcedChange when Utils.IsOSX(): case ESysProxyType.ForcedChange when Utils.IsOSX():
@ -66,7 +65,7 @@
private static void GetWindowsProxyString(Config config, int port, out string strProxy, out string strExceptions) private static void GetWindowsProxyString(Config config, int port, out string strProxy, out string strExceptions)
{ {
strExceptions = config.SystemProxyItem.SystemProxyExceptions; strExceptions = $"{config.ConstItem.DefIEProxyExceptions};{config.SystemProxyItem.SystemProxyExceptions}";
if (config.SystemProxyItem.NotProxyLocalAddress) if (config.SystemProxyItem.NotProxyLocalAddress)
{ {
strExceptions = $"<local>;{strExceptions}"; strExceptions = $"<local>;{strExceptions}";

View file

@ -3058,15 +3058,6 @@ namespace ServiceLib.Resx {
} }
} }
/// <summary>
/// 查找类似 Exception. Do not use proxy server for addresses,with a comma (,) 的本地化字符串。
/// </summary>
public static string TbSettingsExceptionTip2 {
get {
return ResourceManager.GetString("TbSettingsExceptionTip2", resourceCulture);
}
}
/// <summary> /// <summary>
/// 查找类似 Follow System Theme 的本地化字符串。 /// 查找类似 Follow System Theme 的本地化字符串。
/// </summary> /// </summary>

View file

@ -1380,14 +1380,11 @@
</data> </data>
<data name="TransportExtraTip" xml:space="preserve"> <data name="TransportExtraTip" xml:space="preserve">
<value>جیسون خام XHTTP Extra, فرمت: { XHTTPObject }</value> <value>جیسون خام XHTTP Extra, فرمت: { XHTTPObject }</value>
</data> </data>
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve"> <data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
<value>هنگام بستن پنجره در سینی پنهان شوید</value> <value>هنگام بستن پنجره در سینی پنهان شوید</value>
</data> </data>
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve"> <data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
<value>تعداد در هر زمان برای دسته خودکار در طول تست سرعت (حداکثر 1000)</value> <value>تعداد در هر زمان برای دسته خودکار در طول تست سرعت (حداکثر 1000)</value>
</data> </data>
<data name="TbSettingsExceptionTip2" xml:space="preserve"> </root>
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
</data>
</root>

View file

@ -1387,7 +1387,4 @@
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve"> <data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
<value>Number per time for auto batch during speedtest(max 1000)</value> <value>Number per time for auto batch during speedtest(max 1000)</value>
</data> </data>
<data name="TbSettingsExceptionTip2" xml:space="preserve">
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
</data>
</root> </root>

View file

@ -1387,7 +1387,4 @@
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve"> <data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
<value>Number per time for auto batch during speedtest(max 1000)</value> <value>Number per time for auto batch during speedtest(max 1000)</value>
</data> </data>
<data name="TbSettingsExceptionTip2" xml:space="preserve">
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
</data>
</root> </root>

View file

@ -1384,7 +1384,4 @@
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve"> <data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
<value>测速时自动分批的每批数量最大1000</value> <value>测速时自动分批的每批数量最大1000</value>
</data> </data>
<data name="TbSettingsExceptionTip2" xml:space="preserve">
<value>例外. 对于下列地址不使用代理配置文件:使用逗号(,)分隔</value>
</data>
</root> </root>

View file

@ -1384,7 +1384,4 @@
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve"> <data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
<value>測速時自動分批的每批數量最大1000</value> <value>測速時自動分批的每批數量最大1000</value>
</data> </data>
<data name="TbSettingsExceptionTip2" xml:space="preserve">
<value>例外. 對於下列位址不使用代理設定檔:使用逗號(,)分隔</value>
</data>
</root> </root>

View file

@ -122,7 +122,7 @@ namespace ServiceLib.Services.CoreConfig
singboxConfig.inbounds.Clear(); singboxConfig.inbounds.Clear();
singboxConfig.outbounds.RemoveAt(0); singboxConfig.outbounds.RemoveAt(0);
var initPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest); var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
@ -144,8 +144,8 @@ namespace ServiceLib.Services.CoreConfig
} }
//find unused port //find unused port
var port = initPort; var port = httpPort;
for (int k = initPort; k < Global.MaxPort; k++) for (int k = httpPort; k < Global.MaxPort; k++)
{ {
if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0) if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0)
{ {
@ -157,7 +157,7 @@ namespace ServiceLib.Services.CoreConfig
} }
//found //found
port = k; port = k;
initPort = port + 1; httpPort = port + 1;
break; break;
} }

View file

@ -248,7 +248,7 @@ namespace ServiceLib.Services.CoreConfig
v2rayConfig.outbounds.Clear(); v2rayConfig.outbounds.Clear();
v2rayConfig.routing.rules.Clear(); v2rayConfig.routing.rules.Clear();
var initPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest); var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.speedtest);
foreach (var it in selecteds) foreach (var it in selecteds)
{ {
@ -270,8 +270,8 @@ namespace ServiceLib.Services.CoreConfig
} }
//find unused port //find unused port
var port = initPort; var port = httpPort;
for (var k = initPort; k < Global.MaxPort; k++) for (var k = httpPort; k < Global.MaxPort; k++)
{ {
if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0) if (lstIpEndPoints?.FindIndex(_it => _it.Port == k) >= 0)
{ {
@ -283,7 +283,7 @@ namespace ServiceLib.Services.CoreConfig
} }
//found //found
port = k; port = k;
initPort = port + 1; httpPort = port + 1;
break; break;
} }

View file

@ -280,13 +280,13 @@ namespace ServiceLib.Services
{ {
return null; return null;
} }
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks); var httpPort = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
if (await SocketCheck(Global.Loopback, port) == false) if (await SocketCheck(Global.Loopback, httpPort) == false)
{ {
return null; return null;
} }
return new WebProxy($"socks5://{Global.Loopback}:{port}"); return new WebProxy(Global.Loopback, httpPort);
} }
private async Task<bool> SocketCheck(string ip, int port) private async Task<bool> SocketCheck(string ip, int port)

View file

@ -191,7 +191,7 @@ namespace ServiceLib.Services
{ {
try try
{ {
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}"); WebProxy webProxy = new(Global.Loopback, it.Port);
var output = await GetRealPingTime(downloadHandle, webProxy); var output = await GetRealPingTime(downloadHandle, webProxy);
ProfileExHandler.Instance.SetTestDelay(it.IndexId, output); ProfileExHandler.Instance.SetTestDelay(it.IndexId, output);
@ -262,7 +262,7 @@ namespace ServiceLib.Services
var item = await AppHandler.Instance.GetProfileItem(it.IndexId); var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
if (item is null) continue; if (item is null) continue;
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}"); WebProxy webProxy = new(Global.Loopback, it.Port);
await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) => await downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
{ {
@ -324,7 +324,7 @@ namespace ServiceLib.Services
var item = await AppHandler.Instance.GetProfileItem(it.IndexId); var item = await AppHandler.Instance.GetProfileItem(it.IndexId);
if (item is null) continue; if (item is null) continue;
var webProxy = new WebProxy($"socks5://{Global.Loopback}:{it.Port}"); WebProxy webProxy = new(Global.Loopback, it.Port);
_ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) => _ = downloadHandle.DownloadDataAsync(url, webProxy, timeout, (success, msg) =>
{ {
decimal.TryParse(msg, out var dec); decimal.TryParse(msg, out var dec);

View file

@ -697,10 +697,7 @@
<TabItem Name="tabSystemproxy" Header="{x:Static resx:ResUI.TbSettingsSystemproxy}"> <TabItem Name="tabSystemproxy" Header="{x:Static resx:ResUI.TbSettingsSystemproxy}">
<DockPanel Classes="Margin8"> <DockPanel Classes="Margin8">
<StackPanel <StackPanel DockPanel.Dock="Bottom" Orientation="Vertical">
Name="panSystemProxyAdvanced"
DockPanel.Dock="Bottom"
Orientation="Vertical">
<StackPanel Orientation="Horizontal"> <StackPanel Orientation="Horizontal">
<TextBlock <TextBlock
VerticalAlignment="Center" VerticalAlignment="Center"
@ -726,17 +723,11 @@
</StackPanel> </StackPanel>
<TextBlock <TextBlock
Name="txbSettingsExceptionTip" Grid.Row="1"
VerticalAlignment="Center" VerticalAlignment="Center"
Classes="Margin8" Classes="Margin8"
DockPanel.Dock="Top" DockPanel.Dock="Top"
Text="{x:Static resx:ResUI.TbSettingsExceptionTip}" /> Text="{x:Static resx:ResUI.TbSettingsExceptionTip}" />
<TextBlock
Name="txbSettingsExceptionTip2"
VerticalAlignment="Center"
Classes="Margin8"
DockPanel.Dock="Top"
Text="{x:Static resx:ResUI.TbSettingsExceptionTip2}" />
<TextBox <TextBox
x:Name="txtsystemProxyExceptions" x:Name="txtsystemProxyExceptions"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"

View file

@ -166,14 +166,9 @@ namespace v2rayN.Desktop.Views
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables); this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
}); });
if (Utils.IsWindows()) if (!Utils.IsWindows())
{ {
txbSettingsExceptionTip2.IsVisible = false; tabSystemproxy.IsVisible = false;
}
else
{
txbSettingsExceptionTip.IsVisible = false;
panSystemProxyAdvanced.IsVisible = false;
} }
if (Utils.IsOSX()) if (Utils.IsOSX())