Skip to content

Commit

Permalink
Add system proxy exception function for linux
Browse files Browse the repository at this point in the history
  • Loading branch information
2dust committed Dec 6, 2024
1 parent 5f5d717 commit dbd4f55
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 10 deletions.
30 changes: 27 additions & 3 deletions v2rayN/ServiceLib/Handler/SysProxy/ProxySettingLinux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
{
public class ProxySettingLinux
{
public static async Task SetProxy(string host, int port)
public static async Task SetProxy(string host, int port, string exceptions)
{
var lstCmd = GetSetCmds(host, port);
var lstCmd = GetSetCmds(host, port, exceptions);

await ExecCmd(lstCmd);
}
Expand All @@ -29,7 +29,7 @@ private static async Task ExecCmd(List<CmdItem> lstCmd)
}
}

private static List<CmdItem> GetSetCmds(string host, int port)
private static List<CmdItem> GetSetCmds(string host, int port, string exceptions)
{
var isKde = IsKde(out var configDir);
List<string> lstType = ["", "http", "https", "socks", "ftp"];
Expand All @@ -41,13 +41,21 @@ private static List<CmdItem> GetSetCmds(string host, int port)
{
lstCmd.AddRange(GetSetCmd4Kde(type, host, port, configDir));
}
if (exceptions.IsNotEmpty())
{
lstCmd.AddRange(GetSetCmd4Kde("exceptions", exceptions, 0, configDir));
}
}
else
{
foreach (var type in lstType)
{
lstCmd.AddRange(GetSetCmd4Gnome(type, host, port));
}
if (exceptions.IsNotEmpty())
{
lstCmd.AddRange(GetSetCmd4Gnome("exceptions", exceptions, 0));
}
}
return lstCmd;
}
Expand Down Expand Up @@ -89,6 +97,14 @@ private static List<CmdItem> GetSetCmd4Kde(string type, string host, int port, s
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
{
var type2 = type.Equals("https") ? "http" : type;
Expand All @@ -114,6 +130,14 @@ private static List<CmdItem> GetSetCmd4Gnome(string type, string host, int port)
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
{
lstCmd.Add(new()
Expand Down
3 changes: 2 additions & 1 deletion v2rayN/ServiceLib/Handler/SysProxy/SysProxyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static async Task<bool> UpdateSysProxy(Config config, bool forceDisable)
try
{
var port = AppHandler.Instance.GetLocalPort(EInboundProtocol.socks);
var exceptions = config.SystemProxyItem.SystemProxyExceptions;
if (port <= 0)
{
return false;
Expand All @@ -27,7 +28,7 @@ public static async Task<bool> UpdateSysProxy(Config config, bool forceDisable)
break;
}
case ESysProxyType.ForcedChange when Utils.IsLinux():
await ProxySettingLinux.SetProxy(Global.Loopback, port);
await ProxySettingLinux.SetProxy(Global.Loopback, port, exceptions);
break;

case ESysProxyType.ForcedChange when Utils.IsOSX():
Expand Down
9 changes: 9 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions v2rayN/ServiceLib/Resx/ResUI.fa-Ir.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1380,11 +1380,14 @@
</data>
<data name="TransportExtraTip" xml:space="preserve">
<value>جیسون خام XHTTP Extra, فرمت: { XHTTPObject }</value>
</data>
</data>
<data name="TbSettingsHide2TrayWhenClose" xml:space="preserve">
<value>هنگام بستن پنجره در سینی پنهان شوید</value>
</data>
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
<value>تعداد در هر زمان برای دسته خودکار در طول تست سرعت (حداکثر 1000)</value>
</data>
</root>
<data name="TbSettingsExceptionTip2" xml:space="preserve">
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1387,4 +1387,7 @@
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
<value>Number per time for auto batch during speedtest(max 1000)</value>
</data>
<data name="TbSettingsExceptionTip2" xml:space="preserve">
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.ru.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1387,4 +1387,7 @@
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
<value>Number per time for auto batch during speedtest(max 1000)</value>
</data>
<data name="TbSettingsExceptionTip2" xml:space="preserve">
<value>Exception. Do not use proxy server for addresses,with a comma (,)</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1384,4 +1384,7 @@
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
<value>测速时自动分批的每批数量(最大1000)</value>
</data>
<data name="TbSettingsExceptionTip2" xml:space="preserve">
<value>例外. 对于下列地址不使用代理配置文件:使用逗号(,)分隔</value>
</data>
</root>
3 changes: 3 additions & 0 deletions v2rayN/ServiceLib/Resx/ResUI.zh-Hant.resx
Original file line number Diff line number Diff line change
Expand Up @@ -1384,4 +1384,7 @@
<data name="TbSettingsSpeedTestPageSize" xml:space="preserve">
<value>測速時自動分批的每批數量(最大1000)</value>
</data>
<data name="TbSettingsExceptionTip2" xml:space="preserve">
<value>例外. 對於下列位址不使用代理設定檔:使用逗號(,)分隔</value>
</data>
</root>
13 changes: 11 additions & 2 deletions v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,10 @@

<TabItem Name="tabSystemproxy" Header="{x:Static resx:ResUI.TbSettingsSystemproxy}">
<DockPanel Classes="Margin8">
<StackPanel DockPanel.Dock="Bottom" Orientation="Vertical">
<StackPanel
Name="panSystemProxyAdvanced"
DockPanel.Dock="Bottom"
Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<TextBlock
VerticalAlignment="Center"
Expand All @@ -723,11 +726,17 @@
</StackPanel>

<TextBlock
Grid.Row="1"
Name="txbSettingsExceptionTip"
VerticalAlignment="Center"
Classes="Margin8"
DockPanel.Dock="Top"
Text="{x:Static resx:ResUI.TbSettingsExceptionTip}" />
<TextBlock
Name="txbSettingsExceptionTip2"
VerticalAlignment="Center"
Classes="Margin8"
DockPanel.Dock="Top"
Text="{x:Static resx:ResUI.TbSettingsExceptionTip2}" />
<TextBox
x:Name="txtsystemProxyExceptions"
VerticalAlignment="Stretch"
Expand Down
9 changes: 7 additions & 2 deletions v2rayN/v2rayN.Desktop/Views/OptionSettingWindow.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,14 @@ public OptionSettingWindow()
this.BindCommand(ViewModel, vm => vm.SaveCmd, v => v.btnSave).DisposeWith(disposables);
});

if (!Utils.IsWindows())
if (Utils.IsWindows())
{
tabSystemproxy.IsVisible = false;
txbSettingsExceptionTip2.IsVisible = false;
}
else
{
txbSettingsExceptionTip.IsVisible = false;
panSystemProxyAdvanced.IsVisible = false;
}

if (Utils.IsOSX())
Expand Down

0 comments on commit dbd4f55

Please sign in to comment.